Skip to content

Commit

Permalink
[backport#15163] Correct units for "-dbcache" and "-prune"
Browse files Browse the repository at this point in the history
Summary:
6f6514a08090b37b5e8c086015ee4881813ef867 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

---

Backport of Core [[bitcoin/bitcoin#15163 | PR15163]]

Test Plan:
  ninja all check check-functional

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7896
  • Loading branch information
laanwj authored and majcosta committed Oct 12, 2020
1 parent 227c112 commit b94d486
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
17 changes: 8 additions & 9 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,8 @@ void SetupServerArgs() {
OptionsCategory::OPTIONS);
gArgs.AddArg(
"-dbcache=<n>",
strprintf(
"Set database cache size in megabytes (%d to %d, default: %d)",
nMinDbCache, nMaxDbCache, nDefaultDbCache),
strprintf("Set database cache size in MiB (%d to %d, default: %d)",
nMinDbCache, nMaxDbCache, nDefaultDbCache),
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-debuglogfile=<file>",
strprintf("Specify location of debug log file. Relative paths "
Expand Down Expand Up @@ -1854,8 +1853,8 @@ bool AppInitParameterInteraction(Config &config) {
.translated,
MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
}
LogPrintf("Prune configured to target %uMiB on disk for block and undo "
"files.\n",
LogPrintf("Prune configured to target %u MiB on disk for block and "
"undo files.\n",
nPruneTarget / 1024 / 1024);
fPruneMode = true;
}
Expand Down Expand Up @@ -2363,20 +2362,20 @@ bool AppInitMain(Config &config, RPCServer &rpcServer,
int64_t nMempoolSizeMax =
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
LogPrintf("Cache configuration:\n");
LogPrintf("* Using %.1fMiB for block index database\n",
LogPrintf("* Using %.1f MiB for block index database\n",
nBlockTreeDBCache * (1.0 / 1024 / 1024));
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
LogPrintf("* Using %.1fMiB for transaction index database\n",
LogPrintf("* Using %.1f MiB for transaction index database\n",
nTxIndexCache * (1.0 / 1024 / 1024));
}
for (BlockFilterType filter_type : g_enabled_filter_types) {
LogPrintf("* Using %.1f MiB for %s block filter index database\n",
filter_index_cache * (1.0 / 1024 / 1024),
BlockFilterTypeName(filter_type));
}
LogPrintf("* Using %.1fMiB for chain state database\n",
LogPrintf("* Using %.1f MiB for chain state database\n",
nCoinDBCache * (1.0 / 1024 / 1024));
LogPrintf("* Using %.1fMiB for in-memory UTXO set (plus up to %.1fMiB of "
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));
Expand Down
2 changes: 1 addition & 1 deletion src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<item>
<widget class="QLabel" name="databaseCacheUnitLabel">
<property name="text">
<string>MB</string>
<string>MiB</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80;
#define QAPP_APP_NAME_TESTNET "BitcoinABC-Qt-testnet"
#define QAPP_APP_NAME_REGTEST "BitcoinABC-Qt-regtest"

/* One gigabyte (GB) in bytes */
static constexpr uint64_t GB_BYTES{1'000'000'000};

#endif // BITCOIN_QT_GUICONSTANTS_H
2 changes: 1 addition & 1 deletion src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fs.h>
#include <interfaces/node.h>
#include <qt/forms/ui_intro.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/intro.h>
#include <util/system.h>
Expand All @@ -19,7 +20,6 @@

#include <cmath>

static const uint64_t GB_BYTES = 1000000000LL;
/**
* Total required space (in GB) depending on user choice (prune, not prune).
*/
Expand Down
17 changes: 10 additions & 7 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <interfaces/node.h>
#include <netbase.h>
#include <qt/bitcoinunits.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <txdb.h> // for -dbcache defaults
Expand All @@ -33,13 +34,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet)
/* Main elements init */
ui->databaseCache->setMinimum(nMinDbCache);
ui->databaseCache->setMaximum(nMaxDbCache);
static const uint64_t GiB = 1024 * 1024 * 1024;
static const uint64_t nMinDiskSpace =
MIN_DISK_SPACE_FOR_BLOCK_FILES / GiB +
(MIN_DISK_SPACE_FOR_BLOCK_FILES % GiB)
? 1
: 0;
ui->pruneSize->setMinimum(nMinDiskSpace);
ui->threadsScriptVerif->setMinimum(-GetNumCores());
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
ui->pruneWarning->setVisible(false);
Expand Down Expand Up @@ -178,6 +172,15 @@ void OptionsDialog::setModel(OptionsModel *_model) {
mapper->toFirst();

updateDefaultProxyNets();

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

/* warn when one of the following settings changes by user action (placed
Expand Down
8 changes: 5 additions & 3 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <net.h>
#include <netbase.h>
#include <qt/bitcoinunits.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/intro.h>
#include <txdb.h> // for -dbcache defaults
Expand Down Expand Up @@ -103,10 +104,11 @@ void OptionsModel::Init(bool resetSettings) {
if (!settings.contains("nPruneSize")) {
settings.setValue("nPruneSize", 2);
}
// Convert prune size to MB:
const uint64_t nPruneSizeMB = settings.value("nPruneSize").toInt() * 1000;
// Convert prune size from GB to MiB:
const uint64_t nPruneSizeMiB =
(settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool()
? std::to_string(nPruneSizeMB)
? std::to_string(nPruneSizeMiB)
: "0")) {
addOverriddenOption("-prune");
}
Expand Down
9 changes: 5 additions & 4 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,17 @@ static const signed int DEFAULT_CHECKBLOCKS = 6;
static const unsigned int DEFAULT_CHECKLEVEL = 3;

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

Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def has_block(index):
assert not has_block(
3), "blk00003.dat is still there, should be pruned by now"

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

0 comments on commit b94d486

Please sign in to comment.