Skip to content

Commit 3634670

Browse files
committed
[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.
1 parent a17df4e commit 3634670

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/net.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,18 +1112,11 @@ bool CConnman::AttemptToEvictConnection()
11121112
continue;
11131113
if (node->fDisconnect)
11141114
continue;
1115-
bool peer_relay_txes = false;
1116-
bool peer_filter_not_null = false;
1117-
if (node->m_tx_relay != nullptr) {
1118-
LOCK(node->m_tx_relay->cs_filter);
1119-
peer_relay_txes = node->m_tx_relay->fRelayTxes;
1120-
peer_filter_not_null = node->m_tx_relay->pfilter != nullptr;
1121-
}
11221115
NodeEvictionCandidate candidate = {node->GetId(), node->m_connected, node->m_min_ping_time,
11231116
node->m_last_block_time, node->m_last_tx_time,
11241117
HasAllDesirableServiceFlags(node->nServices),
1125-
peer_relay_txes, peer_filter_not_null, node->nKeyedNetGroup,
1126-
node->m_prefer_evict, node->addr.IsLocal(),
1118+
node->m_relays_txs.load(), node->m_bloom_filter_loaded.load(),
1119+
node->nKeyedNetGroup, node->m_prefer_evict, node->addr.IsLocal(),
11271120
node->ConnectedThroughNetwork()};
11281121
vEvictionCandidates.push_back(candidate);
11291122
}

src/net.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,16 @@ class CNode
577577
// m_tx_relay == nullptr if we're not relaying transactions with this peer
578578
std::unique_ptr<TxRelay> m_tx_relay;
579579

580+
/** Whether we should relay transactions to this peer (their version
581+
* message did not include fRelay=false and this is not a block-relay-only
582+
* connection). This only changes from false to true. It will never change
583+
* back to false. Used only in inbound eviction logic. */
584+
std::atomic_bool m_relays_txs{false};
585+
586+
/** Whether this peer has loaded a bloom filter. Used only in inbound
587+
* eviction logic. */
588+
std::atomic_bool m_bloom_filter_loaded{false};
589+
580590
/** UNIX epoch time of the last block received from this peer that we had
581591
* not yet seen (e.g. not already received from another peer), that passed
582592
* preliminary validity checks and was saved to disk, even if we don't

src/net_processing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
26752675
if (pfrom.m_tx_relay != nullptr) {
26762676
LOCK(pfrom.m_tx_relay->cs_filter);
26772677
pfrom.m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message
2678+
if (fRelay) pfrom.m_relays_txs = true;
26782679
}
26792680

26802681
if((nServices & NODE_WITNESS))
@@ -3993,7 +3994,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
39933994
{
39943995
LOCK(pfrom.m_tx_relay->cs_filter);
39953996
pfrom.m_tx_relay->pfilter.reset(new CBloomFilter(filter));
3997+
pfrom.m_bloom_filter_loaded = true;
39963998
pfrom.m_tx_relay->fRelayTxes = true;
3999+
pfrom.m_relays_txs = true;
39974000
}
39984001
return;
39994002
}
@@ -4037,7 +4040,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
40374040
}
40384041
LOCK(pfrom.m_tx_relay->cs_filter);
40394042
pfrom.m_tx_relay->pfilter = nullptr;
4043+
pfrom.m_bloom_filter_loaded = false;
40404044
pfrom.m_tx_relay->fRelayTxes = true;
4045+
pfrom.m_relays_txs = true;
40414046
return;
40424047
}
40434048

0 commit comments

Comments
 (0)