@@ -451,6 +451,8 @@ class PeerManagerImpl final : public PeerManager
451
451
452
452
void ProcessGetData (CNode& pfrom, Peer& peer, const std::atomic<bool >& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main);
453
453
454
+ void ProcessBlock (CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing );
455
+
454
456
/* * Relay map (txid or wtxid -> CTransactionRef) */
455
457
typedef std::map<uint256, CTransactionRef> MapRelay;
456
458
MapRelay mapRelay GUARDED_BY (cs_main);
@@ -2309,6 +2311,18 @@ void PeerManagerImpl::ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv)
2309
2311
m_connman.PushMessage (&peer, std::move (msg));
2310
2312
}
2311
2313
2314
+ void PeerManagerImpl::ProcessBlock (CNode& pfrom, const std::shared_ptr<const CBlock>& pblock, bool fForceProcessing )
2315
+ {
2316
+ bool fNewBlock = false ;
2317
+ m_chainman.ProcessNewBlock (m_chainparams, pblock, fForceProcessing , &fNewBlock );
2318
+ if (fNewBlock ) {
2319
+ pfrom.nLastBlockTime = GetTime ();
2320
+ } else {
2321
+ LOCK (cs_main);
2322
+ mapBlockSource.erase (pblock->GetHash ());
2323
+ }
2324
+ }
2325
+
2312
2326
void PeerManagerImpl::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
2313
2327
const std::chrono::microseconds time_received,
2314
2328
const std::atomic<bool >& interruptMsgProc)
@@ -3390,7 +3404,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3390
3404
LOCK (cs_main);
3391
3405
mapBlockSource.emplace (pblock->GetHash (), std::make_pair (pfrom.GetId (), false ));
3392
3406
}
3393
- bool fNewBlock = false ;
3394
3407
// Setting fForceProcessing to true means that we bypass some of
3395
3408
// our anti-DoS protections in AcceptBlock, which filters
3396
3409
// unrequested blocks that might be trying to waste our resources
@@ -3400,13 +3413,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3400
3413
// we have a chain with at least nMinimumChainWork), and we ignore
3401
3414
// compact blocks with less work than our tip, it is safe to treat
3402
3415
// reconstructed compact blocks as having been requested.
3403
- m_chainman.ProcessNewBlock (m_chainparams, pblock, /* fForceProcessing=*/ true , &fNewBlock );
3404
- if (fNewBlock ) {
3405
- pfrom.nLastBlockTime = GetTime ();
3406
- } else {
3407
- LOCK (cs_main);
3408
- mapBlockSource.erase (pblock->GetHash ());
3409
- }
3416
+ ProcessBlock (pfrom, pblock, /* fForceProcessing=*/ true );
3410
3417
LOCK (cs_main); // hold cs_main for CBlockIndex::IsValid()
3411
3418
if (pindex->IsValid (BLOCK_VALID_TRANSACTIONS)) {
3412
3419
// Clear download state for this block, which is in
@@ -3483,20 +3490,13 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3483
3490
}
3484
3491
} // Don't hold cs_main when we call into ProcessNewBlock
3485
3492
if (fBlockRead ) {
3486
- bool fNewBlock = false ;
3487
3493
// Since we requested this block (it was in mapBlocksInFlight), force it to be processed,
3488
3494
// even if it would not be a candidate for new tip (missing previous block, chain not long enough, etc)
3489
3495
// This bypasses some anti-DoS logic in AcceptBlock (eg to prevent
3490
3496
// disk-space attacks), but this should be safe due to the
3491
3497
// protections in the compact block handler -- see related comment
3492
3498
// in compact block optimistic reconstruction handling.
3493
- m_chainman.ProcessNewBlock (m_chainparams, pblock, /* fForceProcessing=*/ true , &fNewBlock );
3494
- if (fNewBlock ) {
3495
- pfrom.nLastBlockTime = GetTime ();
3496
- } else {
3497
- LOCK (cs_main);
3498
- mapBlockSource.erase (pblock->GetHash ());
3499
- }
3499
+ ProcessBlock (pfrom, pblock, /* fForceProcessing=*/ true );
3500
3500
}
3501
3501
return ;
3502
3502
}
@@ -3551,14 +3551,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3551
3551
// cs_main in ProcessNewBlock is fine.
3552
3552
mapBlockSource.emplace (hash, std::make_pair (pfrom.GetId (), true ));
3553
3553
}
3554
- bool fNewBlock = false ;
3555
- m_chainman.ProcessNewBlock (m_chainparams, pblock, forceProcessing, &fNewBlock );
3556
- if (fNewBlock ) {
3557
- pfrom.nLastBlockTime = GetTime ();
3558
- } else {
3559
- LOCK (cs_main);
3560
- mapBlockSource.erase (pblock->GetHash ());
3561
- }
3554
+ ProcessBlock (pfrom, pblock, forceProcessing);
3562
3555
return ;
3563
3556
}
3564
3557
0 commit comments