From 82e96006ae03a7debebb9ad36f939ddabb0d2f9f Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sun, 16 Feb 2014 22:00:12 +0100 Subject: [PATCH] add constants for shared (GUI/core) -dbcache settings - adds nDefaultDbCache, nMaxDbCache and nMinDbCache in txdb.h --- src/init.cpp | 10 ++++++---- src/qt/forms/optionsdialog.ui | 12 +----------- src/qt/optionsdialog.cpp | 6 ++++-- src/qt/optionsmodel.cpp | 3 ++- src/txdb.h | 7 +++++++ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 787c72e15..c05ed4356 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -196,7 +196,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -testnet " + _("Use the test network") + "\n"; strUsage += " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n"; strUsage += " -gen " + _("Generate coins (default: 0)") + "\n"; - strUsage += " -dbcache= " + _("Set database cache size in megabytes (default: 100)") + "\n"; + strUsage += " -dbcache= " + strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache) + "\n"; strUsage += " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n"; strUsage += " -proxy= " + _("Connect through SOCKS proxy") + "\n"; strUsage += " -socks= " + _("Select SOCKS version for -proxy (4 or 5, default: 5)") + "\n"; @@ -776,9 +776,11 @@ bool AppInit2(boost::thread_group& threadGroup) } // cache size calculations - size_t nTotalCache = GetArg("-dbcache", 100) << 20; - if (nTotalCache < (1 << 22)) - nTotalCache = (1 << 22); // total cache cannot be less than 4 MiB + size_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20); + if (nTotalCache < (nMinDbCache << 20)) + nTotalCache = (nMinDbCache << 20); // total cache cannot be less than nMinDbCache + else if (nTotalCache > (nMaxDbCache << 20)) + nTotalCache = (nMaxDbCache << 20); // total cache cannot be greater than nMaxDbCache size_t nBlockTreeDBCache = nTotalCache / 8; if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false)) nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index b4a9f1f58..a0626f989 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -53,17 +53,7 @@ - - - Set database cache size in megabytes (default: 25) - - - 1024 - - - 25 - - + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index f4eb7ef07..e31542961 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -14,8 +14,9 @@ #include "monitoreddatamapper.h" #include "optionsmodel.h" +#include "main.h" // for CTransaction::nMinTxFee #include "netbase.h" -#include "main.h" +#include "txdb.h" // for -dbcache defaults #include #include @@ -34,7 +35,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) : GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this); /* Main elements init */ - ui->databaseCache->setMaximum(sizeof(void*) > 4 ? 4096 : 1024); + ui->databaseCache->setMinimum(nMinDbCache); + ui->databaseCache->setMaximum(nMaxDbCache); /* Network elements init */ #ifndef USE_UPNP diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index e0c478872..1a460b927 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -14,6 +14,7 @@ #include "init.h" #include "main.h" #include "net.h" +#include "txdb.h" // for -dbcache defaults #ifdef ENABLE_WALLET #include "wallet.h" #include "walletdb.h" @@ -84,7 +85,7 @@ void OptionsModel::Init() #endif if (!settings.contains("nDatabaseCache")) - settings.setValue("nDatabaseCache", 100); + settings.setValue("nDatabaseCache", nDefaultDbCache); if (!SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString())) strOverriddenByCommandLine += "-dbcache "; diff --git a/src/txdb.h b/src/txdb.h index 7ce6585d3..0512396e9 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -18,6 +18,13 @@ class CBigNum; class CCoins; class uint256; +// -dbcache default (MiB) +static const int nDefaultDbCache = 100; +// max. -dbcache in (MiB) +static const int nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024; +// min. -dbcache in (MiB) +static const int nMinDbCache = 4; + /** CCoinsView backed by the LevelDB coin database (chainstate/) */ class CCoinsViewDB : public CCoinsView {