In the previous post I explained the Longest Chain Rule using an analogy. The analogy seemed to help several of the Mango Readers grasp the importance the rule plays. If you haven’t read it yet, I urge you to do so. The Longest Chain Rule plays a vital role in the Bitcoin and Ethereum consensus mechanism. Furthermore, it may also clear out other doubts you may have concerning Blockchain Forks.
This brings me to a question I received from Randy yesterday:
Great explanation on longest chain!
" Why do we have 'Forks' if we have the Longest Chain Rule?
Is the longest chain rule applied during a 'fork' ? "
Cheers! - Randy “
Quick Answer: Yes, the Longest Chain Rule will kick in when forks appear. Each fork will have its own chain and miners can pick which one to apply their work on. But eventually the longer of the chains will be declared the winner – and all miners will apply their work onto that chain.
That’s the quick and dirty answer. But I’d like to dive a bit deeper into this – and run you guys through exactly how this happens.
Why? Because understanding the Longest Chain Rule will be fundamental in allowing you to grasp other ideas (for example: 51% Attack). In fact, once you grasp this idea – most of the other concepts will become super easy and intuitive.
Longest Chain & Blockchain Forks
But what exactly is a “fork” ?
A fork is simply an occurence of a disagreement. Remember, the primary aim of a consensus model is “ordering of events”.
Questions that fall under “ordering of events” criteria:
Q) “Who gets to place the next block?”
Q)“Whose transaction gets verified first?”
So when we have a disagreement in who gets to place the next block – we will have a “fork”
Going back to the Farmer Analogy – the fork was simply the two rows that were placed at the townhall. Up until the disagreement, everything was fine and dandy. Once the disagreement occurred – two rows were laid. Each row represented a decision. Villagers will vote by placing their sacks of rice in each of the two rows and the longer of the two rows will win.
It’s a similar process in a blockchain. Initially, everything is fine & dandy – and there’s only one “main chain”. When a disagreement occurs, the chain splits into two. This is called a “fork”.
(It’s kinda like when you’re driving down the main road and it “forks” into two different paths. You have to now choose between two paths. In the blockchain, the mainchain splits into two – and the miners now choose between two chains.)
But why do disagreements occur? Isn’t proof of work supposed to solve that?
Why Do Blockchain Forks Occur ?
The Proof Of Work Consensus model is designed to allow the network come to agreement. So forks like this shouldn’t happen, right?
If you read my post on the PoW Cryptographic Puzzle, you know that miners compete against each other to win the right to place the next block.
The “winner” is the miner who solves the puzzles first. The rest of the network then “agrees’ that he gets to place the next block – and they will continue the process with his block being deemed the last approved/valid block.
Let’s say the last valid block is Block A. Miners are now competing fo Block B. Miners will attempt to solve the puzzle until they hear a winner is declared. “
However, ever so often – we may have two “winners” simultaneously.
Since, the winner is broadcasted and propagated through the network – different participants may hear a different winner. Once a winner is declared and “heard”, the miners accept that winning block and move on to the next block.
So now we may have one group of miners accepting Block B, and the rest of the miners accepting Block B2. Hence, fork…
How Are Blockchain Forks Resolved - Orphaned Chains
Alright, so a fork has occurred. What now? How do we achieve consensus again? Did the Proof Of Work Consensus method fail here? No – it didn’t.
Proof Of Work accounts for this sort of scenario with the Longest Chain Rule.
The Longest Chain Rule ensures that network will recognise the “chain with most work” as the main chain. The chain with the most work is typically (not always) the longest of the forks.
Block B and Block B2 seemed to have won the Cryptographic Puzzle at the same time. The chain splits. There are now two scenarios that may take place:
Let’s assume Scenario #1 takes place.
This would mean that there are far more people solving for the cryptographic puzzle on Chain B.
Remember – the chance to solve the puzzle is random. But since Chain B has more people trying to solve the puzzle, it will probably solve it faster. The key word here is “probably”. Chain B2 may still solve the next (or next few) puzzles faster.
However, over a longer period of time – the probability will win out. Eventually Chain B will outpace Chain B2. The Longest Chain Rule will then kick in – and the following will happen:
- Chain B will be considered the main chain.
- The transactions contained within all the blocks on Chain B will be considered true and valid.
- All the blocks & transactions on Chain B2 will be considered orphaned and will be ignored.
That’s pretty much it – simpler than you thought it’d be eh? The longest chain rule plays a crucial role in achieving consensus. You can probably use this explanation to figure out how this would play out in a 51% attack as well. If not, I’ll be writing a post on that soon. And now that you know the Longest Chain Rule, it’ll be a breeze to understand 🙂
Did this post help you?
Help Us Keep Doing What We Do Best!
Tip Jar 🙂
Did you enjoy this post?
Help Us Keep Doing What We Do Best!
Tip Jar 🙂
Get my upcoming eBook for Free!
"The Mango Guide TO Understanding Blockchain"
Offer Valid For FIRST 500 registrations only