In this blog, I will discuss blockchain forks and how these types of blockchain forks are solved. In blockchain forks, there are actually two miners who want to verify a transaction on the blockchain at the same time. How is this "disagreement" resolved? How is it decided what the ''right'' blockchain is? What happens to the (orphaned) block that is not verified?
Longest chain rule - explained via an analogy
In a fictional village, 100 farmers live and work. These farmers all have a piece of land on which grain is grown. Each month, these farmers carry bags of grain to a central point. At this central point, all bags of grain are collected and shipped to be sold. 50 farmers believe that the bags of grain could be larger so that more grain could be sold. The other 50 farmers disagree because larger bags are heavier. Elderly and weaker people cannot carry a larger and heavier bag to the central point. So there is a disagreement among the farmers. How do we solve this? The mayor says we solve this by voting. But some farmers protest, because they don't want each bag of grain to have equal weight. They argue that the heavier a bag of grain is, the more weighty his or her vote is.
And then a farmer named Satoshi came up with an idea. If everyone came to the central point next month to deliver their bags of grain, we would vote by the number of bags. So we create two rows of bags of grain. One row is the ''increase the volume of grain bags and thus more sales'' (row 1), while the other row is ''we are not going to increase the volume of these grain bags'' (row 2). Each farmer with bags of grain places their bag at one of the two rows. The row with the most bags of grain (i.e. longest row), wins! Suppose this is the row where ''the volume of the bags are increased to boost sales'' (row 1). This results in the bags of grain being increased because row 2 is shorter (longest chain rule).
Disagreements within a blockchain are resolved in the same way. The farmers are the miners (those who verify a transaction on the blockchain) and the rows of grain represent the blocks in the blockchain. If there is disagreement, network participants (nodes) can "fork" the current chain. This starts a new chain of blocks. Participants who agree on this new chain can now apply their "blocks" to the new chain as well. Eventually, if the new chain extends the old one - the Longest Chain Rule will come into effect and will be declared the winning chain.
Blockchain forks
Before the disagreement, all was well and fine. There is only one chain on which the blocks are verified. The moment there is a disagreement, the blockchain is actually split into 2 blockchains. This is called a ''fork''. For example, think of a road that splits into a road to the left and a road to the right. Eventually you choose one of the two. On the blockchain, the same applies. The main blockchain is split into two, and the miners then decide which of the two becomes the main blockchain.
Why do Forks occur?
The proof of work consensus mechanism is designed to reach agreement in a blockchain system. As you may know, the task of miners is to verify transactions on the blockchain. The fastest miner to accomplish this (via a hashing puzzle) gets to verify the transaction. Miners thus compete with each other.
Suppose we have block number A and the miners compete with each other to verify block B on the blockchain. Miners try to solve the hashing puzzle as fast as possible until there is a winner. So this miner gets to add the block to the blockchain. So far so good.
Sometimes two miners solve the hashing puzzle at the same time. One half of the miners accepts block B and the other half accepts block B2. So a fork...
How are forks resolved?
So we have a disagreement between the miners. The miners disagree on which block (B or B2) will become the next block on the main blockchain.
So we have two scenarios.
1. The majority of miners choose block B as the valid blockchain.
2. The majority of miners choose block B2 as the valid blockchain.
Suppose the majority of miners choose scenario number 1. This means that there are many more miners verifying transactions on block B (block C, D etc). Over a longer period of time, we see the block from B increase with other blocks, while the row from B2 lags behind. So after a period of time, we see that due to the longest chain rule, the main chain continues on block B. This has the following consequences:
1. Chain B is the valid/main chain;
2. The transactions that are on block B (and further) are valid;
3. The transactions and blocks from B2 are ignored and are called ''orphan'' blocks.
What happens to orphan blocks?
The transactions in the alternate fork don't disappear - they simply get put back into the pool of unconfirmed transactions and miners will put them into a subsequent block (on the main chain). Orphan blocks do not become invalid.
To illustrate
There is no disagreement. Block B is verified on the main chain:
Two miners solve the hashing puzzle simultaneously. There is a disagreement among miners which block should be the on the main chain:
Block B (and further) will be the main chain, because it has the longest chain (most difficult to create and could be the only ‘true version’ of the blockchain). More hashing puzzles are solved on the B row. Blocks B2 and B3 are orphaned. They are put back to miners to verify so they can be added to the next block (on the main chain).
Do miners of orphan blocks receive a reward for their time and effort?
Miners who are the first to solve the hashing puzzle and are allowed to verify a transaction on the blockchain, receive a block reward and transaction fee. It is logical to say that miners who have verified orphan blocks (solving a hashing puzzle) also get these rewards. But that unfortunately is not the case. Many miners find this unfair. They are not rewarded for the work they do because they do not contribute to the authoritative (main) chain.
This is different with uncle blocks. This is the same as orphan blocks, but uncle blocks originate on the Ethereum blockchain (in this article, I discussed the Bitcoin blockchain). Miners of uncle blocks receive a block reward for their time and effort. Ethereum incentivizes uncle blocks for several reasons. One of the reasons is to increase the number of transactions on the blockchain.
Orphan blocks:
Double spending?
Please note that no double spending occurred. It looked liked it because two transactions were verified on the blockchain simultaneously. But because the longest chain is the valid main chain, the other transaction (B2) is invalid. So no double spending attack could occur. The B2 transaction would be deemed invalid. Just one transaction came through, which is transaction B.
Read my blog about the double spending problem here.
BTC address: bc1q3nnm8m2vrsv8med8a38dl37g8l3mm4wa7ph7wj
ETH address: 0x38b84E2D3B50F83A067A7488C1733180651f418A
Reactie plaatsen
Reacties