Balances, nonces, and actually charging for a transaction.
Everything before this namespace computed a price and charged nobody.
settle returns the transaction to APPLY: the sender's own tx-data, plus
the ownership stamps, plus the datoms that debit the sender, advance the
nonce, and record the fee. One transaction.
Splitting them would be a divergence bug waiting for a crash: a node that applied the effects and died before the debit would carry a different balance than its peers forever, and the app-hash comparison would find it one block later with no way to say which half was right. Making the fee part of the same transaction means there is no window.
It also means a REFUSED transaction still produces a transaction: the fee and the nonce bump, without the sender's effects. A refusal that wrote nothing would leave the nonce unspent, and a transaction that can be retried for free after being refused is a free retry loop.
n+1 exactly. Monotonic-but-gappy is enough to stop a replay and is simpler
to implement, but sequential buys two things worth the strictness: a
mempool can order an account's pending transactions without guessing, and an
account cannot burn its own nonce space by jumping to a large value.
The nonce lives on the account entity, so it advances in the same transaction as the fee -- there is no separate replay table to keep consistent with the balance.
There is nothing to take. This deliberately leaves cheap spam from empty accounts to the layer that can actually stop it: the mempool drops a transaction whose sender cannot cover the base fee, before it reaches consensus. Doing it here would mean pretending to charge an account with a zero balance, which is bookkeeping theatre.
The cost an attacker still imposes is one signature verification at the
network edge. That is the cheapest check we have, and it is why
urd.consensus.auth refuses an unknown author before any crypto runs.
Balances, nonces, and actually charging for a transaction. Everything before this namespace computed a price and charged nobody. ## The charge is tx-data, not a side effect `settle` returns the transaction to APPLY: the sender's own tx-data, plus the ownership stamps, plus the datoms that debit the sender, advance the nonce, and record the fee. One transaction. Splitting them would be a divergence bug waiting for a crash: a node that applied the effects and died before the debit would carry a different balance than its peers forever, and the app-hash comparison would find it one block later with no way to say which half was right. Making the fee part of the same transaction means there is no window. It also means a REFUSED transaction still produces a transaction: the fee and the nonce bump, without the sender's effects. A refusal that wrote nothing would leave the nonce unspent, and a transaction that can be retried for free after being refused is a free retry loop. ## Nonces are sequential, not merely increasing `n+1` exactly. Monotonic-but-gappy is enough to stop a replay and is simpler to implement, but sequential buys two things worth the strictness: a mempool can order an account's pending transactions without guessing, and an account cannot burn its own nonce space by jumping to a large value. The nonce lives on the account entity, so it advances in the same transaction as the fee -- there is no separate replay table to keep consistent with the balance. ## An account that cannot pay is refused and charged nothing There is nothing to take. This deliberately leaves cheap spam from empty accounts to the layer that can actually stop it: the mempool drops a transaction whose sender cannot cover the base fee, before it reaches consensus. Doing it here would mean pretending to charge an account with a zero balance, which is bookkeeping theatre. The cost an attacker still imposes is one signature verification at the network edge. That is the cheapest check we have, and it is why `urd.consensus.auth` refuses an unknown author before any crypto runs.
(account db hex){:eid :balance :nonce} for hex, or nil when the key has no account.
No account means no balance means cannot transact. Genesis credits the initial set; everyone else is credited by someone who already has funds.
`{:eid :balance :nonce}` for `hex`, or nil when the key has no account.
No account means no balance means cannot transact. Genesis credits the
initial set; everyone else is credited by someone who already has funds.(collected-fees db since-tx)Total recorded by transactions since since-tx (exclusive), and the
transactions counted.
Distribution reads this rather than a running counter, because a counter is a row every transaction would have to write -- the contention this design exists to avoid.
A fee datom only counts if it sits on ITS OWN transaction entity, i.e. the
datom's entity equals the datom's tx. Datalog cannot express that constraint
conveniently, and the naive query -- match any :urd/fee and sum it --
counted a fee planted on any row at all. A sender who owned a row, or who
chose an unallocated id above the transaction watermark, minted money at
distribution: measured, 999,999,999 credited for a fee of 1,375.
skuld.ledger.ownership/protocol-attributes is the primary defence and now
refuses :urd/fee anywhere but a transaction entity. This is the second
one, and it is the cheaper of the two to be sure of.
Total recorded by transactions since `since-tx` (exclusive), and the transactions counted. Distribution reads this rather than a running counter, because a counter is a row every transaction would have to write -- the contention this design exists to avoid. ## Why this walks datoms instead of querying A fee datom only counts if it sits on ITS OWN transaction entity, i.e. the datom's entity equals the datom's tx. Datalog cannot express that constraint conveniently, and the naive query -- match any `:urd/fee` and sum it -- counted a fee planted on any row at all. A sender who owned a row, or who chose an unallocated id above the transaction watermark, minted money at distribution: measured, 999,999,999 credited for a fee of 1,375. `skuld.ledger.ownership/protocol-attributes` is the primary defence and now refuses `:urd/fee` anywhere but a transaction entity. This is the second one, and it is the cheaper of the two to be sure of.
(credit-tx-data db hex amount)(credit-tx-data db hex amount genesis)Give hex amount. Upserts on the unique key, so it also creates the
account -- which is how genesis funds the initial holders.
The 3-arity registers the account's genesis record at the same time. That pairing is deliberate: an account with a balance but no genesis can be funded and can never transact, because nothing can authorise a key for it.
Give `hex` `amount`. Upserts on the unique key, so it also creates the account -- which is how genesis funds the initial holders. The 3-arity registers the account's genesis record at the same time. That pairing is deliberate: an account with a balance but no genesis can be funded and can never transact, because nothing can authorise a key for it.
(distribute-tx-data db total validators)Split total among validators in proportion to their power.
validators is {hex power}. Returns tx-data crediting each.
Integer division, and the remainder is deliberately left UNDISTRIBUTED rather than given to anyone: handing the dust to the first validator by iteration order would make the reward depend on map ordering, which differs between nodes and is exactly the kind of divergence an app-hash comparison would find a block later with no way to attribute it.
Split `total` among `validators` in proportion to their power.
`validators` is `{hex power}`. Returns tx-data crediting each.
Integer division, and the remainder is deliberately left UNDISTRIBUTED
rather than given to anyone: handing the dust to the first validator by
iteration order would make the reward depend on map ordering, which differs
between nodes and is exactly the kind of divergence an app-hash comparison
would find a block later with no way to attribute it.Where a transaction records what it paid.
On the TRANSACTION entity, which is unique per transaction, so recording a fee contends with nothing.
Where a transaction records what it paid. On the TRANSACTION entity, which is unique per transaction, so recording a fee contends with nothing.
A key's hex. :db.unique/identity, so the account entity is the key
entity -- the same one skuld.ledger.ownership points :urd/owner at.
One entity per key, carrying its balance, its nonce, and the rows it owns. Two entities would let a balance and an ownership record disagree about who a key is.
A key's hex. `:db.unique/identity`, so the account entity is the key entity -- the same one `skuld.ledger.ownership` points `:urd/owner` at. One entity per key, carrying its balance, its nonce, and the rows it owns. Two entities would let a balance and an ownership record disagree about who a key is.
Installed by genesis. Kontor runs :schema-flexibility :write, so none of
this can be implicit.
Installed by genesis. Kontor runs `:schema-flexibility :write`, so none of this can be implicit.
(settle db {:keys [sender nonce tx-data]} {:keys [schedule]})Price, authorise and charge a transaction. Returns what to apply.
{:ok? was the sender's tx-data accepted
:reason why not
:fee charged either way
:apply the tx-data to transact -- effects + stamps + charge, or
just the charge when refused
:violations ...}
envelope is {:sender <hex> :nonce n :tx-data [...]}. The SIGNATURE is
not checked here -- skuld.boundary/admit does that at the edge, before this
is reached, for the same reason urd.consensus.auth verifies before the
state machine sees anything.
Order: nonce, then funds, then price, then scope. Each is cheaper than the next and each can refuse on its own.
The accounting datoms are NOT themselves priced -- charging for the charge is circular, since the fee would change the datoms that carry it. They are protocol overhead, covered by the base fee. The consequence is that the applied transaction contains a few more datoms than were paid for, which is a constant per transaction and not a lever anyone can pull.
Price, authorise and charge a transaction. Returns what to apply.
{:ok? was the sender's tx-data accepted
:reason why not
:fee charged either way
:apply the tx-data to transact -- effects + stamps + charge, or
just the charge when refused
:violations ...}
`envelope` is `{:sender <hex> :nonce n :tx-data [...]}`. The SIGNATURE is
not checked here -- `skuld.boundary/admit` does that at the edge, before this
is reached, for the same reason `urd.consensus.auth` verifies before the
state machine sees anything.
Order: nonce, then funds, then price, then scope. Each is cheaper than the
next and each can refuse on its own.
The accounting datoms are NOT themselves priced -- charging for the charge
is circular, since the fee would change the datoms that carry it. They are
protocol overhead, covered by the base fee. The consequence is that the
applied transaction contains a few more datoms than were paid for, which is
a constant per transaction and not a lever anyone can pull.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 |