@@ -1310,7 +1310,7 @@ int GetNumBlocksOfPeers()
1310
1310
1311
1311
bool IsInitialBlockDownload ()
1312
1312
{
1313
- AssertLockHeld (cs_main);
1313
+ LOCK (cs_main);
1314
1314
if (fImporting || fReindex || chainActive.Height () < Checkpoints::GetTotalBlocksEstimate ())
1315
1315
return true ;
1316
1316
static int64_t nLastUpdate;
@@ -2087,7 +2087,7 @@ void static FindMostWorkChain() {
2087
2087
2088
2088
// Try to activate to the most-work chain (thereby connecting it).
2089
2089
bool ActivateBestChain (CValidationState &state) {
2090
- AssertLockHeld (cs_main);
2090
+ LOCK (cs_main);
2091
2091
CBlockIndex *pindexOldTip = chainActive.Tip ();
2092
2092
bool fComplete = false ;
2093
2093
while (!fComplete ) {
@@ -2136,7 +2136,6 @@ bool ActivateBestChain(CValidationState &state) {
2136
2136
2137
2137
bool AddToBlockIndex (CBlock& block, CValidationState& state, const CDiskBlockPos& pos)
2138
2138
{
2139
- AssertLockHeld (cs_main);
2140
2139
// Check for duplicate
2141
2140
uint256 hash = block.GetHash ();
2142
2141
if (mapBlockIndex.count (hash))
@@ -2173,6 +2172,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
2173
2172
if (!ActivateBestChain (state))
2174
2173
return false ;
2175
2174
2175
+ LOCK (cs_main);
2176
2176
if (pindexNew == chainActive.Tip ())
2177
2177
{
2178
2178
// Clear fork warning if its no longer applicable
@@ -2962,6 +2962,7 @@ bool LoadBlockIndex()
2962
2962
2963
2963
2964
2964
bool InitBlockIndex () {
2965
+ LOCK (cs_main);
2965
2966
// Check whether we're already initialized
2966
2967
if (chainActive.Genesis () != NULL )
2967
2968
return true ;
@@ -4201,6 +4202,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
4201
4202
}
4202
4203
}
4203
4204
4205
+ TRY_LOCK (cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState()
4206
+ if (!lockMain)
4207
+ return true ;
4208
+
4204
4209
// Address refresh broadcast
4205
4210
static int64_t nLastRebroadcast;
4206
4211
if (!IsInitialBlockDownload () && (GetTime () - nLastRebroadcast > 24 * 60 * 60 ))
@@ -4251,10 +4256,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
4251
4256
pto->PushMessage (" addr" , vAddr);
4252
4257
}
4253
4258
4254
- TRY_LOCK (cs_main, lockMain);
4255
- if (!lockMain)
4256
- return true ;
4257
-
4258
4259
CNodeState &state = *State (pto->GetId ());
4259
4260
if (state.fShouldBan ) {
4260
4261
if (pto->addr .IsLocal ())
0 commit comments