@@ -5787,29 +5787,34 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5787
5787
BlockTransactions resp;
5788
5788
vRecv >> resp;
5789
5789
5790
- LOCK (cs_main);
5790
+ CBlock block;
5791
+ bool fBlockRead = false ;
5792
+ {
5793
+ LOCK (cs_main);
5791
5794
5792
- map<uint256, pair<NodeId, list<QueuedBlock>::iterator> >::iterator it = mapBlocksInFlight.find (resp.blockhash );
5793
- if (it == mapBlocksInFlight.end () || !it->second .second ->partialBlock ||
5794
- it->second .first != pfrom->GetId ()) {
5795
- LogPrint (" net" , " Peer %d sent us block transactions for block we weren't expecting\n " , pfrom->id );
5796
- return true ;
5797
- }
5795
+ map<uint256, pair<NodeId, list<QueuedBlock>::iterator> >::iterator it = mapBlocksInFlight.find (resp.blockhash );
5796
+ if (it == mapBlocksInFlight.end () || !it->second .second ->partialBlock ||
5797
+ it->second .first != pfrom->GetId ()) {
5798
+ LogPrint (" net" , " Peer %d sent us block transactions for block we weren't expecting\n " , pfrom->id );
5799
+ return true ;
5800
+ }
5798
5801
5799
- PartiallyDownloadedBlock& partialBlock = *it->second .second ->partialBlock ;
5800
- CBlock block;
5801
- ReadStatus status = partialBlock.FillBlock (block, resp.txn );
5802
- if (status == READ_STATUS_INVALID) {
5803
- MarkBlockAsReceived (resp.blockhash ); // Reset in-flight state in case of whitelist
5804
- Misbehaving (pfrom->GetId (), 100 );
5805
- LogPrintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->id );
5806
- return true ;
5807
- } else if (status == READ_STATUS_FAILED) {
5808
- // Might have collided, fall back to getdata now :(
5809
- std::vector<CInv> invs;
5810
- invs.push_back (CInv (MSG_BLOCK | GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ()), resp.blockhash ));
5811
- pfrom->PushMessage (NetMsgType::GETDATA, invs);
5812
- } else {
5802
+ PartiallyDownloadedBlock& partialBlock = *it->second .second ->partialBlock ;
5803
+ ReadStatus status = partialBlock.FillBlock (block, resp.txn );
5804
+ if (status == READ_STATUS_INVALID) {
5805
+ MarkBlockAsReceived (resp.blockhash ); // Reset in-flight state in case of whitelist
5806
+ Misbehaving (pfrom->GetId (), 100 );
5807
+ LogPrintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->id );
5808
+ return true ;
5809
+ } else if (status == READ_STATUS_FAILED) {
5810
+ // Might have collided, fall back to getdata now :(
5811
+ std::vector<CInv> invs;
5812
+ invs.push_back (CInv (MSG_BLOCK | GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ()), resp.blockhash ));
5813
+ pfrom->PushMessage (NetMsgType::GETDATA, invs);
5814
+ } else
5815
+ fBlockRead = true ;
5816
+ } // Don't hold cs_main when we call into ProcessNewBlock
5817
+ if (fBlockRead ) {
5813
5818
CValidationState state;
5814
5819
ProcessNewBlock (state, chainparams, pfrom, &block, false , NULL , &connman);
5815
5820
int nDoS;
0 commit comments