Skip to content

Commit 6f6514a

Browse files
committed
Correct units for "-dbcache" and "-prune"
All dbcache-related values in the code are measured in MiB (not in megabytes, MB) or in bytes. The GUI "-prune" values in GB are translated to the node values in MiB correctly. The maximum of the "-prune" QSpinBox is not limited by the default value of 99 (GB). Also, this improves log readability.
1 parent 84d0fdc commit 6f6514a

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
@@ -346,7 +346,7 @@ void SetupServerArgs()
346346
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
347347
gArgs.AddArg("-datadir=<dir>", "Specify data directory", false, OptionsCategory::OPTIONS);
348348
gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), true, OptionsCategory::OPTIONS);
349-
gArgs.AddArg("-dbcache=<n>", strprintf("Set database cache size in megabytes (%d to %d, default: %d)", nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
349+
gArgs.AddArg("-dbcache=<n>", strprintf("Set database cache size in MiB (%d to %d, default: %d)", nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
350350
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);
351351
gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), true, OptionsCategory::OPTIONS);
352352
gArgs.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", false, OptionsCategory::OPTIONS);
@@ -1055,7 +1055,7 @@ bool AppInitParameterInteraction()
10551055
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
10561056
return InitError(strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
10571057
}
1058-
LogPrintf("Prune configured to target %uMiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
1058+
LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
10591059
fPruneMode = true;
10601060
}
10611061

@@ -1416,12 +1416,12 @@ bool AppInitMain(InitInterfaces& interfaces)
14161416
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
14171417
int64_t nMempoolSizeMax = gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
14181418
LogPrintf("Cache configuration:\n");
1419-
LogPrintf("* Using %.1fMiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
1419+
LogPrintf("* Using %.1f MiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
14201420
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1421-
LogPrintf("* Using %.1fMiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
1421+
LogPrintf("* Using %.1f MiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
14221422
}
1423-
LogPrintf("* Using %.1fMiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
1424-
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));
1423+
LogPrintf("* Using %.1f MiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
1424+
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));
14251425

14261426
bool fLoaded = false;
14271427
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);
@@ -161,6 +158,10 @@ void OptionsDialog::setModel(OptionsModel *_model)
161158
mapper->toFirst();
162159

163160
updateDefaultProxyNets();
161+
162+
// Prune values are in GB to be consistent with intro.cpp
163+
static constexpr uint64_t nMinDiskSpace = (MIN_DISK_SPACE_FOR_BLOCK_FILES / GB_BYTES) + (MIN_DISK_SPACE_FOR_BLOCK_FILES % GB_BYTES) ? 1 : 0;
164+
ui->pruneSize->setRange(nMinDiskSpace, _model->node().getAssumedBlockchainSize());
164165
}
165166

166167
/* 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)