Blockchain By Example
上QQ阅读APP看书,第一时间看更新

Checkpoints

The Bitcoin Core client has hardcoded checkpoints verifying that certain specific blocks should be found at certain heights. They are regularly added in new versions of the client to avoid accepting any forks from the network prior to the last checkpoint, thereby making transactions irreversible.

As our blockchain doesn't have previous blocks, you have to disable these checkpoints for Readercoin, otherwise your node will not be able to construct additional blocks nor start mining, as it will be waiting for non-existent blocks.

In the chainparams.cpp file, locate the checkpointData map:

The map stores a collection of preset checkpoints such that the first element of each pair is the block height, and the second is the hash of that block.

Remove all checkpoint pairs to end up with the following form:

checkpointData = (CCheckpointData) { { {}, } };

Make the same modification in the mainnet, testnet, and regtest classes. Alternatively, in validation.h you can set the following constant to false: static const bool DEFAULT_CHECKPOINTS_ENABLED = true; or, in checkpoints.cpp, you can hack the GetLastCheckpoint function by making it returns a null pointer as follows:

CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) { 
const MapCheckpoints &checkpoints = data.mapCheckpoints;
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints)) {
const uint256 &hash = i.second;
BlockMap::const_iterator t = mapBlockIndex.find(hash);
if (t != mapBlockIndex.end()) {
// return t->second;
return null;
}
}
return nullptr;
}

Now, the checkpoints are disabled. Nonetheless, if you want to keep them, you can premine 50 blocks, put their weights and hashes in the checkpoints, and then reenable the checkpoints. After all, they are a powerful way for blockchain developers to protect against remining the whole chain.

The message readercoin is downloading blocks will be displayed if the client hasn't yet downloaded all the checkpoint blocks.