From 62932cc686dc46ce14c026993deea8e561654177 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 20 Apr 2020 14:42:52 +0000 Subject: [PATCH 1/5] GUI/Intro: Return actual prune setting from showIfNeeded --- src/qt/bitcoin.cpp | 12 +++++------- src/qt/bitcoin.h | 2 +- src/qt/intro.cpp | 4 ++-- src/qt/intro.h | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index eaaaaeb904..f7db865e32 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -315,11 +315,9 @@ void BitcoinApplication::parameterSetup() InitParameterInteraction(gArgs); } -void BitcoinApplication::InitializePruneSetting(bool prune) +void BitcoinApplication::InitPruneSetting(int64_t prune_MiB) { - // If prune is set, intentionally override existing prune size with - // the default size since this is called when choosing a new datadir. - optionsModel->SetPruneTargetGB(prune ? DEFAULT_PRUNE_TARGET_GB : 0, true); + optionsModel->SetPruneTargetGB(PruneMiBtoGB(prune_MiB), true); } void BitcoinApplication::requestInitialize() @@ -508,9 +506,9 @@ int GuiMain(int argc, char* argv[]) /// 5. Now that settings and translations are available, ask user for data directory // User language is set up: pick a data directory bool did_show_intro = false; - bool prune = false; // Intro dialog prune check box + int64_t prune_MiB = 0; // Intro dialog prune configuration // Gracefully exit if the user cancels - if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS; + if (!Intro::showIfNeeded(did_show_intro, prune_MiB)) return EXIT_SUCCESS; /// 6. Determine availability of data directory and parse bitcoin.conf /// - Do not call GetDataDir(true) before this step finishes @@ -594,7 +592,7 @@ int GuiMain(int argc, char* argv[]) if (did_show_intro) { // Store intro dialog settings other than datadir (network specific) - app.InitializePruneSetting(prune); + app.InitPruneSetting(prune_MiB); } if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index 69e0a5921e..17ea67ba66 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -68,7 +68,7 @@ public: /// Create options model void createOptionsModel(bool resetSettings); /// Initialize prune setting - void InitializePruneSetting(bool prune); + void InitPruneSetting(int64_t prune_MiB); /// Create main window void createWindow(const NetworkStyle *networkStyle); /// Create splash screen diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 235722d091..437c941f70 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -182,7 +182,7 @@ void Intro::setDataDirectory(const QString &dataDir) } } -bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) +bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) { did_show_intro = false; @@ -233,7 +233,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) } // Additional preferences: - prune = intro.ui->prune->isChecked(); + prune_MiB = intro.ui->prune->isChecked() ? PruneGBtoMiB(intro.m_prune_target_gb) : int64_t(0); settings.setValue("strDataDir", dataDir); settings.setValue("fReset", false); diff --git a/src/qt/intro.h b/src/qt/intro.h index 51f42de7ac..67888343a5 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -47,7 +47,7 @@ public: * @note do NOT call global GetDataDir() before calling this function, this * will cause the wrong path to be cached. */ - static bool showIfNeeded(bool& did_show_intro, bool& prune); + static bool showIfNeeded(bool& did_show_intro, int64_t& prune_MiB); Q_SIGNALS: void requestCheck(); From f2e5a6b54fa38b10d822609939b8108bd8fe041b Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 19 Nov 2020 03:19:30 +0000 Subject: [PATCH 2/5] GUI/Intro: Abstract GUI-to-option into Intro::getPrune --- src/qt/intro.cpp | 12 +++++++++++- src/qt/intro.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 437c941f70..61fb1463b9 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -182,6 +182,16 @@ void Intro::setDataDirectory(const QString &dataDir) } } +int64_t Intro::getPruneMiB() const +{ + switch (ui->prune->checkState()) { + case Qt::Checked: + return PruneGBtoMiB(m_prune_target_gb); + case Qt::Unchecked: default: + return 0; + } +} + bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) { did_show_intro = false; @@ -233,7 +243,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) } // Additional preferences: - prune_MiB = intro.ui->prune->isChecked() ? PruneGBtoMiB(intro.m_prune_target_gb) : int64_t(0); + prune_MiB = intro.getPruneMiB(); settings.setValue("strDataDir", dataDir); settings.setValue("fReset", false); diff --git a/src/qt/intro.h b/src/qt/intro.h index 67888343a5..bf7dad6ffb 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -36,6 +36,7 @@ public: QString getDataDirectory(); void setDataDirectory(const QString &dataDir); + int64_t getPruneMiB() const; /** * Determine data directory. Let the user choose if the current one doesn't exist. From e2dcd957fa206a28404ff824fb764b8889705fb2 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 21 Apr 2020 21:14:11 +0000 Subject: [PATCH 3/5] GUI/Intro: Rework UI flow to let the user set prune size in GBs --- src/qt/forms/intro.ui | 46 ++++++++++++++++++++++++++++++++----------- src/qt/intro.cpp | 12 ++++++++++- src/qt/intro.h | 2 +- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/qt/forms/intro.ui b/src/qt/forms/intro.ui index f27a4ebe44..db1b567049 100644 --- a/src/qt/forms/intro.ui +++ b/src/qt/forms/intro.ui @@ -7,7 +7,7 @@ 0 0 674 - 415 + 447 @@ -200,6 +200,40 @@ + + + + + + Limit block chain storage to + + + 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. + + + + + + + GB + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -210,16 +244,6 @@ - - - - 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. - - - - - - diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 61fb1463b9..e91722795c 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -139,17 +140,25 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si ); ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME)); + const int min_prune_target_GB = std::ceil(MIN_DISK_SPACE_FOR_BLOCK_FILES / 1e9); + ui->pruneGB->setRange(min_prune_target_GB, std::numeric_limits::max()); if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB ui->prune->setChecked(true); ui->prune->setEnabled(false); } - ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(m_prune_target_gb)); + ui->pruneGB->setValue(m_prune_target_gb); + ui->pruneGB->setToolTip(ui->prune->toolTip()); UpdatePruneLabels(ui->prune->isChecked()); connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) { UpdatePruneLabels(prune_checked); UpdateFreeSpaceLabel(); }); + connect(ui->pruneGB, QOverload::of(&QSpinBox::valueChanged), [this](int prune_GB) { + m_prune_target_gb = prune_GB; + UpdatePruneLabels(ui->prune->isChecked()); + UpdateFreeSpaceLabel(); + }); startThread(); } @@ -371,6 +380,7 @@ void Intro::UpdatePruneLabels(bool prune_checked) storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory."); } ui->lblExplanation3->setVisible(prune_checked); + ui->pruneGB->setEnabled(prune_checked); ui->sizeWarningLabel->setText( tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + storageRequiresMsg.arg(m_required_space_gb) + " " + diff --git a/src/qt/intro.h b/src/qt/intro.h index bf7dad6ffb..88fe2b722d 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -73,7 +73,7 @@ private: //! Total required space (in GB) depending on user choice (prune or not prune). int64_t m_required_space_gb{0}; uint64_t m_bytes_available{0}; - const int64_t m_prune_target_gb; + int64_t m_prune_target_gb; void startThread(); void checkPath(const QString &dataDir); From 2a84c6bcf61429ac507b506a39247b3a66edbcb4 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 21 Apr 2020 22:02:25 +0000 Subject: [PATCH 4/5] GUI/Intro: Estimate max age of backups that can be restored with pruning --- src/qt/forms/intro.ui | 7 +++++++ src/qt/intro.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/qt/forms/intro.ui b/src/qt/forms/intro.ui index db1b567049..ac3b6c7328 100644 --- a/src/qt/forms/intro.ui +++ b/src/qt/forms/intro.ui @@ -219,6 +219,13 @@ + + + + pruneGB + + + diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index e91722795c..f66eba1fef 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -148,6 +148,7 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si } ui->pruneGB->setValue(m_prune_target_gb); ui->pruneGB->setToolTip(ui->prune->toolTip()); + ui->lblPruneSuffix->setToolTip(ui->prune->toolTip()); UpdatePruneLabels(ui->prune->isChecked()); connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) { @@ -381,6 +382,10 @@ void Intro::UpdatePruneLabels(bool prune_checked) } ui->lblExplanation3->setVisible(prune_checked); ui->pruneGB->setEnabled(prune_checked); + static constexpr uint64_t nPowTargetSpacing = 10 * 60; // from chainparams, which we don't have at this stage + static constexpr uint32_t expected_block_data_size = 2250000; // includes undo data + const uint64_t expected_backup_days = m_prune_target_gb * 1e9 / (uint64_t(expected_block_data_size) * 86400 / nPowTargetSpacing); + ui->lblPruneSuffix->setText(tr("(sufficient to restore backups %n day(s) old)", "block chain pruning", expected_backup_days)); ui->sizeWarningLabel->setText( tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + storageRequiresMsg.arg(m_required_space_gb) + " " + From 415fb2e1abac189fcbe8eccf2ea065724d17460f Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 19 Nov 2020 03:08:40 +0000 Subject: [PATCH 5/5] GUI/Intro: Move prune setting below explanation --- src/qt/forms/intro.ui | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/qt/forms/intro.ui b/src/qt/forms/intro.ui index ac3b6c7328..a1e94f99e6 100644 --- a/src/qt/forms/intro.ui +++ b/src/qt/forms/intro.ui @@ -200,6 +200,36 @@ + + + + When you click OK, %1 will begin to download and process the full %4 block chain (%2GB) starting with the earliest transactions in %3 when %4 initially launched. + + + true + + + + + + + This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run %1, it will continue downloading where it left off. + + + true + + + + + + + If you have chosen to limit block chain storage (pruning), the historical data must still be downloaded and processed, but will be deleted afterward to keep your disk usage low. + + + true + + + @@ -241,36 +271,6 @@ - - - - When you click OK, %1 will begin to download and process the full %4 block chain (%2GB) starting with the earliest transactions in %3 when %4 initially launched. - - - true - - - - - - - This initial synchronisation is very demanding, and may expose hardware problems with your computer that had previously gone unnoticed. Each time you run %1, it will continue downloading where it left off. - - - true - - - - - - - If you have chosen to limit block chain storage (pruning), the historical data must still be downloaded and processed, but will be deleted afterward to keep your disk usage low. - - - true - - -