diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -438,13 +438,13 @@ gArgs.AddArg( "-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", - nDefaultDbBatchSize), + DEFAULT_DB_BATCH_SIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg( "-dbcache=", strprintf("Set database cache size in MiB (%d to %d, default: %d)", - nMinDbCache, nMaxDbCache, nDefaultDbCache), + MIN_DB_CACHE_MB, MAX_DB_CACHE_MB, DEFAULT_DB_CACHE_MB), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-debuglogfile=", strprintf("Specify location of debug log file. Relative paths " @@ -2349,24 +2349,24 @@ bool fReindexChainState = gArgs.GetBoolArg("-reindex-chainstate", false); // cache size calculations - int64_t nTotalCache = (gArgs.GetArg("-dbcache", nDefaultDbCache) << 20); - // total cache cannot be less than nMinDbCache - nTotalCache = std::max(nTotalCache, nMinDbCache << 20); - // total cache cannot be greater than nMaxDbcache - nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); + int64_t nTotalCache = (gArgs.GetArg("-dbcache", DEFAULT_DB_CACHE_MB) << 20); + // total cache cannot be less than MIN_DB_CACHE_MB + nTotalCache = std::max(nTotalCache, MIN_DB_CACHE_MB << 20); + // total cache cannot be greater than MAX_DB_CACHE_MB + nTotalCache = std::min(nTotalCache, MAX_DB_CACHE_MB << 20); int64_t nBlockTreeDBCache = - std::min(nTotalCache / 8, nMaxBlockDBCache << 20); + std::min(nTotalCache / 8, MAX_BLOCK_DB_CACHE_MB << 20); nTotalCache -= nBlockTreeDBCache; int64_t nTxIndexCache = std::min(nTotalCache / 8, gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX) - ? nMaxTxIndexCache << 20 + ? MAX_TX_INDEX_CACHE_MB << 20 : 0); nTotalCache -= nTxIndexCache; int64_t filter_index_cache = 0; if (!g_enabled_filter_types.empty()) { size_t n_indexes = g_enabled_filter_types.size(); int64_t max_cache = - std::min(nTotalCache / 8, max_filter_index_cache << 20); + std::min(nTotalCache / 8, MAX_FILTER_INDEX_CACHE_MB << 20); filter_index_cache = max_cache / n_indexes; nTotalCache -= filter_index_cache * n_indexes; } @@ -2374,7 +2374,7 @@ int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // cap total coins db cache - nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); + nCoinDBCache = std::min(nCoinDBCache, MAX_COINS_DB_CACHE_MB << 20); nTotalCache -= nCoinDBCache; // the rest goes to in-memory cache nCoinCacheUsage = nTotalCache; diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -32,8 +32,8 @@ ui->setupUi(this); /* Main elements init */ - ui->databaseCache->setMinimum(nMinDbCache); - ui->databaseCache->setMaximum(nMaxDbCache); + ui->databaseCache->setMinimum(MIN_DB_CACHE_MB); + ui->databaseCache->setMaximum(MAX_DB_CACHE_MB); 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 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -107,7 +107,7 @@ SetPrune(settings.value("bPrune").toBool()); if (!settings.contains("nDatabaseCache")) { - settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache); + settings.setValue("nDatabaseCache", (qint64)DEFAULT_DB_CACHE_MB); } if (!m_node.softSetArg( "-dbcache", @@ -565,7 +565,7 @@ // 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)nDefaultDbCache); + settings.setValue("nDatabaseCache", (qint64)DEFAULT_DB_CACHE_MB); } settings.setValue(strSettingsVersionKey, CLIENT_VERSION); diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -27,25 +27,25 @@ //! No need to periodic flush if at least this much space still available. static constexpr int MAX_BLOCK_COINSDB_USAGE = 10; +//! min. -dbcache (MiB) +static constexpr int64_t MIN_DB_CACHE_MB = 4; +//! max. -dbcache (MiB) +static constexpr int64_t MAX_DB_CACHE_MB = sizeof(void *) > 4 ? 16384 : 1024; //! -dbcache default (MiB) -static const int64_t nDefaultDbCache = 450; +static constexpr int64_t DEFAULT_DB_CACHE_MB = 1024; //! -dbbatchsize default (bytes) -static const int64_t nDefaultDbBatchSize = 16 << 20; -//! max. -dbcache (MiB) -static const int64_t nMaxDbCache = sizeof(void *) > 4 ? 16384 : 1024; -//! min. -dbcache (MiB) -static const int64_t nMinDbCache = 4; +static constexpr int64_t DEFAULT_DB_BATCH_SIZE = 16 << 20; //! Max memory allocated to block tree DB specific cache, if no -txindex (MiB) -static const int64_t nMaxBlockDBCache = 2; +static constexpr int64_t MAX_BLOCK_DB_CACHE_MB = 2; //! Max memory allocated to block tree DB specific cache, if -txindex (MiB) // Unlike for the UTXO database, for the txindex scenario the leveldb cache make // a meaningful difference: // https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991 -static const int64_t nMaxTxIndexCache = 1024; +static constexpr int64_t MAX_TX_INDEX_CACHE_MB = 1024; //! Max memory allocated to all block filter index caches combined in MiB. -static const int64_t max_filter_index_cache = 1024; +static constexpr int64_t MAX_FILTER_INDEX_CACHE_MB = 1024; //! Max memory allocated to coin DB specific cache (MiB) -static const int64_t nMaxCoinsDBCache = 8; +static constexpr int64_t MAX_COINS_DB_CACHE_MB = 8; /** CCoinsView backed by the coin database (chainstate/) */ class CCoinsViewDB final : public CCoinsView { diff --git a/src/txdb.cpp b/src/txdb.cpp --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -87,7 +87,7 @@ size_t count = 0; size_t changed = 0; size_t batch_size = - (size_t)gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize); + (size_t)gArgs.GetArg("-dbbatchsize", DEFAULT_DB_BATCH_SIZE); int crash_simulate = gArgs.GetArg("-dbcrashratio", 0); assert(!hashBlock.IsNull());