Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ BITCOIN_CORE_H = \
util/hash_type.h \
util/helpers.h \
util/asmap.h \
util/chaintype.h \
util/getuniquepath.h \
util/macros.h \
util/message.h \
Expand Down Expand Up @@ -993,6 +994,7 @@ libbitcoin_util_a_SOURCES = \
util/bip32.cpp \
util/bytevectorhash.cpp \
util/check.cpp \
util/chaintype.cpp \
util/edge.cpp \
util/error.cpp \
util/fees.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/bench/load_external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <bench/data.h>
#include <chainparams.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <validation.h>

/**
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/bench/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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,
};

Expand Down
5 changes: 3 additions & 2 deletions src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <policy/policy.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <util/chaintype.h>
#include <validation.h>

#include <vector>
Expand Down Expand Up @@ -85,7 +86,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 {
Expand All @@ -100,7 +101,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
static void MempoolCheck(benchmark::Bench& bench)
{
FastRandomContext det_rand{true};
auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(CBaseChainParams::REGTEST, {"-checkmempool=1"});
auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(ChainType::REGTEST, {"-checkmempool=1"});
CTxMemPool& pool = *testing_setup.get()->m_node.mempool;
LOCK2(cs_main, pool.cs);
testing_setup->PopulateMempool(det_rand, 400, true);
Expand Down
3 changes: 2 additions & 1 deletion src/bench/rpc_blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include <rpc/blockchain.h>
#include <streams.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <validation.h>

#include <univalue.h>

namespace {

struct TestBlockAndIndex {
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
CBlock block{};
uint256 blockHash{};
CBlockIndex blockindex{};
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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.GetChainType());
} catch (const std::exception& e) {
tfm::format(std::cerr, "Error: %s\n", e.what());
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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.GetChainType());

return std::nullopt;
}
Expand Down
36 changes: 27 additions & 9 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,24 +1349,42 @@ 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 ChainType chain)
{
if (chain == CBaseChainParams::MAIN) {
if (chain == ChainType::MAIN) {
return std::unique_ptr<CChainParams>(new CMainParams());
} else if (chain == CBaseChainParams::TESTNET) {
} else if (chain == ChainType::TESTNET) {
return std::unique_ptr<CChainParams>(new CTestNetParams());
} else if (chain == CBaseChainParams::DEVNET) {
} else if (chain == ChainType::DEVNET) {
return std::unique_ptr<CChainParams>(new CDevNetParams(args));
} else if (chain == CBaseChainParams::REGTEST) {
} else if (chain == ChainType::REGTEST) {
return std::unique_ptr<CChainParams>(new CRegTestParams(args));
}
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__));
}

std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
{
const auto chain_type{ChainTypeFromString(chain)};
if (!chain_type) {
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
return CreateChainParams(args, *chain_type);
}

void SelectParams(const std::string& network)
void SelectParams(const ChainType chain)
{
SelectBaseParams(network);
globalChainParams = CreateChainParams(gArgs, network);
SelectBaseParams(chain);
globalChainParams = CreateChainParams(gArgs, chain);
}

void SelectParams(const std::string& chain)
{
const auto chain_type{ChainTypeFromString(chain)};
if (!chain_type) {
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
SelectParams(*chain_type);
}

void SetupChainParamsOptions(ArgsManager& argsman)
Expand Down
5 changes: 5 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <netaddress.h>
#include <primitives/block.h>
#include <protocol.h>
#include <util/chaintype.h>
#include <util/hash_type.h>

#include <memory>
Expand Down Expand Up @@ -121,6 +122,8 @@ class CChainParams
int LLMQConnectionRetryTimeout() const { return nLLMQConnectionRetryTimeout; }
/** Return the network string */
std::string NetworkIDString() const { return strNetworkID; }
ChainType GetChainType() const { return ChainTypeFromString(strNetworkID).value(); }
std::string GetChainTypeString() const { return strNetworkID; }
/** 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]; }
Expand Down Expand Up @@ -197,6 +200,7 @@ class CChainParams
* @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 ChainType chain);
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);

/**
Expand All @@ -209,6 +213,7 @@ 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 ChainType chain);
void SelectParams(const std::string& chain);

/**
Expand Down
32 changes: 25 additions & 7 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,40 @@ const CBaseChainParams& BaseParams()
* Port numbers for incoming Tor connections (9996, 19996, 19796, 19896) 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 ChainType chain)
{
if (chain == CBaseChainParams::MAIN)
if (chain == ChainType::MAIN)
return std::make_unique<CBaseChainParams>("", 9998, 9996);
else if (chain == CBaseChainParams::TESTNET)
else if (chain == ChainType::TESTNET)
return std::make_unique<CBaseChainParams>("testnet3", 19998, 19996);
else if (chain == CBaseChainParams::DEVNET)
else if (chain == ChainType::DEVNET)
return std::make_unique<CBaseChainParams>(gArgs.GetDevNetName(), 19798, 19796);
else if (chain == CBaseChainParams::REGTEST)
else if (chain == ChainType::REGTEST)
return std::make_unique<CBaseChainParams>("regtest", 19898, 19896);
else
throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__));
}

std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
{
const auto chain_type{ChainTypeFromString(chain)};
if (!chain_type) {
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
return CreateBaseChainParams(*chain_type);
}

void SelectBaseParams(const std::string& chain)
void SelectBaseParams(const ChainType chain)
{
globalChainBaseParams = CreateBaseChainParams(chain);
gArgs.SelectConfigNetwork(chain);
gArgs.SelectConfigNetwork(ChainTypeToString(chain));
}

void SelectBaseParams(const std::string& chain)
{
const auto chain_type{ChainTypeFromString(chain)};
if (!chain_type) {
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
SelectBaseParams(*chain_type);
}
4 changes: 4 additions & 0 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef BITCOIN_CHAINPARAMSBASE_H
#define BITCOIN_CHAINPARAMSBASE_H

#include <util/chaintype.h>

#include <memory>
#include <string>

Expand Down Expand Up @@ -44,6 +46,7 @@ class CBaseChainParams
* @returns a CBaseChainParams* of the chosen chain.
* @throws a std::runtime_error if the chain is not supported.
*/
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain);
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);

/**
Expand All @@ -58,6 +61,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman);
const CBaseChainParams& BaseParams();

/** Sets the params returned by Params() to those for the given network. */
void SelectBaseParams(const ChainType chain);
void SelectBaseParams(const std::string& chain);

#endif // BITCOIN_CHAINPARAMSBASE_H
2 changes: 1 addition & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ class NodeImpl : public Node
std::vector<ExternalSigner> signers = {};
const std::string command = gArgs.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;
for (auto& signer : signers) {
result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
Expand Down
3 changes: 2 additions & 1 deletion src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <fs.h>
#include <qt/intro.h>
#include <qt/forms/ui_intro.h>
#include <util/chaintype.h>

#include <qt/guiconstants.h>
#include <qt/guiutil.h>
Expand Down Expand Up @@ -223,7 +224,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.GetChainType());
} catch (const std::exception&) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/qt/networkstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BITCOIN_QT_NETWORKSTYLE_H
#define BITCOIN_QT_NETWORKSTYLE_H

#include <util/chaintype.h>

#include <QIcon>
#include <QPixmap>
#include <QString>
Expand All @@ -17,7 +19,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; }
Expand Down
12 changes: 12 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags
reloadThemedWidgets();

GUIUtil::handleCloseWindowShortcut(this);

updateWindowTitle();
}

RPCConsole::~RPCConsole()
Expand Down Expand Up @@ -1523,3 +1525,13 @@ void RPCConsole::updateAlerts(const QString& warnings)
this->ui->label_alerts->setVisible(!warnings.isEmpty());
this->ui->label_alerts->setText(warnings);
}

void RPCConsole::updateWindowTitle()
{
const ChainType chain = Params().GetChainType();
if (chain == ChainType::MAIN) return;

const QString chainType = QString::fromStdString(Params().GetChainTypeString());
const QString title = tr("Node window - [%1]").arg(chainType);
this->setWindowTitle(title);
}
2 changes: 2 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public Q_SLOTS:
return time_at_event.count() ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
}

void updateWindowTitle();

private Q_SLOTS:
void updateAlerts(const QString& warnings);
};
Expand Down
3 changes: 2 additions & 1 deletion src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <qt/test/uritests.h>
#include <qt/test/trafficgraphdatatests.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>

#ifdef ENABLE_WALLET
#include <qt/test/addressbooktests.h>
Expand Down Expand Up @@ -59,7 +60,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";
}());

Expand Down
3 changes: 2 additions & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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>
Expand Down Expand Up @@ -397,7 +398,7 @@ static RPCHelpMan addconnection()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (Params().NetworkIDString() != CBaseChainParams::REGTEST) {
if (Params().GetChainType() != ChainType::REGTEST) {
throw std::runtime_error("addconnection is for regression testing (-regtest mode) only.");
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/blockmanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -18,7 +19,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,
};
Expand Down
Loading
Loading