Skip to content

fix(cli): pre-check reclaim --pool and name the cause and deadline - #2238

Merged
yigitdot merged 3 commits into
mainfrom
claude/pool-reclaim-deadline-check-1eff6a
Sep 30, 2026
Merged

yigitdot merged 3 commits into
mainfrom
claude/pool-reclaim-deadline-check-1eff6a

Conversation

@yigitdot

@yigitdot yigitdot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2237.

Problem

decdn pool reclaim --pool sent reclaim without reading the pool first. Any revert became one fixed message naming two possible causes ("not closed, or its dispute window has not elapsed yet"). The message gave no deadline, and the keystore password was asked for before the chain said no.

Behavior

reclaim --pool now reads the pool (getPool) and the head block's timestamp on a wallet-free provider, and runs them through the same plan_reclaim that --all uses. The check runs before the buyer store opens and the keystore unlocks. A pool that can't be reclaimed is refused with its own cause, with no password prompt and no transaction:

Pool Result
never opened (zero owner) pool 0x… does not exist on this PaymentPool contract — a mistyped --pool, or the wrong payment_pool address
Open pool 0x… is still Open — run \decdn pool close --pool 0x…` first`
Closing, in window pool 0x… is still in its dispute window; reclaimable after Unix 1790875000 (in 2d 0h 36m)
Closing, past deadline sends reclaim
Closed pool 0x… is already Closed — its residual was already reclaimed

The owner check runs first because a never-opened pool reads as status 0, which is Open.

If the chain still reverts after the check passed, the error names the causes that remain: a concurrent reclaim, or the USDC refund transfer to the owner. One shared message covers the estimation-time and receipt-time reverts.

Chain time, not the local clock

The contract gates on block.timestamp >= disputeDeadline. The --pool check, the --all sweep, and the pool list Reclaimable column now compare against the head block's timestamp, not SystemTime::now(). A machine whose clock trails the chain no longer refuses a pool the chain would reclaim. The three private head_timestamp copies in unbond, update_multiaddrs, and update_region become one chain_ctx::head_timestamp.

Other changes

  • decdn_client::provider::build_read_provider: a new wallet-free builder. It shares a private parse_rpc_url with build_provider, so the redacted invalid-URL error lives in one place. The public-API snapshot is updated.
  • reclaim --all renders its in-window deadline with format_expiry, the same rendering as pool list.
  • The --pool help text and the reclaim / plan_reclaim / ReclaimPlan docs describe the check.

The deadline is shown as Unix time plus time remaining, not a UTC calendar date. The CLI has no date dependency, and this matches the existing pool list column.

Test plan

  • Unit: single_reclaim_gate_names_the_cause covers each refusal and the at- and past-deadline sends
  • Unit: invalid_rpc_url_is_redacted_from_both_builders
  • Integration: reclaim_pool_reads_chain_before_store_or_keystore (unreachable RPC → getPool failed, no keystore error, no store file created)
  • Anvil e2e: cli_pool_reclaim_precheck goes missing → Open → in-window → reclaim after an evm_increaseTime past the window (wall clock unchanged) → Closed. Every refusal runs with a wrong keystore password.
  • cargo clippy --workspace --all-targets -D warnings (plus decdn-e2e with anvil-e2e), cargo fmt --check, cargo doc -D warnings, check_crate_edges.py, public-api-test
  • cargo nextest run -p decdn-cli -p decdn-client: all pass except driver::tests::an_idle_lane_releases_its_surplus_workers_before_the_drive_ends. It fails in every full parallel run and passes on its own, and this PR does not change the driver code. Tracked in Flaky under load: driver::tests::an_idle_lane_releases_its_surplus_workers_before_the_drive_ends #2240.

🤖 Generated with Claude Code

…2237)

`pool reclaim --pool` now reads the pool on a wallet-free provider and
runs it through plan_reclaim before the keystore unlock. An Open,
in-window, Closed, or nonexistent pool fails with its own cause (the
in-window case prints the deadline and time remaining) and sends no
transaction. A revert after the pre-check names the remaining race
causes. reclaim --all renders its in-window deadline the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 18:36

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-code-quality

github-code-quality Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 0f1c9e7 in the claude/pool-reclaim-... branch remains at 86%, unchanged from commit 74e2cd4 in the main branch.

Show a line coverage summary of the most impacted files.
File main 74e2cd4 claude/pool-reclaim-... 0f1c9e7 +/-
crates/cli/src/...ds/chain_ctx.rs 91% 89% -2%
crates/node/src/dht/publish.rs 92% 92% 0%
crates/cli/src/...mands/unbond.rs 74% 74% 0%
crates/node/src...s/client/mod.rs 96% 96% 0%
crates/client/src/scheduler.rs 96% 96% 0%
crates/cli/src/...ommands/pool.rs 67% 68% +1%
crates/cli/src/...tate_key/eth.rs 49% 50% +1%
crates/cli/src/...pdate_region.rs 69% 71% +2%
crates/cli/src/...e_multiaddrs.rs 67% 69% +2%
crates/client/src/provider.rs 96% 99% +3%

Updated September 29, 2026 19:42 UTC

…d to end

The reclaim --pool pre-check, the reclaim --all sweep, and the pool list
Reclaimable column now compare the dispute deadline against the head
block's timestamp, the clock the contract uses, instead of the local
clock. A machine whose clock trails the chain no longer refuses a pool
the chain would reclaim. The three private head_timestamp copies move to
chain_ctx as one shared helper.

The post-check revert message names the causes that remain (a concurrent
reclaim, or the USDC refund transfer). Docs and the --pool help describe
the pre-check. The client public-API snapshot lists build_read_provider.

Tests: the pre-check runs before the store opens and the keystore
unlocks; both provider builders redact an invalid rpc_url; an anvil
journey walks missing, Open, in-window, chain-time-elapsed, and Closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yigitdot
yigitdot merged commit 4904d7c into main Sep 30, 2026
55 of 57 checks passed
@yigitdot
yigitdot deleted the claude/pool-reclaim-deadline-check-1eff6a branch September 30, 2026 00:04
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.

pool reclaim --pool: check the dispute deadline before sending, and name the cause and deadline in the error

3 participants