Repository navigation
Description
Context
ADR 022 §Popularity Signals and Market Dynamics describes how a node learns "what content is in demand before being asked to serve it" via two complementary signals:
- FIND_VALUE query frequency — non-suppressible; Kademlia routes FIND_VALUE queries for hash H to nodes closest to H regardless of holdings, so a node close to H sees demand without holding the blob.
- Local cache-miss frequency — bounded LRU map of miss timestamps per hash.
When either crosses a threshold (defaults: 5 FIND_VALUE queries or 3 misses in a 300-second window), the node MAY proactively prefetch the blob, subject to operator-policy gates.
This is the demand-driven side of the DHT and is intentionally deferred from PRs #642-#647 because (a) it's gated off-by-default behind `prefetch.enabled = false` and (b) it depends on the iterative FindValue lookup that ships separately.
Scope
Implement the prefetch decision pipeline per ADR 022 §Popularity Signals:
- Signal 1: FIND_VALUE-query-frequency tracker on the responder side, bounded LRU.
- Signal 2: Cache-miss-frequency tracker (`HashMap<Hash, VecDeque>`, max 10,000 entries, 5-minute LRU pruning).
- Prefetch decision: when either signal crosses its threshold, schedule a DHT FindValue → probe → `cdn/client/v1` pull-through, subject to:
- `prefetch.enabled` (default `false` — opt-in).
- `prefetch.require_authorized_origin` (default `true` — closes the demand-supply Sybil attack).
- `prefetch.budget_usdc_per_hour` (operator-set finite cap).
- `prefetch.demand_quality_min_ratio` auto-throttle (default `0.1`).
Acceptance criteria (from #320)
- AC 7 — A node with `prefetch.enabled = true` observing a prefetch trigger for hash H initiates a prefetch, subject to the origin gate, budget ceiling, and demand-quality auto-throttle.
- AC 8 — Demand signals derive from DHT FIND_VALUE traffic and local cache-miss timestamps; both are emitted as observability metrics.
Threat model (ADR 022 §Popularity Signals)
The ADR documents two compositional Sybil attacks (demand-only and demand-supply) and the load-bearing defenses:
- `require_authorized_origin` closes demand-supply by requiring the prefetched blob have a DAO-ratified origin.
- `budget_usdc_per_hour` defends the loss function as a circuit-breaker.
- `demand_quality_min_ratio` auto-throttles signal poisoning past the origin gate.
Dependencies
- Iterative requester-side FindValue lookup (separate follow-up issue).
- `OriginAssignment` chain reads (separate follow-up; `OriginDirectory` trait already exists).
References
- ADR 022 §Popularity Signals and Market Dynamics: `adr/022-content-discovery.md`
- Configuration block: ADR 022 §"Recommended configuration"
Splits out from #320 (called "PR 5 (optional)" in the plan at `/home/thiras/.claude/plans/issue-320-atomic-fox.md`).
Activity
github-actions commentedon May 21, 2026
🎯 Triage report
This issue implements ACs 7-8 of the DHT content-discovery epic (#320): the demand-driven prefetch decision pipeline with two signal sources (FIND_VALUE query frequency and cache-miss frequency), four operator policy gates, and the threat-model mitigations documented in ADR 022 §Popularity Signals. It is explicitly deferred from PRs #642-#647 and has two hard dependencies (iterative FindValue lookup #649 and
OriginAssignmentchain reads) that must land first.📊 Assessment
technical,blockedOriginAssignmentchain reads) don't have closed issues yet; a coding agent starting now would hit stubs. Suitable once those land.🔗 Similar issues
💡 Notes and suggestions
Implementation approach:
FindValueRequestin the DHT responder handler; increment a boundedHashMap<Hash, VecDeque<Instant>>(LRU-pruned at 300s). No new ALPN needed.CacheEngineon cache-miss path to push a timestamp into the same or a parallelHashMap<Hash, VecDeque<Instant>>(max 10,000 entries, 5-minute window).PrefetchTask { hash }. The task runs:DhtLookup::find_providers(hash)(DHT: iterative requester-side FindValue lookup (α=3 + ADR 022 §Lookup integrity filters) #649) →cdn/probe/v1→cdn/client/v1pull-through.prefetch.enabled(defaultfalse)prefetch.require_authorized_origin: consultOriginDirectory::lookup_origins(hash)— skip if emptyprefetch.budget_usdc_per_hour: token-bucket against recent pull-through spendprefetch.demand_quality_min_ratio: ratio of cache hits to pull attempts over rolling windowKey anti-panic reminder: All
HashMapaccesses must use.get()/.entry(); the workspace-wide clippy deny onindexing_slicingwill rejectmap[key].Sybil attack surface to test:
require_authorized_origin.require_authorized_origin+budget_usdc_per_hourcircuit breaker.Suggested sub-tasks:
PrefetchConfigfields to the config schema incrates/commoncrates/node/src/dht/)CacheEngine(crates/cache/)PrefetchSchedulerwith policy gatesprefetch.enabled = truetriggers prefetch after threshold crossingsthiras commentedon Jun 5, 2026
PR #819 implements the core slice of this issue.
Scope note: the issue text predates an ADR change. ADR 022 §Popularity Signals now drives speculative prefetch from a single signal — FIND_VALUE query frequency. The "Signal 2" described here (local cache-miss frequency as a prefetch trigger) was superseded by ADR 037 (reactive chunk-paced pull-through); per-hash cache-miss frequency remains an observability metric only and does not drive acquisition. PR #819 therefore implements Signal 1 only.
PR #819 lands (behind
prefetch.enabled = false): the[prefetch]config block, the FIND_VALUEPopularityTracker, thePrefetchPolicydecision engine (enabled → demand-quality throttle → authorized-origin → budget gates), the 7 prefetch metrics, and handler/runtime wiring that decides and meters on FIND_VALUE traffic. This satisfies AC 8 (demand derives from FIND_VALUE traffic).AC 7 (a node actually initiates the FindValue→probe→pull-through acquisition, plus
OriginAssignmentevent subscription and live ledger feedback) is tracked as the follow-up in #820.fix(node): address PR #819 review — edge-trigger, hot-path, lock scope (
fix(node): address PR #819 review — clock, throttle naming, origin ga…
fix(cli): allow too_many_lines on write_validate_summary (#650)
feat(node): add DHT prefetch popularity signal + decision engine (#650)…
thiras commentedon Jun 10, 2026
Closing as superseded by #820 — everything still open here is tracked there with current context:
PopularityTracker,PrefetchPolicy, config, metrics, behindprefetch.enabled = false).Whether #820 gets built at all is gated on the keep/defer/drop decision in #822.
feat(node): wire live DHT prefetch acquisition + ledger feedback (#820)…