@@ -5828,29 +5828,34 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5828
5828
BlockTransactions resp;
5829
5829
vRecv >> resp;
5830
5830
5831
- LOCK (cs_main);
5831
+ CBlock block;
5832
+ bool fBlockRead = false ;
5833
+ {
5834
+ LOCK (cs_main);
5832
5835
5833
- map<uint256, pair<NodeId, list<QueuedBlock>::iterator> >::iterator it = mapBlocksInFlight.find (resp.blockhash );
5834
- if (it == mapBlocksInFlight.end () || !it->second .second ->partialBlock ||
5835
- it->second .first != pfrom->GetId ()) {
5836
- LogPrint (" net" , " Peer %d sent us block transactions for block we weren't expecting\n " , pfrom->id );
5837
- return true ;
5838
- }
5836
+ map<uint256, pair<NodeId, list<QueuedBlock>::iterator> >::iterator it = mapBlocksInFlight.find (resp.blockhash );
5837
+ if (it == mapBlocksInFlight.end () || !it->second .second ->partialBlock ||
5838
+ it->second .first != pfrom->GetId ()) {
5839
+ LogPrint (" net" , " Peer %d sent us block transactions for block we weren't expecting\n " , pfrom->id );
5840
+ return true ;
5841
+ }
5839
5842
5840
- PartiallyDownloadedBlock& partialBlock = *it->second .second ->partialBlock ;
5841
- CBlock block;
5842
- ReadStatus status = partialBlock.FillBlock (block, resp.txn );
5843
- if (status == READ_STATUS_INVALID) {
5844
- MarkBlockAsReceived (resp.blockhash ); // Reset in-flight state in case of whitelist
5845
- Misbehaving (pfrom->GetId (), 100 );
5846
- LogPrintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->id );
5847
- return true ;
5848
- } else if (status == READ_STATUS_FAILED) {
5849
- // Might have collided, fall back to getdata now :(
5850
- std::vector<CInv> invs;
5851
- invs.push_back (CInv (MSG_BLOCK | GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ()), resp.blockhash ));
5852
- pfrom->PushMessage (NetMsgType::GETDATA, invs);
5853
- } else {
5843
+ PartiallyDownloadedBlock& partialBlock = *it->second .second ->partialBlock ;
5844
+ ReadStatus status = partialBlock.FillBlock (block, resp.txn );
5845
+ if (status == READ_STATUS_INVALID) {
5846
+ MarkBlockAsReceived (resp.blockhash ); // Reset in-flight state in case of whitelist
5847
+ Misbehaving (pfrom->GetId (), 100 );
5848
+ LogPrintf (" Peer %d sent us invalid compact block/non-matching block transactions\n " , pfrom->id );
5849
+ return true ;
5850
+ } else if (status == READ_STATUS_FAILED) {
5851
+ // Might have collided, fall back to getdata now :(
5852
+ std::vector<CInv> invs;
5853
+ invs.push_back (CInv (MSG_BLOCK | GetFetchFlags (pfrom, chainActive.Tip (), chainparams.GetConsensus ()), resp.blockhash ));
5854
+ pfrom->PushMessage (NetMsgType::GETDATA, invs);
5855
+ } else
5856
+ fBlockRead = true ;
5857
+ } // Don't hold cs_main when we call into ProcessNewBlock
5858
+ if (fBlockRead ) {
5854
5859
CValidationState state;
5855
5860
ProcessNewBlock (state, chainparams, pfrom, &block, false , NULL );
5856
5861
int nDoS;
0 commit comments