mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00
net_processing: simplify ProcessGetData and FindTxForGetData args
No need to pass mempool or connman to PeerManagerImpl methods.
This commit is contained in:
parent
34207b9004
commit
7b7117efd0
@ -442,9 +442,9 @@ private:
|
||||
std::atomic<int64_t> m_last_tip_update{0};
|
||||
|
||||
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
|
||||
CTransactionRef FindTxForGetData(const CTxMemPool& mempool, const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main);
|
||||
CTransactionRef FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main);
|
||||
|
||||
void ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainparams, CConnman& connman, CTxMemPool& mempool, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(!cs_main, peer.m_getdata_requests_mutex);
|
||||
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(!cs_main, peer.m_getdata_requests_mutex);
|
||||
|
||||
/** Relay map (txid or wtxid -> CTransactionRef) */
|
||||
typedef std::map<uint256, CTransactionRef> MapRelay;
|
||||
@ -1851,9 +1851,9 @@ void static ProcessGetBlockData(CNode& pfrom, Peer& peer, const CChainParams& ch
|
||||
}
|
||||
}
|
||||
|
||||
CTransactionRef PeerManagerImpl::FindTxForGetData(const CTxMemPool& mempool, const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main)
|
||||
CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main)
|
||||
{
|
||||
auto txinfo = mempool.info(gtxid);
|
||||
auto txinfo = m_mempool.info(gtxid);
|
||||
if (txinfo.tx) {
|
||||
// If a TX could have been INVed in reply to a MEMPOOL request,
|
||||
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
|
||||
@ -1878,7 +1878,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CTxMemPool& mempool, con
|
||||
return {};
|
||||
}
|
||||
|
||||
void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const CChainParams& chainparams, CConnman& connman, CTxMemPool& mempool, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(!cs_main, peer.m_getdata_requests_mutex)
|
||||
void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(!cs_main, peer.m_getdata_requests_mutex)
|
||||
{
|
||||
AssertLockNotHeld(cs_main);
|
||||
|
||||
@ -1907,17 +1907,17 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const CChainParam
|
||||
continue;
|
||||
}
|
||||
|
||||
CTransactionRef tx = FindTxForGetData(mempool, pfrom, ToGenTxid(inv), mempool_req, now);
|
||||
CTransactionRef tx = FindTxForGetData(pfrom, ToGenTxid(inv), mempool_req, now);
|
||||
if (tx) {
|
||||
// WTX and WITNESS_TX imply we serialize with witness
|
||||
int nSendFlags = (inv.IsMsgTx() ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
|
||||
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
||||
mempool.RemoveUnbroadcastTx(tx->GetHash());
|
||||
m_connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
||||
m_mempool.RemoveUnbroadcastTx(tx->GetHash());
|
||||
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
|
||||
std::vector<uint256> parent_ids_to_add;
|
||||
{
|
||||
LOCK(mempool.cs);
|
||||
auto txiter = mempool.GetIter(tx->GetHash());
|
||||
LOCK(m_mempool.cs);
|
||||
auto txiter = m_mempool.GetIter(tx->GetHash());
|
||||
if (txiter) {
|
||||
const CTxMemPoolEntry::Parents& parents = (*txiter)->GetMemPoolParentsConst();
|
||||
parent_ids_to_add.reserve(parents.size());
|
||||
@ -1945,7 +1945,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const CChainParam
|
||||
if (it != peer.m_getdata_requests.end() && !pfrom.fPauseSend) {
|
||||
const CInv &inv = *it++;
|
||||
if (inv.IsGenBlkMsg()) {
|
||||
ProcessGetBlockData(pfrom, peer, chainparams, inv, connman);
|
||||
ProcessGetBlockData(pfrom, peer, m_chainparams, inv, m_connman);
|
||||
}
|
||||
// else: If the first item on the queue is an unknown type, we erase it
|
||||
// and continue processing the queue on the next call.
|
||||
@ -1968,7 +1968,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const CChainParam
|
||||
// In normal operation, we often send NOTFOUND messages for parents of
|
||||
// transactions that we relay; if a peer is missing a parent, they may
|
||||
// assume we have them and request the parents from us.
|
||||
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::NOTFOUND, vNotFound));
|
||||
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::NOTFOUND, vNotFound));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2968,7 +2968,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
{
|
||||
LOCK(peer->m_getdata_requests_mutex);
|
||||
peer->m_getdata_requests.insert(peer->m_getdata_requests.end(), vInv.begin(), vInv.end());
|
||||
ProcessGetData(pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc);
|
||||
ProcessGetData(pfrom, *peer, interruptMsgProc);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -4043,7 +4043,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
||||
{
|
||||
LOCK(peer->m_getdata_requests_mutex);
|
||||
if (!peer->m_getdata_requests.empty()) {
|
||||
ProcessGetData(*pfrom, *peer, m_chainparams, m_connman, m_mempool, interruptMsgProc);
|
||||
ProcessGetData(*pfrom, *peer, interruptMsgProc);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user