@@ -278,6 +278,9 @@ struct Peer {
278
278
/* * A bloom filter for which transactions to announce to the peer. See BIP37. */
279
279
std::unique_ptr<CBloomFilter> m_bloom_filter PT_GUARDED_BY (m_bloom_filter_mutex) GUARDED_BY(m_bloom_filter_mutex){nullptr };
280
280
281
+ /* * A rolling bloom filter of all announced tx CInvs to this peer */
282
+ CRollingBloomFilter m_recently_announced_invs GUARDED_BY (NetEventsInterface::g_msgproc_mutex){INVENTORY_MAX_RECENT_RELAY, 0.000001 };
283
+
281
284
mutable RecursiveMutex m_tx_inventory_mutex;
282
285
/* * A filter of all the txids and wtxids that the peer has announced to
283
286
* us or we have announced to the peer. We use this to avoid announcing
@@ -314,6 +317,10 @@ struct Peer {
314
317
{
315
318
return WITH_LOCK (m_tx_relay_mutex, return m_tx_relay.get ());
316
319
};
320
+ const TxRelay* GetTxRelay () const EXCLUSIVE_LOCKS_REQUIRED(!m_tx_relay_mutex)
321
+ {
322
+ return WITH_LOCK (m_tx_relay_mutex, return m_tx_relay.get ());
323
+ };
317
324
318
325
/* * A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */
319
326
std::vector<CAddress> m_addrs_to_send GUARDED_BY (NetEventsInterface::g_msgproc_mutex);
@@ -400,7 +407,7 @@ struct Peer {
400
407
{}
401
408
402
409
private:
403
- Mutex m_tx_relay_mutex;
410
+ mutable Mutex m_tx_relay_mutex;
404
411
405
412
/* * Transaction relay data. May be a nullptr. */
406
413
std::unique_ptr<TxRelay> m_tx_relay GUARDED_BY (m_tx_relay_mutex);
@@ -481,9 +488,6 @@ struct CNodeState {
481
488
// ! Whether this peer is an inbound connection
482
489
const bool m_is_inbound;
483
490
484
- // ! A rolling bloom filter of all announced tx CInvs to this peer.
485
- CRollingBloomFilter m_recently_announced_invs GUARDED_BY (NetEventsInterface::g_msgproc_mutex){INVENTORY_MAX_RECENT_RELAY, 0.000001 };
486
-
487
491
CNodeState (bool is_inbound) : m_is_inbound(is_inbound) {}
488
492
};
489
493
@@ -904,7 +908,7 @@ class PeerManagerImpl final : public PeerManager
904
908
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
905
909
906
910
/* * Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
907
- CTransactionRef FindTxForGetData (const CNode & peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
911
+ CTransactionRef FindTxForGetData (const Peer & peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
908
912
LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
909
913
910
914
void ProcessGetData (CNode& pfrom, Peer& peer, const std::atomic<bool >& interruptMsgProc)
@@ -2254,7 +2258,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
2254
2258
}
2255
2259
}
2256
2260
2257
- CTransactionRef PeerManagerImpl::FindTxForGetData (const CNode & peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
2261
+ CTransactionRef PeerManagerImpl::FindTxForGetData (const Peer & peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
2258
2262
{
2259
2263
auto txinfo = m_mempool.info (gtxid);
2260
2264
if (txinfo.tx ) {
@@ -2269,7 +2273,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTx
2269
2273
{
2270
2274
LOCK (cs_main);
2271
2275
// Otherwise, the transaction must have been announced recently.
2272
- if (State (peer.GetId ())->m_recently_announced_invs .contains (gtxid.GetHash ())) {
2276
+ if (Assume (peer.GetTxRelay ())->m_recently_announced_invs .contains (gtxid.GetHash ())) {
2273
2277
// If it was, it can be relayed from either the mempool...
2274
2278
if (txinfo.tx ) return std::move (txinfo.tx );
2275
2279
// ... or the relay pool.
@@ -2312,7 +2316,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
2312
2316
continue ;
2313
2317
}
2314
2318
2315
- CTransactionRef tx = FindTxForGetData (pfrom , ToGenTxid (inv), mempool_req, now);
2319
+ CTransactionRef tx = FindTxForGetData (peer , ToGenTxid (inv), mempool_req, now);
2316
2320
if (tx) {
2317
2321
// WTX and WITNESS_TX imply we serialize with witness
2318
2322
int nSendFlags = (inv.IsMsgTx () ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 );
@@ -2336,8 +2340,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
2336
2340
for (const uint256& parent_txid : parent_ids_to_add) {
2337
2341
// Relaying a transaction with a recent but unconfirmed parent.
2338
2342
if (WITH_LOCK (tx_relay->m_tx_inventory_mutex , return !tx_relay->m_tx_inventory_known_filter .contains (parent_txid))) {
2339
- LOCK (cs_main);
2340
- State (pfrom.GetId ())->m_recently_announced_invs .insert (parent_txid);
2343
+ tx_relay->m_recently_announced_invs .insert (parent_txid);
2341
2344
}
2342
2345
}
2343
2346
} else {
@@ -5687,7 +5690,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5687
5690
}
5688
5691
if (tx_relay->m_bloom_filter && !tx_relay->m_bloom_filter ->IsRelevantAndUpdate (*txinfo.tx )) continue ;
5689
5692
// Send
5690
- State (pto-> GetId ()) ->m_recently_announced_invs .insert (hash);
5693
+ tx_relay ->m_recently_announced_invs .insert (hash);
5691
5694
vInv.push_back (inv);
5692
5695
nRelayedTransactions++;
5693
5696
{
0 commit comments