Skip to content

Commit 58d91af

Browse files
committed
Fix race for mapBlockIndex in AppInitMain
1 parent fc5c237 commit 58d91af

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/init.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,9 +1631,16 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
16311631

16321632
// ********************************************************* Step 11: start node
16331633

1634+
int chain_active_height;
1635+
16341636
//// debug print
1635-
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
1636-
LogPrintf("nBestHeight = %d\n", chainActive.Height());
1637+
{
1638+
LOCK(cs_main);
1639+
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
1640+
chain_active_height = chainActive.Height();
1641+
}
1642+
LogPrintf("nBestHeight = %d\n", chain_active_height);
1643+
16371644
if (gArgs.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
16381645
StartTorControl(threadGroup, scheduler);
16391646

@@ -1649,7 +1656,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
16491656
connOptions.nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections);
16501657
connOptions.nMaxAddnode = MAX_ADDNODE_CONNECTIONS;
16511658
connOptions.nMaxFeeler = 1;
1652-
connOptions.nBestHeight = chainActive.Height();
1659+
connOptions.nBestHeight = chain_active_height;
16531660
connOptions.uiInterface = &uiInterface;
16541661
connOptions.nSendBufferMaxSize = 1000*gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
16551662
connOptions.nReceiveFloodSize = 1000*gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);

0 commit comments

Comments
 (0)