Skip to content

Commit

Permalink
Merge bitcoin#8665: Assert all the things!
Browse files Browse the repository at this point in the history
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
  • Loading branch information
laanwj authored and PastaPastaPasta committed Feb 26, 2019
1 parent b09e3e0 commit c4a3cd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,9 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockH

unsigned int GetNextWorkRequiredBTC(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
assert(pindexLast != NULL);
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();

// Genesis block
if (pindexLast == NULL)
return nProofOfWorkLimit;

// Only change once per interval
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
{
Expand Down
8 changes: 6 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false)
{
AssertLockHeld(cs_main);

assert(pindex);
// pindex->phashBlock can be null if called by CreateNewBlock/TestBlockValidity
assert((pindex->phashBlock == NULL) ||
(*pindex->phashBlock == block.GetHash()));
int64_t nTimeStart = GetTimeMicros();

// Check it again in case a previous version let a bad block in
Expand Down Expand Up @@ -3321,7 +3324,8 @@ static bool CheckIndexAgainstCheckpoint(const CBlockIndex* pindexPrev, CValidati

bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
{
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
assert(pindexPrev != NULL);
const int nHeight = pindexPrev->nHeight + 1;
// Check proof of work
if(Params().NetworkIDString() == CBaseChainParams::MAIN && nHeight <= 68589){
// architecture issues with DGW v1 and v2)
Expand Down

0 comments on commit c4a3cd6

Please sign in to comment.