How exactly do Bitcoin nodes validate newly mined blocks and update their separate versions of the blockchain?

Is the following an accurate summary of what happens?
(I’ve also included some questions)

  1. When a new block has been successfully mined, it is propagated throughout the Bitcoin network for nodes to validate.

  2. When a node receives a new block, it validates it by running the PoW algorithm to check that adding the new block to its version of the blockchain generates the same hash value. If it doesn’t, then the block is rejected. If it does, then it’s added to the node’s own version of the blockchain, and propagated to other nodes.

  3. If a node subsequently receives a valid competing block (to the one just validated and added as in 2. above), will it immediately replace the previously added block (which would then become a stale block) if the competing block has a higher difficulty? Or will it also add the valid competing block and temporarily maintain a split version of the blockchain until it receives a valid block which links mathematically to one of the two branches, discarding at this point the block on the “shorter” branch?

  4. Each node also continuously compares its growing version of the entire blockchain with the versions maintained by the other nodes it communicates with.
    If a node discovers a version that is “longer” than its own, does it automatically add the other version’s additional block(s), and discard any blocks included in its own version which are different (which would then become stale blocks)? Or does each node decide for itself if and when to amend its own version in this way? For example, could it decide to wait to make such amendments until a certain number of blocks have been added to the other node’s “different” block(s)? Does this have anything to do with the process of synching?
    If a node discovers a version that isn’t “longer” in terms of number of blocks, but does have a different final block, rather than just decide arbitrarily, will it choose the version with the highest total difficulty? (I think this is what @ivan explains, in the Blockchain & Bitcoin 101 lecture on stale blocks, as being what the decision is actually based on, rather than “length” in terms of number of blocks).

I’d really like to get some more clarity on these points…

@filip

1 and 2 completely correct.

  1. If a node received a valid block at the same block height as the previous one, it will be kept in the node and be another valid chain or “path”. It won’t replace the previous one. The node keeps track of all valid blocks that comes along. But the node will choose to work on the chain with the “most” pow, which basically means the chain with the highest sum of difficulties. The only blocks a node completely rejects are blocks where the parent block is unknown to the node. You can read more about this here and here.

  2. I think a lot of these questions are answered by my previous answer. Generally, new blocks are sent through the network when they are discovered by the miners. When a miner mines a new block, it will send it to the nearby nodes. Those nodes will add it to their blockchain if valid according to my answer above. If this new block adds enough difficulty to one of the chains, then the active chain might switch for that node, yes. But it never discards any blocks, except if the blocks parent is unknown to the node.

Synching is the process of getting up to date with the current blockchain. If you start up a new full node, it has none of the blockchain. It needs to sync with other nodes in order to build up the full blockchain. It will do that by querying other nodes around it for the genesis block, the block nr1, then nr2 and so on. This process takes a day or so.

I would highly recommend you to start your own full node if you’re interested in these kinds of topics. Then you can see it for yourself :slight_smile:

I hope I answered your questions, let me know if you have any follow ups :slight_smile:

3 Likes

Thanks @filip for the helpful comments and links! I’ve continued to research this, and I also got some feedback from this thread I posted in the bitcointalk.org forum. I’ve tried to pull everything together in a revised summary of what I now think happens. As a follow-up, would you mind having a look and letting me know what you think?


  1. When a new block has been successfully mined, it is propagated throughout the network for nodes to validate.

  2. When a node receives a newly mined block, it first validates the whole block (e.g. hash of block header < difficulty target; hash of previous block = hash of a block which node can build on, etc.). If invalid, the block is immediately rejected. If valid, the node immediately propagates the block to other nodes in the network for them to validate, and then procedes to validate the block’s individual transactions (e.g. all inputs are valid UTXOs; sum of outputs < or = sum of inputs, etc.). If all of its transactions are valid, the block is accepted by the node, added to its version of the blockchain, and the block’s transactions removed from the node’s mempool.

  3. If the same node subsequently receives a valid competing block (with the same parent as the one added in 2. above), the initially-added block remains at the tip of the node’s active chain, but the valid competing block is also kept, marked as stale, but still monitored. If the node then receives a valid block which links cryptographically to the stale block, the block at the tip of what was the active chain becomes stale, and the now longer branch becomes the active chain instead.

  4. If a node receives a valid block which links cryptographically to a stale block, and this creates a chain which, although shorter in terms of number of blocks, happens to have a higher sum of “difficulties” than the active chain, then this will now become the new active chain. All of the blocks after the split in the previously active chain will now become stale.

  5. Stale blocks are not discarded because they are still valid blocks with an ancestor within the active chain. Their transactions, however, remain in the nodes’s mempool (or are returned to the mempool if previously removed). If a stale block becomes part of a node’s active chain again, its transactions will be removed from the node’s mempool.

5 Likes

That summary looks correct, very detailed description of the process. Great job on doing your research!

2 Likes

Thanks Filip, I really appreciate the support :smiley:

I’ve just watched your video on Accidental Forks (Blockchain & Bitcoin 101 course) which goes over the concept of stale blocks again, from the miners perspective. I assume that everything we’ve already discussed above also applies to mining nodes as well. For example, to take a similar example to the one you use in the video:

  • Two blocks (1A & 1B) have been mined and distributed simultaneously.

  • We operate a mining node. We receive 1A first, so we add it to our version of the blockchain, and immediately start mining the next block (2A) based on 1A.

  • While mining 2A, we receive 1B. We don’t discard it, but mark it as stale and monitor it.

  • Before solving 2A, we receive block 2B (mined by another miner who received 1B first).

  • Even though for us 1B is a stale block, we append 2B to 1B.

  • Chain B now becomes our active chain, because it is longer than A;
    so, 1B is no longer a stale block;
    we also stop mining 2A, and start mining 3B.

  • 1A now becomes a stale block. It isn’t discarded, just disregarded temporarily, but still monitored (just in case a valid 2A comes our way).

Is that correct? I think what I have found confusing in the videos is when blocks are described as being “thrown away”. Maybe I’ve just thought about it all too much :rofl:, but it definitely makes more sense to me to think about stale blocks as being kept and monitored, perhaps “deactivated” or “disregarded temporarily”, rather than “thrown away”.

Shall I put a link to this thread in the Updates & Forks Discussion thread? It may be helpful to anyone else who has been confused by something similar…

6 Likes

Great! Thank you for taking the course :slight_smile:

Yes it would be the same for miners as well. Miners are full nodes also and generally act the same.

Please post the link in the general thread as well :+1:

2 Likes

Thx for the post, and now I have a question on my mind.
What happens to the tx from the stale block? Does the same miner have to put them in the new block and they are stuck to him until that or are they redistribute in the mempool and other miners can choose to put them in their block?

1 Like

Ivan mentioned in the Bitcoin Basics course that stale block TXs are returned to the mempool.

Still getting through the course though :slight_smile:

1 Like

Hi @Vlad.P,

No

Each node has their own separate mempool, so other miners will be able to select the transactions (included in another node’s stale block) from their own mempool if they haven’t yet been removed, or if they’ve been returned to their mempool when a previously validated and active block becomes stale.

Have a look at this earlier post of mine in this same discussion thread: I think it goes some way to answering your question.

That’s correct @biokillos, or they simply remain in that node’s mempool if they haven’t previously been removed.

1 Like

Thanks for the reply :grin:

1 Like

Thanks for this explanation! Great Course!