« Back to home

QBFT Consensus in Hyperledger Besu: Six Nodes, Step by Step

Six machines share one genesis file. Four of them start as validators, two more join later, one crashes at the worst moment, the network loses half its validators and stops, and then it recovers without ever producing two conflicting blocks. That is the story the animation below tells, one message at a time, using the rules in Besu’s `consensus/qbft-core` module.

QBFT is the Byzantine fault tolerant consensus protocol that Besu recommends for private and consortium networks. The earlier post, Inside Hyperledger Besu, placed it inside the whole client. This one zooms in on the protocol itself: who proposes, how many votes are enough, why a failed round cannot fork the chain, and how members join and leave. The companion podcast episode, How QBFT Consensus Works, tells the same story in about half an hour.

The animation

Press Play, or step with the arrow buttons. The chapter buttons jump to each part. Each step’s text sits under the network view, and the panels below it track the height, round, proposer, quorum math, vote tally and finalized chain. Expand opens it full screen with the panels beside the network, and New tab opens the standalone page. In the standalone page, the left and right arrow keys step, the space bar pauses, and R replays a step.

QBFT animation New tab ↗
Seven chapters, 35 steps. Message colors: violet PROPOSAL, cyan PREPARE, green COMMIT, amber ROUND-CHANGE.

Everything follows from n

Every threshold in QBFT is computed from one number, the size of the current validator set, n. In Besu’s BftHelpers:

  • Quorum is ⌈2n/3⌉. That many PREPARE, COMMIT or ROUND-CHANGE messages are needed to move on.
  • f, the number of Byzantine (arbitrarily faulty) validators tolerated, is ⌊(n−1)/3⌋.
  • The future round-change threshold is f+1, used by the optional early round change described below.
  • A validator vote passes with ⌊n/2⌋+1 proposer votes.

With four validators the quorum is 3 and f is 1. The safety argument is about overlap. Any two quorums of 3 out of 4 share at least 2·3−4 = 2 validators. Since 2 is more than f, at least one honest validator is in both, and an honest validator never signs two different blocks at the same height and round. So two conflicting blocks can never both collect a quorum.

With six validators, the setup for most of the animation, the quorum is 4 and f is still 1. Two quorums share at least 4+4−6 = 2 validators. The same argument holds.

Genesis, peering and the first blocks

All six nodes use the same genesis.json. Its qbft section sets the block period and the round timeout. Its extraData field lists the initial validators: N1 to N4. N5 and N6 are provisioned but not started.

The validators connect over RLPx and speak two sub-protocols: eth for blocks and transactions, and istanbul/100 for QBFT consensus messages. Every consensus message is signed by its author and gossiped once, with duplicates dropped, so a message reaches every validator even without a direct link.

The proposer rotates round-robin through the validator list sorted by address. For block 1 the previous proposer is the genesis coinbase, which is not a validator, so Besu picks the first validator after it.

Joining as a validator

N5 boots with the same genesis file and connects to a few peers. At first it is a plain full node: it syncs and checks every header on its own. Each header must carry commit seals from at least a quorum of the validators that were active at that height, and its validator list must match what earlier votes imply.

Membership is decided on-chain by the current validators. Each operator calls qbft_proposeValidatorVote on their own validator. That only records a local intention. The vote becomes real when that validator next proposes a block and writes the vote into the block header. Every node runs the same tally over the same headers, so they all agree on the exact block where N5 becomes a validator. Once it is in, the thresholds are recomputed for the new n. N6 joins the same way.

The Besu documentation covers this header-vote mode and the alternative, where a smart contract holds the validator list.

Anatomy of a block

At height 10 the happy path is shown slowly, in four steps.

  1. PROPOSAL. The proposer for this height and round builds a block, signs a proposal and sends it to the validators. Each receiver checks that the author is the right proposer, that the header is valid and that the transactions execute.
  2. PREPARE. Every validator that accepts the proposal broadcasts a PREPARE for the block hash. A node that holds the proposal plus a quorum of PREPAREs is prepared. The proposal and those PREPAREs form a prepared certificate, and the node is now locked on that block.
  3. COMMIT. Each prepared validator broadcasts a COMMIT carrying its commit seal, a signature over the block hash. A node with a quorum of COMMITs is committed.
  4. Import. The node writes the seals into the header and imports the block. It is final. There are no forks, no reorgs and no confirmation depth to wait for.

Different nodes may hold different sets of seals, but they still agree on the block, because the on-chain block hash excludes the seals and the round number.

Round change

At height 11 the proposer, N1, has crashed. The others wait for a proposal that never comes. A crashed validator still counts toward n, so the quorum stays 4 of 6.

When the round timer expires, each validator moves to round 1 and broadcasts a ROUND-CHANGE. The round 1 proposer is the next validator in the rotation. It waits for a quorum of ROUND-CHANGEs, proposes a fresh block, and attaches those messages as justification. Without that proof, a node could claim any round it liked. Five live validators are more than the quorum of four, so block 11 is finalized in round 1.

The round timeout doubles with every round: 4 seconds, then 8, then 16 in this example. That back-off gives a slow network time to catch up.

Locking keeps the chain safe

Height 12 is the hard case. The network is congested. Three validators collect enough PREPAREs and lock on block B. Two do not. Then the COMMITs are delayed past the timeout, and nobody reaches a quorum of COMMITs. No node can tell whether some other node committed B, so the protocol has to assume one might have.

In the round change, the locked validators include their prepared certificate. The new proposer looks at the quorum of ROUND-CHANGEs it collected, takes the certificate from the highest prepared round, and must re-propose B, changing only the round and the proposer. Validators reject a new proposal that ignores the certificate.

Why is that enough? If anyone committed B in round 0, at least four validators prepared it. Any four ROUND-CHANGEs overlap those four in at least two validators, which is more than f. So at least one honest validator reports the lock, and no different block can be finalized at height 12.

Crash faults: live, then halted, never forked

With six validators QBFT stays safe with up to one malicious validator, and stays live as long as four honest validators are online. In the animation, two validators crash and blocks keep coming, with no margin left. When a third goes down, only three can vote. No proposal gets a quorum of PREPAREs, and no later round gets a quorum of ROUND-CHANGEs. The chain halts. That is the design: QBFT chooses safety over liveness and waits rather than risk a fork.

When the crashed nodes return, they sync, start the next height at round 0, and see ROUND-CHANGEs for round 2 from the nodes that stayed up. With the opt-in flag --Xqbft-enable-early-round-change, f+1 messages for a higher round are enough to jump straight there, because at least one of the senders is honest. By default, a node moves to a future round only after a full quorum of ROUND-CHANGEs for it, which is slower but just as safe. Either way, block production resumes.

Leaving the network

A validator should not just switch off. An offline validator still counts toward n and toward the quorum, so two silent departures from six would leave the remaining four with no fault margin at all. Instead the operators vote it out with qbft_proposeValidatorVote and false. Once the drop votes reach the threshold, the set shrinks, the quorum is recomputed, and the departing node becomes an ordinary follower that still receives finalized blocks. Only then is it stopped, and, with node permissioning, removed from the allowlist.

The rules on one page

Concept Rule in Besu n = 6
Quorum for PREPARE, COMMIT and ROUND-CHANGE ⌈2n/3⌉ 4
Byzantine faults tolerated, f ⌊(n−1)/3⌋ 1
Move to a future round Quorum of ROUND-CHANGEs, or f+1 with the early round change flag 4 (2)
Add or remove a validator ⌊n/2⌋+1 proposer votes 4
Round timeout Request timeout × 2round 4 s, 8 s, 16 s…
Proposer Round-robin after the parent block’s proposer, plus the round number

Sources