Repository navigation
feat(payments): group-commit voucher fsyncs, ack after commit (#1483) - #1490
Conversation
|
Warning Review limit reached
Next review available in: 57 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (15)
WalkthroughAdds a configurable voucher group-commit interval, stages voucher state in memory before durable persistence, buffers cancellable frame reads, batches delivery recoup, and validates successful and failed batch commits through configuration, unit, and loopback tests. ChangesVoucher group-commit flow
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ClientHandler
participant ChannelState
participant ChannelStateStore
Client->>ClientHandler: send cumulative voucher burst
ClientHandler->>ChannelState: stage each voucher
ClientHandler->>ChannelStateStore: record final staged state
ChannelStateStore-->>ClientHandler: commit success or failure
ClientHandler-->>Client: acknowledgements or RetryLater rejection
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 |
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]>
ec5910a to
f74776b
Compare
Coverage reportTotal: 81.29% (was 81.24%, ▲ +0.05%) — 53206/65450 lines
History
|
Supersedes #1487 (auto-closed when its base branch
claude/upbeat-babbage-dd8661was deleted by #1485's merge). Now rebased directly ontomain(which contains #1477 via #1485). No content change from #1487's approved state.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. Builds on #1477's credit window, which takes the delayed ack off the delivery critical path.
How
crates/incentive—ChannelState::stage_vouchervalidates + advances a candidate without persisting;apply_voucherrefactored to stage → record → swap. Because vouchers are cumulative, the final staged state supersedes every intermediate one, so onestore.recordcommits the whole batch (one fsync) — no newChannelStateStoremethod needed.crates/nodehandlers/client —collect_voucher_batchgathers up tocredit_window / intervalvouchers (first read blocking to preserve park-awaiting-voucher; the rest under a bounded commit interval via a cancellation-safeBufferedVoucherReader), verifies each against the advancing candidate, commits the prefix once, then acks each. A failed commit fails the WHOLE batch →RetryLater, no acks, state unchanged (ADR 003 §355). Mid-batch verify rejection commits the valid prefix first. Both the buffered (deliver) and window pull-through (window_forward_loop) loops share the batched recoup, gating the ADR 011 takedown check oncollected_anyso 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 reader thatread_frame'sread_exactcannot survive a gather timeout.payment.voucher_commit_interval_ms(default 5 ms), documented with the sizing constraintcredit_window >= throughput * (RTT + commit_interval).Durability::Immediateis kept on the batched commit.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; protocolparse_frametests.Closes #1483
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes