mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Testchains: Introduce custom chain whose constructor...
...reads params from regular arguments
This commit is contained in:
parent
46749eba94
commit
a06be15279
4 changed files with 78 additions and 5 deletions
|
|
@ -395,6 +395,73 @@ void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom params for testing.
|
||||
*/
|
||||
class CCustomParams : public CRegTestParams {
|
||||
void UpdateFromArgs(ArgsManager& args)
|
||||
{
|
||||
UpdateVersionBitsParametersFromArgs(args);
|
||||
|
||||
consensus.nSubsidyHalvingInterval = args.GetArg("-con_nsubsidyhalvinginterval", consensus.nSubsidyHalvingInterval);
|
||||
consensus.BIP16Exception = uint256S(args.GetArg("-con_bip16exception", "0x0"));
|
||||
consensus.BIP34Height = args.GetArg("-con_bip34height", consensus.BIP34Height);
|
||||
consensus.BIP34Hash = uint256S(args.GetArg("-con_bip34hash", "0x0"));
|
||||
consensus.BIP65Height = args.GetArg("-con_bip65height", consensus.BIP65Height);
|
||||
consensus.BIP66Height = args.GetArg("-con_bip66height", consensus.BIP66Height);
|
||||
consensus.powLimit = uint256S(args.GetArg("-con_powlimit", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
|
||||
consensus.nPowTargetTimespan = args.GetArg("-con_npowtargettimespan", consensus.nPowTargetTimespan);
|
||||
consensus.nPowTargetSpacing = args.GetArg("-con_npowtargetspacing", consensus.nPowTargetSpacing);
|
||||
consensus.fPowAllowMinDifficultyBlocks = args.GetBoolArg("-con_fpowallowmindifficultyblocks", consensus.fPowAllowMinDifficultyBlocks);
|
||||
consensus.fPowNoRetargeting = args.GetBoolArg("-con_fpownoretargeting", consensus.fPowNoRetargeting);
|
||||
consensus.nRuleChangeActivationThreshold = (uint32_t)args.GetArg("-con_nrulechangeactivationthreshold", consensus.nRuleChangeActivationThreshold);
|
||||
consensus.nMinerConfirmationWindow = (uint32_t)args.GetArg("-con_nminerconfirmationwindow", consensus.nMinerConfirmationWindow);
|
||||
|
||||
consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0"));
|
||||
consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00"));
|
||||
|
||||
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
|
||||
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);
|
||||
fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand);
|
||||
m_fallback_fee_enabled = args.GetBoolArg("-fallback_fee_enabled", m_fallback_fee_enabled);
|
||||
|
||||
bech32_hrp = args.GetArg("-bech32_hrp", bech32_hrp);
|
||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, args.GetArg("-pubkeyprefix", 111));
|
||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, args.GetArg("-scriptprefix", 196));
|
||||
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, args.GetArg("-secretprefix", 239));
|
||||
|
||||
std::string extpubprefix = args.GetArg("-extpubkeyprefix", "043587CF");
|
||||
assert(IsHex(extpubprefix) && extpubprefix.size() == 8 && "-extpubkeyprefix must be hex string of length 8");
|
||||
base58Prefixes[EXT_PUBLIC_KEY] = ParseHex(extpubprefix);
|
||||
|
||||
std::string extprvprefix = args.GetArg("-extprvkeyprefix", "04358394");
|
||||
assert(IsHex(extprvprefix) && extprvprefix.size() == 8 && "-extprvkeyprefix must be hex string of length 8");
|
||||
base58Prefixes[EXT_SECRET_KEY] = ParseHex(extprvprefix);
|
||||
|
||||
const std::string magic_str = args.GetArg("-pchmessagestart", "FABFB5DA");
|
||||
assert(IsHex(magic_str) && magic_str.size() == 8 && "-pchmessagestart must be hex string of length 8");
|
||||
const std::vector<unsigned char> magic_byte = ParseHex(magic_str);
|
||||
std::copy(begin(magic_byte), end(magic_byte), pchMessageStart);
|
||||
|
||||
vSeeds.clear();
|
||||
if (gArgs.IsArgSet("-seednode")) {
|
||||
const auto seednodes = gArgs.GetArgs("-seednode");
|
||||
if (seednodes.size() != 1 || seednodes[0] != "0") {
|
||||
vSeeds = seednodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args)
|
||||
{
|
||||
strNetworkID = chain;
|
||||
UpdateFromArgs(args);
|
||||
genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN);
|
||||
consensus.hashGenesisBlock = genesis.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
static std::unique_ptr<const CChainParams> globalChainParams;
|
||||
|
||||
const CChainParams &Params() {
|
||||
|
|
@ -404,13 +471,15 @@ const CChainParams &Params() {
|
|||
|
||||
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
|
||||
{
|
||||
// Reserved names for non-custom chains
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
return std::unique_ptr<CChainParams>(new CMainParams());
|
||||
else if (chain == CBaseChainParams::TESTNET)
|
||||
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
||||
else if (chain == CBaseChainParams::REGTEST)
|
||||
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
|
||||
return std::unique_ptr<CChainParams>(new CCustomParams(chain, gArgs));
|
||||
}
|
||||
|
||||
void SelectParams(const std::string& network)
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ const std::string CBaseChainParams::REGTEST = "regtest";
|
|||
|
||||
void SetupChainParamsBaseOptions()
|
||||
{
|
||||
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, testnet, regtest", false, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Reserved values: main, test, regtest", false, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
|
||||
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", true, OptionsCategory::CHAINPARAMS);
|
||||
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest or custom only)", true, OptionsCategory::CHAINPARAMS);
|
||||
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);
|
||||
}
|
||||
|
||||
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
|
||||
|
|
@ -40,8 +41,8 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain
|
|||
return MakeUnique<CBaseChainParams>("testnet3", 18332);
|
||||
else if (chain == CBaseChainParams::REGTEST)
|
||||
return MakeUnique<CBaseChainParams>("regtest", 18443);
|
||||
else
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
|
||||
return MakeUnique<CBaseChainParams>(chain, 18553);
|
||||
}
|
||||
|
||||
void SelectBaseParams(const std::string& chain)
|
||||
|
|
|
|||
|
|
@ -349,6 +349,7 @@ void SetupServerArgs()
|
|||
// Hidden Options
|
||||
std::vector<std::string> hidden_args = {"-rpcssl", "-benchmark", "-h", "-help", "-socks", "-tor", "-debugnet", "-whitelistalwaysrelay",
|
||||
"-prematurewitness", "-walletprematurewitness", "-promiscuousmempoolflags", "-blockminsize", "-dbcrashratio", "-forcecompactdb", "-usehd",
|
||||
"-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",
|
||||
// GUI args. These will be overwritten by SetupUIArgs for the GUI
|
||||
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-rootcertificates=<file>", "-splash", "-uiplatform"};
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR
|
|||
# list unsupported, deprecated and duplicate args as they need no documentation
|
||||
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-promiscuousmempoolflags', '-blockminsize', '-dbcrashratio', '-forcecompactdb', '-usehd'])
|
||||
|
||||
SET_DOC_OPTIONAL.update(['-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'])
|
||||
|
||||
|
||||
def main():
|
||||
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue