Repository navigation
feat(client-pull): persisted peer knowledge base for probe-less client fetch - #1946
Conversation
…wledge base Co-Authored-By: Claude Opus 4.8 <[email protected]>
… 012 two-clock staleness
…th failure, and stop identity refresh on outage
There was a problem hiding this comment.
🟡 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) inUpstreamPullHeaderand feeds it into peer-store sampling/suppression. - Extends the CLI with
--rediscoverplus 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.
Coverage reportTotal: 82.85% (was 82.82%, ▲ +0.03%) — 74956/90475 lines
History
|
…rite errors, skipped records)
… 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]>
What
Gives
decdn fetcha 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.rsowns 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.jsonis deleted and folded into it.On a fetch,
discover_providerconsults 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--rediscoverflag and an optional[client] region_allowlistconfig pre-filter.Why
Key design points
StreamResponserate ceiling; a stale-low remembered price can never cause an overpay.decdn fetchprocesses.Reviewer notes
The whole-branch review caught and fixed three seam bugs worth a second look:
eth_address: Address::ZERO) could be selected as a payment lane;store_fast_pathnow also filters!identity_prunable(symmetric with the outage-fallback filter).(root, total_bytes)partial store + on-disk pool watermarks, so no bytes are re-paid). This is what preserves the invariant above; seecrates/cli/src/commands/fetch.rsfetch()failover loop.Known deferrals (parked with rationale):
--capacity-bond-addressto the EIP-712 deliveryverifyingContractand callscontract.usdc()unconditionally, so no CLI seam isolates the registry read. The fallback logic is unit-covered (resolve_bootstrapcached-fallback test).Tests
Unit tests across
peer_store(records, EWMA, staleness, prune/LRU, atomic writes), selection (store_fast_pathranking/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