3

In the Bitcoin network, each peer maintains a full copy of the ledger (blockchain). What will happen if a peer losts one of its blocks in the blockchain (e.g. another process on the peer accidentally wiped out the disk area that stores the block)? Will this peer be able to detect that this block is missing? If yes, how will the peer detect it and how is it going to repair?

1 Answer 1

4

It depends on the implementation. For Bitcoin Core, the node maintains a database which has the locations of all blocks on disk. If a block is deleted, then it will notice that the location of a block either does not exist or contains garbage or invalid data. If it does notice that a block is missing (or something is corrupted), it will attempt to rebuild the database using the blocks stored on disk and then download the missing blocks from its peers.

However, blocks can actually be deleted after they have been verified and the local database has updated so that the node knows the block it has just deleted was a valid block. This is called pruning, and with pruning, old, historical blocks can be deleted as they aren't used for anything in normal node operation (except helping new nodes sync).

2
  • Thanks @Andrew Chow, you mentioned "then it will notice that the location of a block either does not exist or contains garbage or invalid data", I am wondering how "it will notice". Is there a background thread on each peer that periodically checking the integrity of the blockchain, or the peer needs to scan through the blockchain for some reason?
    – Qi Zhang
    Jul 5, 2017 at 13:56
  • The node verifies integrity of its databases and of the blockchain on startup. I think you could delete blocks while it is running and it won't notice, but there will be an error next time it starts up.
    – Andrew Chow
    Jul 5, 2017 at 16:34

Your Answer

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

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