From 36346703f8558d6781c079c29ddece5a97477beb Mon Sep 17 00:00:00 2001 From: John Newbery Date: Wed, 27 Jan 2021 20:44:10 +0000 Subject: [PATCH] [net] Add CNode.m_relays_txs and CNode.m_bloom_filter_loaded We'll move the transaction relay data into Peer in subsequent commits, but the inbound eviction logic needs to know if the peer is relaying txs and if the peer has loaded a bloom filter. This is currently redundant information with m_tx_relay->fRelayTxes, but when m_tx_relay is moved into net_processing, then we'll need these separate fields in CNode. --- src/net.cpp | 11 ++--------- src/net.h | 10 ++++++++++ src/net_processing.cpp | 5 +++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 955eec46e38..d9c309811d0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1112,18 +1112,11 @@ bool CConnman::AttemptToEvictConnection() continue; if (node->fDisconnect) continue; - bool peer_relay_txes = false; - bool peer_filter_not_null = false; - if (node->m_tx_relay != nullptr) { - LOCK(node->m_tx_relay->cs_filter); - peer_relay_txes = node->m_tx_relay->fRelayTxes; - peer_filter_not_null = node->m_tx_relay->pfilter != nullptr; - } NodeEvictionCandidate candidate = {node->GetId(), node->m_connected, node->m_min_ping_time, node->m_last_block_time, node->m_last_tx_time, HasAllDesirableServiceFlags(node->nServices), - peer_relay_txes, peer_filter_not_null, node->nKeyedNetGroup, - node->m_prefer_evict, node->addr.IsLocal(), + node->m_relays_txs.load(), node->m_bloom_filter_loaded.load(), + node->nKeyedNetGroup, node->m_prefer_evict, node->addr.IsLocal(), node->ConnectedThroughNetwork()}; vEvictionCandidates.push_back(candidate); } diff --git a/src/net.h b/src/net.h index a38310938b3..d7f57e24963 100644 --- a/src/net.h +++ b/src/net.h @@ -577,6 +577,16 @@ public: // m_tx_relay == nullptr if we're not relaying transactions with this peer std::unique_ptr m_tx_relay; + /** Whether we should relay transactions to this peer (their version + * message did not include fRelay=false and this is not a block-relay-only + * connection). This only changes from false to true. It will never change + * back to false. Used only in inbound eviction logic. */ + std::atomic_bool m_relays_txs{false}; + + /** Whether this peer has loaded a bloom filter. Used only in inbound + * eviction logic. */ + std::atomic_bool m_bloom_filter_loaded{false}; + /** UNIX epoch time of the last block received from this peer that we had * not yet seen (e.g. not already received from another peer), that passed * preliminary validity checks and was saved to disk, even if we don't diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 59cd83e4935..8008c209bc7 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2675,6 +2675,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, if (pfrom.m_tx_relay != nullptr) { LOCK(pfrom.m_tx_relay->cs_filter); pfrom.m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message + if (fRelay) pfrom.m_relays_txs = true; } if((nServices & NODE_WITNESS)) @@ -3993,7 +3994,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, { LOCK(pfrom.m_tx_relay->cs_filter); pfrom.m_tx_relay->pfilter.reset(new CBloomFilter(filter)); + pfrom.m_bloom_filter_loaded = true; pfrom.m_tx_relay->fRelayTxes = true; + pfrom.m_relays_txs = true; } return; } @@ -4037,7 +4040,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, } LOCK(pfrom.m_tx_relay->cs_filter); pfrom.m_tx_relay->pfilter = nullptr; + pfrom.m_bloom_filter_loaded = false; pfrom.m_tx_relay->fRelayTxes = true; + pfrom.m_relays_txs = true; return; }