Skip to content

Commit 153a688

Browse files
committed
Merge bitcoin/bitcoin#27576: kernel: Remove args, settings, chainparams, chainparamsbase from kernel library
db77f87 scripted-diff: move settings to common namespace (TheCharlatan) c27e4bd move-only: Move settings to the common library (TheCharlatan) c2dae5d kernel: Remove chainparams, chainparamsbase, args, settings from kernel library (TheCharlatan) 05870b1 refactor: Remove gArgs access from validation.cpp (TheCharlatan) 8789b11 refactor: Add path argument to FindSnapshotChainstateDir (TheCharlatan) ef95be3 refactor: Add stop_at_height option in ChainstateManager (TheCharlatan) Pull request description: This pull request is part of the `libbitcoinkernel` project bitcoin/bitcoin#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: bitcoin/bitcoin#26177 bitcoin/bitcoin#27125 bitcoin/bitcoin#25527 bitcoin/bitcoin#25487 bitcoin/bitcoin#25290 ACKs for top commit: MarcoFalke: lgtm ACK db77f87 🍄 hebasto: ACK db77f87, I have reviewed the code and it looks OK. ryanofsky: Code review ACK db77f87. Looks great! Tree-SHA512: cbfbd705d056f2f10f16810d4f869eb152362fff2c5ddae5e1ac6785deae095588e52ad48b29d921962b085e51de1e0ecab6e50f46149ffe3c16250608a2c93a
2 parents 456af7a + db77f87 commit 153a688

27 files changed

+167
-171
lines changed

src/Makefile.am

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ BITCOIN_CORE_H = \
143143
compat/compat.h \
144144
compat/cpuid.h \
145145
compat/endian.h \
146+
common/settings.h \
146147
common/system.h \
147148
compressor.h \
148149
consensus/consensus.h \
@@ -309,7 +310,6 @@ BITCOIN_CORE_H = \
309310
util/readwritefile.h \
310311
util/result.h \
311312
util/serfloat.h \
312-
util/settings.h \
313313
util/sock.h \
314314
util/spanparsing.h \
315315
util/string.h \
@@ -663,6 +663,7 @@ libbitcoin_common_a_SOURCES = \
663663
common/init.cpp \
664664
common/interfaces.cpp \
665665
common/run_command.cpp \
666+
common/settings.cpp \
666667
common/system.cpp \
667668
compressor.cpp \
668669
core_read.cpp \
@@ -733,7 +734,6 @@ libbitcoin_util_a_SOURCES = \
733734
util/moneystr.cpp \
734735
util/rbf.cpp \
735736
util/readwritefile.cpp \
736-
util/settings.cpp \
737737
util/thread.cpp \
738738
util/threadinterrupt.cpp \
739739
util/threadnames.cpp \
@@ -912,12 +912,8 @@ libbitcoinkernel_la_SOURCES = \
912912
kernel/bitcoinkernel.cpp \
913913
arith_uint256.cpp \
914914
chain.cpp \
915-
chainparamsbase.cpp \
916-
chainparams.cpp \
917915
clientversion.cpp \
918916
coins.cpp \
919-
common/args.cpp \
920-
common/config.cpp \
921917
compressor.cpp \
922918
consensus/merkle.cpp \
923919
consensus/tx_check.cpp \
@@ -978,7 +974,6 @@ libbitcoinkernel_la_SOURCES = \
978974
util/moneystr.cpp \
979975
util/rbf.cpp \
980976
util/serfloat.cpp \
981-
util/settings.cpp \
982977
util/strencodings.cpp \
983978
util/string.cpp \
984979
util/syscall_sandbox.cpp \

src/addrdb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <chainparams.h>
1010
#include <clientversion.h>
1111
#include <common/args.h>
12+
#include <common/settings.h>
1213
#include <cstdint>
1314
#include <hash.h>
1415
#include <logging.h>
@@ -21,7 +22,6 @@
2122
#include <univalue.h>
2223
#include <util/fs.h>
2324
#include <util/fs_helpers.h>
24-
#include <util/settings.h>
2525
#include <util/translation.h>
2626

2727
namespace {
@@ -132,7 +132,7 @@ CBanDB::CBanDB(fs::path ban_list_path)
132132
bool CBanDB::Write(const banmap_t& banSet)
133133
{
134134
std::vector<std::string> errors;
135-
if (util::WriteSettings(m_banlist_json, {{JSON_KEY, BanMapToJson(banSet)}}, errors)) {
135+
if (common::WriteSettings(m_banlist_json, {{JSON_KEY, BanMapToJson(banSet)}}, errors)) {
136136
return true;
137137
}
138138

@@ -152,10 +152,10 @@ bool CBanDB::Read(banmap_t& banSet)
152152
return false;
153153
}
154154

155-
std::map<std::string, util::SettingsValue> settings;
155+
std::map<std::string, common::SettingsValue> settings;
156156
std::vector<std::string> errors;
157157

158-
if (!util::ReadSettings(m_banlist_json, settings, errors)) {
158+
if (!common::ReadSettings(m_banlist_json, settings, errors)) {
159159
for (const auto& err : errors) {
160160
LogPrintf("Cannot load banlist %s: %s\n", fs::PathToString(m_banlist_json), err);
161161
}

src/bitcoin-chainstate.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include <kernel/context.h>
1818
#include <kernel/validation_cache_sizes.h>
1919

20-
#include <chainparams.h>
21-
#include <common/args.h>
2220
#include <consensus/validation.h>
2321
#include <core_io.h>
2422
#include <node/blockstorage.h>
@@ -53,13 +51,9 @@ int main(int argc, char* argv[])
5351
}
5452
std::filesystem::path abs_datadir = std::filesystem::absolute(argv[1]);
5553
std::filesystem::create_directories(abs_datadir);
56-
gArgs.ForceSetArg("-datadir", abs_datadir.string());
5754

5855

59-
// SETUP: Misc Globals
60-
SelectParams(ChainType::MAIN);
61-
auto chainparams = CChainParams::Main();
62-
56+
// SETUP: Context
6357
kernel::Context kernel_context{};
6458
// We can't use a goto here, but we can use an assert since none of the
6559
// things instantiated so far requires running the epilogue to be torn down
@@ -106,16 +100,18 @@ int main(int argc, char* argv[])
106100
};
107101
auto notifications = std::make_unique<KernelNotifications>();
108102

103+
109104
// SETUP: Chainstate
105+
auto chainparams = CChainParams::Main();
110106
const ChainstateManager::Options chainman_opts{
111107
.chainparams = *chainparams,
112-
.datadir = gArgs.GetDataDirNet(),
108+
.datadir = abs_datadir,
113109
.adjusted_time_callback = NodeClock::now,
114110
.notifications = *notifications,
115111
};
116112
const node::BlockManager::Options blockman_opts{
117113
.chainparams = chainman_opts.chainparams,
118-
.blocks_dir = gArgs.GetBlocksDirPath(),
114+
.blocks_dir = abs_datadir / "blocks",
119115
};
120116
ChainstateManager chainman{chainman_opts, blockman_opts};
121117

@@ -148,7 +144,8 @@ int main(int argc, char* argv[])
148144
// Main program logic starts here
149145
std::cout
150146
<< "Hello! I'm going to print out some information about your datadir." << std::endl
151-
<< "\t" << "Path: " << gArgs.GetDataDirNet() << std::endl;
147+
<< "\t"
148+
<< "Path: " << abs_datadir << std::endl;
152149
{
153150
LOCK(chainman.GetMutex());
154151
std::cout

src/common/args.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <common/args.h>
77

88
#include <chainparamsbase.h>
9+
#include <common/settings.h>
910
#include <logging.h>
1011
#include <sync.h>
1112
#include <tinyformat.h>
@@ -14,7 +15,6 @@
1415
#include <util/check.h>
1516
#include <util/fs.h>
1617
#include <util/fs_helpers.h>
17-
#include <util/settings.h>
1818
#include <util/strencodings.h>
1919

2020
#ifdef WIN32
@@ -104,7 +104,7 @@ KeyInfo InterpretKey(std::string key)
104104
* @return parsed settings value if it is valid, otherwise nullopt accompanied
105105
* by a descriptive error string
106106
*/
107-
std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
107+
std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
108108
unsigned int flags, std::string& error)
109109
{
110110
// Return negated settings as false values.
@@ -238,15 +238,15 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
238238
return false;
239239
}
240240

241-
std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
241+
std::optional<common::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
242242
if (!value) return false;
243243

244244
m_settings.command_line_options[keyinfo.name].push_back(*value);
245245
}
246246

247247
// we do not allow -includeconf from command line, only -noincludeconf
248-
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
249-
const util::SettingsSpan values{*includes};
248+
if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
249+
const common::SettingsSpan values{*includes};
250250
// Range may be empty if -noincludeconf was passed
251251
if (!values.empty()) {
252252
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
@@ -361,7 +361,7 @@ std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
361361
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
362362
{
363363
std::vector<std::string> result;
364-
for (const util::SettingsValue& value : GetSettingsList(strArg)) {
364+
for (const common::SettingsValue& value : GetSettingsList(strArg)) {
365365
result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
366366
}
367367
return result;
@@ -408,7 +408,7 @@ bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
408408
LOCK(cs_args);
409409
m_settings.rw_settings.clear();
410410
std::vector<std::string> read_errors;
411-
if (!util::ReadSettings(path, m_settings.rw_settings, read_errors)) {
411+
if (!common::ReadSettings(path, m_settings.rw_settings, read_errors)) {
412412
SaveErrors(read_errors, errors);
413413
return false;
414414
}
@@ -430,7 +430,7 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
430430

431431
LOCK(cs_args);
432432
std::vector<std::string> write_errors;
433-
if (!util::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
433+
if (!common::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
434434
SaveErrors(write_errors, errors);
435435
return false;
436436
}
@@ -441,10 +441,10 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
441441
return true;
442442
}
443443

444-
util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
444+
common::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
445445
{
446446
LOCK(cs_args);
447-
return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
447+
return common::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
448448
/*ignore_nonpersistent=*/true, /*get_chain_type=*/false);
449449
}
450450

@@ -460,11 +460,11 @@ std::string ArgsManager::GetArg(const std::string& strArg, const std::string& st
460460

461461
std::optional<std::string> ArgsManager::GetArg(const std::string& strArg) const
462462
{
463-
const util::SettingsValue value = GetSetting(strArg);
463+
const common::SettingsValue value = GetSetting(strArg);
464464
return SettingToString(value);
465465
}
466466

467-
std::optional<std::string> SettingToString(const util::SettingsValue& value)
467+
std::optional<std::string> SettingToString(const common::SettingsValue& value)
468468
{
469469
if (value.isNull()) return std::nullopt;
470470
if (value.isFalse()) return "0";
@@ -473,7 +473,7 @@ std::optional<std::string> SettingToString(const util::SettingsValue& value)
473473
return value.get_str();
474474
}
475475

476-
std::string SettingToString(const util::SettingsValue& value, const std::string& strDefault)
476+
std::string SettingToString(const common::SettingsValue& value, const std::string& strDefault)
477477
{
478478
return SettingToString(value).value_or(strDefault);
479479
}
@@ -485,11 +485,11 @@ int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) cons
485485

486486
std::optional<int64_t> ArgsManager::GetIntArg(const std::string& strArg) const
487487
{
488-
const util::SettingsValue value = GetSetting(strArg);
488+
const common::SettingsValue value = GetSetting(strArg);
489489
return SettingToInt(value);
490490
}
491491

492-
std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
492+
std::optional<int64_t> SettingToInt(const common::SettingsValue& value)
493493
{
494494
if (value.isNull()) return std::nullopt;
495495
if (value.isFalse()) return 0;
@@ -498,7 +498,7 @@ std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
498498
return LocaleIndependentAtoi<int64_t>(value.get_str());
499499
}
500500

501-
int64_t SettingToInt(const util::SettingsValue& value, int64_t nDefault)
501+
int64_t SettingToInt(const common::SettingsValue& value, int64_t nDefault)
502502
{
503503
return SettingToInt(value).value_or(nDefault);
504504
}
@@ -510,18 +510,18 @@ bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
510510

511511
std::optional<bool> ArgsManager::GetBoolArg(const std::string& strArg) const
512512
{
513-
const util::SettingsValue value = GetSetting(strArg);
513+
const common::SettingsValue value = GetSetting(strArg);
514514
return SettingToBool(value);
515515
}
516516

517-
std::optional<bool> SettingToBool(const util::SettingsValue& value)
517+
std::optional<bool> SettingToBool(const common::SettingsValue& value)
518518
{
519519
if (value.isNull()) return std::nullopt;
520520
if (value.isBool()) return value.get_bool();
521521
return InterpretBool(value.get_str());
522522
}
523523

524-
bool SettingToBool(const util::SettingsValue& value, bool fDefault)
524+
bool SettingToBool(const common::SettingsValue& value, bool fDefault)
525525
{
526526
return SettingToBool(value).value_or(fDefault);
527527
}
@@ -738,7 +738,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
738738
{
739739
auto get_net = [&](const std::string& arg) {
740740
LOCK(cs_args);
741-
util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
741+
common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),
742742
/* ignore_default_section_config= */ false,
743743
/*ignore_nonpersistent=*/false,
744744
/* get_chain_type= */ true);
@@ -769,24 +769,24 @@ bool ArgsManager::UseDefaultSection(const std::string& arg) const
769769
return m_network == ChainTypeToString(ChainType::MAIN) || m_network_only_args.count(arg) == 0;
770770
}
771771

772-
util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
772+
common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
773773
{
774774
LOCK(cs_args);
775-
return util::GetSetting(
775+
return common::GetSetting(
776776
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
777777
/*ignore_nonpersistent=*/false, /*get_chain_type=*/false);
778778
}
779779

780-
std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
780+
std::vector<common::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
781781
{
782782
LOCK(cs_args);
783-
return util::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
783+
return common::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
784784
}
785785

786786
void ArgsManager::logArgsPrefix(
787787
const std::string& prefix,
788788
const std::string& section,
789-
const std::map<std::string, std::vector<util::SettingsValue>>& args) const
789+
const std::map<std::string, std::vector<common::SettingsValue>>& args) const
790790
{
791791
std::string section_str = section.empty() ? "" : "[" + section + "] ";
792792
for (const auto& arg : args) {

0 commit comments

Comments
 (0)