TeachMeBitcoin

Nakamoto Consensus

From TeachMeBitcoin, the free encyclopedia ⏱️ 4 min read

Nakamoto Consensus (The Longest Chain Rule)

In a centralized database, a single master server decides which transactions are real. But in a decentralized, global network where anyone can run a node or a miner, how does the network coordinate to agree on a single, shared ledger?

If different miners broadcast different blocks at the same time, how does the network resolve the conflict?

The answer is Nakamoto Consensus, which utilizes the Heaviest Chain Rule (commonly referred to as the Longest Chain Rule).


🍴 The Fork: When Two Truths Exist

Because Bitcoin nodes are distributed across the globe, it takes several seconds for a newly mined block to propagate to all peers. Occasionally, this latency causes a temporary conflict:

  1. Simultaneous Solution: Miner A (in Canada) and Miner B (in Germany) find a valid block at almost the exact same second.
  2. Conflicting Broadcast:
    • Miner A broadcasts Block 100-A to their local peers.
    • Miner B broadcasts Block 100-B to their local peers.
  3. A Split Network: The network is now split in half. Nodes in North America adopt Block 100-A as the tip of their ledger, while nodes in Europe adopt Block 100-B.

Both blocks are mathematically valid, and both contain valid transactions. The network has forked.

                                  β”Œβ”€β”€β”€β–Ί [ Block 100-A ] (North America Tip)
                                  β”‚
 [ Block 99 ] ─────────────────────
                                  β”‚
                                  └───► [ Block 100-B ] (Europe Tip)

Without a central leader to decide, how does Bitcoin heal this split and converge back to a single truth?


πŸ† The Heaviest Chain Rule (Heuristic Consensus)

Satoshi Nakamoto’s solution is beautifully simple: Trust the chain that represents the most accumulated physical work.

When a fork occurs, nodes do not panic. They keep both branches in their memory database, but they treat the branch they heard about first as the active branch. They then wait for the next block to be mined.

Miners on both sides of the ocean begin compiling Block 101: * Miners in North America build on top of Block 100-A. * Miners in Europe build on top of Block 100-B.

Eventually, some miner somewhere in the world solves Block 101. Let's assume a miner in Singapore solves Block 101-A (linked to Block 100-A):

                                  β”Œβ”€β”€β”€β–Ί [ Block 100-A ] ───► [ Block 101-A ] (Winner!)
                                  β”‚
 [ Block 99 ] ─────────────────────
                                  β”‚
                                  └───► [ Block 100-B ] (Discarded)

As Block 101-A propagates across the global network, the European nodes receive it. They see that: * Their current active chain length is 100 blocks (ending in 100-B). * The newly arrived chain length is 101 blocks (ending in 101-A). * The 101-block chain has more accumulated Proof of Work difficulty.

Following the consensus rules programmed into the software, the European nodes immediately perform a blockchain reorganization (reorg). They discard Block 100-B, switch their active pointer to Block 100-A -> 101-A, and begin mining Block 102.

Consensus is achieved, and the split is healed trustlessly.


βš–οΈ "Longest" vs. "Heaviest": A Critical Technical Distinction

In casual conversation, we say "the longest chain wins." However, in the Bitcoin codebase, this is a slight misnomer. The rule is actually the chain with the most accumulated Proof of Work difficulty wins.

Why does this distinction matter? * If consensus was based strictly on the number of blocks, an attacker could copy the Bitcoin software, set the difficulty target to near-zero, and quickly mine 1 million fake blocks in a few minutes on a home laptop. * If that attacker connected their 1-million-block chain to the network, nodes would see it is "longer" than the real chain (which has ~850,000 blocks as of 2024). * However, because each block on the fake chain had near-zero difficulty, the total accumulated work of those 1 million blocks is infinitesimally small. * The nodes will see that the real chain of 850,000 high-difficulty blocks has trillions of times more accumulated thermodynamic energy, and they will instantly reject the attacker's fake "longer" chain.

Nakamoto Consensus ensures that the chain backed by the most physical energy is always accepted as the ultimate truth.

β˜• Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!