fix: force checkpoint

This commit is contained in:
nandhh 2024-08-05 17:43:07 +08:00
parent 91b7760dd9
commit c834c7dbf9
2 changed files with 14 additions and 1 deletions

View File

@ -26,6 +26,12 @@ struct CCheckpointData {
const auto& final_checkpoint = mapCheckpoints.rbegin();
return final_checkpoint->first /* height */;
}
const uint256 GetHash() const {
const auto& final_checkpoint = mapCheckpoints.rbegin();
return final_checkpoint->second /* hash */;
}
};
struct AssumeutxoHash : public BaseHash<uint256> {

View File

@ -3473,11 +3473,18 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
// Don't accept any forks from the main chain prior to last checkpoint.
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
// BlockIndex().
const CBlockIndex* pcheckpoint = blockman.GetLastCheckpoint(chainman.GetParams().Checkpoints());
const CCheckpointData& checkpointdata = chainman.GetParams().Checkpoints();
const CBlockIndex* pcheckpoint = blockman.GetLastCheckpoint(checkpointdata);
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
LogPrintf("ERROR: %s: forked chain older than last checkpoint (height %d)\n", __func__, nHeight);
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "bad-fork-prior-to-checkpoint");
}
if (nHeight == checkpointdata.GetHeight() && block.GetHash() != checkpointdata.GetHash()) {
LogPrintf("ERROR: %s: forked chain on last checkpoint (height %d)\n", __func__, nHeight);
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "bad-fork-to-checkpoint");
}
}
// Check timestamp against prev