@@ -2922,14 +2922,15 @@ static void NotifyHeaderTip() {
2922
2922
*/
2923
2923
bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
2924
2924
CBlockIndex *pindexMostWork = NULL ;
2925
+ CBlockIndex *pindexNewTip = NULL ;
2925
2926
do {
2926
2927
boost::this_thread::interruption_point ();
2927
2928
if (ShutdownRequested ())
2928
2929
break ;
2929
2930
2930
- CBlockIndex *pindexNewTip = NULL ;
2931
2931
const CBlockIndex *pindexFork;
2932
2932
bool fInitialDownload ;
2933
+ int nNewHeight;
2933
2934
{
2934
2935
LOCK (cs_main);
2935
2936
CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2952,6 +2953,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2952
2953
pindexNewTip = chainActive.Tip ();
2953
2954
pindexFork = chainActive.FindFork (pindexOldTip);
2954
2955
fInitialDownload = IsInitialBlockDownload ();
2956
+ nNewHeight = chainActive.Height ();
2955
2957
}
2956
2958
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
2957
2959
@@ -2980,7 +2982,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2980
2982
{
2981
2983
LOCK (cs_vNodes);
2982
2984
BOOST_FOREACH (CNode* pnode, vNodes) {
2983
- if (chainActive. Height () > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
2985
+ if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
2984
2986
BOOST_REVERSE_FOREACH (const uint256& hash, vHashes) {
2985
2987
pnode->PushBlockHash (hash);
2986
2988
}
@@ -2993,7 +2995,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2993
2995
}
2994
2996
}
2995
2997
}
2996
- } while (pindexMostWork != chainActive. Tip () );
2998
+ } while (pindexNewTip != pindexMostWork );
2997
2999
CheckBlockIndex (chainparams.GetConsensus ());
2998
3000
2999
3001
// Write changes periodically to disk, after relay.
@@ -4569,6 +4571,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4569
4571
strCommand == NetMsgType::FILTERCLEAR))
4570
4572
{
4571
4573
if (pfrom->nVersion >= NO_BLOOM_VERSION) {
4574
+ LOCK (cs_main);
4572
4575
Misbehaving (pfrom->GetId (), 100 );
4573
4576
return false ;
4574
4577
} else {
@@ -4584,6 +4587,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4584
4587
if (pfrom->nVersion != 0 )
4585
4588
{
4586
4589
pfrom->PushMessage (NetMsgType::REJECT, strCommand, REJECT_DUPLICATE, string (" Duplicate version message" ));
4590
+ LOCK (cs_main);
4587
4591
Misbehaving (pfrom->GetId (), 1 );
4588
4592
return false ;
4589
4593
}
@@ -4643,7 +4647,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4643
4647
pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);
4644
4648
4645
4649
// Potentially mark this peer as a preferred download peer.
4650
+ {
4651
+ LOCK (cs_main);
4646
4652
UpdatePreferredDownload (pfrom, State (pfrom->GetId ()));
4653
+ }
4647
4654
4648
4655
// Change version
4649
4656
pfrom->PushMessage (NetMsgType::VERACK);
@@ -4701,6 +4708,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4701
4708
else if (pfrom->nVersion == 0 )
4702
4709
{
4703
4710
// Must have a version message before anything else
4711
+ LOCK (cs_main);
4704
4712
Misbehaving (pfrom->GetId (), 1 );
4705
4713
return false ;
4706
4714
}
@@ -4736,6 +4744,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4736
4744
return true ;
4737
4745
if (vAddr.size () > 1000 )
4738
4746
{
4747
+ LOCK (cs_main);
4739
4748
Misbehaving (pfrom->GetId (), 20 );
4740
4749
return error (" message addr size() = %u" , vAddr.size ());
4741
4750
}
@@ -4803,6 +4812,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4803
4812
vRecv >> vInv;
4804
4813
if (vInv.size () > MAX_INV_SZ)
4805
4814
{
4815
+ LOCK (cs_main);
4806
4816
Misbehaving (pfrom->GetId (), 20 );
4807
4817
return error (" message inv size() = %u" , vInv.size ());
4808
4818
}
@@ -4878,6 +4888,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4878
4888
vRecv >> vInv;
4879
4889
if (vInv.size () > MAX_INV_SZ)
4880
4890
{
4891
+ LOCK (cs_main);
4881
4892
Misbehaving (pfrom->GetId (), 20 );
4882
4893
return error (" message getdata size() = %u" , vInv.size ());
4883
4894
}
@@ -5129,6 +5140,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5129
5140
// Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
5130
5141
unsigned int nCount = ReadCompactSize (vRecv);
5131
5142
if (nCount > MAX_HEADERS_RESULTS) {
5143
+ LOCK (cs_main);
5132
5144
Misbehaving (pfrom->GetId (), 20 );
5133
5145
return error (" headers message size = %u" , nCount);
5134
5146
}
@@ -5390,8 +5402,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5390
5402
LOCK (pfrom->cs_filter );
5391
5403
5392
5404
if (!filter.IsWithinSizeConstraints ())
5405
+ {
5393
5406
// There is no excuse for sending a too-large filter
5407
+ LOCK (cs_main);
5394
5408
Misbehaving (pfrom->GetId (), 100 );
5409
+ }
5395
5410
else
5396
5411
{
5397
5412
delete pfrom->pfilter ;
@@ -5411,13 +5426,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5411
5426
// and thus, the maximum size any matched object can have) in a filteradd message
5412
5427
if (vData.size () > MAX_SCRIPT_ELEMENT_SIZE)
5413
5428
{
5429
+ LOCK (cs_main);
5414
5430
Misbehaving (pfrom->GetId (), 100 );
5415
5431
} else {
5416
5432
LOCK (pfrom->cs_filter );
5417
5433
if (pfrom->pfilter )
5418
5434
pfrom->pfilter ->insert (vData);
5419
5435
else
5436
+ {
5437
+ LOCK (cs_main);
5420
5438
Misbehaving (pfrom->GetId (), 100 );
5439
+ }
5421
5440
}
5422
5441
}
5423
5442
0 commit comments