mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge #17164: p2p: Avoid allocating memory for addrKnown where we don't need it
b6d2183858Minor refactoring to remove implied m_addr_relay_peer. (User)a552e8477cadded asserts to check m_addr_known when it's used (User)090b75c14bp2p: Avoid allocating memory for addrKnown where we don't need it (User) Pull request description: We should allocate memory for addrKnown filter only for those peers which are expected to participate in address relay. Currently, we do it for all peers (including SPV and block-relay-only), which results in extra RAM where it's not needed. Upd: In future, we would still allow SPVs to ask for addrs, so allocation still will be done by default. However, they will be able to opt-out via [this proposal](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-October/017428.html) and then we could save some more memory. This PR still saves memory for block-relay-only peers immediately after merging. Top commit has no ACKs. Tree-SHA512: e84d93b2615556d466f5ca0e543580fde763911a3bfea3127c493ddfaba8f05c8605cb94ff795d165af542b594400995a2c51338185c298581408687e7812463
This commit is contained in:
11
src/net.h
11
src/net.h
@@ -776,13 +776,12 @@ public:
|
||||
|
||||
// flood relay
|
||||
std::vector<CAddress> vAddrToSend;
|
||||
CRollingBloomFilter addrKnown;
|
||||
const std::unique_ptr<CRollingBloomFilter> m_addr_known;
|
||||
bool fGetAddr{false};
|
||||
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
|
||||
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
|
||||
|
||||
const bool m_addr_relay_peer;
|
||||
bool IsAddrRelayPeer() const { return m_addr_relay_peer; }
|
||||
bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
|
||||
|
||||
// List of block ids we still have announce.
|
||||
// There is no final sorting before sending, as they are always sent immediately
|
||||
@@ -931,7 +930,8 @@ public:
|
||||
|
||||
void AddAddressKnown(const CAddress& _addr)
|
||||
{
|
||||
addrKnown.insert(_addr.GetKey());
|
||||
assert(m_addr_known);
|
||||
m_addr_known->insert(_addr.GetKey());
|
||||
}
|
||||
|
||||
void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
|
||||
@@ -939,7 +939,8 @@ public:
|
||||
// Known checking here is only to save space from duplicates.
|
||||
// SendMessages will filter it again for knowns that were added
|
||||
// after addresses were pushed.
|
||||
if (_addr.IsValid() && !addrKnown.contains(_addr.GetKey())) {
|
||||
assert(m_addr_known);
|
||||
if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey())) {
|
||||
if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
|
||||
vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user