Liking cljdoc? Tell your friends :D

skuld.block

One block: the whole application, in the order it has to happen.

Everything below this namespace is a pure function or a single-transaction boundary. This is where they compose into the thing a validator actually runs, and the composition is almost entirely about ORDER.

The order is load-bearing

mint -> allocate -> liveness -> transactions -> staking intents
     -> set changes -> persist -> conservation

Taken from Cosmos, where it is mint -> distribution -> slashing -> evidence -> staking-EndBlock and the comment explaining it is worth more than the code: distribution must run BEFORE slashing so that rewards are allocated against the stake distribution that actually did the work. Slash first and you have allocated rewards against stake that no longer exists, leaving them stranded with nothing to pay them from.

The same reasoning puts liveness before transactions here: a validator jailed this block should not be paid for it, and jailing is what removes it from the set.

Why the stake state is persisted into the same database

Not as a convenience. urd's app-hash exists to catch divergence one block after it happens, and it covers what is in the database. Stake state held beside the database is stake state where two nodes can silently disagree about a balance forever -- which is precisely the failure apphash defaults to REQUIRED in order to prevent.

It is stored two ways, deliberately:

an entity per validator, delegation and unbonding pair, with the fields an invariant must read as real attributes -- see the projection note further down, and save-stake-tx-data. It used to be one EDN blob under :urd.stake/state, rewritten whole every block; that attribute is gone.

:urd.stake/globals the scalars that are not per-entity: height, time, the community pool, the last announced set. :urd.stake/power one datom per bonded validator, so an invariant can gate on whether the sender is a current validator.

Both are in the urd.stake namespace, which ownership/protocol-attribute? refuses to let any sender write.

One block: the whole application, in the order it has to happen.

Everything below this namespace is a pure function or a single-transaction
boundary. This is where they compose into the thing a validator actually
runs, and the composition is almost entirely about ORDER.

## The order is load-bearing

    mint -> allocate -> liveness -> transactions -> staking intents
         -> set changes -> persist -> conservation

Taken from Cosmos, where it is `mint -> distribution -> slashing ->
evidence -> staking-EndBlock` and the comment explaining it is worth more
than the code: distribution must run BEFORE slashing so that rewards are
allocated against the stake distribution that actually did the work. Slash
first and you have allocated rewards against stake that no longer exists,
leaving them stranded with nothing to pay them from.

The same reasoning puts liveness before transactions here: a validator
jailed this block should not be paid for it, and jailing is what removes it
from the set.

## Why the stake state is persisted into the same database

Not as a convenience. urd's app-hash exists to catch divergence one block
after it happens, and it covers what is in the database. Stake state held
beside the database is stake state where two nodes can silently disagree
about a balance forever -- which is precisely the failure `apphash` defaults
to REQUIRED in order to prevent.

It is stored two ways, deliberately:

  an entity per validator, delegation and unbonding pair, with the fields an
  invariant must read as real attributes -- see the projection note further
  down, and `save-stake-tx-data`. It used to be one EDN blob under
  `:urd.stake/state`, rewritten whole every block; that attribute is gone.

  :urd.stake/globals the scalars that are not per-entity: height, time, the
                     community pool, the last announced set.
  :urd.stake/power   one datom per bonded validator, so an invariant can gate
                     on whether the sender is a current validator.

Both are in the `urd.stake` namespace, which `ownership/protocol-attribute?`
refuses to let any sender write.
raw docstring

apply-blockclj

(apply-block conn policy {:keys [height time commit txs] :as block})

Apply one decided block on the validator's single-writer connection. Each envelope settlement checkpoints its receipt, budgets and staking intents atomically. Redelivery resumes an interrupted block or returns the last completed result. Staking, balance movements and height finalize together.

Apply one decided block on the validator's single-writer connection.
Each envelope settlement checkpoints its receipt, budgets and staking intents
atomically. Redelivery resumes an interrupted block or returns the last
completed result. Staking, balance movements and height finalize together.
sourceraw docstring

default-epoch-lengthclj

Blocks per epoch: how long a validator set stays put.

Stake-driven set changes are held to the epoch boundary; jailing is not. The reasons pull in opposite directions and both are real.

FOR holding them: round-robin's proposer is (mod height (count validators)) over the sorted ids, so every set change reindexes the whole rotation. Once staking is reachable from a transaction, that index is something an attacker can churn on demand. Cosmos's ADR-039 wants epochs for the same stability -- it names threshold cryptography, which cannot run a DKG that outlives its own validator set, and light-client proof size. Solana bounds the same thing differently, with a rate limit of about 9% of active stake per epoch.

AGAINST holding them: ADR-039 is equally clear about the cost, and jailing is where it bites. A jailed validator that stays in the set keeps taking proposer turns it will not answer, so deferring an involuntary removal defeats the purpose of having one -- the mechanism exists to remove a validator that is hurting liveness NOW.

So: economic churn waits for the boundary, provable absence does not. The griefing vector ADR-039 mentions -- a validator timing an infraction to remove itself from proposer duty -- is real and is the price.

Blocks per epoch: how long a validator set stays put.

Stake-driven set changes are held to the epoch boundary; jailing is not. The
reasons pull in opposite directions and both are real.

FOR holding them: round-robin's proposer is `(mod height (count
validators))` over the sorted ids, so every set change reindexes the whole
rotation. Once staking is reachable from a transaction, that index is
something an attacker can churn on demand. Cosmos's ADR-039 wants epochs for
the same stability -- it names threshold cryptography, which cannot run a DKG
that outlives its own validator set, and light-client proof size. Solana
bounds the same thing differently, with a rate limit of about 9% of active
stake per epoch.

AGAINST holding them: ADR-039 is equally clear about the cost, and jailing is
where it bites. A jailed validator that stays in the set keeps taking
proposer turns it will not answer, so deferring an involuntary removal
defeats the purpose of having one -- the mechanism exists to remove a
validator that is hurting liveness NOW.

So: economic churn waits for the boundary, provable absence does not. The
griefing vector ADR-039 mentions -- a validator timing an infraction to
remove itself from proposer duty -- is real and is the price.
sourceraw docstring

finalized-dbclj

(finalized-db db)

Read the last complete block. Ordinary opens need no history walk. During a partial block, follow at most one commit per settled envelope.

Read the last complete block. Ordinary opens need no history walk. During
a partial block, follow at most one commit per settled envelope.
sourceraw docstring

load-stakeclj

(load-stake db params)

The persisted stake state, or a fresh one.

Reassembled from datoms rather than read out of one blob -- see the projection note above. params is supplied by the caller and never persisted: it is node configuration, and a chain whose parameters came back out of its own database could not have them changed by anything but a migration.

The persisted stake state, or a fresh one.

Reassembled from datoms rather than read out of one blob -- see the
projection note above. `params` is supplied by the caller and never
persisted: it is node configuration, and a chain whose parameters came back
out of its own database could not have them changed by anything but a
migration.
sourceraw docstring

max-block-bytesclj

source

max-envelopesclj

source

max-preparation-unitsclj

source

max-settlement-datomsclj

source

reconcile-supplyclj

(reconcile-supply db genesis-supply)

Audit a finalized snapshot against an independently supplied opening supply. Storage reserves are already in liquid balances. Commission is already in outstanding rewards. The audit scans accounts once and runs off the block path.

Audit a finalized snapshot against an independently supplied opening supply.
Storage reserves are already in liquid balances. Commission is already in
outstanding rewards. The audit scans accounts once and runs off the block path.
sourceraw docstring

save-stake-tx-dataclj

(save-stake-tx-data db st through)

Persist st as datoms, plus the queryable power projection.

Takes the DATABASE, because a projection has to say what is no longer there as well as what is -- see vanished-tx-data, and note that the first version of this function did not, which made a complete undelegation halt the chain.

Persist `st` as datoms, plus the queryable power projection.

Takes the DATABASE, because a projection has to say what is no longer there
as well as what is -- see `vanished-tx-data`, and note that the first version
of this function did not, which made a complete undelegation halt the chain.
sourceraw docstring

schemaclj

source

transactions-fit?clj

(transactions-fit? txs)

Check structural envelope count and byte limits before voting on a transaction batch.

Check structural envelope count and byte limits before voting on a transaction batch.
sourceraw docstring

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