From 60b5392d92ed2ee0d658e8c4270793fb87e7cb29 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 16 Aug 2021 13:49:50 +0100 Subject: [PATCH] partial bitcoin#22778: Reduce resource usage for inbound block-relay-only connections includes: - 290a8dab0288344fa5731ec2ffd09478e9420a2f --- src/net_processing.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 2005644b64a91..34f7df8eba030 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -272,25 +272,34 @@ struct Peer { struct TxRelay { mutable RecursiveMutex m_bloom_filter_mutex; - // We use m_relay_txs for two purposes - - // a) it allows us to not relay tx invs before receiving the peer's version message - // b) the peer may tell us in its version message that we should not relay tx invs - // unless it loads a bloom filter. + /** Whether the peer wishes to receive transaction announcements. + * + * This is initially set based on the fRelay flag in the received + * `version` message. If initially set to false, it can only be flipped + * to true if we have offered the peer NODE_BLOOM services and it sends + * us a `filterload` or `filterclear` message. See BIP37. */ bool m_relay_txs GUARDED_BY(m_bloom_filter_mutex){false}; + /** A bloom filter for which transactions to announce to the peer. See BIP37. */ std::unique_ptr m_bloom_filter PT_GUARDED_BY(m_bloom_filter_mutex) GUARDED_BY(m_bloom_filter_mutex){nullptr}; mutable RecursiveMutex m_tx_inventory_mutex; - // inventory based relay + /** A filter of all the txids that the peer has announced to + * us or we have announced to the peer. We use this to avoid announcing + * the same txid to a peer that already has the transaction. */ CRollingBloomFilter m_tx_inventory_known_filter GUARDED_BY(m_tx_inventory_mutex){50000, 0.000001}; - // Set of transaction ids we still have to announce. - // They are sorted by the mempool before relay, so the order is not important. + /** Set of transaction ids we still have to announce. We use the + * mempool to sort transactions in dependency order before relay, so + * this does not have to be sorted. */ std::set m_tx_inventory_to_send GUARDED_BY(m_tx_inventory_mutex); - // List of non-tx/non-block inventory items + /** List of non-tx/non-block inventory items */ std::vector vInventoryOtherToSend GUARDED_BY(m_tx_inventory_mutex); - // Used for BIP35 mempool sending, also protected by m_tx_inventory_mutex + /** Whether the peer has requested us to send our complete mempool. Only + * permitted if the peer has NetPermissionFlags::Mempool. See BIP35. */ bool m_send_mempool GUARDED_BY(m_tx_inventory_mutex){false}; - // Last time a "MEMPOOL" request was serviced. + /** The last time a BIP35 `mempool` request was serviced. */ std::atomic m_last_mempool_req{0s}; + /** The next time after which we will send an `inv` message containing + * transaction announcements to this peer. */ std::chrono::microseconds m_next_inv_send_time GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0}; };