From ba8fc7d788932b25864fb260ca14983aa2398c23 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Mon, 17 Apr 2023 22:20:59 +0200 Subject: [PATCH] refactor: Replace string chain name constants with ChainTypes This commit effectively moves the definition of these constants out of the chainparamsbase to their own file. Using the ChainType enums provides better type safety compared to passing around strings. The commit is part of an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager and other functionality that should not be part of the kernel library. --- src/bench/checkblock.cpp | 3 +- src/bench/load_external.cpp | 3 +- src/bench/logging.cpp | 3 +- src/bench/mempool_stress.cpp | 5 ++- src/bench/rpc_blockchain.cpp | 3 +- src/bench/rpc_mempool.cpp | 3 +- src/bitcoin-chainstate.cpp | 3 +- src/bitcoin-cli.cpp | 25 +++++++---- src/bitcoin-tx.cpp | 2 +- src/bitcoin-util.cpp | 2 +- src/bitcoin-wallet.cpp | 2 +- src/chainparams.cpp | 22 ++++++---- src/chainparams.h | 5 ++- src/chainparamsbase.cpp | 23 +++++----- src/chainparamsbase.h | 16 +++---- src/common/args.cpp | 20 ++++----- src/common/args.h | 2 +- src/common/config.cpp | 5 ++- src/common/init.cpp | 2 +- src/init.cpp | 25 +++++------ src/kernel/chainparams.cpp | 9 ++-- src/kernel/chainparams.h | 9 ++-- src/node/interfaces.cpp | 2 +- src/node/mempool_args.cpp | 2 +- src/qt/bitcoin.cpp | 2 +- src/qt/guiutil.cpp | 25 +++++------ src/qt/intro.cpp | 3 +- src/qt/networkstyle.cpp | 15 ++++--- src/qt/networkstyle.h | 4 +- src/qt/rpcconsole.cpp | 2 +- src/qt/test/apptests.cpp | 2 +- src/qt/test/test_main.cpp | 3 +- src/rpc/blockchain.cpp | 2 +- src/rpc/external_signer.cpp | 2 +- src/rpc/mining.cpp | 2 +- src/rpc/net.cpp | 3 +- src/test/argsman_tests.cpp | 43 ++++++++++--------- src/test/blockmanager_tests.cpp | 3 +- src/test/checkqueue_tests.cpp | 5 ++- src/test/fuzz/addrman.cpp | 3 +- src/test/fuzz/block.cpp | 3 +- src/test/fuzz/descriptor_parse.cpp | 3 +- src/test/fuzz/headerssync.cpp | 3 +- src/test/fuzz/integer.cpp | 3 +- src/test/fuzz/key.cpp | 3 +- src/test/fuzz/key_io.cpp | 3 +- src/test/fuzz/message.cpp | 3 +- src/test/fuzz/net.cpp | 3 +- src/test/fuzz/p2p_transport_serialization.cpp | 3 +- src/test/fuzz/parse_univalue.cpp | 3 +- src/test/fuzz/pow.cpp | 3 +- src/test/fuzz/process_message.cpp | 3 +- src/test/fuzz/process_messages.cpp | 2 +- src/test/fuzz/rpc.cpp | 3 +- src/test/fuzz/script.cpp | 3 +- src/test/fuzz/script_format.cpp | 3 +- src/test/fuzz/script_sign.cpp | 3 +- src/test/fuzz/signet.cpp | 3 +- src/test/fuzz/system.cpp | 2 +- src/test/fuzz/transaction.cpp | 3 +- src/test/fuzz/utxo_snapshot.cpp | 3 +- src/test/fuzz/utxo_total_supply.cpp | 3 +- src/test/fuzz/versionbits.cpp | 3 +- src/test/key_io_tests.cpp | 11 ++--- src/test/pow_tests.cpp | 33 +++++++------- src/test/settings_tests.cpp | 8 ++-- src/test/txvalidationcache_tests.cpp | 3 +- src/test/util/setup_common.cpp | 17 ++++---- src/test/util/setup_common.h | 15 ++++--- src/test/validation_tests.cpp | 9 ++-- src/test/versionbits_tests.cpp | 9 ++-- src/util/settings.cpp | 8 ++-- src/util/settings.h | 6 +-- .../external_signer_scriptpubkeyman.cpp | 2 +- src/wallet/test/init_test_fixture.cpp | 3 +- src/wallet/test/init_test_fixture.h | 3 +- src/wallet/test/wallet_test_fixture.cpp | 5 ++- src/wallet/test/wallet_test_fixture.h | 3 +- 78 files changed, 288 insertions(+), 229 deletions(-) diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 260c8991ce1..269ac847a57 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include // These are the two major time-sinks which happen after we have fully received @@ -36,7 +37,7 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench) stream.write({&a, 1}); // Prevent compaction ArgsManager bench_args; - const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN); bench.unit("block").run([&] { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 0fd842c7c36..2ff72a30121 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include /** @@ -22,7 +23,7 @@ */ static void LoadExternalBlockFile(benchmark::Bench& bench) { - const auto testing_setup{MakeNoLogFileContext(CBaseChainParams::MAIN)}; + const auto testing_setup{MakeNoLogFileContext(ChainType::MAIN)}; // Create a single block as in the blocks files (magic bytes, block size, // block data) as a stream object. diff --git a/src/bench/logging.cpp b/src/bench/logging.cpp index 9aedb26236d..c97c4e151b6 100644 --- a/src/bench/logging.cpp +++ b/src/bench/logging.cpp @@ -5,6 +5,7 @@ #include #include #include +#include // All but 2 of the benchmarks should have roughly similar performance: // @@ -18,7 +19,7 @@ static void Logging(benchmark::Bench& bench, const std::vector& ext LogInstance().DisableCategory(BCLog::LogFlags::ALL); TestingSetup test_setup{ - CBaseChainParams::REGTEST, + ChainType::REGTEST, extra_args, }; diff --git a/src/bench/mempool_stress.cpp b/src/bench/mempool_stress.cpp index 80c959cdfbc..826da73800b 100644 --- a/src/bench/mempool_stress.cpp +++ b/src/bench/mempool_stress.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -88,7 +89,7 @@ static void ComplexMemPool(benchmark::Bench& bench) childTxs = static_cast(bench.complexityN()); } std::vector ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/1); - const auto testing_setup = MakeNoLogFileContext(CBaseChainParams::MAIN); + const auto testing_setup = MakeNoLogFileContext(ChainType::MAIN); CTxMemPool& pool = *testing_setup.get()->m_node.mempool; LOCK2(cs_main, pool.cs); bench.run([&]() NO_THREAD_SAFETY_ANALYSIS { @@ -103,7 +104,7 @@ static void ComplexMemPool(benchmark::Bench& bench) static void MempoolCheck(benchmark::Bench& bench) { FastRandomContext det_rand{true}; - auto testing_setup = MakeNoLogFileContext(CBaseChainParams::REGTEST, {"-checkmempool=1"}); + auto testing_setup = MakeNoLogFileContext(ChainType::REGTEST, {"-checkmempool=1"}); CTxMemPool& pool = *testing_setup.get()->m_node.mempool; LOCK2(cs_main, pool.cs); testing_setup->PopulateMempool(det_rand, 400, true); diff --git a/src/bench/rpc_blockchain.cpp b/src/bench/rpc_blockchain.cpp index f68b6acb5b6..a9b197b1901 100644 --- a/src/bench/rpc_blockchain.cpp +++ b/src/bench/rpc_blockchain.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ namespace { struct TestBlockAndIndex { - const std::unique_ptr testing_setup{MakeNoLogFileContext(CBaseChainParams::MAIN)}; + const std::unique_ptr testing_setup{MakeNoLogFileContext(ChainType::MAIN)}; CBlock block{}; uint256 blockHash{}; CBlockIndex blockindex{}; diff --git a/src/bench/rpc_mempool.cpp b/src/bench/rpc_mempool.cpp index e3e1a07c833..af1fa7c572e 100644 --- a/src/bench/rpc_mempool.cpp +++ b/src/bench/rpc_mempool.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -21,7 +22,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& poo static void RpcMempool(benchmark::Bench& bench) { - const auto testing_setup = MakeNoLogFileContext(CBaseChainParams::MAIN); + const auto testing_setup = MakeNoLogFileContext(ChainType::MAIN); CTxMemPool& pool = *Assert(testing_setup->m_node.mempool); LOCK2(cs_main, pool.cs); diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 2b139cf9084..52e697a78d9 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -25,6 +25,7 @@ #include #include #include