Chapter 06 · ~14 min

Commonware: the parts we stand on

Library, not framework — what we delegate, what we keep, and why the same stack runs in two universes.

What you’ll walk away with

Three doors

Picture the meeting where this started. The task: add BFT consensus to a production sequencer — a live system with its own block format, its own VM, its own storage and RPC and operational habits. There are three doors out of that meeting.

Door one: write the protocol yourself. You just read chapter 3. Thirty years of very smart people shipping subtle liveness bugs is not a dare — and even a correct implementation buys you a decade of maintaining your own view-change lore.

Door two: adopt a framework. A chain-in-a-box gives you consensus on day one — and its opinions forever after. Its block format, its state model, its storage engine, its RPC surface. Our node already has all of those, in production. Re-platforming a working system into a framework’s shape is a rewrite wearing a costume.

Door three: compose a library. Take the parts that took thirty years to get right — the vote state machine, authenticated networking, durable journals and archives — as primitives with seams, and keep absolute ownership of everything else. That’s commonware: a toolkit of composable blockchain components, each usable without the others.

The rest of this chapter is what door three looks like in our repository — and the punchline is how little of it there is.

The parts, by name

Twelve crates, one version, pinned exactly. Below is the map: click any crate to see what we actually take from it and where it lives in our tree. Start with consensus — the big one — then runtime, which is the quiet hero of this whole chapter. Notice two crates are dashed: our code never imports them directly; they’re pinned only so the family moves in lockstep.

Read the footer line again, because it’s the chapter’s first aha in one sentence: the list of things not on that map — block format, transaction types, execution, state storage, RPC — is exactly the list of things a framework would have taken. Everything our users touch stayed ours.

One validator, assembled

So what do the parts make? One file in the repo answers that literally — lib/consensus/core/src/stack.rs assembles a validator’s entire consensus stack, and opens with an ASCII diagram of what it built. The widget below is that diagram, made clickable. Click through the layers top to bottom — the right edge tells you who owns each one. Then press the swap button and watch carefully which boxes change. Missions:

  1. Click the simplex engine — it speaks only 32-byte digests. Full blocks travel on a separate gossip channel and meet the engine’s world one layer down.
  2. Click Inline — by the time our code is asked anything, the block’s structure (parent linkage, heights, epoch rules) is already checked. We only judge content.
  3. Click the two gold layers — our adapters and the seam. This is the entire surface we maintain toward the library.
  4. Now swap universes, and find every box that did not change.

Put into one sentence what you just clicked through:

Our commonware-facing code is two thin adapters implementing two traits — Application (build a block, verify a block) and Reporter (a finalized block arrived) — and everything consensus asks of the node fits in one trait, ExecutionEnv, with four core calls: genesis_block, build, verify, commit.

That’s the whole treaty between thirty years of consensus research and our node. The trait is about a hundred readable lines — lib/consensus/core/src/execution.rs — and its doc comment states the design rule this chapter orbits: everything consensus needs from the node goes through it, and nothing else. (The same Reporter trait, implemented a second time, is how the node’s observability taps the full activity stream — votes, certificates, misbehavior evidence. That story belongs to the operations chapter.)

For the rigor-minded: what “generic” means here, precisely

The engine is generic over a signing scheme (what a vote physically is — chapter 5’s multisig and threshold designs are both schemes under this abstraction) and a leader elector (chapter 4 used round-robin; unpredictable rotations slot into the same seam). It is also generic over the runtime and the network, which is the next section. The concrete choices our committee runs with are configuration, not architecture — the reference docs and lib/consensus/core/src/types.rs are the source of truth for what’s instantiated today, and this guide deliberately doesn’t hard-code it.

Same code, two universes

Here is the design decision that quietly pays for everything chapter 4 made you feel. Nothing in the consensus stack ever calls the clock, spawns a task, opens a socket, or touches a disk directly. All of it goes through runtime traits — a clock, a spawner, storage, metrics — plus a network interface. Which means the universe the stack runs in is a parameter:

Consensus bugs live in interleavings — a crash between a vote and its broadcast, a partition healing one message too late. Wall-clock tests sample interleavings at random and pray; a seeded scheduler enumerates them on demand, and replays any of them exactly. The testing doc says it best, and it’s worth quoting verbatim:

The deterministic swap is not a mock of consensus — it is the production consensus stack on different hardware.

If this sounds familiar, it should: every simulator in this guide works the same way — seeded randomness, virtual time, “reset” replaying the identical run. The guide didn’t invent that style; it inherited the repo’s.

The toy blockchain you already have

The plan for this chapter once included “build a toy blockchain to play with”. It turns out the repo ships one, and it’s load-bearing: lib/consensus/sim/ is a complete miniature chain — the production consensus stack over the deterministic runtime, with an ExecutionEnv of content-free blocks (and a second one running the real VM over in-memory state, for scenarios where state itself is the assertion). Its test directory is a scenario corpus organized by capability — partitions, byzantine peers of both flavors, crash-restart, epochs, late join, migration — and it runs in CI. A guided reading order, roughly forty-five minutes:

  1. lib/consensus/core/src/execution.rs — the seam trait itself. Read the doc comments; you now have the vocabulary for all of them.
  2. lib/consensus/sim/src/execution.rs — the mock environment. Notice how little a “blockchain” needs to be.
  3. lib/consensus/sim/src/cluster.rs — SimCluster: N validators, scriptable links (partitions, loss, latency), crash and restart.
  4. One scenario file from lib/consensus/sim/tests/ — partitions.rs reads like chapter 4’s mission list written in Rust, which is not a coincidence.

Try to break it

Time to attack the claim this chapter stands on. Below are two complete simplex committees — chapter 4’s protocol, animation removed — each running twelve virtual seconds over a lossy network, each producing an event trace and a rolling fingerprint (same shape as the runtime’s audit fingerprint). Your mission is to catch determinism lying:

  1. Both runs start from the same seed. Compare the fingerprints — then look at the last events of each trace. Identical, event for event.
  2. Press harsher network: 20% packet loss, doubled latency. Surely chaos breaks it? Chaos is drawn from the seed — the same messengers fall in the same ditches. Fingerprints still match.
  3. Now try to make the same seed produce two different histories. Take your time with the controls. There is no combination that does it — and that missing button is precisely what the repo’s whole testing strategy stands on.
  4. Concede, and press new fate for B: a different seed, a genuinely different universe — and the widget pins the exact first event where the histories fork. When a nightly seed sweep fails, that fork point is what the harness hands the engineer: not “flaky”, but seed 1999, event 41, here’s the replay.

The four things to keep

Where this lives in our stack

Next: you now know the seam by name — four calls, one trait. Chapter 7 is what lives behind it on the real node: how build borrows the sequencer’s machinery, how verify means re-executing a leader’s block before vouching for it, how speculative state floats in overlays until finality collapses it, and where certificates go to live forever.