Make difficulty interface algorithm-aware
This commit is contained in:
parent
a745563d28
commit
366b3d4a51
4 changed files with 6 additions and 5 deletions
|
|
@ -36,7 +36,7 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
|
||||||
|
|
||||||
// Updating time can change work required on testnet:
|
// Updating time can change work required on testnet:
|
||||||
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams, ALGO_SHA256D);
|
||||||
|
|
||||||
return nNewTime - nOldTime;
|
return nNewTime - nOldTime;
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +172,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||||
// Fill in header
|
// Fill in header
|
||||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus(), ALGO_SHA256D);
|
||||||
pblock->nNonce = 0;
|
pblock->nNonce = 0;
|
||||||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,8 +145,9 @@ static unsigned int ApplyFastRiseProtection(
|
||||||
return fastTarget.GetCompact();
|
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.
|
// Vexta is SHA256D-only.
|
||||||
if (pindexLast == nullptr) {
|
if (pindexLast == nullptr) {
|
||||||
return InitialDifficulty(params);
|
return InitialDifficulty(params);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class CBlockIndex;
|
||||||
class uint256;
|
class uint256;
|
||||||
|
|
||||||
unsigned int InitialDifficulty(const Consensus::Params& params);
|
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 */
|
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
||||||
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
|
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
|
||||||
|
|
|
||||||
|
|
@ -3263,7 +3263,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
|
||||||
|
|
||||||
// Check proof of work
|
// Check proof of work
|
||||||
const Consensus::Params& consensusParams = params.GetConsensus();
|
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");
|
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work");
|
||||||
|
|
||||||
// Check against checkpoints
|
// Check against checkpoints
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue