Skip to content

Commit

Permalink
Remove useless 2500 limit on AddrMan queries
Browse files Browse the repository at this point in the history
Summary:
bitcoin/bitcoin@7cc0e81
This is a backport of [[bitcoin/bitcoin#18991 | core#18991]] [2/5]

Depends on D10053

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10054
  • Loading branch information
naumenkogs authored and PiRK committed Sep 7, 2021
1 parent 5c9fac9 commit fe421f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CAddrInfo : public CAddress {
#define ADDRMAN_GETADDR_MAX_PCT 23

//! the maximum number of nodes to return in a getaddr call
#define ADDRMAN_GETADDR_MAX 2500
#define ADDRMAN_GETADDR_MAX 1000

//! Convenience
#define ADDRMAN_TRIED_BUCKET_COUNT (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2)
Expand Down
5 changes: 5 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ static const int TIMEOUT_INTERVAL = 20 * 60;
static const int FEELER_INTERVAL = 120;
/** The maximum number of new addresses to accumulate before announcing. */
static const unsigned int MAX_ADDR_TO_SEND = 1000;
// TODO: remove ADDRMAN_GETADDR_MAX and let the caller specify this limit with
// MAX_ADDR_TO_SEND.
static_assert(MAX_ADDR_TO_SEND == ADDRMAN_GETADDR_MAX,
"Max allowed ADDR message size should be equal to the max number "
"of records returned from AddrMan.");
/** Maximum length of the user agent string in `version` message */
static const unsigned int MAX_SUBVERSION_LENGTH = 256;
/**
Expand Down
7 changes: 4 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ void PeerManager::ProcessMessage(const Config &config, CNode &pfrom,
if (!pfrom.RelayAddrsWithConn()) {
return;
}
if (vAddr.size() > 1000) {
if (vAddr.size() > MAX_ADDR_TO_SEND) {
Misbehaving(
pfrom, 20,
strprintf("%s message size = %u", msg_type, vAddr.size()));
Expand Down Expand Up @@ -5193,8 +5193,9 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
if (!pto->m_addr_known->contains(addr.GetKey())) {
pto->m_addr_known->insert(addr.GetKey());
vAddr.push_back(addr);
// receiver rejects addr messages larger than 1000
if (vAddr.size() >= 1000) {
// receiver rejects addr messages larger than
// MAX_ADDR_TO_SEND
if (vAddr.size() >= MAX_ADDR_TO_SEND) {
m_connman.PushMessage(
pto, msgMaker.Make(make_flags, msg_type, vAddr));
vAddr.clear();
Expand Down

0 comments on commit fe421f6

Please sign in to comment.