Skip to content

fix(node,payments): tombstone forgotten floor-loss rows, meter persist failures - #1784

Merged
alpergundogdu merged 4 commits into
mainfrom
claude/issues-1781-1782-1783-iaxai2
Aug 24, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
claude/issues-1781-1782-1783-iaxai2

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

One PR for #1781 / #1782 / #1783 — all three fell out of the #1780 review and touch the same pool floor-loss surface (PoolFloorLossStore, the FloorReservation drop path, and their tests), so the fix, the instrumentation, and the coverage land together.

#1781 — forget/record resurrection race

A FloorReservation drop snapshots its cumulative total under the floor lock, then persists it from an independent spawn_blocking task. That write could land after forget_pool_floor's durable delete committed, re-inserting a row for a closed pool — and since #1780 made record_loss monotonic, 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_loss now 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 racing record_loss may be the pool's first.
  • record_loss checks 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).
  • New sweep_forgotten trait 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.
  • The memory store mirrors the semantics exactly (totals + tombstones under one mutex).

#1782 — meter persist failures, surface corruption distinctly

  • New counter decdn_floor_loss_persist_failures_total, bumped on every failed record_loss from the drop guard. Both dispatch paths (spawn_blocking and the no-runtime sync fallback) share one closure, so the accounting cannot drift between them.
  • Both log lines now carry micro — the µUSDC total that failed to reach disk.
  • The floor-loss redb impl maps redb::Error::Corrupted into the existing StoreError::Corrupt variant, and the drop site logs that case at error! ("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.
  • Registry row added to adr/appendix-observability.md (Payment Pool Metrics, live) and a DecdnFloorLossPersistFailures alert added to monitoring/prometheus-alerts.yml; both name-gates in metrics.rs pass.

#1783 — integration coverage

  • record_loss_races_the_lane_flush_on_the_shared_file (tests/channel_state_store.rs): apply_voucher lane 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 real Drop guard (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-dispatched record_loss until 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.
  • Store-level record-after-forget / sweep tests over both impls, and a threaded forget-vs-record race test on redb.

Validation

  • cargo test -p decdn-node (lib 715, all integration suites incl. the full 102-test client_loopback) and cargo 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-targets clean, cargo fmt --check clean, 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

…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
Copilot AI lite review requested due to automatic review settings August 24, 2026 10:13
… 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_loss terminal and prevent late record_loss from resurrecting closed-pool rows; add a bring-up sweep_forgotten reclamation hook.
  • Add decdn_floor_loss_persist_failures_total instrumentation (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.

Comment thread crates/node/src/channel_store.rs Resolved
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
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.66% (was 81.60%, ▲ +0.06%) — 65320/79990 lines

File Coverage Lines Δ
crates/incentive/src/store.rs 92.47% 307/332 ▲ +0.36%
crates/node/src/channel_store.rs 86.29% 1328/1539 ▼ 0.56%
crates/node/src/handlers/client/mod.rs 92.21% 1421/1541 ▲ +0.16%
crates/node/src/metrics.rs 94.46% 852/902 ● 0.00%
History
Commit Total Δ vs base
900d011 81.63% ▲ +0.03%
a0758af (HEAD) 81.66% ▲ +0.06%

…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]>
@alpergundogdu
alpergundogdu merged commit 1ece85d into main Aug 24, 2026
24 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issues-1781-1782-1783-iaxai2 branch August 24, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants