[net processing] Move m_recently_announced_invs from CNodeState to Peer
This commit is contained in:
1 parent
938a8e2566
commit
279c53d7e4
1 file changed
+14
-11
+14
-11
@@ -278,6 +278,9 @@ struct Peer {
|
|||||||
/** A bloom filter for which transactions to announce to the peer. See BIP37. */
|
/** 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};
|
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;
|
mutable RecursiveMutex m_tx_inventory_mutex;
|
||||||
/** A filter of all the txids and wtxids that the peer has announced to
|
/** 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
|
* 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());
|
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);
|
||||||
@@ -400,7 +407,7 @@ struct Peer {
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex m_tx_relay_mutex;
|
mutable Mutex m_tx_relay_mutex;
|
||||||
|
|
||||||
/** Transaction relay data. May be a nullptr. */
|
/** Transaction relay data. May be a nullptr. */
|
||||||
std::unique_ptr<TxRelay> m_tx_relay GUARDED_BY(m_tx_relay_mutex);
|
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
|
//! Whether this peer is an inbound connection
|
||||||
const bool m_is_inbound;
|
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) {}
|
CNodeState(bool is_inbound) : m_is_inbound(is_inbound) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -904,7 +908,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 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);
|
LOCKS_EXCLUDED(cs_main) 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)
|
||||||
@@ -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);
|
auto txinfo = m_mempool.info(gtxid);
|
||||||
if (txinfo.tx) {
|
if (txinfo.tx) {
|
||||||
@@ -2269,7 +2273,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTx
|
|||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
// Otherwise, the transaction must have been announced recently.
|
// 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 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.
|
||||||
@@ -2312,7 +2316,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransactionRef tx = FindTxForGetData(pfrom, ToGenTxid(inv), mempool_req, now);
|
CTransactionRef tx = FindTxForGetData(peer, 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);
|
||||||
@@ -2336,8 +2340,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
|
|||||||
for (const uint256& parent_txid : parent_ids_to_add) {
|
for (const uint256& parent_txid : parent_ids_to_add) {
|
||||||
// Relaying a transaction with a recent but unconfirmed parent.
|
// 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))) {
|
if (WITH_LOCK(tx_relay->m_tx_inventory_mutex, return !tx_relay->m_tx_inventory_known_filter.contains(parent_txid))) {
|
||||||
LOCK(cs_main);
|
tx_relay->m_recently_announced_invs.insert(parent_txid);
|
||||||
State(pfrom.GetId())->m_recently_announced_invs.insert(parent_txid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
if (tx_relay->m_bloom_filter && !tx_relay->m_bloom_filter->IsRelevantAndUpdate(*txinfo.tx)) continue;
|
||||||
// Send
|
// Send
|
||||||
State(pto->GetId())->m_recently_announced_invs.insert(hash);
|
tx_relay->m_recently_announced_invs.insert(hash);
|
||||||
vInv.push_back(inv);
|
vInv.push_back(inv);
|
||||||
nRelayedTransactions++;
|
nRelayedTransactions++;
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user