node, qt: use `1_MiB` for dbcache conversions
What changed, and why it matters
This commit is a tiny code cleanup in Bitcoin Core. It replaces old-style bit-shift math (>> 20) with a clearer named constant (1_MiB) when converting database cache sizes to megabytes. There is no security issue here—just improved readability.
No security action needed. This is a routine refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change replaces >> 20 (divide by 2^20) with / 1_MiB in four locations related to -dbcache handling: argument help text, oversized cache warning, Qt options dialog range, and Qt settings migration. The arithmetic is semantically equivalent for positive values. No functional or security change is introduced.
Changed components
src/init.cppsrc/node/caches.cppsrc/qt/optionsdialog.cppsrc/qt/optionsmodel.cppInspect captured patch +5 / −5
diff --git a/src/init.cpp b/src/init.cpp
index f22302ff..44f06079 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -530,7 +530,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", DEFAULT_DB_CACHE_BATCH), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
- argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, node::GetDefaultDBCache() >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
+ argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE / 1_MiB, node::GetDefaultDBCache() / 1_MiB), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-allowignoredconf", strprintf("For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error.", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-loadblock=<file>", "Imports blocks from an external file on startup. Obfuscated blocks are not supported.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
diff --git a/src/node/caches.cpp b/src/node/caches.cpp
index 7b0223e3..fc13b8a2 100644
--- a/src/node/caches.cpp
+++ b/src/node/caches.cpp
@@ -92,7 +92,7 @@ void LogOversizedDbCache(const ArgsManager& args) noexcept
const uint64_t db_cache{CalculateDbCacheBytes(args)};
if (ShouldWarnOversizedDbCache(db_cache, *total_ram)) {
InitWarning(bilingual_str{tfm::format(_("A %zu MiB dbcache may be too large for a system memory of only %zu MiB."),
- db_cache >> 20, *total_ram >> 20)});
+ db_cache / 1_MiB, *total_ram / 1_MiB)});
}
}
}
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp
index f68e5825..a68829c2 100644
--- a/src/qt/optionsdialog.cpp
+++ b/src/qt/optionsdialog.cpp
@@ -95,7 +95,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
ui->verticalLayout->setStretchFactor(ui->tabWidget, 1);
/* Main elements init */
- ui->databaseCache->setRange(MIN_DB_CACHE >> 20, std::numeric_limits<int>::max());
+ ui->databaseCache->setRange(MIN_DB_CACHE / 1_MiB, std::numeric_limits<int>::max());
ui->threadsScriptVerif->setMinimum(-GetNumCores());
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
ui->pruneWarning->setVisible(false);
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index d52c65d6..49e3c4b8 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -469,7 +469,7 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
suffix.empty() ? getOption(option, "-prev") :
DEFAULT_PRUNE_TARGET_GB;
case DatabaseCache:
- return qlonglong(SettingTo<int64_t>(setting(), node::GetDefaultDBCache() >> 20));
+ return qlonglong(SettingTo<int64_t>(setting(), node::GetDefaultDBCache() / 1_MiB));
case ThreadsScriptVerif:
return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_SCRIPTCHECK_THREADS));
case Listen:
@@ -732,7 +732,7 @@ void OptionsModel::checkAndMigrate()
// see https://github.com/bitcoin/bitcoin/pull/8273
// force people to upgrade to the new value if they are using 100MB
if (settingsVersion < 130000 && settings.contains("nDatabaseCache") && settings.value("nDatabaseCache").toLongLong() == 100)
- settings.setValue("nDatabaseCache", (qint64)(DEFAULT_DB_CACHE >> 20));
+ settings.setValue("nDatabaseCache", qint64(DEFAULT_DB_CACHE / 1_MiB));
settings.setValue(strSettingsVersionKey, CLIENT_VERSION);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.