Skip to content

Commit 82e9600

Browse files
author
Philip Kaufmann
committed
add constants for shared (GUI/core) -dbcache settings
- adds nDefaultDbCache, nMaxDbCache and nMinDbCache in txdb.h
1 parent 879b390 commit 82e9600

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

src/init.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ std::string HelpMessage(HelpMessageMode hmm)
196196
strUsage += " -testnet " + _("Use the test network") + "\n";
197197
strUsage += " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n";
198198
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
199-
strUsage += " -dbcache=<n> " + _("Set database cache size in megabytes (default: 100)") + "\n";
199+
strUsage += " -dbcache=<n> " + strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache) + "\n";
200200
strUsage += " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n";
201201
strUsage += " -proxy=<ip:port> " + _("Connect through SOCKS proxy") + "\n";
202202
strUsage += " -socks=<n> " + _("Select SOCKS version for -proxy (4 or 5, default: 5)") + "\n";
@@ -776,9 +776,11 @@ bool AppInit2(boost::thread_group& threadGroup)
776776
}
777777

778778
// cache size calculations
779-
size_t nTotalCache = GetArg("-dbcache", 100) << 20;
780-
if (nTotalCache < (1 << 22))
781-
nTotalCache = (1 << 22); // total cache cannot be less than 4 MiB
779+
size_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
780+
if (nTotalCache < (nMinDbCache << 20))
781+
nTotalCache = (nMinDbCache << 20); // total cache cannot be less than nMinDbCache
782+
else if (nTotalCache > (nMaxDbCache << 20))
783+
nTotalCache = (nMaxDbCache << 20); // total cache cannot be greater than nMaxDbCache
782784
size_t nBlockTreeDBCache = nTotalCache / 8;
783785
if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false))
784786
nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB

src/qt/forms/optionsdialog.ui

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,7 @@
5353
</widget>
5454
</item>
5555
<item>
56-
<widget class="QSpinBox" name="databaseCache">
57-
<property name="toolTip">
58-
<string>Set database cache size in megabytes (default: 25)</string>
59-
</property>
60-
<property name="maximum">
61-
<number>1024</number>
62-
</property>
63-
<property name="value">
64-
<number>25</number>
65-
</property>
66-
</widget>
56+
<widget class="QSpinBox" name="databaseCache"/>
6757
</item>
6858
<item>
6959
<widget class="QLabel" name="databaseCacheUnitLabel">

src/qt/optionsdialog.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#include "monitoreddatamapper.h"
1515
#include "optionsmodel.h"
1616

17+
#include "main.h" // for CTransaction::nMinTxFee
1718
#include "netbase.h"
18-
#include "main.h"
19+
#include "txdb.h" // for -dbcache defaults
1920

2021
#include <QDir>
2122
#include <QIntValidator>
@@ -34,7 +35,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
3435
GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this);
3536

3637
/* Main elements init */
37-
ui->databaseCache->setMaximum(sizeof(void*) > 4 ? 4096 : 1024);
38+
ui->databaseCache->setMinimum(nMinDbCache);
39+
ui->databaseCache->setMaximum(nMaxDbCache);
3840

3941
/* Network elements init */
4042
#ifndef USE_UPNP

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "init.h"
1515
#include "main.h"
1616
#include "net.h"
17+
#include "txdb.h" // for -dbcache defaults
1718
#ifdef ENABLE_WALLET
1819
#include "wallet.h"
1920
#include "walletdb.h"
@@ -84,7 +85,7 @@ void OptionsModel::Init()
8485
#endif
8586

8687
if (!settings.contains("nDatabaseCache"))
87-
settings.setValue("nDatabaseCache", 100);
88+
settings.setValue("nDatabaseCache", nDefaultDbCache);
8889
if (!SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
8990
strOverriddenByCommandLine += "-dbcache ";
9091

src/txdb.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class CBigNum;
1818
class CCoins;
1919
class uint256;
2020

21+
// -dbcache default (MiB)
22+
static const int nDefaultDbCache = 100;
23+
// max. -dbcache in (MiB)
24+
static const int nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024;
25+
// min. -dbcache in (MiB)
26+
static const int nMinDbCache = 4;
27+
2128
/** CCoinsView backed by the LevelDB coin database (chainstate/) */
2229
class CCoinsViewDB : public CCoinsView
2330
{

0 commit comments

Comments
 (0)