Liking cljdoc? Tell your friends :D

skuld.consensus

The seam between the ledger and consensus: where a stake change becomes a validator set change.

Both halves of this existed and were tested, and they were not connected. apply-block computed :updates -- stake/consensus-updates, the deltas the consensus layer is told about -- and returned them to a caller that threw them away. On the other side, round-robin/activate-updates and tendermint/activate-updates read :validator-updates off a finalized proposal and reindex the set. Nothing carried the first to the second, so a validator could be jailed by the ledger and go on proposing forever.

Trigger and activation are different moments

This is the whole design, and it is Cosmos's:

block N applied  ->  updates produced   (the TRIGGER)
value proposed   ->  updates ride along
value decided    ->  updates activated  (the ACTIVATION)

The updates a block produces are attached to the NEXT value this node proposes, not applied when they are computed. Applying them at computation time would change the set on a block that consensus has not decided yet, and a node that reorganised would have reconfigured on a proposal that never happened.

stake/consensus-updates says the same thing from its end: the updates are the trigger, consensus applies them when the value is decided.

Why the pending set is per-node state and not a broadcast

Every node applies every decided block and computes the updates for itself. They agree because apply-block is deterministic, which is the property the three-JVM test in skuld.network-test exists to establish. A node does not take another node's word for what the set should become -- that would make the validator set a thing a proposer could assert rather than a thing the chain computes, and round-robin/activate-updates explains at length why nodes disagreeing about the set at a height breaks its safety argument outright.

So :pending is carried, not sent. The only thing that crosses the network is the proposed value, and it crosses as evidence of what the proposer's ledger computed -- which every other node then checks by computing the same thing.

What this namespace deliberately does not do

This namespace carries updates; it does not decide what causes them. Two triggers reach it.

STAKING INTENTS. skuld.staking admits :create-validator, :delegate and :undelegate as ordinary signed transactions, and block/apply-block applies them before set changes are computed.

LIVENESS. A validator that stops voting is jailed by stake/record-vote, jailing removes it from active-set, and that is a set change with no transaction in it at all. skuld.set-change-test drives that path end to end through a simulated cluster, because it is the one trigger that needs no sender.

The seam between the ledger and consensus: where a stake change becomes a
validator set change.

Both halves of this existed and were tested, and they were not connected.
`apply-block` computed `:updates` -- `stake/consensus-updates`, the deltas
the consensus layer is told about -- and returned them to a caller that threw
them away. On the other side, `round-robin/activate-updates` and
`tendermint/activate-updates` read `:validator-updates` off a finalized
proposal and reindex the set. Nothing carried the first to the second, so a
validator could be jailed by the ledger and go on proposing forever.

## Trigger and activation are different moments

This is the whole design, and it is Cosmos's:

    block N applied  ->  updates produced   (the TRIGGER)
    value proposed   ->  updates ride along
    value decided    ->  updates activated  (the ACTIVATION)

The updates a block produces are attached to the NEXT value this node
proposes, not applied when they are computed. Applying them at computation
time would change the set on a block that consensus has not decided yet, and
a node that reorganised would have reconfigured on a proposal that never
happened.

`stake/consensus-updates` says the same thing from its end: the updates are
the trigger, consensus applies them when the value is decided.

## Why the pending set is per-node state and not a broadcast

Every node applies every decided block and computes the updates for itself.
They agree because `apply-block` is deterministic, which is the property the
three-JVM test in `skuld.network-test` exists to establish. A node does not
take another node's word for what the set should become -- that would make
the validator set a thing a proposer could assert rather than a thing the
chain computes, and `round-robin/activate-updates` explains at length why
nodes disagreeing about the set at a height breaks its safety argument
outright.

So `:pending` is carried, not sent. The only thing that crosses the network
is the proposed value, and it crosses as evidence of what the proposer's
ledger computed -- which every other node then checks by computing the same
thing.

## What this namespace deliberately does not do

This namespace carries updates; it does not decide what causes them. Two
triggers reach it.

STAKING INTENTS. `skuld.staking` admits `:create-validator`, `:delegate` and
`:undelegate` as ordinary signed transactions, and `block/apply-block`
applies them before set changes are computed.

LIVENESS. A validator that stops voting is jailed by `stake/record-vote`,
jailing removes it from `active-set`, and that is a set change with no
transaction in it at all. `skuld.set-change-test` drives that path end to end
through a simulated cluster, because it is the one trigger that needs no
sender.
raw docstring

apply!clj

(apply! {:keys [conn policy] :as d} block)

Apply block and carry forward whatever validator updates it produced.

Returns [driver' result], where result is apply-block's own map. The driver is returned rather than mutated so that a caller replaying blocks -- which skuld.validator does, in a fresh JVM, to check determinism -- gets the same answer from the same inputs.

:pending is REPLACED, not accumulated. consensus-updates is a diff against the last committed set, so a block that produces no change produces an empty vector, and appending would re-announce a set change every block until something else happened.

Apply `block` and carry forward whatever validator updates it produced.

Returns `[driver' result]`, where `result` is `apply-block`'s own map. The
driver is returned rather than mutated so that a caller replaying blocks --
which `skuld.validator` does, in a fresh JVM, to check determinism -- gets
the same answer from the same inputs.

`:pending` is REPLACED, not accumulated. `consensus-updates` is a diff
against the last committed set, so a block that produces no change produces
an empty vector, and appending would re-announce a set change every block
until something else happened.
sourceraw docstring

driverclj

(driver conn policy)

A node's ledger-side state: its connection, its policy, and the updates its last applied block produced.

:pending starts empty. A genesis set is not an update -- there is no previous set to diff against, and stake/commit-set adopts the genesis set as the baseline precisely so that the first block emits nothing.

A node's ledger-side state: its connection, its policy, and the updates its
last applied block produced.

`:pending` starts empty. A genesis set is not an update -- there is no
previous set to diff against, and `stake/commit-set` adopts the genesis set
as the baseline precisely so that the first block emits nothing.
sourceraw docstring

tendermint-optionsclj

(tendermint-options local-driver application-valid?)

Build a validator's proposal checks. local-driver reads the driver for this validator. application-valid? checks the application's block payload.

Build a validator's proposal checks. local-driver reads the driver for this
validator. application-valid? checks the application's block payload.
sourceraw docstring

valueclj

(value {:keys [pending]} payload)

The value to propose: payload plus any pending validator updates.

Only the ledger supplies :validator-updates. Compute a Tendermint content ID after this function returns so the digest covers the final updates.

:validator-updates is attached only when there are some. An empty vector would be harmless -- every activate-updates guards with seq -- but it would also appear in the app-hash of every block, and a field that is present-but-empty in almost every block is one a reader learns to skip.

The value to propose: `payload` plus any pending validator updates.

Only the ledger supplies `:validator-updates`. Compute a Tendermint content
ID after this function returns so the digest covers the final updates.

`:validator-updates` is attached only when there are some. An empty vector
would be harmless -- every `activate-updates` guards with `seq` -- but it
would also appear in the app-hash of every block, and a field that is
present-but-empty in almost every block is one a reader learns to skip.
sourceraw docstring

value-fnclj

(value-fn drivers payload-fn)

A :value-fn for urd.consensus.sim, over an atom of {peer-id driver}.

The simulator answers a node's :request-value effect through this hook, so it is the whole of what a proposer contributes. payload-fn builds whatever the application wants decided -- a snapshot id, an app-hash, a transaction batch -- and this adds the set changes that node's own ledger computed.

An atom because the drivers advance as blocks are applied and the simulator itself is a pure value; the alternative is threading a ledger through sim/advance, which would mean the simulator knowing what a ledger is.

A `:value-fn` for `urd.consensus.sim`, over an atom of `{peer-id driver}`.

The simulator answers a node's `:request-value` effect through this hook, so
it is the whole of what a proposer contributes. `payload-fn` builds whatever
the application wants decided -- a snapshot id, an app-hash, a transaction
batch -- and this adds the set changes that node's own ledger computed.

An atom because the drivers advance as blocks are applied and the simulator
itself is a pure value; the alternative is threading a ledger through
`sim/advance`, which would mean the simulator knowing what a ledger is.
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