diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-04-29 23:38:46 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-04-29 23:47:11 +0300 |
commit | e1e1e708fa0fbc0c51460305da5d401ed8f218f3 (patch) | |
tree | bd5983170c4fe527271bf7e6f4a9b304aaaa0615 | |
parent | 298fd02e4a34666f049a02b63381692cde636658 (diff) | |
parent | 415fb2e1abac189fcbe8eccf2ea065724d17460f (diff) |
Merge bitcoin-core/gui#125: Enable changing the autoprune block space size in intro dialog
415fb2e1abac189fcbe8eccf2ea065724d17460f GUI/Intro: Move prune setting below explanation (Luke Dashjr)
2a84c6bcf61429ac507b506a39247b3a66edbcb4 GUI/Intro: Estimate max age of backups that can be restored with pruning (Luke Dashjr)
e2dcd957fa206a28404ff824fb764b8889705fb2 GUI/Intro: Rework UI flow to let the user set prune size in GBs (Luke Dashjr)
f2e5a6b54fa38b10d822609939b8108bd8fe041b GUI/Intro: Abstract GUI-to-option into Intro::getPrune (Luke Dashjr)
62932cc686dc46ce14c026993deea8e561654177 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 https://github.com/bitcoin/bitcoin/pull/18728
ACKs for top commit:
ryanofsky:
Code review ACK 415fb2e1abac189fcbe8eccf2ea065724d17460f. Changes since last review: mb/gib suffixes, constexpr QOverload expected_backup_days tweaks, new moveonly layout commit
jarolrod:
Tested ACK 415fb2e.
Talkless:
tACK 415fb2e1abac189fcbe8eccf2ea065724d17460f, tested on Debian Sid with Qt 5.15.2.
hebasto:
ACK 415fb2e1abac189fcbe8eccf2ea065724d17460f, my unresolved comments are not blockers, and they could be resolved in follow ups.
Tree-SHA512: bd4882a9c08e6a6eb14b7fb6366983db8581425b4949fea212785d34d8fad9e32fb81ca8c8cdbfb2c05ea394aaf5a746ba2cf16623795c7252c3bdb61d455f00
-rw-r--r-- | src/qt/bitcoin.cpp | 12 | ||||
-rw-r--r-- | src/qt/bitcoin.h | 2 | ||||
-rw-r--r-- | src/qt/forms/intro.ui | 53 | ||||
-rw-r--r-- | src/qt/intro.cpp | 31 | ||||
-rw-r--r-- | src/qt/intro.h | 5 |
5 files changed, 79 insertions, 24 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index de71b7dea7..a30cac3504 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -319,11 +319,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() @@ -533,9 +531,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 @@ -617,7 +615,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 5fd6bd607f..f9fab0534b 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/forms/intro.ui b/src/qt/forms/intro.ui index f27a4ebe44..a1e94f99e6 100644 --- a/src/qt/forms/intro.ui +++ b/src/qt/forms/intro.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>674</width> - <height>415</height> + <height>447</height> </rect> </property> <property name="windowTitle"> @@ -211,16 +211,6 @@ </widget> </item> <item> - <widget class="QCheckBox" name="prune"> - <property name="toolTip"> - <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> - </property> - <property name="text"> - <string></string> - </property> - </widget> - </item> - <item> <widget class="QLabel" name="lblExplanation2"> <property name="text"> <string>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.</string> @@ -241,6 +231,47 @@ </widget> </item> <item> + <layout class="QHBoxLayout" name="pruneOptLayout"> + <item> + <widget class="QCheckBox" name="prune"> + <property name="text"> + <string>Limit block chain storage to</string> + </property> + <property name="toolTip"> + <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> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="pruneGB"> + <property name="suffix"> + <string> GB</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lblPruneSuffix"> + <property name="buddy"> + <cstring>pruneGB</cstring> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <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> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index aa6b2665fa..ed39307fd7 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -17,6 +17,7 @@ #include <interfaces/node.h> #include <util/system.h> +#include <validation.h> #include <QFileDialog> #include <QSettings> @@ -139,17 +140,26 @@ 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<int>::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()); + ui->lblPruneSuffix->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<int>::of(&QSpinBox::valueChanged), [this](int prune_GB) { + m_prune_target_gb = prune_GB; + UpdatePruneLabels(ui->prune->isChecked()); + UpdateFreeSpaceLabel(); + }); startThread(); } @@ -182,7 +192,17 @@ void Intro::setDataDirectory(const QString &dataDir) } } -bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) +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 +253,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) } // Additional preferences: - prune = intro.ui->prune->isChecked(); + prune_MiB = intro.getPruneMiB(); settings.setValue("strDataDir", dataDir); settings.setValue("fReset", false); @@ -361,6 +381,11 @@ 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); + 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) + " " + diff --git a/src/qt/intro.h b/src/qt/intro.h index 51f42de7ac..88fe2b722d 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. @@ -47,7 +48,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(); @@ -72,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); |