Repository navigation
Closed
Copy link
Labels
rustDependabot: a Cargo update; use area: labels for Rust code otherwise
Description
Context
PR #642 (now landed in the #320 stack) defined the BatchStoreRequest / BatchStoreAck wire types at their ADR-022 canonical discriminants (4 and 5) so the wire format wouldn't need a future shuffle. The handler-side admission was deferred: today the handler rejects BatchStore requests with APP_ERR_UNSUPPORTED_MESSAGE (`0x01`) so publishers fall back to per-hash `Store` per ADR 022 §Schema Evolution.
This issue is to implement the handler-side admission so publishers can use the bandwidth optimization at scale (ADR 022 §DHT Bandwidth Analysis: ~80% wire-bytes reduction at `C ≥ 10k` cached blobs).
Acceptance criteria (ACs 17-20 from issue #320)
- AC 17 — `BatchStoreRequest { n ≤ 256 hashes }` from publisher P produces `BatchStoreAck { results }` with one bool per request hash in request order. The batch-level `holder` is checked once against the authenticated QUIC NodeId; the remaining admission decisions (rate limit, per-publisher quota with two-tier eviction, active-staker check) are applied per-hash and match those of `n` separate `StoreRequest` RPCs.
- AC 18 — A `BatchStoreRequest` consumes between 1 and `n` tokens from each rate-limit bucket: stage 1 charges 1 token before deserialization; stage 2 charges up to `n-1` more after reading `n = hashes.len()`, bounded by remaining budget. The first `k` admitted hashes pass per-hash processing; the remaining `n-k` are marked `false` in the ack without further processing.
- AC 19 — A `BatchStoreRequest` with `hashes.len() > 256` is rejected by closing the stream with `MALFORMED_MESSAGE` (`0x03`); the publisher MUST split larger publish sets across multiple batches.
- AC 20 — A publisher whose `BatchStoreRequest` to a given receiver results in stream-close-without-ack MUST fall back to per-hash `StoreRequest` for subsequent publications to that receiver; the publisher SHOULD cache the negative result for some bounded duration to avoid repeated drop-and-fallback cycles.
Implementation notes
- The handler's `read_dht_request` currently has a dedicated arm for `BatchStore` that rejects with `APP_ERR_UNSUPPORTED_MESSAGE`. Replace it with a real handler that routes `BatchStore` through the existing `RecordStore::insert_at` per-hash with shared receiver-anchored `receive_us`.
- Two-stage rate-limit accounting needs a new method on `DhtRateLimiter` that consumes up to `n` tokens with a partial-admit signal.
- Publisher-side fallback negotiation needs a new outbound `client::batch_store` primitive and a small per-receiver `unsupported_until` cache.
References
- ADR 022 §STORE Flow (BatchStore + two-stage rate-limit accounting): `adr/022-content-discovery.md`
- Wire types: `crates/protocol/src/dht.rs` (`BatchStoreRequest` / `BatchStoreAck`, `MAX_BATCH_STORE_HASHES`)
- Current handler arm: `crates/node/src/handlers/dht.rs::read_dht_request` (BatchStore → `APP_ERR_UNSUPPORTED_MESSAGE`)
Tracks the BatchStore split-out from #320.
Activity
github-actions commentedon May 21, 2026
🎯 Triage report
This issue tracks the handler-side implementation of
BatchStoreadmission in the DHT ALPN handler, split out from the parent #320 tracking issue. The wire types (BatchStoreRequest/BatchStoreAck) are already defined (landed in PR #642), but the handler currently short-circuits withAPP_ERR_UNSUPPORTED_MESSAGE. Full implementation requires three distinct pieces: handler admission logic, two-stage rate-limit accounting onDhtRateLimiter, and a publisher-side fallback cache.📊 Assessment
technical,poc-blocking,rustcrates/nodeandcrates/protocolwith no unresolved design questions🔗 Similar issues
DhtRateLimitertwo-stage method needed by AC 18 will need to be consistent with that workbatch_storeclient primitive💡 Notes and suggestions
Implementation decomposition:
crates/node/src/handlers/dht.rs): Replace theBatchStore → APP_ERR_UNSUPPORTED_MESSAGEarm with real logic. Validatehashes.len() ≤ 256(returnMALFORMED_MESSAGE0x03 on violation per AC 19). Checkholderonce against the authenticated QUIC NodeId. Loop over hashes callingRecordStore::insert_atwith a sharedreceive_ustimestamp; collect per-hash bool results intoBatchStoreAck.DhtRateLimiter): New methodadmit_batch(n) -> (admitted: usize, remaining_budget: usize). Stage 1 deducts 1 token before deserialization. Stage 2 deducts up ton-1more after reading the hash count; firstkhashes proceed, rest are false in the ack (AC 18). Coordinate with cdn/dht/v1 DoS hardening — per-publisher quota, DHT rate limit, lookup invariants #625 to ensure the quota semantics stay consistent.client::batch_store): New outbound primitive that sendsBatchStoreRequestand handles stream-close-without-ack by populating anunsupported_until: HashMap<NodeId, Instant>cache. When a node is in the unsupported window, the publisher falls back to individualStoreRequestRPCs (AC 20). Cache expiry should be bounded (e.g., 5–30 min configurable).Key invariant to verify: The
receive_ustimestamp used for the whole batch must be anchored to the receiver's clock at the time of theBatchStoreRequestarrival, not per-hash insertion time — this prevents a batch from having internally inconsistent TTLs.Watch out for anti-panic policy: All slice indexing into the hashes vec must use
.get()or iterators — directhashes[i]will fail clippy'sindexing_slicingdeny.feat(node): implement DHT BatchStore handler-side admission (closes #648