Skip to content

Debounce watcher checkpoint writes to cut fsync amplification on backlog drain (#751 follow-up) #784

Closed

Description

@thiras

Follow-up from the #751 seller-settlement robustness review (PR #781, Alper's MEDIUM-3).

Problem

ChannelStateStoreImpl::record_last_seen_block (crates/node/src/channel_store.rs) commits with Durability::Immediate, so every distinct new block carrying a provider-owned ChannelOpened triggers a synchronous fsynced commit. Draining a backlog after a resubscribe over a busy range fsyncs once per block, and for a popular provider that's a steady fsync/block in steady state too.

Why it's safe to debounce

The persisted checkpoint is only a floor for the resume backfill:

  • The resume backfill rounds the checkpoint down by REORG_MARGIN_BLOCKS (resolve_backfill_start), and
  • register_open_channel is idempotent.

So the persisted value is safe to advance coarsely — a checkpoint that lags the true scan position by a bounded amount only widens the next rescan, never narrows it (the WatcherCheckpointStore contract). Losing the most-recent few blocks of checkpoint progress on a crash just re-scans them.

Proposed fix

Debounce the checkpoint write to a coarser cadence — e.g. flush at most every N seconds or every N blocks (whichever first), and force a final flush on graceful shutdown. Keeps the durability contract (the stored value is always a valid, monotonic floor) while cutting write amplification on high-fan-out nodes.

Priority

Low at the testnet target (tens of nodes). Worth doing before a high-fan-out production provider. In-code pointer: see the doc note on MAX fsync in record_last_seen_block and advance_checkpoint.

Activity

  1. added
    kind:feature
    on Jun 2, 2026
  2. added a commit that references this issue on Jun 2, 2026
  3. added
    prio:low
    rust
    on Jun 2, 2026
  4. github-actions commented on Jun 2, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped performance optimization follow-up from the #751 seller-settlement review (PR #781, MEDIUM-3). The issue identifies that ChannelStateStoreImpl::record_last_seen_block issues a synchronous Durability::Immediate commit on every new block, causing fsync-per-block write amplification during backlog drains and on busy provider nodes. The fix is safe because the checkpoint is a monotonic floor and the backfill is idempotent — debouncing only widens the next rescan, never skips events.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Clear optimization with well-understood safety argument; no design ambiguity
    Labels technical, low, rust, prod-blocking Performance/implementation concern in Rust node crate; low priority at PoC/testnet scale, meaningful before high-fan-out production
    Coding agent Suitable Precise file pointer (crates/node/src/channel_store.rs), well-reasoned durability invariant, clear success criteria (debounce by N seconds/blocks + flush on graceful shutdown)
    💡 Notes and suggestions

    Implementation sketch:

    1. Add a last_flushed_block: AtomicU64 (or equivalent behind a Mutex) and a last_flushed_instant: Instant to ChannelStateStoreImpl.
    2. In record_last_seen_block, buffer the new value in memory and only call commit(Durability::Immediate) when either:
      • current_block - last_flushed_block >= N (block-count threshold), or
      • Instant::now() - last_flushed_instant >= T (time threshold).
    3. Add a flush_checkpoint() method (called from Drop impl or a graceful-shutdown hook in the node crate) that forces Durability::Immediate regardless of thresholds.
    4. Reasonable defaults to bikeshed: N = 100 blocks, T = 30 s (or make them config fields in ChannelStoreConfig).

    Invariant to preserve: The stored value must never exceed the highest block for which register_open_channel has already been called — i.e., only advance the checkpoint after successfully processing the block, not speculatively. The current per-block flush already guarantees this; the debounced version must too (buffer the in-memory high-water mark separately from the persisted one).

    Edge case: on a crash between flushes the node re-scans [stored_checkpoint - REORG_MARGIN_BLOCKS, head]. With N=100 that's at most 100 + REORG_MARGIN_BLOCKS extra blocks on recovery — confirm this is acceptable for the target block time (Arbitrum ~0.25 s/block → ~25 s of rescan at N=100).

    Test: add a unit test asserting that record_last_seen_block called N−1 times does not call the underlying store's commit, and the N-th call (or a flush_checkpoint()) does.

    Generated by Agentic Triage for issue #784 · sonnet46 470.8K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featureprio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions