In this post, we will take a look at “orphan blocks” in Bitcoin. For the most part, all blockchains that utilize the Proof-of-Work (PoW) algorithm function similarly to what I describe below.
In Bitcoin, there is a concept known as “longest chain wins”. What this means is that the chain with the most cumulative PoW will be the valid or “main” chain accepted by the network. This rule exists to prevent an individual or group of individuals from outpacing the collective network (unless said group represents more than 50% of that network). Because the PoW algorithm requires an immense amount of computation, and thus energy, it is much too difficult and expensive for malicious actors to try and maintain the longest chain.
Also Read: How Bitcoin Mining Work?
Most often the longest chain will be the chain that contains the most amount of blocks, but if the chain has the same number of blocks, it will instead be the chain with more collective PoW (by summing the difficulties). It should be noted the term “longest chain wins” can often be a bit misleading as it suggests that there could be multiple independent competing chains (unless we are referring to testnets, but they do not compete) in a single network. Instead it should be thought that multiple paths can be taken in a chain and nodes are expected to follow the path with the most PoW.
But what do I mean by these paths? Well we often get into a situation where there is an unintended divergence or “fork” in the network.
In blockchains using the PoW algorithm, unintentional forks happen when two miners on the network solve the PoW puzzle at a similar time. When these miners announce they have a “winning” block to the rest of the network (propagation), it is not instantaneous, due to latency.
It will always take some amount of time before all nodes can become aware of a newly mined block.
For example, let’s say that two miners both solve the PoW puzzle at almost the same time. We’ll call these blocks B and B’. Both miners will propagate their “winning” block to their nearest neighbors who will in turn repeat the process. This happens until the entire network is aware of the new block. If it takes 10 seconds (this is not how long it actually takes) for a block to reach the entire network, and both miners are on opposite sides of the world, at 5 seconds into propagation we will have a split network (assuming latency remains constant across the network).
Half the network now believes the chain with block B at its head is the correct chain to follow, while the other half believe B’ to be the correct chain.
Well, this is obviously a problem because…
To rectify this issue, after the entire network becomes aware of both B and B’ they will keep the block they saw first at the head of their chain, but will also link the block they saw second to their parent (the block that came immediately before B and B’) as a reference.
After this, the mining nodes immediately begin the process of mining the next block, and the race begins. Depending on the miner, the next block will either be added to the chain with block B or the chain with block B’.
For this example, let’s assume that a miner with B as their winning block mines the next block C. They will now add C to their chain (making it the longest chain) and propagate this to the rest of the network. Unless there is another fork, upon receiving C, nodes with block B’ at the head of their main chain will accept the path with block B (with C being the head) as it is now the longest chain.
B’ transactions are then returned to the mempool, B’ is discarded and spit on making it an orphan, and much to the dismay of the miner of B’, they lose their reward for mining the block.
This is the reason Bitcoin block intervals are set to 10 minutes. Satoshi Nakamoto determined it to be the sweet spot between fast (enough) confirmation times and low probability of forks and therefore less orphans in the world, which is always a good thing.
For a nice visualization and more in-depth look at this and more visit chapter 10 of “Mastering Bitcoin” by Andreas Antonopoulos, available on GitHub.
It recently came to my attention that there is a lot of confusion surrounding the difference between an orphan block and a stale block. I want to use this section to clarify the different meanings of the two.
- A stale block is a block that is mined on top of an orphan.
It should be noted that the situation depicted above will not happen in Bitcoin because the entire network will choose to follow D as soon as it is mined and propagated to them.
2. An orphan block is really a stale block.
Some will say that the term “orphan blocks” as I have used them in this post should be instead referenced as stale blocks.
3. A stale block is a block that is being worked on after a valid PoW is found.
The full breath of this has already been summed up nicely on a site called “BitCoin Source” (I no longer believe it is still maintained), so I will include their definition.
“At any second, a block may be “solved.” This means that everyone else in the world working on that block must stop, and restart their work. Continuing to work after that point is known as working on a “stale block” because it is old data, and old transactions.”
4. An orphan block is a block that does not have a “parent”.
This is the reason for number 2. Some people believe that an orphan block should only refer to a block that “has no parent”.
Because Bitcoin is a wide distributed network, some nodes can be aware of blocks that other nodes are not. If a node receives a block and they are not aware of its parent they cannot validate it, so they will have to ask their peers in the network for this information. Until they receive this information, the block is considered an orphan.
However, these types of orphans no longer exist in Bitcoin after v0.10 because of a change in the way nodes download blocks.