Skip to content

DHT: prefetch and popularity signals (ACs 7-8 of #320, ADR 022 §Popularity Signals) #650

Closed as not planned

Description

@thiras

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:

  1. 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.
  2. 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

  1. self-assigned this
    on May 21, 2026
  2. added
    status:blocked
    on May 21, 2026
  3. github-actions commented on May 21, 2026

    @github-actions

    🎯 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 OriginAssignment chain reads) that must land first.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature New subsystem implementing demand-driven prefetch per ADR 022
    Labels technical, blocked Implementation task blocked on #649 (iterative FindValue) and OriginAssignment chain reads
    Coding agent Needs more info Requirements are well-specified but the two declared dependencies (#649 + OriginAssignment chain 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:

    1. Signal tracker 1 — intercept FindValueRequest in the DHT responder handler; increment a bounded HashMap<Hash, VecDeque<Instant>> (LRU-pruned at 300s). No new ALPN needed.
    2. Signal tracker 2 — hook CacheEngine on cache-miss path to push a timestamp into the same or a parallel HashMap<Hash, VecDeque<Instant>> (max 10,000 entries, 5-minute window).
    3. Prefetch scheduler — when either counter crosses threshold, enqueue a 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/v1 pull-through.
    4. Policy gates (check in order, short-circuit):
      • prefetch.enabled (default false)
      • prefetch.require_authorized_origin: consult OriginDirectory::lookup_origins(hash) — skip if empty
      • prefetch.budget_usdc_per_hour: token-bucket against recent pull-through spend
      • prefetch.demand_quality_min_ratio: ratio of cache hits to pull attempts over rolling window

    Key anti-panic reminder: All HashMap accesses must use .get()/.entry(); the workspace-wide clippy deny on indexing_slicing will reject map[key].

    Sybil attack surface to test:

    • Demand-only attack: synthetic FIND_VALUE flood for an unauthorized blob should be stopped by require_authorized_origin.
    • Demand-supply attack: flood + hold the blob at an adversarial node — stopped by require_authorized_origin + budget_usdc_per_hour circuit breaker.

    Suggested sub-tasks:

    • Add PrefetchConfig fields to the config schema in crates/common
    • Implement FIND_VALUE frequency tracker in DHT responder (crates/node/src/dht/)
    • Implement cache-miss frequency tracker in CacheEngine (crates/cache/)
    • Implement PrefetchScheduler with policy gates
    • Wire metrics/observability for both signals (AC 8)
    • Integration test: node with prefetch.enabled = true triggers prefetch after threshold crossings
    • Threat model tests: demand-only and demand-supply attack simulations

    Generated by Agentic Triage for issue #650 · ● 1.5M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. removed
    status:blocked
    on May 29, 2026
  5. removed their assignment
    on May 30, 2026
  6. added
    rust
    on Jun 5, 2026
  7. thiras commented on Jun 5, 2026

    @thiras
    ContributorAuthor

    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_VALUE PopularityTracker, the PrefetchPolicy decision 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 OriginAssignment event subscription and live ledger feedback) is tracked as the follow-up in #820.

  8. added 4 commits that reference this issue on Jun 5, 2026
  9. thiras commented on Jun 10, 2026

    @thiras
    ContributorAuthor

    Closing as superseded by #820 — everything still open here is tracked there with current context:

    Whether #820 gets built at all is gated on the keep/defer/drop decision in #822.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:lowrust

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions