Skip to content

Group-commit voucher fsyncs (ack after commit): amortise the 3.18 ms per-voucher commit #1483

Closed

Description

@alpergundogdu

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 sending VoucherAck or 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 RetryLater rather 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.

Activity

  1. added
    prio:high
    rust
    on Jul 28, 2026
  2. changed the title [-]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[/+] on Jul 28, 2026
  3. alpergundogdu commented on Jul 28, 2026

    @alpergundogdu
    ContributorAuthor

    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.

  4. added this to the v0.1 milestone on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:highrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions