Skip to content

feat(node): batch DHT re-publish by receiver; drop BatchStore fallback (#1616) - #1748

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1616-b98231
Aug 18, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1616-b98231

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1616.

Context

The BatchStore handler this issue describes (admission + two-stage rate-limit accounting) already shipped in PR #713 (closes #648) — the issue was filed from a stale reading of the code. The genuinely-missing pieces were:

  1. The outbound batch primitive (client::batch_store) + fallback cache were dead code (referenced only in tests) — nothing in production ever sent a BatchStore.
  2. The re-publish scheduler still fanned out one per-hash Store per (peer, hash) and never batched, even at cold-start where ADR 022 calls for it.

Key decision: BatchStore is mandatory in cdn/dht/v1

Every node ships discriminants 4/5 from day one, so no node speaks the DHT ALPN without implementing BatchStore. The "optional-with-fallback" framing was a version-negotiation shim for a peer that cannot exist pre-launch. Per the repo's pre-launch rule (no version negotiation; change the format and delete the old shape), this PR batches unconditionally and rips the shim out.

What changed

Wire batching into the re-publish scheduler (crates/node/src/dht/publish.rs)

  • New pure group_by_receiver inverts a drain cycle's due hashes into receiver → hashes (each hash's K+3 closest), unit-tested.
  • publish_batch sends one client::batch_store per receiver, split at the MAX_BATCH_STORE_HASHES (256) cap, one task per receiver.
  • The eager per-insert publish stays per-hash Store — a size-1 batch buys nothing.

Delete the fallback shim (−1054 lines)

  • Removed batch_fallback.rs (BatchStoreFallback), batch_store_with_fallback, classify_batch_error, per_hash_fallback, extract_app_error_code + downcast helpers, and the exchange_on reset-probing that existed only to feed them.
  • Kept the real feature: client::batch_store, client::store, and the whole receiver-side handler (handle_batch_store, admit_batch_extra).

ADR 022 + docstrings

  • BatchStore/BatchStoreAck are now documented as mandatory in cdn/dht/v1 (no fallback, no negotiation); rewrote §STORE Flow Batched STORE, §Schema Evolution, and AC 19 (was the fallback-cache requirement, now the publisher-side batching behavior).
  • Fixed the stale "handler deferred to a follow-up issue" docstrings in crates/protocol/src/dht.rs.

Reviewer notes

  • The receiver still closes genuinely-unknown variants (discriminant ≥ 8, or a response on a server stream) with UNSUPPORTED_MESSAGE — that's unchanged. Only the sender-side treatment of UNSUPPORTED as "fall back to per-hash" is removed.
  • No wire-format change: BatchStore/BatchStoreAck already occupied discriminants 4/5.

Verification

  • cargo fmt --check, cargo clippy --all-targets — clean (all pre-commit hooks passed)
  • cargo nextest run -p decdn-protocol -p decdn-node — 1009 passed, 0 failed
  • cargo test --no-run -p decdn-e2e --features anvil-e2e — compiles
  • TDD: group_by_receiver written test-first (watched it fail, then pass)

🤖 Generated with Claude Code

#1616)

The BatchStore handler (admission + two-stage rate-limit accounting) already
shipped in #713. What was missing: the outbound batch primitive was dead code
(tests only) and the re-publish scheduler never batched.

BatchStore is mandatory in cdn/dht/v1 — every node ships discriminants 4/5 from
day one — so the "optional-with-fallback" framing was a version-negotiation shim
for a peer that cannot exist pre-launch. Per the pre-launch rule (no version
negotiation; delete the old shape), rip it out and batch unconditionally.

- publish.rs: the periodic drain groups due hashes by receiver (each hash's K+3
  closest) and sends one client::batch_store per receiver, split at the 256-hash
  cap. Eager per-insert publish stays per-hash Store (a size-1 batch buys
  nothing). New pure group_by_receiver, unit-tested.
- Delete the fallback shim: batch_fallback.rs (BatchStoreFallback),
  batch_store_with_fallback, classify_batch_error, per_hash_fallback,
  extract_app_error_code + downcast helpers, and the exchange_on reset-probing
  that only fed them. Keep client::batch_store, client::store, and the whole
  receiver-side handler.
- ADR 022: BatchStore/BatchStoreAck are mandatory in cdn/dht/v1 (no fallback, no
  negotiation); rewrite §STORE Flow Batched STORE, §Schema Evolution, and AC 19.
  Fix the stale "handler deferred to a follow-up issue" docstrings in
  protocol/src/dht.rs.

Net -1054/+210. cargo fmt/clippy clean; nextest 1009 passed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 18, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes DHT BatchStore adoption end-to-end by wiring unconditional publisher-side batching into the node republish scheduler and deleting the now-unneeded “optional batching + per-hash fallback” shim. It aligns the implementation and docs/ADR 022 with the repo’s pre-launch rule (no version-negotiation shims): BatchStore is treated as mandatory for cdn/dht/v1.

Changes:

  • Implement receiver-grouped republish batching (group_by_receiver + publish_batch) so periodic republish sends one BatchStore (split to 256) per receiver instead of per-hash fanout.
  • Remove publisher-side fallback machinery (BatchStoreFallback, batch_store_with_fallback, per-hash fallback helpers) and associated tests/exports.
  • Update protocol docs and ADR 022 to reflect BatchStore as mandatory and specify publisher-side batching behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/node/src/dht/publish.rs Implements receiver-grouped batching for periodic republish and adds unit tests for grouping logic.
crates/node/src/dht/client.rs Removes fallback/negotiation helpers; positions batch_store as the mandatory primitive used by republish batching.
crates/node/src/dht/mod.rs Drops batch_fallback module and re-exports.
crates/node/src/dht/batch_fallback.rs Deletes the fallback cache implementation (no longer needed with mandatory batching).
crates/node/tests/dht_loopback.rs Removes fallback-negotiation integration tests; keeps loopback coverage for the batch_store primitive.
crates/protocol/src/dht.rs Updates BatchStore/BatchStoreAck documentation to match mandatory support and new scheduler behavior.
adr/022-content-discovery.md Updates STORE flow and acceptance criteria to require publisher-side batching and remove fallback negotiation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/dht/client.rs Resolved
Comment thread crates/node/src/dht/publish.rs Resolved
@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.64% (was 80.72%, ▼ 0.07%) — 58015/71941 lines

File Coverage Lines Δ
crates/node/src/dht/batch_fallback.rs — — deleted
crates/node/src/dht/client.rs 74.80% 92/123 ▼ 2.16%
crates/node/src/dht/publish.rs 73.53% 250/340 ▼ 12.36%
crates/protocol/src/dht.rs 99.01% 399/403 ● 0.00%
History
Commit Total Δ vs base
533abb9 80.65% ▼ 0.07%
e503aaf (HEAD) 80.64% ▼ 0.07%

…e select loop

Address PR review:
- client::batch_store now errors on a BatchStoreAck whose results length
  doesn't match the request, instead of silently returning a vector that
  mis-maps onto the request hashes. The deleted fallback wrapper used to
  guard this; the primitive is now called directly, so it must guard itself.
- The periodic republish drain reschedules the held hashes, then fires the
  batched publish on a detached task rather than awaiting it inside the
  run_republish select loop. A slow/unreachable receiver could otherwise hold
  the loop for up to (chunks × DHT_CLIENT_TIMEOUT), delaying the shutdown
  signal and eager cache-insert publishes. The sweep is best-effort —
  abandoned on shutdown, retried next cycle.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 58aaa97 into main Aug 18, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1616-b98231 branch August 18, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DHT BatchStore handler: admission + two-stage rate-limit accounting DHT: implement BatchStore handler-side admission (ACs 17-20 of ADR 022)

2 participants