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.
This commit is contained in:
Wladimir J. van der Laan 2015-07-31 17:55:05 +02:00
parent 0847d9cb5f
commit a8d0407c4f
1 changed files with 7 additions and 3 deletions

View File

@ -3311,6 +3311,10 @@ bool LoadBlockIndex()
bool InitBlockIndex() { bool InitBlockIndex() {
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
LOCK(cs_main); 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 // Check whether we're already initialized
if (chainActive.Genesis() != NULL) if (chainActive.Genesis() != NULL)
return true; return true;
@ -3344,9 +3348,6 @@ bool InitBlockIndex() {
} }
} }
// Initialize global variables that cannot be constructed at startup.
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
return true; return true;
} }
@ -3716,6 +3717,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{ {
case MSG_TX: case MSG_TX:
{ {
assert(recentRejects);
if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip) if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip)
{ {
// If the chain tip has changed previously rejected transactions // If the chain tip has changed previously rejected transactions
@ -4329,6 +4331,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Probably non-standard or insufficient fee/priority // Probably non-standard or insufficient fee/priority
LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString()); LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString());
vEraseQueue.push_back(orphanHash); vEraseQueue.push_back(orphanHash);
assert(recentRejects);
recentRejects->insert(orphanHash); recentRejects->insert(orphanHash);
} }
mempool.check(pcoinsTip); mempool.check(pcoinsTip);
@ -4352,6 +4355,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// already in the mempool; if the tx isn't in the mempool that // 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. // means it was rejected and we shouldn't ask for it again.
if (!mempool.exists(tx.GetHash())) { if (!mempool.exists(tx.GetHash())) {
assert(recentRejects);
recentRejects->insert(tx.GetHash()); recentRejects->insert(tx.GetHash());
} }
if (pfrom->fWhitelisted) { if (pfrom->fWhitelisted) {