From 366b3d4a516cd5b0bc375d566a212db05ef31fc2 Mon Sep 17 00:00:00 2001 From: Capri Date: Sat, 12 Sep 2026 21:32:15 +0000 Subject: [PATCH] Make difficulty interface algorithm-aware --- src/miner.cpp | 4 ++-- src/pow.cpp | 3 ++- src/pow.h | 2 +- src/validation.cpp | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c2f171c..83bf383 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -36,7 +36,7 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam // Updating time can change work required on testnet: if (consensusParams.fPowAllowMinDifficultyBlocks) - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams, ALGO_SHA256D); return nNewTime - nOldTime; } @@ -172,7 +172,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus(), ALGO_SHA256D); pblock->nNonce = 0; pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); diff --git a/src/pow.cpp b/src/pow.cpp index 2625f0d..4bf25b6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -145,8 +145,9 @@ static unsigned int ApplyFastRiseProtection( return fastTarget.GetCompact(); } -unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) +unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params, int algo) { + (void)algo; // Vexta is SHA256D-only. if (pindexLast == nullptr) { return InitialDifficulty(params); diff --git a/src/pow.h b/src/pow.h index fc92de0..f49168c 100644 --- a/src/pow.h +++ b/src/pow.h @@ -16,7 +16,7 @@ class CBlockIndex; class uint256; unsigned int InitialDifficulty(const Consensus::Params& params); -unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&); +unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&, int algo); /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&); diff --git a/src/validation.cpp b/src/validation.cpp index 26c899c..0ca4a9d 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3263,7 +3263,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio // Check proof of work const Consensus::Params& consensusParams = params.GetConsensus(); - if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) + if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams, ALGO_SHA256D)) return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work"); // Check against checkpoints