Repository navigation
Description
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 NodeIdonce 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.
resultscarries per-hash outcome. Quota-exhausted entries returnaccepted: 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_receiverand send oneBatchStoreRequestper 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_LIMITEDor 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
BatchStoreRequestandBatchStoreAckare validDhtMessagevariants with≤256hashes per request.- Rate-limit accounting charges
hashes.len()tokens per batch admission, not 1. - Per-publisher quota and global eviction decisions are per-hash; the ack reports per-hash outcomes in request order.
- The publisher bootstrap path uses batched STORE by default; falls back to per-hash STORE on receiver
RATE_LIMITEDor unknown-variant stream close. - Wire-bytes savings at bootstrap (C=10,000 cached blobs) is ≥40% versus per-hash STORE in handler integration tests.
References
- ADR 022 — DHT bandwidth analysis, cold-start re-publish jitter, motivate batched STORE #629 (DHT bandwidth analysis — motivates this work)
- ADR 022 § Message Types
- ADR 022 § DHT Rate Limiting
- ADR 013 § Schema Evolution
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
github-actions commentedon May 21, 2026
🎯 Triage report
This is a well-scoped protocol enhancement to add
BatchStoreRequest/BatchStoreAckvariants toDhtMessage(ADR 022), motivated by concrete wire-cost analysis in #629. The change spanscrates/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
enhancement,rust,technical(existing)🔗 Similar issues
💡 Notes and suggestions
Implementation checklist:
crates/protocol/src/message.rs— addBatchStoreRequest { hashes: Vec<Hash>, holder: NodeId }andBatchStoreAck { results: Vec<(Hash, bool)> }as newDhtMessagevariants; add discriminant-locking tests per ADR 013crates/node/src/handlers/dht.rs(or equivalent) — handleBatchStoreRequest: single auth check, consumehashes.len()rate-limit tokens at admission, per-hash quota/eviction, sendBatchStoreAckwith ordered resultsargmin_receiver, send oneBatchStoreRequestper receiver tick; fall back to per-hash STORE onRATE_LIMITEDor missing ackDesign notes:
crates/node/tests/probe_loopback.rsas the canonical pattern for the required loopback integration test.refactor(node): bound per-hash fallback wall-clock + cap batch-fallba…
feat(node): implement DHT BatchStore handler-side admission (closes #648