In this article, we learn about blockchain forks, what they are, how they happen, and why they happen.
Table of contents.
- The Blockchain Forking Process.
- Bitcoin scalability problem.
- Hard forks and Soft Forks
A blockchain is a decentralized database, every network peer stores a copy of the entire blockchain. In some cases, copies from different peers are valid but not always similar. This can be caused by blocks arriving at different nodes at different times leading to each having a different perspective of the blockchain.
This is resolved by each node selecting and attempting to extend the chain representing the most cumulative Proof-of-Work. In order for the chains to converge into a single chain, nodes have to select the chain with the most cumulative Proof-of-Work. Forks are just temporary inconsistencies in a blockchain resolved by reconvergences as more blocks are added to one of the forks making it the main chain.
The Blockchain Forking Process.
As mentioned each node has a different perspective of the blockchain. As each receives blocks from neighboring peers, it updates its own copy of the blockchain by selecting the chain with the most cumulative Proof-of-Work. In the following diagrams in this section, each node has a shape representing the block it believes is at the tip of the current main chain.
In this case, a star means the tip of the main chain is a star, a triangle means the tip of the main chain is also a triangle, and downward-facing square means that the tip of the main chain is also a downward-facing square, and so forth.
This is demonstrated in the image below;
Above all nodes agree on a single tip which is a star.
In blockchain technologies, a fork is the result of two candidate blocks competing to form the longest chain. Forks happen when two miners solve the cryptographic puzzle at the same time and immediately broadcast their winning blocks to their immediate neighboring peers that in turn propagate the block across the network. Each node after receiving and validating the new block from each of the miners propagates to neighboring peers that incorporate it into their own copies of the blockchain thus extending the blockchain by one block. If a peer node later sees another candidate block that extends the same parent, it connects the second candidate to form a secondary chain.
The following image demonstrates the above concept;
Above we have two miners who solve a cryptographic puzzle at the same time. Both blocks become children of the star block - main chain. In our case, we have the triangular block that originates from Node X(miner X) and a downward-facing triangular block originating from Node Y(miner Y).
In the case, a miner X finds a Proof-of-Work solution for triangular block extending the blockchain that is built on top of the parent star block and simultaneously the miner Y, currently extending the star block finds a solution for the downward-facing triangular block, we will have two valid blocks a the upward triangular block and the downward triangular block.
The former originated from Node X and the latter from Node Y. Both extend the star block. Both are also likely to have similar transactions with a difference in their orderings.
The two nodes will propagate their solutions meaning that while some nodes will receive triangular blocks others will receive downward-facing triangular blocks. This is demonstrated in the image below;
Above a random Node X receives the propagated triangular block and started a chain with it. It also selects the chain with the triangular block as its tip as the main chain. Later the same node receives the downward-facing triangular block(yellow) block. Since it is the second one to be received, it is used to form a secondary chain. This secondary chain is kept as a reference and can also be used later if it turns out to be the one with the most cumulative Proof-of-Work.
On the other hand, Node Y builds a chain based on the downward-facing triangular block. When it later receives the upward-facing triangular block, it connects it to the star block parent as a secondary chain. Neither chain is invalid, these are just different valid perspectives. A single chain is expected to come out as the winner and this is determined by the cumulative PoW for each. Nodes that agree with Node Y start mining a candidate block with a downward-facing triangular node as their parent extending the chain they believe to be the main chain. This is the same for nodes agreeing with Node X, they also start mining a candidate block that extends the chain with a triangular node as its tip.
Note that the network hashing power is also divided into two, the first is used to develop the downward-facing triangular chain and the second is used to develop the triangular chain. This computational power in most cases will be evenly split however a single side will most likely solve the cryptographic puzzle first and propagate the winning block before the other does.
For example, in the case the triangular chain solves the puzzle first, we will have a square extending the chain. This new block is propagated and the whole network validates it as the correct solution. All nodes will now choose the triangular chain as the winner and extend the chain by a single block.
Nodes that had previously chosen the downward-facing triangular chain will now have two chains, a star-triangular chain and a star-square chain.
Now, since the star-square chain is now the longest chain, this is because it has more cumulative PoW(Proof of Work) than its counterpart, it makes other nodes select it as the main chain. This results in a convergence. Now we have a single chain that all peers agree on.
A reconvergence comes as a result of nodes revising their views of the blockchain to incorporate the new evidence of a longer chain - the main chain. A miner who previously worked on a candidate block that referenced the square chain as their parent now has to extend to the star-square chain since it is the longest chain.
We now have the network looking as shown in the following image;
Theoretically, it is possible for a fork to extend two new blocks, this comes as a result of two blocks being found simultaneously by miners on opposing sides of previously formed chains. The chances of such cases very are low. A single-block form can happen every day while a two-block form can happen every few weeks at most. Three-block forks seldom occur.
The 10-minute block interval is designed as a compromise between fast confirmation times and the probability of a fork. A faster block time leads to transactions being processed faster and more forks being created while a slower block time reduces the number of forks that can be created at a time but makes processing transactions slow.
Bitcoin scalability problem.
This refers to Bitcoin's limited capacity to handle large amounts of transactions in a short period.
This comes as a result of the size of Bitcoin blocks which is small(1 MB). Remember blocks are responsible for storing transactions, the problem with Bitcoin is that the number of transactions it can handle compared to Ethereum is small.
Bitcoin's transaction processing capacity is limited by the average block creation time of 10 minutes. This combined with the small block size is a constraint on network throughput. That is, the network can only process 3 to 7 transactions per second.
Such issues are what cause blockchain forks to emerge. In the next section, we learn about the two different types of forks and give examples of Bitcoin forks that came about as a result of its scalability issues.
Hard forks and Soft Forks.
In this section, we learn about the major two types of forks that can happen in a blockchain, what causes them, and examples of both.
A hard fork involves a change to a blockchain network's protocol, this renders all previous invalid blocks and transactions valid or all valid blocks and transactions invalid, it can be either way. It is like a software patch or upgrades where participants, 'miners' in this case are required to upgrade their software to the latest version.
Hard forks result in two chains of the blockchain, one following a newer protocol and the other abiding by the old. The latter's nodes and transactions are rendered invalid through such a fork.
What does this mean for participants with a stake? Well, the coins are not lost as they are issued back in the new protocol. Miners have a choice on which blockchain they will choose to direct their computational power to.
Examples of hard forks in Bitcoin include; Bitcoin Cash, and Bitcoin Sv.
Examples of Etherium hard forks include; Ethereum Classic.
These forks when made result in previous transactions being invalidated. In this case, old nodes see the new nodes as valid this makes a soft fork backward compatible. For this fork to occur, miners must come to a consensus and decide to upgrade so the new features or rules can be incorporated into the network.
A soft fork can be used to add blockchain features such as new types of transactions, in this fork, miner nodes and other participants are left to understand the new transaction type.
Note that soft forks follow the same rules are their predecessor therefore, they don't need any node to upgrade for consensus to be upheld.
An example of a soft fork is the SegWit update made to the Bitcoin blockchain in 2015.
In 2016 a DAO(Decentralized Autonomous Organization) was started in the Ethereum blockchain, the end result of this was two chains, the original Etherium before the event and Etherium Classic which was as a result of its participants refusing to go back to the previous chain.
The hard fork of Bitcoin Cash and SegWit2x. This resulted in Bitcoin Cash in August 2017. This chain had larger block sizes compared to the original Bitcoin. It also has lower transaction fees compared to Bitcoin.
Blockchain forks occur when two or more blocks have the same block height.
Forks happen as a result of transmission delays in the network. Forks can also be induced deliberately as a result of disagreeing interests between participants or occur accidentally. The latter happens when two or more miners solve the cryptographic puzzle simultaneously. Intentionally induced forks aim to change the rules of the existing blockchain.
Intentional forks can be hard or soft. Hard forks change the rules of a blockchain. In this case, when the rules change, nodes/peers that agree with the rules upgrade their software and they are no longer participants of the old blockchain. Case on point, Bitcoin Cash - a hard fork of Bitcoin with lower transaction fees and faster than its predecessor.
Soft forks allow nodes to be backward-compatible. In this case, nodes can choose not to follow the new rules but remain valid.