aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2021-01-02 01:46:00 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2023-12-27 02:57:30 +0000
commitd298ff8b62b2624ed390c8a2f905c888ffc956ff (patch)
treec916a37f8b583afb17218232a2a65e96eef308ad /src/node
parent96ec3b67a7a7f968d002e13d6fc227f69b7f07d7 (diff)
downloadbitcoin-d298ff8b62b2624ed390c8a2f905c888ffc956ff.tar.xz
During IBD, prune as much as possible until we get close to where we will eventually keep blocks
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 53f616de23..d5cbd9311a 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -298,6 +298,7 @@ void BlockManager::FindFilesToPrune(
// Distribute our -prune budget over all chainstates.
const auto target = std::max(
MIN_DISK_SPACE_FOR_BLOCK_FILES, GetPruneTarget() / chainman.GetAll().size());
+ const uint64_t target_sync_height = chainman.m_best_header->nHeight;
if (chain.m_chain.Height() < 0 || target == 0) {
return;
@@ -320,10 +321,13 @@ void BlockManager::FindFilesToPrune(
// On a prune event, the chainstate DB is flushed.
// To avoid excessive prune events negating the benefit of high dbcache
// values, we should not prune too rapidly.
- // So when pruning in IBD, increase the buffer a bit to avoid a re-prune too soon.
- if (chainman.IsInitialBlockDownload()) {
- // Since this is only relevant during IBD, we use a fixed 10%
- nBuffer += target / 10;
+ // So when pruning in IBD, increase the buffer to avoid a re-prune too soon.
+ const auto chain_tip_height = chain.m_chain.Height();
+ if (chainman.IsInitialBlockDownload() && target_sync_height > (uint64_t)chain_tip_height) {
+ // Since this is only relevant during IBD, we assume blocks are at least 1 MB on average
+ static constexpr uint64_t average_block_size = 1000000; /* 1 MB */
+ const uint64_t remaining_blocks = target_sync_height - chain_tip_height;
+ nBuffer += average_block_size * remaining_blocks;
}
for (int fileNumber = 0; fileNumber < this->MaxBlockfileNum(); fileNumber++) {