mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 17:24:58 +02:00
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.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <common/args.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <streams.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <validation.h>
|
||||
|
||||
// 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
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <bench/data.h>
|
||||
#include <chainparams.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <validation.h>
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@
|
||||
*/
|
||||
static void LoadExternalBlockFile(benchmark::Bench& bench)
|
||||
{
|
||||
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
|
||||
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
|
||||
|
||||
// Create a single block as in the blocks files (magic bytes, block size,
|
||||
// block data) as a stream object.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <bench/bench.h>
|
||||
#include <logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
|
||||
// All but 2 of the benchmarks should have roughly similar performance:
|
||||
//
|
||||
@@ -18,7 +19,7 @@ static void Logging(benchmark::Bench& bench, const std::vector<const char*>& ext
|
||||
LogInstance().DisableCategory(BCLog::LogFlags::ALL);
|
||||
|
||||
TestingSetup test_setup{
|
||||
CBaseChainParams::REGTEST,
|
||||
ChainType::REGTEST,
|
||||
extra_args,
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <policy/policy.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -88,7 +89,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
|
||||
childTxs = static_cast<int>(bench.complexityN());
|
||||
}
|
||||
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/1);
|
||||
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
|
||||
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(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<TestChain100Setup>(CBaseChainParams::REGTEST, {"-checkmempool=1"});
|
||||
auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(ChainType::REGTEST, {"-checkmempool=1"});
|
||||
CTxMemPool& pool = *testing_setup.get()->m_node.mempool;
|
||||
LOCK2(cs_main, pool.cs);
|
||||
testing_setup->PopulateMempool(det_rand, 400, true);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <rpc/blockchain.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <univalue.h>
|
||||
@@ -15,7 +16,7 @@
|
||||
namespace {
|
||||
|
||||
struct TestBlockAndIndex {
|
||||
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
|
||||
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
|
||||
CBlock block{};
|
||||
uint256 blockHash{};
|
||||
CBlockIndex blockindex{};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <rpc/mempool.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <txmempool.h>
|
||||
#include <util/chaintype.h>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
@@ -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<const ChainTestingSetup>(CBaseChainParams::MAIN);
|
||||
const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN);
|
||||
CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);
|
||||
LOCK2(cs_main, pool.cs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user