@@ -1241,8 +1241,10 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para
1241
1241
(GetBlockProofEquivalentTime (*pindexBestHeader, *pindex, *pindexBestHeader, consensusParams) < STALE_RELAY_AGE_LIMIT);
1242
1242
}
1243
1243
1244
- PeerLogicValidation::PeerLogicValidation (CConnman& connman, BanMan* banman, CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool)
1245
- : m_connman(connman),
1244
+ PeerLogicValidation::PeerLogicValidation (const CChainParams& chainparams, CConnman& connman, BanMan* banman,
1245
+ CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool)
1246
+ : m_chainparams(chainparams),
1247
+ m_connman(connman),
1246
1248
m_banman(banman),
1247
1249
m_chainman(chainman),
1248
1250
m_mempool(pool),
@@ -2340,7 +2342,7 @@ static void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv, const CChainPar
2340
2342
2341
2343
void PeerLogicValidation::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
2342
2344
const std::chrono::microseconds time_received,
2343
- const CChainParams& chainparams, const std::atomic<bool >& interruptMsgProc)
2345
+ const std::atomic<bool >& interruptMsgProc)
2344
2346
{
2345
2347
LogPrint (BCLog::NET, " received: %s (%u bytes) peer=%d\n " , SanitizeString (msg_type), vRecv.size (), pfrom.GetId ());
2346
2348
if (gArgs .IsArgSet (" -dropmessagestest" ) && GetRand (gArgs .GetArg (" -dropmessagestest" , 0 )) == 0 )
@@ -2772,7 +2774,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2772
2774
}
2773
2775
2774
2776
pfrom.vRecvGetData .insert (pfrom.vRecvGetData .end (), vInv.begin (), vInv.end ());
2775
- ProcessGetData (pfrom, chainparams , m_connman, m_mempool, interruptMsgProc);
2777
+ ProcessGetData (pfrom, m_chainparams , m_connman, m_mempool, interruptMsgProc);
2776
2778
return ;
2777
2779
}
2778
2780
@@ -2825,7 +2827,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2825
2827
}
2826
2828
// If pruning, don't inv blocks unless we have on disk and are likely to still have
2827
2829
// for some reasonable time window (1 hour) that block relay might require.
2828
- const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams .GetConsensus ().nPowTargetSpacing ;
2830
+ const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / m_chainparams .GetConsensus ().nPowTargetSpacing ;
2829
2831
if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= ::ChainActive ().Tip ()->nHeight - nPrunedBlocksLikelyToHave))
2830
2832
{
2831
2833
LogPrint (BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
@@ -2886,7 +2888,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2886
2888
}
2887
2889
2888
2890
CBlock block;
2889
- bool ret = ReadBlockFromDisk (block, pindex, chainparams .GetConsensus ());
2891
+ bool ret = ReadBlockFromDisk (block, pindex, m_chainparams .GetConsensus ());
2890
2892
assert (ret);
2891
2893
2892
2894
SendBlockTransactions (block, req, pfrom, m_connman);
@@ -2920,7 +2922,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2920
2922
return ;
2921
2923
}
2922
2924
2923
- if (!BlockRequestAllowed (pindex, chainparams .GetConsensus ())) {
2925
+ if (!BlockRequestAllowed (pindex, m_chainparams .GetConsensus ())) {
2924
2926
LogPrint (BCLog::NET, " %s: ignoring request from peer=%i for old block header that isn't in the main chain\n " , __func__, pfrom.GetId ());
2925
2927
return ;
2926
2928
}
@@ -3198,7 +3200,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3198
3200
3199
3201
const CBlockIndex *pindex = nullptr ;
3200
3202
BlockValidationState state;
3201
- if (!m_chainman.ProcessNewBlockHeaders ({cmpctblock.header }, state, chainparams , &pindex)) {
3203
+ if (!m_chainman.ProcessNewBlockHeaders ({cmpctblock.header }, state, m_chainparams , &pindex)) {
3202
3204
if (state.IsInvalid ()) {
3203
3205
MaybePunishNodeForBlock (pfrom.GetId (), state, /* via_compact_block*/ true , " invalid header via cmpctblock" );
3204
3206
return ;
@@ -3254,10 +3256,10 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3254
3256
}
3255
3257
3256
3258
// If we're not close to tip yet, give up and let parallel block fetch work its magic
3257
- if (!fAlreadyInFlight && !CanDirectFetch (chainparams .GetConsensus ()))
3259
+ if (!fAlreadyInFlight && !CanDirectFetch (m_chainparams .GetConsensus ()))
3258
3260
return ;
3259
3261
3260
- if (IsWitnessEnabled (pindex->pprev , chainparams .GetConsensus ()) && !nodestate->fSupportsDesiredCmpctVersion ) {
3262
+ if (IsWitnessEnabled (pindex->pprev , m_chainparams .GetConsensus ()) && !nodestate->fSupportsDesiredCmpctVersion ) {
3261
3263
// Don't bother trying to process compact blocks from v1 peers
3262
3264
// after segwit activates.
3263
3265
return ;
@@ -3341,16 +3343,17 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3341
3343
}
3342
3344
} // cs_main
3343
3345
3344
- if (fProcessBLOCKTXN )
3345
- return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, time_received, chainparams, interruptMsgProc);
3346
+ if (fProcessBLOCKTXN ) {
3347
+ return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, time_received, interruptMsgProc);
3348
+ }
3346
3349
3347
3350
if (fRevertToHeaderProcessing ) {
3348
3351
// Headers received from HB compact block peers are permitted to be
3349
3352
// relayed before full validation (see BIP 152), so we don't want to disconnect
3350
3353
// the peer if the header turns out to be for an invalid block.
3351
3354
// Note that if a peer tries to build on an invalid chain, that
3352
3355
// will be detected and the peer will be disconnected/discouraged.
3353
- return ProcessHeadersMessage (pfrom, m_connman, m_chainman, m_mempool, {cmpctblock.header }, chainparams , /* via_compact_block=*/ true );
3356
+ return ProcessHeadersMessage (pfrom, m_connman, m_chainman, m_mempool, {cmpctblock.header }, m_chainparams , /* via_compact_block=*/ true );
3354
3357
}
3355
3358
3356
3359
if (fBlockReconstructed ) {
@@ -3370,7 +3373,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3370
3373
// we have a chain with at least nMinimumChainWork), and we ignore
3371
3374
// compact blocks with less work than our tip, it is safe to treat
3372
3375
// reconstructed compact blocks as having been requested.
3373
- m_chainman.ProcessNewBlock (chainparams , pblock, /* fForceProcessing=*/ true , &fNewBlock );
3376
+ m_chainman.ProcessNewBlock (m_chainparams , pblock, /* fForceProcessing=*/ true , &fNewBlock );
3374
3377
if (fNewBlock ) {
3375
3378
pfrom.nLastBlockTime = GetTime ();
3376
3379
} else {
@@ -3460,7 +3463,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3460
3463
// disk-space attacks), but this should be safe due to the
3461
3464
// protections in the compact block handler -- see related comment
3462
3465
// in compact block optimistic reconstruction handling.
3463
- m_chainman.ProcessNewBlock (chainparams , pblock, /* fForceProcessing=*/ true , &fNewBlock );
3466
+ m_chainman.ProcessNewBlock (m_chainparams , pblock, /* fForceProcessing=*/ true , &fNewBlock );
3464
3467
if (fNewBlock ) {
3465
3468
pfrom.nLastBlockTime = GetTime ();
3466
3469
} else {
@@ -3493,7 +3496,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3493
3496
ReadCompactSize (vRecv); // ignore tx count; assume it is 0.
3494
3497
}
3495
3498
3496
- return ProcessHeadersMessage (pfrom, m_connman, m_chainman, m_mempool, headers, chainparams , /* via_compact_block=*/ false );
3499
+ return ProcessHeadersMessage (pfrom, m_connman, m_chainman, m_mempool, headers, m_chainparams , /* via_compact_block=*/ false );
3497
3500
}
3498
3501
3499
3502
if (msg_type == NetMsgType::BLOCK)
@@ -3522,7 +3525,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3522
3525
mapBlockSource.emplace (hash, std::make_pair (pfrom.GetId (), true ));
3523
3526
}
3524
3527
bool fNewBlock = false ;
3525
- m_chainman.ProcessNewBlock (chainparams , pblock, forceProcessing, &fNewBlock );
3528
+ m_chainman.ProcessNewBlock (m_chainparams , pblock, forceProcessing, &fNewBlock );
3526
3529
if (fNewBlock ) {
3527
3530
pfrom.nLastBlockTime = GetTime ();
3528
3531
} else {
@@ -3751,17 +3754,17 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3751
3754
}
3752
3755
3753
3756
if (msg_type == NetMsgType::GETCFILTERS) {
3754
- ProcessGetCFilters (pfrom, vRecv, chainparams , m_connman);
3757
+ ProcessGetCFilters (pfrom, vRecv, m_chainparams , m_connman);
3755
3758
return ;
3756
3759
}
3757
3760
3758
3761
if (msg_type == NetMsgType::GETCFHEADERS) {
3759
- ProcessGetCFHeaders (pfrom, vRecv, chainparams , m_connman);
3762
+ ProcessGetCFHeaders (pfrom, vRecv, m_chainparams , m_connman);
3760
3763
return ;
3761
3764
}
3762
3765
3763
3766
if (msg_type == NetMsgType::GETCFCHECKPT) {
3764
- ProcessGetCFCheckPt (pfrom, vRecv, chainparams , m_connman);
3767
+ ProcessGetCFCheckPt (pfrom, vRecv, m_chainparams , m_connman);
3765
3768
return ;
3766
3769
}
3767
3770
@@ -3839,7 +3842,6 @@ bool PeerLogicValidation::MaybeDiscourageAndDisconnect(CNode& pnode)
3839
3842
3840
3843
bool PeerLogicValidation::ProcessMessages (CNode* pfrom, std::atomic<bool >& interruptMsgProc)
3841
3844
{
3842
- const CChainParams& chainparams = Params ();
3843
3845
//
3844
3846
// Message format
3845
3847
// (4) message start
@@ -3851,7 +3853,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3851
3853
bool fMoreWork = false ;
3852
3854
3853
3855
if (!pfrom->vRecvGetData .empty ())
3854
- ProcessGetData (*pfrom, chainparams , m_connman, m_mempool, interruptMsgProc);
3856
+ ProcessGetData (*pfrom, m_chainparams , m_connman, m_mempool, interruptMsgProc);
3855
3857
3856
3858
if (!pfrom->orphan_work_set .empty ()) {
3857
3859
std::list<CTransactionRef> removed_txn;
@@ -3916,7 +3918,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3916
3918
}
3917
3919
3918
3920
try {
3919
- ProcessMessage (*pfrom, msg_type, vRecv, msg.m_time , chainparams, interruptMsgProc);
3921
+ ProcessMessage (*pfrom, msg_type, vRecv, msg.m_time , interruptMsgProc);
3920
3922
if (interruptMsgProc)
3921
3923
return false ;
3922
3924
if (!pfrom->vRecvGetData .empty ())
0 commit comments