Skip to content

Commit 291123f

Browse files
hebastoPastaPastaPasta
authored andcommitted
Merge bitcoin-core/gui#125: Enable changing the autoprune block space size in intro dialog
415fb2e GUI/Intro: Move prune setting below explanation (Luke Dashjr) 2a84c6b GUI/Intro: Estimate max age of backups that can be restored with pruning (Luke Dashjr) e2dcd95 GUI/Intro: Rework UI flow to let the user set prune size in GBs (Luke Dashjr) f2e5a6b GUI/Intro: Abstract GUI-to-option into Intro::getPrune (Luke Dashjr) 62932cc GUI/Intro: Return actual prune setting from showIfNeeded (Luke Dashjr) Pull request description: ![Screenshot_20200911_095102](https://user-images.githubusercontent.com/1095675/92933661-0c4cea00-f436-11ea-9853-2456091ffab3.png) Moved from bitcoin#18728 ACKs for top commit: ryanofsky: Code review ACK 415fb2e. Changes since last review: mb/gib suffixes, constexpr QOverload expected_backup_days tweaks, new moveonly layout commit jarolrod: Tested ACK 415fb2e. Talkless: tACK 415fb2e, tested on Debian Sid with Qt 5.15.2. hebasto: ACK 415fb2e, my unresolved comments are not blockers, and they could be resolved in follow ups. Tree-SHA512: bd4882a9c08e6a6eb14b7fb6366983db8581425b4949fea212785d34d8fad9e32fb81ca8c8cdbfb2c05ea394aaf5a746ba2cf16623795c7252c3bdb61d455f00
1 parent 98f03b3 commit 291123f

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

src/qt/bitcoin.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,9 @@ void BitcoinApplication::parameterSetup()
308308
InitParameterInteraction(gArgs);
309309
}
310310

311-
void BitcoinApplication::InitializePruneSetting(bool prune)
311+
void BitcoinApplication::InitPruneSetting(int64_t prune_MiB)
312312
{
313-
// If prune is set, intentionally override existing prune size with
314-
// the default size since this is called when choosing a new datadir.
315-
optionsModel->SetPruneTargetGB(prune ? DEFAULT_PRUNE_TARGET_GB : 0, true);
313+
optionsModel->SetPruneTargetGB(PruneMiBtoGB(prune_MiB), true);
316314
}
317315

318316
void BitcoinApplication::requestInitialize()
@@ -555,9 +553,9 @@ int GuiMain(int argc, char* argv[])
555553
/// 5. Now that settings and translations are available, ask user for data directory
556554
// User language is set up: pick a data directory
557555
bool did_show_intro = false;
558-
bool prune = false; // Intro dialog prune check box
556+
int64_t prune_MiB = 0; // Intro dialog prune configuration
559557
// Gracefully exit if the user cancels
560-
if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS;
558+
if (!Intro::showIfNeeded(did_show_intro, prune_MiB)) return EXIT_SUCCESS;
561559

562560
/// 6. Determine availability of data directory and parse dash.conf
563561
/// - Do not call GetDataDir(true) before this step finishes
@@ -729,7 +727,7 @@ int GuiMain(int argc, char* argv[])
729727

730728
if (did_show_intro) {
731729
// Store intro dialog settings other than datadir (network specific)
732-
app.InitializePruneSetting(prune);
730+
app.InitPruneSetting(prune_MiB);
733731
}
734732

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

src/qt/bitcoin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BitcoinApplication: public QApplication
6868
/// Create options model
6969
void createOptionsModel(bool resetSettings);
7070
/// Initialize prune setting
71-
void InitializePruneSetting(bool prune);
71+
void InitPruneSetting(int64_t prune_MiB);
7272
/// Create main window
7373
void createWindow(const NetworkStyle *networkStyle);
7474
/// Create splash screen

src/qt/forms/intro.ui

+42-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>674</width>
10-
<height>415</height>
10+
<height>447</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -210,16 +210,6 @@
210210
</property>
211211
</widget>
212212
</item>
213-
<item>
214-
<widget class="QCheckBox" name="prune">
215-
<property name="toolTip">
216-
<string>Reverting this setting requires re-downloading the entire blockchain. It is faster to download the full chain first and prune it later. Disables some advanced features.</string>
217-
</property>
218-
<property name="text">
219-
<string></string>
220-
</property>
221-
</widget>
222-
</item>
223213
<item>
224214
<widget class="QLabel" name="lblExplanation2">
225215
<property name="text">
@@ -240,6 +230,47 @@
240230
</property>
241231
</widget>
242232
</item>
233+
<item>
234+
<layout class="QHBoxLayout" name="pruneOptLayout">
235+
<item>
236+
<widget class="QCheckBox" name="prune">
237+
<property name="text">
238+
<string>Limit block chain storage to</string>
239+
</property>
240+
<property name="toolTip">
241+
<string>Reverting this setting requires re-downloading the entire blockchain. It is faster to download the full chain first and prune it later. Disables some advanced features.</string>
242+
</property>
243+
</widget>
244+
</item>
245+
<item>
246+
<widget class="QSpinBox" name="pruneGB">
247+
<property name="suffix">
248+
<string> GB</string>
249+
</property>
250+
</widget>
251+
</item>
252+
<item>
253+
<widget class="QLabel" name="lblPruneSuffix">
254+
<property name="buddy">
255+
<cstring>pruneGB</cstring>
256+
</property>
257+
</widget>
258+
</item>
259+
<item>
260+
<spacer name="horizontalSpacer_2">
261+
<property name="orientation">
262+
<enum>Qt::Horizontal</enum>
263+
</property>
264+
<property name="sizeHint" stdset="0">
265+
<size>
266+
<width>40</width>
267+
<height>20</height>
268+
</size>
269+
</property>
270+
</spacer>
271+
</item>
272+
</layout>
273+
</item>
243274
<item>
244275
<spacer name="verticalSpacer">
245276
<property name="orientation">

src/qt/intro.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <interfaces/node.h>
2020
#include <util/system.h>
21+
#include <validation.h>
2122

2223
#include <QFileDialog>
2324
#include <QSettings>
@@ -140,17 +141,26 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si
140141
);
141142
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
142143

144+
const int min_prune_target_GB = std::ceil(MIN_DISK_SPACE_FOR_BLOCK_FILES / 1e9);
145+
ui->pruneGB->setRange(min_prune_target_GB, std::numeric_limits<int>::max());
143146
if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB
144147
ui->prune->setChecked(true);
145148
ui->prune->setEnabled(false);
146149
}
147-
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(m_prune_target_gb));
150+
ui->pruneGB->setValue(m_prune_target_gb);
151+
ui->pruneGB->setToolTip(ui->prune->toolTip());
152+
ui->lblPruneSuffix->setToolTip(ui->prune->toolTip());
148153
UpdatePruneLabels(ui->prune->isChecked());
149154

150155
connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) {
151156
UpdatePruneLabels(prune_checked);
152157
UpdateFreeSpaceLabel();
153158
});
159+
connect(ui->pruneGB, QOverload<int>::of(&QSpinBox::valueChanged), [this](int prune_GB) {
160+
m_prune_target_gb = prune_GB;
161+
UpdatePruneLabels(ui->prune->isChecked());
162+
UpdateFreeSpaceLabel();
163+
});
154164

155165
startThread();
156166
}
@@ -183,7 +193,17 @@ void Intro::setDataDirectory(const QString &dataDir)
183193
}
184194
}
185195

186-
bool Intro::showIfNeeded(bool& did_show_intro, bool& prune)
196+
int64_t Intro::getPruneMiB() const
197+
{
198+
switch (ui->prune->checkState()) {
199+
case Qt::Checked:
200+
return PruneGBtoMiB(m_prune_target_gb);
201+
case Qt::Unchecked: default:
202+
return 0;
203+
}
204+
}
205+
206+
bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
187207
{
188208
did_show_intro = false;
189209

@@ -238,7 +258,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, bool& prune)
238258
}
239259

240260
// Additional preferences:
241-
prune = intro.ui->prune->isChecked();
261+
prune_MiB = intro.getPruneMiB();
242262

243263
settings.setValue("strDataDir", dataDir);
244264
settings.setValue("strDataDirDefault", dataDirDefaultCurrent);
@@ -367,6 +387,11 @@ void Intro::UpdatePruneLabels(bool prune_checked)
367387
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
368388
}
369389
ui->lblExplanation3->setVisible(prune_checked);
390+
ui->pruneGB->setEnabled(prune_checked);
391+
static constexpr uint64_t nPowTargetSpacing = 2.5 * 60; // from chainparams, which we don't have at this stage
392+
static constexpr uint32_t expected_block_data_size = 2250000; // includes undo data
393+
const uint64_t expected_backup_days = m_prune_target_gb * 1e9 / (uint64_t(expected_block_data_size) * 86400 / nPowTargetSpacing);
394+
ui->lblPruneSuffix->setText(tr("(sufficient to restore backups %n day(s) old)", "block chain pruning", expected_backup_days));
370395
ui->sizeWarningLabel->setText(
371396
tr("%1 will download and store a copy of the Dash block chain.").arg(PACKAGE_NAME) + " " +
372397
storageRequiresMsg.arg(m_required_space_gb) + " " +

src/qt/intro.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Intro : public QDialog
3636

3737
QString getDataDirectory();
3838
void setDataDirectory(const QString &dataDir);
39+
int64_t getPruneMiB() const;
3940

4041
/**
4142
* Determine data directory. Let the user choose if the current one doesn't exist.
@@ -47,7 +48,7 @@ class Intro : public QDialog
4748
* @note do NOT call global GetDataDir() before calling this function, this
4849
* will cause the wrong path to be cached.
4950
*/
50-
static bool showIfNeeded(bool& did_show_intro, bool& prune);
51+
static bool showIfNeeded(bool& did_show_intro, int64_t& prune_MiB);
5152

5253
Q_SIGNALS:
5354
void requestCheck();
@@ -72,7 +73,7 @@ private Q_SLOTS:
7273
//! Total required space (in GB) depending on user choice (prune or not prune).
7374
int64_t m_required_space_gb{0};
7475
uint64_t m_bytes_available{0};
75-
const int64_t m_prune_target_gb;
76+
int64_t m_prune_target_gb;
7677

7778
void startThread();
7879
void checkPath(const QString &dataDir);

0 commit comments

Comments
 (0)