A real-network runtime for urd.consensus.node.
The simulator interprets a node's effects against logical time and an
in-memory network; this interprets the SAME effects against core.async, a
wall clock and a ConsensusNetwork. One algorithm, two interpreters, and the
algorithm cannot tell them apart -- which is the point, and is what makes a
schedule that fails in the simulator meaningful about a deployment.
ConsensusAlgorithm protocolThis used to drive urd.consensus.state-machine, an earlier version of
node. Three things changed, and each was a layering fault rather than a
translation:
The effect vocabulary was one algorithm's, generalised by accident.
A supposedly generic runtime knew request-missing-proposal,
request-state-sync, request-votes, broadcast-finalization,
add-own-vote and trigger-next-round by name -- every one of them
round-robin's. They are ordinary messages, a vote, and a timer; the
algorithm spells them that way now and this interprets the thirteen
effects the protocol actually defines.
add-own-vote meant a node's own vote lived in the runtime's log
rather than in the node's state. A vote outside the state machine is a
vote the state machine cannot count.
Timers were wall-clock milliseconds. A node now asks for TICKS and
:tick-ms converts. That keeps the algorithm's contract identical under
both interpreters: logical time is what makes a failing schedule
reproducible, and an algorithm whose timeouts are milliseconds cannot be
replayed at all.
ConsensusNetwork is topic pubsub with no unicast, so send-to is carried on
a :direct topic with a :to field and filtered on receipt. That is honest
rather than clever: the message reaches every peer and all but one drop it, so
send-to here costs what a broadcast costs. Kabel's pubsub is the constraint;
a transport with real unicast should override this.
A real-network runtime for `urd.consensus.node`. The simulator interprets a node's effects against logical time and an in-memory network; this interprets the SAME effects against core.async, a wall clock and a `ConsensusNetwork`. One algorithm, two interpreters, and the algorithm cannot tell them apart -- which is the point, and is what makes a schedule that fails in the simulator meaningful about a deployment. ## Ported from the legacy `ConsensusAlgorithm` protocol This used to drive `urd.consensus.state-machine`, an earlier version of `node`. Three things changed, and each was a layering fault rather than a translation: 1. **The effect vocabulary was one algorithm's, generalised by accident.** A supposedly generic runtime knew `request-missing-proposal`, `request-state-sync`, `request-votes`, `broadcast-finalization`, `add-own-vote` and `trigger-next-round` by name -- every one of them round-robin's. They are ordinary messages, a vote, and a timer; the algorithm spells them that way now and this interprets the thirteen effects the protocol actually defines. 2. **`add-own-vote` meant a node's own vote lived in the runtime's log rather than in the node's state.** A vote outside the state machine is a vote the state machine cannot count. 3. **Timers were wall-clock milliseconds.** A node now asks for TICKS and `:tick-ms` converts. That keeps the algorithm's contract identical under both interpreters: logical time is what makes a failing schedule reproducible, and an algorithm whose timeouts are milliseconds cannot be replayed at all. ## Unicast over a broadcast transport `ConsensusNetwork` is topic pubsub with no unicast, so `send-to` is carried on a `:direct` topic with a `:to` field and filtered on receipt. That is honest rather than clever: the message reaches every peer and all but one drop it, so `send-to` here costs what a broadcast costs. Kabel's pubsub is the constraint; a transport with real unicast should override this.
(committed-tail runtime)The committed vertices this runtime still retains, for assertions and for
the revert check. See default-tail-limit.
The committed vertices this runtime still retains, for assertions and for the revert check. See `default-tail-limit`.
How many committed vertices are retained so :revert can be verified.
The simulator keeps every committed vertex and can therefore always check a
revert's :dropped. A node that runs for a month cannot. This is the depth
of reorg that stays checkable; past it do-revert refuses rather than
guesses.
How many committed vertices are retained so `:revert` can be verified. The simulator keeps every committed vertex and can therefore always check a revert's `:dropped`. A node that runs for a month cannot. This is the depth of reorg that stays checkable; past it `do-revert` refuses rather than guesses.
How long one logical tick lasts in the real world.
The algorithms' timeouts are in ticks -- round-robin's proposal timeout is 8 -- so this is the single knob that turns a simulated schedule into a real one.
How long one logical tick lasts in the real world. The algorithms' timeouts are in ticks -- round-robin's proposal timeout is 8 -- so this is the single knob that turns a simulated schedule into a real one.
Where send-to is emulated. See the namespace docstring: this transport has
no unicast, so a directed message rides a topic with a :to field and is
filtered on receipt.
Where `send-to` is emulated. See the namespace docstring: this transport has no unicast, so a directed message rides a topic with a `:to` field and is filtered on receipt.
(dropped-messages runtime)Number of malformed messages discarded and incoming or outgoing envelopes dropped because the runtime reached its network concurrency limit.
Number of malformed messages discarded and incoming or outgoing envelopes dropped because the runtime reached its network concurrency limit.
(interpret-effect runtime effect)Interpret one effect. Every branch is an effect node defines; there are no
algorithm-specific ones left.
Interpret one effect. Every branch is an effect `node` defines; there are no algorithm-specific ones left.
(last-error runtime)The exception that halted this runtime's event loop, or nil.
A stopped runtime and a quiet one look identical from get-state; this is
how a caller tells them apart.
The exception that halted this runtime's event loop, or nil. A stopped runtime and a quiet one look identical from `get-state`; this is how a caller tells them apart.
Marks the internal event that carries a landed write back to the loop.
persist-then cannot be finished where it is issued. The simulator steps the
node with persisted and only THEN releases the gated effects, in that order,
on one thread. Here the completion arrives on a go block while the event loop
is elsewhere, so releasing :then inline would put this node's binding
messages on the wire BEFORE it had processed its own write landing -- the one
ordering the barrier exists to impose. Routing the completion through the
event channel puts both steps back on the loop, in the simulator's order.
Marks the internal event that carries a landed write back to the loop. `persist-then` cannot be finished where it is issued. The simulator steps the node with `persisted` and only THEN releases the gated effects, in that order, on one thread. Here the completion arrives on a go block while the event loop is elsewhere, so releasing `:then` inline would put this node's binding messages on the wire BEFORE it had processed its own write landing -- the one ordering the barrier exists to impose. Routing the completion through the event channel puts both steps back on the loop, in the simulator's order.
(run-event-loop runtime)The event loop.
(go-try- (loop ...)) rather than go-loop-try-, and that is not a style
preference. superv.async 0.3.50 defines
(defmacro go-loop-try- [bindings & body]
`(go-try- ~S (loop ~bindings ~@body)))
and ~S unquotes the supervisor VALUE into the expansion. S holds
channels, so the macro emits a literal channel: harmless on the JVM, where it
is an object reference, and fatal under ClojureScript, which refuses to
compile the namespace, reporting that a ManyToManyChannel is not a valid
ClojureScript constant. It is also passing S as a discarded first body form
to a macro whose whole point is that it runs WITHOUT supervision, so nothing
is lost by expanding it by hand.
That single macro use is why urd.consensus.runtime did not compile under
cljs. Worth reporting upstream -- see the note in the plan.
The event loop.
`(go-try- (loop ...))` rather than `go-loop-try-`, and that is not a style
preference. superv.async 0.3.50 defines
(defmacro go-loop-try- [bindings & body]
`(go-try- ~S (loop ~bindings ~@body)))
and `~S` unquotes the supervisor VALUE into the expansion. `S` holds
channels, so the macro emits a literal channel: harmless on the JVM, where it
is an object reference, and fatal under ClojureScript, which refuses to
compile the namespace, reporting that a ManyToManyChannel is not a valid
ClojureScript constant. It is also passing `S` as a discarded first body form
to a macro whose whole point is that it runs WITHOUT supervision, so nothing
is lost by expanding it by hand.
That single macro use is why `urd.consensus.runtime` did not compile under
cljs. Worth reporting upstream -- see the note in the plan.(send-event! runtime event)Inject an event. {:type :start-round} from the legacy API is translated, so
existing callers keep working.
Inject an event. `{:type :start-round}` from the legacy API is translated, so
existing callers keep working.(setup-network-handlers runtime)Subscribe to exactly the topics the node DECLARED, plus :direct.
This list used to be hardcoded as [:proposals :votes :finalizations :recovery :direct] -- round-robin's vocabulary, in a runtime that called
itself generic. Every other algorithm broadcasts somewhere else entirely:
Tendermint on :consensus, SCP on :scp, Bullshark on :bullshark,
Nakamoto on :headers. Their messages were accepted, sent, and delivered to
nobody.
It failed silently, which is the part worth remembering. Tendermint on this runtime started cleanly, reported no error, and sat at height 0 forever -- four nodes each waiting for votes that had gone nowhere. Nothing in the system could tell the difference between a message nobody had subscribed to and a message nobody had sent.
Subscribe to exactly the topics the node DECLARED, plus `:direct`. This list used to be hardcoded as `[:proposals :votes :finalizations :recovery :direct]` -- round-robin's vocabulary, in a runtime that called itself generic. Every other algorithm broadcasts somewhere else entirely: Tendermint on `:consensus`, SCP on `:scp`, Bullshark on `:bullshark`, Nakamoto on `:headers`. Their messages were accepted, sent, and delivered to nobody. It failed silently, which is the part worth remembering. Tendermint on this runtime started cleanly, reported no error, and sat at height 0 forever -- four nodes each waiting for votes that had gone nowhere. Nothing in the system could tell the difference between a message nobody had subscribed to and a message nobody had sent.
(start-runtime! {:keys [peer-id node state-machine network store validators
on-propose on-finalize on-revert on-resync
on-equivocation tick-ms tail-limit seed auth]
:as config})Start a runtime driving node.
Config:
:peer-id :node :network :validators
:store a urd.consensus.store/DurableStore; in-memory by default,
which is durable across a node restart and not across a
process one
:on-propose (fn [context]) -> value
:on-finalize (fn [vertices])
:on-revert (fn [to-vertex dropped])
:on-resync (fn [vertices])
:delivered-through how many committed vertices the consumer has ALREADY
applied -- a number or a 0-arg fn. etcd's Config.Applied.
Without it a restarting node has to guess, and both guesses
are wrong in some case: re-announcing the whole prefix is
impossible once the log is compacted, and announcing nothing
drops entries that were committed but never delivered.
:on-equivocation (fn [peer evidence])
:tick-ms wall-clock duration of one logical tick
:tail-limit committed vertices retained for revert checking
:seed make sampling REPRODUCIBLE, for simulation and tests. Without
it every sample is drawn from the host's cryptographic source,
which is what Snowman's security actually requires.
Accepts :state-machine as an alias for :node, so callers written against
the legacy runtime keep working.
Start a runtime driving `node`.
Config:
:peer-id :node :network :validators
:store a `urd.consensus.store/DurableStore`; in-memory by default,
which is durable across a node restart and not across a
process one
:on-propose (fn [context]) -> value
:on-finalize (fn [vertices])
:on-revert (fn [to-vertex dropped])
:on-resync (fn [vertices])
:delivered-through how many committed vertices the consumer has ALREADY
applied -- a number or a 0-arg fn. etcd's `Config.Applied`.
Without it a restarting node has to guess, and both guesses
are wrong in some case: re-announcing the whole prefix is
impossible once the log is compacted, and announcing nothing
drops entries that were committed but never delivered.
:on-equivocation (fn [peer evidence])
:tick-ms wall-clock duration of one logical tick
:tail-limit committed vertices retained for revert checking
:seed make sampling REPRODUCIBLE, for simulation and tests. Without
it every sample is drawn from the host's cryptographic source,
which is what Snowman's security actually requires.
Accepts `:state-machine` as an alias for `:node`, so callers written against
the legacy runtime keep working.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 |