Repository navigation
feat(cli): add decdn node unbond + G-NODE-06 journey (#1033) - #1353
Conversation
`CapacityBond` has shipped the full unbonding surface all along — `requestUnbond(amount)` starts the window, `unbond()` withdraws once it matures, and ADR 026 § Capacity-bond curve names the pair as the only way to lower a bond — but no Rust path reached either call. `capacity_bond.rs` declared `bond` / `declareMbps` / `registerNode` and stopped, and `NodeCommand` had no `Unbond`, so an operator who bonded via `decdn node bond` had no supported way to get TOKEN back out. Add one state-aware `decdn node unbond` covering all three phases of the window, picked from chain state rather than a flag: no request in flight declares the tier down (if needed) and calls `requestUnbond`; a maturing request reports the unlock time and exits non-zero; a matured one withdraws. Same plan / --dry-run / --json / idempotent-re-run shape as `decdn node bond`. Two contract facts drive the UX, and both are surfaced rather than left to a revert: - A request in flight makes `isActive` false for the WHOLE window — it is a conjunct of the predicate, independent of the remaining bond. So this is a ~14-day outage, not a background operation, and a terminal run confirms before starting one (`--yes` for automation; headless without it refuses rather than assuming consent). - `requestUnbond`'s floor is `bondRequired(declaredMbps)`, NOT `minBond`, so the contract permits unbonding into an inactive state. The three amount flags therefore pick deliberately different floors: `--to-mbps` retains `max(minBond, bondRequired(N))` and keeps the operator eligible, `--all` goes to the contract's own floor and says so, and `--amount` is pre-checked against the curve so `BondBelowCurve` never surfaces raw — it fails with the `decdn node bond --mbps` invocation needed instead. G-NODE-06 drives the production binary through the whole journey against a real `CapacityBond`: bond up, reduce with `--to-mbps`, assert the node is inactive while the request matures, assert the maturing re-run touches no state, warp past `unlockAt`, withdraw, assert the TOKEN returned and the node is active again, and assert a below-curve `--amount` is rejected before any transaction. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (5)
WalkthroughChangesNode unbond workflow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Operator
participant CLI
participant CapacityBond
Operator->>CLI: run node unbond
CLI->>CapacityBond: read bond and unbonding state
CapacityBond-->>CLI: return current state
CLI->>CapacityBond: requestUnbond or unbond
CapacityBond-->>CLI: return transaction receipt
CLI-->>Operator: print phase and transaction hashes
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces the decdn node unbond command, which allows operators to lower their on-chain capacity bond in a state-aware, multi-phase process (request, waiting, and withdraw). It includes CLI integration, updated contract bindings, and comprehensive end-to-end tests. The review feedback highlights a critical issue regarding the command's idempotency: if a previous run successfully declared a lower capacity but failed to request the unbond, a subsequent retry would fail because the target capacity is no longer strictly less than the declared capacity. The reviewer suggested allowing target <= declared and skipping the declaration transaction when they are equal to ensure the command converges correctly.
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: 81.53% (was 81.74%, ▼ 0.21%) — 51899/63656 lines
History
|
`--to-mbps` submits `declareMbps` and `requestUnbond` as two transactions. A run that landed the first and lost the second — reverted, dropped receipt, Ctrl-C — leaves the tier already reduced while the bond is still high. The `target < declared` guard then rejected the identical re-run with "not below the current declared tier", pointing the operator at `decdn node bond`, which cannot release anything. That stranded exactly the operator the command's idempotence exists for, and contradicted `execute`'s independently-skippable step structure. Accept `target == declared` and skip the redundant declare, mirroring `bond`'s `needs_declare`. The rule moves into a named `tier_step` so it is testable without a chain; the downstream `release > 0` check still catches the genuinely-nothing-to-do case, so accepting equality costs no safety. G-NODE-06 gains the convergence leg. The half-done state is reachable with the shipped commands — `node bond` at a tier the operator is already over-bonded for has zero shortfall, so it submits `declareMbps` and nothing else, byte for byte what a partially-failed unbond leaves behind. Verified the new leg fails against the pre-fix binary with the exact reported error before passing with the fix. Reported by gemini-code-assist on #1353. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… plan math (#1033) Follow-up to a multi-agent review of #1353. Three classes of defect, none cosmetic. **A landed declareMbps was reported nowhere.** `execute` built `Outcome` locally, so when `requestUnbond` failed after `declareMbps` mined, `?` discarded it and stdout was empty. The operator saw "failed", concluded nothing changed, and was wrong: their declared tier was already halved with no tx hash recorded anywhere. That is exactly the resumable state 8da691c was written to serve — the resume logic worked, but nobody was told they were in it. The outcome is now owned by `run`, always written before the error propagates, and the error names the landed declare and the fact that re-running resumes. **`--yes` suppressed the disclosure, not just the prompt.** `Bypassed` returned before both `writeln!`s, so a scripted `--all --yes` could leave a node permanently inactive with no warning at all. The consequences are now printed on every path; only the prompt is gated. While there, `confirm_or_bail` consumes `decide_confirmation` exhaustively instead of re-deriving Prompt/NeedFlag from `interactive` — previously swapping those two arms changed no behaviour and failed only a unit test, which made the confirmation assertions decorative. **Two tests certified behaviour they never executed.** The `--all` arm was 100% unexecuted (its only e2e use returns from the pending-request branch before `resolve_release`), and `--to-mbps`'s `max(minBond, ·)` term was inert at the journey's tiers — deleting it broke nothing, though it is the entire documented difference between the two flags. Adds a mocked-provider module (`Asserter`, already used in decdn-node) covering both, plus `--amount`'s bounds. Queueing exact response counts also pins which reads happen. Verified by negative control: deleting the minBond floor now fails a test, and the `--all` copy-paste regression fails two. Also: the `Waiting` arm of `execute` bails instead of returning a silent `Ok` that would print `submitted=false` and exit 0; maturity compares in U256 so it no longer depends on a narrowing conversion's saturation constant; `declaredMbps` conversion is loud because it gates `tier_step` and failed open; the capacity band is checked only when a `declareMbps` will actually be sent; `send` carries the tx hash into the receipt-timeout error and restores bond's per-step revert hint; `write_plan` regains the `dry_run` key so a preview is distinguishable from a real no-op. Comment/help corrections, all verified against the contract: `--to-mbps` help still stated the pre-8da691c strict rule; `--all` help asserted an unconditional drop below minBond that is false above ~1000 Mbps; a comment justified a decision with `clippy::unreachable`, which the workspace does not enable; the `nodeIdOf` analogy described a mapping getter that is actually a hand-written view; "every precondition" omitted `whenNotPaused`; plus ADR section, chrono, and from_args scope claims. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Multi-agent review applied —
|
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.94% (2500/2811 lines) |
…#1350, #1355) (#1358) Follow-ups filed off the reviews of #1340, #1341 and #1353. Closes #1342, #1343, #1344, #1345, #1350 and #1355; #1356 was closed as a duplicate of #1347, which stays open for the deferred swap-revert tests. BREAKING: `ReportGate` and `ReputationWiring`'s struct literal are gone — `ReputationWiring` is now a sum type (`Disabled` / `Enabled { sink, staked, publish }`), so an admission set without a sink is unrepresentable rather than warned about at runtime. That deletes the test #1344 asked for instead of adding it. `GossipRuntimeConfig::subscribe_reputation` is also gone; the operator-facing `[gossip] subscribe_reputation` key is unchanged, but `decdn-node` now resolves it into the wiring variant at the one site that builds it, so there is a single off-switch instead of two. `AnnounceGate::Disabled` is `#[cfg(test)]`. It fails OPEN on ADR 001 rule 2 and was guarded only by a doc comment plus a test on `announce_staked_gate`, which would have stayed green if a future edit passed `Disabled` to `spawn` — the hole #1170 closed. It no longer exists in production builds. Transaction submission is unified in `decdn_incentive::tx::send`, including both swap venues (they spend USDC and read the hash after `get_receipt()`, so a receipt timeout named no transaction at all). `send` takes a caller-owned `landed` slot: `Some` means "may have taken effect" — including the unreadable- receipt case — and is cleared on a confirmed revert. `bond`, `setup`, `register` and `appeal` use it. `channel` deliberately does not: it classifies a revert as an expected outcome rather than an error. That slot is what makes the re-run guidance safe. The earlier wording asserted "no TOKEN was transferred" / "on-chain state is unchanged" and told the operator to re-run immediately; alloy's nonce filler resolves against the pending block, so re-running while a bond tx is in flight submits a second one and doubles the bond. `setup`'s live phases are one fallible section with a single reporting site, so a failure at any phase emits the aggregated `--json` summary with whatever landed — previously a register-phase failure printed nothing and a landed swap's hash had no machine-readable carrier at all. `build_summary` emits one shape on both paths with a `partial` flag. Note for the record: commit `edb3e80`'s message asserts a symbol (`bundle_pull::discover_candidates`) that does not exist — copied from #1350's text without verifying, in a commit about fixing inaccurate comments. The code is correct; the message could not be amended. Tests: new `cli_setup_partial` e2e journey drives the production binary against anvil (with a new `ChainFixture::pause_capacity_bond` lever, since starving the operator of TOKEN trips the pre-flight instead of entering the live phase); the gossip integration test's drain now varies its payload per round, because plumtree dedups byte-identical messages for 90s and a constant payload collapsed a 50-round budget to ~6. Every new test was mutation-verified.
…unbond gate question (#1351, #1352, #1354) (#1360) Closes #1351, #1352, #1354 — the three surviving follow-ups from #1033/#1353, all on one surface. **#1351 — an operator that ever declared a tier could never fully unbond.** `requestUnbond` enforces `activeBond >= bondRequired(declaredMbps)`; `declareMbps` was the only writer of `declaredMbps` and cannot set it back to 0 (band floor `MIN_CAPACITY_FLOOR_MBPS = 10`, not governance-lowerable); `deregisterNode` left the tier standing. ADR 003 § Node Registry already asserted the intended behaviour, so the contract contradicted its own source of truth. `deregisterNode` now clears `declaredMbps`, emitting `MbpsDeclared(op, old, 0)` rather than writing silently (that log is the only push signal indexers have), skipped when no tier was ever declared. +105 bytes runtime, 1,214 of EIP-170 headroom left; no new event or selector, so the frozen interface is untouched. The fix covers the voluntary path only. `deregisterNode` requires an active node while `declareMbps` does not, so a tier declared without registering — the state `decdn node bond --mbps N` leaves behind — or left standing by an ejection still pins `bondRequired(declaredMbps)`. Measured: an operator slashed to auto-ejection keeps 10,126 TOKEN against a 50,161 floor with not one wei withdrawable. Not a regression (the floor was previously permanent for everyone) and deliberately not fixed here: clearing the tier on the involuntary paths would let a just-slashed operator immediately withdraw their whole remaining bond, which is a slashing-economics decision for ADR 026. Recorded in ADR 026, fenced by `test_ejectedOperator_keepsTheTierAndCannotUnbond`, tracked in #1361. **#1352 — no slash/appeal gate on `requestUnbond`, deliberately.** #1033 listed "unbond blocked while a slash/appeal is pending" as a negative case; that text was wrong and the contract is right. The 14-day window outlasts SlashJudge's 5-day evidence window by 9 days and the bond stays slashable throughout, so a gate adds nothing an honest challenger needs while handing a griefing challenger an indefinite freeze on an honest exit. The cited spec anchor does not exist — no file in the workspace contains the string G-NODE-06 — so the wrong text lived only in the closed #1033; the G-NODE-06 module docs now say the absent assertion is deliberate. **#1354 — four `decdn node unbond` behaviours only the real binary can reach.** `--dry-run` and the headless confirmation refusal cost no chain time; a below-crossover `--to-mbps 10` and a real `--all` release are appended after step 6. The `--all` leg had never run end to end (step 3 only reached its already-in-flight error) and is where `--all`'s bare curve floor visibly diverges from `--to-mbps`'s `max(minBond, curve)` — 199.696… TOKEN retained versus 50,000 at the same tier. Every expected amount is re-derived from chain state. Tests: every new e2e leg and every new Solidity test is mutation-verified, not merely green — dropping the dry-run short-circuit, bypassing the headless refusal, removing either floor from `--all`/`--to-mbps`, removing the `declaredMbps` clear or its zero-guard, and over-clearing `unbondingOf` each fail the intended test. `test_deregisterNode_preservesUnbondingSlashStampAndFirstBonded` fences the opposite direction: deleting `unbondingOf` in `deregisterNode` would orphan escrowed TOKEN, and clearing `_slashedAtEpoch` would let an operator launder a slash out of their ADR 036 voting weight by cycling deregister/re-register. `.gas-snapshot` regenerated. Also corrects pre-existing doc errors found on the way: ADR 003 and the key-rotation appendix both said `unbond()` starts the unbonding window (it is `requestUnbond`), the appendix referenced a `CapacityBond.withdraw()` that does not exist, ADR 019 § Re-Onboarding miscounted its own list, and ADR 003's `reclaimNodeId` paragraph claimed parity with `deregisterNode` that no longer holds. Follow-ups: #1359 (`deregisterNode` has no CLI surface), #1361 (tier stuck on the ejection and never-registered paths).
Closes #1033.
Why
CapacityBondhas shipped the full unbonding surface all along —requestUnbond(amount)starts the window (contracts/src/CapacityBond.sol:615),unbond()withdraws once it matures (:639), and ADR 026:155 names the pair as the only way to lower a bond. But no Rust path reached either call:crates/incentive/src/capacity_bond.rsdeclaredbond/declareMbps/registerNodeand stopped, andNodeCommandhadBond/Registerbut noUnbond. An operator who bonded viadecdn node bondhad no supported way to get TOKEN back out.This is the CLI half #1033's triage note called out as the prerequisite — and since the e2e harness already has the time control it needs (
crates/e2e/src/time.rsexists to 'advance the chain clock across dispute / compliance / timelock / unbond windows'), the e2e half lands here too.What
One state-aware
decdn node unbondcovering all three phases of the window, picked from chain state rather than a flag. Same plan /--dry-run/--json/ idempotent-re-run shape asdecdn node bond.declareMbpsdown if needed, thenrequestUnbondunbond()Amounts:
--to-mbps N(curve-derived),--all,--amount N(base units) — mutually exclusive via a clapArgGroup.Two contract facts that shaped the UX
Both were found by reading
CapacityBond.sol, and both are surfaced to the operator rather than left to a revert:isActivefalse for the WHOLE window. It is a conjunct of the predicate, independent of the remaining bond. So this is a ~14-day outage, not a background operation. A terminal run warns and confirms;--yesbypasses for automation; headless without--yesrefuses rather than assuming consent. The e2e asserts the node really does go inactive while its retained bond still coversminBond.requestUnbond's floor isbondRequired(declaredMbps), notminBond. The contract permits unbonding into an inactive state. So the three flags pick deliberately different floors:--to-mbpsretainsmax(minBond, bondRequired(N))and keeps the operator eligible;--allgoes to the contract's own floor and says so;--amountis pre-checked soBondBelowCurvenever surfaces raw — it fails with thedecdn node bond --mbpsinvocation needed instead.Tests
crates/e2e/tests/g_node_06_unbond.rs(anvil-e2e) drives the production binary through the whole journey against a realCapacityBond: bond up →--to-mbpsreduce → assert inactive → assert the maturing re-run exits non-zero and touches no state → assert an amount flag during a pending request errors → warp pastunlockAt→ withdraw → assert the TOKEN returned and the node is active again → assert a below-curve--amountis rejected before any transaction.k = 12.6,α = 1.2,minBond = 50_000TOKEN, the curve only overtakes the floor around 1000 Mbps, so lower tiers collapse both targets tominBondand the journey would assert nothing. An in-test assertion re-derives this from chain state, so a governance retune of the curve fails loudly rather than silently hollowing out the test.unbond.rsover the pure output/decision functions, including the confirmation gate (split intodecide_confirmationthe wayterms::decideis, so the guard against an accidental window-long outage is testable without a TTY).Verification
Follow-ups filed, not bundled
Both found while reading the contract; neither belongs in a CLI PR:
declareMbpscan never fully unbond (declaredMbpshas one writer, floored at 10 Mbps;deregisterNodedoesn't clear it). This is why--allis documented as 'everything the curve permits' rather than 'exit'.requestUnbondhas no slash/appeal-pending gate, contradicting cli+e2e G-NODE-06: decdn node unbond / capacity reduction #1033's stated negative case. ADR 026 arguably makes the 14-day window the mitigation instead, so the e2e deliberately does not assert either way.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
decdn node unbondcommand.--to-mbps,--all,--amount,--yes, and--jsonoptions.Tests