Repository navigation
fix(contracts,e2e): make deregistration a real bond exit; settle the unbond gate question (#1351, #1352, #1354) - #1360
Conversation
…unbond gate question (#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` is the only writer of `declaredMbps` and cannot set it back to 0 (the band floor `MIN_CAPACITY_FLOOR_MBPS = 10` is not governance-lowerable), and `deregisterNode` left the tier standing. So the curve floor was permanent: an operator who declared 10 Mbps was locked out of `bondRequired(10)` worth of TOKEN forever, whether or not they still ran a node. This is not a design question — ADR 003 § Node Registry already asserts the intended behaviour ("a full exit is just `deregisterNode` followed by `unbond()`", "an operator who changes their mind can re-register without re-funding"). The contract contradicted its own source of truth. `deregisterNode` now clears `declaredMbps`, so the documented sequence works: `deregisterNode()` -> `requestUnbond(activeBond)` -> window -> `unbond()`. The clear is announced via `MbpsDeclared(operator, old, 0)` rather than written silently — that event is the only tier signal an indexer has, and a second quiet writer would desync it. It is skipped entirely when no tier was ever declared, so a never-declared operator pays no SSTORE and logs no 0 -> 0 no-op. No new event or selector, so the frozen interface is untouched; +105 bytes of runtime, leaving 1,214 of EIP-170 headroom. **#1352 — no slash/appeal gate on `requestUnbond`, deliberately.** #1033 listed "unbond blocked while a slash/appeal is pending" as a negative case. That was wrong, and the contract is right. ADR 026 § Unbonding window already argues the 14-day window outlasts SlashJudge's 5-day evidence window by 9 days and that slashing during unbonding is permitted, so a gate adds nothing an honest challenger needs — while handing a griefing challenger an indefinite freeze on an honest operator's exit, with no expiry to unstick a challenge that is never revealed. Recorded in ADR 026 in place; the spec anchor #1352 cites 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 missing assertion is deliberate, so nobody "fixes" it later. **#1354 — four `decdn node unbond` behaviours only the real binary can reach.** `--dry-run` and the headless confirmation refusal go in before step 1 while the state is clean and cost no chain time; a below-crossover `--to-mbps 10` and a real `--all` release are appended after step 6. The `--all` leg is the one that had never run end to end — step 3 only reached its already-in-flight error — and it is where `--all`'s bare curve floor visibly differs from `--to-mbps`'s `max(minBond, curve)`: the same tier retains 199.696… TOKEN under one and 50,000 under the other. Every expected amount is re-derived from chain state, so a governance retune of the curve fails loudly rather than passing vacuously. Tests: all four new e2e legs and three of the four new Solidity tests were mutation-verified (drop the dry-run short-circuit; make `--all` retain `minBond`, or one base unit above the curve; drop `--to-mbps`'s `minBond` floor; turn the headless refusal into a bypass; remove the `declaredMbps` clear). The fourth Solidity test guards the `oldMbps != 0` skip and was verified by removing that guard. The journey runs in ~18 s locally against a 780 s ceiling, so `OVERALL_TIMEOUT` is unchanged. `.gas-snapshot` regenerated. Follow-up: #1359 — `deregisterNode` still has no CLI surface, so the exit path is named in `unbond`'s docs as a raw contract call. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Warning Review limit reached
Next review available in: 37 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 (9)
WalkthroughDeregistration now clears a node operator’s declared capacity tier without moving the bond. The contract tests cover event behavior, full exit, and re-registration. ADRs, operator procedures, CLI documentation, gas snapshots, and end-to-end tests describe and validate the updated unbonding lifecycle. ChangesNode exit lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Operator
participant CLI
participant CapacityBond
participant UnbondingWindow
Operator->>CLI: request unbond or full exit
CLI->>CapacityBond: deregisterNode()
CapacityBond->>CapacityBond: clear declaredMbps
CLI->>CapacityBond: requestUnbond(amount)
CapacityBond->>UnbondingWindow: start unlock period
Operator->>CLI: unbond after unlock
CLI->>CapacityBond: unbond()
CapacityBond-->>Operator: release permitted bond
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 |
Contracts coverageLine coverage: 89.16% (2509/2814 lines) |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
Pull request overview
This PR aligns CapacityBond’s unbonding/exit semantics with the ADRs by making deregistration clear the declared-capacity tier (enabling full bond exit), documenting the intentional absence of a slash/appeal gate on requestUnbond, and extending the G-NODE-06 e2e journey to cover real-binary-only unbond behaviors.
Changes:
- Contracts:
deregisterNodenow clearsdeclaredMbps(with an explicitMbpsDeclared(old, 0)signal) so a full exit can proceed viaderegisterNode() -> requestUnbond(activeBond) -> unbond(). - Tests: add Solidity coverage for deregistration tier-clearing, full exit, and re-registration behavior; extend e2e coverage for
--dry-run, headless confirmation refusal, below-crossover--to-mbps, and a real--allrelease. - Docs/ADRs: update ADR 003/019/026 and operator key-rotation appendix to reflect the clarified exit sequence and the deliberate “no slash/appeal gate” decision.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/e2e/tests/g_node_06_unbond.rs | Adds additional G-NODE-06 legs to exercise dry-run, headless refusal, below-crossover --to-mbps, and a real --all unbond path. |
| crates/cli/src/commands/unbond.rs | Updates command documentation to clarify that --all is not a full exit while registered; exit requires on-chain deregisterNode. |
| contracts/src/CapacityBond.sol | Clears declaredMbps on deregisterNode, emitting MbpsDeclared(old, 0) to keep indexers consistent. |
| contracts/test/CapacityBond.t.sol | Adds tests covering tier clearing on deregistration, “never declared” emission behavior, full exit flow, and re-registration requirements. |
| contracts/.gas-snapshot | Regenerates gas snapshot to reflect bytecode and test-suite changes. |
| adr/appendix-operator-key-rotation.md | Updates key-rotation procedure to use requestUnbond(activeBond) and clarifies declaredMbps clearing implications. |
| adr/026-tokenomics.md | Documents full-exit semantics via deregistration and records that requestUnbond has no slash/appeal-pending gate by design. |
| adr/019-node-onboarding.md | Notes that deregistration clears declaredMbps and that re-registration requires re-declaring capacity. |
| adr/003-payments.md | Updates the node-registry section to reflect tier-clearing on deregistration and the correct unbonding sequence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 81.54% (was 81.52%, ▲ +0.02%) — 52824/64785 lines
History
|
… can actually reach Review follow-ups on #1360. Three independent reviews converged on the same defect: the ADR text I added asserted an invariant the contract does not have. `deregisterNode` requires an active node, but `declareMbps` carries no such gate. So a tier can be declared in states from which it can never be cleared, and in each the operator stays pinned at `bondRequired(declaredMbps)`: - bonded and declared but never registered — the state `decdn node bond --mbps N` leaves behind on its own; - auto-ejected on slashing, blacklist-ejected, or displaced by `reclaimNodeId`. Measured on an operator onboarded at 1000 Mbps and slashed to auto-ejection: 10,126 TOKEN remains, the standing floor is 50,161, `deregisterNode` reverts `NodeNotActive` and `requestUnbond(1)` reverts `BondBelowCurve` — not one wei is withdrawable, and freeing it costs ~4x the trapped amount in fresh capital. That is not a regression (before this branch the floor was permanent for every operator), and it is not fixed here: clearing the tier on the involuntary paths would let a just-slashed operator immediately begin withdrawing their entire remaining bond, which is a slashing-economics decision for ADR 026 rather than a mechanical fix. It is now stated accurately in ADR 026, pinned by a test, and tracked in #1361. `test_ejectedOperator_keepsTheTierAndCannotUnbond` fences the boundary so closing the gap is a deliberate, visible change. `test_deregisterNode_preservesUnbondingSlashStampAndFirstBonded` fences the other direction — this commit's predecessor turned `deregisterNode` from a pure deactivator into a state-clearing function, which invites a later "finish the cleanup" refactor. Deleting `unbondingOf` there would orphan escrowed TOKEN with no withdrawal path; clearing `_slashedAtEpoch` would let an operator launder a slash out of their ADR 036 voting weight by cycling deregister/re-register. Mutation-verified by adding `delete unbondingOf[msg.sender]` to `deregisterNode`. Doc corrections, all verified against the contract rather than carried over: - ADR 019 § Re-Onboarding said "two differences" while listing three, and its new item 3 was false for the auto-ejection cohort the section exists to serve. - The key-rotation appendix still claimed "only `deregisterNode` triggers unbonding" fifty lines below the steps that were fixed for saying exactly that. - ADR 003's `reclaimNodeId` paragraph said it behaves "exactly as `deregisterNode`" (no longer true — reclaim does not clear the tier) and repeated the `unbond()`-starts-the-window error corrected earlier in the file. - Three sites quoted ADR 003's pre-rewrite sentence verbatim, preserving inside quotation marks the very wording this branch replaced. - The appendix's new `declaredMbps` row sat in the "does not carry over" table while its own text conceded the tier survives that path; moved to "survives" alongside its `firstBondedAt` precedent. - `MbpsDeclared` is the only *log-based* tier signal, not the only signal — `declaredMbps` is a public mapping and ADR 016 documents indexers polling it. - The e2e note cited "ADR 026 § Unbonding window", which is not a section. Also: the `declaredMbps` NatSpec now states the invariant (every write emits `MbpsDeclared`) rather than counting writers, which would go stale silently the moment #1361 adds a third; e2e legs 7-9 assert `phase` on their withdrawals so a surprise reports by name instead of cascading into a bare non-zero exit two legs later; and `_onboardAtTier` reads `minBond` off the contract like its `_bondForMbps` neighbour. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review round: three agents (correctness, test coverage, comment/ADR accuracy)All three converged on the same defect, and it was mine — not in the contract change, but in the ADR text I wrote around it. Fixed in The findingADR 026 asserted "leaving the active set is the only thing that releases [the curve floor]". False.
Measured rather than reasoned (throwaway Foundry probe, since removed): an operator onboarded at 1000 Mbps and slashed to auto-ejection keeps 10,126 TOKEN against a standing floor of 50,161. Why it is not fixed hereClearing the tier inside Note this is not a regression — before this branch the floor was permanent for every operator, not just ejected ones. ChangesTests (both mutation-verified):
Doc corrections — each verified against the contract, not carried over:
Robustness: the Not taken
Re-verified: |
…1361) (#1362) Six filed review follow-ups from the #1360 and #1341 reviews, plus the residual half of #1347. - #1361 — `CapacityBond.declareMbps(0)` accepted from an inactive operator, releasing a tier four deactivation paths could otherwise never clear. Active operators still revert. +49 bytes. - #1359 — new `decdn node deregister`; `unbond --all` issues `declareMbps(0)` for unregistered operators, without which #1361 had no CLI path. - #1348 — `decdn_protocol::Region` newtype; `region_hint` `String` -> `Option<Region>`; `PEER_CACHE_VERSION` 1->2. - #1349 — registry retry budget made aggregate across pages; `--timeout-ms` bounds the registry read. - #1347 — `tx::run_then_cleanup` extracted and tested; deferral note corrected. - #1346 — `[cache] peer_cache_path` dropped from ADR 012. A five-agent review before opening the PR found and fixed: the discovery timeout cancelling the ADR-012 peer-cache fallback; a "trapped bond" justification overstated ~100x (a tier-down declaration always released all but `bondRequired(minCapacityMbps)` — 199.7 of 20,252.7 TOKEN was actually trapped); two vacuous tests that passed with their feature mutated out; `--region usa` silently ignored; and stale claims in ADR 003 and the contract NatSpec. Copilot review: fixed `Region`'s deserializer echoing rejected input into operator-facing errors. Pushed back on a claimed missing `Future` import — it is in the Rust 2024 prelude and the crate compiles. Closes #1346, #1347, #1348, #1349, #1359, #1361.
Closes #1351, closes #1352, closes #1354 — the three surviving follow-ups from #1033/#1353, all on one surface:
CapacityBondunbonding semantics, ADR 026/003, and the G-NODE-06 journey.#1351 — an operator that ever declared a tier could never fully unbond
requestUnbondenforcesactiveBond >= bondRequired(declaredMbps);declareMbpsis the only writer ofdeclaredMbpsand cannot set it back to 0 (the band floorMIN_CAPACITY_FLOOR_MBPS = 10is not governance-lowerable);deregisterNodeleft the tier standing. The curve floor was therefore permanent — an operator who declared 10 Mbps was locked out ofbondRequired(10)worth of TOKEN forever, whether or not they still ran a node.This turned out not to be an open design question. ADR 003 § Node Registry already asserts the intended behaviour — "a full exit is just
deregisterNodefollowed byunbond()" and "an operator who changes their mind can re-register without re-funding". The contract contradicted its own source of truth.deregisterNodenow clearsdeclaredMbps, making the documented sequence work:The clear is announced via
MbpsDeclared(operator, old, 0)rather than written silently — that event is the only tier signal an indexer has, so a second quiet writer would desync it. It is skipped when no tier was ever declared, so a never-declared operator pays no SSTORE and logs no0 -> 0no-op.InterfaceFreezeis untouched..gas-snapshotregenerated.#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; the contract is right.
ADR 026 § Unbonding window already argues the 14-day window outlasts
SlashJudge's 5-day evidence window by 9 days and that slashing during unbonding is permitted — so a gate adds nothing an honest challenger needs, while handing a griefing challenger an indefinite freeze on an honest operator's exit (a challenge that is never revealed has no expiry to unstick it). Recorded in ADR 026 in place.Note the spec anchor #1352 cites (
internal/Product/gaps-and-e2e-test-specs.md#g-node-06) does not exist — no file in the workspace contains the stringG-NODE-06— so the wrong text lived only in the body of the closed #1033. The G-NODE-06 module docs now state that the missing assertion is deliberate, so a future contributor does not "fix" the gap by asserting a gate that must not exist.#1354 — four
decdn node unbondbehaviours only the real binary can reach--dry-runand the headless confirmation refusal go in before step 1, while the state is still clean; both cost zero chain time. A below-crossover--to-mbps 10and a real--allrelease are appended after step 6.The
--allleg is the one that had never run end to end — step 3 only reached its already-in-flight error — and it is where--all's bare curve floor visibly diverges from--to-mbps'smax(minBond, curve): at the same tier one retains 199.696… TOKEN and the other 50,000. Every expected amount is re-derived from chain state, so a governance retune of the curve fails loudly instead of passing vacuously.Verification
Every new e2e leg and three of the four new Solidity tests are mutation-verified, not merely green:
dry_runshort-circuit--to-mbpsdrops itsminBondfloor199696542250100298769vs50000000000000000000000)--allretainsminBond, or one base unit above the curvedeclaredMbpsclearoldMbps != 0skiptest_deregisterNode_emitsNoMbpsEventWhenNeverDeclaredforge test— 757 passedFOUNDRY_PROFILE=ci forge build --sizes --deny warnings,forge fmt --check, solhint — cleancargo nextest run --workspace— 2574 passedcargo nextest run -p decdn-e2e --features anvil-e2e --test g_node_06_unbond— passes in ~18 s against the 780 sOVERALL_TIMEOUT, so the constant is unchangedpre-commit run --all-files— cleanNote the e2e drives the prebuilt
target/debug/decdn, socargo build -p decdn-cliis required before the journey picks up a CLI change — the first mutation run passed misleadingly until that was accounted for.Follow-up
#1359 —
deregisterNodestill has no CLI surface, so a full exit is expressible on-chain but not fromdecdn. Until it lands,unbond's module docs name the raw contract call, matching the precedent insetup.rs's already-registered error.Out of scope
#1346, #1348 and #1349 target code that only exists on the still-open #1341 and must be stacked on that branch.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests