Skip to content

Commit 93e8c46

Browse files
laanwjFuzzbawls
authored andcommitted
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 9a59420 commit 93e8c46

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4710,6 +4710,10 @@ bool LoadBlockIndex(std::string& strError)
47104710
bool InitBlockIndex()
47114711
{
47124712
LOCK(cs_main);
4713+
4714+
// Initialize global variables that cannot be constructed at startup.
4715+
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
4716+
47134717
// Check whether we're already initialized
47144718
if (chainActive.Genesis() != NULL)
47154719
return true;
@@ -4741,9 +4745,6 @@ bool InitBlockIndex()
47414745
}
47424746
}
47434747

4744-
// Initialize global variables that cannot be constructed at startup.
4745-
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
4746-
47474748
return true;
47484749
}
47494750

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

0 commit comments

Comments
 (0)