Skip to content
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

Fix underflow when blocks are ahead of headers #1212

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
// the received headers. We can still get ahead by up to a single maximum-sized
// headers message here, but never further, so that's fine.
if (pindexBestHeader) {
uint64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
bool too_far_ahead = fTrimHeaders && (headers_ahead >= nHeaderDownloadBuffer);
if (too_far_ahead) {
LOCK(cs_main);
Expand Down Expand Up @@ -4532,7 +4532,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
if (pindexBestHeader == nullptr)
pindexBestHeader = m_chainman.ActiveChain().Tip();
bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
uint64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
// ELEMENTS: Only download if our headers aren't "too far ahead" of our blocks.
bool got_enough_headers = fTrimHeaders && (headers_ahead >= nHeaderDownloadBuffer);
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && !got_enough_headers) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool fPruneMode = false;
uint64_t nPruneTarget = 0;
bool fTrimHeaders = false;
uint64_t nMustKeepFullHeaders = std::numeric_limits<uint64_t>::max();
uint64_t nHeaderDownloadBuffer = std::numeric_limits<uint64_t>::max();
int64_t nHeaderDownloadBuffer = std::numeric_limits<int64_t>::max();

// TODO make namespace {
RecursiveMutex cs_LastBlockFile;
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern bool fTrimHeaders;
extern uint64_t nMustKeepFullHeaders;
/** Target number of headers to download beyond the blocks we have. */
// NOTE: this currently only operates when in header trim mode, but it's really independent of that.
extern uint64_t nHeaderDownloadBuffer;
extern int64_t nHeaderDownloadBuffer;

//! Check whether the block associated with this index entry is pruned or not.
bool IsBlockPruned(const CBlockIndex* pblockindex);
Expand Down