Skip to content

Commit

Permalink
Merge 884f7cc into merged_master (Bitcoin PR #16714)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Nov 3, 2020
2 parents c366388 + 884f7cc commit aaff32e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class NodeImpl : public Node
return gArgs.ParseParameters(argc, argv, error);
}
bool readConfigFiles(std::string& error) override { return gArgs.ReadConfigFiles(error, true); }
void forceSetArg(const std::string& arg, const std::string& value) override { gArgs.ForceSetArg(arg, value); }
bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); }
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
void selectParams(const std::string& network) override { SelectParams(network); }
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Node
//! Set command line arguments.
virtual bool parseParameters(int argc, const char* const argv[], std::string& error) = 0;

//! Set a command line argument
virtual void forceSetArg(const std::string& arg, const std::string& value) = 0;

//! Set a command line argument if it doesn't already have a value
virtual bool softSetArg(const std::string& arg, const std::string& value) = 0;

Expand Down
15 changes: 13 additions & 2 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ void BitcoinApplication::parameterSetup()
m_node.initParameterInteraction();
}

void BitcoinApplication::SetPrune(bool prune, bool force) {
optionsModel->SetPrune(prune, force);
}

void BitcoinApplication::requestInitialize()
{
qDebug() << __func__ << ": Requesting initialize";
Expand Down Expand Up @@ -488,8 +492,10 @@ 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
if (!Intro::pickDataDirectory(*node))
return EXIT_SUCCESS;
bool did_show_intro = false;
bool prune = false; // Intro dialog prune check box
// Gracefully exit if the user cancels
if (!Intro::showIfNeeded(*node, did_show_intro, prune)) return EXIT_SUCCESS;

/// 6. Determine availability of data directory and parse bitcoin.conf
/// - Do not call GetDataDir(true) before this step finishes
Expand Down Expand Up @@ -563,6 +569,11 @@ int GuiMain(int argc, char* argv[])
// Load GUI settings from QSettings
app.createOptionsModel(gArgs.GetBoolArg("-resetguisettings", false));

if (did_show_intro) {
// Store intro dialog settings other than datadir (network specific)
app.SetPrune(prune, true);
}

if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
app.createSplashScreen(networkStyle.data());

Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class BitcoinApplication: public QApplication
void parameterSetup();
/// Create options model
void createOptionsModel(bool resetSettings);
/// Update prune value
void SetPrune(bool prune, bool force = false);
/// Create main window
void createWindow(const NetworkStyle *networkStyle);
/// Create splash screen
Expand Down
10 changes: 10 additions & 0 deletions src/qt/forms/intro.ui
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@
</property>
</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">
Expand Down
18 changes: 17 additions & 1 deletion src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));

uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
if (pruneTarget > 1) { // -prune=1 means enabled, above that it's a size in MB
ui->prune->setChecked(true);
ui->prune->setEnabled(false);
}
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : 2));
requiredSpace = m_blockchain_size;
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
if (pruneTarget) {
Expand Down Expand Up @@ -184,8 +189,10 @@ void Intro::setDataDirectory(const QString &dataDir)
}
}

bool Intro::pickDataDirectory(interfaces::Node& node)
bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune)
{
did_show_intro = false;

QSettings settings;
/* If data directory provided on command line, no need to look at settings
or show a picking dialog */
Expand All @@ -209,6 +216,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
Intro intro(0, node.getAssumedBlockchainSize(), node.getAssumedChainStateSize());
intro.setDataDirectory(dataDir);
intro.setWindowIcon(QIcon(":icons/bitcoin"));
did_show_intro = true;

while(true)
{
Expand All @@ -231,6 +239,9 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
}
}

// Additional preferences:
prune = intro.ui->prune->isChecked();

settings.setValue("strDataDir", dataDir);
settings.setValue("fReset", false);
}
Expand Down Expand Up @@ -267,6 +278,11 @@ void Intro::setStatus(int status, const QString &message, quint64 bytesAvailable
{
freeString += " " + tr("(of %n GB needed)", "", requiredSpace);
ui->freeSpace->setStyleSheet("QLabel { color: #800000 }");
ui->prune->setChecked(true);
} else if (bytesAvailable / GB_BYTES - requiredSpace < 10) {
freeString += " " + tr("(%n GB needed for full chain)", "", requiredSpace);
ui->freeSpace->setStyleSheet("QLabel { color: #999900 }");
ui->prune->setChecked(true);
} else {
ui->freeSpace->setStyleSheet("");
}
Expand Down
3 changes: 2 additions & 1 deletion src/qt/intro.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ class Intro : public QDialog

/**
* Determine data directory. Let the user choose if the current one doesn't exist.
* Let the user configure additional preferences such as pruning.
*
* @returns true if a data directory was selected, false if the user cancelled the selection
* dialog.
*
* @note do NOT call global GetDataDir() before calling this function, this
* will cause the wrong path to be cached.
*/
static bool pickDataDirectory(interfaces::Node& node);
static bool showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& prune);

Q_SIGNALS:
void requestCheck();
Expand Down
22 changes: 17 additions & 5 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ void OptionsModel::Init(bool resetSettings)
settings.setValue("bPrune", false);
if (!settings.contains("nPruneSize"))
settings.setValue("nPruneSize", 2);
// Convert prune size from GB to MiB:
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMiB) : "0")) {
addOverriddenOption("-prune");
}
SetPrune(settings.value("bPrune").toBool());

if (!settings.contains("nDatabaseCache"))
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
Expand Down Expand Up @@ -240,6 +236,22 @@ static const QString GetDefaultProxyAddress()
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
}

void OptionsModel::SetPrune(bool prune, bool force)
{
QSettings settings;
settings.setValue("bPrune", prune);
// Convert prune size from GB to MiB:
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
std::string prune_val = prune ? std::to_string(nPruneSizeMiB) : "0";
if (force) {
m_node.forceSetArg("-prune", prune_val);
return;
}
if (!m_node.softSetArg("-prune", prune_val)) {
addOverriddenOption("-prune");
}
}

// read QSettings values and return them
QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
Expand Down
3 changes: 3 additions & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class OptionsModel : public QAbstractListModel
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }

/* Explicit setters */
void SetPrune(bool prune, bool force = false);

/* Restart flag helper */
void setRestartRequired(bool fRequired);
bool isRestartRequired() const;
Expand Down

0 comments on commit aaff32e

Please sign in to comment.