A Blockchain Primer › Module 3 › Lesson 3.3
Lesson 3.3: Which Chain Counts When There's a Fork? — The Longest Chain and Eventual Consistency
- #1. The Core Question
- #2. An Everyday Analogy
- #3. Core Concepts Explained
- #4. Diagrams
- #5. Key Takeaways
- #6. Quiz
The last lesson explained how nodes validate and accept transactions and blocks. But network delays, blocks produced at the same moment, and messages arriving out of order can leave different nodes seeing different histories for a while. This lesson asks: when several conflicting chains show up, how do nodes settle on one chain they all accept?
1. The Core Question
Say half the nodes believe the transaction history is A and the other half believe it's B. Which one should users trust? With no central authority to make the call, how do nodes each pick the same version on their own?
This lesson answers three questions: How do forks happen? How do the longest chain and heaviest chain criteria pick the authoritative chain? And why do we say a blockchain becomes consistent eventually, not immediately?
The short version: Each node picks the path with the most accumulated work. A temporary fork leaves orphan blocks behind, and the deeper a block sits, the more stable it becomes.
2. An Everyday Analogy
Dirt Paths in a Park
A park has paved paths, but it also has dirt paths that visitors have worn into the grass. No park manager holds a vote on which path should exist. When lots of people choose the same shortcut on their own, that path gets worn deeper and deeper into the ground. Paths that few people use slowly fade away.
Nodes choosing a transaction history work a lot like this. There's no central vote. Each node uses the same criterion to decide which chain to extend. The path most nodes choose keeps getting longer, and the minority branches get abandoned over time.
A Fork in the Road
At some point, a road splits in two. Both branches exist for a while, but which one becomes the main road depends on how many people keep using it and which one gets built out further.
A blockchain fork works the same way. Two branches can be the same length for a while, until the next block shows up and breaks the tie.
3. Core Concepts Explained
3.1 Why Forks Happen
Blocks have to spread across the network. Two situations can easily cause a fork:
- A node creates a new block, but the news hasn't reached every node yet.
- Two nodes solve a new block at almost the same moment, and each one broadcasts its own block.
As a result, some nodes keep building on the old block while others build on the new one. Instead of a straight line, the blockchain grows into a tree with branches.
A fork doesn't mean the system is broken. It's a normal side effect of spreading information in a distributed system. What matters is that all nodes eventually use the same rules to pick one authoritative chain.
3.2 The Longest Chain Criterion
The longest chain criterion says: pick the path with the most blocks.
The idea is that more blocks usually means more total computing work went into the path. A node doesn't need a central authority to tell it which chain to pick. It just has to see which path is longer.
If two branches are the same length, the longest chain criterion can't name a winner yet. Nodes are free to pick which one to extend first. Whichever branch the next block attaches to breaks the tie, and the other one becomes an orphaned branch.
3.3 The Heaviest Chain Criterion
When blocks have different difficulties, more blocks doesn't necessarily mean the most accumulated work. That's where the heaviest chain criterion comes in.
Every block header records its difficulty. Add up the difficulty of every block on a path, and you get that path's weight. The path with the greatest weight is the one with the most accumulated computing work.
If every block has the same difficulty, the longest chain and heaviest chain criteria pick the same chain. When difficulty changes over time, they can disagree, and real systems usually go with the heaviest chain.
3.4 Orphan Blocks
Once nodes have picked an authoritative chain, the blocks on the other branches are no longer part of the authoritative history. These are called orphan blocks.
Transactions in orphan blocks are treated as if they never happened, and they can't be used to prove ownership. The rewards paid for these blocks are taken back, and their transactions go back into the processing queue, where they can still make it into the authoritative chain later.
3.5 Eventually Consistent, Not Immediately Consistent
When a fork appears, different nodes may see different histories for a while. But as new blocks keep getting added, one branch pulls ahead and the others get abandoned. In the end, every node lands on the same authoritative chain. This is called eventual consistency.
The deeper a block sits, the less likely it is to be abandoned, because:
- It was added earlier.
- More blocks have already been stacked on top of it.
- More and more nodes have accepted it.
- A random fork is less likely to replace it.
So the longer a transaction has been confirmed, the safer it usually is. A block that was just added can still get replaced by a fork.
3.6 Why Forks Don't Split Forever
Forks usually share a common trunk. Nodes are only competing on different branches at the tip of that trunk. Every new block gives one branch more of an edge, and the other branches drop out over time.
So in practice, a blockchain looks more like a tree or a cactus. It has a trunk and branches, but the branches get pruned according to the selection criterion.
3.7 The 51% Attack
If an attacker controls more than half of the voting power in the system, they could turn blocks on the authoritative chain into orphan blocks and then build a new authoritative chain that works in their favor. This is often called a 51% attack.
In systems that rely on proof of work, voting power is tied to computing power. To control most of the voting power, you have to control most of the computing power. The attacker would need to:
- Redo the proof of work for the tampered block.
- Redo the proof of work for every block after it.
- Catch up with and pass the chain the honest nodes maintain.
If honest nodes control most of the computing power, they produce blocks faster, the attacker struggles to catch up, and the tampered chain gets discarded.
3.8 Why Randomness Matters
If you could predict the order in which blocks get produced, attackers could plan ahead. They could target a particular node, a particular time window, or whoever is about to produce the next block.
The hash puzzle makes it random who solves it first, so no one knows in advance who will produce the next block. That makes attacks harder to plan and their payoff harder to calculate. Randomness isn't decoration. It's part of what makes consensus secure.
3.9 Relying on an Honest Majority
The name "51% attack" can make people think you need exactly 51%. What it really means is "controlling the majority of voting power." This mechanism's security rests on one assumption: no single participant or organization can control most of the computing power for long.
If an attacker controls most of the computing power, they can suppress competing chains, create forks, and reverse transactions, and you can no longer trust the system's integrity.
4. Diagrams
Figure 3-3-1: Forks and the Longest Chain
Figure 3-3-2: The Longest Chain vs. the Heaviest Chain
5. Key Takeaways
- Forks come from network delays and blocks produced at the same moment. They're a normal part of distributed systems.
- The longest chain criterion picks the path with the most blocks. The heaviest chain criterion picks the path with the greatest total difficulty.
- When difficulty is the same, both criteria give the same result. When difficulty changes over time, the heaviest chain is usually used.
- Blocks that lose out in a fork are called orphan blocks. Their transactions are treated as if they never happened and get processed again.
- Eventual consistency: as new blocks are added, nodes end up on the same authoritative chain.
- The deeper a block sits, the less likely it is to be replaced, and the more stable its transactions' confirmation.
- A 51% attack means controlling most of the voting power so you can turn blocks on the authoritative chain into orphan blocks.
- Proof of work ties voting power to computing power. Security rests on the assumption that honest nodes hold most of the computing power.
6. Quiz
Part 1: Single Choice (1–4)
Question 1
What's the most common cause of a blockchain fork?
A. Every node going offline at once
B. Network propagation delays, or two nodes producing a block at almost the same moment
C. Too many private keys
D. Block headers with no timestamp
Show answer
Answer: B
Explanation: Forks usually come from network propagation delays or blocks produced at almost the same moment. Nodes going offline, the number of private keys, and missing timestamps aren't the main causes.
Question 2
What does the longest chain criterion pick?
A. The path with the most blocks
B. The path with the largest block size
C. The single transaction with the highest fee
D. The block with the earliest timestamp
Show answer
Answer: A
Explanation: The longest chain criterion looks at the number of blocks, not block size, fees, or a single timestamp.
Question 3
When blocks have different difficulties, what should you use?
A. The longest chain criterion
B. The heaviest chain criterion, which adds up the difficulty of every block on the path
C. Picking a chain at random
D. Picking the chain with the fewest transactions
Show answer
Answer: B
Explanation: When difficulties differ, more blocks doesn't mean more accumulated work, so you use the heaviest chain criterion and add up the difficulty.
Question 4
What happens to the transactions in orphan blocks?
A. They disappear forever and can never be processed again
B. They're treated as if they never happened and go back into the processing queue
C. They automatically become valid transactions
D. They go straight to the attacker's account
Show answer
Answer: B
Explanation: Transactions in orphan blocks are treated as if they never happened and go back into the processing queue, where they can still make it into the authoritative chain later.
Part 2: Multiple Choice (5–7)
Question 5
Which statements about forks are correct?
A. A fork can come from delays in spreading messages
B. Two branches can be the same length for a while
C. The next new block can break the tie
D. Once a fork appears, it never converges
Show answer
Answer: A, B, C
Explanation: A fork can come from delays or blocks produced at the same moment, and the next block breaks a tie. D is wrong because forks eventually converge.
Question 6
Which statements about eventual consistency are correct?
A. The deeper a block sits, the less likely it is to be replaced
B. The more blocks stacked on top, the more stable the transactions
C. A newly added block can still be abandoned because of a fork
D. Every transaction is absolutely final the instant it's added to a block
Show answer
Answer: A, B, C
Explanation: The deeper a block sits, the more stable it is, and new blocks can still be replaced. D is wrong because it claims transactions are "absolutely final the instant" they're added.
Question 7
Which statements about the 51% attack are correct?
A. The attack aims to control most of the voting power
B. In a proof of work system, most of the voting power usually means most of the computing power
C. The attacker has to catch up with and pass the honest chain
D. When honest nodes control most of the computing power, the attack is more likely to succeed
Show answer
Answer: A, B, C
Explanation: A 51% attack means controlling most of the voting power, which under proof of work means most of the computing power, and the attacker has to catch up with the honest chain. D is wrong because an honest majority makes the attack harder.
Part 3: True or False (8–9)
Question 8
True or false: the longest chain is always the chain with the most accumulated computing work, even when blocks have different difficulties.
Show answer
Answer: False
Explanation: When difficulties differ, the longest chain doesn't necessarily have the most accumulated work, so you should use the heaviest chain.
Question 9
True or false: randomness in block production makes it harder for attackers to predict who will produce a block and when.
Show answer
Answer: True
Explanation: Random block production makes it hard for attackers to predict who will produce a block and when, so attacks are harder to plan.
Part 4: Scenario Analysis (10)
Question 10
After block B, a chain splits into two branches of the same length: branch C and branch D. Then one node produces E after C, and another node produces F after D, so the branches are still the same length. Finally, a node produces G after E.
Answer the following:
- Which branch becomes the authoritative chain?
- Which branch's blocks become orphan blocks?
- Why is a newly added block less stable than a deeper one?
Show answer
Answer:
- The branch with G becomes the authoritative chain, because it kept growing after E and is now longer than the D/F branch.
- The blocks on the branch with D and F become orphan blocks.
- A newly added block has no blocks stacked on top of it yet, so another branch could still grow longer and replace it. A deeper block already has many blocks built on top of it, so it's much less likely to be abandoned.