-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: increase the number of block headers able to be downloaded at once to 8000 in protocol version 70235
#6239
Changes from all commits
993c7c0
bcf0320
e23410f
303bc7a
b137280
07876b2
f6c68ba
b423f42
b224f3f
a6bbaac
cfe99fd
697743d
48c7f98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
P2P and Network Changes | ||
----------------------- | ||
|
||
The max number of compressed block headers which can be requested at once has been increased from 2000 to 8000. This | ||
change activates with the protocol version `70235` and only applies to compressed block headers. | ||
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1038,6 +1038,15 @@ static bool IsLimitedPeer(const Peer& peer) | |||||||
(peer.m_their_services & NODE_NETWORK_LIMITED)); | ||||||||
} | ||||||||
|
||||||||
/** Get maximum number of headers that can be included in one batch */ | ||||||||
static uint16_t GetHeadersLimit(const CNode& pfrom, bool compressed) | ||||||||
{ | ||||||||
if (pfrom.GetCommonVersion() >= INCREASE_MAX_HEADERS2_VERSION && compressed) { | ||||||||
return MAX_HEADERS_COMPRESSED_RESULT; | ||||||||
} | ||||||||
return MAX_HEADERS_UNCOMPRESSED_RESULT; | ||||||||
} | ||||||||
|
||||||||
static void PushInv(Peer& peer, const CInv& inv) | ||||||||
{ | ||||||||
// Dash always initializes m_tx_relay | ||||||||
|
@@ -2952,16 +2961,17 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer, | |||||||
} | ||||||||
|
||||||||
// Consider fetching more headers. | ||||||||
if (nCount == MAX_HEADERS_RESULTS) { | ||||||||
std::string msg_type = UsesCompressedHeaders(peer) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS; | ||||||||
const bool uses_compressed = UsesCompressedHeaders(peer); | ||||||||
const std::string msg_type = uses_compressed ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS; | ||||||||
if (nCount == GetHeadersLimit(pfrom, uses_compressed)) { | ||||||||
// Headers message had its maximum size; the peer may have more headers. | ||||||||
if (MaybeSendGetHeaders(pfrom, msg_type, m_chainman.ActiveChain().GetLocator(pindexLast), peer)) { | ||||||||
LogPrint(BCLog::NET, "more %s (%d) to end to peer=%d (startheight:%d)\n", | ||||||||
msg_type, pindexLast->nHeight, pfrom.GetId(), peer.m_starting_height); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
UpdatePeerStateForReceivedHeaders(pfrom, pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS); | ||||||||
UpdatePeerStateForReceivedHeaders(pfrom, pindexLast, received_new_header, nCount == GetHeadersLimit(pfrom, uses_compressed)); | ||||||||
|
||||||||
// Consider immediately downloading blocks. | ||||||||
HeadersDirectFetchBlocks(pfrom, peer, pindexLast); | ||||||||
|
@@ -4055,8 +4065,8 @@ void PeerManagerImpl::ProcessMessage( | |||||||
pindex = m_chainman.ActiveChain().Next(pindex); | ||||||||
} | ||||||||
|
||||||||
const auto send_headers = [this /* for m_connman */, &hashStop, &pindex, &nodestate, &pfrom, &msgMaker](auto msg_type, auto& v_headers, auto callback) { | ||||||||
int nLimit = MAX_HEADERS_RESULTS; | ||||||||
const auto send_headers = [this /* for m_connman */, &hashStop, &pindex, &nodestate, &pfrom, &msgMaker](auto msg_type_internal, auto& v_headers, auto callback) { | ||||||||
int nLimit = GetHeadersLimit(pfrom, msg_type_internal == NetMsgType::HEADERS2); | ||||||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex)) { | ||||||||
v_headers.push_back(callback(pindex)); | ||||||||
|
||||||||
|
@@ -4076,7 +4086,7 @@ void PeerManagerImpl::ProcessMessage( | |||||||
// will re-announce the new block via headers (or compact blocks again) | ||||||||
// in the SendMessages logic. | ||||||||
nodestate->pindexBestHeaderSent = pindex ? pindex : m_chainman.ActiveChain().Tip(); | ||||||||
m_connman.PushMessage(&pfrom, msgMaker.Make(msg_type, v_headers)); | ||||||||
m_connman.PushMessage(&pfrom, msgMaker.Make(msg_type_internal, v_headers)); | ||||||||
}; | ||||||||
|
||||||||
LogPrint(BCLog::NET, "%s %d to %s from peer=%d\n", msg_type, (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom.GetId()); | ||||||||
|
@@ -4564,7 +4574,7 @@ void PeerManagerImpl::ProcessMessage( | |||||||
|
||||||||
// Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks. | ||||||||
unsigned int nCount = ReadCompactSize(vRecv); | ||||||||
if (nCount > MAX_HEADERS_RESULTS) { | ||||||||
if (nCount > GetHeadersLimit(pfrom, msg_type == NetMsgType::HEADERS2)) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can commit result to variable and reuse it further down, also consider changing misbehavior text to mention headers2 when appropriate due to different limit.
Suggested change
|
||||||||
Misbehaving(pfrom.GetId(), 20, strprintf("headers message size = %u", nCount)); | ||||||||
return; | ||||||||
} | ||||||||
|
@@ -6003,4 +6013,4 @@ bool PeerManagerImpl::SendMessages(CNode* pto) | |||||||
} | ||||||||
} // release cs_main | ||||||||
return true; | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -85,7 +85,8 @@ static const int MAX_SCRIPTCHECK_THREADS = 15; | |||||||||
static const int DEFAULT_SCRIPTCHECK_THREADS = 0; | ||||||||||
/** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends | ||||||||||
* less than this number, we reached its tip. Changing this value is a protocol upgrade. */ | ||||||||||
Comment on lines
86
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||
static const unsigned int MAX_HEADERS_RESULTS = 2000; | ||||||||||
static const unsigned int MAX_HEADERS_UNCOMPRESSED_RESULT = 2000; | ||||||||||
static const unsigned int MAX_HEADERS_COMPRESSED_RESULT = 8000; | ||||||||||
|
||||||||||
static const int64_t DEFAULT_MAX_TIP_AGE = 6 * 60 * 60; // ~144 blocks behind -> 2 x fork detection time, was 24 * 60 * 60 in bitcoin | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ | |||||
*/ | ||||||
|
||||||
|
||||||
static const int PROTOCOL_VERSION = 70234; | ||||||
static const int PROTOCOL_VERSION = 70235; | ||||||
|
||||||
//! initial proto version, to be increased after version/verack negotiation | ||||||
static const int INIT_PROTO_VERSION = 209; | ||||||
|
@@ -58,6 +58,9 @@ static const int NO_LEGACY_ISLOCK_PROTO_VERSION = 70231; | |||||
//! Inventory type for DSQ messages added | ||||||
static const int DSQ_INV_VERSION = 70234; | ||||||
|
||||||
//! Maximum header count for HEADRES2 message was increased from 2000 to 8000 in this version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
static const int INCREASE_MAX_HEADERS2_VERSION = 70235; | ||||||
|
||||||
// Make sure that none of the values above collide with `ADDRV2_FORMAT`. | ||||||
|
||||||
#endif // BITCOIN_VERSION_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: first line already mentions it's compressed-only