Liking cljdoc? Tell your friends :D

Staking

Staking is an ordinary signed transaction — no second envelope kind, no separate signing scheme.

[{:db/id "intent"
  :urd.stake.intent/op :delegate
  :urd.stake.intent/validator "<validator namespace>"
  :urd.stake.intent/amount 3000000}]

Solana is the precedent: its Stake Program was a builtin inside the validator and is now an ordinary program, so the runtime reads staking state rather than owning it.

Three operations

opextra fieldsrefuses on
:create-validatorcommission-num, commission-den:validator-exists, :bad-commission, :not-your-namespace
:delegateamount:no-such-validator, :bad-amount, :insufficient-balance
:undelegateamount:no-such-validator, :no-delegation, :bad-amount

A validator id is its operator's namespace, so you can only create one for yourself — otherwise operator ids could be squatted before their owners arrived.

Commission travels as a numerator and a denominator, not a rational: datahike has no ratio type, and hasch/edn-hash has no coercion for a Ratio, so one could never reach a digest. Out of [0,1] is refused, not clamped — a validator that asked for 150% and silently got 100% has been given something it did not ask for.

You ask in tokens; the protocol converts to shares. That is what keeps a slash invisible to the request: the same intent means the same fraction of the same stake whether or not the validator was slashed between signing and application.

An intent that cannot be honoured is refused, never thrown. It arrived over the wire; a block that could be halted by one bad intent would be a denial of service anyone could buy for the price of a transaction.

Intents within one block see each other's spending. Without that netting, 6,000,000 delegated twice from a balance of 10,000,000 gave a validator 12,000,000 of stake nobody held.

:redelegate is deliberately absent. Cosmos has it and pays with transitive rules that stop "redelegation hopping"; undelegate-then-delegate is the same thing at the cost of an unbonding period, and adding the fast path before the slow one works is how the hard part gets skipped.

Shares, not tokens

A delegation holds shares. A slash reduces the validator's token balance and leaves every share count alone, so one write dilutes every delegator proportionally — instead of iterating over all of them.

Shares are scaled by 10¹⁸ and held as BigInt: 10⁶ tokens × 10¹⁸ overflows a long.

A validator with shares outstanding against zero tokens has no defined redemption rate — any delegation into it divides by zero. That throws, and is also one of the conservation checks.

Rewards are F1

O(1) in the number of delegators. The validator accumulates a cumulative reward-per-token ratio; a delegation records the period it joined at; what is owed is the difference between the ratio then and now, times the stake.

The ratio is fixed-point at 10¹⁸, not an exact rational, and that is a deliberate choice rather than an inherited limitation. Adding rationals multiplies denominators, and measured on a cumulative reward ratio the reduced denominator grew ~26 bits per period:

periodsdenominator
10294 bits
1002,748 bits
40010,363 bits

That is a multi-megabyte integer after a million blocks — stored, hashed into the app-hash, and compared every block.

Truncation dust is routed, not discarded: it goes to the community pool and leaves :outstanding in the same step, or solvency drifts one unit per period forever.

Participation-weighted

The denominator keeps absentees; the payout does not. An absent validator's share falls to the community pool.

Both alternatives are worse. Sui's lets a two-thirds cartel collect an honest validator's income. Cosmos ignores the vote flag entirely — with a TODO from 2018 still in the file.

A :nil vote counts as participation. It is a vote; only :absent is not.

Slashing

Three properties worth knowing:

Retroactive. An unbonding entry is stamped with the height it was created at, which is what makes it slashable for an infraction at or after that height. That window is the only reason unbonding takes time.

Power at the infraction, not now. A slash takes the power the validator held when it misbehaved, passed in rather than recomputed — recomputing produced a measured 10× over-slash landing on a delegator who joined afterwards.

Recorded at the height applied. The slash is stamped with when it landed, not when the infraction happened, because that is what later reward calculations must reconcile against.

Rescaling has to carry: reducing over successive slashes and then computing the final segment from the original snapshot pays stake × (1 − f_last) instead of stake × ∏(1 − fᵢ).

Liveness: jailing, not slashing

A window of 100 blocks at half participation. Cross it and the validator is jailed — removed from the active set — for ten minutes.

No downtime slash, and that is a departure from Cosmos. With participation-weighted rewards, absence is already priced continuously: every missed block costs its fees. Slashing on top charges twice for one fault, and the second charge lands mostly on delegators who did nothing.

A newly bonded validator is not jailable until a full window has passed, and unjailing resets the window — otherwise it would be re-jailed immediately for absence it already paid for.

Equivocation is the one fault that takes stake, and it tombstones: a fault detected with a delay can be discovered many times for one key compromise, so it needs a cap, and the tombstone is the cap.

The active set

Sorted by power descending, then id ascending — a total order, so two nodes cannot disagree about which of two equal-power validators is in. Jailed validators are excluded (jailing is removal). Zero power stops the scan. Capped at max-validators.

Ranking uses potential power — an unbonded validator with stake must be rankable, or it could never enter the set.

The set's total power has a ceiling of 2³⁷. That is not a BFT bound; it is arithmetic headroom for the consensus layer's proposer-priority accumulator, kept well below the platform maximum because ClojureScript numbers are doubles and hold exact integers only to 2⁵³.

Updates are emitted as a diff, power zero meaning removal, and deliberately not sorted here — the consensus layer canonicalises in one place, because CometBFT #3181 was two honest nodes disagreeing about the proposer after the application emitted updates in different orders.

Epochs

Stake-driven set changes wait for an epoch boundary (default: 10 blocks). Jailing does not.

Both directions are real, and Cosmos's ADR-039 argues both. For waiting: round-robin's proposer is (mod height (count validators)) over sorted ids, so every set change reindexes the rotation — and once staking is reachable from a transaction, that index is something an attacker can churn on demand. Against: a jailed validator held in the set keeps taking proposer turns it will not answer, which defeats the point of having jailing at all.

So economic churn waits and provable absence does not. :epoch-length 1 is exactly the old behaviour, which is ADR-039's own framing of immediate execution as the degenerate epoch.

A change computed mid-epoch is not lost — the baseline only advances when updates are actually emitted, so it accumulates into the diff the boundary block reports.

Epochs bound when the set changes, not how much. Solana also caps churn at ~9% of active stake per epoch; skuld has no such rate limit.

Stored as datoms

The stake model was once one EDN blob rewritten whole every block. Measured:

blob per block
4 validators, 0 delegations1.7 KB
4 validators, 1,000 delegations114 KB
100 validators, 10,000 delegations1.16 MB

It is now an entity per validator, delegation and unbonding pair, with the fields an invariant must read as real attributes — a Datalog query cannot look inside a string. datahike writes no datom for an unchanged value, so persistence became proportional to change: a block touching one delegation writes about one delegation.

What stays in a per-entity blob is bounded by construction: a validator's reward internals and signing window, a delegation's period snapshot, an unbonding pair's entries.

Ids travel as pr-str/read-string, not str/keyword — production ids are namespace strings and most tests use keywords, and (str :v1) loses the difference, which would pass every test and merge two validators in production.

Tombstones

undelegate removes a delegation at its last share, so it simply stops appearing in the model. A save that wrote only what the model contains left the old row at full share count — the next block read it back, the delegation resurrected, and the share-conservation check then halted every node, permanently, because the datom persists and replays on restart.

An ordinary delegator triggered that by unbonding completely, for the price of two transactions. Vanished rows are now zeroed rather than left; zeroing rather than retracting because the read path already drops zero-share rows.

Matured delegator principal is credited to its liquid account in the same commit as the final block height. The block checks delegation against liquid balance available after storage collateral.

Delegators can request :withdraw-rewards for their own position. Validator operators can request :withdraw-commission and :unjail for their own namespace. A share change credits already-earned rewards in the same block.

Not built

Verified by grep, and stated on the README's front page:

  • handle-equivocation has no authenticated evidence entry point. Double-sign slashing is machinery with nothing driving it from a block.
  • Supply reconciliation runs as an operator audit using an independently known genesis supply.

See also

Ownership for why intents are inert · Conservation for the checks over this state · Economics for fees and issuance

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close