0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

[net processing] Pass TxRelay to FindTxForGetData instead of Peer

This commit is contained in:
dergoegge 2023-03-31 13:15:22 +02:00
parent c85ee76a36
commit 3fa4c54ac5

View file

@ -317,10 +317,6 @@ struct Peer {
{ {
return WITH_LOCK(m_tx_relay_mutex, return m_tx_relay.get()); return WITH_LOCK(m_tx_relay_mutex, return m_tx_relay.get());
}; };
const TxRelay* GetTxRelay() const EXCLUSIVE_LOCKS_REQUIRED(!m_tx_relay_mutex)
{
return WITH_LOCK(m_tx_relay_mutex, return m_tx_relay.get());
};
/** A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */ /** A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */
std::vector<CAddress> m_addrs_to_send GUARDED_BY(NetEventsInterface::g_msgproc_mutex); std::vector<CAddress> m_addrs_to_send GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
@ -908,7 +904,7 @@ private:
std::atomic<std::chrono::seconds> m_last_tip_update{0s}; std::atomic<std::chrono::seconds> m_last_tip_update{0s};
/** 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 Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex); EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc) void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
@ -2258,7 +2254,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
} }
} }
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
{ {
auto txinfo = m_mempool.info(gtxid); auto txinfo = m_mempool.info(gtxid);
if (txinfo.tx) { if (txinfo.tx) {
@ -2271,7 +2267,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const GenTxi
} }
// Otherwise, the transaction must have been announced recently. // Otherwise, the transaction must have been announced recently.
if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(gtxid.GetHash())) { if (tx_relay.m_recently_announced_invs.contains(gtxid.GetHash())) {
// If it was, it can be relayed from either the mempool... // If it was, it can be relayed from either the mempool...
if (txinfo.tx) return std::move(txinfo.tx); if (txinfo.tx) return std::move(txinfo.tx);
// ... or the relay pool. // ... or the relay pool.
@ -2313,7 +2309,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
continue; continue;
} }
CTransactionRef tx = FindTxForGetData(peer, ToGenTxid(inv), mempool_req, now); CTransactionRef tx = FindTxForGetData(*tx_relay, 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);