mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 04:12:36 -03:00
[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.
This commit is contained in:
parent
a17df4e876
commit
36346703f8
3 changed files with 17 additions and 9 deletions
11
src/net.cpp
11
src/net.cpp
|
@ -1112,18 +1112,11 @@ bool CConnman::AttemptToEvictConnection()
|
||||||
continue;
|
continue;
|
||||||
if (node->fDisconnect)
|
if (node->fDisconnect)
|
||||||
continue;
|
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,
|
NodeEvictionCandidate candidate = {node->GetId(), node->m_connected, node->m_min_ping_time,
|
||||||
node->m_last_block_time, node->m_last_tx_time,
|
node->m_last_block_time, node->m_last_tx_time,
|
||||||
HasAllDesirableServiceFlags(node->nServices),
|
HasAllDesirableServiceFlags(node->nServices),
|
||||||
peer_relay_txes, peer_filter_not_null, node->nKeyedNetGroup,
|
node->m_relays_txs.load(), node->m_bloom_filter_loaded.load(),
|
||||||
node->m_prefer_evict, node->addr.IsLocal(),
|
node->nKeyedNetGroup, node->m_prefer_evict, node->addr.IsLocal(),
|
||||||
node->ConnectedThroughNetwork()};
|
node->ConnectedThroughNetwork()};
|
||||||
vEvictionCandidates.push_back(candidate);
|
vEvictionCandidates.push_back(candidate);
|
||||||
}
|
}
|
||||||
|
|
10
src/net.h
10
src/net.h
|
@ -577,6 +577,16 @@ public:
|
||||||
// m_tx_relay == nullptr if we're not relaying transactions with this peer
|
// m_tx_relay == nullptr if we're not relaying transactions with this peer
|
||||||
std::unique_ptr<TxRelay> m_tx_relay;
|
std::unique_ptr<TxRelay> 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
|
/** 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
|
* 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
|
* preliminary validity checks and was saved to disk, even if we don't
|
||||||
|
|
|
@ -2675,6 +2675,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
if (pfrom.m_tx_relay != nullptr) {
|
if (pfrom.m_tx_relay != nullptr) {
|
||||||
LOCK(pfrom.m_tx_relay->cs_filter);
|
LOCK(pfrom.m_tx_relay->cs_filter);
|
||||||
pfrom.m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message
|
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))
|
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);
|
LOCK(pfrom.m_tx_relay->cs_filter);
|
||||||
pfrom.m_tx_relay->pfilter.reset(new CBloomFilter(filter));
|
pfrom.m_tx_relay->pfilter.reset(new CBloomFilter(filter));
|
||||||
|
pfrom.m_bloom_filter_loaded = true;
|
||||||
pfrom.m_tx_relay->fRelayTxes = true;
|
pfrom.m_tx_relay->fRelayTxes = true;
|
||||||
|
pfrom.m_relays_txs = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4037,7 +4040,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
}
|
}
|
||||||
LOCK(pfrom.m_tx_relay->cs_filter);
|
LOCK(pfrom.m_tx_relay->cs_filter);
|
||||||
pfrom.m_tx_relay->pfilter = nullptr;
|
pfrom.m_tx_relay->pfilter = nullptr;
|
||||||
|
pfrom.m_bloom_filter_loaded = false;
|
||||||
pfrom.m_tx_relay->fRelayTxes = true;
|
pfrom.m_tx_relay->fRelayTxes = true;
|
||||||
|
pfrom.m_relays_txs = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue