Repository navigation
fix(node,payments): tombstone forgotten floor-loss rows, meter persist failures - #1784
Merged
Merged
Conversation
…t failures Close the forget_loss/record_loss resurrection race (#1781): a FloorReservation drop snapshots its cumulative total under the floor lock, then persists it from an independent blocking task, so the write could land after forget_pool_floor's durable delete and re-insert a row for a closed pool — permanent since #1780 made record_loss monotonic. forget_loss now deletes the row and tombstones the pool id in one redb transaction, and record_loss checks the tombstone inside its own write transaction, making the late write a no-op. Handler bring-up sweeps the tombstones before hydration — the one point where no persist can be in flight — bounding their growth to one process lifetime. Instrument the drop-time persist (#1782): a new decdn_floor_loss_persist_failures_total counter fires on every failed record_loss, both dispatch paths log the µUSDC total that failed to reach disk, and redb corruption maps to StoreError::Corrupt and logs at error! — a corrupt or write-latched lanes.redb fails every later persist until the file is reopened, unlike a transient fault. Registry row in the observability appendix and a Prometheus alert added. Add the missing integration coverage (#1783): record_loss racing the lane flush on the shared redb file, two sequential drops through the real Drop guard driving the store's monotonic contract, the #1781 interleaving made deterministic with a gated store, and restart hydration distinguishable from overwrite semantics (the smaller total lands last). Closes #1781. Closes #1782. Closes #1783. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EtAhosYcK8HGWFRUCT2QfJ
… registry The appendix registry row for decdn_floor_loss_persist_failures_total linked 003-payments.md bare; the ADR reference-hygiene gate requires every cross-ADR link to carry a resolving #heading anchor. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EtAhosYcK8HGWFRUCT2QfJ
There was a problem hiding this comment.
Pull request overview
This PR hardens the node’s pool floor-loss persistence surface against a forget-vs-late-drop resurrection race, improves operational visibility into drop-time persist failures (including distinguishing corruption), and adds integration coverage for the redb-backed store behavior under concurrency and restart.
Changes:
- Add durable “forgotten” tombstones to make
forget_lossterminal and prevent laterecord_lossfrom resurrecting closed-pool rows; add a bring-upsweep_forgottenreclamation hook. - Add
decdn_floor_loss_persist_failures_totalinstrumentation (plus alert + observability registry) and surface corruption distinctly at the drop site. - Add integration and unit tests covering concurrent lane writes vs floor-loss writes, restart monotonicity, and deterministic late-persist-after-forget behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| monitoring/prometheus-alerts.yml | Adds DecdnFloorLossPersistFailures alert for sustained drop-time persist failures. |
| crates/node/tests/channel_state_store.rs | Adds integration tests driving concurrent lane writes and floor-loss record/forget churn on the shared lanes.redb file, plus restart hydration assertions. |
| crates/node/src/metrics.rs | Introduces the floor_loss_persist_failures counter + recorder hook. |
| crates/node/src/handlers/client/mod.rs | Wires metrics into FloorReservation and counts/logs drop-time persist failures; performs bring-up tombstone sweep before hydration. |
| crates/node/src/channel_store.rs | Implements tombstone table + atomic tombstone checks in record_loss, terminal forget_loss, and sweep_forgotten; maps redb corruption into StoreError::Corrupt. |
| crates/incentive/src/store.rs | Extends PoolFloorLossStore with sweep_forgotten and mirrors tombstone semantics in the in-memory store. |
| adr/appendix-observability.md | Registers the new persist-failure metric in the observability appendix. |
Suppressed comments (1)
crates/node/src/channel_store.rs:1457
- This comment claims the sweep “heals any row a pre-tombstone build leaked”, but the sweep only removes loss rows for keys that are present in the tombstone table. A leaked row from a pre-tombstone build would not have a tombstone, so it would not be removed by this sweep.
// Belt-and-braces: `record_loss`'s in-transaction tombstone check means
// a tombstoned pool can hold no loss row, but the removal is O(1) per
// tombstone and heals any row a pre-tombstone build leaked.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The sweep's existence probe distinguishes "table never created" from "no tombstones" — any committed record_loss creates the table empty as a side effect of its in-transaction check — and the per-tombstone row removal is a defensive no-op, not a repair of leaked rows (a row without a tombstone is untouched by the sweep). Say both accurately, and keep forget_loss's no-early-return rationale in present tense. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EtAhosYcK8HGWFRUCT2QfJ
Coverage reportTotal: 81.66% (was 81.60%, ▲ +0.06%) — 65320/79990 lines
History
|
…iduals (#1786) * fix(node,payments): close the floor-loss error-path and in-memory residuals Review follow-ups on the #1781/#1782 fix: - forget_pool_floor: a failed forget_loss leaves the closed pool's row with no tombstone, open to permanent re-insertion by a late drop-dispatched record_loss — the #1781 leak through the error path. Count it under floor_loss_persist_failures so DecdnFloorLossPersistFailures covers this mode, and surface a corrupt payment store at error!, mirroring the drop-time persist. Outcome handling lives in note_forget_outcome; metric docs, the registry row, and the alert text now name both write paths. - release_live_repaid: get_mut instead of entry().or_default(), so a repayment that lands after forget_pool_floor removed the pool's entry cannot re-insert a default state for the closed pool — the in-memory face of the same resurrection race, which the drop guard already avoids. - sweep_forgotten: drop the separate read-transaction existence probe; the write transaction's no-op abort already rolls back table creation, the same property record_loss's in-transaction check relies on. - Reword two test docstrings into present-tense counterfactuals. - New tests: a repaid release after forget leaves the map untouched, and a failed forget bumps the persist-failure counter. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_013d9kpLBeSy4kRmBazVEy7x * docs(node): name both dead-charge log lines in the alert and metric docs Review-bot follow-up on the failure-signal wording: the alert header and summary say "writes", not "persists", and both the alert comment and the counter's field doc cite the warn!/error! pair for the persist and forget paths. Co-Authored-By: Claude <[email protected]> Claude-Session: https://claude.ai/code/session_013d9kpLBeSy4kRmBazVEy7x --------- Co-authored-by: Claude <[email protected]>
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.
One PR for #1781 / #1782 / #1783 — all three fell out of the #1780 review and touch the same pool floor-loss surface (
PoolFloorLossStore, theFloorReservationdrop path, and their tests), so the fix, the instrumentation, and the coverage land together.#1781 — forget/record resurrection race
A
FloorReservationdrop snapshots its cumulative total under the floor lock, then persists it from an independentspawn_blockingtask. That write could land afterforget_pool_floor's durable delete committed, re-inserting a row for a closed pool — and since #1780 maderecord_lossmonotonic, nothing ever removed it again (one permanent row per closed pool that hit the race, rehydrated on every boot).Fixed in the store, where the ordering can actually be enforced (option 2 from the issue):
forget_lossnow deletes the row and tombstones the pool id in the same redb write transaction (pool_floor_loss_forgotten_v1). The tombstone goes in even for a never-recorded pool — the racingrecord_lossmay be the pool's first.record_losschecks the tombstone inside its own write transaction; redb's exclusive writer slot makes the check atomic with the insert, so there is no check-then-write window. A tombstoned pool is a no-op (taking the existing no-op abort path, so no extra fsync).sweep_forgottentrait method reclaims tombstones at handler bring-up — the one point where no reservation exists and no persist can be in flight — bounding tombstone growth to one process lifetime. The sweep also removes any loss row a tombstone masks, healing rows leaked before this fix.#1782 — meter persist failures, surface corruption distinctly
decdn_floor_loss_persist_failures_total, bumped on every failedrecord_lossfrom the drop guard. Both dispatch paths (spawn_blocking and the no-runtime sync fallback) share one closure, so the accounting cannot drift between them.micro— the µUSDC total that failed to reach disk.redb::Error::Corruptedinto the existingStoreError::Corruptvariant, and the drop site logs that case aterror!("payment store corrupt") — after a mid-commit failure redb refuses further writes until the file is reopened, so the remedy is an operator restart, unlike a transient fault.adr/appendix-observability.md(Payment Pool Metrics,live) and aDecdnFloorLossPersistFailuresalert added tomonitoring/prometheus-alerts.yml; both name-gates inmetrics.rspass.#1783 — integration coverage
record_loss_races_the_lane_flush_on_the_shared_file(tests/channel_state_store.rs):apply_voucherlane writes, raising + non-raising (abort-path)record_loss, and record/forget churn interleaved on one redb file — the fsync-contention shape perf(node,payments): flush lanes in redb key order, enforce monotonic floor loss #1780's abort exists for, never previously driven concurrently.floor_reservation_sequential_drops_accumulate_dead_charge: two drops on one pool through the realDropguard (sync fallback), asserting the accumulator and the persisted total walk upward and a repaid guard writes nothing — the first test exercising the guard against the monotonic contract rather than the contract in isolation.late_drop_persist_after_forget_does_not_resurrect_row: the fix(node): forget_loss/record_loss resurrection race leaves a permanent floor-loss row #1781 interleaving made deterministic — a gated store holds the drop-dispatchedrecord_lossuntil the forget has committed.floor_loss_restart_hydrates_the_monotonic_maximum: restart survival distinguishable from the old overwrite semantics (the smaller total lands last before the reopen), plus tombstone persistence + boot sweep across the restart.Validation
cargo test -p decdn-node(lib 715, all integration suites incl. the full 102-testclient_loopback) andcargo test -p decdn-incentive(258) — all green. One pre-existing flake observed once under heavy parallel load (sighup_signal::persistent_sighup_observes_both_signals), passes 3/3 in isolation, unrelated to this diff.cargo clippy --workspace --all-targetsclean,cargo fmt --checkclean, markdownlint clean on the appendix, alerts YAML parses.Closes #1781. Closes #1782. Closes #1783.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EtAhosYcK8HGWFRUCT2QfJ
Generated by Claude Code