@@ -696,6 +696,10 @@ class PeerManagerImpl final : public PeerManager
696
696
/* * Send `feefilter` message. */
697
697
void MaybeSendFeefilter (CNode& node, Peer& peer, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
698
698
699
+ FastRandomContext m_rng GUARDED_BY (NetEventsInterface::g_msgproc_mutex);
700
+
701
+ FeeFilterRounder m_fee_filter_rounder GUARDED_BY (NetEventsInterface::g_msgproc_mutex);
702
+
699
703
const CChainParams& m_chainparams;
700
704
CConnman& m_connman;
701
705
AddrMan& m_addrman;
@@ -1053,7 +1057,7 @@ class PeerManagerImpl final : public PeerManager
1053
1057
bool SetupAddressRelay (const CNode& node, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1054
1058
1055
1059
void AddAddressKnown (Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1056
- void PushAddress (Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand ) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1060
+ void PushAddress (Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
1057
1061
};
1058
1062
1059
1063
const CNodeState* PeerManagerImpl::State (NodeId pnode) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -1085,15 +1089,15 @@ void PeerManagerImpl::AddAddressKnown(Peer& peer, const CAddress& addr)
1085
1089
peer.m_addr_known ->insert (addr.GetKey ());
1086
1090
}
1087
1091
1088
- void PeerManagerImpl::PushAddress (Peer& peer, const CAddress& addr, FastRandomContext& insecure_rand )
1092
+ void PeerManagerImpl::PushAddress (Peer& peer, const CAddress& addr)
1089
1093
{
1090
1094
// Known checking here is only to save space from duplicates.
1091
1095
// Before sending, we'll filter it again for known addresses that were
1092
1096
// added after addresses were pushed.
1093
1097
assert (peer.m_addr_known );
1094
1098
if (addr.IsValid () && !peer.m_addr_known ->contains (addr.GetKey ()) && IsAddrCompatible (peer, addr)) {
1095
1099
if (peer.m_addrs_to_send .size () >= MAX_ADDR_TO_SEND) {
1096
- peer.m_addrs_to_send [insecure_rand .randrange (peer.m_addrs_to_send .size ())] = addr;
1100
+ peer.m_addrs_to_send [m_rng .randrange (peer.m_addrs_to_send .size ())] = addr;
1097
1101
} else {
1098
1102
peer.m_addrs_to_send .push_back (addr);
1099
1103
}
@@ -1877,7 +1881,9 @@ std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrm
1877
1881
PeerManagerImpl::PeerManagerImpl (CConnman& connman, AddrMan& addrman,
1878
1882
BanMan* banman, ChainstateManager& chainman,
1879
1883
CTxMemPool& pool, Options opts)
1880
- : m_chainparams(chainman.GetParams()),
1884
+ : m_rng{opts.deterministic_rng },
1885
+ m_fee_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}, m_rng},
1886
+ m_chainparams (chainman.GetParams()),
1881
1887
m_connman(connman),
1882
1888
m_addrman(addrman),
1883
1889
m_banman(banman),
@@ -2183,7 +2189,6 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
2183
2189
const CSipHasher hasher{m_connman.GetDeterministicRandomizer (RANDOMIZER_ID_ADDRESS_RELAY)
2184
2190
.Write (hash_addr)
2185
2191
.Write (time_addr)};
2186
- FastRandomContext insecure_rand;
2187
2192
2188
2193
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
2189
2194
unsigned int nRelayNodes = (fReachable || (hasher.Finalize () & 1 )) ? 2 : 1 ;
@@ -2207,7 +2212,7 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
2207
2212
};
2208
2213
2209
2214
for (unsigned int i = 0 ; i < nRelayNodes && best[i].first != 0 ; i++) {
2210
- PushAddress (*best[i].second , addr, insecure_rand );
2215
+ PushAddress (*best[i].second , addr);
2211
2216
}
2212
2217
}
2213
2218
@@ -3793,7 +3798,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3793
3798
const bool rate_limited = !pfrom.HasPermission (NetPermissionFlags::Addr);
3794
3799
uint64_t num_proc = 0 ;
3795
3800
uint64_t num_rate_limit = 0 ;
3796
- Shuffle (vAddr.begin (), vAddr.end (), FastRandomContext () );
3801
+ Shuffle (vAddr.begin (), vAddr.end (), m_rng );
3797
3802
for (CAddress& addr : vAddr)
3798
3803
{
3799
3804
if (interruptMsgProc)
@@ -4735,9 +4740,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4735
4740
} else {
4736
4741
vAddr = m_connman.GetAddresses (pfrom, MAX_ADDR_TO_SEND, MAX_PCT_ADDR_TO_SEND);
4737
4742
}
4738
- FastRandomContext insecure_rand;
4739
4743
for (const CAddress &addr : vAddr) {
4740
- PushAddress (*peer, addr, insecure_rand );
4744
+ PushAddress (*peer, addr);
4741
4745
}
4742
4746
return ;
4743
4747
}
@@ -5339,8 +5343,7 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
5339
5343
}
5340
5344
if (std::optional<CService> local_service = GetLocalAddrForPeer (node)) {
5341
5345
CAddress local_addr{*local_service, peer.m_our_services , Now<NodeSeconds>()};
5342
- FastRandomContext insecure_rand;
5343
- PushAddress (peer, local_addr, insecure_rand);
5346
+ PushAddress (peer, local_addr);
5344
5347
}
5345
5348
peer.m_next_local_addr_send = GetExponentialRand (current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
5346
5349
}
@@ -5419,22 +5422,21 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
5419
5422
if (pto.IsBlockOnlyConn ()) return ;
5420
5423
5421
5424
CAmount currentFilter = m_mempool.GetMinFee ().GetFeePerK ();
5422
- static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
5423
5425
5424
5426
if (m_chainman.IsInitialBlockDownload ()) {
5425
5427
// Received tx-inv messages are discarded when the active
5426
5428
// chainstate is in IBD, so tell the peer to not send them.
5427
5429
currentFilter = MAX_MONEY;
5428
5430
} else {
5429
- static const CAmount MAX_FILTER{g_filter_rounder .round (MAX_MONEY)};
5431
+ static const CAmount MAX_FILTER{m_fee_filter_rounder .round (MAX_MONEY)};
5430
5432
if (peer.m_fee_filter_sent == MAX_FILTER) {
5431
5433
// Send the current filter if we sent MAX_FILTER previously
5432
5434
// and made it out of IBD.
5433
5435
peer.m_next_send_feefilter = 0us;
5434
5436
}
5435
5437
}
5436
5438
if (current_time > peer.m_next_send_feefilter ) {
5437
- CAmount filterToSend = g_filter_rounder .round (currentFilter);
5439
+ CAmount filterToSend = m_fee_filter_rounder .round (currentFilter);
5438
5440
// We always have a fee filter of at least the min relay fee
5439
5441
filterToSend = std::max (filterToSend, m_mempool.m_min_relay_feerate .GetFeePerK ());
5440
5442
if (filterToSend != peer.m_fee_filter_sent ) {
0 commit comments