Skip to content

Commit de842cb

Browse files
committed
Merge #432: [0.17] QA: Use resgtest2 chain instead of regtest for rpc tests
a1e0c56 QA: Use resgtest2 chain instead of regtest for rpc tests (Jorge Timón) 4454c52 QA: Adapt BitcoinTestFramework for chains other than "regtest" (Jorge Timón) a06be15 Testchains: Introduce custom chain whose constructor... (Jorge Timón) 46749eb Testchains: Qt: Simplify network/chain styles and add a default purple (Jorge Timón) c0c1e38 Testchains: Generic selection with -chain=<str> in addition of -testnet and -regtest (Jorge Timón) 56515c3 9102: Really don't validate genesis block (Gregory Sanders) Pull request description: Backport of bitcoin/bitcoin#8994 The tests seem to pass with: ``` python3 ./test/functional/test_runner.py -j4 --extended ``` Let's please try to keep all general review things on bitcoin/bitcoin#8994 and elements-specific things here. Dependencies: - [x] [0.17] Don't edit Chainparams after initialization #427 - [x] [0.17] Test: Fix example_test.py #434 Tree-SHA512: e216587b6f9d3a462372915e01c8eb3c65a61e4ea29f398e65a7fc03a3ea5676c4711527b5cc2c115893591e7cd5b0ecd2f1fac4faf7ef747a022e2657bc99d4
2 parents 5042698 + a1e0c56 commit de842cb

33 files changed

+336
-247
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int AppInitRPC(int argc, char* argv[])
129129
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
130130
return EXIT_FAILURE;
131131
}
132-
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
132+
// Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
133133
try {
134134
SelectBaseParams(gArgs.GetChainName());
135135
} catch (const std::exception& e) {

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int AppInitRawTx(int argc, char* argv[])
8686
return EXIT_FAILURE;
8787
}
8888

89-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
89+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
9090
try {
9191
SelectParams(gArgs.GetChainName());
9292
} catch (const std::exception& e) {

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static bool AppInit(int argc, char* argv[])
9898
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
9999
return false;
100100
}
101-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
101+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
102102
try {
103103
SelectParams(gArgs.GetChainName());
104104
} catch (const std::exception& e) {

src/chainparams.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,73 @@ void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args
395395
}
396396
}
397397

398+
/**
399+
* Custom params for testing.
400+
*/
401+
class CCustomParams : public CRegTestParams {
402+
void UpdateFromArgs(ArgsManager& args)
403+
{
404+
UpdateVersionBitsParametersFromArgs(args);
405+
406+
consensus.nSubsidyHalvingInterval = args.GetArg("-con_nsubsidyhalvinginterval", consensus.nSubsidyHalvingInterval);
407+
consensus.BIP16Exception = uint256S(args.GetArg("-con_bip16exception", "0x0"));
408+
consensus.BIP34Height = args.GetArg("-con_bip34height", consensus.BIP34Height);
409+
consensus.BIP34Hash = uint256S(args.GetArg("-con_bip34hash", "0x0"));
410+
consensus.BIP65Height = args.GetArg("-con_bip65height", consensus.BIP65Height);
411+
consensus.BIP66Height = args.GetArg("-con_bip66height", consensus.BIP66Height);
412+
consensus.powLimit = uint256S(args.GetArg("-con_powlimit", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
413+
consensus.nPowTargetTimespan = args.GetArg("-con_npowtargettimespan", consensus.nPowTargetTimespan);
414+
consensus.nPowTargetSpacing = args.GetArg("-con_npowtargetspacing", consensus.nPowTargetSpacing);
415+
consensus.fPowAllowMinDifficultyBlocks = args.GetBoolArg("-con_fpowallowmindifficultyblocks", consensus.fPowAllowMinDifficultyBlocks);
416+
consensus.fPowNoRetargeting = args.GetBoolArg("-con_fpownoretargeting", consensus.fPowNoRetargeting);
417+
consensus.nRuleChangeActivationThreshold = (uint32_t)args.GetArg("-con_nrulechangeactivationthreshold", consensus.nRuleChangeActivationThreshold);
418+
consensus.nMinerConfirmationWindow = (uint32_t)args.GetArg("-con_nminerconfirmationwindow", consensus.nMinerConfirmationWindow);
419+
420+
consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0"));
421+
consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00"));
422+
423+
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
424+
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);
425+
fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand);
426+
m_fallback_fee_enabled = args.GetBoolArg("-fallback_fee_enabled", m_fallback_fee_enabled);
427+
428+
bech32_hrp = args.GetArg("-bech32_hrp", bech32_hrp);
429+
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, args.GetArg("-pubkeyprefix", 111));
430+
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, args.GetArg("-scriptprefix", 196));
431+
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, args.GetArg("-secretprefix", 239));
432+
433+
std::string extpubprefix = args.GetArg("-extpubkeyprefix", "043587CF");
434+
assert(IsHex(extpubprefix) && extpubprefix.size() == 8 && "-extpubkeyprefix must be hex string of length 8");
435+
base58Prefixes[EXT_PUBLIC_KEY] = ParseHex(extpubprefix);
436+
437+
std::string extprvprefix = args.GetArg("-extprvkeyprefix", "04358394");
438+
assert(IsHex(extprvprefix) && extprvprefix.size() == 8 && "-extprvkeyprefix must be hex string of length 8");
439+
base58Prefixes[EXT_SECRET_KEY] = ParseHex(extprvprefix);
440+
441+
const std::string magic_str = args.GetArg("-pchmessagestart", "FABFB5DA");
442+
assert(IsHex(magic_str) && magic_str.size() == 8 && "-pchmessagestart must be hex string of length 8");
443+
const std::vector<unsigned char> magic_byte = ParseHex(magic_str);
444+
std::copy(begin(magic_byte), end(magic_byte), pchMessageStart);
445+
446+
vSeeds.clear();
447+
if (gArgs.IsArgSet("-seednode")) {
448+
const auto seednodes = gArgs.GetArgs("-seednode");
449+
if (seednodes.size() != 1 || seednodes[0] != "0") {
450+
vSeeds = seednodes;
451+
}
452+
}
453+
}
454+
455+
public:
456+
CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args)
457+
{
458+
strNetworkID = chain;
459+
UpdateFromArgs(args);
460+
genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN);
461+
consensus.hashGenesisBlock = genesis.GetHash();
462+
}
463+
};
464+
398465
static std::unique_ptr<const CChainParams> globalChainParams;
399466

400467
const CChainParams &Params() {
@@ -404,13 +471,15 @@ const CChainParams &Params() {
404471

405472
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
406473
{
474+
// Reserved names for non-custom chains
407475
if (chain == CBaseChainParams::MAIN)
408476
return std::unique_ptr<CChainParams>(new CMainParams());
409477
else if (chain == CBaseChainParams::TESTNET)
410478
return std::unique_ptr<CChainParams>(new CTestNetParams());
411479
else if (chain == CBaseChainParams::REGTEST)
412480
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
413-
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
481+
482+
return std::unique_ptr<CChainParams>(new CCustomParams(chain, gArgs));
414483
}
415484

416485
void SelectParams(const std::string& network)

src/chainparamsbase.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ const std::string CBaseChainParams::REGTEST = "regtest";
1717

1818
void SetupChainParamsBaseOptions()
1919
{
20+
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Reserved values: main, test, regtest", false, OptionsCategory::CHAINPARAMS);
2021
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2122
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
2223
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
23-
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", true, OptionsCategory::CHAINPARAMS);
24+
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest or custom only)", true, OptionsCategory::CHAINPARAMS);
25+
gArgs.AddArg("-seednode=<ip>", "Use specified node as seed node. This option can be specified multiple times to connect to multiple nodes. (custom only)", true, OptionsCategory::CHAINPARAMS);
2426
}
2527

2628
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
@@ -39,8 +41,8 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain
3941
return MakeUnique<CBaseChainParams>("testnet3", 18332);
4042
else if (chain == CBaseChainParams::REGTEST)
4143
return MakeUnique<CBaseChainParams>("regtest", 18443);
42-
else
43-
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
44+
45+
return MakeUnique<CBaseChainParams>(chain, 18553);
4446
}
4547

4648
void SelectBaseParams(const std::string& chain)

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ void SetupServerArgs()
349349
// Hidden Options
350350
std::vector<std::string> hidden_args = {"-rpcssl", "-benchmark", "-h", "-help", "-socks", "-tor", "-debugnet", "-whitelistalwaysrelay",
351351
"-prematurewitness", "-walletprematurewitness", "-promiscuousmempoolflags", "-blockminsize", "-dbcrashratio", "-forcecompactdb", "-usehd",
352+
"-con_fpowallowmindifficultyblocks", "-con_fpownoretargeting", "-con_nsubsidyhalvinginterval", "-con_bip16exception", "-con_bip34height", "-con_bip65height", "-con_bip66height", "-con_npowtargettimespan", "-con_npowtargetspacing", "-con_nrulechangeactivationthreshold", "-con_nminerconfirmationwindow", "-con_powlimit", "-con_bip34hash", "-con_nminimumchainwork", "-con_defaultassumevalid", "-npruneafterheight", "-fdefaultconsistencychecks", "-fmineblocksondemand", "-bech32_hrp", "-fallback_fee_enabled", "-pubkeyprefix", "-scriptprefix", "-secretprefix", "-extpubkeyprefix", "-extprvkeyprefix", "-pchmessagestart",
352353
// GUI args. These will be overwritten by SetupUIArgs for the GUI
353354
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-rootcertificates=<file>", "-splash", "-uiplatform"};
354355

src/qt/bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ int main(int argc, char *argv[])
654654
// - QSettings() will use the new application name after this, resulting in network-specific settings
655655
// - Needs to be done before createOptionsModel
656656

657-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
657+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
658658
try {
659659
node->selectParams(gArgs.GetChainName());
660660
} catch(std::exception &e) {
@@ -666,7 +666,7 @@ int main(int argc, char *argv[])
666666
PaymentServer::ipcParseCommandLine(*node, argc, argv);
667667
#endif
668668

669-
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
669+
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
670670
assert(!networkStyle.isNull());
671671
// Allow for separate UI settings for testnets
672672
QApplication::setApplicationName(networkStyle->getAppName());

src/qt/guiutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
562562
// Start client minimized
563563
QString strArgs = "-min";
564564
// Set -testnet /-regtest options
565-
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
565+
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
566566

567567
#ifdef UNICODE
568568
boost::scoped_array<TCHAR> args(new TCHAR[strArgs.length() + 1]);
@@ -672,7 +672,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
672672
optionFile << "Name=Bitcoin\n";
673673
else
674674
optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
675-
optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
675+
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
676676
optionFile << "Terminal=false\n";
677677
optionFile << "Hidden=false\n";
678678
optionFile.close();

src/qt/networkstyle.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
#include <qt/guiconstants.h>
88

9+
#include <chainparamsbase.h>
10+
#include <tinyformat.h>
11+
912
#include <QApplication>
1013

1114
static const struct {
1215
const char *networkId;
1316
const char *appName;
1417
const int iconColorHueShift;
1518
const int iconColorSaturationReduction;
16-
const char *titleAddText;
1719
} network_styles[] = {
18-
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
19-
{"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
20-
{"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
20+
{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
21+
{"test", QAPP_APP_NAME_TESTNET, 70, 30},
22+
{"regtest", QAPP_APP_NAME_TESTNET, 160, 30}
2123
};
2224
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
2325

@@ -75,8 +77,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
7577
trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
7678
}
7779

78-
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
80+
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
7981
{
82+
std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId);
8083
for (unsigned x=0; x<network_styles_count; ++x)
8184
{
8285
if (networkId == network_styles[x].networkId)
@@ -85,8 +88,8 @@ const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
8588
network_styles[x].appName,
8689
network_styles[x].iconColorHueShift,
8790
network_styles[x].iconColorSaturationReduction,
88-
network_styles[x].titleAddText);
91+
titleAddText.c_str());
8992
}
9093
}
91-
return 0;
94+
return new NetworkStyle(strprintf("%s-%s", QAPP_APP_NAME_DEFAULT, networkId).c_str(), 250, 30, titleAddText.c_str());
9295
}

src/qt/networkstyle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NetworkStyle
1414
{
1515
public:
1616
/** Get style associated with provided BIP70 network id, or 0 if not known */
17-
static const NetworkStyle *instantiate(const QString &networkId);
17+
static const NetworkStyle* instantiate(const std::string& networkId);
1818

1919
const QString &getAppName() const { return appName; }
2020
const QIcon &getAppIcon() const { return appIcon; }

0 commit comments

Comments
 (0)