Skip to content

Commit a8d0407

Browse files
committed
Move recentRejects initialization to top of InitBlockIndex
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.
1 parent 0847d9c commit a8d0407

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,10 @@ bool LoadBlockIndex()
33113311
bool InitBlockIndex() {
33123312
const CChainParams& chainparams = Params();
33133313
LOCK(cs_main);
3314+
3315+
// Initialize global variables that cannot be constructed at startup.
3316+
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
3317+
33143318
// Check whether we're already initialized
33153319
if (chainActive.Genesis() != NULL)
33163320
return true;
@@ -3344,9 +3348,6 @@ bool InitBlockIndex() {
33443348
}
33453349
}
33463350

3347-
// Initialize global variables that cannot be constructed at startup.
3348-
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
3349-
33503351
return true;
33513352
}
33523353

@@ -3716,6 +3717,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
37163717
{
37173718
case MSG_TX:
37183719
{
3720+
assert(recentRejects);
37193721
if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip)
37203722
{
37213723
// If the chain tip has changed previously rejected transactions
@@ -4329,6 +4331,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
43294331
// Probably non-standard or insufficient fee/priority
43304332
LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString());
43314333
vEraseQueue.push_back(orphanHash);
4334+
assert(recentRejects);
43324335
recentRejects->insert(orphanHash);
43334336
}
43344337
mempool.check(pcoinsTip);
@@ -4352,6 +4355,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
43524355
// already in the mempool; if the tx isn't in the mempool that
43534356
// means it was rejected and we shouldn't ask for it again.
43544357
if (!mempool.exists(tx.GetHash())) {
4358+
assert(recentRejects);
43554359
recentRejects->insert(tx.GetHash());
43564360
}
43574361
if (pfrom->fWhitelisted) {

0 commit comments

Comments
 (0)