Skip to content

Implement decdn node bond — idempotent stake-to-capacity-tier (ADR 019 §2.1–2.2) #932

Closed

Description

@alpergundogdu

Problem

ADR 019 Phase 2.1/2.2 require an operator to approve TOKEN, bond it, and declareMbps before registerNode (#929). There is no command for this — operators must hand-compute the bond amount (k × Mbps^α) and submit three transactions in order.

Decision: one idempotent command, not flags on register

bond() is additive (activeBond += amount) while registerNode() is one-shot. Bundling them into register would make a partial failure (bond lands, declareMbps reverts) unsafe to retry — a re-run would double-bond. So this is a separate command, split at the contract's real transaction boundary, matching the repo's one-subcommand-per-operation convention.

decdn node bond --mbps <N>

Idempotent "stake to capacity tier N". The operator passes only --mbps; the TOKEN amount is computed from the contract so nobody hand-calculates the curve.

  1. Read bondRequired(N), activeBond(operator), minBond(), declaredMbps(operator), token(), and the current ERC20 allowance from chain.
  2. target = max(minBond, bondRequired(N)) (registerNode needs activeBond ≥ minBond AND ≥ bondRequired(declaredMbps)).
  3. shortfall = target.saturating_sub(activeBond). If shortfall > 0: check token.balanceOf(operator) ≥ shortfall (clear error otherwise), approve the shortfall if allowance < shortfall, then bond(shortfall) — top up to target, never a flat re-bond, so re-running after a partial failure converges instead of over-bonding.
  4. declareMbps(N) unless declaredMbps(operator) == N already (skip the pointless tx).
  5. Report tier, prior/target bond, amount bonded, and tx hashes. --dry-run prints the plan without submitting; --json for machine output.

Band validation ([minCapacityMbps, maxCapacityMbps]) is left to the on-chain declareMbps revert (DeclaredCapacityOutOfBand) rather than re-checked client-side.

Implementation notes

Out of scope

Metadata

Metadata

Assignees

Labels

rust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions