From 1bdda5e0a9a9e8c2567e774ca38480d3bbe39ff2 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Tue, 28 Jan 2020 15:36:35 +0000 Subject: [PATCH 1/4] Add DEFAULT chain and set to liquidv1 This fixes f.e. that when arguments are set in CLI or the config file without a network attached (`port` instead of `liquidv1.port`), they will now be assigned to the liquidv1 instead of Bitcoin mainnet. --- src/chainparamsbase.cpp | 2 ++ src/chainparamsbase.h | 2 ++ src/init.cpp | 6 ++++-- src/test/util_tests.cpp | 2 +- src/util/system.cpp | 6 +++--- src/util/system.h | 4 ++-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index fe8b73861e..c846e94737 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -16,6 +16,8 @@ const std::string CBaseChainParams::TESTNET = "test"; const std::string CBaseChainParams::REGTEST = "regtest"; const std::string CBaseChainParams::LIQUID1 = "liquidv1"; +const std::string CBaseChainParams::DEFAULT = CBaseChainParams::LIQUID1; + void SetupChainParamsBaseOptions() { gArgs.AddArg("-chain=", "Use the chain (default: main). Reserved values: main, test, regtest", false, OptionsCategory::CHAINPARAMS); diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 273128178f..35defd28d9 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -22,6 +22,8 @@ class CBaseChainParams static const std::string REGTEST; static const std::string LIQUID1; + static const std::string DEFAULT; + const std::string& DataDir() const { return strDataDir; } int RPCPort() const { return nRPCPort; } int MainchainRPCPort() const { return nMainchainRPCPort; } diff --git a/src/init.cpp b/src/init.cpp index 2980679a47..4c02c8f747 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -363,10 +363,12 @@ void SetupServerArgs() SetupHelpOptions(gArgs); gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST); // server-only for now - const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); + const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::DEFAULT); + const auto mainnetBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); - const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN); + const auto defaultChainParams = CreateChainParams(CBaseChainParams::DEFAULT); + const auto mainnetChainParams = CreateChainParams(CBaseChainParams::MAIN); const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET); const auto regtestChainParams = CreateChainParams(CBaseChainParams::REGTEST); diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index c56402b5ba..6402d29409 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream) test_args.SetNetworkOnlyArg("-ccc"); test_args.SetNetworkOnlyArg("-h"); - test_args.SelectConfigNetwork(CBaseChainParams::MAIN); + test_args.SelectConfigNetwork(CBaseChainParams::DEFAULT); BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e"); BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2); BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); diff --git a/src/util/system.cpp b/src/util/system.cpp index e31764eebc..3ddb69e82b 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -174,7 +174,7 @@ class ArgsManagerHelper { * See also comments around ArgsManager::ArgsManager() below. */ static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args) { - return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0); + return (am.m_network == CBaseChainParams::DEFAULT || am.m_network_only_args.count(arg) == 0); } /** Convert regular argument into the network-specific setting */ @@ -336,7 +336,7 @@ const std::set ArgsManager::GetUnsuitableSectionOnlyArgs() const if (m_network.empty()) return std::set {}; // if it's okay to use the default section for this network, don't worry - if (m_network == CBaseChainParams::MAIN) return std::set {}; + if (m_network == CBaseChainParams::DEFAULT) return std::set {}; for (const auto& arg : m_network_only_args) { std::pair found_result; @@ -1001,7 +1001,7 @@ std::string ArgsManager::GetChainName() const if (fTestNet) return CBaseChainParams::TESTNET; - std::string default_chain = "liquidv1"; + std::string default_chain = CBaseChainParams::DEFAULT; return GetArg("-chain", default_chain); } diff --git a/src/util/system.h b/src/util/system.h index 9baddc8e68..d85b2dbcb5 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -251,8 +251,8 @@ class ArgsManager void ForceSetArg(const std::string& strArg, const std::string& strValue); /** - * Looks for -regtest, -testnet and returns the appropriate BIP70 chain name. - * @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given. + * Returns the chain name based on the parameters. + * @return CBaseChainParams::DEFAULT by default. */ std::string GetChainName() const; From 02b3cf6aeeb2cae327a792d1f4d50b9ebe02b314 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Wed, 29 Jan 2020 13:17:49 +0000 Subject: [PATCH 2/4] Some Elements/Liquid fixes for Qt GUI --- src/qt/guiutil.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index ba284ae68d..285c22f1fd 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -547,9 +547,11 @@ fs::path static StartupShortcutPath() std::string chain = gArgs.GetChainName(); if (chain == CBaseChainParams::MAIN) return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk"; + if (chain == CBaseChainParams::LIQUID1) + return GetSpecialFolderPath(CSIDL_STARTUP) / "Liquid.lnk"; if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4" return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk"; - return GetSpecialFolderPath(CSIDL_STARTUP) / strprintf("Bitcoin (%s).lnk", chain); + return GetSpecialFolderPath(CSIDL_STARTUP) / strprintf("Elements (%s).lnk", chain); } bool GetStartOnSystemStartup() @@ -630,7 +632,9 @@ fs::path static GetAutostartFilePath() std::string chain = gArgs.GetChainName(); if (chain == CBaseChainParams::MAIN) return GetAutostartDir() / "bitcoin.desktop"; - return GetAutostartDir() / strprintf("bitcoin-%s.lnk", chain); + if (chain == CBaseChainParams::LIQUID1) + return GetAutostartDir() / "liquid.desktop"; + return GetAutostartDir() / strprintf("elements-%s.lnk", chain); } bool GetStartOnSystemStartup() @@ -675,8 +679,10 @@ bool SetStartOnSystemStartup(bool fAutoStart) optionFile << "Type=Application\n"; if (chain == CBaseChainParams::MAIN) optionFile << "Name=Bitcoin\n"; + else if (chain == CBaseChainParams::LIQUID1) + optionFile << "Name=Liquid\n"; else - optionFile << strprintf("Name=Bitcoin (%s)\n", chain); + optionFile << strprintf("Name=Elements (%s)\n", chain); optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain); optionFile << "Terminal=false\n"; optionFile << "Hidden=false\n"; From 7a5a412a18dc3deaf03ad2c8e876d6f592f2d5d1 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 30 Jan 2020 17:29:25 +0000 Subject: [PATCH 3/4] Remove unused ArgsManager::GetUnrecognizedSections --- src/util/system.cpp | 19 ------------------- src/util/system.h | 5 ----- 2 files changed, 24 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index 3ddb69e82b..b9b1312646 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -359,25 +359,6 @@ const std::set ArgsManager::GetUnsuitableSectionOnlyArgs() const return unsuitables; } - -const std::set ArgsManager::GetUnrecognizedSections() const -{ - // Section names to be recognized in the config file. - static const std::set available_sections{ - CBaseChainParams::REGTEST, - CBaseChainParams::TESTNET, - CBaseChainParams::MAIN - }; - std::set diff; - - LOCK(cs_args); - std::set_difference( - m_config_sections.begin(), m_config_sections.end(), - available_sections.begin(), available_sections.end(), - std::inserter(diff, diff.end())); - return diff; -} - void ArgsManager::SelectConfigNetwork(const std::string& network) { LOCK(cs_args); diff --git a/src/util/system.h b/src/util/system.h index d85b2dbcb5..6372acd148 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -171,11 +171,6 @@ class ArgsManager */ const std::set GetUnsuitableSectionOnlyArgs() const; - /** - * Log warnings for unrecognized section names in the config file. - */ - const std::set GetUnrecognizedSections() const; - /** * Return a vector of strings of the given argument * From 719662d3f06a5ae310a41e93f1686e8aca250f02 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 30 Jan 2020 17:57:45 +0000 Subject: [PATCH 4/4] Make elements-cli also use DEFAULT chain by default --- src/bitcoin-cli.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 4f578092b1..a185fccee3 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -36,7 +36,7 @@ static void SetupCliArgs() { SetupHelpOptions(gArgs); - const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); + const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::DEFAULT); const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);