Repository navigation
Description
Follow-up to #1477, which measured the per-voucher fsynced redb commit at 3.18 ms on local SSD (5-20 ms typical on cloud network storage). Even with the credit-window pipelining proposed there, this caps a channel at ~313 MiB/s at a 1 MiB voucher interval: vouchers are serialized by the per-channel mutex and each pays one fsync.
Decision: group commit with the ack sent after the commit. Durability is unchanged; ADR 003 stands as written. The alternative — acking on in-memory validation and committing on a lag — was considered and rejected; it is recorded at the bottom.
Parallelising is not the available lever
redb permits one write transaction at a time per Database, and all seller channel state lives in a single channels.redb (crates/node/src/channel_store.rs). Commits serialize by construction — there is nothing to run in parallel.
Sharding channels across several redb files would allow concurrent commits, but it is a much larger change (redb forbids two Database handles per file, so it means a real sharding layer) for less benefit than batching. Not recommended.
Group commit is the mechanism: one fsync covering many vouchers, amortising the 3.18 ms across the batch.
What the fsync protects
Not just lost revenue on crash. Per ADR 003 §Off-chain voucher state persistence:
a node MUST persist
(last_nonce, last_amount, last_bytes_delivered)per channel and durably commit (fsync, on disk-backed implementations) before sendingVoucherAckor delivering any further bytes for that voucher.
A node that restarts at a stale watermark will re-accept an earlier-nonce voucher that the client — or any wire observer who captured it — resubmits, and serve the bytes a second time for free.
The plan: group commit, ack after commit
Batch vouchers into one fsync; send VoucherAck for the whole batch after the commit returns.
This works because of #1477: once delivery is pipelined behind a credit window, the ack is no longer on the critical path, so delaying it by one commit interval costs nothing in throughput — it consumes credit-window headroom instead. Nothing is ever acked before it is durable.
- ADR 003 preserved verbatim. No protocol change, no ADR amendment.
- No new replay exposure. Crash risk is unchanged from today.
- Server exposure stays exactly the credit window from Paid delivery is stop-and-wait per voucher: throughput is RTT-bound, not link-bound #1477.
- Sizing constraint:
credit_window ≥ throughput × (RTT + commit_interval), so the commit interval spends window headroom. At an 8 MiB window / 50 ms RTT, a 10-20 ms commit interval is comfortable. - A failed commit fails the whole batch — every voucher in it must get
RetryLaterrather than an ack, preserving the existing ADR 003 §355 semantics.
Depends on #1477 landing first. Without the credit window, delaying the ack by a commit interval makes the stall worse, not better.
Rejected: batch with immediate ack
Ack on in-memory validation, commit asynchronously on a bounded lag.
Faster to build and independent of #1477, but it accepts a bounded replay window: on crash, up to the batch lag in bytes can be re-served free. It would require an ADR 003 amendment, since the current text is a MUST — a protocol rule change, not an implementation detail.
Rejected because the ack-after-commit plan reaches the same throughput without spending either the ADR change or the exposure. Revisit only if the commit interval measures as still gating throughput after #1477 and this issue have landed.
Metadata
Metadata
Assignees
Type
Fields
Priority
Activity
[-]Group-commit voucher fsyncs: amortise the 3.18 ms per-voucher commit that caps a channel at ~313 MiB/s[/-][+]Group-commit voucher fsyncs (ack after commit): amortise the 3.18 ms per-voucher commit[/+]alpergundogdu commentedon Jul 28, 2026
Decision (team, 2026-07-28): going with Option A — group commit, ack after commit. Durability unchanged, no ADR 003 amendment. The ack-then-commit variant is recorded in the body as rejected. Sequenced after #1477.
feat(payments): credit-window pipelined paid delivery (#1477)
refactor(payments): gate delivery.rs takedown check on collected_any (#…
feat(payments): credit-window pipelined paid delivery (#1477)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)
feat(payments): credit-window pipelined paid delivery (#1477) (#1485)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)
feat(payments): group-commit voucher fsyncs, ack after commit (#1483)