Skip to content

Commit 1b04660

Browse files
committed
Merge #8665: Assert all the things!
4d51e9b Assert ConnectBlock block and pIndex are the same block (NicolasDorier) 972714c pow: GetNextWorkRequired never called with NULL pindexLast (Daniel Cousens) cc44c8f ContextualCheckBlockHeader should never have pindexPrev to NULL (NicolasDorier) Tree-SHA512: 7cc568bf9417267c335f21ec3d1505b26e56e5b3d5f4d3dbb555279489800aaa65a3bcd7bc376e274dd102912aec16ddbb18de2e2060b2667b41eb979cd9321e
2 parents 857d1e1 + 4d51e9b commit 1b04660

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/pow.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
1414
{
15+
assert(pindexLast != NULL);
1516
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
1617

17-
// Genesis block
18-
if (pindexLast == NULL)
19-
return nProofOfWorkLimit;
20-
2118
// Only change once per difficulty adjustment interval
2219
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
2320
{

src/validation.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17141714
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck)
17151715
{
17161716
AssertLockHeld(cs_main);
1717-
1717+
assert(pindex);
1718+
// pindex->phashBlock can be null if called by CreateNewBlock/TestBlockValidity
1719+
assert((pindex->phashBlock == NULL) ||
1720+
(*pindex->phashBlock == block.GetHash()));
17181721
int64_t nTimeStart = GetTimeMicros();
17191722

17201723
// Check it again in case a previous version let a bad block in
@@ -2948,7 +2951,8 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
29482951

29492952
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
29502953
{
2951-
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
2954+
assert(pindexPrev != NULL);
2955+
const int nHeight = pindexPrev->nHeight + 1;
29522956
// Check proof of work
29532957
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
29542958
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");

0 commit comments

Comments
 (0)