What will happen if a block is lost on a peer?

2

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?

Qi Zhang

Posted 2017-07-05T02:04:31.510

Reputation: 173

Answers

3

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).

Andrew Chow

Posted 2017-07-05T02:04:31.510

Reputation: 40 910

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 2017-07-05T13:56:36.157

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 2017-07-05T16:34:19.293