mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
[net processing] Move m_recently_announced_invs from CNodeState to Peer
This commit is contained in:
@@ -278,6 +278,9 @@ struct Peer {
|
||||
/** A bloom filter for which transactions to announce to the peer. See BIP37. */
|
||||
std::unique_ptr<CBloomFilter> m_bloom_filter PT_GUARDED_BY(m_bloom_filter_mutex) GUARDED_BY(m_bloom_filter_mutex){nullptr};
|
||||
|
||||
/** A rolling bloom filter of all announced tx CInvs to this peer */
|
||||
CRollingBloomFilter m_recently_announced_invs GUARDED_BY(NetEventsInterface::g_msgproc_mutex){INVENTORY_MAX_RECENT_RELAY, 0.000001};
|
||||
|
||||
mutable RecursiveMutex m_tx_inventory_mutex;
|
||||
/** A filter of all the txids and wtxids that the peer has announced to
|
||||
* us or we have announced to the peer. We use this to avoid announcing
|
||||
@@ -314,6 +317,10 @@ struct Peer {
|
||||
{
|
||||
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. */
|
||||
std::vector<CAddress> m_addrs_to_send GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
|
||||
@@ -400,7 +407,7 @@ struct Peer {
|
||||
{}
|
||||
|
||||
private:
|
||||
Mutex m_tx_relay_mutex;
|
||||
mutable Mutex m_tx_relay_mutex;
|
||||
|
||||
/** Transaction relay data. May be a nullptr. */
|
||||
std::unique_ptr<TxRelay> m_tx_relay GUARDED_BY(m_tx_relay_mutex);
|
||||
@@ -481,9 +488,6 @@ struct CNodeState {
|
||||
//! Whether this peer is an inbound connection
|
||||
const bool m_is_inbound;
|
||||
|
||||
//! A rolling bloom filter of all announced tx CInvs to this peer.
|
||||
CRollingBloomFilter m_recently_announced_invs GUARDED_BY(NetEventsInterface::g_msgproc_mutex){INVENTORY_MAX_RECENT_RELAY, 0.000001};
|
||||
|
||||
CNodeState(bool is_inbound) : m_is_inbound(is_inbound) {}
|
||||
};
|
||||
|
||||
@@ -904,7 +908,7 @@ private:
|
||||
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). */
|
||||
CTransactionRef FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
||||
CTransactionRef FindTxForGetData(const Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
||||
LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
|
||||
|
||||
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
|
||||
@@ -2254,7 +2258,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
||||
}
|
||||
}
|
||||
|
||||
CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
||||
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
|
||||
{
|
||||
auto txinfo = m_mempool.info(gtxid);
|
||||
if (txinfo.tx) {
|
||||
@@ -2269,7 +2273,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTx
|
||||
{
|
||||
LOCK(cs_main);
|
||||
// Otherwise, the transaction must have been announced recently.
|
||||
if (State(peer.GetId())->m_recently_announced_invs.contains(gtxid.GetHash())) {
|
||||
if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(gtxid.GetHash())) {
|
||||
// If it was, it can be relayed from either the mempool...
|
||||
if (txinfo.tx) return std::move(txinfo.tx);
|
||||
// ... or the relay pool.
|
||||
@@ -2312,7 +2316,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
|
||||
continue;
|
||||
}
|
||||
|
||||
CTransactionRef tx = FindTxForGetData(pfrom, ToGenTxid(inv), mempool_req, now);
|
||||
CTransactionRef tx = FindTxForGetData(peer, 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);
|
||||
@@ -2336,8 +2340,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
|
||||
for (const uint256& parent_txid : parent_ids_to_add) {
|
||||
// Relaying a transaction with a recent but unconfirmed parent.
|
||||
if (WITH_LOCK(tx_relay->m_tx_inventory_mutex, return !tx_relay->m_tx_inventory_known_filter.contains(parent_txid))) {
|
||||
LOCK(cs_main);
|
||||
State(pfrom.GetId())->m_recently_announced_invs.insert(parent_txid);
|
||||
tx_relay->m_recently_announced_invs.insert(parent_txid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -5687,7 +5690,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
||||
}
|
||||
if (tx_relay->m_bloom_filter && !tx_relay->m_bloom_filter->IsRelevantAndUpdate(*txinfo.tx)) continue;
|
||||
// Send
|
||||
State(pto->GetId())->m_recently_announced_invs.insert(hash);
|
||||
tx_relay->m_recently_announced_invs.insert(hash);
|
||||
vInv.push_back(inv);
|
||||
nRelayedTransactions++;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user