@@ -465,7 +465,7 @@ static bool MarkBlockAsReceived(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs
465
465
466
466
// returns false, still setting pit, if the block was already in flight from the same peer
467
467
// pit will only be valid as long as the same cs_main lock is being held
468
- static bool MarkBlockAsInFlight (NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr , std::list<QueuedBlock>::iterator** pit = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
468
+ static bool MarkBlockAsInFlight (CTxMemPool& mempool, NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr , std::list<QueuedBlock>::iterator** pit = nullptr ) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
469
469
CNodeState *state = State (nodeid);
470
470
assert (state != nullptr );
471
471
@@ -1102,8 +1102,11 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para
1102
1102
(GetBlockProofEquivalentTime (*pindexBestHeader, *pindex, *pindexBestHeader, consensusParams) < STALE_RELAY_AGE_LIMIT);
1103
1103
}
1104
1104
1105
- PeerLogicValidation::PeerLogicValidation (CConnman* connmanIn, BanMan* banman, CScheduler& scheduler)
1106
- : connman(connmanIn), m_banman(banman), m_stale_tip_check_time(0 )
1105
+ PeerLogicValidation::PeerLogicValidation (CConnman* connmanIn, BanMan* banman, CScheduler& scheduler, CTxMemPool& pool)
1106
+ : connman(connmanIn),
1107
+ m_banman(banman),
1108
+ m_mempool(pool),
1109
+ m_stale_tip_check_time(0 )
1107
1110
{
1108
1111
// Initialize global variables that cannot be constructed at startup.
1109
1112
recentRejects.reset (new CRollingBloomFilter (120000 , 0.000001 ));
@@ -1314,7 +1317,7 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const BlockValidatio
1314
1317
//
1315
1318
1316
1319
1317
- bool static AlreadyHave (const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1320
+ bool static AlreadyHave (const CInv& inv, const CTxMemPool& mempool ) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1318
1321
{
1319
1322
switch (inv.type )
1320
1323
{
@@ -1553,7 +1556,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
1553
1556
}
1554
1557
}
1555
1558
1556
- void static ProcessGetData (CNode* pfrom, const CChainParams& chainparams, CConnman* connman, const std::atomic<bool >& interruptMsgProc) LOCKS_EXCLUDED(cs_main)
1559
+ void static ProcessGetData (CNode* pfrom, const CChainParams& chainparams, CConnman* connman, const CTxMemPool& mempool, const std::atomic<bool >& interruptMsgProc) LOCKS_EXCLUDED(cs_main)
1557
1560
{
1558
1561
AssertLockNotHeld (cs_main);
1559
1562
@@ -1666,7 +1669,7 @@ inline void static SendBlockTransactions(const CBlock& block, const BlockTransac
1666
1669
connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::BLOCKTXN, resp));
1667
1670
}
1668
1671
1669
- bool static ProcessHeadersMessage (CNode * pfrom, CConnman * connman, const std::vector<CBlockHeader>& headers, const CChainParams& chainparams, bool via_compact_block)
1672
+ bool static ProcessHeadersMessage (CNode* pfrom, CConnman* connman, CTxMemPool& mempool , const std::vector<CBlockHeader>& headers, const CChainParams& chainparams, bool via_compact_block)
1670
1673
{
1671
1674
const CNetMsgMaker msgMaker (pfrom->GetSendVersion ());
1672
1675
size_t nCount = headers.size ();
@@ -1794,7 +1797,7 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1794
1797
}
1795
1798
uint32_t nFetchFlags = GetFetchFlags (pfrom);
1796
1799
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
1797
- MarkBlockAsInFlight (pfrom->GetId (), pindex->GetBlockHash (), pindex);
1800
+ MarkBlockAsInFlight (mempool, pfrom->GetId (), pindex->GetBlockHash (), pindex);
1798
1801
LogPrint (BCLog::NET, " Requesting block %s from peer=%d\n " ,
1799
1802
pindex->GetBlockHash ().ToString (), pfrom->GetId ());
1800
1803
}
@@ -1848,7 +1851,7 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1848
1851
return true ;
1849
1852
}
1850
1853
1851
- void static ProcessOrphanTx (CConnman* connman, std::set<uint256>& orphan_work_set, std::list<CTransactionRef>& removed_txn) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans)
1854
+ void static ProcessOrphanTx (CConnman* connman, CTxMemPool& mempool, std::set<uint256>& orphan_work_set, std::list<CTransactionRef>& removed_txn) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans)
1852
1855
{
1853
1856
AssertLockHeld (cs_main);
1854
1857
AssertLockHeld (g_cs_orphans);
@@ -1908,7 +1911,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
1908
1911
}
1909
1912
}
1910
1913
1911
- bool ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, BanMan* banman, const std::atomic<bool >& interruptMsgProc)
1914
+ bool ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CTxMemPool& mempool, CConnman* connman, BanMan* banman, const std::atomic<bool >& interruptMsgProc)
1912
1915
{
1913
1916
LogPrint (BCLog::NET, " received: %s (%u bytes) peer=%d\n " , SanitizeString (strCommand), vRecv.size (), pfrom->GetId ());
1914
1917
if (gArgs .IsArgSet (" -dropmessagestest" ) && GetRand (gArgs .GetArg (" -dropmessagestest" , 0 )) == 0 )
@@ -2260,7 +2263,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2260
2263
if (interruptMsgProc)
2261
2264
return true ;
2262
2265
2263
- bool fAlreadyHave = AlreadyHave (inv);
2266
+ bool fAlreadyHave = AlreadyHave (inv, mempool );
2264
2267
LogPrint (BCLog::NET, " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom->GetId ());
2265
2268
2266
2269
if (inv.type == MSG_TX) {
@@ -2311,7 +2314,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2311
2314
}
2312
2315
2313
2316
pfrom->vRecvGetData .insert (pfrom->vRecvGetData .end (), vInv.begin (), vInv.end ());
2314
- ProcessGetData (pfrom, chainparams, connman, interruptMsgProc);
2317
+ ProcessGetData (pfrom, chainparams, connman, mempool, interruptMsgProc);
2315
2318
return true ;
2316
2319
}
2317
2320
@@ -2528,7 +2531,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2528
2531
2529
2532
std::list<CTransactionRef> lRemovedTxn;
2530
2533
2531
- if (!AlreadyHave (inv) &&
2534
+ if (!AlreadyHave (inv, mempool ) &&
2532
2535
AcceptToMemoryPool (mempool, state, ptx, &lRemovedTxn, false /* bypass_limits */ , 0 /* nAbsurdFee */ )) {
2533
2536
mempool.check (&::ChainstateActive ().CoinsTip ());
2534
2537
RelayTransaction (tx.GetHash (), *connman);
@@ -2549,7 +2552,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2549
2552
mempool.size (), mempool.DynamicMemoryUsage () / 1000 );
2550
2553
2551
2554
// Recursively process any orphan transactions that depended on this one
2552
- ProcessOrphanTx (connman, pfrom->orphan_work_set , lRemovedTxn);
2555
+ ProcessOrphanTx (connman, mempool, pfrom->orphan_work_set , lRemovedTxn);
2553
2556
}
2554
2557
else if (state.GetResult () == TxValidationResult::TX_MISSING_INPUTS)
2555
2558
{
@@ -2567,7 +2570,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2567
2570
for (const CTxIn& txin : tx.vin ) {
2568
2571
CInv _inv (MSG_TX | nFetchFlags, txin.prevout .hash );
2569
2572
pfrom->AddInventoryKnown (_inv);
2570
- if (!AlreadyHave (_inv)) RequestTx (State (pfrom->GetId ()), _inv.hash , current_time);
2573
+ if (!AlreadyHave (_inv, mempool )) RequestTx (State (pfrom->GetId ()), _inv.hash , current_time);
2571
2574
}
2572
2575
AddOrphanTx (ptx, pfrom->GetId ());
2573
2576
@@ -2742,7 +2745,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2742
2745
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
2743
2746
(fAlreadyInFlight && blockInFlightIt->second .first == pfrom->GetId ())) {
2744
2747
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr ;
2745
- if (!MarkBlockAsInFlight (pfrom->GetId (), pindex->GetBlockHash (), pindex, &queuedBlockIt)) {
2748
+ if (!MarkBlockAsInFlight (mempool, pfrom->GetId (), pindex->GetBlockHash (), pindex, &queuedBlockIt)) {
2746
2749
if (!(*queuedBlockIt)->partialBlock )
2747
2750
(*queuedBlockIt)->partialBlock .reset (new PartiallyDownloadedBlock (&mempool));
2748
2751
else {
@@ -2815,15 +2818,15 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2815
2818
} // cs_main
2816
2819
2817
2820
if (fProcessBLOCKTXN )
2818
- return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, banman, interruptMsgProc);
2821
+ return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, mempool, connman, banman, interruptMsgProc);
2819
2822
2820
2823
if (fRevertToHeaderProcessing ) {
2821
2824
// Headers received from HB compact block peers are permitted to be
2822
2825
// relayed before full validation (see BIP 152), so we don't want to disconnect
2823
2826
// the peer if the header turns out to be for an invalid block.
2824
2827
// Note that if a peer tries to build on an invalid chain, that
2825
2828
// will be detected and the peer will be banned.
2826
- return ProcessHeadersMessage (pfrom, connman, {cmpctblock.header }, chainparams, /* via_compact_block=*/ true );
2829
+ return ProcessHeadersMessage (pfrom, connman, mempool, {cmpctblock.header }, chainparams, /* via_compact_block=*/ true );
2827
2830
}
2828
2831
2829
2832
if (fBlockReconstructed ) {
@@ -2967,7 +2970,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vR
2967
2970
ReadCompactSize (vRecv); // ignore tx count; assume it is 0.
2968
2971
}
2969
2972
2970
- return ProcessHeadersMessage (pfrom, connman, headers, chainparams, /* via_compact_block=*/ false );
2973
+ return ProcessHeadersMessage (pfrom, connman, mempool, headers, chainparams, /* via_compact_block=*/ false );
2971
2974
}
2972
2975
2973
2976
if (strCommand == NetMsgType::BLOCK)
@@ -3285,12 +3288,12 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3285
3288
bool fMoreWork = false ;
3286
3289
3287
3290
if (!pfrom->vRecvGetData .empty ())
3288
- ProcessGetData (pfrom, chainparams, connman, interruptMsgProc);
3291
+ ProcessGetData (pfrom, chainparams, connman, m_mempool, interruptMsgProc);
3289
3292
3290
3293
if (!pfrom->orphan_work_set .empty ()) {
3291
3294
std::list<CTransactionRef> removed_txn;
3292
3295
LOCK2 (cs_main, g_cs_orphans);
3293
- ProcessOrphanTx (connman, pfrom->orphan_work_set , removed_txn);
3296
+ ProcessOrphanTx (connman, m_mempool, pfrom->orphan_work_set , removed_txn);
3294
3297
for (const CTransactionRef& removedTx : removed_txn) {
3295
3298
AddToCompactExtraTransactions (removedTx);
3296
3299
}
@@ -3353,7 +3356,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3353
3356
bool fRet = false ;
3354
3357
try
3355
3358
{
3356
- fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.m_time , chainparams, connman, m_banman, interruptMsgProc);
3359
+ fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.m_time , chainparams, m_mempool, connman, m_banman, interruptMsgProc);
3357
3360
if (interruptMsgProc)
3358
3361
return false ;
3359
3362
if (!pfrom->vRecvGetData .empty ())
@@ -3819,7 +3822,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3819
3822
3820
3823
// Respond to BIP35 mempool requests
3821
3824
if (fSendTrickle && pto->m_tx_relay ->fSendMempool ) {
3822
- auto vtxinfo = mempool .infoAll ();
3825
+ auto vtxinfo = m_mempool .infoAll ();
3823
3826
pto->m_tx_relay ->fSendMempool = false ;
3824
3827
CFeeRate filterrate;
3825
3828
{
@@ -3865,7 +3868,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3865
3868
}
3866
3869
// Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
3867
3870
// A heap is used so that not all items need sorting if only a few are being sent.
3868
- CompareInvMempoolOrder compareInvMempoolOrder (&mempool );
3871
+ CompareInvMempoolOrder compareInvMempoolOrder (&m_mempool );
3869
3872
std::make_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
3870
3873
// No reason to drain out at many times the network's capacity,
3871
3874
// especially since we have many peers and some will draw much shorter delays.
@@ -3884,7 +3887,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3884
3887
continue ;
3885
3888
}
3886
3889
// Not in the mempool anymore? don't bother sending it.
3887
- auto txinfo = mempool .info (hash);
3890
+ auto txinfo = m_mempool .info (hash);
3888
3891
if (!txinfo.tx ) {
3889
3892
continue ;
3890
3893
}
@@ -3996,7 +3999,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3996
3999
for (const CBlockIndex *pindex : vToDownload) {
3997
4000
uint32_t nFetchFlags = GetFetchFlags (pto);
3998
4001
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
3999
- MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), pindex);
4002
+ MarkBlockAsInFlight (m_mempool, pto->GetId (), pindex->GetBlockHash (), pindex);
4000
4003
LogPrint (BCLog::NET, " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
4001
4004
pindex->nHeight , pto->GetId ());
4002
4005
}
@@ -4039,7 +4042,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
4039
4042
// processing at a later time, see below)
4040
4043
tx_process_time.erase (tx_process_time.begin ());
4041
4044
CInv inv (MSG_TX | GetFetchFlags (pto), txid);
4042
- if (!AlreadyHave (inv)) {
4045
+ if (!AlreadyHave (inv, m_mempool )) {
4043
4046
// If this transaction was last requested more than 1 minute ago,
4044
4047
// then request.
4045
4048
const auto last_request_time = GetTxRequestTime (inv.hash );
@@ -4077,7 +4080,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
4077
4080
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
4078
4081
if (pto->m_tx_relay != nullptr && pto->nVersion >= FEEFILTER_VERSION && gArgs .GetBoolArg (" -feefilter" , DEFAULT_FEEFILTER) &&
4079
4082
!pto->HasPermission (PF_FORCERELAY)) {
4080
- CAmount currentFilter = mempool .GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ).GetFeePerK ();
4083
+ CAmount currentFilter = m_mempool .GetMinFee (gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 ).GetFeePerK ();
4081
4084
int64_t timeNow = GetTimeMicros ();
4082
4085
if (timeNow > pto->m_tx_relay ->nextSendTimeFeeFilter ) {
4083
4086
static CFeeRate default_feerate (DEFAULT_MIN_RELAY_TX_FEE);
0 commit comments