Skip to content

Commit 7f3675b

Browse files
committed
Merge #17696: qt: Force set nPruneSize in QSettings after the intro dialog
af112ab qt: Rename SetPrune() to InitializePruneSetting() (Hennadii Stepanov) b0bfbe5 refactor: Drop `bool force' parameter (Hennadii Stepanov) 68c9bbe qt: Force set nPruneSize in QSettings after intro (Hennadii Stepanov) a82bd8f util: Replace magics with DEFAULT_PRUNE_TARGET_GB (Hennadii Stepanov) Pull request description: On master (5622d8f), having `QSettings` set already ``` $ grep nPruneSize ~/.config/Bitcoin/Bitcoin-Qt-testnet.conf nPruneSize=6 ``` enabling prune option in the intro dialog ``` $ ./src/qt/bitcoin-qt -choosedatadir -testnet ``` ![DeepinScreenshot_select-area_20191208120425](https://user-images.githubusercontent.com/32963518/70388183-eed68580-19b6-11ea-9aa1-f9ad9aaa68a6.png) has no effect: ``` $ grep Prune ~/.bitcoin/testnet3/debug.log 2019-12-08T10:04:41Z Prune configured to target 5722 MiB on disk for block and undo files. ``` --- With this PR: ``` $ grep Prune ~/.bitcoin/testnet3/debug.log 2019-12-08T10:20:35Z Prune configured to target 1907 MiB on disk for block and undo files. ``` This PR has been split of #17453 (the first two commits) as it fixes an orthogonal bug. Refs: - bitcoin/bitcoin#17453 (comment) - bitcoin/bitcoin#17453 (comment) ACKs for top commit: Sjors: Code review re-ACK af112ab ryanofsky: Code review ACK af112ab. Just suggested changes since last review (thanks!) promag: Tested ACK af112ab. Latest suggestions and changes look good to me. Tree-SHA512: 8ddad34b30dcc2cdcad6678ba8a0b36fa176e4e3465862ef6eee9be0f98d8146705138c9c7995dd8c0990af41078ca743fef1a90ed9240081f052f32ddec72b9
2 parents 40a495a + af112ab commit 7f3675b

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

src/qt/bitcoin.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ void BitcoinApplication::parameterSetup()
281281
m_node.initParameterInteraction();
282282
}
283283

284-
void BitcoinApplication::SetPrune(bool prune, bool force) {
285-
optionsModel->SetPrune(prune, force);
284+
void BitcoinApplication::InitializePruneSetting(bool prune)
285+
{
286+
// If prune is set, intentionally override existing prune size with
287+
// the default size since this is called when choosing a new datadir.
288+
optionsModel->SetPruneTargetGB(prune ? DEFAULT_PRUNE_TARGET_GB : 0, true);
286289
}
287290

288291
void BitcoinApplication::requestInitialize()
@@ -562,7 +565,7 @@ int GuiMain(int argc, char* argv[])
562565

563566
if (did_show_intro) {
564567
// Store intro dialog settings other than datadir (network specific)
565-
app.SetPrune(prune, true);
568+
app.InitializePruneSetting(prune);
566569
}
567570

568571
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))

src/qt/bitcoin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class BitcoinApplication: public QApplication
6767
void parameterSetup();
6868
/// Create options model
6969
void createOptionsModel(bool resetSettings);
70-
/// Update prune value
71-
void SetPrune(bool prune, bool force = false);
70+
/// Initialize prune setting
71+
void InitializePruneSetting(bool prune);
7272
/// Create main window
7373
void createWindow(const NetworkStyle *networkStyle);
7474
/// Create splash screen

src/qt/guiconstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80;
5151
/* One gigabyte (GB) in bytes */
5252
static constexpr uint64_t GB_BYTES{1000000000};
5353

54+
// Default prune target displayed in GUI.
55+
static constexpr int DEFAULT_PRUNE_TARGET_GB{2};
56+
5457
#endif // BITCOIN_QT_GUICONSTANTS_H

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
135135
ui->prune->setChecked(true);
136136
ui->prune->setEnabled(false);
137137
}
138-
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : 2));
138+
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : DEFAULT_PRUNE_TARGET_GB));
139139
requiredSpace = m_blockchain_size;
140140
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
141141
if (pruneTarget) {

src/qt/optionsmodel.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ void OptionsModel::Init(bool resetSettings)
9191
if (!settings.contains("bPrune"))
9292
settings.setValue("bPrune", false);
9393
if (!settings.contains("nPruneSize"))
94-
settings.setValue("nPruneSize", 2);
95-
SetPrune(settings.value("bPrune").toBool());
94+
settings.setValue("nPruneSize", DEFAULT_PRUNE_TARGET_GB);
95+
SetPruneEnabled(settings.value("bPrune").toBool());
9696

9797
if (!settings.contains("nDatabaseCache"))
9898
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
@@ -236,7 +236,7 @@ static const QString GetDefaultProxyAddress()
236236
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
237237
}
238238

239-
void OptionsModel::SetPrune(bool prune, bool force)
239+
void OptionsModel::SetPruneEnabled(bool prune, bool force)
240240
{
241241
QSettings settings;
242242
settings.setValue("bPrune", prune);
@@ -252,6 +252,16 @@ void OptionsModel::SetPrune(bool prune, bool force)
252252
}
253253
}
254254

255+
void OptionsModel::SetPruneTargetGB(int prune_target_gb, bool force)
256+
{
257+
const bool prune = prune_target_gb > 0;
258+
if (prune) {
259+
QSettings settings;
260+
settings.setValue("nPruneSize", prune_target_gb);
261+
}
262+
SetPruneEnabled(prune, force);
263+
}
264+
255265
// read QSettings values and return them
256266
QVariant OptionsModel::data(const QModelIndex & index, int role) const
257267
{

src/qt/optionsmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class OptionsModel : public QAbstractListModel
7373
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
7474

7575
/* Explicit setters */
76-
void SetPrune(bool prune, bool force = false);
76+
void SetPruneEnabled(bool prune, bool force = false);
77+
void SetPruneTargetGB(int prune_target_gb, bool force = false);
7778

7879
/* Restart flag helper */
7980
void setRestartRequired(bool fRequired);

0 commit comments

Comments
 (0)