Skip to content

Commit 9e627b6

Browse files
authored
Merge pull request ElementsProject#1212 from psgreco/master-trim-underflow
Fix underflow when blocks are ahead of headers
2 parents 718ac5b + e7fea1d commit 9e627b6

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
20152015
// the received headers. We can still get ahead by up to a single maximum-sized
20162016
// headers message here, but never further, so that's fine.
20172017
if (pindexBestHeader) {
2018-
uint64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
2018+
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
20192019
bool too_far_ahead = fTrimHeaders && (headers_ahead >= nHeaderDownloadBuffer);
20202020
if (too_far_ahead) {
20212021
LOCK(cs_main);
@@ -4532,7 +4532,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
45324532
if (pindexBestHeader == nullptr)
45334533
pindexBestHeader = m_chainman.ActiveChain().Tip();
45344534
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.
4535-
uint64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
4535+
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
45364536
// ELEMENTS: Only download if our headers aren't "too far ahead" of our blocks.
45374537
bool got_enough_headers = fTrimHeaders && (headers_ahead >= nHeaderDownloadBuffer);
45384538
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && !got_enough_headers) {

src/node/blockstorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool fPruneMode = false;
2727
uint64_t nPruneTarget = 0;
2828
bool fTrimHeaders = false;
2929
uint64_t nMustKeepFullHeaders = std::numeric_limits<uint64_t>::max();
30-
uint64_t nHeaderDownloadBuffer = std::numeric_limits<uint64_t>::max();
30+
int64_t nHeaderDownloadBuffer = std::numeric_limits<int64_t>::max();
3131

3232
// TODO make namespace {
3333
RecursiveMutex cs_LastBlockFile;

src/node/blockstorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern bool fTrimHeaders;
5050
extern uint64_t nMustKeepFullHeaders;
5151
/** Target number of headers to download beyond the blocks we have. */
5252
// NOTE: this currently only operates when in header trim mode, but it's really independent of that.
53-
extern uint64_t nHeaderDownloadBuffer;
53+
extern int64_t nHeaderDownloadBuffer;
5454

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

0 commit comments

Comments
 (0)