mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +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};
|
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). */
|
/** 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) */
|
/** Relay map (txid or wtxid -> CTransactionRef) */
|
||||||
typedef std::map<uint256, CTransactionRef> MapRelay;
|
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 (txinfo.tx) {
|
||||||
// If a TX could have been INVed in reply to a MEMPOOL request,
|
// If a TX could have been INVed in reply to a MEMPOOL request,
|
||||||
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
|
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
|
||||||
@ -1878,7 +1878,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CTxMemPool& mempool, con
|
|||||||
return {};
|
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);
|
AssertLockNotHeld(cs_main);
|
||||||
|
|
||||||
@ -1907,17 +1907,17 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const CChainParam
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransactionRef tx = FindTxForGetData(mempool, pfrom, ToGenTxid(inv), mempool_req, now);
|
CTransactionRef tx = FindTxForGetData(pfrom, ToGenTxid(inv), mempool_req, now);
|
||||||
if (tx) {
|
if (tx) {
|
||||||
// WTX and WITNESS_TX imply we serialize with witness
|
// WTX and WITNESS_TX imply we serialize with witness
|
||||||
int nSendFlags = (inv.IsMsgTx() ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
|
int nSendFlags = (inv.IsMsgTx() ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
|
||||||
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
m_connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
||||||
mempool.RemoveUnbroadcastTx(tx->GetHash());
|
m_mempool.RemoveUnbroadcastTx(tx->GetHash());
|
||||||
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
|
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
|
||||||
std::vector<uint256> parent_ids_to_add;
|
std::vector<uint256> parent_ids_to_add;
|
||||||
{
|
{
|
||||||
LOCK(mempool.cs);
|
LOCK(m_mempool.cs);
|
||||||
auto txiter = mempool.GetIter(tx->GetHash());
|
auto txiter = m_mempool.GetIter(tx->GetHash());
|
||||||
if (txiter) {
|
if (txiter) {
|
||||||
const CTxMemPoolEntry::Parents& parents = (*txiter)->GetMemPoolParentsConst();
|
const CTxMemPoolEntry::Parents& parents = (*txiter)->GetMemPoolParentsConst();
|
||||||
parent_ids_to_add.reserve(parents.size());
|
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) {
|
if (it != peer.m_getdata_requests.end() && !pfrom.fPauseSend) {
|
||||||
const CInv &inv = *it++;
|
const CInv &inv = *it++;
|
||||||
if (inv.IsGenBlkMsg()) {
|
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
|
// else: If the first item on the queue is an unknown type, we erase it
|
||||||
// and continue processing the queue on the next call.
|
// 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
|
// In normal operation, we often send NOTFOUND messages for parents of
|
||||||
// transactions that we relay; if a peer is missing a parent, they may
|
// transactions that we relay; if a peer is missing a parent, they may
|
||||||
// assume we have them and request the parents from us.
|
// 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);
|
LOCK(peer->m_getdata_requests_mutex);
|
||||||
peer->m_getdata_requests.insert(peer->m_getdata_requests.end(), vInv.begin(), vInv.end());
|
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;
|
return;
|
||||||
@ -4043,7 +4043,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
|||||||
{
|
{
|
||||||
LOCK(peer->m_getdata_requests_mutex);
|
LOCK(peer->m_getdata_requests_mutex);
|
||||||
if (!peer->m_getdata_requests.empty()) {
|
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