Skip to content

Commit

Permalink
Move recentRejects initialization to top of InitBlockIndex
Browse files Browse the repository at this point in the history
This avoids that premature return in the condition that a new chain is initialized
results in NULL pointer errors due to recentReject not being constructed.

Also add assertions where it is used.
  • Loading branch information
laanwj authored and Fuzzbawls committed Jun 23, 2020
1 parent 9a59420 commit 93e8c46
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4710,6 +4710,10 @@ bool LoadBlockIndex(std::string& strError)
bool InitBlockIndex()
{
LOCK(cs_main);

// Initialize global variables that cannot be constructed at startup.
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));

// Check whether we're already initialized
if (chainActive.Genesis() != NULL)
return true;
Expand Down Expand Up @@ -4741,9 +4745,6 @@ bool InitBlockIndex()
}
}

// Initialize global variables that cannot be constructed at startup.
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));

return true;
}

Expand Down Expand Up @@ -5033,6 +5034,7 @@ bool static AlreadyHave(const CInv& inv)
{
switch (inv.type) {
case MSG_TX: {
assert(recentRejects);
if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
// If the chain tip has changed previously rejected transactions
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
Expand Down Expand Up @@ -5773,6 +5775,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
// Probably non-standard or insufficient fee/priority
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
vEraseQueue.push_back(orphanHash);
assert(recentRejects);
recentRejects->insert(orphanHash);
}
mempool.check(pcoinsTip);
Expand Down Expand Up @@ -5802,6 +5805,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
// already in the mempool; if the tx isn't in the mempool that
// means it was rejected and we shouldn't ask for it again.
if (!mempool.exists(tx.GetHash())) {
assert(recentRejects);
recentRejects->insert(tx.GetHash());
}
if (pfrom->fWhitelisted) {
Expand Down

0 comments on commit 93e8c46

Please sign in to comment.