Skip to content

Commit

Permalink
Fix assertion failure in mining/staking
Browse files Browse the repository at this point in the history
Need to explicitely set pindexPrev and nHeight within the locked scope.
  • Loading branch information
Fuzzbawls committed Mar 23, 2019
1 parent 4841189 commit 580bec5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4990,7 +4990,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis
bool TestBlockValidity(CValidationState& state, const CBlock& block, CBlockIndex* const pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
{
AssertLockHeld(cs_main);
assert(pindexPrev == chainActive.Tip());
assert(pindexPrev && pindexPrev == chainActive.Tip());

CCoinsViewCache viewNew(pcoinsTip);
CBlockIndex indexDummy(block);
Expand Down
5 changes: 4 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
CBlock* pblock = &pblocktemplate->block; // pointer for convenience

// Tip
CBlockIndex* pindexPrev;
CBlockIndex* pindexPrev = nullptr;
{ // Don't keep cs_main locked
LOCK(cs_main);
pindexPrev = chainActive.Tip();
}

const int nHeight = pindexPrev->nHeight + 1;

// Make sure to create the correct block version after zerocoin is enabled
Expand Down Expand Up @@ -191,6 +192,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
{
LOCK2(cs_main, mempool.cs);

CBlockIndex* pindexPrev = chainActive.Tip();
const int nHeight = pindexPrev->nHeight + 1;
CCoinsViewCache view(pcoinsTip);

// Priority order to process transactions
Expand Down

0 comments on commit 580bec5

Please sign in to comment.