Skip to content

Commit d6ea737

Browse files
committed
Remove network state wipe from UnloadBlockIndex.
UnloadBlockIndex is only used during init if we end up reindexing to clear our block state so that we can start over. However, at that time no connections have been brought up as CConnman hasn't been started yet, so all of the network processing state logic is empty when its called. Additionally, the initialization of the recentRejects set is moved to InitPeerLogic.
1 parent fc0c24f commit d6ea737

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/init.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
11001100
return false;
11011101
#endif
11021102
// ********************************************************* Step 6: network initialization
1103+
// Note that we absolutely cannot open any actual connections
1104+
// until the very end ("start node") as the UTXO/block state
1105+
// is not yet setup and may end up being set up twice if we
1106+
// need to reindex later.
11031107

11041108
assert(!g_connman);
11051109
g_connman = std::unique_ptr<CConnman>(new CConnman(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max())));

src/main.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4272,6 +4272,9 @@ bool RewindBlockIndex(const CChainParams& params)
42724272
return true;
42734273
}
42744274

4275+
// May NOT be used after any connections are up as much
4276+
// of the peer-processing logic assumes a consistent
4277+
// block index state
42754278
void UnloadBlockIndex()
42764279
{
42774280
LOCK(cs_main);
@@ -4282,18 +4285,12 @@ void UnloadBlockIndex()
42824285
mempool.clear();
42834286
mapOrphanTransactions.clear();
42844287
mapOrphanTransactionsByPrev.clear();
4285-
nSyncStarted = 0;
42864288
mapBlocksUnlinked.clear();
42874289
vinfoBlockFile.clear();
42884290
nLastBlockFile = 0;
42894291
nBlockSequenceId = 1;
4290-
mapBlockSource.clear();
4291-
mapBlocksInFlight.clear();
4292-
nPreferredDownload = 0;
42934292
setDirtyBlockIndex.clear();
42944293
setDirtyFileInfo.clear();
4295-
mapNodeState.clear();
4296-
recentRejects.reset(NULL);
42974294
versionbitscache.Clear();
42984295
for (int b = 0; b < VERSIONBITS_NUM_BITS; b++) {
42994296
warningcache[b].clear();
@@ -4318,9 +4315,6 @@ bool InitBlockIndex(const CChainParams& chainparams)
43184315
{
43194316
LOCK(cs_main);
43204317

4321-
// Initialize global variables that cannot be constructed at startup.
4322-
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
4323-
43244318
// Check whether we're already initialized
43254319
if (chainActive.Genesis() != NULL)
43264320
return true;
@@ -4709,6 +4703,11 @@ std::string GetWarnings(const std::string& strFor)
47094703
// blockchain -> download logic notification
47104704
//
47114705

4706+
PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn) : connman(connmanIn) {
4707+
// Initialize global variables that cannot be constructed at startup.
4708+
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
4709+
}
4710+
47124711
void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
47134712
const int nNewHeight = pindexNew->nHeight;
47144713
connman->SetBestHeight(nNewHeight);

src/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class PeerLogicValidation : public CValidationInterface {
542542
CConnman* connman;
543543

544544
public:
545-
PeerLogicValidation(CConnman* connmanIn) : connman(connmanIn) {}
545+
PeerLogicValidation(CConnman* connmanIn);
546546

547547
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
548548
virtual void BlockChecked(const CBlock& block, const CValidationState& state);

0 commit comments

Comments
 (0)