Staking as datoms: what a sender may ask for, and what the protocol does with it.
urd already had two envelope kinds -- :tx-data for ordinary writes and
:registration for installing an invariant -- each with its own digest and
its own admission function mirroring the other. A third would have made that
a pattern, and the pattern is a bad one: every kind is a separate signed
shape, a separate refusal ordering, and a separate thing a client must
implement.
So staking is ordinary tx-data. A sender writes
[{:urd.stake.intent/op :delegate
:urd.stake.intent/validator "<validator id>"
:urd.stake.intent/amount 1000}]
and that goes through the boundary every other write goes through: the same signature check, the same nonce, the same pricing, the same storage rules, the same invariants. Nothing new on the wire, and a client that can transact can stake.
Solana is the precedent worth naming. Its Stake Program was a builtin inside the validator and has since been converted to an ordinary BPF program invoked like any other; the runtime no longer owns staking, it READS the state staking produces. This is the same move in urd's vocabulary, where the ordinary programming model is datoms rather than accounts.
Writing one of these datoms moves nothing. It records that a sender asked.
apply runs at the end of the block, re-validates every intent against
state the sender does not control -- their balance, the shares they actually
hold, whether the validator exists -- and only then moves value. A malformed,
unaffordable or simply wrong intent is refused there, having paid its fee for
the bytes.
Two things follow, and both are deliberate:
apply is handed
[sender intent] pairs by skuld.block, which knows who signed each
transaction. A :urd.stake.intent/delegator field would be a field the
sender writes, and taking the actor from user data is the mistake
skuld.ledger.authz/verified-author? exists to avoid.stake/undelegate throws on more shares
than are held -- correctly, it is a programming error there -- but here the
argument came off the wire, so it is an ordinary refusal. A block that
could be halted by one bad intent would be a denial of service anyone could
trigger for the price of a transaction.Not a fresh identifier. You need an account to hold the tokens you are
delegating, an account IS a namespace (the hex of a genesis hash), and
keying delegations by it therefore costs nothing and gives every delegation
an owner the protocol can already authenticate. skuld.ledger.stake keeps
delegator ids opaque, so it needs no change to accept them.
Staking as datoms: what a sender may ask for, and what the protocol does
with it.
## Why an intent and not a message
urd already had two envelope kinds -- `:tx-data` for ordinary writes and
`:registration` for installing an invariant -- each with its own digest and
its own admission function mirroring the other. A third would have made that
a pattern, and the pattern is a bad one: every kind is a separate signed
shape, a separate refusal ordering, and a separate thing a client must
implement.
So staking is ordinary tx-data. A sender writes
[{:urd.stake.intent/op :delegate
:urd.stake.intent/validator "<validator id>"
:urd.stake.intent/amount 1000}]
and that goes through the boundary every other write goes through: the same
signature check, the same nonce, the same pricing, the same storage rules,
the same invariants. Nothing new on the wire, and a client that can transact
can stake.
Solana is the precedent worth naming. Its Stake Program was a builtin inside
the validator and has since been converted to an ordinary BPF program
invoked like any other; the runtime no longer owns staking, it READS the
state staking produces. This is the same move in urd's vocabulary, where the
ordinary programming model is datoms rather than accounts.
## An intent is inert, and that is the security argument
Writing one of these datoms moves nothing. It records that a sender asked.
`apply` runs at the end of the block, re-validates every intent against
state the sender does not control -- their balance, the shares they actually
hold, whether the validator exists -- and only then moves value. A malformed,
unaffordable or simply wrong intent is refused there, having paid its fee for
the bytes.
Two things follow, and both are deliberate:
- The ACTOR is never read from the datoms. `apply` is handed
`[sender intent]` pairs by `skuld.block`, which knows who signed each
transaction. A `:urd.stake.intent/delegator` field would be a field the
sender writes, and taking the actor from user data is the mistake
`skuld.ledger.authz/verified-author?` exists to avoid.
- A refused intent does not throw. `stake/undelegate` throws on more shares
than are held -- correctly, it is a programming error there -- but here the
argument came off the wire, so it is an ordinary refusal. A block that
could be halted by one bad intent would be a denial of service anyone could
trigger for the price of a transaction.
## The delegator is an account namespace
Not a fresh identifier. You need an account to hold the tokens you are
delegating, an account IS a namespace (the hex of a genesis hash), and
keying delegations by it therefore costs nothing and gives every delegation
an owner the protocol can already authenticate. `skuld.ledger.stake` keeps
delegator ids opaque, so it needs no change to accept them.(apply-intents state balance-of pairs)Apply pairs of [sender intent] in order.
Returns {:state s :debits {ns n} :results [...]}. :debits are the
balance movements the caller must transact -- this namespace does not touch
the database, so that the whole of it stays a pure function of state and
requests, which is what makes two validators applying the same block agree.
Apply `pairs` of `[sender intent]` in order.
Returns `{:state s :debits {ns n} :results [...]}`. `:debits` are the
balance movements the caller must transact -- this namespace does not touch
the database, so that the whole of it stays a pure function of state and
requests, which is what makes two validators applying the same block agree.(debit-tx-data db debits)Datoms moving debits out of the delegators' balances.
Bonded tokens leave the account entirely rather than being marked reserved. Cosmos does the same -- delegated tokens live in the bonded pool, not the delegator's account -- and the reason is that a reservation is a second number that has to agree with the first forever, which is exactly the kind of invariant that drifts.
Datoms moving `debits` out of the delegators' balances. Bonded tokens leave the account entirely rather than being marked reserved. Cosmos does the same -- delegated tokens live in the bonded pool, not the delegator's account -- and the reason is that a reservation is a second number that has to agree with the first forever, which is exactly the kind of invariant that drifts.
(intents datoms)The intents in datoms, as maps, in a deterministic order.
Reads PRODUCED datoms rather than submitted forms. That is the same rule the
rest of this system runs on and it has been got wrong three times: submitted
forms do not name what a transaction touches, so a :db/retractEntity or a
lookup ref would hide an intent from anything reading the request instead of
the result.
Only ADDED datoms count. Retracting an intent attribute is not a request.
The intents in `datoms`, as maps, in a deterministic order. Reads PRODUCED datoms rather than submitted forms. That is the same rule the rest of this system runs on and it has been got wrong three times: submitted forms do not name what a transaction touches, so a `:db/retractEntity` or a lookup ref would hide an intent from anything reading the request instead of the result. Only ADDED datoms count. Retracting an intent attribute is not a request.
The operations a sender may request.
:redelegate is deliberately absent. Cosmos has it and pays for it with the
transitive-redelegation rules that stop redelegation hopping -- an
immature redelegation into a validator blocks new ones out of it, which is a
whole state machine of its own. 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.
The operations a sender may request. `:redelegate` is deliberately absent. Cosmos has it and pays for it with the transitive-redelegation rules that stop `redelegation hopping` -- an immature redelegation into a validator blocks new ones out of it, which is a whole state machine of its own. 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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |