The difference between stale and orphan blocks

The difference between stale and orphan blocks

  • Post Author:
  • Post Category:Bitcoin

The deeper I go into Bitcoin, the more confusion I see around certain words and definitions. One example I’d like to talk about today involves the terms “stale block” and “orphan block”. These are often used interchangeably, but don’t quite mean the same thing.

Orphan blocks

An orphan block is a block with no parent, at least according to the node that is looking at it. This happens when a node receives a block before it has been made aware of the corresponding parent block. When this happens it puts the orphan block in a holding area and waits for the missing parent.

To visualize this, let’s pretend we have a node that has a copy of the blockchain up to block 5. A peer tells us about block 7. But wait! Since we haven’t found out about block 6 yet, block 7 cannot be added to the blockchain. In this scenario, block 7 is an orphan block and will not get added to the chain until the node learns about block 6.

One thing to note is you actually don’t see orphan blocks anymore. In February 2015, Bitcoin Core v0.10.0 was released which changed the way blocks were downloaded. Peers began asking for just the block headers before downloading the rest of the block. In the example above, the node would not bother asking for the rest of block 7 because it needs block 6 first.

Stale blocks

Stale blocks are ones that are not part of the current best chain. To understand this, it’s important to know two things:

  1. Sometimes there can be more than one block at the same height
  2. Bitcoin nodes follow the longest chain with the most proof-of-work

In scenarios where the blockchain has basically forked, nodes will wait to see which chain ends up with more blocks and go with that one. If you’ve heard about transaction confirmations, and the rule of thumb to wait 6 blocks before considering a transaction confirmed, this is why.

There are a number of reasons why there could be more than one active chain. Maybe two miners simultaneously find a new block, or perhaps a reorganization (reorg) is in progress. In any case, where there are multiple active chains, there will eventually be stale blocks. At some point one of the chains will grow longer than the other, causing the blocks on the other chain to become stale.

Sometimes stale blocks are referred to as extinct, and sometimes they are referred to as orphan blocks (which is confusing to say the least!). This is because payouts from stale blocks (the coinbase transactions) are referred to as being “orphaned” in the code (here’s just one example where we see this usage).

Visualizing stale blocks

The diagram below is a scenario where two miners have mined block 5 at the same time. While the two versions of Block 5 are different, they are both valid. At this point in time, neither chain is better than the other.

Now, let’s pretend a new block, block 6 has been mined on chain #2. This makes chain #2 is the longest, best chain with the most proof-of-work. Chain #1 is abandoned and purple block 5 is considered to be stale.

Sources

Shoutout to Pieter Wiulle and Murch on Stack Exchange for providing some much needed clarity around these terms! There are many places on the web where stale blocks are referred to as orphan blocks, even if that usage isn’t technically correct.