Merge fc06881f13 into merged_master (Bitcoin PR bitcoin/bitcoin#27491)

This commit is contained in:
Byron Hambly 2025-05-23 13:02:22 +02:00
commit cbd7b123d9
93 changed files with 546 additions and 303 deletions

View file

@ -296,6 +296,7 @@ BITCOIN_CORE_H = \
util/bip32.h \
util/bitdeque.h \
util/bytevectorhash.h \
util/chaintype.h \
util/check.h \
util/epochguard.h \
util/error.h \
@ -752,6 +753,7 @@ libbitcoin_util_a_SOURCES = \
util/asmap.cpp \
util/bip32.cpp \
util/bytevectorhash.cpp \
util/chaintype.cpp \
util/check.cpp \
util/error.cpp \
util/exception.cpp \
@ -1039,6 +1041,7 @@ libbitcoinkernel_la_SOURCES = \
txdb.cpp \
txmempool.cpp \
uint256.cpp \
util/chaintype.cpp \
util/check.cpp \
util/exception.cpp \
util/fs.cpp \

View file

@ -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

View file

@ -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.

View file

@ -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,
};

View file

@ -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>
@ -91,7 +92,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 {
@ -106,7 +107,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);
const CBlockIndex* chain_tip = testing_setup.get()->m_node.chainman->ActiveChainstate().m_chain.Tip();

View file

@ -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 {
std::unique_ptr<TestingSetup> testing_setup{MakeNoLogFileContext<TestingSetup>(CBaseChainParams::MAIN)};
std::unique_ptr<TestingSetup> testing_setup{MakeNoLogFileContext<TestingSetup>(ChainType::MAIN)};
CBlock block{};
uint256 blockHash{};
CBlockIndex blockindex{};

View file

@ -3,12 +3,12 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bench/bench.h>
#include <chainparamsbase.h>
#include <kernel/cs_main.h>
#include <kernel/mempool_entry.h>
#include <rpc/mempool.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/chaintype.h>
#include <univalue.h>
@ -22,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);

View file

@ -25,6 +25,7 @@
#include <node/chainstate.h>
#include <scheduler.h>
#include <script/sigcache.h>
#include <util/chaintype.h>
#include <util/thread.h>
#include <validation.h>
#include <validationinterface.h>
@ -52,7 +53,7 @@ int main(int argc, char* argv[])
// SETUP: Misc Globals
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
auto chainparams = CChainParams::Main();
kernel::Context kernel_context{};

View file

@ -20,6 +20,7 @@
#include <rpc/request.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/exception.h>
#include <util/strencodings.h>
#include <util/system.h>
@ -73,10 +74,10 @@ static void SetupCliArgs(ArgsManager& argsman)
{
SetupHelpOptions(argsman);
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::DEFAULT);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET);
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
const auto defaultBaseParams = CreateBaseChainParams(ChainType::LIQUID1); // ELEMENTS
const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET);
const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET);
const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST);
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@ -174,7 +175,7 @@ static int AppInitRPC(int argc, char* argv[])
}
// Check for chain settings (BaseParams() calls are only valid after this clause)
try {
SelectBaseParams(gArgs.GetChainName());
SelectBaseParams(gArgs.GetChainTypeMeta());
} catch (const std::exception& e) {
tfm::format(std::cerr, "Error: %s\n", e.what());
return EXIT_FAILURE;
@ -426,10 +427,16 @@ private:
std::vector<Peer> m_peers;
std::string ChainToString() const
{
if (gArgs.GetChainName() == CBaseChainParams::TESTNET) return " testnet";
if (gArgs.GetChainName() == CBaseChainParams::SIGNET) return " signet";
if (gArgs.GetChainName() == CBaseChainParams::REGTEST) return " regtest";
return "";
switch (gArgs.GetChainType()) {
case ChainType::TESTNET:
return " testnet";
case ChainType::SIGNET:
return " signet";
case ChainType::REGTEST:
return " regtest";
default:
return "";
}
}
std::string PingTimeToString(double seconds) const
{

View file

@ -7,6 +7,7 @@
#endif
#include <asset.h>
#include <chainparamsbase.h>
#include <clientversion.h>
#include <coins.h>
#include <common/args.h>
@ -94,7 +95,7 @@ static int AppInitRawTx(int argc, char* argv[])
// Check for chain settings (Params() calls are only valid after this clause)
try {
SelectParams(gArgs.GetChainName());
SelectParams(gArgs.GetChainTypeMeta());
} catch (const std::exception& e) {
tfm::format(std::cerr, "Error: %s\n", e.what());
return EXIT_FAILURE;

View file

@ -75,7 +75,7 @@ static int AppInitUtil(ArgsManager& args, int argc, char* argv[])
// Check for chain settings (Params() calls are only valid after this clause)
try {
SelectParams(args.GetChainName());
SelectParams(args.GetChainTypeMeta());
} catch (const std::exception& e) {
tfm::format(std::cerr, "Error: %s\n", e.what());
return EXIT_FAILURE;

View file

@ -91,7 +91,7 @@ static std::optional<int> WalletAppInit(ArgsManager& args, int argc, char* argv[
return EXIT_FAILURE;
}
// Check for chain settings (Params() calls are only valid after this clause)
SelectParams(args.GetChainName());
SelectParams(args.GetChainTypeMeta());
return std::nullopt;
}

View file

@ -5,6 +5,7 @@
#include <chainparams.h>
#include <chainparamsbase.h>
#include <chainparamsseeds.h>
#include <common/args.h>
#include <consensus/merkle.h>
@ -14,6 +15,7 @@
#include <primitives/transaction.h>
#include <logging.h>
#include <script/interpreter.h>
#include <util/chaintype.h>
#include <util/string.h>
#include <crypto/sha256.h>
@ -100,38 +102,56 @@ const CChainParams &Params() {
return *globalChainParams;
}
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainTypeMeta chain)
{
// Reserved names for non-custom chains
if (chain == CBaseChainParams::MAIN) {
switch (chain.chain_type) {
case ChainType::MAIN:
return CChainParams::Main();
} else if (chain == CBaseChainParams::TESTNET) {
case ChainType::TESTNET:
return CChainParams::TestNet();
} else if (chain == CBaseChainParams::SIGNET) {
case ChainType::SIGNET: {
auto opts = CChainParams::SigNetOptions{};
ReadSigNetArgs(args, opts);
return CChainParams::SigNet(opts);
} else if (chain == CBaseChainParams::REGTEST) {
}
case ChainType::REGTEST: {
auto opts = CChainParams::RegTestOptions{};
ReadRegTestArgs(args, opts);
return CChainParams::RegTest(opts);
} else if (chain == CBaseChainParams::LIQUID1) {
}
case ChainType::LIQUID1:
return CChainParams::LiquidV1(args);
} else if (chain == CBaseChainParams::LIQUID1TEST) {
case ChainType::LIQUID1TEST:
return CChainParams::LiquidV1Test(args);
} else if (chain == CBaseChainParams::LIQUIDTESTNET) {
case ChainType::LIQUIDTESTNET: {
auto opts = CChainParams::RegTestOptions{};
ReadRegTestArgs(args, opts);
return CChainParams::LiquidTestNet(chain, args, opts);
}
case ChainType::CUSTOM:
// just log the custom chain and fallthrough to the catch-all for custom params
LogPrintf("CreateChainParams for custom chain: %s\n", chain.chain_name);
}
auto opts = CChainParams::RegTestOptions{};
ReadRegTestArgs(args, opts);
return CChainParams::Custom(chain, args, opts);
}
void SelectParams(const std::string& network)
void SelectParams(const ChainTypeMeta chain)
{
SelectBaseParams(network);
globalChainParams = CreateChainParams(gArgs, network);
SelectBaseParams(chain);
globalChainParams = CreateChainParams(gArgs, chain);
}
// ELEMENTS:
// keep the original ChainType constructors, which just call our new ChainTypeMeta constructors
// this helps not to have to change all the other callsites
// in general: don't use these, they're "lossy" for custom chain names
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain) {
return CreateChainParams(args, ChainTypeMetaFrom(chain));
}
void SelectParams(const ChainType chain) {
SelectParams(ChainTypeMetaFrom(chain));
}

View file

@ -8,11 +8,11 @@
#include <kernel/chainparams.h>
#include <chainparamsbase.h>
#include <consensus/params.h>
#include <netaddress.h>
#include <primitives/block.h>
#include <protocol.h>
#include <util/chaintype.h>
#include <util/hash_type.h>
#include <cstdint>
@ -21,12 +21,14 @@
#include <unordered_map>
#include <vector>
class ArgsManager;
/**
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
* @returns a CChainParams* of the chosen chain.
* @throws a std::runtime_error if the chain is not supported.
*/
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain);
/**
* Return the currently selected parameters. This won't change after app
@ -38,6 +40,10 @@ const CChainParams &Params();
* Sets the params returned by Params() to those for the given chain name.
* @throws std::runtime_error when the chain is not supported.
*/
void SelectParams(const std::string& chain);
void SelectParams(const ChainType chain);
// ELEMENTS
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainTypeMeta chain);
void SelectParams(const ChainTypeMeta chain);
#endif // BITCOIN_CHAINPARAMS_H

View file

@ -7,19 +7,10 @@
#include <common/args.h>
#include <tinyformat.h>
#include <util/chaintype.h>
#include <assert.h>
const std::string CBaseChainParams::MAIN = "main";
const std::string CBaseChainParams::TESTNET = "test";
const std::string CBaseChainParams::SIGNET = "signet";
const std::string CBaseChainParams::REGTEST = "regtest";
const std::string CBaseChainParams::LIQUID1 = "liquidv1";
const std::string CBaseChainParams::LIQUID1TEST = "liquidv1test";
const std::string CBaseChainParams::LIQUIDTESTNET = "liquidtestnet";
const std::string CBaseChainParams::DEFAULT = CBaseChainParams::LIQUID1;
void SetupChainParamsBaseOptions(ArgsManager& argsman)
{
argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: liquidv1). Reserved values: main, test, signet, regtest, liquidv1, liquidv1test", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
@ -77,30 +68,39 @@ const CBaseChainParams& BaseParams()
* Port numbers for incoming Tor connections (8334, 18334, 38334, 18445) have
* been chosen arbitrarily to keep ranges of used ports tight.
*/
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainTypeMeta chain)
{
if (chain == CBaseChainParams::MAIN) {
switch (chain.chain_type) {
case ChainType::MAIN:
return std::make_unique<CBaseChainParams>("", 8332, 18332, 8334);
} else if (chain == CBaseChainParams::TESTNET) {
case ChainType::TESTNET:
return std::make_unique<CBaseChainParams>("testnet3", 18332, 8332, 18334);
} else if (chain == CBaseChainParams::SIGNET) {
case ChainType::SIGNET:
return std::make_unique<CBaseChainParams>("signet", 38332, 18332, 38334);
} else if (chain == CBaseChainParams::REGTEST) {
case ChainType::REGTEST:
return std::make_unique<CBaseChainParams>("regtest", 18443, 18332, 18445);
} else if (chain == CBaseChainParams::LIQUID1) {
case ChainType::LIQUID1:
return std::make_unique<CBaseChainParams>("liquidv1", 7041, 8332, 37041);
} else if (chain == CBaseChainParams::LIQUID1TEST) {
case ChainType::LIQUID1TEST:
return std::make_unique<CBaseChainParams>("liquidv1test", 7040, 18332, 37040); // Use same ports as customparams
} else if (chain == CBaseChainParams::LIQUIDTESTNET) {
return std::make_unique<CBaseChainParams>(chain, 7039, 18331, 37039);
case ChainType::LIQUIDTESTNET:
return std::make_unique<CBaseChainParams>("liquidtestnet", 7039, 18331, 37039);
case ChainType::CUSTOM:
return std::make_unique<CBaseChainParams>(chain.chain_name, 7040, 18332, 37040);
}
// ELEMENTS:
return std::make_unique<CBaseChainParams>(chain, 7040, 18332, 37040);
return std::make_unique<CBaseChainParams>(chain.chain_name, 7040, 18332, 37040);
}
void SelectBaseParams(const std::string& chain)
void SelectBaseParams(const ChainTypeMeta chain)
{
globalChainBaseParams = CreateBaseChainParams(chain);
gArgs.SelectConfigNetwork(chain);
gArgs.SelectConfigNetwork(chain.chain_name);
}
// ELEMENTS
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain) {
return CreateBaseChainParams(ChainTypeMetaFrom(chain));
}
void SelectBaseParams(const ChainType chain) {
SelectBaseParams(ChainTypeMetaFrom(chain));
}

View file

@ -6,6 +6,8 @@
#define BITCOIN_CHAINPARAMSBASE_H
#include <cstdint>
#include <util/chaintype.h>
#include <memory>
#include <string>
@ -18,19 +20,6 @@ class ArgsManager;
class CBaseChainParams
{
public:
///@{
/** Chain name strings */
static const std::string MAIN;
static const std::string TESTNET;
static const std::string SIGNET;
static const std::string REGTEST;
static const std::string LIQUID1;
static const std::string LIQUID1TEST;
static const std::string LIQUIDTESTNET;
///@}
static const std::string DEFAULT;
const std::string& DataDir() const { return strDataDir; }
uint16_t RPCPort() const { return m_rpc_port; }
uint16_t OnionServiceTargetPort() const { return m_onion_service_target_port; }
@ -52,7 +41,7 @@ private:
* @returns a CBaseChainParams* of the chosen chain.
* @throws a std::runtime_error if the chain is not supported.
*/
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain);
/**
*Set the arguments for chainparams
@ -65,7 +54,11 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman);
*/
const CBaseChainParams& BaseParams();
/** Sets the params returned by Params() to those for the given network. */
void SelectBaseParams(const std::string& chain);
/** Sets the params returned by Params() to those for the given chain. */
void SelectBaseParams(const ChainType chain);
// ELEMENTS
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainTypeMeta chain);
void SelectBaseParams(const ChainTypeMeta chain);
#endif // BITCOIN_CHAINPARAMSBASE_H

View file

@ -10,6 +10,7 @@
#include <sync.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
@ -33,6 +34,7 @@
#include <stdexcept>
#include <string>
#include <utility>
#include <variant>
#ifdef LIQUID
const char * const BITCOIN_CONF_FILENAME = "liquid.conf";
@ -145,7 +147,7 @@ std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
if (m_network.empty()) return std::set<std::string> {};
// if it's okay to use the default section for this network, don't worry
if (m_network == CBaseChainParams::DEFAULT) return std::set<std::string> {};
if (m_network == ChainTypeToString(ChainType::LIQUID1)) return std::set<std::string> {};
for (const auto& arg : m_network_only_args) {
if (OnlyHasDefaultSectionSetting(m_settings, m_network, SettingName(arg))) {
@ -431,7 +433,7 @@ util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) c
{
LOCK(cs_args);
return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
/*ignore_nonpersistent=*/true, /*get_chain_name=*/false);
/*ignore_nonpersistent=*/true, /*get_chain_type=*/false);
}
bool ArgsManager::IsArgNegated(const std::string& strArg) const
@ -761,40 +763,53 @@ fs::path ArgsManager::GetConfigFilePath() const
return GetConfigFile(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME));
}
std::string ArgsManager::GetChainName() const
ChainType ArgsManager::GetChainType() const
{
std::variant<ChainType, std::string> arg = GetChainArg();
if (auto* parsed = std::get_if<ChainType>(&arg)) return *parsed;
throw std::runtime_error(strprintf("Unknown chain %s.", std::get<std::string>(arg)));
}
std::string ArgsManager::GetChainTypeString() const
{
auto arg = GetChainArg();
if (auto* parsed = std::get_if<ChainType>(&arg)) return ChainTypeToString(*parsed);
return std::get<std::string>(arg);
}
std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
{
auto get_net = [&](const std::string& arg) {
LOCK(cs_args);
util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
/* ignore_default_section_config= */ false,
/*ignore_nonpersistent=*/false,
/* get_chain_name= */ true);
/* get_chain_type= */ true);
return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
};
const bool fRegTest = get_net("-regtest");
const bool fSigNet = get_net("-signet");
const bool fTestNet = get_net("-testnet");
const bool is_chain_arg_set = IsArgSet("-chain");
const auto chain_arg = GetArg("-chain");
if ((int)is_chain_arg_set + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
}
if (fRegTest)
return CBaseChainParams::REGTEST;
if (fSigNet) {
return CBaseChainParams::SIGNET;
if (chain_arg) {
if (auto parsed = ChainTypeFromString(*chain_arg)) return *parsed;
// Not a known string, so return original string
return *chain_arg;
}
if (fTestNet)
return CBaseChainParams::TESTNET;
std::string default_chain = CBaseChainParams::DEFAULT;
return GetArg("-chain", default_chain);
if (fRegTest) return ChainType::REGTEST;
if (fSigNet) return ChainType::SIGNET;
if (fTestNet) return ChainType::TESTNET;
return ChainType::LIQUID1;
}
bool ArgsManager::UseDefaultSection(const std::string& arg) const
{
return m_network == CBaseChainParams::DEFAULT || m_network_only_args.count(arg) == 0;
return m_network == ChainTypeToString(ChainType::LIQUID1) || m_network_only_args.count(arg) == 0;
}
util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
@ -802,7 +817,7 @@ util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
LOCK(cs_args);
return util::GetSetting(
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
/*ignore_nonpersistent=*/false, /*get_chain_name=*/false);
/*ignore_nonpersistent=*/false, /*get_chain_type=*/false);
}
std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
@ -840,6 +855,36 @@ void ArgsManager::LogArgs() const
logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
}
// ELEMENTS
ChainTypeMeta ArgsManager::GetChainTypeMeta() const
{
auto get_net = [&](const std::string& arg) {
LOCK(cs_args);
util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
/* ignore_default_section_config= */ false,
/* ignore_nonpersistent=*/ false,
/* get_chain_type= */ true);
return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
};
const bool fRegTest = get_net("-regtest");
const bool fSigNet = get_net("-signet");
const bool fTestNet = get_net("-testnet");
const auto chain_arg = GetArg("-chain");
if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
}
if (chain_arg) {
return ChainTypeMetaFrom(*chain_arg);
}
if (fRegTest) return { ChainType::REGTEST, "regtest" };
if (fSigNet) return { ChainType::SIGNET, "signet" };
if (fTestNet) return { ChainType::TESTNET, "testnet" };
return { ChainType::LIQUID1, "liquidv1" };
}
// END ELEMENTS
namespace common {
#ifdef WIN32
WinCmdLineArgs::WinCmdLineArgs()

View file

@ -7,6 +7,7 @@
#include <compat/compat.h>
#include <sync.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <util/settings.h>
@ -17,6 +18,7 @@
#include <set>
#include <stdint.h>
#include <string>
#include <variant>
#include <vector>
class ArgsManager;
@ -321,10 +323,17 @@ protected:
/**
* Returns the appropriate chain name from the program arguments.
* @return CBaseChainParams::DEFAULT by default; raises runtime error if an invalid combination is given.
* @return ChainType::MAIN by default; raises runtime error if an invalid
* combination, or unknown chain is given.
*/
std::string GetChainName() const;
ChainType GetChainType() const;
/**
* Returns the appropriate chain name string from the program arguments.
* @return ChainType::MAIN string by default; raises runtime error if an
* invalid combination is given.
*/
std::string GetChainTypeString() const;
/**
* Add argument
@ -400,6 +409,11 @@ protected:
*/
void LogArgs() const;
/**
* ELEMENTS
*/
ChainTypeMeta GetChainTypeMeta() const;
private:
/**
* Get data directory path
@ -409,6 +423,14 @@ private:
*/
const fs::path& GetDataDir(bool net_specific) const;
/**
* Return -regtest/-signet/-testnet/-chain= setting as a ChainType enum if a
* recognized chain name was set, or as a string if an unrecognized chain
* name was set. Raise an exception if an invalid combination of flags was
* provided.
*/
std::variant<ChainType, std::string> GetChainArg() const;
// Helper function for LogArgs().
void logArgsPrefix(
const std::string& prefix,

View file

@ -8,6 +8,7 @@
#include <sync.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <util/settings.h>
#include <util/string.h>
@ -152,7 +153,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
}
}
if (use_conf_file) {
std::string chain_id = GetChainName();
std::string chain_id = GetChainTypeString();
std::vector<std::string> conf_file_names;
auto add_includes = [&](const std::string& network, size_t skip = 0) {
@ -191,7 +192,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
conf_file_names.clear();
add_includes(chain_id, /* skip= */ chain_includes);
add_includes({}, /* skip= */ default_includes);
std::string chain_id_final = GetChainName();
std::string chain_id_final = GetChainTypeString();
if (chain_id_final != chain_id) {
// Also warn about recursive includeconf for the chain that was specified in one of the includeconfs
add_includes(chain_id_final);

View file

@ -26,7 +26,7 @@ std::optional<ConfigError> InitConfig(ArgsManager& args, SettingsAbortFn setting
}
// Check for chain settings (Params() calls are only valid after this clause)
SelectParams(args.GetChainName());
SelectParams(args.GetChainTypeMeta());
// Create datadir if it does not exist.
const auto base_path{args.GetDataDirBase()};

View file

@ -18,6 +18,7 @@
#include <blockfilter.h>
#include <chain.h>
#include <chainparams.h>
#include <chainparamsbase.h>
#include <common/args.h>
#include <consensus/amount.h>
#include <deploymentstatus.h>
@ -70,6 +71,7 @@
#include <txdb.h>
#include <txmempool.h>
#include <util/asmap.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
@ -418,16 +420,16 @@ void SetupServerArgs(ArgsManager& argsman)
init::AddLoggingArgs(argsman);
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::DEFAULT);
const auto mainnetBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET);
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
const auto defaultChainParams = CreateChainParams(argsman, CBaseChainParams::DEFAULT);
const auto mainnetChainParams = CreateChainParams(argsman, CBaseChainParams::MAIN);
const auto testnetChainParams = CreateChainParams(argsman, CBaseChainParams::TESTNET);
const auto signetChainParams = CreateChainParams(argsman, CBaseChainParams::SIGNET);
const auto regtestChainParams = CreateChainParams(argsman, CBaseChainParams::REGTEST);
const auto defaultBaseParams = CreateBaseChainParams(ChainType::LIQUID1);
const auto mainnetBaseParams = CreateBaseChainParams(ChainType::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET);
const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET);
const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST);
const auto defaultChainParams = CreateChainParams(argsman, ChainType::LIQUID1);
const auto mainnetChainParams = CreateChainParams(argsman, ChainType::MAIN);
const auto testnetChainParams = CreateChainParams(argsman, ChainType::TESTNET);
const auto signetChainParams = CreateChainParams(argsman, ChainType::SIGNET);
const auto regtestChainParams = CreateChainParams(argsman, ChainType::REGTEST);
// Hidden Options
std::vector<std::string> hidden_args = {
@ -900,14 +902,14 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
// Error if network-specific options (-addnode, -connect, etc) are
// specified in default section of config file, but not overridden
// on the command line or in this network's section of the config file.
std::string network = args.GetChainName();
if (network == CBaseChainParams::SIGNET) {
// on the command line or in this chain's section of the config file.
ChainTypeMeta chain = args.GetChainTypeMeta(); // ELEMENTS
if (chain.chain_type == ChainType::SIGNET) {
LogPrintf("Signet derived magic (message start): %s\n", HexStr(chainparams.MessageStart()));
}
bilingual_str errors;
for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) {
errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network);
errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, chain.chain_name, chain.chain_name);
}
if (!errors.empty()) {

View file

@ -10,13 +10,13 @@
#include <consensus/merkle.h>
#include <consensus/params.h>
#include <hash.h>
#include <chainparamsbase.h>
#include <logging.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <script/script.h>
#include <uint256.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <issuance.h>
@ -190,7 +190,7 @@ static void UpdateElementsActivationParametersFromArgs(Consensus::Params& consen
class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = CBaseChainParams::MAIN;
m_chain_type = ChainTypeMetaFrom(ChainType::MAIN);
consensus.signet_blocks = false;
consensus.signet_challenge.clear();
consensus.nSubsidyHalvingInterval = 210000;
@ -341,7 +341,7 @@ public:
class CTestNetParams : public CChainParams {
public:
CTestNetParams() {
strNetworkID = CBaseChainParams::TESTNET;
m_chain_type = ChainTypeMetaFrom(ChainType::TESTNET);
consensus.signet_blocks = false;
consensus.signet_challenge.clear();
consensus.nSubsidyHalvingInterval = 210000;
@ -506,7 +506,7 @@ public:
vSeeds = *options.seeds;
}
strNetworkID = CBaseChainParams::SIGNET;
m_chain_type = ChainTypeMetaFrom(ChainType::SIGNET);
consensus.signet_blocks = true;
consensus.signet_challenge.assign(bin.begin(), bin.end());
consensus.nSubsidyHalvingInterval = 210000;
@ -603,7 +603,7 @@ class CRegTestParams : public CChainParams
public:
explicit CRegTestParams(const RegTestOptions& opts)
{
strNetworkID = CBaseChainParams::REGTEST;
m_chain_type = ChainTypeMetaFrom(ChainType::REGTEST);
consensus.signet_blocks = false;
consensus.signet_challenge.clear();
consensus.nSubsidyHalvingInterval = 150;
@ -964,7 +964,7 @@ protected:
accept_discount_ct = args.GetBoolArg("-acceptdiscountct", accept_discount_ct) || create_discount_ct;
// Calculate pegged Bitcoin asset
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name);
uint256 entropy;
GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash);
@ -996,7 +996,7 @@ protected:
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN, consensus);
} else if (consensus.genesis_style == "elements") {
// Intended compatibility with Liquid v1 and elements-0.14.1
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name);
genesis = CreateGenesisBlock(consensus, CScript() << commit, CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0);
if (initialFreeCoins != 0 || initial_reissuance_tokens != 0) {
AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), parentGenesisBlockHash, (initialFreeCoins > 0) ? 1 : 0, initialFreeCoins, (initial_reissuance_tokens > 0) ? 1 : 0, initial_reissuance_tokens, CScript() << OP_TRUE);
@ -1012,9 +1012,9 @@ protected:
}
public:
CCustomParams(const std::string& chain, const ArgsManager& args, const RegTestOptions& opts) : CRegTestParams(opts)
CCustomParams(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& opts) : CRegTestParams(opts)
{
strNetworkID = chain;
m_chain_type = chain;
//default settings
initialFreeCoins = 0;
@ -1052,9 +1052,9 @@ public:
*/
class CLiquidTestNetParams : public CCustomParams {
public:
CLiquidTestNetParams(const std::string& chain, const ArgsManager& args, const RegTestOptions& opts) : CCustomParams(chain, args, opts)
CLiquidTestNetParams(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& opts) : CCustomParams(chain, args, opts)
{
strNetworkID = chain;
m_chain_type = chain;
// not a debug chain
fDefaultConsistencyChecks = false;
@ -1111,7 +1111,7 @@ public:
explicit CLiquidV1Params(const ArgsManager& args)
{
strNetworkID = "liquidv1";
m_chain_type = ChainTypeMetaFrom(ChainType::LIQUID1);
consensus.nSubsidyHalvingInterval = 150;
consensus.BIP34Height = 0;
consensus.BIP34Hash = uint256();
@ -1218,7 +1218,7 @@ public:
// Calculate pegged Bitcoin asset
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name);
uint256 entropy;
GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash);
@ -1360,7 +1360,7 @@ public:
{
// Our goal here is to override ONLY the things from liquidv1 that make no sense for a test chain / which are pointless and burdensome to require people to override manually.
strNetworkID = "liquidv1test";
m_chain_type = ChainTypeMetaFrom(ChainType::LIQUID1TEST);
m_is_test_chain = true;
m_is_mockable_chain = false;
@ -1584,7 +1584,7 @@ public:
consensus.total_valid_epochs = args.GetIntArg("-total_valid_epochs", consensus.total_valid_epochs);
// Calculate pegged Bitcoin asset
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name);
uint256 entropy;
GenerateAssetEntropy(entropy, COutPoint(uint256(commit), 0), parentGenesisBlockHash);
CalculateAsset(consensus.pegged_asset, entropy);
@ -1615,7 +1615,7 @@ public:
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN, consensus);
} else if (consensus.genesis_style == "elements") {
// Intended compatibility with Liquid v1 and elements-0.14.1
std::vector<unsigned char> commit = CommitToArguments(consensus, strNetworkID);
std::vector<unsigned char> commit = CommitToArguments(consensus, m_chain_type.chain_name);
genesis = CreateGenesisBlock(consensus, CScript() << commit, CScript(OP_RETURN), 1296688602, 2, 0x207fffff, 1, 0);
if (initialFreeCoins != 0 || initial_reissuance_tokens != 0) {
AppendInitialIssuance(genesis, COutPoint(uint256(commit), 0), parentGenesisBlockHash, (initialFreeCoins > 0) ? 1 : 0, initialFreeCoins, (initial_reissuance_tokens > 0) ? 1 : 0, initial_reissuance_tokens, CScript() << OP_TRUE);
@ -1631,12 +1631,12 @@ public:
}
};
std::unique_ptr<const CChainParams> CChainParams::Custom(const std::string& chain, const ArgsManager& args, const RegTestOptions& options)
std::unique_ptr<const CChainParams> CChainParams::Custom(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& options)
{
return std::make_unique<const CCustomParams>(chain, args, options);
}
std::unique_ptr<const CChainParams> CChainParams::LiquidTestNet(const std::string& chain, const ArgsManager& args, const RegTestOptions& options)
std::unique_ptr<const CChainParams> CChainParams::LiquidTestNet(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& options)
{
return std::make_unique<const CLiquidTestNetParams>(chain, args, options);
}

View file

@ -12,6 +12,7 @@
#include <primitives/block.h>
#include <protocol.h>
#include <uint256.h>
#include <util/chaintype.h>
#include <util/hash_type.h>
#include <util/system.h>
@ -120,8 +121,10 @@ public:
uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
/** Whether it is possible to mine blocks on demand (no retargeting) */
bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
/** Return the network string */
std::string NetworkIDString() const { return strNetworkID; }
/** Return the chain type string */
std::string GetChainTypeString() const { return m_chain_type.chain_name; }
/** Return the chain type */
ChainTypeMeta GetChainTypeMeta() const { return m_chain_type; }
/** Return the list of hostnames to look up for DNS seeds */
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
@ -172,10 +175,10 @@ public:
bool fastprune{false};
};
static std::unique_ptr<const CChainParams> LiquidTestNet(const std::string& chain, const ArgsManager& args, const RegTestOptions& options);
static std::unique_ptr<const CChainParams> LiquidTestNet(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& options);
static std::unique_ptr<const CChainParams> LiquidV1Test(const ArgsManager& args);
static std::unique_ptr<const CChainParams> LiquidV1(const ArgsManager& args);
static std::unique_ptr<const CChainParams> Custom(const std::string& chain, const ArgsManager& args, const RegTestOptions& options);
static std::unique_ptr<const CChainParams> Custom(const ChainTypeMeta chain, const ArgsManager& args, const RegTestOptions& options);
static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
static std::unique_ptr<const CChainParams> Main();
@ -194,7 +197,7 @@ protected:
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::string bech32_hrp;
std::string blech32_hrp;
std::string strNetworkID;
ChainTypeMeta m_chain_type;
CBlock genesis;
CAmount initialFreeCoins;
CAmount initial_reissuance_tokens;

View file

@ -240,7 +240,7 @@ public:
std::vector<ExternalSigner> signers = {};
const std::string command = args().GetArg("-signer", "");
if (command == "") return {};
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
result.reserve(signers.size());
for (auto& signer : signers) {

View file

@ -89,7 +89,7 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, con
mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString());
return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.GetChainTypeString());
}
mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);

View file

@ -574,7 +574,7 @@ int GuiMain(int argc, char* argv[])
return EXIT_FAILURE;
}
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().GetChainTypeMeta().chain_type));
assert(!networkStyle.isNull());
// Allow for separate UI settings for testnets
QApplication::setApplicationName(networkStyle->getAppName());

View file

@ -23,6 +23,7 @@
#include <protocol.h>
#include <script/script.h>
#include <script/standard.h>
#include <util/chaintype.h>
#include <util/exception.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
@ -511,14 +512,14 @@ bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
#ifdef WIN32
fs::path static StartupShortcutPath()
{
std::string chain = gArgs.GetChainName();
if (chain == CBaseChainParams::MAIN)
ChainType chain = gArgs.GetChainType();
if (chain == ChainType::MAIN)
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
if (chain == CBaseChainParams::LIQUID1)
if (chain == ChainType::LIQUID1)
return GetSpecialFolderPath(CSIDL_STARTUP) / "Liquid.lnk";
if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
if (chain == ChainType::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk";
return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Elements (%s).lnk", chain));
return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Elements (%s).lnk", ChainTypeToString(chain)));
}
bool GetStartOnSystemStartup()
@ -551,7 +552,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
// Start client minimized
QString strArgs = "-min";
// Set -testnet /-regtest options
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainTypeString()));
// Set the path to the shortcut target
psl->SetPath(pszExePath);
@ -596,12 +597,12 @@ fs::path static GetAutostartDir()
fs::path static GetAutostartFilePath()
{
std::string chain = gArgs.GetChainName();
if (chain == CBaseChainParams::MAIN)
ChainType chain = gArgs.GetChainType();
if (chain == ChainType::MAIN)
return GetAutostartDir() / "bitcoin.desktop";
if (chain == CBaseChainParams::LIQUID1)
if (chain == ChainType::LIQUID1)
return GetAutostartDir() / "liquid.desktop";
return GetAutostartDir() / fs::u8path(strprintf("elements-%s.desktop", chain));
return GetAutostartDir() / fs::u8path(strprintf("elements-%s.desktop", ChainTypeToString(chain)));
}
bool GetStartOnSystemStartup()
@ -641,17 +642,17 @@ bool SetStartOnSystemStartup(bool fAutoStart)
std::ofstream optionFile{GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc};
if (!optionFile.good())
return false;
std::string chain = gArgs.GetChainName();
ChainType chain = gArgs.GetChainType();
// Write a bitcoin.desktop file to the autostart directory:
optionFile << "[Desktop Entry]\n";
optionFile << "Type=Application\n";
if (chain == CBaseChainParams::MAIN)
if (chain == ChainType::MAIN)
optionFile << "Name=Bitcoin\n";
else if (chain == CBaseChainParams::LIQUID1)
else if (chain == ChainType::LIQUID1)
optionFile << "Name=Liquid\n";
else
optionFile << strprintf("Name=Elements (%s)\n", chain);
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
optionFile << strprintf("Name=Elements (%s)\n", ChainTypeToString(chain));
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", ChainTypeToString(chain));
optionFile << "Terminal=false\n";
optionFile << "Hidden=false\n";
optionFile.close();

View file

@ -9,6 +9,7 @@
#include <chainparams.h>
#include <qt/intro.h>
#include <qt/forms/ui_intro.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <qt/guiconstants.h>
@ -219,7 +220,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
{
/* Use selectParams here to guarantee Params() can be used by node interface */
try {
SelectParams(gArgs.GetChainName());
SelectParams(gArgs.GetChainTypeMeta());
} catch (const std::exception&) {
return false;
}

View file

@ -6,23 +6,23 @@
#include <qt/guiconstants.h>
#include <chainparamsbase.h>
#include <tinyformat.h>
#include <util/chaintype.h>
#include <QApplication>
static const struct {
const char *networkId;
const ChainType networkId;
const char *appName;
const int iconColorHueShift;
const int iconColorSaturationReduction;
} network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
{"test", QAPP_APP_NAME_TESTNET, 70, 30},
{"liquidv1", QAPP_APP_NAME_LIQUID, 0, 0},
{"liquidtestnet", QAPP_APP_NAME_LIQUIDTESTNET, 80, 80},
{"signet", QAPP_APP_NAME_SIGNET, 35, 15},
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30}
{ChainType::MAIN, QAPP_APP_NAME_DEFAULT, 0, 0},
{ChainType::TESTNET, QAPP_APP_NAME_TESTNET, 70, 30},
{ChainType::SIGNET, QAPP_APP_NAME_SIGNET, 35, 15},
{ChainType::REGTEST, QAPP_APP_NAME_REGTEST, 160, 30},
{ChainType::LIQUID1, QAPP_APP_NAME_LIQUID, 0, 0},
{ChainType::LIQUIDTESTNET, QAPP_APP_NAME_LIQUIDTESTNET, 80, 80},
};
// titleAddText needs to be const char* for tr()
@ -79,9 +79,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
}
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
const NetworkStyle* NetworkStyle::instantiate(const ChainType networkId)
{
std::string titleAddText = networkId == "liquidv1" ? "" : strprintf("[%s]", networkId);
std::string titleAddText = networkId == ChainType::LIQUID1 ? "" : strprintf("[%s]", ChainTypeToString(networkId));
for (const auto& network_style : network_styles) {
if (networkId == network_style.networkId)
return new NetworkStyle(
@ -91,9 +91,9 @@ const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
titleAddText.c_str());
}
// If it doesn't match any, use regtest since it's a custom chain
assert(networkId != "regtest");
assert(networkId != ChainType::REGTEST);
// but keep the chain name in the title
NetworkStyle* instance = const_cast<NetworkStyle*>(instantiate("regtest"));
NetworkStyle* instance = const_cast<NetworkStyle*>(instantiate(ChainType::REGTEST));
instance->titleAddText = titleAddText.c_str();
return instance;
}

View file

@ -5,6 +5,8 @@
#ifndef BITCOIN_QT_NETWORKSTYLE_H
#define BITCOIN_QT_NETWORKSTYLE_H
#include <util/chaintype.h>
#include <QIcon>
#include <QPixmap>
#include <QString>
@ -14,7 +16,7 @@ class NetworkStyle
{
public:
/** Get style associated with provided network id, or 0 if not known */
static const NetworkStyle* instantiate(const std::string& networkId);
static const NetworkStyle* instantiate(const ChainType networkId);
const QString &getAppName() const { return appName; }
const QIcon &getAppIcon() const { return appIcon; }

View file

@ -748,7 +748,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->dataDir->setText(model->dataDir());
ui->blocksDir->setText(model->blocksDir());
ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
ui->networkName->setText(QString::fromStdString(Params().GetChainTypeString()));
//Setup autocomplete and attach it
QStringList wordList;

View file

@ -73,7 +73,7 @@ void AppTests::appTests()
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
m_app.parameterSetup();
QVERIFY(m_app.createOptionsModel(/*resetSettings=*/true));
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString()));
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().GetChainTypeMeta().chain_type));
m_app.setupPlatformStyle();
m_app.createWindow(style.data());
connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests);

View file

@ -14,6 +14,7 @@
#include <qt/test/rpcnestedtests.h>
#include <qt/test/uritests.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#ifdef ENABLE_WALLET
#include <qt/test/addressbooktests.h>
@ -57,7 +58,7 @@ int main(int argc, char* argv[])
//
// All tests must use their own testing setup (if needed).
fs::create_directories([] {
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
BasicTestingSetup dummy{ChainType::REGTEST};
return gArgs.GetDataDirNet() / "blocks";
}());

View file

@ -1420,7 +1420,7 @@ RPCHelpMan getblockchaininfo()
const int height{tip.nHeight};
UniValue obj(UniValue::VOBJ);
obj.pushKV("chain", chainparams.NetworkIDString());
obj.pushKV("chain", chainparams.GetChainTypeString());
obj.pushKV("blocks", height);
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex());

View file

@ -2,7 +2,6 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparamsbase.h>
#include <common/args.h>
#include <external_signer.h>
#include <rpc/protocol.h>
@ -43,7 +42,7 @@ static RPCHelpMan enumeratesigners()
{
const std::string command = gArgs.GetArg("-signer", "");
if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>");
const std::string chain = gArgs.GetChainName();
const std::string chain = gArgs.GetChainTypeString();
UniValue signers_res = UniValue::VARR;
try {
std::vector<ExternalSigner> signers;

View file

@ -457,7 +457,7 @@ static RPCHelpMan getmininginfo()
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
}
obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", chainman.GetParams().NetworkIDString());
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
obj.pushKV("warnings", GetWarnings(false).original);
return obj;
},

View file

@ -21,6 +21,7 @@
#include <rpc/util.h>
#include <sync.h>
#include <timedata.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/time.h>
@ -354,7 +355,7 @@ static RPCHelpMan addconnection()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (Params().NetworkIDString().find("regtest") == std::string::npos) {
if (Params().GetChainTypeMeta().chain_name.find("regtest") == std::string::npos) {
throw std::runtime_error("addconnection is for regression testing (chain should have \"regtest\" in the name) only.");
}

View file

@ -138,7 +138,7 @@ static fs::path GetMainchainAuthCookieFile()
{
std::string cookie_file = MAINCHAIN_COOKIEAUTH_FILE;
// Bitcoin mainnet exception
if (gArgs.GetChainName() == "liquidv1") {
if (gArgs.GetChainTypeMeta().chain_type == ChainType::LIQUID1) {
cookie_file = ".cookie";
}
fs::path cookie_path = fs::PathFromString(gArgs.GetArg("-mainchainrpccookiefile", cookie_file));

View file

@ -8,6 +8,7 @@
#include <test/util/setup_common.h>
#include <test/util/str.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <util/strencodings.h>
@ -580,7 +581,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
test_args.SetNetworkOnlyArg("-ccc");
test_args.SetNetworkOnlyArg("-h");
test_args.SelectConfigNetwork(CBaseChainParams::DEFAULT);
test_args.SelectConfigNetwork(ChainTypeToString(ChainType::LIQUID1));
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e");
BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2);
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
@ -637,7 +638,7 @@ BOOST_AUTO_TEST_CASE(util_GetArg)
BOOST_CHECK_EQUAL(testArgs.GetArg("pritest4", "default"), "b");
}
BOOST_AUTO_TEST_CASE(util_GetChainName)
BOOST_AUTO_TEST_CASE(util_GetChainTypeString)
{
TestArgsManager test_args;
const auto testnet = std::make_pair("-testnet", ArgsManager::ALLOW_ANY);
@ -656,39 +657,39 @@ BOOST_AUTO_TEST_CASE(util_GetChainName)
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
std::string default_chain = "liquidv1";
BOOST_CHECK_EQUAL(test_args.GetChainName(), default_chain);
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), default_chain);
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
BOOST_CHECK_EQUAL(test_args.GetChainName(), "regtest");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "regtest");
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error));
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error);
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error);
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error);
// check setting the network to test (and thus making
// [test] regtest=1 potentially relevant) doesn't break things
@ -696,23 +697,23 @@ BOOST_AUTO_TEST_CASE(util_GetChainName)
BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error);
BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_test_no_reg, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_EQUAL(test_args.GetChainName(), "test");
BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test");
BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error));
test_args.ReadConfigString(testnetconf);
BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error);
BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error);
}
// Test different ways settings can be merged, and verify results. This test can
@ -756,8 +757,8 @@ struct ArgsMergeTestingSetup : public BasicTestingSetup {
ForEachNoDup(conf_actions, SET, SECTION_NEGATE, [&] {
for (bool soft_set : {false, true}) {
for (bool force_set : {false, true}) {
for (const std::string& section : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET}) {
for (const std::string& network : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET}) {
for (const std::string& section : {ChainTypeToString(ChainType::MAIN), ChainTypeToString(ChainType::TESTNET), ChainTypeToString(ChainType::SIGNET)}) {
for (const std::string& network : {ChainTypeToString(ChainType::MAIN), ChainTypeToString(ChainType::TESTNET), ChainTypeToString(ChainType::SIGNET)}) {
for (bool net_specific : {false, true}) {
fn(arg_actions, conf_actions, soft_set, force_set, section, network, net_specific);
}
@ -914,7 +915,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup)
BOOST_CHECK_EQUAL(out_sha_hex, "f0a5a84ec85569ae13bf8c94f0dd5d5c6989c84041fb56bd4fb41e1a09818e40");
}
// Similar test as above, but for ArgsManager::GetChainName function.
// Similar test as above, but for ArgsManager::GetChainTypeString function.
struct ChainMergeTestingSetup : public BasicTestingSetup {
static constexpr int MAX_ACTIONS = 2;
@ -983,7 +984,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup)
desc += " || ";
try {
desc += parser.GetChainName();
desc += parser.GetChainTypeString();
} catch (const std::runtime_error& e) {
desc += "error: ";
desc += e.what();

View file

@ -16,7 +16,7 @@
// For elements serialization rules
struct ElementsSetup : public TestingSetup {
ElementsSetup() : TestingSetup("custom") {}
ElementsSetup() : TestingSetup(ChainType::CUSTOM) {}
};
BOOST_FIXTURE_TEST_SUITE(blind_tests, ElementsSetup)

View file

@ -5,6 +5,7 @@
#include <chainparams.h>
#include <node/blockstorage.h>
#include <node/context.h>
#include <util/chaintype.h>
#include <validation.h>
#include <boost/test/unit_test.hpp>
@ -20,7 +21,7 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
{
const auto params {CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)};
const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)};
node::BlockManager::Options blockman_opts{
.chainparams = *params,
};

View file

@ -7,6 +7,7 @@
#include <sync.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <util/time.h>
#include <boost/test/unit_test.hpp>
@ -27,9 +28,9 @@
struct NoLockLoggingTestingSetup : public TestingSetup {
NoLockLoggingTestingSetup()
#ifdef DEBUG_LOCKCONTENTION
: TestingSetup{CBaseChainParams::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {}
: TestingSetup{ChainType::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {}
#else
: TestingSetup{CBaseChainParams::MAIN} {}
: TestingSetup{ChainType::MAIN} {}
#endif
};

View file

@ -16,6 +16,7 @@
#include <test/util/setup_common.h>
#include <time.h>
#include <util/asmap.h>
#include <util/chaintype.h>
#include <cassert>
#include <cstdint>
@ -34,7 +35,7 @@ int32_t GetCheckRatio()
void initialize_addrman()
{
static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::REGTEST);
static const auto testing_setup = MakeNoLogFileContext<>(ChainType::REGTEST);
g_setup = testing_setup.get();
}

View file

@ -11,6 +11,7 @@
#include <pubkey.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <validation.h>
#include <version.h>
@ -19,7 +20,7 @@
void initialize_block()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(block, initialize_block)

View file

@ -21,9 +21,9 @@ FUZZ_TARGET(bloom_filter)
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
// ELEMENTS: needed as Solver depends on Params()
if (fuzzed_data_provider.ConsumeBool()) {
SelectParams(CBaseChainParams::LIQUID1);
SelectParams(ChainType::LIQUID1);
} else {
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
}
CBloomFilter bloom_filter{

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsbase.h>
#include <coins.h>
#include <consensus/amount.h>
#include <consensus/tx_check.h>

View file

@ -4,7 +4,6 @@
#include <addrman.h>
#include <chainparams.h>
#include <chainparamsbase.h>
#include <common/args.h>
#include <net.h>
#include <netaddress.h>

View file

@ -6,11 +6,12 @@
#include <pubkey.h>
#include <script/descriptor.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
void initialize_descriptor_parse()
{
ECC_Start();
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
}
FUZZ_TARGET_INIT(descriptor_parse, initialize_descriptor_parse)

View file

@ -52,7 +52,7 @@ void initialize_deserialize()
FUZZ_TARGET_INIT(name, initialize_deserialize) \
{ \
try { \
SelectParams(CBaseChainParams::LIQUID1); /* ELEMENTS */ \
SelectParams(ChainType::LIQUID1); /* ELEMENTS */ \
code \
} catch (const invalid_fuzzing_input_exception&) { \
} \

View file

@ -6,6 +6,7 @@
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <uint256.h>
#include <util/chaintype.h>
#include <util/time.h>
#include <validation.h>
@ -15,7 +16,7 @@
static void initialize_headers_sync_state_fuzz()
{
static const auto testing_setup = MakeNoLogFileContext<>(
/*chain_name=*/CBaseChainParams::MAIN);
/*chain_type=*/ChainType::MAIN);
}
void MakeHeadersContinuous(

View file

@ -26,6 +26,7 @@
#include <test/fuzz/util.h>
#include <uint256.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/moneystr.h>
#include <util/overflow.h>
@ -42,7 +43,7 @@
void initialize_integer()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(integer, initialize_integer)

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsbase.h>
#include <key.h>
#include <key_io.h>
#include <outputtype.h>
@ -17,6 +16,7 @@
#include <script/standard.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <cassert>
@ -28,7 +28,7 @@
void initialize_key()
{
ECC_Start();
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(key, initialize_key)

View file

@ -5,6 +5,7 @@
#include <chainparams.h>
#include <key_io.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <cassert>
#include <cstdint>
@ -14,7 +15,7 @@
void initialize_key_io()
{
ECC_Start();
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
}
FUZZ_TARGET_INIT(key_io, initialize_key_io)

View file

@ -7,6 +7,7 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/chaintype.h>
#include <util/message.h>
#include <util/strencodings.h>
@ -19,7 +20,7 @@
void initialize_message()
{
ECC_Start();
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(message, initialize_message)

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsbase.h>
#include <net.h>
#include <net_permissions.h>
#include <netaddress.h>
@ -16,6 +15,7 @@
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <util/asmap.h>
#include <util/chaintype.h>
#include <cstdint>
#include <optional>
@ -24,7 +24,7 @@
void initialize_net()
{
static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::MAIN);
static const auto testing_setup = MakeNoLogFileContext<>(ChainType::MAIN);
}
FUZZ_TARGET_INIT(net, initialize_net)

View file

@ -9,6 +9,7 @@
#include <protocol.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <cassert>
#include <cstdint>
@ -18,7 +19,7 @@
void initialize_p2p_transport_serialization()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serialization)

View file

@ -7,13 +7,14 @@
#include <rpc/client.h>
#include <rpc/util.h>
#include <test/fuzz/fuzz.h>
#include <util/chaintype.h>
#include <limits>
#include <string>
void initialize_parse_univalue()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(parse_univalue, initialize_parse_univalue)

View file

@ -9,6 +9,7 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/overflow.h>
@ -19,7 +20,7 @@
void initialize_pow()
{
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
}
FUZZ_TARGET_INIT(pow, initialize_pow)

View file

@ -19,6 +19,7 @@
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <test/util/validation.h>
#include <util/chaintype.h>
#include <validationinterface.h>
#include <version.h>
@ -57,7 +58,7 @@ void initialize_process_message()
Assert(GetNumMsgTypes() == getAllNetMessageTypes().size()); // If this fails, add or remove the message type below
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
/*chain_name=*/CBaseChainParams::REGTEST,
/*chain_type=*/ChainType::REGTEST,
/*extra_args=*/{"-txreconciliation"});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {

View file

@ -24,7 +24,7 @@ const TestingSetup* g_setup;
void initialize_process_messages()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
/*chain_name=*/CBaseChainParams::REGTEST,
/*chain_type=*/ChainType::REGTEST,
/*extra_args=*/{"-txreconciliation"});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {

View file

@ -27,7 +27,7 @@ FUZZ_TARGET(psbt)
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
PartiallySignedTransaction psbt_mut;
// ELEMENTS: needed as Solver depends on Params()
SelectParams(CBaseChainParams::LIQUID1);
SelectParams(ChainType::LIQUID1);
std::string error;
auto str = fuzzed_data_provider.ConsumeRandomLengthString();
if (!DecodeRawPSBT(psbt_mut, MakeByteSpan(str), error)) {

View file

@ -28,7 +28,7 @@ void initialize_rbf(void) {
g_setup = testing_setup.get();
// ELEMENTS: our mempool needs Params() to be set for multiple reasons -- to check
// the discount CT rate, to figure out pegin policy, etc
SelectParams(CBaseChainParams::LIQUID1);
SelectParams(ChainType::LIQUID1);
}
FUZZ_TARGET_INIT(rbf, initialize_rbf)

View file

@ -23,6 +23,7 @@
#include <test/util/setup_common.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/time.h>
@ -37,7 +38,7 @@
namespace {
struct RPCFuzzTestingSetup : public TestingSetup {
RPCFuzzTestingSetup(const std::string& chain_name, const std::vector<const char*>& extra_args, const std::string& fedpegscript) : TestingSetup{chain_name, extra_args, fedpegscript}
RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args, const std::string& fedpegscript) : TestingSetup{chain_type, extra_args, fedpegscript}
{
}

View file

@ -22,6 +22,7 @@
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <algorithm>
#include <cassert>
@ -32,7 +33,7 @@
void initialize_script()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(script, initialize_script)

View file

@ -11,10 +11,11 @@
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <univalue.h>
#include <util/chaintype.h>
void initialize_script_format()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(script_format, initialize_script_format)

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsbase.h>
#include <key.h>
#include <pubkey.h>
#include <script/sigcache.h>

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <chainparamsbase.h>
#include <key.h>
#include <psbt.h>
#include <pubkey.h>
@ -14,6 +13,7 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/chaintype.h>
#include <util/translation.h>
#include <cassert>
@ -27,7 +27,7 @@
void initialize_script_sign()
{
ECC_Start();
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(script_sign, initialize_script_sign)

View file

@ -11,6 +11,7 @@
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <cstdint>
#include <optional>
@ -18,7 +19,7 @@
void initialize_signet()
{
static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::SIGNET);
static const auto testing_setup = MakeNoLogFileContext<>(ChainType::SIGNET);
}
FUZZ_TARGET_INIT(signet, initialize_signet)

View file

@ -108,7 +108,7 @@ FUZZ_TARGET_INIT(system, initialize_system)
(void)args_manager.GetArgs(s1);
(void)args_manager.GetBoolArg(s1, b);
try {
(void)args_manager.GetChainName();
(void)args_manager.GetChainTypeString();
} catch (const std::runtime_error&) {
}
(void)args_manager.GetHelpMessage();

View file

@ -15,6 +15,7 @@
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/rbf.h>
#include <validation.h>
#include <version.h>
@ -23,7 +24,7 @@
void initialize_transaction()
{
SelectParams(CBaseChainParams::REGTEST);
SelectParams(ChainType::REGTEST);
}
FUZZ_TARGET_INIT(transaction, initialize_transaction)

View file

@ -6,7 +6,6 @@
#define BITCOIN_TEST_FUZZ_UTIL_H
#include <arith_uint256.h>
#include <chainparamsbase.h>
#include <coins.h>
#include <compat/compat.h>
#include <consensus/amount.h>

View file

@ -10,6 +10,7 @@
#include <test/fuzz/util.h>
#include <test/util/mining.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <validation.h>
#include <validationinterface.h>
@ -22,7 +23,7 @@ const std::vector<std::shared_ptr<CBlock>>* g_chain;
void initialize_chain()
{
const auto params{CreateChainParams(ArgsManager{}, CBaseChainParams::REGTEST)};
const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)};
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
g_chain = &chain;
}

View file

@ -14,6 +14,7 @@
#include <test/fuzz/util.h>
#include <test/util/mining.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <validation.h>
#include <version.h>
@ -21,7 +22,7 @@ FUZZ_TARGET(utxo_total_supply)
{
/** The testing setup that creates a chainman only (no chainstate) */
ChainTestingSetup test_setup{
CBaseChainParams::REGTEST,
ChainType::REGTEST,
{
"-testactivationheight=bip34@2",
},

View file

@ -4,7 +4,6 @@
#include <kernel/mempool_persist.h>
#include <chainparamsbase.h>
#include <node/mempool_args.h>
#include <node/mempool_persist_args.h>
#include <test/fuzz/FuzzedDataProvider.h>

View file

@ -7,6 +7,7 @@
#include <common/args.h>
#include <consensus/params.h>
#include <primitives/block.h>
#include <util/chaintype.h>
#include <versionbits.h>
#include <test/fuzz/FuzzedDataProvider.h>
@ -104,7 +105,7 @@ std::unique_ptr<const CChainParams> g_params;
void initialize()
{
// this is actually comparatively slow, so only do it once
g_params = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN);
g_params = CreateChainParams(ArgsManager{}, ChainType::MAIN);
assert(g_params != nullptr);
}

View file

@ -10,6 +10,7 @@
#include <script/script.h>
#include <test/util/json.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <boost/test/unit_test.hpp>
@ -24,7 +25,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse)
UniValue tests = read_json(std::string(json_tests::key_io_valid, json_tests::key_io_valid + sizeof(json_tests::key_io_valid)));
CKey privkey;
CTxDestination destination;
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
for (unsigned int idx = 0; idx < tests.size(); idx++) {
const UniValue& test = tests[idx];
@ -37,7 +38,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse)
const std::vector<std::byte> exp_payload{ParseHex<std::byte>(test[1].get_str())};
const UniValue &metadata = test[2].get_obj();
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
SelectParams(find_value(metadata, "chain").get_str());
SelectParams(ChainTypeMetaFrom(find_value(metadata, "chain").get_str()));
bool try_case_flip = find_value(metadata, "tryCaseFlip").isNull() ? false : find_value(metadata, "tryCaseFlip").get_bool();
if (isPrivkey) {
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
@ -96,7 +97,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen)
std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str());
const UniValue &metadata = test[2].get_obj();
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
SelectParams(find_value(metadata, "chain").get_str());
SelectParams(ChainTypeMetaFrom(find_value(metadata, "chain").get_str()));
if (isPrivkey) {
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
CKey key;
@ -113,7 +114,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen)
}
}
SelectParams(CBaseChainParams::MAIN);
SelectParams(ChainType::MAIN);
}
@ -135,7 +136,7 @@ BOOST_AUTO_TEST_CASE(key_io_invalid)
std::string exp_base58string = test[0].get_str();
// must be invalid as public and as private key
for (const auto& chain : { CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST }) {
for (const auto& chain : {ChainType::MAIN, ChainType::TESTNET, ChainType::SIGNET, ChainType::REGTEST}) {
SelectParams(chain);
destination = DecodeDestination(exp_base58string);
BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey in mainnet:" + strTest);

View file

@ -40,7 +40,7 @@ const std::string fedpegscript_str = "512103dff4923d778550cc13ce0d887d737553b4b5
// Needed for easier parent PoW check, and setting fedpegscript
struct FedpegSetup : public BasicTestingSetup {
FedpegSetup() : BasicTestingSetup("custom", {}, fedpegscript_str) {}
FedpegSetup() : BasicTestingSetup(ChainType::CUSTOM, {}, fedpegscript_str) {}
};
BOOST_FIXTURE_TEST_SUITE(pegin_witness_tests, FedpegSetup)

View file

@ -7,6 +7,7 @@
#include <pow.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <boost/test/unit_test.hpp>
@ -15,7 +16,7 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
/* Test calculation of next difficulty target with no constraints applying */
BOOST_AUTO_TEST_CASE(get_next_work)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
int64_t nLastRetargetTime = 1261130161; // Block #30240
CBlockIndex pindexLast;
pindexLast.nHeight = 32255;
@ -34,7 +35,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
/* Test the constraint on the upper bound for next work */
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
int64_t nLastRetargetTime = 1231006505; // Block #0
CBlockIndex pindexLast;
pindexLast.nHeight = 2015;
@ -48,7 +49,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
/* Test the constraint on the lower bound for actual time taken */
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
int64_t nLastRetargetTime = 1279008237; // Block #66528
CBlockIndex pindexLast;
pindexLast.nHeight = 68543;
@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
/* Test the constraint on the upper bound for actual time taken */
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 46367;
@ -81,7 +82,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
{
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
nBits = UintToArith256(consensus.powLimit).GetCompact(true);
@ -91,7 +92,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
{
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits{~0x00800000U};
hash.SetHex("0x1");
@ -100,7 +101,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
{
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 nBits_arith = UintToArith256(consensus.powLimit);
@ -112,7 +113,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
{
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 hash_arith = UintToArith256(consensus.powLimit);
@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
{
const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus();
const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus();
uint256 hash;
unsigned int nBits;
arith_uint256 hash_arith{0};
@ -135,7 +136,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
std::vector<CBlockIndex> blocks(10000);
for (int i = 0; i < 10000; i++) {
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
@ -155,9 +156,9 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
}
}
void sanity_check_chainparams(const ArgsManager& args, std::string chainName)
void sanity_check_chainparams(const ArgsManager& args, ChainType chain_type)
{
const auto chainParams = CreateChainParams(args, chainName);
const auto chainParams = CreateChainParams(args, chain_type);
const auto consensus = chainParams->GetConsensus();
// hash genesis is correct
@ -184,22 +185,22 @@ void sanity_check_chainparams(const ArgsManager& args, std::string chainName)
BOOST_AUTO_TEST_CASE(ChainParams_MAIN_sanity)
{
sanity_check_chainparams(*m_node.args, CBaseChainParams::MAIN);
sanity_check_chainparams(*m_node.args, ChainType::MAIN);
}
BOOST_AUTO_TEST_CASE(ChainParams_REGTEST_sanity)
{
sanity_check_chainparams(*m_node.args, CBaseChainParams::REGTEST);
sanity_check_chainparams(*m_node.args, ChainType::REGTEST);
}
BOOST_AUTO_TEST_CASE(ChainParams_TESTNET_sanity)
{
sanity_check_chainparams(*m_node.args, CBaseChainParams::TESTNET);
sanity_check_chainparams(*m_node.args, ChainType::TESTNET);
}
BOOST_AUTO_TEST_CASE(ChainParams_SIGNET_sanity)
{
sanity_check_chainparams(*m_node.args, CBaseChainParams::SIGNET);
sanity_check_chainparams(*m_node.args, ChainType::SIGNET);
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -6,12 +6,12 @@
#include <test/util/setup_common.h>
#include <test/util/str.h>
#include <util/fs.h>
#include <boost/test/unit_test.hpp>
#include <common/args.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/fs.h>
#include <util/strencodings.h>
#include <util/string.h>
@ -190,7 +190,7 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup)
if (!out_file) throw std::system_error(errno, std::generic_category(), "fopen failed");
}
const std::string& network = CBaseChainParams::MAIN;
const std::string& network = ChainTypeToString(ChainType::MAIN);
ForEachMergeSetup([&](const ActionList& arg_actions, const ActionList& conf_actions, bool force_set,
bool ignore_default_section_config) {
std::string desc;
@ -225,7 +225,7 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup)
}
desc += " || ";
desc += GetSetting(settings, network, name, ignore_default_section_config, /*ignore_nonpersistent=*/false, /*get_chain_name=*/false).write();
desc += GetSetting(settings, network, name, ignore_default_section_config, /*ignore_nonpersistent=*/false, /*get_chain_type=*/false).write();
desc += " |";
for (const auto& s : GetSettingsList(settings, network, name, ignore_default_section_config)) {
desc += " ";

View file

@ -10,13 +10,14 @@
#include <script/standard.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/chaintype.h>
#include <validation.h>
#include <boost/test/unit_test.hpp>
struct Dersig100Setup : public TestChain100Setup {
Dersig100Setup()
: TestChain100Setup{CBaseChainParams::REGTEST, {"-testactivationheight=dersig@102"}} {}
: TestChain100Setup{ChainType::REGTEST, {"-testactivationheight=dersig@102"}} {}
};
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,

View file

@ -46,6 +46,7 @@
#include <timedata.h>
#include <txdb.h>
#include <txmempool.h>
#include <util/chaintype.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/system.h>
@ -102,7 +103,7 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
return os;
}
BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args, const std::string& fedpegscript)
BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args, const std::string& fedpegscript)
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
m_args{}
{
@ -143,7 +144,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
throw std::runtime_error{error};
}
}
SelectParams(chainName);
SelectParams(chainType);
SeedInsecureRand();
if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN);
InitLogging(*m_node.args);
@ -184,8 +185,8 @@ BasicTestingSetup::~BasicTestingSetup()
gArgs.ClearArgs();
}
ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args, const std::string& fedpegscript)
: BasicTestingSetup(chainName, extra_args, fedpegscript)
ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args, const std::string& fedpegscript)
: BasicTestingSetup(chainType, extra_args, fedpegscript)
{
const CChainParams& chainparams = Params();
@ -263,12 +264,12 @@ void ChainTestingSetup::LoadVerifyActivateChainstate()
}
TestingSetup::TestingSetup(
const std::string& chainName,
const ChainType chainType,
const std::vector<const char*>& extra_args,
const std::string& fedpegscript,
const bool coins_db_in_memory,
const bool block_tree_db_in_memory)
: ChainTestingSetup(chainName, extra_args, fedpegscript)
: ChainTestingSetup(chainType, extra_args, fedpegscript)
{
m_coins_db_in_memory = coins_db_in_memory;
m_block_tree_db_in_memory = block_tree_db_in_memory;
@ -295,12 +296,12 @@ TestingSetup::TestingSetup(
}
TestChain100Setup::TestChain100Setup(
const std::string& chain_name,
const ChainType chain_type,
const std::vector<const char*>& extra_args,
const std::string& fedpegscript,
const bool coins_db_in_memory,
const bool block_tree_db_in_memory)
: TestingSetup{CBaseChainParams::REGTEST, extra_args, fedpegscript, coins_db_in_memory, block_tree_db_in_memory}
: TestingSetup{ChainType::REGTEST, extra_args, fedpegscript, coins_db_in_memory, block_tree_db_in_memory}
{
SetMockTime(1598887952);
constexpr std::array<unsigned char, 32> vchKey = {

View file

@ -5,7 +5,6 @@
#ifndef BITCOIN_TEST_UTIL_SETUP_COMMON_H
#define BITCOIN_TEST_UTIL_SETUP_COMMON_H
#include <chainparamsbase.h>
#include <common/args.h>
#include <key.h>
#include <node/caches.h>
@ -14,6 +13,7 @@
#include <pubkey.h>
#include <random.h>
#include <stdexcept>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/string.h>
@ -80,7 +80,7 @@ static constexpr CAmount CENT{1000000};
struct BasicTestingSetup {
node::NodeContext m_node; // keep as first member to be destructed last
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "");
explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "");
~BasicTestingSetup();
const fs::path m_path_root;
@ -96,7 +96,7 @@ struct ChainTestingSetup : public BasicTestingSetup {
bool m_coins_db_in_memory{true};
bool m_block_tree_db_in_memory{true};
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "");
explicit ChainTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "");
~ChainTestingSetup();
// Supplies a chainstate, if one is needed
@ -107,7 +107,7 @@ struct ChainTestingSetup : public BasicTestingSetup {
*/
struct TestingSetup : public ChainTestingSetup {
explicit TestingSetup(
const std::string& chainName = CBaseChainParams::MAIN,
const ChainType chainType = ChainType::MAIN,
const std::vector<const char*>& extra_args = {},
const std::string& fedpegscript = "",
const bool coins_db_in_memory = true,
@ -117,7 +117,7 @@ struct TestingSetup : public ChainTestingSetup {
/** Identical to TestingSetup, but chain set to regtest */
struct RegTestingSetup : public TestingSetup {
RegTestingSetup()
: TestingSetup{CBaseChainParams::REGTEST} {}
: TestingSetup{ChainType::REGTEST} {}
};
class CBlock;
@ -129,7 +129,7 @@ class CScript;
*/
struct TestChain100Setup : public TestingSetup {
TestChain100Setup(
const std::string& chain_name = CBaseChainParams::REGTEST,
const ChainType chain_type = ChainType::REGTEST,
const std::vector<const char*>& extra_args = {},
const std::string& fedpegscript = "",
const bool coins_db_in_memory = true,
@ -208,7 +208,7 @@ struct TestChain100Setup : public TestingSetup {
* be used in "hot loops", for example fuzzing or benchmarking.
*/
template <class T = const BasicTestingSetup>
std::unique_ptr<T> MakeNoLogFileContext(const std::string& chain_name = CBaseChainParams::REGTEST, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "")
std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::REGTEST, const std::vector<const char*>& extra_args = {}, const std::string& fedpegscript = "")
{
const std::vector<const char*> arguments = Cat(
{
@ -217,7 +217,7 @@ std::unique_ptr<T> MakeNoLogFileContext(const std::string& chain_name = CBaseCha
},
extra_args);
return std::make_unique<T>(chain_name, arguments, fedpegscript);
return std::make_unique<T>(chain_type, arguments, fedpegscript);
}
CBlock getBlock13b8a();

View file

@ -7,6 +7,7 @@
#include <net.h>
#include <signet.h>
#include <uint256.h>
#include <util/chaintype.h>
#include <validation.h>
#include <test/util/setup_common.h>
@ -42,7 +43,7 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
BOOST_AUTO_TEST_CASE(block_subsidy_test)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
TestBlockSubsidyHalvings(150); // As in regtest
TestBlockSubsidyHalvings(1000); // Just another interval
@ -50,7 +51,7 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test)
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
{
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN);
CAmount nSum = 0;
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE(signet_parse_tests)
{
ArgsManager signet_argsman;
signet_argsman.ForceSetArg("-signetchallenge", "51"); // set challenge to OP_TRUE
const auto signet_params = CreateChainParams(signet_argsman, CBaseChainParams::SIGNET);
const auto signet_params = CreateChainParams(signet_argsman, ChainType::SIGNET);
CBlock block;
BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{OP_TRUE});
CScript challenge{OP_TRUE};
@ -125,7 +126,7 @@ BOOST_AUTO_TEST_CASE(signet_parse_tests)
//! Test retrieval of valid assumeutxo values.
BOOST_AUTO_TEST_CASE(test_assumeutxo)
{
const auto params = CreateChainParams(*m_node.args, CBaseChainParams::REGTEST);
const auto params = CreateChainParams(*m_node.args, ChainType::REGTEST);
// These heights don't have assumeutxo configurations associated, per the contents
// of kernel/chainparams.cpp.

View file

@ -7,6 +7,7 @@
#include <consensus/params.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <versionbits.h>
#include <boost/test/unit_test.hpp>
@ -418,8 +419,8 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
// check that any deployment on any chain can conceivably reach both
// ACTIVE and FAILED states in roughly the way we expect
for (const auto& chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) {
const auto chainParams = CreateChainParams(*m_node.args, chain_name);
for (const auto& chain_type: {ChainType::MAIN, ChainType::TESTNET, ChainType::SIGNET, ChainType::REGTEST}) {
const auto chainParams = CreateChainParams(*m_node.args, chain_type);
uint32_t chain_all_vbits{0};
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
const auto dep = static_cast<Consensus::DeploymentPos>(i);
@ -440,7 +441,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
// deployment that's not always/never active
ArgsManager args;
args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999"); // January 1, 2008 - December 31, 2008
const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST);
const auto chainParams = CreateChainParams(args, ChainType::REGTEST);
check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY);
}
@ -450,7 +451,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
// live deployment
ArgsManager args;
args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999:403200"); // January 1, 2008 - December 31, 2008, min act height 403200
const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST);
const auto chainParams = CreateChainParams(args, ChainType::REGTEST);
check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY);
}
}

66
src/util/chaintype.cpp Normal file
View file

@ -0,0 +1,66 @@
// Copyright (c) 2023 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/chaintype.h>
#include <cassert>
#include <optional>
#include <string>
std::string ChainTypeToString(ChainType chain)
{
switch (chain) {
case ChainType::MAIN:
return "main";
case ChainType::TESTNET:
return "test";
case ChainType::SIGNET:
return "signet";
case ChainType::REGTEST:
return "regtest";
case ChainType::LIQUID1:
return "liquidv1";
case ChainType::LIQUID1TEST:
return "liquidv1test";
case ChainType::LIQUIDTESTNET:
return "liquidtestnet";
case ChainType::CUSTOM:
return "custom";
}
assert(false);
}
std::optional<ChainType> ChainTypeFromString(std::string_view chain)
{
if (chain == "main") {
return ChainType::MAIN;
} else if (chain == "test") {
return ChainType::TESTNET;
} else if (chain == "signet") {
return ChainType::SIGNET;
} else if (chain == "regtest") {
return ChainType::REGTEST;
} else if (chain == "liquidv1") {
return ChainType::LIQUID1;
} else if (chain == "liquidv1test") {
return ChainType::LIQUID1TEST;
} else if (chain == "liquidtestnet") {
return ChainType::LIQUIDTESTNET;
} else {
return std::nullopt;
}
}
// ELEMENTS
ChainTypeMeta ChainTypeMetaFrom(std::string chain_name) {
if (auto chain = ChainTypeFromString(chain_name)) {
return { *chain, chain_name };
}
return { ChainType::CUSTOM, chain_name };
}
ChainTypeMeta ChainTypeMetaFrom(ChainType chain_type) {
return { chain_type, ChainTypeToString(chain_type) };
}

36
src/util/chaintype.h Normal file
View file

@ -0,0 +1,36 @@
// Copyright (c) 2023 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_UTIL_CHAINTYPE_H
#define BITCOIN_UTIL_CHAINTYPE_H
#include <optional>
#include <string>
enum class ChainType {
MAIN,
TESTNET,
SIGNET,
REGTEST,
// ELEMENTS
LIQUID1,
LIQUID1TEST,
LIQUIDTESTNET,
CUSTOM,
};
std::string ChainTypeToString(ChainType chain);
std::optional<ChainType> ChainTypeFromString(std::string_view chain);
// ELEMENTS
struct ChainTypeMeta {
ChainType chain_type;
std::string chain_name;
};
ChainTypeMeta ChainTypeMetaFrom(std::string chain_name);
ChainTypeMeta ChainTypeMetaFrom(ChainType chain_type);
#endif // BITCOIN_UTIL_CHAINTYPE_H

View file

@ -130,7 +130,7 @@ SettingsValue GetSetting(const Settings& settings,
const std::string& name,
bool ignore_default_section_config,
bool ignore_nonpersistent,
bool get_chain_name)
bool get_chain_type)
{
SettingsValue result;
bool done = false; // Done merging any more settings sources.
@ -145,17 +145,17 @@ SettingsValue GetSetting(const Settings& settings,
// assigned value instead of last. In general, later settings take
// precedence over early settings, but for backwards compatibility in
// the config file the precedence is reversed for all settings except
// chain name settings.
// chain type settings.
const bool reverse_precedence =
(source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
!get_chain_name;
!get_chain_type;
// Weird behavior preserved for backwards compatibility: Negated
// -regtest and -testnet arguments which you would expect to override
// values set in the configuration file are currently accepted but
// silently ignored. It would be better to apply these just like other
// negated values, or at least warn they are ignored.
const bool skip_negated_command_line = get_chain_name;
const bool skip_negated_command_line = get_chain_type;
if (done) return;

View file

@ -60,14 +60,14 @@ bool WriteSettings(const fs::path& path,
//! command line). Only return settings in the
//! read-only config and read-write settings
//! files.
//! @param get_chain_name - enable special backwards compatible behavior
//! for GetChainName
//! @param get_chain_type - enable special backwards compatible behavior
//! for GetChainType
SettingsValue GetSetting(const Settings& settings,
const std::string& section,
const std::string& name,
bool ignore_default_section_config,
bool ignore_nonpersistent,
bool get_chain_name);
bool get_chain_type);
//! Get combined setting value similar to GetSetting(), except if setting was
//! specified multiple times, return a list of all the values specified.

View file

@ -45,7 +45,7 @@ ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() {
const std::string command = gArgs.GetArg("-signer", "");
if (command == "") throw std::runtime_error(std::string(__func__) + ": restart bitcoind with -signer=<cmd>");
std::vector<ExternalSigner> signers;
ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
if (signers.empty()) throw std::runtime_error(std::string(__func__) + ": No external signers found");
// TODO: add fingerprint argument instead of failing in case of multiple signers.
if (signers.size() > 1) throw std::runtime_error(std::string(__func__) + ": More than one external signer found. Please connect only one at a time.");

View file

@ -4,6 +4,7 @@
#include <common/args.h>
#include <univalue.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
@ -13,7 +14,7 @@
#include <wallet/test/init_test_fixture.h>
namespace wallet {
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const ChainType chainType) : BasicTestingSetup(chainType)
{
m_wallet_loader = MakeWalletLoader(*m_node.chain, m_args);

View file

@ -9,11 +9,12 @@
#include <interfaces/wallet.h>
#include <node/context.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
namespace wallet {
struct InitWalletDirTestingSetup: public BasicTestingSetup {
explicit InitWalletDirTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
explicit InitWalletDirTestingSetup(const ChainType chain_type = ChainType::MAIN);
~InitWalletDirTestingSetup();
void SetWalletDir(const fs::path& walletdir_path);

View file

@ -5,10 +5,11 @@
#include <wallet/test/wallet_test_fixture.h>
#include <scheduler.h>
#include <util/chaintype.h>
namespace wallet {
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
: TestingSetup(chainName),
WalletTestingSetup::WalletTestingSetup(const ChainType chainType)
: TestingSetup(chainType),
m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args))},
m_wallet(m_node.chain.get(), "", CreateMockWalletDatabase())
{

View file

@ -10,6 +10,7 @@
#include <interfaces/chain.h>
#include <interfaces/wallet.h>
#include <node/context.h>
#include <util/chaintype.h>
#include <util/check.h>
#include <wallet/wallet.h>
@ -19,7 +20,7 @@ namespace wallet {
/** Testing setup and teardown for wallet.
*/
struct WalletTestingSetup : public TestingSetup {
explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
explicit WalletTestingSetup(const ChainType chainType = ChainType::MAIN);
~WalletTestingSetup();
std::unique_ptr<interfaces::WalletLoader> m_wallet_loader;