From 1ebacb60f8f33d84b1f4894b5307df838d2b1abd Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 21 Mar 2022 15:36:22 +0000 Subject: [PATCH] blockstorage: Add height_last to PruneLockInfo --- src/node/blockstorage.cpp | 12 ++++++++---- src/node/blockstorage.h | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 7464c9054d..810e8469be 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -283,10 +284,13 @@ bool BlockManager::DoPruneLocksForbidPruning(const CBlockFileInfo& block_file_in if (prune_lock.second.height_first == std::numeric_limits::max()) continue; // Remove the buffer and one additional block here to get actual height that is outside of the buffer const unsigned int lock_height{(unsigned)std::max(1, prune_lock.second.height_first - PRUNE_LOCK_BUFFER - 1)}; - if (block_file_info.nHeightLast > lock_height) { - LogPrint(BCLog::PRUNE, "%s limited pruning to height %d\n", prune_lock.first, lock_height); - return true; - } + const unsigned int lock_height_last{(unsigned)std::max(1, SaturatingAdd(prune_lock.second.height_last, PRUNE_LOCK_BUFFER))}; + if (block_file_info.nHeightFirst > lock_height_last) continue; + if (block_file_info.nHeightLast <= lock_height) continue; + // TODO: Check each block within the file against the prune_lock range + + LogPrint(BCLog::PRUNE, "%s limited pruning to height %d\n", prune_lock.first, lock_height); + return true; } return false; } diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 35ba993aba..eacc9c6387 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -93,6 +93,7 @@ struct CBlockIndexHeightOnlyComparator { struct PruneLockInfo { int height_first{std::numeric_limits::max()}; //! Height of earliest block that should be kept and not pruned + int height_last{std::numeric_limits::max()}; //! Height of latest block that should be kept and not pruned }; enum BlockfileType { @@ -253,8 +254,9 @@ private: /** * Map from external index name to oldest block that must not be pruned. * - * @note Internally, only blocks at height (height_first - PRUNE_LOCK_BUFFER - 1) and - * below will be pruned, but callers should avoid assuming any particular buffer size. + * @note Internally, only blocks before height (height_first - PRUNE_LOCK_BUFFER - 1) and + * after height (height_last + PRUNE_LOCK_BUFFER) will be pruned, but callers should + * avoid assuming any particular buffer size. */ std::unordered_map m_prune_locks GUARDED_BY(::cs_main);