Skip to content

feat(client-pull): persisted peer knowledge base for probe-less client fetch - #1946

Merged
alpergundogdu merged 16 commits into
mainfrom
claude/client-peer-rtt-map
Sep 7, 2026
Merged

alpergundogdu merged 16 commits into
mainfrom
claude/client-peer-rtt-map

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Gives decdn fetch a persisted per-peer knowledge base so repeat fetches skip probing peers it already knows are near and cheap — the "streaming music, don't re-probe every song" case. This implements ADR 037's long-specified-but-unbuilt client RTT map, and extends it.

A new crates/client-pull/src/peer_store.rs owns a directory of one JSON file per peer under <data_dir>/peers/<node_id>.json, each record carrying registry-fed identity and interaction-fed latency/price that age on two independent clocks. peers.json is deleted and folded into it.

On a fetch, discover_provider consults the store first and takes a probe-less fast path when it holds ≥3 fresh candidates (ranked by measured latency), with the full probe/discovery path as an in-fetch fallback. Samples are harvested off the critical path from both probes and completed-stream TTFB. Adds a --rediscover flag and an optional [client] region_allowlist config pre-filter.

Why

  • Repeat fetches currently re-probe ~5 candidates every time and re-learn the same latency/price. The store makes the second fetch probe-less.
  • Non-holders that were probed (warm-lane candidates) are now remembered too, not just holders.
  • Load-bearing invariant (design-approved): the store can only ever make a fetch faster, never make one fail that probing would have served.

Key design points

  • Price is a ranking hint only. Payment is still gated by the signed StreamResponse rate ceiling; a stale-low remembered price can never cause an overpay.
  • Two-clock staleness / field-aware eviction: fresh identity + stale latency is kept and re-measured; very stale identity is pruned.
  • Atomic per-file writes (temp + rename), lock-free and safe across concurrent decdn fetch processes.
  • Not in scope (deferred, documented): ADR 037's active latency sweep (sentinel-hash probing of un-fetched nodes) — distinct from the harvest shipped here.

Reviewer notes

The whole-branch review caught and fixed three seam bugs worth a second look:

  1. Fast-path identity guard — a stats-only placeholder record (eth_address: Address::ZERO) could be selected as a payment lane; store_fast_path now also filters !identity_prunable (symmetric with the outage-fallback filter).
  2. Discovery fallback on fast-path failure — when every fast-path candidate fails with a retryable error, the fetch now re-resolves once via forced discovery within the same fetch (guarded against recursion; resume is automatic via the content-keyed (root, total_bytes) partial store + on-disk pool watermarks, so no bytes are re-paid). This is what preserves the invariant above; see crates/cli/src/commands/fetch.rs fetch() failover loop.
  3. No identity refresh on outage — identity is harvested only on a live registry read, so a departed node isn't circularly "confirmed" against the store's own identities during outages.

Known deferrals (parked with rationale):

  • Per-lane stream-TTFB for secondary multi-source lanes (their opens live in the scheduler, out of scope; those peers are still populated via probe harvest).
  • The e2e registry-outage journey is not driven end-to-end — the CLI couples --capacity-bond-address to the EIP-712 delivery verifyingContract and calls contract.usdc() unconditionally, so no CLI seam isolates the registry read. The fallback logic is unit-covered (resolve_bootstrap cached-fallback test).

Tests

Unit tests across peer_store (records, EWMA, staleness, prune/LRU, atomic writes), selection (store_fast_path ranking/gating, region filter, --rediscover), and a feature-gated e2e (crates/e2e/tests/peer_store_probeless.rs, --features anvil-e2e) proving a probe-less second fetch across separate CLI processes. Full workspace suite green.

ADRs 037 and 012 amended to match (present-tense canon).

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 5, 2026 08:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new peer-store fallback path regresses user-visible outage diagnostics (no staleness reported, and store write/decode failures are silently swallowed), which undermines operational safety and conflicts with the updated ADR expectations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a persisted per-peer knowledge base to the paid client fetch path so repeat decdn fetch runs can skip registry/probe work when enough fresh peer stats already exist, while preserving the “store can only make a fetch faster, never make one fail” invariant via in-fetch rediscovery fallback.

Changes:

  • Introduces PeerStore (per-peer JSON records) and wires it into bootstrap fallback + probe-less fast-path selection.
  • Records stream-derived TTFB (ttfb_ms) in UpstreamPullHeader and feeds it into peer-store sampling/suppression.
  • Extends the CLI with --rediscover plus optional [client] region_allowlist, and adds e2e coverage for cross-process probe-less repeat fetches.
File summaries
File Description
crates/protocol/Cargo.toml Updates comment referencing the new client peer store (JSON consumer format).
crates/node/src/node_origin/backend_source.rs Sets ttfb_ms = 0.0 for local origin re-encode headers (no network RTT).
crates/e2e/tests/peer_store_probeless.rs New anvil-backed e2e proving cross-process persistence and probe-less second fetch.
crates/common/src/config/types.rs Adds [client] config section with region_allowlist and TOML parsing tests.
crates/common/src/cli/fetch.rs Adds --rediscover flag to fetch CLI args and tests for its default/behavior.
crates/client-pull/src/source.rs Sets ttfb_ms = 0.0 in scripted doubles (no network RTT).
crates/client-pull/src/peer_store.rs New PeerStore/PeerRecord implementation (atomic per-file writes, EWMA, staleness, prune/cap) + unit tests.
crates/client-pull/src/lib.rs Exposes peer_store module + re-exports; adds ttfb_ms to UpstreamPullHeader and measures it in open_progressive_pull.
crates/client-pull/src/driver.rs Updates test header construction to include ttfb_ms.
crates/client-pull/src/discovery.rs Replaces peers.json cache with peer-store-backed bootstrap fallback; adds region-allowlist filtering helper + tests.
crates/client-pull/Cargo.toml Updates dependency comments to reflect peer store persistence semantics.
crates/cli/src/commands/fetch.rs Implements store fast path, harvesting, rediscovery fallback loop, region allowlist parsing/filtering, and peer-store sample/failure stamping.
crates/cli/src/commands/config.rs Documents [client] region_allowlist in the default config and validates it parses.
crates/cli/src/commands/bundle_pull.rs Updates a comment to refer to “peer store” rather than “peer cache”.
adr/037-regional-proxy-warming.md Updates ADR 037 to describe the persisted unified store and probe-less routing approach.
adr/012-client.md Updates ADR 012 bootstrap steps and state tree to reflect the peer store.
Review details
  • Files reviewed: 16/16 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/client-pull/src/discovery.rs Resolved
Comment thread crates/client-pull/src/discovery.rs Resolved
Comment thread crates/client-pull/src/peer_store.rs Resolved
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.85% (was 82.82%, ▲ +0.03%) — 74956/90475 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 52.07% 553/1062 ● 0.00%
crates/cli/src/commands/config.rs 87.16% 808/927 ▼ 0.16%
crates/cli/src/commands/fetch.rs 39.27% 818/2083 ▲ +2.29%
crates/client-pull/src/discovery.rs 96.64% 777/804 ▲ +0.15%
crates/client-pull/src/driver.rs 91.94% 992/1079 ▲ +0.01%
crates/client-pull/src/lib.rs 89.78% 1775/1977 ▼ 0.04%
crates/client-pull/src/peer_store.rs 95.69% 311/325 new
crates/client-pull/src/source.rs 92.98% 318/342 ▲ +0.04%
crates/common/src/cli/fetch.rs 96.41% 188/195 ▲ +0.08%
crates/common/src/config/types.rs 100.00% 18/18 new
crates/node/src/node_origin/backend_source.rs 79.62% 207/260 ▲ +0.16%
History
Commit Total Δ vs base
4940636 82.81% ▼ 0.01%
d64d201 (HEAD) 82.85% ▲ +0.03%

@alpergundogdu
alpergundogdu merged commit da5c90c into main Sep 7, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the claude/client-peer-rtt-map branch September 7, 2026 12:31
thiras added a commit that referenced this pull request Sep 27, 2026
… count (#2175)

* fix(node,client): heal a stale payer by lane headroom, not the stream count

A reloaded lane now counts its whole claim, the signed bytes plus the
proved chain frontier, as already credited (#2171). Crediting only the
signed half handed each restart up to a chain of free headroom, which
also masked the stall below.

A stale proof must pay its chunk in full from lane headroom (#2173). An
honest lagging sibling always finds its chunk there, because the proof
that superseded it folded the payment and a metering voucher takes no
whole chunk. A restarted payer that lost vouchers finds nothing. The node
decides at the proof that pays the chunk: a sealed or closing voucher
below the anchor, or a reveal that folds nothing. On a short headroom it
rejects AmountRegression with the watermark bundle and commits no credit.

This replaces the active_streams <= 1 gate on the #1946 resume bundle.
The gate let a restarted payer beside a live sibling stall until
VOUCHER_READ_TIMEOUT, and it tore down an honest sibling whose peer
stream had already ended. The per-lane stream counter and LaneSlot had
no other reader and are removed.

A voucher at the signed amount with fewer bytes is now a BytesRegression
too, not only one with more bytes.

The client treats an AmountRegression whose bundle its ledger already
covers as healed by a sibling stream, and retries, as it does for
UnderFold.

Closes #2171
Closes #2173

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(client,node): anchor-checked reveals and at-anchor stale vouchers

Review follow-ups to the stale-proof heal.

Client: PoolLedger::meter takes the stream's anchored root and returns
Metered::Moved, sending nothing, when a sibling rolled the lane between
the stream's anchor and the tick. The stream also records the root its
own Open/Roll/closing voucher signed, not a post-send re-read that can
already name a sibling's newer chain. Either race released a reveal the
node placed against the wrong root, which folded nothing.

Node: a voucher AT the signed anchor that pays its chunk is stale too. A
restarted payer that re-signs the node's own watermark for a same-size
transfer otherwise waited out VOUCHER_READ_TIMEOUT, on main as well.
The stale reject logs the lane and the credit figures, at warn when no
bundle can be built.

Client heal logs say whether a sibling reseeded first or the ledger is
already past the bundle. New end-to-end tests cover the voucher-path
reject (sub-chunk transfer, one and two transfers behind) and a
concurrent range set healing on one ledger. Stale LaneSlot references,
the removed multi-stream exception in fetch.rs, and the ADR 003/005
wording (ignored/refuses nothing, strict-below, reveal bundles) are
brought in line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(client): regenerate the SDK API snapshot for Metered::Moved

The public API snapshot carries the anchored-root argument of
PoolLedger::meter and the Metered::Moved variant.

The write-failure recovery no longer re-reads the lane's chain root into
the stream's anchor after a StreamEnd: the stream has ended, nothing
meters on it again, and the re-read could name a sibling's newer chain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants