mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 08:44:02 +02:00
Merge bitcoin/bitcoin#27576: kernel: Remove args, settings, chainparams, chainparamsbase from kernel library
db77f87c63scripted-diff: move settings to common namespace (TheCharlatan)c27e4bdc35move-only: Move settings to the common library (TheCharlatan)c2dae5d7d8kernel: Remove chainparams, chainparamsbase, args, settings from kernel library (TheCharlatan)05870b1c92refactor: Remove gArgs access from validation.cpp (TheCharlatan)8789b11114refactor: Add path argument to FindSnapshotChainstateDir (TheCharlatan)ef95be334frefactor: Add stop_at_height option in ChainstateManager (TheCharlatan) Pull request description: This pull request is part of the `libbitcoinkernel` project https://github.com/bitcoin/bitcoin/issues/27587 https://github.com/bitcoin/bitcoin/projects/18 and more specifically its "Step 2: Decouple most non-consensus code from libbitcoinkernel". --- This completes the removal of the node's chainparams, chainparamsbase, args and settings files and their respective classes from the kernel library. This is the last pull request in a long series working towards decoupling the `ArgsManager` and the `gArgs` global from kernel code. These prior pull requests are: https://github.com/bitcoin/bitcoin/pull/26177 https://github.com/bitcoin/bitcoin/pull/27125 https://github.com/bitcoin/bitcoin/pull/25527 https://github.com/bitcoin/bitcoin/pull/25487 https://github.com/bitcoin/bitcoin/pull/25290 ACKs for top commit: MarcoFalke: lgtm ACKdb77f87c63🍄 hebasto: ACKdb77f87c63, I have reviewed the code and it looks OK. ryanofsky: Code review ACKdb77f87c63. Looks great! Tree-SHA512: cbfbd705d056f2f10f16810d4f869eb152362fff2c5ddae5e1ac6785deae095588e52ad48b29d921962b085e51de1e0ecab6e50f46149ffe3c16250608a2c93a
This commit is contained in:
@@ -85,7 +85,7 @@ class CheckValueTest : public TestChain100Setup
|
||||
{
|
||||
public:
|
||||
struct Expect {
|
||||
util::SettingsValue setting;
|
||||
common::SettingsValue setting;
|
||||
bool default_string = false;
|
||||
bool default_int = false;
|
||||
bool default_bool = false;
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
std::optional<std::vector<std::string>> list_value;
|
||||
const char* error = nullptr;
|
||||
|
||||
explicit Expect(util::SettingsValue s) : setting(std::move(s)) {}
|
||||
explicit Expect(common::SettingsValue s) : setting(std::move(s)) {}
|
||||
Expect& DefaultString() { default_string = true; return *this; }
|
||||
Expect& DefaultInt() { default_int = true; return *this; }
|
||||
Expect& DefaultBool() { default_bool = true; return *this; }
|
||||
@@ -1022,14 +1022,14 @@ BOOST_AUTO_TEST_CASE(util_ReadWriteSettings)
|
||||
// Test writing setting.
|
||||
TestArgsManager args1;
|
||||
args1.ForceSetArg("-datadir", fs::PathToString(m_path_root));
|
||||
args1.LockSettings([&](util::Settings& settings) { settings.rw_settings["name"] = "value"; });
|
||||
args1.LockSettings([&](common::Settings& settings) { settings.rw_settings["name"] = "value"; });
|
||||
args1.WriteSettingsFile();
|
||||
|
||||
// Test reading setting.
|
||||
TestArgsManager args2;
|
||||
args2.ForceSetArg("-datadir", fs::PathToString(m_path_root));
|
||||
args2.ReadSettingsFile();
|
||||
args2.LockSettings([&](util::Settings& settings) { BOOST_CHECK_EQUAL(settings.rw_settings["name"].get_str(), "value"); });
|
||||
args2.LockSettings([&](common::Settings& settings) { BOOST_CHECK_EQUAL(settings.rw_settings["name"].get_str(), "value"); });
|
||||
|
||||
// Test error logging, and remove previously written setting.
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <blockfilter.h>
|
||||
#include <clientversion.h>
|
||||
#include <common/args.h>
|
||||
#include <common/settings.h>
|
||||
#include <common/system.h>
|
||||
#include <common/url.h>
|
||||
#include <netbase.h>
|
||||
@@ -22,7 +23,6 @@
|
||||
#include <test/fuzz/util.h>
|
||||
#include <util/error.h>
|
||||
#include <util/fees.h>
|
||||
#include <util/settings.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
#include <util/translation.h>
|
||||
@@ -63,7 +63,7 @@ FUZZ_TARGET(string)
|
||||
(void)IsDeprecatedRPCEnabled(random_string_1);
|
||||
(void)Join(random_string_vector, random_string_1);
|
||||
(void)JSONRPCError(fuzzed_data_provider.ConsumeIntegral<int>(), random_string_1);
|
||||
const util::Settings settings;
|
||||
const common::Settings settings;
|
||||
(void)OnlyHasDefaultSectionSetting(settings, random_string_1, random_string_2);
|
||||
(void)ParseNetwork(random_string_1);
|
||||
(void)ParseOutputType(random_string_1);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <common/args.h>
|
||||
#include <common/settings.h>
|
||||
#include <logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <univalue.h>
|
||||
#include <util/settings.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <limits>
|
||||
@@ -57,8 +57,8 @@ BOOST_AUTO_TEST_CASE(setting_args)
|
||||
ArgsManager args;
|
||||
SetupArgs(args, {{"-foo", ArgsManager::ALLOW_ANY}});
|
||||
|
||||
auto set_foo = [&](const util::SettingsValue& value) {
|
||||
args.LockSettings([&](util::Settings& settings) {
|
||||
auto set_foo = [&](const common::SettingsValue& value) {
|
||||
args.LockSettings([&](common::Settings& settings) {
|
||||
settings.rw_settings["foo"] = value;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/settings.h>
|
||||
#include <common/settings.h>
|
||||
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/str.h>
|
||||
@@ -21,20 +21,20 @@
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
inline bool operator==(const util::SettingsValue& a, const util::SettingsValue& b)
|
||||
inline bool operator==(const common::SettingsValue& a, const common::SettingsValue& b)
|
||||
{
|
||||
return a.write() == b.write();
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const util::SettingsValue& value)
|
||||
inline std::ostream& operator<<(std::ostream& os, const common::SettingsValue& value)
|
||||
{
|
||||
os << value.write();
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const std::pair<std::string, util::SettingsValue>& kv)
|
||||
inline std::ostream& operator<<(std::ostream& os, const std::pair<std::string, common::SettingsValue>& kv)
|
||||
{
|
||||
util::SettingsValue out(util::SettingsValue::VOBJ);
|
||||
common::SettingsValue out(common::SettingsValue::VOBJ);
|
||||
out.__pushKV(kv.first, kv.second);
|
||||
os << out.write();
|
||||
return os;
|
||||
@@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
|
||||
"null": null
|
||||
})");
|
||||
|
||||
std::map<std::string, util::SettingsValue> expected{
|
||||
std::map<std::string, common::SettingsValue> expected{
|
||||
{"string", "string"},
|
||||
{"num", 5},
|
||||
{"bool", true},
|
||||
@@ -68,15 +68,15 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
|
||||
};
|
||||
|
||||
// Check file read.
|
||||
std::map<std::string, util::SettingsValue> values;
|
||||
std::map<std::string, common::SettingsValue> values;
|
||||
std::vector<std::string> errors;
|
||||
BOOST_CHECK(util::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(common::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(values.begin(), values.end(), expected.begin(), expected.end());
|
||||
BOOST_CHECK(errors.empty());
|
||||
|
||||
// Check no errors if file doesn't exist.
|
||||
fs::remove(path);
|
||||
BOOST_CHECK(util::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(common::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(values.empty());
|
||||
BOOST_CHECK(errors.empty());
|
||||
|
||||
@@ -85,29 +85,29 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
|
||||
"dupe": "string",
|
||||
"dupe": "dupe"
|
||||
})");
|
||||
BOOST_CHECK(!util::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(!common::ReadSettings(path, values, errors));
|
||||
std::vector<std::string> dup_keys = {strprintf("Found duplicate key dupe in settings file %s", fs::PathToString(path))};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), dup_keys.begin(), dup_keys.end());
|
||||
BOOST_CHECK(values.empty());
|
||||
|
||||
// Check non-kv json files not allowed
|
||||
WriteText(path, R"("non-kv")");
|
||||
BOOST_CHECK(!util::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(!common::ReadSettings(path, values, errors));
|
||||
std::vector<std::string> non_kv = {strprintf("Found non-object value \"non-kv\" in settings file %s", fs::PathToString(path))};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), non_kv.begin(), non_kv.end());
|
||||
|
||||
// Check invalid json not allowed
|
||||
WriteText(path, R"(invalid json)");
|
||||
BOOST_CHECK(!util::ReadSettings(path, values, errors));
|
||||
BOOST_CHECK(!common::ReadSettings(path, values, errors));
|
||||
std::vector<std::string> fail_parse = {strprintf("Unable to parse settings file %s", fs::PathToString(path))};
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), fail_parse.begin(), fail_parse.end());
|
||||
}
|
||||
|
||||
//! Check settings struct contents against expected json strings.
|
||||
static void CheckValues(const util::Settings& settings, const std::string& single_val, const std::string& list_val)
|
||||
static void CheckValues(const common::Settings& settings, const std::string& single_val, const std::string& list_val)
|
||||
{
|
||||
util::SettingsValue single_value = GetSetting(settings, "section", "name", false, false, false);
|
||||
util::SettingsValue list_value(util::SettingsValue::VARR);
|
||||
common::SettingsValue single_value = GetSetting(settings, "section", "name", false, false, false);
|
||||
common::SettingsValue list_value(common::SettingsValue::VARR);
|
||||
for (const auto& item : GetSettingsList(settings, "section", "name", false)) {
|
||||
list_value.push_back(item);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ static void CheckValues(const util::Settings& settings, const std::string& singl
|
||||
// Simple settings merge test case.
|
||||
BOOST_AUTO_TEST_CASE(Simple)
|
||||
{
|
||||
util::Settings settings;
|
||||
common::Settings settings;
|
||||
settings.command_line_options["name"].push_back("val1");
|
||||
settings.command_line_options["name"].push_back("val2");
|
||||
settings.ro_config["section"]["name"].push_back(2);
|
||||
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(Simple)
|
||||
// The last given arg takes precedence when specified via commandline.
|
||||
CheckValues(settings, R"("val2")", R"(["val1","val2",2])");
|
||||
|
||||
util::Settings settings2;
|
||||
common::Settings settings2;
|
||||
settings2.ro_config["section"]["name"].push_back("val2");
|
||||
settings2.ro_config["section"]["name"].push_back("val3");
|
||||
|
||||
@@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(Simple)
|
||||
// its default value.
|
||||
BOOST_AUTO_TEST_CASE(NullOverride)
|
||||
{
|
||||
util::Settings settings;
|
||||
common::Settings settings;
|
||||
settings.command_line_options["name"].push_back("value");
|
||||
BOOST_CHECK_EQUAL(R"("value")", GetSetting(settings, "section", "name", false, false, false).write().c_str());
|
||||
settings.forced_settings["name"] = {};
|
||||
@@ -195,11 +195,11 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup)
|
||||
bool ignore_default_section_config) {
|
||||
std::string desc;
|
||||
int value_suffix = 0;
|
||||
util::Settings settings;
|
||||
common::Settings settings;
|
||||
|
||||
const std::string& name = ignore_default_section_config ? "wallet" : "server";
|
||||
auto push_values = [&](Action action, const char* value_prefix, const std::string& name_prefix,
|
||||
std::vector<util::SettingsValue>& dest) {
|
||||
std::vector<common::SettingsValue>& dest) {
|
||||
if (action == SET || action == SECTION_SET) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
dest.push_back(value_prefix + ToString(++value_suffix));
|
||||
|
||||
@@ -184,7 +184,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
BOOST_CHECK(!chainman.IsSnapshotValidated());
|
||||
BOOST_CHECK(!node::FindSnapshotChainstateDir());
|
||||
BOOST_CHECK(!node::FindSnapshotChainstateDir(m_args.GetDataDirNet()));
|
||||
}
|
||||
|
||||
size_t initial_size;
|
||||
@@ -234,7 +234,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||
auto_infile >> coin;
|
||||
}));
|
||||
|
||||
BOOST_CHECK(!node::FindSnapshotChainstateDir());
|
||||
BOOST_CHECK(!node::FindSnapshotChainstateDir(m_args.GetDataDirNet()));
|
||||
|
||||
BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(
|
||||
this, [](AutoFile& auto_infile, SnapshotMetadata& metadata) {
|
||||
@@ -258,7 +258,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||
}));
|
||||
|
||||
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(this));
|
||||
BOOST_CHECK(fs::exists(*node::FindSnapshotChainstateDir()));
|
||||
BOOST_CHECK(fs::exists(*node::FindSnapshotChainstateDir(m_args.GetDataDirNet())));
|
||||
|
||||
// Ensure our active chain is the snapshot chainstate.
|
||||
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull());
|
||||
@@ -271,7 +271,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
|
||||
fs::path found = *node::FindSnapshotChainstateDir();
|
||||
fs::path found = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
|
||||
|
||||
// Note: WriteSnapshotBaseBlockhash() is implicitly tested above.
|
||||
BOOST_CHECK_EQUAL(
|
||||
@@ -491,7 +491,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_init, SnapshotTestSetup)
|
||||
|
||||
this->SetupSnapshot();
|
||||
|
||||
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir();
|
||||
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
|
||||
BOOST_CHECK(fs::exists(snapshot_chainstate_dir));
|
||||
BOOST_CHECK_EQUAL(snapshot_chainstate_dir, gArgs.GetDataDirNet() / "chainstate_snapshot");
|
||||
|
||||
@@ -565,7 +565,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_completion, SnapshotTestSetup
|
||||
SnapshotCompletionResult res;
|
||||
auto mock_shutdown = [](bilingual_str msg) {};
|
||||
|
||||
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir();
|
||||
fs::path snapshot_chainstate_dir = *node::FindSnapshotChainstateDir(m_args.GetDataDirNet());
|
||||
BOOST_CHECK(fs::exists(snapshot_chainstate_dir));
|
||||
BOOST_CHECK_EQUAL(snapshot_chainstate_dir, gArgs.GetDataDirNet() / "chainstate_snapshot");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user