Skip to content

Commit 77339e5

Browse files
committed
Merge #15163: Correct units for "-dbcache" and "-prune"
6f6514a Correct units for "-dbcache" and "-prune" (Hennadii Stepanov) Pull request description: Actually, all `dbcache`-related values in the code are measured in MiB (not in megabytes, MB) or in bytes (e.g., `nTotalCache`). See: https://github.com/bitcoin/bitcoin/blob/master/src/txdb.h https://github.com/bitcoin/bitcoin/blob/ba8c8b22272ad40fe2de465d7e745532bab48d3b/src/init.cpp#L1405-L1424 Also, "-prune" is fixed: 1. The GUI values in GB are translated to the node values in MiB correctly. 2. The maximum of the "prune" `QSpinBox` is not limited by default value of 99 (GB). Fix: #15106 Tree-SHA512: 151ec43b31b1074db8b345fedb1dcc10bde225899a5296bfc183f57e1553d13ac27db8db100226646769ad03c9fcab29d88763065a471757c6c41ac51108459d
2 parents 04226f8 + 6f6514a commit 77339e5

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

src/init.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void SetupServerArgs()
352352
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
353353
gArgs.AddArg("-datadir=<dir>", "Specify data directory", false, OptionsCategory::OPTIONS);
354354
gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), true, OptionsCategory::OPTIONS);
355-
gArgs.AddArg("-dbcache=<n>", strprintf("Set database cache size in megabytes (%d to %d, default: %d)", nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
355+
gArgs.AddArg("-dbcache=<n>", strprintf("Set database cache size in MiB (%d to %d, default: %d)", nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
356356
gArgs.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), false, OptionsCategory::OPTIONS);
357357
gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), true, OptionsCategory::OPTIONS);
358358
gArgs.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", false, OptionsCategory::OPTIONS);
@@ -1061,7 +1061,7 @@ bool AppInitParameterInteraction()
10611061
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
10621062
return InitError(strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
10631063
}
1064-
LogPrintf("Prune configured to target %uMiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
1064+
LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
10651065
fPruneMode = true;
10661066
}
10671067

@@ -1423,12 +1423,12 @@ bool AppInitMain(InitInterfaces& interfaces)
14231423
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
14241424
int64_t nMempoolSizeMax = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
14251425
LogPrintf("Cache configuration:\n");
1426-
LogPrintf("* Using %.1fMiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
1426+
LogPrintf("* Using %.1f MiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
14271427
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1428-
LogPrintf("* Using %.1fMiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
1428+
LogPrintf("* Using %.1f MiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
14291429
}
1430-
LogPrintf("* Using %.1fMiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
1431-
LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
1430+
LogPrintf("* Using %.1f MiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
1431+
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
14321432

14331433
bool fLoaded = false;
14341434
while (!fLoaded && !ShutdownRequested()) {

src/qt/forms/optionsdialog.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<item>
122122
<widget class="QLabel" name="databaseCacheUnitLabel">
123123
<property name="text">
124-
<string>MB</string>
124+
<string>MiB</string>
125125
</property>
126126
<property name="textFormat">
127127
<enum>Qt::PlainText</enum>

src/qt/guiconstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ static const int MAX_URI_LENGTH = 255;
5252
#define QAPP_APP_NAME_TESTNET "Bitcoin-Qt-testnet"
5353
#define QAPP_APP_NAME_REGTEST "Bitcoin-Qt-regtest"
5454

55+
/* One gigabyte (GB) in bytes */
56+
static constexpr uint64_t GB_BYTES{1000000000};
57+
5558
#endif // BITCOIN_QT_GUICONSTANTS_H

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qt/intro.h>
1111
#include <qt/forms/ui_intro.h>
1212

13+
#include <qt/guiconstants.h>
1314
#include <qt/guiutil.h>
1415

1516
#include <interfaces/node.h>
@@ -21,7 +22,6 @@
2122

2223
#include <cmath>
2324

24-
static const uint64_t GB_BYTES = 1000000000LL;
2525
/* Total required space (in GB) depending on user choice (prune, not prune) */
2626
static uint64_t requiredSpace;
2727

src/qt/optionsdialog.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qt/forms/ui_optionsdialog.h>
1111

1212
#include <qt/bitcoinunits.h>
13+
#include <qt/guiconstants.h>
1314
#include <qt/guiutil.h>
1415
#include <qt/optionsmodel.h>
1516

@@ -37,10 +38,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
3738
/* Main elements init */
3839
ui->databaseCache->setMinimum(nMinDbCache);
3940
ui->databaseCache->setMaximum(nMaxDbCache);
40-
static const uint64_t GiB = 1024 * 1024 * 1024;
41-
static const uint64_t nMinDiskSpace = MIN_DISK_SPACE_FOR_BLOCK_FILES / GiB +
42-
(MIN_DISK_SPACE_FOR_BLOCK_FILES % GiB) ? 1 : 0;
43-
ui->pruneSize->setMinimum(nMinDiskSpace);
4441
ui->threadsScriptVerif->setMinimum(-GetNumCores());
4542
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
4643
ui->pruneWarning->setVisible(false);
@@ -167,6 +164,10 @@ void OptionsDialog::setModel(OptionsModel *_model)
167164
mapper->toFirst();
168165

169166
updateDefaultProxyNets();
167+
168+
// Prune values are in GB to be consistent with intro.cpp
169+
static constexpr uint64_t nMinDiskSpace = (MIN_DISK_SPACE_FOR_BLOCK_FILES / GB_BYTES) + (MIN_DISK_SPACE_FOR_BLOCK_FILES % GB_BYTES) ? 1 : 0;
170+
ui->pruneSize->setRange(nMinDiskSpace, _model->node().getAssumedBlockchainSize());
170171
}
171172

172173
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */

src/qt/optionsmodel.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <qt/optionsmodel.h>
1010

1111
#include <qt/bitcoinunits.h>
12+
#include <qt/guiconstants.h>
1213
#include <qt/guiutil.h>
1314

1415
#include <interfaces/node.h>
@@ -92,10 +93,10 @@ void OptionsModel::Init(bool resetSettings)
9293
settings.setValue("bPrune", false);
9394
if (!settings.contains("nPruneSize"))
9495
settings.setValue("nPruneSize", 2);
95-
// Convert prune size to MB:
96-
const uint64_t nPruneSizeMB = settings.value("nPruneSize").toInt() * 1000;
97-
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMB) : "0")) {
98-
addOverriddenOption("-prune");
96+
// Convert prune size from GB to MiB:
97+
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
98+
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMiB) : "0")) {
99+
addOverriddenOption("-prune");
99100
}
100101

101102
if (!settings.contains("nDatabaseCache"))

src/validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
201201
static const signed int DEFAULT_CHECKBLOCKS = 6;
202202
static const unsigned int DEFAULT_CHECKLEVEL = 3;
203203

204-
// Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
204+
// Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
205205
// At 1MB per block, 288 blocks = 288MB.
206206
// Add 15% for Undo data = 331MB
207207
// Add 20% for Orphan block rate = 397MB
208208
// We want the low water mark after pruning to be at least 397 MB and since we prune in
209209
// full block file chunks, we need the high water mark which triggers the prune to be
210210
// one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
211-
// Setting the target to > than 550MB will make it likely we can respect the target.
211+
// Setting the target to >= 550 MiB will make it likely we can respect the target.
212212
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
213213

214214
/**

test/functional/feature_pruning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def has_block(index):
320320
if has_block(3):
321321
raise AssertionError("blk00003.dat is still there, should be pruned by now")
322322

323-
# stop node, start back up with auto-prune at 550MB, make sure still runs
323+
# stop node, start back up with auto-prune at 550 MiB, make sure still runs
324324
self.stop_node(node_number)
325325
self.start_node(node_number, extra_args=["-prune=550"])
326326

0 commit comments

Comments
 (0)