We looked at double spending and immutability in blockchain in the previous article. In this article, let’s discuss forks in blockchain.
Forks, as the name implies, splits the blockchain into two branches. A blockchain can have several types of forks. We call the first type we are going to look at a temporary fork. This happens when two miners mine blocks at the same time.
When this happens, miners continue mining referring to the block they received first. Since miners don’t receive the blocks in the same order, this results in two branches. Once one branch becomes longer, nodes accept it as the right branch and abandon the other branch. We call the abandoned branch an orphaned branch. When a branch becomes orphaned, all the transactions in the blocks go back to mempools and miners will have to confirm them again.
However, forks can also occur after an update to the blockchain protocol. When such a thing happens, not all nodes would update to the latest protocol right away. This would mean there will be some nodes using the new version and others using the older version.
This type of fork can be of two types depending on the backward compatibility of the update. If the update is backward compatible, it creates a soft fork. If it is not, then it creates a hard fork.
To understand this, let’s try to make sense of backward compatibility. If an update is backward compatible, then blocks produced using the newer protocol will still be compatible with the older protocol. For example, if the new protocol reduces the maximum size of a block from 1 MB to 512 kB, the blocks mined using the newer protocol will still be compatible with the older protocol since 512 kB is less than 1 MB and, hence, valid.
When this happens, the nodes using the latest protocol will reject blocks produced by the miners using the older protocol since 1-MB-sized blocks are larger than the maximum allowed size for a block. Thus, nodes using the latest protocol will be blind to the blocks produced by nodes running the older protocol.
However, nodes using the older version will be able to accept blocks produced by both the latest protocol and the older protocol since a block size of 512 kB is less than the allowed maximum size of 1 MB. This creates a fork. Both the latest nodes and the older nodes will be working on their chains but the older nodes will be able to see both chains. In other words, only the older nodes will be aware of the fork.
We call the resultant fork a soft fork. If more nodes update to the latest protocol, the branch containing the chain of blocks worked on by the nodes running the latest protocol will become longer and the nodes running the older version will have to orphan their branch and continue working on the chain of the latest nodes. Eventually, there will be no reward for older nodes as the blocks they mine get continuously orphaned. Consequently, this will force them to update.
However, if most nodes refuse to update and only a few nodes update, then the chain of the older nodes will always be longer. Then, it is the chain produced by the latest nodes that the older nodes will orphan. Nevertheless, the latest nodes will continue working on their branch since they can’t see the other branch.
This creates a precarious situation. Since the number of nodes working on the latest branch is small, then it makes this branch susceptible to the 51% attack. At the same time, the latest nodes can perform transactions only with a limited number of nodes. This may force them to downgrade their nodes to the older version to continue transacting with everyone else.
Hence, it’s up to the community to convince nodes, both transacting parties and miners, to update to the newer protocol. If a substantial number of nodes update, then that would eventually force the rest to update as we saw earlier.
When an update to a protocol is backward incompatible, it creates a hard fork. Let’s say the new protocol increases the maximum allowed size of a block to 2 MB. Older nodes won’t accept the blocks mined by the latest nodes since they can only accept blocks that are less than 1 MB. However, the latest nodes will be able to accept blocks mined by the older nodes.
This would mean the older nodes can’t see the chain the latest nodes are working on. But the latest nodes can see both their chain and that of the older nodes. If there are more older nodes than the latest nodes, then the latest nodes will continue to have their branch orphaned. In that case, more nodes should be encouraged to update or else the older nodes will keep winning.
If there are more latest nodes than older nodes, then the latest nodes will have their branch win. But since the older nodes can’t see the latest nodes’ branch, their chain will not suffer a fork. Unlike the case with a soft fork, even if a substantial number of nodes update, the older nodes will still have no incentive to update. This is because older nodes can see only their branch and hence, will not have their branch orphaned.
This poses a risk of the network splitting into two. This happened in reality when some nodes updated to a blockchain protocol that increased the maximum size of a block to 8 MB. This meant that the older nodes continued with their chain with a substantial number of miners mining on it while the latest nodes continued with their chain with enough miners working on it to ensure their branch remained longer.
This makes a hard fork a permanent split in comparison to a soft fork. So, following a hard fork, in effect, we get two blockchains that share a common history until the point of the fork. However, if the branch worked on by the old nodes becomes longer, the new nodes will be forced to orphan their branch and accept the branch of the older nodes. This would defeat the whole purpose of updating the protocol. So, in such situations, the hard fork is turned into a separate currency.
This is how Bitcoin Cash was born. The maximum size of a block was increased to 8 MB and the Bitcoin community was divided into two. Some of the community members accepted the new protocol while others resisted resulting in a hard fork. The new blockchain became Bitcoin Cash.
In this article, we talked about blockchain forks. In the upcoming articles, let’s look at the 51% attack in detail.