mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
net_processing: Make MAX_HEADERS_RESULTS a PeerManager option
This commit is contained in:
parent
a74bdeea1b
commit
0c02d4b2bd
2 changed files with 11 additions and 9 deletions
|
@ -113,9 +113,6 @@ static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
|
|||
static constexpr auto BLOCK_STALLING_TIMEOUT_DEFAULT{2s};
|
||||
/** Maximum timeout for stalling block download. */
|
||||
static constexpr auto BLOCK_STALLING_TIMEOUT_MAX{64s};
|
||||
/** 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. */
|
||||
static const unsigned int MAX_HEADERS_RESULTS = 2000;
|
||||
/** Maximum depth of blocks we're willing to serve as compact blocks to peers
|
||||
* when requested. For older blocks, a regular BLOCK response will be sent. */
|
||||
static const int MAX_CMPCTBLOCK_DEPTH = 5;
|
||||
|
@ -2786,7 +2783,7 @@ bool PeerManagerImpl::CheckHeadersAreContinuous(const std::vector<CBlockHeader>&
|
|||
bool PeerManagerImpl::IsContinuationOfLowWorkHeadersSync(Peer& peer, CNode& pfrom, std::vector<CBlockHeader>& headers)
|
||||
{
|
||||
if (peer.m_headers_sync) {
|
||||
auto result = peer.m_headers_sync->ProcessNextHeaders(headers, headers.size() == MAX_HEADERS_RESULTS);
|
||||
auto result = peer.m_headers_sync->ProcessNextHeaders(headers, headers.size() == m_opts.max_headers_result);
|
||||
// If it is a valid continuation, we should treat the existing getheaders request as responded to.
|
||||
if (result.success) peer.m_last_getheaders_timestamp = {};
|
||||
if (result.request_more) {
|
||||
|
@ -2880,7 +2877,7 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
|
|||
// Only try to sync with this peer if their headers message was full;
|
||||
// otherwise they don't have more headers after this so no point in
|
||||
// trying to sync their too-little-work chain.
|
||||
if (headers.size() == MAX_HEADERS_RESULTS) {
|
||||
if (headers.size() == m_opts.max_headers_result) {
|
||||
// Note: we could advance to the last header in this set that is
|
||||
// known to us, rather than starting at the first header (which we
|
||||
// may already have); however this is unlikely to matter much since
|
||||
|
@ -3192,7 +3189,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
|
|||
assert(pindexLast);
|
||||
|
||||
// Consider fetching more headers if we are not using our headers-sync mechanism.
|
||||
if (nCount == MAX_HEADERS_RESULTS && !have_headers_sync) {
|
||||
if (nCount == m_opts.max_headers_result && !have_headers_sync) {
|
||||
// Headers message had its maximum size; the peer may have more headers.
|
||||
if (MaybeSendGetHeaders(pfrom, GetLocator(pindexLast), peer)) {
|
||||
LogDebug(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n",
|
||||
|
@ -3200,7 +3197,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
|
|||
}
|
||||
}
|
||||
|
||||
UpdatePeerStateForReceivedHeaders(pfrom, peer, *pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS);
|
||||
UpdatePeerStateForReceivedHeaders(pfrom, peer, *pindexLast, received_new_header, nCount == m_opts.max_headers_result);
|
||||
|
||||
// Consider immediately downloading blocks.
|
||||
HeadersDirectFetchBlocks(pfrom, peer, *pindexLast);
|
||||
|
@ -4518,7 +4515,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
// we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
|
||||
std::vector<CBlock> vHeaders;
|
||||
int nLimit = MAX_HEADERS_RESULTS;
|
||||
int nLimit = m_opts.max_headers_result;
|
||||
LogDebug(BCLog::NET, "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom.GetId());
|
||||
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex))
|
||||
{
|
||||
|
@ -5002,7 +4999,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
// 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 > m_opts.max_headers_result) {
|
||||
Misbehaving(*peer, strprintf("headers message size = %u", nCount));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ static const bool DEFAULT_PEERBLOOMFILTERS = false;
|
|||
static const bool DEFAULT_PEERBLOCKFILTERS = false;
|
||||
/** Maximum number of outstanding CMPCTBLOCK requests for the same block. */
|
||||
static const unsigned int MAX_CMPCTBLOCKS_INFLIGHT_PER_BLOCK = 3;
|
||||
/** 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. */
|
||||
static const unsigned int MAX_HEADERS_RESULTS = 2000;
|
||||
|
||||
struct CNodeStateStats {
|
||||
int nSyncHeight = -1;
|
||||
|
@ -71,6 +74,8 @@ public:
|
|||
//! Whether or not the internal RNG behaves deterministically (this is
|
||||
//! a test-only option).
|
||||
bool deterministic_rng{false};
|
||||
//! Number of headers sent in one getheaders message result.
|
||||
uint32_t max_headers_result{MAX_HEADERS_RESULTS};
|
||||
};
|
||||
|
||||
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
|
||||
|
|
Loading…
Reference in a new issue