Skip to content

DHT: batch StoreRequest for bootstrap and dense re-publish #630

Closed

Description

@alpergundogdu

Context

The DHT bandwidth analysis in #629 identifies bootstrap surge (230,000 STOREs from a publisher with C=10,000 cached blobs) as the load-bearing motivation for batching StoreRequest. Without batching, ~11.5 MB of pure QUIC stream framing dominates the wire cost per bootstrap; batched at 256 hashes/RPC, framing drops to ~45 KB. Total bytes-on-wire savings at bootstrap: ~60% — ~30 percentage points from framing elimination plus ~20 from holder-field de-duplication (one holder per batch instead of per-RPC).

Standard Kademlia does not batch STORE — Maymounkov & Mazières (2002), BEP 5, and libp2p's kad-dht all use one key per call. The convention is historical (UDP MTU constraints in the original spec) and use-case-specific (sparse-publication BitTorrent / IPFS regime). Neither applies here: we're on iroh QUIC and we're in a dense-publication incentive-driven regime. None of Kademlia's theoretical properties (XOR metric, k-bucket geometry, iterative lookup convergence) depend on STORE being one-key-per-RPC.

Scope

Wire types (crates/protocol)

struct BatchStoreRequest {
    hashes: Vec<Hash>,       // ≤256 entries; one publisher, many hashes for one receiver
    holder: NodeId,          // single holder; checked once vs authenticated QUIC NodeId
}

struct BatchStoreAck {
    results: Vec<(Hash, bool)>,  // per-hash accepted/rejected; same order as request
}

Add as new variants to DhtMessage. Per ADR 022's schema evolution rules and the "unknown variants silently dropped" guarantee, this is a backward-compatible extension — publishers can fall back to per-hash STORE on RATE_LIMITED or stream close without ack.

Handler (crates/node)

  • Single holder, one auth check. Verify holder == authenticated QUIC NodeId once for the whole batch.
  • Per-hash admission. Rate limit consumes hashes.len() tokens at admission (preserves the spirit of work-rate limiting). Per-publisher quota and global-LRU eviction apply per-hash; partial acceptance is the norm, not the exception.
  • Non-atomic ack. results carries per-hash outcome. Quota-exhausted entries return accepted: false; rate-limited-but-some-admitted is not possible because the rate-limit fires once for the whole batch.

Publisher side (crates/node)

  • Bootstrap path. On cold start, group cached blobs by argmin_receiver and send one BatchStoreRequest per receiver per scheduler tick instead of per-blob STOREs.
  • Steady-state re-publish. When the scheduler fires for multiple blobs with overlapping receiver sets within a small window, opportunistically batch.
  • Negotiation. Try batched first; fall back to per-hash STORE if the receiver returns RATE_LIMITED or closes the stream without an ack (suggesting unknown-variant drop).

Constants

Parameter Value Rationale
Max hashes per batch 256 ~8 KB payload at 32B/hash; bounds per-batch work and wire size

Out of scope

  • FIND_VALUE batching. Different hashes have different K-closest sets, so lookups don't share peers. No useful opportunity.
  • FIND_NODE batching. Routing-table maintenance bandwidth is already negligible (~1.4 Kbps per node).
  • Batched ack pipelining. Each batch produces one ack; no need for streaming acks.

Acceptance criteria

  1. BatchStoreRequest and BatchStoreAck are valid DhtMessage variants with ≤256 hashes per request.
  2. Rate-limit accounting charges hashes.len() tokens per batch admission, not 1.
  3. Per-publisher quota and global eviction decisions are per-hash; the ack reports per-hash outcomes in request order.
  4. The publisher bootstrap path uses batched STORE by default; falls back to per-hash STORE on receiver RATE_LIMITED or unknown-variant stream close.
  5. Wire-bytes savings at bootstrap (C=10,000 cached blobs) is ≥40% versus per-hash STORE in handler integration tests.

References

Activity

  1. added
    kind:feature
    rust
    on May 21, 2026
  2. github-actions commented on May 21, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped protocol enhancement to add BatchStoreRequest/BatchStoreAck variants to DhtMessage (ADR 022), motivated by concrete wire-cost analysis in #629. The change spans crates/protocol (new wire types), crates/node (DHT handler + publisher bootstrap path), and integration tests verifying ≥40% bytes-on-wire savings. It is a backward-compatible extension under ADR 013's unknown-variant-drop guarantee.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature / Enhancement Protocol extension adding new capability (batched STORE RPC), not a bug fix
    Labels enhancement, rust, technical (existing) Pure Rust protocol + handler implementation; no ADR change needed
    Coding agent Suitable Requirements are fully specified: wire types with exact shapes, handler semantics (rate-limit token accounting, per-hash admission, partial ack), publisher bootstrap changes, fallback negotiation, and quantitative acceptance criteria

    🔗 Similar issues

    💡 Notes and suggestions

    Implementation checklist:

    • crates/protocol/src/message.rs — add BatchStoreRequest { hashes: Vec<Hash>, holder: NodeId } and BatchStoreAck { results: Vec<(Hash, bool)> } as new DhtMessage variants; add discriminant-locking tests per ADR 013
    • crates/node/src/handlers/dht.rs (or equivalent) — handle BatchStoreRequest: single auth check, consume hashes.len() rate-limit tokens at admission, per-hash quota/eviction, send BatchStoreAck with ordered results
    • Publisher bootstrap path — group blobs by argmin_receiver, send one BatchStoreRequest per receiver tick; fall back to per-hash STORE on RATE_LIMITED or missing ack
    • Steady-state scheduler — opportunistic batching when multiple blobs share a receiver within a scheduler window
    • Integration test asserting ≥40% bytes-on-wire reduction at C=10,000 blobs bootstrap

    Design notes:

    • The rate-limit fires once per batch (whole-batch accept/reject), so partial acceptance only happens at per-hash quota/eviction level — the ack still needs to carry per-hash outcomes.
    • The 256-hash cap (~8 KB payload) is well within typical QUIC stream limits; no special framing changes needed.
    • The fallback negotiation (unknown-variant stream close → retry per-hash) relies on ADR 013's unknown-variant guarantee already being implemented in the DHT handler.
    • Check crates/node/tests/probe_loopback.rs as the canonical pattern for the required loopback integration test.

    Generated by Agentic Triage for issue #630 · ● 1.6M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featurerust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions