Repository navigation
feat(node): lean positive probe cache (ADR 001, 15s TTL, no evidence retention) (#1165) - #1223
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…retention) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…robe cache) The metric has been specified at appendix-observability.md:86 and scraped by monitoring/grafana-dashboard.json:411 without ever being emitted. Splitting RefusalVerdict::DurableMiss over a DurableMissCause keeps BlobTooLarge — which shares the verdict but says nothing about any hold mechanism — out of the count. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ate walk Task 3 of the positive-probe-cache plan (#1165). Pure behaviour-neutral prep: try_pull and a new open_from_candidates (lifted from open_progressive_pull's inline loop) now take an explicit budget and report attempts consumed via a new PullOutcome, so a later change can share one MAX_PROVIDER_ATTEMPTS budget across the probe-cache walk and the DHT-discovery fallback walk. Both call sites still pass the full MAX_PROVIDER_ATTEMPTS, so nothing observable changes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Wire PositiveProbeCache into NodeOriginDeps (beside the negative cache) and write the top-10 (node_id, rate_per_mb, rtt_ms) triple at the tail of probe_and_rank, extracted into a shared `rank` helper. Write-only and behaviour-neutral: nothing reads the cache yet, so the full decdn-node suite (798 tests) stays green and unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…T (ADR 001) Origin::fetch now checks the positive probe cache before running a fresh DHT lookup + probe fanout: cached_candidates rebuilds ranked Candidates from a hit (fresh reputation/region, no ADR 030 latency re-scoring), filtered through the same negative-cache and wedged-channel checks probe_and_rank applies. MAX_PROVIDER_ATTEMPTS is now a single fetch-wide budget shared between the cached-candidate walk and the cold-path fallback, so a fully-refusing cache hit cannot double the worst-case pull-through deadline. Adds four integration tests exercising the wire-level property (no probe sent on a hit), TTL expiry, the shared attempt budget, and the negative cache's precedence over a stale positive hit — plus a probe-counting and a refusal-counting test-server variant to observe those properties at the wire rather than through metrics alone. Co-Authored-By: Claude Opus 4.8 <[email protected]>
open_progressive_pull (the window-paced pull path) wrote the positive probe cache via probe_and_rank but never read it, unlike Origin::fetch (the buffered path), which Task 5 made cached-first. Both consumers share one probe cache and the same probe_and_rank chokepoint that fills it, so a path that only writes pays the cost for the other's benefit. Restructures open_progressive_pull to check cached_candidates() first, walking the cached candidates via open_from_candidates() under a shared MAX_PROVIDER_ATTEMPTS budget before falling through to discover + probe on a miss or exhausted cache, mirroring Origin::fetch's flow exactly. Metering delta: node_pull_attempt() now fires once per call, after the cache-check on both branches (previously it fired unconditionally right after discovery, before probing). No prior test asserted node_pull_attempts_total on the progressive path, so this is safe — the buffered and window paths now agree on the metering contract. Adds a_progressive_pull_reuses_a_probe_cache_entry_written_by_a_buffered_fetch, which runs Origin::fetch then open_progressive_pull for the same hash and asserts the wire-level probe counter stays at 1 while the progressive pull still delivers the verified payload. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…deferred staker filter (#1165) Origin::fetch's cache-hit-then-fall-through-to-cold path (the branch that exercises the `if !attempt_metered` skip guarding node_pull_attempt() from double-counting) had no coverage where the cached phase spends FEWER than MAX_PROVIDER_ATTEMPTS before failing. Adds a test that warms the cache with a single refusing provider, brings a second healthy provider online between fetches, and asserts node_pull_attempts_total stays at 2 (not 3) across both fetches. Also notes in cached_candidates why the staker-set membership filter is deliberately not re-applied on a cache hit. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
WalkthroughAdds an LRU/TTL positive probe cache, cached-first origin pull orchestration for buffered and progressive paths, probe-cache metrics, durable refusal causes, runtime wiring, and integration coverage for expiry, filtering, budgets, and cache reuse. ChangesPositive probe cache integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Origin
participant PositiveProbeCache
participant DHTProbe
participant Provider
Origin->>PositiveProbeCache: look up hash
PositiveProbeCache-->>Origin: return cached ranked provider data
Origin->>Provider: attempt cached pull
Origin->>DHTProbe: perform fresh lookup and probe on cache miss or fallthrough
DHTProbe-->>PositiveProbeCache: store ranked provider triples
DHTProbe-->>Origin: return cold candidates
Origin->>Provider: attempt cold pull
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.92% (2488/2798 lines) |
There was a problem hiding this comment.
Code Review
This pull request implements the positive probe cache as specified in ADR 001, allowing repeat cache misses for popular hashes to skip DHT lookups and probe fanouts. It introduces PositiveProbeCache (a bounded LRU cache with a 15-second TTL), integrates it into both the buffered and window-paced pull paths under a shared attempt budget, and adds corresponding metrics and tests. The reviewer suggested an optimization in the get method of PositiveProbeCache to reduce map operations by performing shift_remove first, which simplifies the control flow and improves performance.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 81.53% (was 81.44%, ▲ +0.09%) — 48709/59746 lines
History
|
…ilures - probe_cache insert doc: MAX_PROVIDERS_PER_HASH as a code span, not an intra-doc link (a public method may not link a private const under rustdoc -D warnings). - plan doc: blank lines around lists/fences (MD031/MD032). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…iew) Drops the redundant O(1) get before the O(N) shift_remove; the hit path is now two IndexMap ops. Behaviourally identical — an expired entry is still evicted before returning None. Covered by the existing LRU/expiry tests. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ullOutcome<T> From the five-agent PR review of #1223: - probe_cache_hits doc + appendix row: a hit is "the walk STARTED from a cache entry", not "lookup+fanout skipped entirely" — the partial-budget fall-through re-probes within the same fetch and stays counted as a hit. - node_pull_no_providers gated behind !attempt_metered in both pull paths, restoring its documented exclusivity with node_pull_attempts ("not a pull failure") on hit-then-fallthrough fetches that re-discover empty. - DurableMissCause metric site: exhaustive match instead of ==, so a third cause must decide its telemetry (the file's own exhaustiveness doctrine). - PullOutcome made generic over the payload; open_from_candidates returns PullOutcome<(UpstreamPullHeader, NodeProgressivePull)> instead of a bare tuple (drops the .await.0 access); the misleading Pin<Box<dyn Future>> justification is gone. - Comment accuracy: staker-filter backstop narrowed to deregistration only (ejection/unbonding survive address resolution); invalidate doc no longer claims "every provider failed" when only the budgeted prefix was tried; KNOWN LIMITATION (#1129) cross-referenced at both budget==0 exits; DEFAULT_TTL doc cites ADR 001's second bound (probe_hold_duration); rot-prone free-floating 15s literals reworded; provenance tag -> #1223. - const size tripwire on ProbedProvider (no-evidence-retention invariant). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ion metric, window fallthrough, suppressed-entry miss (#1223) Co-Authored-By: Claude Opus 4.8 <[email protected]>
altanoruc
left a comment
There was a problem hiding this comment.
Reviewed the positive probe-cache implementation at 4f41578. The shared attempt budget, negative/wedged-provider filtering, cache invalidation, and buffered/progressive-path coverage are well exercised, and the current CI suite is green. I found one blocking ADR/policy regression on cache hits: current active-staker membership is not revalidated before opening the paid stream.
… 001) The cache-hit path (cached_candidates) bypassed find_providers, so it skipped the active-staker filter the cold path applies — a node ejected or unbonding inside the 15s TTL could win a paid pull the cold path would deny (addr_resolver is not this guard: the address binding survives ejection/unbonding, only deregistration clears it). Re-apply deps.staker_set.is_active on each cached provider, per the ADR. Requested by review on #1223. A static-config origin that is not a staker is now skipped on a hit and falls through to the cold path, where the unfiltered directory fallback re-serves it: static-only deployments get correctness, not hit acceleration. Production directories are chain-backed + staker-filtered, so their origins are stakers and the check is complete. Existing probe-cache tests now seed the staker set from the providers they inject (matching production); find_providers still returns empty for them (no routing entries), so cold-path discovery is unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…kerSet Merged origin/main, which retired the StakerSet::subscribe_changes seam and StakerChange (#1231, zero production consumers). The #1223 regression test helper implemented the old trait, so the PR-merge build failed to compile (unresolved StakerChange import, subscribe_changes not a trait member). Strip the broadcast field/method; MutableStakerSet now needs only is_active + active_nodes. new() is const now that the channel is gone. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…obe-cache # Conflicts: # crates/node/src/metrics.rs
…-path budget exhaustion Addresses PR review findings: - Rewrite the ProbedProvider "no evidence retention" size tripwire comment to describe the `size_of <= 48` assert as the review speed-bump it is (4 bytes of padding slack let a small field slip past), and name the actual guards: the `Copy` derive and the exhaustive struct literal at the write site. - Fix the `probe_cache_hits` doc (metrics.rs + appendix-observability.md): an all-cached-fail hit either falls through cold (budget remaining) OR returns a clean miss (budget exhausted, the common case with 10 providers vs a 3 budget), counted as a hit either way. The old "falls through" wording was wrong on the common path. - Broaden the `probe_cache_misses` suppression-cause list to include the inactive-staker and bad-key filters, not just negative-cache/wedged. - Add a window-path twin of the buffered budget test: three cached refusers driven through `open_progressive_pull` exercise the window path's own `budget == 0` short-circuit and `invalidate`, proven at the wire (probes 3→3→6, streams 3→6→9). Neither statement had test coverage before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #1165.
What
Implements the ADR 001 §Probe cache positive cache: a short-lived LRU
hash → Vec<(NodeId, rate_per_mb, rtt)>(15s TTL, 1024 entries, ≤10 providers/hash) checked before the DHT lookup. A repeat cache-miss for a popular hash skips both the DHT FIND_VALUE and the probe fanout, going straight to selection. Covers both pull paths — buffered (Origin::fetch) and window-paced (open_progressive_pull).Design highlights
ProbeResponse. Itsslash_sigis another node's on-chain slashable statement; an availability cache has no business being an evidence locker.ProbedProviderhas exactly three fields, enforced by aconstsize tripwire so it can't silently grow.DEFAULT_TTL = PROBE_SLASH_WINDOW / 2(ADR 005 §Derived constants) — a governance change to the slashing window moves it automatically; a literal15swould silently not. Also bounded belowprobe_hold_duration(35s) so the eviction hold still covers a stream opened from a cached entry.MAX_PROVIDER_ATTEMPTS(=3) budget (threaded via a genericPullOutcome<T>), so the worst case stays 3 sequential pulls andouter_pull_deadlineneeds no change. A cached phase that exhausts the budget short-circuits beforediscover.cached_candidatesre-applies the negative-cache and wedged-channel filters, re-checks active-staker membership (staker_set.is_active— the same admission gatefind_providersapplies on the cold path, so a node ejected/unbonding inside the TTL is denied a paid pull), and rebuilds reputation/region fresh every time (never cached). It deliberately does not re-run the ADR-030 region-latency penalty (a hit performs no probe → no new evidence).indexmap, mirroring the existingNegativeProbeCacheline-for-line (no new dependency).Observability
decdn_probe_post_eviction_failures_total(ADR 001-mandated, specified at appendix-observability.md:86 and already scraped bygrafana-dashboard.json— it had never been emitted). ADurableMissCausesplit (exhaustivematch, not==) keepsBlobTooLargeout of the count and forces any future cause to decide its telemetry.decdn_probe_cache_hits_total/decdn_probe_cache_misses_total(registered in the appendix). A 'hit' is counted when the candidate walk starts from a live entry; if every cached provider then fails within budget the fetch falls through cold but stays counted — the doc + appendix row say so explicitly.Tests
New unit tests pin the cache's LRU/TTL/truncation semantics; integration tests assert at the wire (a probe-counting
AtomicUsize), not just on metrics: second-fetch-skips-probe, past-TTL-reprobes, shared-budget (3 refusals not 6), hit-honours-negative-cache, cross-path reuse, partial-budget fall-through metering, invalidate-on-exhaustion, post-eviction-metric emission, fully-suppressed-entry miss, wedged-provider filter, and hit-drops-a-no-longer-active-provider (ejection inside the TTL). Full workspace suite green;clippy --workspace --all-targetsandfmtclean.Review rounds addressed
probe_cache_hitssemantics,node_pull_no_providersexclusivity gate), exhaustiveDurableMissCausematch, genericPullOutcome<T>, comment-accuracy fixes, plus coverage-gap tests.893dac1) + regression test (2d8093b). One accepted tradeoff: a static-config origin that isn't a staker is skipped on a hit and served via cold fallthrough instead — correctness preserved, hit-acceleration lost for static-only deployments; a non-issue in production (chain-backed directories are staker-filtered).Notes
PROBE_TIMEOUTis 5s but ADR 001 mandates 500ms (reverted by fix: bound the requester's fetch loop, and classify what comes back (#1088, #1144, #1134, #1143) #1145).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests