Sign in

Forks and conflict resolution

Suggest an edit

The last lesson assumed the ideal case, where one block producer proposes a block, the network accepts it, and the chain grows by one. This lesson is about what happens when two producers finish a valid block at almost the same instant.

Two valid blocks can appear at the same height

A block produced in one city does not appear in every node in the world simultaneously. It propagates outward through the gossip network, hop by hop, and during the seconds it takes to reach everyone, another producer somewhere else might finish their own block. Both blocks are valid, and both point at the same parent block, but they contain different transactions. The chain now has a temporary fork: two competing versions of what block N+1 should be.

Block N branching into two competing Block N+1 versions from producer A and producer BBlock N, the shared parent, has arrows pointing to two separate Block N+1 candidates: one from producer A and one from producer B. Half the network sees producer A's block first while the other half sees producer B's block first, creating a temporary fork that the network must resolve. Block N the shared parent Block N+1 producer A Block N+1 producer B half the network sees producer A's block first other half sees producer B's block first A temporary fork. Both branches are valid. The network has to pick one.

A node that received producer A's block first is treating block N+1 from A as the current tip. A node that received producer B's block first is treating block N+1 from B as the tip. Both are doing the right thing according to the rules they know.

If nothing else happened, the network would stay split forever, with two separate histories, each consistent within its own population of nodes. The goal of consensus is that everyone ends up with the same view, so the protocol needs a way to choose one branch.

Every node picks a branch by the same rule

Every blockchain protocol includes a fork choice rule, which is a deterministic procedure for picking one branch over another whenever a fork appears. The rule has to satisfy two requirements. It has to be computable by any node from local information, with no central referee. And it has to be the same rule on every node, so that two honest nodes seeing the same fork will independently arrive at the same answer.

The specific rule depends on the chain, but every rule takes some property that is hard to fake, measures it across the competing branches, and picks the branch that has more of it. Bitcoin picks the branch with the most cumulative proof of work behind it. Ethereum counts the votes of its validators, weighted by their stake, and picks the branch with the most weight behind it.

At the moment a fork appears, no branch has any advantage yet, because both are one block past the shared parent.

The branch that gets the next block wins

Each producer in the network builds on the version of the chain they currently see as the tip. Some producers are building on top of A's block, others on top of B's.

The moment one branch gets a second block before the other, it has more work or stake behind it. Nodes that were on the losing branch see the new, longer branch coming through gossip, recognise it as the one their fork choice rule prefers, and switch over. They discard the block they had as N+1 and replace it with the winning branch's blocks N+1 and N+2.

Block N forks into winning branch (N+1, N+2) versus orphaned N+1 blockBlock N splits into two branches. The winning branch extends with N+1 from producer A and N+2 from producer C, while the losing branch's N+1 block from producer B is left orphaned as a dead end. Block N N+1 producer A N+2 producer C winning branch N+1 producer B orphaned The winning branch gets longer. The losing branch becomes an abandoned dead end.

The block on the losing branch is now called an orphan. It was valid when it was produced, the network briefly accepted it, but the fork choice rule no longer points at it. The transactions inside it never made it to the canonical chain. Their effects on state are undone everywhere.

This rewriting of recent history is called a reorganisation, usually shortened to reorg. Reorgs of one or two blocks happen routinely on most networks. They almost never cause problems in practice, because no application built on top of the chain treats a brand-new block as final.

Each block on top makes a reorg less likely

If your transaction has just been included in the most recent block, that block is the most likely block in the chain to be replaced by a reorg. Each additional block built on top of it makes a reorg exponentially less likely. The alternative branch would have to outproduce the current canonical branch by enough to overtake it, and that becomes harder with every block it falls behind.

So exchanges, payment processors, and high-value applications wait for some number of additional blocks (called confirmations) before treating a transaction as final. The specific number depends on the chain and the value at stake. On Bitcoin the usual wait is six confirmations. A block takes about ten minutes, so reversing a transaction six blocks deep means redoing about an hour of the whole network's work while keeping up with the new blocks. The economics of proof of work puts a price on that. On a chain with 10-second blocks, the same six confirmations are one minute of that network's work. Small payments might be safe after one or two confirmations. Multi-million-dollar transfers wait for many more. The exact threshold is a risk-management choice, and the principle behind it is that depth in the chain equals safety from reorganisation.

Some chains have an additional mechanism that explicitly marks blocks as finalised after a certain depth or after enough validators sign off on them. Once a block is finalised under such a mechanism, the protocol guarantees it will never be reorganised, and applications on those chains wait for finality in place of counting confirmations. On Ethereum finality comes at around 12.8 minutes, and exchanges and other high-value applications wait for it. The consensus lesson of the Ethereum course shows how it works. On either kind of chain, do not treat a new block as permanent immediately.

A rule change can split the chain for good

The forks discussed so far are temporary. The fork choice rule brings every node back to one history once one branch gets ahead. A different kind of fork happens when the rules of the protocol themselves change, and not every node updates to the new rules. Two populations of nodes end up running different software, and no fork choice rule can settle a disagreement about what counts as a valid block.

A soft fork tightens the existing rules, so every block that's valid under the new rules is also valid under the old rules. Nodes running old software still accept the new chain, and if enough block producers move to the new rules, nothing splits.

A hard fork changes the rules in a way that's not backwards-compatible. Some blocks valid under the new rules are not valid under the old rules, so nodes running old software reject them. If both populations keep producing blocks, they split into two separate chains that share their history up to the fork point and nothing after it. Ethereum and Ethereum Classic split this way in July 2016, when most of the community adopted a hard fork that returned the ETH an attacker had taken from a fund called The DAO, and a minority kept running the original chain. Bitcoin and Bitcoin Cash split in 2017, when a group that wanted bigger blocks launched its own version of Bitcoin, as the Bitcoin forks lesson describes.