Repository navigation
fix(node): count a resolved pool's on-chain redemptions toward its remaining deposit - #2709
Merged
Merged
Conversation
…maining deposit After a restart the pool projection is empty, so the admit path seeds a pool it has not folded from one `getPool`. The seed set `total_redeemed` to zero, so a pool drained before the restart reported its whole deposit as `remaining` for the rest of the node's uptime, and the admission solvency gate and the mid-stream re-check served it unpaid (GHSA-9x5g-h559-vp5m). The seed now carries `getPool.totalRedeemed` as an unanchored snapshot, and the settlement sink's `on_tick_complete` re-reads each unanchored pool at one pinned block (`reanchor_pools`, at most 64 pools per tick). `PoolRedeemed` folds take the log's block: an advance above the anchor on a lane with a folded baseline adds to the snapshot, an event at or below the anchor only sets baselines, and an advance on a lane with no baseline drops the anchor for the next re-read. `remaining` subtracts the larger of the lane fold and the snapshot, both lower bounds on `totalRedeemed`, so it never counts a redemption twice and errs only toward serving until the next clean tick. `record_opened` / `record_topup` keep the highest deposit, so a replayed older log never lowers a newer read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Critical re-anchoring flaws can restore drained pools’ spendable balances, stall the shared poller for minutes, and indefinitely starve later pending pools of refreshes.
3 open issues
What changed in this PR
This PR addresses incorrect pool balances after node restarts by including on-chain redemptions in resolved pool snapshots used for admission and mid-stream solvency checks.
Changes:
- Seed resolved pools with
totalRedeemedand fold redemption events relative to snapshot anchors. - Re-anchor pending pools through bounded-count watcher reads and preserve the highest observed deposit.
- Add regression tests and document the security fix.
| File | Description |
|---|---|
crates/node/src/pool_view/tests.rs |
Tests snapshot accounting, replay handling, and deposit monotonicity. |
crates/node/src/pool_view.rs |
Adds redemption snapshots and block-aware accounting. |
crates/node/src/payment_settlement/tests.rs |
Tests admission seeds and re-anchor outcomes. |
crates/node/src/payment_settlement.rs |
Seeds on-chain totals and adds end-of-tick re-anchoring. |
crates/node/src/handlers/client/tests.rs |
Updates redemption calls for the block parameter. |
CHANGELOG.md |
Documents the restart-related solvency fix. |
Review effort: Balanced
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 4 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
- A redemption the snapshot cannot place marks it stale instead of clearing the anchor, so advances on baselined lanes above the old anchor keep counting until the re-read lands. A replayed `PoolRedeemed` with no block marks it stale only when a lane advances. - `reanchor_pools` reads at most eight pools at once, stops at the first fault, and rotates its start through a cursor so pools past the 64-pool cap get their turn. A pool absent at the pinned block stays pending instead of being forgotten; only a `Closed` read forgets it. - `PoolProjection::reanchor` applies a whole tick's reads in one publish. - Event-opened pools take `PoolOpened` / `PoolToppedUp` deposits as absolute values again, so a reorg can lower them. A snapshot-seeded pool skips a top-up its read already holds, takes one above the read as absolute, and only raises its deposit for one it cannot order; `folded_through` counts top-ups, so a re-read from a lagging backend never lowers the deposit. - Docs no longer call the sink the projection's only writer, and the CHANGELOG names the reorg over-count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Review pass (
Left as is:
|
- `PoolProjection::reanchor` skips a read whose `totalRedeemed` or deposit is below what the entry already holds, and the pool stays pending. Both only rise on chain, so such a read comes from a backend behind the admit read, whose block the `folded_through` guard cannot see. A drained seed with no folded lane no longer anchors at an older zero. - A faulted read moves the re-anchor cursor too, so a pool whose read keeps failing cannot hold back the pools behind it. - Re-anchor RPCs are bounded by a 3 s `REANCHOR_RPC_TIMEOUT`, so a hung endpoint holds the shared poller for at most two of them per tick. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The settlement sink records the highest block of any log it applied, a pool it did not hold yet included, and `reanchor_pools` skips a tick whose block number is below it. A redemption the watcher dropped while the pool was absent never reaches the entry's `folded_through`, so a read pinned below it would anchor without it and leave `remaining` high for good. - `record_resolved` takes a `PoolRead`, so the admit seed and the re-anchor share one input and `deposit` / `total_redeemed` cannot be swapped. `reanchor` sets every `Snapshot` field explicitly. - Docs: `deposit` is the latest folded value, not a maximum; a reorg-dropped redemption stays counted until on-chain `totalRedeemed` passes it, not until the next re-read; the projection has more than one writer; `forget` and the module doc name the re-anchor's `Closed` drop; the skip and timeout docs say what the code does. - Tests: the block guard, the `since` reset, an unordered top-up on a snapshot pool, a `Closing` read, a fault after a good read, and a block behind the watcher each have a test that fails without their rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closed
9 tasks
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Fixes GHSA-9x5g-h559-vp5m (H2 in the internal audit).
After a restart the node's pool projection is empty, and the settlement watcher resumes at a rewound checkpoint. A pool opened earlier therefore reaches the serve path through
ResolvingPoolView::resolve, which reads it with onegetPool.record_resolvedseeded that pool withtotal_redeemed = 0, so a pool drained before the restart reported its whole deposit asremainingfor the rest of the node's uptime. The admission solvency gate and the mid-streampool_funds_committedre-check then served it unpaid.Seeding
totalRedeemedalone is not enough. It would double-count: a long-lived lane's firstPoolRedeemedafter the seed has no per-lane baseline, so its whole cumulative would be counted again on top of the read. A watcher catching up from an old checkpoint also folds events the read already holds.The fix makes the seed a snapshot and keeps it exact:
Seed.
record_resolvedstoresgetPool.totalRedeemedas an unanchoredSnapshot. A drained pool readsremaining = 0from its first admission.Re-anchor. The settlement sink's
on_tick_complete(reanchor_pools) reads every pending pool at one pinned block and anchors it there in a single publish:REANCHOR_RPC_TIMEOUT, and the first fault stops the batch. A hung endpoint holds the shared poller for about 6 s per tick, and the watcher never goes into backoff. A faulted pool still moves the cursor, so it cannot hold back the pools behind it;Closedis forgotten. One absent at the pinned block stays pending, as does one whose read reports atotalRedeemedor deposit below what the entry already holds. Both values only rise on chain, so such a read comes from a backend behind the admit read.Fold.
PoolRedeemedfolds now take the log's block number:remaining. It subtracts the larger of the lane fold andsnapshot.redeemed + since. Both are lower bounds on on-chaintotalRedeemed, so no redemption counts twice andremainingerrs only toward serving, until the next clean tick.Deposit. An event-opened pool takes deposits as absolute values, as before, so a reorg can still lower them. A snapshot pool:
folded_throughcovers top-ups too, so a re-read from a lagging backend never lowers the deposit.Reviewer notes
pool_view.rsfirst: theSnapshotdoc,record_redeemed,reanchor, thenPoolEntry::status. Then readreanchor_poolsinpayment_settlement.rs.getPool. The extra reads happen in the watcher, once per seeded pool, and again only after a redemption on a lane the projection has no baseline for. Such a redemption costs the sender a transaction.totalRedeemedpasses it again, because the projection never rewinds a fold.warn!for faults,debug!for skips). Metrics would needadr/appendix-observability.mdrows and devops dashboards, so they are tracked in node: meter the settlement re-anchor path (pending pools, skipped and faulted re-reads) #2710.LogSink::on_tick_completetakes no head. That costs oneeth_blockNumberper tick, and only while pools are pending.signer_spenthas the same blind spot on resolved pools, so the mid-stream cap headroom fails open there. The admitgetAuthorizationread and the on-chainmin(cap − spent)are the backstops. I'll file a follow-up issue.record_resolved_rebuilds_remaining_without_double_countis deleted. It asserted the zero seed this PR fixes.Verification
pre-commiton the changed files (hook run at commit; cargo-deny reports the unrelated RUSTSEC-2026-0387crypto-bigintadvisory as a warning)cargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest run -p decdn-node: 1841 passed. The full workspace run is left to CI; onlydecdn-nodechanged.CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-itemsremainingfails 7 tests, including both admit-seed tests;replayed_redemptions_at_or_below_the_anchor_are_not_counted_again;a_stale_snapshot_keeps_counting_advances_it_can_place;reanchor_below_the_seed_is_ignored;reanchor_below_a_folded_event_is_ignored;applied_throughskip failsreanchor_pools_skips_a_block_behind_the_watcher;sinceacross a re-anchor failsanchored_snapshot_counts_a_known_lanes_advance_once.fix, lowercase subjectCHANGELOG.mdentry under Security🤖 Generated with Claude Code