Skip to content

Commit f7e95fe

Browse files
committed
GUI: Intro: Have user choose assumevalid
1 parent 0e27096 commit f7e95fe

File tree

6 files changed

+107
-2
lines changed

6 files changed

+107
-2
lines changed

src/qt/bitcoin.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ int GuiMain(int argc, char* argv[])
593593
if (intro) {
594594
// Store intro dialog settings other than datadir (network specific)
595595
app.InitPruneSetting(intro->getPruneMiB());
596-
intro.reset();
596+
gArgs.ForceSetArg("-assumevalid", intro->getAssumeValid().toStdString());
597597
}
598598

599599
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
@@ -609,6 +609,12 @@ int GuiMain(int argc, char* argv[])
609609
// This is acceptable because this function only contains steps that are quick to execute,
610610
// so the GUI thread won't be held up.
611611
if (app.baseInitialize()) {
612+
if (intro) {
613+
// Store intro dialog settings other than datadir (network specific)
614+
node->context()->chain->updateRwSetting("assumevalid", intro->getAssumeValid().toStdString());
615+
// We can release the Intro widget now
616+
intro.reset();
617+
}
612618
app.requestInitialize();
613619
#if defined(Q_OS_WIN)
614620
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(PACKAGE_NAME), (HWND)app.getMainWinId());

src/qt/bitcoin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <assert.h>
1414
#include <memory>
1515

16+
#include <interfaces/chain.h>
1617
#include <interfaces/node.h>
1718

1819
class BitcoinGUI;

src/qt/forms/intro.ui

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,64 @@
271271
</item>
272272
</layout>
273273
</item>
274+
<item>
275+
<widget class="QWidget" name="groupAssumeValid">
276+
<layout class="QVBoxLayout">
277+
<item>
278+
<widget class="QLabel" name="lblExplanationAssumeValid">
279+
<property name="text">
280+
<string>The initial synchronisation process can go faster if you skip verification of older transactions. This does, however, require trusting that the &quot;assumed valid&quot; blockchain below is in fact valid. Uncheck this if you want to fully validate the entire blockchain history.</string>
281+
</property>
282+
<property name="wordWrap">
283+
<bool>true</bool>
284+
</property>
285+
</widget>
286+
</item>
287+
<item>
288+
<layout class="QHBoxLayout" name="layoutAssumeValid">
289+
<item>
290+
<widget class="QCheckBox" name="assumevalid">
291+
<property name="toolTip">
292+
<string>Reverting this setting will slow down initial synchronisation due to validating old transactions</string>
293+
</property>
294+
<property name="text">
295+
<string>Skip validation of the transactions until after block:</string>
296+
</property>
297+
<property name="checked">
298+
<bool>true</bool>
299+
</property>
300+
</widget>
301+
</item>
302+
<item>
303+
<spacer>
304+
<property name="orientation">
305+
<enum>Qt::Horizontal</enum>
306+
</property>
307+
</spacer>
308+
</item>
309+
</layout>
310+
</item>
311+
<item>
312+
<layout class="QHBoxLayout" name="layoutAssumeValidBlock">
313+
<item>
314+
<spacer>
315+
<property name="orientation">
316+
<enum>Qt::Horizontal</enum>
317+
</property>
318+
</spacer>
319+
</item>
320+
<item>
321+
<widget class="QLineEdit" name="assumevalidBlock">
322+
<property name="maxLength">
323+
<number>64</number>
324+
</property>
325+
</widget>
326+
</item>
327+
</layout>
328+
</item>
329+
</layout>
330+
</widget>
331+
</item>
274332
<item>
275333
<spacer name="verticalSpacer">
276334
<property name="orientation">

src/qt/intro.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,37 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si
161161
UpdateFreeSpaceLabel();
162162
});
163163

164+
bool have_user_assumevalid = false;
165+
if (gArgs.IsArgSet("-assumevalid")) {
166+
const auto user_assumevalid = gArgs.GetArg("-assumevalid", /* ignored default; determines return type */ "");
167+
if (uint256S(user_assumevalid).IsNull()) {
168+
// -assumevalid=0: default checkbox to off, and initialise with chainparams later
169+
ui->assumevalid->setChecked(false);
170+
} else {
171+
// -assumevalid=blockhash: initialise with the user-specified value, enabled
172+
ui->assumevalid->setChecked(true);
173+
ui->assumevalidBlock->setText(QString::fromStdString(user_assumevalid));
174+
have_user_assumevalid = true;
175+
}
176+
}
177+
if (!have_user_assumevalid) {
178+
const auto chainparams = CreateChainParams(gArgs, gArgs.GetChainName());
179+
const uint256 default_assumevalid = chainparams ? chainparams->GetConsensus().defaultAssumeValid : uint256();
180+
if (default_assumevalid.IsNull()) {
181+
// no chainparams assumevalid (nor user-provided), so hide the options entirely
182+
ui->groupAssumeValid->setVisible(false);
183+
} else {
184+
// assumevalid from chainparams only (normal case): disable editing of blockhash
185+
ui->assumevalidBlock->setText(QString::fromStdString(default_assumevalid.GetHex()));
186+
ui->assumevalidBlock->setReadOnly(true);
187+
}
188+
}
189+
{
190+
// TODO: Ideally, we would include actual margins here (instead of extra digits), but this seems non-trivial
191+
const int text_width = ui->assumevalidBlock->fontMetrics().width("4") * (64 + 4);
192+
ui->assumevalidBlock->setFixedWidth(text_width);
193+
}
194+
164195
startThread();
165196
}
166197

@@ -202,6 +233,14 @@ int64_t Intro::getPruneMiB() const
202233
}
203234
}
204235

236+
QString Intro::getAssumeValid() const
237+
{
238+
if (!ui->assumevalid->isChecked()) {
239+
return "0";
240+
}
241+
return ui->assumevalidBlock->text();
242+
}
243+
205244
bool Intro::showIfNeeded(std::unique_ptr<Intro>& intro)
206245
{
207246
intro.reset();

src/qt/intro.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Intro : public QDialog
3939
QString getDataDirectory();
4040
void setDataDirectory(const QString &dataDir);
4141
int64_t getPruneMiB() const;
42+
QString getAssumeValid() const;
4243

4344
/**
4445
* Determine data directory. Let the user choose if the current one doesn't exist.

src/util/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <string>
1212
#include <vector>
1313

14-
class UniValue;
14+
#include <univalue.h>
1515

1616
namespace util {
1717

0 commit comments

Comments
 (0)