0

I just completed parsing the Testnet3 Bitcoin blockchain stored in the blk.dat files into a database. Since I was using multi-processing to parse several files at the same time, I didn't add the height to the blockchain while parsing it. Instead, I did this after the whole blockchain was parsed.

Everything was going smoothly while adding the height to the blocks for the most part. However, approaching the end of the blockchain (the last 7%), my code started to crash because it started to find 2 different blocks that had the same previous block (basically, a fork), and I had already constrained my database to avoid having 2 blocks with the same height. All these tiny forks I have been finding are just one block long, and it looks like the closer I get to the end, the most common it is to find these tiny forks.

I have had to look both block-ids up in a block explorer to find out which one is the official block and which one is the fork ("fake" block). One of them is always non-existent for which I know it is not an ID misplacing. I have been manually deleting the link of the "fake" block so my code can keep adding the height, but as I said before, it becomes more and more common to find these tiny forks the more I approach the end of the blockchain.

I was just wondering if this is normal, or if there is something really wrong with my blk.dat files.

1 Answer 1

2

This is normal, especially on testnet. What you are seeing are known as stale blocks (or also incorrectly as orphan blocks). These occur when miners complete a block at around the same time so some nodes receive the two blocks in a different order. The conflict resolves when the next block is found.

You will commonly see stale blocks on testnet due to testnet's low difficulty. Furthermore, you see these towards the chain tip because it is only possible to receive these when you are not attempting to do the initial sync. So you won't receive stale blocks during the initial sync, but once you exit that and begin normal operation and your node receives new blocks, you will end up receiving stale blocks (but they aren't necessarily stale yet).

You will need to modify your code to handle stale blocks.

3
  • Thanks a lot Andrew. I really appreciate your thorough answer. Commented Sep 13, 2020 at 15:45
  • I actually found a 3-block stale fork Commented Sep 13, 2020 at 19:46
  • Longer forks are possible, although less likely. However with testnet, it's not all that unusual.
    – Ava Chow
    Commented Sep 14, 2020 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.