Qt: Add prune setting to OptionsDialog

Make default prune size 3GB

Use GiB and MiB

Add DEFAULT_PRUNE_TARGET_GB

PruneMiBtoGB & PruneGBtoMiB
This commit is contained in:
alamshafil 2022-04-14 18:16:07 -04:00
parent 0e02aea03a
commit 71f5e6c488
6 changed files with 128 additions and 0 deletions

View File

@ -37,6 +37,69 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_0_Main">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_Main_Prune">
<item>
<widget class="QCheckBox" name="prune">
<property name="toolTip">
<string>Disables some advanced features but all blocks will still be fully validated. Reverting this setting requires re-downloading the entire blockchain. Actual disk usage may be somewhat higher.</string>
</property>
<property name="text">
<string>Prune &amp;block storage to</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="pruneSize"/>
</item>
<item>
<widget class="QLabel" name="pruneSizeUnitLabel">
<property name="text">
<string>GB</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_Main_Prune">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="pruneWarning">
<property name="text">
<string>Reverting this setting requires re-downloading the entire blockchain.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2_Main">
<item>

View File

@ -5,6 +5,8 @@
#ifndef BITCOIN_QT_GUICONSTANTS_H
#define BITCOIN_QT_GUICONSTANTS_H
#include "validation.h"
/* Milliseconds between model updates */
static const int MODEL_UPDATE_DELAY = 250;
@ -53,4 +55,20 @@ static const int MAX_URI_LENGTH = 255;
#define QAPP_APP_NAME_DEFAULT "Dogecoin-Qt"
#define QAPP_APP_NAME_TESTNET "Dogecoin-Qt-testnet"
/* One gigabyte (GB) in bytes */
static constexpr uint64_t GB_BYTES{1000000000};
/**
* Convert configured prune target bytes to displayed GB. Round up to avoid underestimating max disk usage.
*/
constexpr inline int PruneBytestoGB(uint64_t bytes) { return (bytes + GB_BYTES - 1) / GB_BYTES; }
/**
* Convert displayed prune target GB to configured MiB. Round down so roundtrip GB -> MiB -> GB conversion is stable.
*/
constexpr inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
// Default prune target displayed in GUI.
static constexpr int DEFAULT_PRUNE_TARGET_GB{PruneBytestoGB(MIN_DISK_SPACE_FOR_BLOCK_FILES)};
#endif // BITCOIN_QT_GUICONSTANTS_H

View File

@ -10,6 +10,7 @@
#include "ui_optionsdialog.h"
#include "bitcoinunits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
@ -41,8 +42,14 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
/* Main elements init */
ui->databaseCache->setMinimum(nMinDbCache);
ui->databaseCache->setMaximum(nMaxDbCache);
ui->pruneSize->setMinimum(DEFAULT_PRUNE_TARGET_GB);
ui->threadsScriptVerif->setMinimum(-GetNumCores());
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
ui->pruneWarning->setVisible(false);
ui->pruneWarning->setStyleSheet("QLabel { color: red; }");
ui->pruneSize->setEnabled(false);
connect(ui->prune, SIGNAL(toggled(bool)), ui->pruneSize, SLOT(setEnabled(bool)));
/* Network elements init */
#ifndef USE_UPNP
@ -160,6 +167,9 @@ void OptionsDialog::setModel(OptionsModel *_model)
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
/* Main */
connect(ui->prune, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->prune, SIGNAL(clicked(bool)), this, SLOT(togglePruneWarning(bool)));
connect(ui->pruneSize, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
connect(ui->databaseCache, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
connect(ui->threadsScriptVerif, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
/* Wallet */
@ -179,6 +189,8 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
mapper->addMapping(ui->threadsScriptVerif, OptionsModel::ThreadsScriptVerif);
mapper->addMapping(ui->databaseCache, OptionsModel::DatabaseCache);
mapper->addMapping(ui->prune, OptionsModel::Prune);
mapper->addMapping(ui->pruneSize, OptionsModel::PruneSize);
/* Wallet */
mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange);
@ -257,6 +269,11 @@ void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
}
}
void OptionsDialog::togglePruneWarning(bool enabled)
{
ui->pruneWarning->setVisible(!ui->pruneWarning->isVisible());
}
void OptionsDialog::showRestartWarning(bool fPersistent)
{
ui->statusLabel->setStyleSheet("QLabel { color: red; }");

View File

@ -52,6 +52,7 @@ private Q_SLOTS:
void on_hideTrayIcon_stateChanged(int fState);
void togglePruneWarning(bool enabled);
void showRestartWarning(bool fPersistent = false);
void clearStatusLabel();
void updateProxyValidationState();

View File

@ -9,6 +9,7 @@
#include "optionsmodel.h"
#include "bitcoinunits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "amount.h"
@ -90,6 +91,16 @@ void OptionsModel::Init(bool resetSettings)
// by command-line and show this in the UI.
// Main
if (!settings.contains("bPrune"))
settings.setValue("bPrune", false);
if (!settings.contains("nPruneSize"))
settings.setValue("nPruneSize", DEFAULT_PRUNE_TARGET_GB);
// Convert prune size to MiB:
const uint64_t nPruneSizeMiB = PruneGBtoMiB(settings.value("nPruneSize").toInt());
if (!SoftSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMiB) : "0")) {
addOverriddenOption("-prune");
}
if (!settings.contains("nDatabaseCache"))
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
if (!SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
@ -241,6 +252,10 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("language");
case CoinControlFeatures:
return fCoinControlFeatures;
case Prune:
return settings.value("bPrune");
case PruneSize:
return settings.value("nPruneSize");
case DatabaseCache:
return settings.value("nDatabaseCache");
case ThreadsScriptVerif:
@ -377,6 +392,18 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
Q_EMIT coinControlFeaturesChanged(fCoinControlFeatures);
break;
case Prune:
if (settings.value("bPrune") != value) {
settings.setValue("bPrune", value);
setRestartRequired(true);
}
break;
case PruneSize:
if (settings.value("nPruneSize") != value) {
settings.setValue("nPruneSize", value);
setRestartRequired(true);
}
break;
case DatabaseCache:
if (settings.value("nDatabaseCache") != value) {
settings.setValue("nDatabaseCache", value);

View File

@ -43,6 +43,8 @@ public:
Language, // QString
CoinControlFeatures, // bool
ThreadsScriptVerif, // int
Prune, // bool
PruneSize, // int
DatabaseCache, // int
SpendZeroConfChange, // bool
Listen, // bool