@@ -5787,29 +5787,34 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
57875787 BlockTransactions resp;
57885788 vRecv >> resp;
57895789
5790- LOCK (cs_main);
5790+ CBlock block;
5791+ bool fBlockRead = false ;
5792+ {
5793+ LOCK (cs_main);
57915794
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+ }
57985801
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 ) {
58135818 CValidationState state;
58145819 ProcessNewBlock (state, chainparams, pfrom, &block, false , NULL , &connman);
58155820 int nDoS;
0 commit comments