Repository navigation
refactor(node): drop PaymentPool close monitor; lean on the redeem sweep - #1761
Conversation
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]>
There was a problem hiding this comment.
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
PoolCloseInitiatedhandling 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.
Coverage reportTotal: 81.15% (was 81.09%, ▲ +0.06%) — 59548/73384 lines
History
|
`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]>
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 89.65% (2563/2859 lines) |
…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]>
What
Removes the node's
PoolCloseInitiatedclose monitor and relies on the existing periodic redeem sweep to redeem before an owner canreclaima 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
redeem_thresholdpolicy 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
PoolCloseInitiatedmatch arm,redeem_pool_on_close, the now-unusedsaturating_u64/is_expiredhelpers, and the event from the settlement filter's topic0 set. Three now-deadPoolSettlementSinkfields go with it, dropping the sink's generic parameter.blockchain.redeem_interval_secsat 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.appendix-fraud-detection.md, andarchitecture.mdto the sweep-based canon.Testing
cargo build,cargo clippy,cargo fmt --checkclean ondecdn-node+decdn-common.cargo nextest run -p decdn-node payment_settlement— 20/20 pass.> 6h, accept== 6h— pass.🤖 Generated with Claude Code
Closes #1763.