Repository navigation
feat(node): idle buyer-channel cooperative-close reconcile sweep - #987
Conversation
The node opens a buyer-side PaymentChannel against each upstream provider it pulls from on a cache miss (#744). Until now an idle channel's deposit stayed locked until on-chain expiry (default 90 days) — the existing reclaim sweep only acts after expiry. This adds an idle-reconcile sweep that cooperatively closes idle channels early (reusing the #971 client core), reclaiming the deposit in one tx with no dispute window. Behavior (folds into the existing hourly buyer sweep cadence): - ACTIVE channels are skipped — idleness is "no voucher-nonce progress for RECONCILE_IDLE_SWEEPS (~24h) consecutive sweeps", tracked in-memory across sweeps (`observe_idle`). A channel we're still pulling from is never closed out from under the workload; any nonce progress resets the tally. - IDLE + provider reachable → cooperative close; on Settled the local record is forgotten and `buyer_reconcile_settled` is bumped. - IDLE + provider unreachable/declined/reverted → left untouched for the existing expiry-reclaim sweep (the safety net). A never-paid (nonce 0) or already-expired channel is skipped outright. Two new primitives: - `NodeAddressResolver::node_id_for(addr)` — reverse of `address_of`, since the buyer store keys channels by the provider's operator address but dialing needs its NodeId. O(n) scan (hourly, few channels). A deregistered provider isn't found → treated as unreachable. - The reconcile task wiring (`BuyerReconcileConfig`: endpoint + resolver), threaded through `BuyerChannelService::bootstrap` and gated on node→node pull-through being enabled (resolver present). Absent → reconcile disabled, expiry reclaim runs alone exactly as before. The unreachable-provider unilateral close→settle path is deferred to a follow-up; the expiry reclaim already recovers those deposits (just later). Idle horizon is a const (not config) — YAGNI; promote if an operator needs to tune it. Tests: `observe_idle` first-sight/threshold/reset; reverse-lookup resolve+miss. 843 node+incentive tests pass; workspace clippy + fmt + doc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds an “idle buyer-channel reconcile” sweep to the node’s buyer-side PaymentChannel service so node→node cache-miss buyer channels can be cooperatively closed (deposit reclaimed early) after sustained voucher inactivity, rather than waiting for on-chain expiry. This integrates the cooperative-close core from the shared client-pull logic and wires it into the node runtime only when node→node pull-through provides the necessary dial/resolution plumbing.
Changes:
- Thread optional reconcile dial config into
BuyerChannelService::bootstrapand spawn an hourly idle-reconcile loop that cooperatively closes long-idle, non-expired, paid channels. - Extend
NodeAddressResolverwithnode_id_for(address)reverse lookup to map provider operator addresses back to dialableNodeIds. - Add a new metric counter for reconcile-settled channels and update e2e wiring/tests to pass the new optional reconcile argument.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/buyer_channel.rs | Adds reconcile config + idle observation policy + background reconcile loop that attempts cooperative close for idle buyer channels. |
| crates/node/src/dht/node_address.rs | Extends resolver trait with reverse lookup (node_id_for) and implements it for static + chain-backed directories; adds unit tests. |
| crates/node/src/runtime/mod.rs | Wires BuyerReconcileConfig into buyer-channel bootstrap only when a node-address resolver is available. |
| crates/node/src/metrics.rs | Adds buyer_reconcile_settled counter + bump method for successful cooperative-close reconciliations. |
| crates/node/tests/anvil_settlement_e2e.rs | Updates e2e test bootstrap calls to pass None for the new optional reconcile configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces an idle-reconcile sweep mechanism to cooperatively close idle buyer channels and reclaim deposits early, including the necessary reverse address lookup wiring and tracking metrics. The review feedback highlights a potential issue where persistent failures (such as invalid public keys, or declined/reverted cooperative closes) are not cleared from the idle observation map, leading to hourly retries and log spam. Implementing a backoff by resetting the idle tally for these channels is recommended.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 83.44% (was 83.67%, ▼ 0.23%) — 41450/49678 lines
History
|
…fixes Address review feedback on #987: - Drop the idle observation on invalid-pubkey, Declined, and Reverted outcomes so a persistent fault backs off ~24h instead of re-dialing / re-submitting (and re-logging) on every hourly sweep. The Reverted path was burning gas hourly until a (≤90-day) expiry; the expiry-reclaim sweep stays the eventual safety net. The Err (unreachable) path keeps retrying hourly — that fault is transient. (gemini-code-assist) - Remove a stray "ponytail:" word from node_id_for's comment. (Copilot) - Correct two comments that referenced a "zero idle threshold" disable path the code never implements (RECONCILE_IDLE_SWEEPS is a const); reconcile is gated solely on dial wiring being present. (Copilot) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #972. The final leg of cooperative close: the node, as a buyer on node→node cache-miss pulls (#744), now reclaims its deposit on idle channels early via cooperative close, instead of waiting out the on-chain expiry (default 90 days). Reuses the client core from #973. Base =
main.Behavior
Folds into the existing hourly buyer sweep. Per non-expired channel:
RECONCILE_IDLE_SWEEPS(~24h) consecutive sweeps, tracked in memory (observe_idle). Any nonce progress resets the tally, so a channel we're still pulling from is never closed out from under the workload (your first constraint). In-memory state re-seeds on restart — a safe bias (nothing closed until observed idle post-restart).Settledthe local record is forgotten andbuyer_reconcile_settledis bumped.Two new primitives
NodeAddressResolver::node_id_for(addr)— reverse ofaddress_of. The buyer store keys channels by the provider's operator address, but dialing for a waiver needs its NodeId. O(n) scan (hourly, few channels). A deregistered provider isn't found → treated as unreachable.BuyerReconcileConfig(endpoint + resolver), threaded throughBuyerChannelService::bootstrap, gated on node→node pull-through being enabled (resolver present). Absent → reconcile disabled, the proven expiry-reclaim path runs alone, untouched.Scope calls (per discussion)
closeChannel→settleChannelis deferred (follow-up filed). Buyer-side unilateral close/window-tracking doesn't exist yet and the expiry sweep already recovers those deposits, just later — not worth doubling this PR's surface.Tests
observe_idle(first-sight not idle / idle at threshold / reset on progress) and the reverse lookup (resolve + miss).cargo nextest run -p decdn-node -p decdn-incentive→ 843 passing; workspace clippy + fmt + doc clean. (The anvil e2e buyer-bootstrap calls take the newNonereconcile arg; reconcile itself isn't exercised there — its decision logic is covered by the pure-function tests.)🤖 Generated with Claude Code