Repository navigation
feat(payments): group-commit voucher fsyncs, ack after commit (#1483) - #1487
alpergundogdu wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Code reviewOne non-blocking item — comment accuracy / consistency. The group-commit core (batch supersession, commit-before-ack durability, whole-batch Takedown check: comment says "once per committed batch" but it runs on every non-done iteration, and it now diverges from decdn/crates/node/src/handlers/client/delivery.rs Lines 199 to 209 in 650444d To be clear, this is not a correctness regression: whenever decdn/crates/node/src/handlers/client/window.rs Lines 442 to 486 in 650444d Suggest: fix the comment (or re-nest the check under the batch block) so 🤖 Generated with Claude Code |
|
Fixed in d18f971: restored the 🤖 Addressed by Claude Code |
f25367a to
6d23558
Compare
Amortise the per-voucher fsynced redb commit (~3.18 ms/voucher on local SSD, Durability::Immediate) across a batch of vouchers instead of one fsync each. Before this, a single channel caps at ~313 MiB/s at a 1 MiB interval because vouchers serialize on the per-channel mutex and each pays one fsync. Group commit with the ack sent AFTER the commit returns (Option A). Nothing is ever acked before it is durable, so ADR 003 §Off-chain voucher state persistence stands verbatim — no ADR amendment, no new replay exposure. Builds on #1477's credit window, which takes the delayed ack off the delivery critical path. Mechanism (stacked on #1477's seam): - crates/incentive: `ChannelState::stage_voucher` validates + advances a candidate WITHOUT persisting; `apply_voucher` is refactored to stage + record + swap. Because vouchers are cumulative, the final staged state supersedes every intermediate one, so one `store.record` commits the whole batch (one fsync) — no new store method is needed. - crates/node handlers/client: `collect_voucher_batch` gathers up to `credit_window / interval` vouchers (first read blocking to preserve the park-awaiting-voucher semantics; the rest under a bounded commit interval via a cancellation-safe `BufferedVoucherReader`), verifies each against the advancing candidate, commits the prefix once, then writes one VoucherAck per voucher. A failed commit fails the WHOLE batch → RetryLater, no acks, state unchanged (ADR 003 §355). A mid-batch verify rejection commits the valid prefix first, then rejects. Both the buffered (`deliver`) and window pull-through (`window_forward_loop`) loops use the shared batched recoup, gating the ADR 011 takedown check on `collected_any` so the two read symmetrically; stop-and-wait (window = one interval) collapses to one voucher per commit exactly as before. - crates/protocol: `parse_frame` (sync, non-consuming) backs the cancellation-safe buffered reader that `read_frame`'s `read_exact` cannot. - config: `payment.voucher_commit_interval_ms` (default 5 ms) is the governable commit interval, documented with the sizing constraint `credit_window >= throughput * (RTT + commit_interval)`. Keeps Durability::Immediate on the batched commit. TDD: batched-throughput test (8 vouchers → 1 record, proven to fail without batching) and a crash/rollback test (failed commit → RetryLater, zero acks, watermark unchanged), plus incentive-level staging tests. Closes #1483 Co-Authored-By: Claude Opus 4.8 <[email protected]>
d18f971 to
0f60522
Compare
|
Auto-closed when the base branch 🤖 Addressed by Claude Code |
Stacked on #1477 (base branch
claude/upbeat-babbage-dd8661). Review/merge that first; this PR's diff is only the group-commit work.What
Amortise the per-voucher fsynced redb commit (measured 3.18 ms/voucher on local SSD,
Durability::Immediate) across a batch of vouchers instead of one fsync each. Today a single channel caps at ~313 MiB/s at a 1 MiB interval because vouchers serialize on the per-channel mutex and each pays one fsync.Plan: group commit, ack AFTER the commit returns (Option A). Nothing is ever acked before it is durable, so ADR 003 §Off-chain voucher state persistence stands verbatim — no ADR amendment, no new replay exposure. This builds on #1477's credit window, which takes the delayed ack off the delivery critical path (ADR 003 line 103 already anticipates this batching).
How
crates/incentive—ChannelState::stage_vouchervalidates + advances a candidate without persisting;apply_voucheris refactored to stage → record → swap (behaviour identical). Because vouchers are cumulative, the final staged state supersedes every intermediate one, so onestore.recordcommits the whole batch (one fsync) — no newChannelStateStoremethod is needed.crates/nodehandlers/client —collect_voucher_batchgathers up tocredit_window / intervalvouchers: the first read blocks (preserving the park-awaiting-voucher semantics), the rest under a bounded commit interval via a cancellation-safeBufferedVoucherReader. It verifies each against the advancing candidate, commits the prefix once, then writes oneVoucherAckper voucher. A failed commit fails the WHOLE batch →RetryLater, no acks, state unchanged (ADR 003 §355). A mid-batch verify rejection commits the valid prefix first, then rejects — faithful to the pre-batch per-voucher order. Both the buffered (deliver) and window pull-through (window_forward_loop) loops share the batched recoup; stop-and-wait (window = one interval) collapses to one voucher per commit exactly as before.crates/protocol—parse_frame(sync, non-consuming) backs the cancellation-safe reader thatread_frame'sread_exactcannot survive a gather timeout.payment.voucher_commit_interval_ms(default 5 ms) is the governable commit interval, documented with the sizing constraintcredit_window >= throughput * (RTT + commit_interval).Durability::Immediateis kept on the (now batched) commit — durability is not weakened anywhere.Tests (TDD)
group_commit_amortises_the_fsync_across_a_batch— 8 cumulative vouchers commit with exactly 1record; verified to FAIL under forced stop-and-wait.group_commit_failure_rejects_whole_batch_with_retry_later— failed commit → oneRetryLater, zero acks, watermark unchanged.stage_voucherstaging tests (batch == sequential; rejection leaves candidate untouched); protocolparse_frametests.cargo nextest run -p decdn-node -p decdn-incentive(1143 + incentive passing),cargo clippy --all-targets,cargo fmt --check, andcargo doc -D warningsall clean.Closes #1483
🤖 Generated with Claude Code