Skip to content

Commit

Permalink
Unify bitcoin-qt and bitcoind persistent settings
Browse files Browse the repository at this point in the history
If a setting like pruning, port mapping, or a network proxy is enabled in the
GUI, it will now be stored in the bitcoin persistent setting file and shared
with bitcoind, instead of being stored as Qt settings (backed by the windows
registry and platform specific config files).
  • Loading branch information
ryanofsky committed May 1, 2019
1 parent f1a5b92 commit a50315a
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 273 deletions.
23 changes: 22 additions & 1 deletion src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,30 @@ class NodeImpl : public Node
}
bool readConfigFiles(std::string& error) override { return gArgs.ReadConfigFiles(error, true); }
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); }
bool readSettingsFile() override { return gArgs.ReadSettingsFile(); }
util::SettingsValue getSetting(const std::string& name) override { return gArgs.GetPersistentSetting(name); }
void updateSetting(const std::string& name, const util::SettingsValue& value) override
{
gArgs.LockSettings([&](util::Settings& settings) {
if (value.isNull()) {
settings.rw_settings.erase(name);
} else {
settings.rw_settings[name] = value;
}
});
}
bool writeSettingsFile() override { return gArgs.WriteSettingsFile(); }
bool isSettingIgnored(const std::string& name) override
{
bool ignored = false;
gArgs.LockSettings([&](util::Settings& settings) {
if (auto* options = util::FindKey(settings.command_line_options, name)) {
ignored = !options->empty();
}
});
return ignored;
}
uint64_t getAssumedBlockchainSize() override { return Params().AssumedBlockchainSize(); }
uint64_t getAssumedChainStateSize() override { return Params().AssumedChainStateSize(); }
std::string getNetwork() override { return Params().NetworkIDString(); }
Expand Down
34 changes: 27 additions & 7 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#ifndef BITCOIN_INTERFACES_NODE_H
#define BITCOIN_INTERFACES_NODE_H

#include <addrdb.h> // For banmap_t
#include <amount.h> // For CAmount
#include <net.h> // For CConnman::NumConnections
#include <netaddress.h> // For Network
#include <addrdb.h> // For banmap_t
#include <amount.h> // For CAmount
#include <net.h> // For CConnman::NumConnections
#include <netaddress.h> // For Network
#include <util/settings.h> // For util::SettingsValue

#include <functional>
#include <memory>
Expand Down Expand Up @@ -44,9 +45,6 @@ class Node
//! 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;

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

//! Load settings from configuration file.
virtual bool readConfigFiles(std::string& error) = 0;

Expand All @@ -58,6 +56,28 @@ class Node
//! network-specific.
virtual bool readSettingsFile() = 0;

// Return <datadir>/settings.json setting value. If not set will return underlying config value.
virtual util::SettingsValue getSetting(const std::string& name) = 0;

//! Update a setting in <datadir>/settings.json.
//!
//! Updated setting values are returned by getSetting() and GetArg()
//! immediately but are not saved to disk until writeSettingsFile() is
//! called.
//!
//! Setting name should be a command line -option name specified without the
//! hyphen prefix. In GetArg() calls, values in settings.json will take
//! precedence over values in bitcoin.conf, but will not take precedence
//! over values specified explicitly on the command line.
virtual void updateSetting(const std::string& name, const util::SettingsValue& value) = 0;

//! Save <datadir>/settings.json file with updated settings.
virtual bool writeSettingsFile() = 0;

//! Return whether a particular setting in <datadir>/settings.json is or
//! would be ignored because it is also specified in the command line.
virtual bool isSettingIgnored(const std::string& name) = 0;

//! Get the (assumed) blockchain size.
virtual uint64_t getAssumedBlockchainSize() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
<item>
<widget class="QLabel" name="overriddenByCommandLineInfoLabel">
<property name="text">
<string>Options set in this dialog are overridden by the command line or in the configuration file:</string>
<string>Options set in this dialog are overridden by the command line:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
Expand Down
3 changes: 2 additions & 1 deletion src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>

#include <interfaces/node.h>
#include <util/system.h>
Expand Down Expand Up @@ -134,7 +135,7 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
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) {
uint64_t prunedGBs = std::ceil(pruneTarget * 1024 * 1024.0 / GB_BYTES);
uint64_t prunedGBs = PruneMiBtoGB(pruneTarget);
if (prunedGBs <= requiredSpace) {
requiredSpace = prunedGBs;
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
Expand Down
Loading

0 comments on commit a50315a

Please sign in to comment.