@@ -298,6 +298,7 @@ void BlockManager::FindFilesToPrune(
298
298
// Distribute our -prune budget over all chainstates.
299
299
const auto target = std::max (
300
300
MIN_DISK_SPACE_FOR_BLOCK_FILES, GetPruneTarget () / chainman.GetAll ().size ());
301
+ const uint64_t target_sync_height = chainman.m_best_header ->nHeight ;
301
302
302
303
if (chain.m_chain .Height () < 0 || target == 0 ) {
303
304
return ;
@@ -320,10 +321,13 @@ void BlockManager::FindFilesToPrune(
320
321
// On a prune event, the chainstate DB is flushed.
321
322
// To avoid excessive prune events negating the benefit of high dbcache
322
323
// values, we should not prune too rapidly.
323
- // So when pruning in IBD, increase the buffer a bit to avoid a re-prune too soon.
324
- if (chainman.IsInitialBlockDownload ()) {
325
- // Since this is only relevant during IBD, we use a fixed 10%
326
- nBuffer += target / 10 ;
324
+ // So when pruning in IBD, increase the buffer to avoid a re-prune too soon.
325
+ const auto chain_tip_height = chain.m_chain .Height ();
326
+ if (chainman.IsInitialBlockDownload () && target_sync_height > (uint64_t )chain_tip_height) {
327
+ // Since this is only relevant during IBD, we assume blocks are at least 1 MB on average
328
+ static constexpr uint64_t average_block_size = 1000000 ; /* 1 MB */
329
+ const uint64_t remaining_blocks = target_sync_height - chain_tip_height;
330
+ nBuffer += average_block_size * remaining_blocks;
327
331
}
328
332
329
333
for (int fileNumber = 0 ; fileNumber < this ->MaxBlockfileNum (); fileNumber++) {
0 commit comments