Skip to content

refactor(node): drop PaymentPool close monitor; lean on the redeem sweep - #1761

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/1037-redeem-many-dispute-51e03a
Aug 20, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/1037-redeem-many-dispute-51e03a

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Removes the node's PoolCloseInitiated close monitor and relies on the existing periodic redeem sweep to redeem before an owner can reclaim a closing pool. Adds a config cap on the sweep interval so this is safe.

Closes the design question in #1037: there was never a "dispute" to build — under the shared PaymentPool, redemption is cumulative and provider-only, so a node's only defense against a grace-window close is to redeem its vouchers, which the sweep already does.

Why the monitor bought nothing

  • Timing — the 48h grace floor gives any sane sweep interval (default 5m) hundreds of attempts to redeem before reclaim.
  • Offline nodes — the monitor is in-process, so it can't help a node that's down for the whole window; the sweep has the same property. No delta.
  • Sub-threshold dust — the monitor's one unique behavior was force-redeeming dust at a zero floor, which spends more gas than it recovers and contradicts the redeem_threshold policy the node applies for the pool's whole life. Forfeiting that dust back to the owner at reclaim is the correct outcome.

Dropping it also stops every provider on a pool from racing to redeem on the same block when it closes — independent sweep phases spread that load.

Changes

  • Delete the PoolCloseInitiated match arm, redeem_pool_on_close, the now-unused saturating_u64 / is_expired helpers, and the event from the settlement filter's topic0 set. Three now-dead PoolSettlementSink fields go with it, dropping the sink's generic parameter.
  • Cap blockchain.redeem_interval_secs at 6h at config load (48h grace floor ÷ 8× margin), with tests for the rejected and accepted boundaries. A misconfigured interval can no longer silently strand vouchers past a close — the safety net the monitor implicitly provided.
  • Rewrite ADR 003 § Owner reclaims before a node redeems, appendix-fraud-detection.md, and architecture.md to the sweep-based canon.

Testing

  • cargo build, cargo clippy, cargo fmt --check clean on decdn-node + decdn-common.
  • cargo nextest run -p decdn-node payment_settlement — 20/20 pass.
  • New config tests: reject > 6h, accept == 6h — pass.

🤖 Generated with Claude Code

Closes #1763.

The node watched `PoolCloseInitiated` and force-redeemed every lane of a
closing pool at a zero floor before `disputeDeadline`. This bought nothing
the periodic redeem sweep does not already provide, and its one unique
behavior was undesirable:

- Timing: the 48h grace floor gives any sane sweep interval (default 5m)
  hundreds of attempts to redeem before reclaim.
- Offline nodes: the monitor is in-process, so it cannot help a node that
  is down for the window — the sweep has the same property. No delta.
- The only unique behavior was force-redeeming sub-threshold dust
  (floor = 0), which spends more gas than it recovers and contradicts the
  `redeem_threshold` policy the node applies for the pool's whole life.
  Forfeiting that dust to the owner at reclaim is the correct outcome.

Dropping the monitor also stops every provider on a pool from racing to
redeem on the same block when it closes; independent sweep phases spread
that load.

Delete the `PoolCloseInitiated` match arm, `redeem_pool_on_close`, the
now-unused `saturating_u64`/`is_expired` helpers, and the event from the
settlement filter's topic0 set (three now-dead `PoolSettlementSink` fields
go with it, dropping the sink's generic). Cap `redeem_interval_secs` at 6h
at config load so a misconfigured interval can never silently strand
vouchers past a close — the safety net the monitor implicitly provided.

Rewrite ADR 003 § Owner reclaims, appendix-fraud-detection, and
architecture.md to the sweep-based canon.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 20, 2026 10:00

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 simplifies the node’s seller-side PaymentPool settlement logic by removing the PoolCloseInitiated close monitor and relying on the existing periodic redeem sweep (now bounded by config validation) to redeem vouchers before a pool can be reclaimed. It also updates ADR documentation to reflect the sweep-based defense model.

Changes:

  • Remove PoolCloseInitiated handling from the node settlement log sink and delete the close-redeem monitor code path.
  • Enforce a config-time upper bound on blockchain.redeem_interval_secs (<= 6h) and add boundary tests.
  • Update ADR docs (architecture.md, 003-payments.md, and fraud appendix) to describe the sweep-based approach.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/src/pool_view.rs Updates projection documentation to explicitly state it does not track a Closing state.
crates/node/src/payment_settlement.rs Removes close-monitor logic and PoolCloseInitiated topic filtering; updates module docs/tests accordingly.
crates/common/src/config/mod.rs Caps redeem_interval_secs at 6h during config resolution and adds tests for the cap.
adr/architecture.md Updates threat-model wording to remove reliance on close-event visibility and align with sweep-based redemption.
adr/appendix-fraud-detection.md Replaces the “in-process redemption monitor” description with the periodic redeem sweep approach.
adr/003-payments.md Updates the “owner reclaims before node redeems” defense section to sweep-based behavior and config cap.

💡 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/payment_settlement.rs Resolved
@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.15% (was 81.09%, ▲ +0.06%) — 59548/73384 lines

File Coverage Lines Δ
crates/cli/src/commands/rotate_key/eth.rs 47.09% 356/756 ● 0.00%
crates/common/src/config/mod.rs 97.09% 6678/6878 ▲ +0.01%
crates/node/src/metrics.rs 94.36% 836/886 ▼ 0.73%
crates/node/src/payment_settlement.rs 49.17% 533/1084 ▲ +3.18%
crates/node/src/pool_view.rs 96.30% 182/189 ● 0.00%
crates/node/src/runtime/mod.rs 48.23% 1089/2258 ● 0.00%
History
Commit Total Δ vs base
e3778e1 81.18% ▲ +0.09%
31ddee3 81.18% ▲ +0.09%
93e8f25 (HEAD) 81.15% ▲ +0.06%

`is_registered` is `registered_until > now`, so a broken clock yielding 0
makes a cached registration look live (skips the read), not expired. The
comment claimed the opposite direction. Correct it and note the skip is
benign — an actually-expired capability no-ops as transient-empty at the
contract.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.65% (2563/2859 lines)
▼ -0.03pp vs base (89.67% → 89.65%)
Run: 32361205889

…rics

The buyer/seller payment layer migrated from pairwise payment channels to
the shared `PaymentPool`, but a family of Prometheus counters describing the
old `closeChannel`/`disputeChannel`/`settleChannel`/cooperative-close model
was left behind. None of them has any live emission site — the functions
their docs reference (`try_settle`, `try_auto_settle_close`,
`maybe_dispute_stale_close`, the auto-settle arm of `try_redeem`) no longer
exist — so they exported flat zero forever.

Remove them and their zero-and-increment tests:
- buyer unilateral close / settle (#988/#989): buyer_unilateral_close_*,
  buyer_settle_ok, buyer_settle_deferred
- buyer reconcile cooperative-close (#972/#1495): buyer_reconcile_settled,
  buyer_reconcile_watermark_healed
- seller auto-settlement close (#742): settlement_auto_triggered/_failures
- self-defense disputeChannel (#1586): settlement_dispute_ok/_failures
- settleChannel finalization sweep (#810): settlement_finalize_* (8 counters)
- payment-channel cooperative close: serve_stream_rejected_cooperative_close_signed,
  cooperative_close_request_unauthorized, cooperative_close_auth_no_echo

Trim the three dead reasons out of the shared serve-stream-rejected test
without touching its live counters. Refresh the docs of the counters/comments
that survive but still spoke the channel model: the live watcher_persist_failures
counter (now a PoolReclaimed lane-forget signal), the seller-settlement bootstrap
comment (signs redeemMany, folds PaymentPool events), and the rotate-key operator
help (old voucherSigner keeps signing vouchers until capability expiry — no
cooperative close to countersign).

The buyer service (BuyerPoolService) and its store (PersistentPoolStateStore)
are already pure pool code; only the buyer_channel.rs / channel_store.rs file
names remain stale and are left for a separate rename.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify node payment settlement: drop PaymentPool close monitor + dead pairwise-channel dispute residue

2 participants