Make block validation algorithm-aware

This commit is contained in:
Capri 2026-09-12 21:39:18 +00:00
commit 49bd690ed7
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM

View file

@ -3110,8 +3110,8 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true) static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{ {
// Check proof of work matches claimed amount // Check proof of work matches claimed amount.
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) if (fCheckPOW && !CheckProofOfWork(block.GetPoWAlgoHash(consensusParams), block.nBits, consensusParams))
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "high-hash", "proof of work failed"); return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "high-hash", "proof of work failed");
return true; return true;
@ -3261,9 +3261,15 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
assert(pindexPrev != nullptr); assert(pindexPrev != nullptr);
const int nHeight = pindexPrev->nHeight + 1; const int nHeight = pindexPrev->nHeight + 1;
// Check proof of work // Check proof-of-work algorithm and difficulty.
const Consensus::Params& consensusParams = params.GetConsensus(); const Consensus::Params& consensusParams = params.GetConsensus();
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams, ALGO_SHA256D)) const int algo = block.GetAlgo();
// RandomX is not active yet. Preserve the current SHA256D-only consensus.
if (algo != ALGO_SHA256D)
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "algo-inactive", "PoW algorithm is not active");
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams, algo))
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work"); return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work");
// Check against checkpoints // Check against checkpoints