You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Debounce watcher checkpoint writes to cut fsync amplification on backlog drain (#751 follow-up) #784
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
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.
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:
Add a last_flushed_block: AtomicU64 (or equivalent behind a Mutex) and a last_flushed_instant: Instant to ChannelStateStoreImpl.
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).
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.
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.
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
Activity
fix(node): address PR #781 review (Alper) — watcher recovery + doc ac…
github-actions commentedon Jun 2, 2026
🎯 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_blockissues a synchronousDurability::Immediatecommit 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
technical,low,rust,prod-blockingcrates/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:
last_flushed_block: AtomicU64(or equivalent behind aMutex) and alast_flushed_instant: InstanttoChannelStateStoreImpl.record_last_seen_block, buffer the new value in memory and only callcommit(Durability::Immediate)when either:current_block - last_flushed_block >= N(block-count threshold), orInstant::now() - last_flushed_instant >= T(time threshold).flush_checkpoint()method (called fromDropimpl or a graceful-shutdown hook in thenodecrate) that forcesDurability::Immediateregardless of thresholds.N = 100 blocks,T = 30 s(or make them config fields inChannelStoreConfig).Invariant to preserve: The stored value must never exceed the highest block for which
register_open_channelhas 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]. WithN=100that's at most 100 +REORG_MARGIN_BLOCKSextra blocks on recovery — confirm this is acceptable for the target block time (Arbitrum ~0.25 s/block → ~25 s of rescan atN=100).Test: add a unit test asserting that
record_last_seen_blockcalled N−1 times does not call the underlying store'scommit, and the N-th call (or aflush_checkpoint()) does.Add this agentic workflows to your repo
To install this agentic workflow, run
feat(node): seller-settlement robustness follow-ups (#751) (#781)
fix(node): debounce watcher checkpoint writes (#784) (#792)