From cda83e8ae1389b03c1b431103200843bcc1778c3 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 10 Dec 2020 22:26:17 +0000 Subject: [PATCH 1/2] GUI: Intro: Output a std::unique_ptr from Intro::showIfNeeded --- src/qt/bitcoin.cpp | 10 +++++----- src/qt/intro.cpp | 18 +++++++----------- src/qt/intro.h | 4 +++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index bad4e72794..2cae57205f 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -575,10 +575,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; - int64_t prune_MiB = 0; // Intro dialog prune configuration + std::unique_ptr intro; // Gracefully exit if the user cancels - if (!Intro::showIfNeeded(did_show_intro, prune_MiB)) return EXIT_SUCCESS; + if (!Intro::showIfNeeded(intro)) return EXIT_SUCCESS; /// 6-7. Parse bitcoin.conf, determine network, switch to network specific /// options, and create datadir and settings.json. @@ -651,9 +650,10 @@ int GuiMain(int argc, char* argv[]) return EXIT_FAILURE; } - if (did_show_intro) { + if (intro) { // Store intro dialog settings other than datadir (network specific) - app.InitPruneSetting(prune_MiB); + app.InitPruneSetting(intro->getPruneMiB()); + intro.reset(); } try diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index f86b167076..37d7a3e6e0 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -202,9 +202,9 @@ int64_t Intro::getPruneMiB() const } } -bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) +bool Intro::showIfNeeded(std::unique_ptr& intro) { - did_show_intro = false; + intro.reset(); QSettings settings; /* If data directory provided on command line, no need to look at settings @@ -226,19 +226,18 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) } /* If current default data directory does not exist, let the user choose one */ - Intro intro(nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize()); - intro.setDataDirectory(dataDir); - intro.setWindowIcon(QIcon(":icons/bitcoin")); - did_show_intro = true; + intro = std::make_unique(nullptr, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize()); + intro->setDataDirectory(dataDir); + intro->setWindowIcon(QIcon(QStringLiteral(":icons/bitcoin"))); while(true) { - if(!intro.exec()) + if(!intro->exec()) { /* Cancel clicked */ return false; } - dataDir = intro.getDataDirectory(); + dataDir = intro->getDataDirectory(); try { if (TryCreateDirectories(GUIUtil::QStringToPath(dataDir))) { // If a new data directory has been created, make wallets subdirectory too @@ -252,9 +251,6 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) } } - // Additional preferences: - 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 900c657b27..063b0cf43d 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -9,6 +9,8 @@ #include #include +#include + static const bool DEFAULT_CHOOSE_DATADIR = false; class FreespaceChecker; @@ -48,7 +50,7 @@ public: * @note do NOT call global gArgs.GetDataDirNet() before calling this function, this * will cause the wrong path to be cached. */ - static bool showIfNeeded(bool& did_show_intro, int64_t& prune_MiB); + static bool showIfNeeded(std::unique_ptr& intro); Q_SIGNALS: void requestCheck(); From 2da00fd2bd6941352057e15c0987d808fcacf079 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 10 Dec 2020 23:26:03 +0000 Subject: [PATCH 2/2] GUI: Intro: Have user choose assumevalid --- src/qt/bitcoin.cpp | 10 +++++++- src/qt/bitcoin.h | 1 + src/qt/forms/intro.ui | 58 +++++++++++++++++++++++++++++++++++++++++++ src/qt/intro.cpp | 39 +++++++++++++++++++++++++++++ src/qt/intro.h | 1 + 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 2cae57205f..eb3e13693b 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #ifdef ENABLE_WALLET @@ -653,7 +654,7 @@ int GuiMain(int argc, char* argv[]) if (intro) { // Store intro dialog settings other than datadir (network specific) app.InitPruneSetting(intro->getPruneMiB()); - intro.reset(); + gArgs.ForceSetArg("-assumevalid", intro->getAssumeValid().toStdString()); } try @@ -663,6 +664,13 @@ int GuiMain(int argc, char* argv[]) // This is acceptable because this function only contains steps that are quick to execute, // so the GUI thread won't be held up. if (app.baseInitialize()) { + if (intro) { + // Store intro dialog settings other than datadir (network specific) + common::SettingsValue intro_assumevalid = intro->getAssumeValid().toStdString(); + app.node().context()->chain->overwriteRwSetting("assumevalid", intro_assumevalid); + // We can release the Intro widget now + intro.reset(); + } app.requestInitialize(); #if defined(Q_OS_WIN) WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId()); diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index 9622c9d57d..5ce499f749 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -9,6 +9,7 @@ #include #endif +#include #include #include diff --git a/src/qt/forms/intro.ui b/src/qt/forms/intro.ui index 9ab91f6aa9..33703e0124 100644 --- a/src/qt/forms/intro.ui +++ b/src/qt/forms/intro.ui @@ -271,6 +271,64 @@ + + + + + + + The initial synchronisation process can go faster if you skip verification of older transactions. This does, however, require trusting that the "assumed valid" blockchain below is in fact valid. Uncheck this if you want to fully validate the entire blockchain history. + + + true + + + + + + + + + Reverting this setting will slow down initial synchronisation due to validating old transactions + + + Skip validation of the transactions until after block: + + + true + + + + + + + Qt::Horizontal + + + + + + + + + + + Qt::Horizontal + + + + + + + 64 + + + + + + + + diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 37d7a3e6e0..eb3f6c9a20 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -161,6 +161,37 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si UpdateFreeSpaceLabel(); }); + bool have_user_assumevalid = false; + if (gArgs.IsArgSet("-assumevalid")) { + const auto user_assumevalid = gArgs.GetArg("-assumevalid", /* ignored default; determines return type */ ""); + if (uint256S(user_assumevalid).IsNull()) { + // -assumevalid=0: default checkbox to off, and initialise with chainparams later + ui->assumevalid->setChecked(false); + } else { + // -assumevalid=blockhash: initialise with the user-specified value, enabled + ui->assumevalid->setChecked(true); + ui->assumevalidBlock->setText(QString::fromStdString(user_assumevalid)); + have_user_assumevalid = true; + } + } + if (!have_user_assumevalid) { + const auto chainparams = CreateChainParams(gArgs, gArgs.GetChainType()); + const uint256 default_assumevalid = chainparams ? chainparams->GetConsensus().defaultAssumeValid : uint256(); + if (default_assumevalid.IsNull()) { + // no chainparams assumevalid (nor user-provided), so hide the options entirely + ui->groupAssumeValid->setVisible(false); + } else { + // assumevalid from chainparams only (normal case): disable editing of blockhash + ui->assumevalidBlock->setText(QString::fromStdString(default_assumevalid.GetHex())); + ui->assumevalidBlock->setReadOnly(true); + } + } + { + // TODO: Ideally, we would include actual margins here (instead of extra digits), but this seems non-trivial + const int text_width = ui->assumevalidBlock->fontMetrics().horizontalAdvance(QStringLiteral("4")) * (64 + 4); + ui->assumevalidBlock->setFixedWidth(text_width); + } + startThread(); } @@ -202,6 +233,14 @@ int64_t Intro::getPruneMiB() const } } +QString Intro::getAssumeValid() const +{ + if (!ui->assumevalid->isChecked()) { + return QStringLiteral("0"); + } + return ui->assumevalidBlock->text(); +} + bool Intro::showIfNeeded(std::unique_ptr& intro) { intro.reset(); diff --git a/src/qt/intro.h b/src/qt/intro.h index 063b0cf43d..1e3eb5c629 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -39,6 +39,7 @@ public: QString getDataDirectory(); void setDataDirectory(const QString &dataDir); int64_t getPruneMiB() const; + QString getAssumeValid() const; /** * Determine data directory. Let the user choose if the current one doesn't exist.