mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
Chainparams: Get rid of CChainParams& Params(std::string)
This commit is contained in:
parent
f87f3626e3
commit
2351a064a6
@ -40,7 +40,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
||||
char a = '\0';
|
||||
stream.write(&a, 1); // Prevent compaction
|
||||
|
||||
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
||||
@ -48,7 +48,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
||||
assert(stream.Rewind(sizeof(block_bench::block413567)));
|
||||
|
||||
CValidationState validationState;
|
||||
assert(CheckBlock(block, validationState, params));
|
||||
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +333,6 @@ public:
|
||||
};
|
||||
|
||||
static std::unique_ptr<CChainParams> globalChainParams;
|
||||
static std::unique_ptr<CChainParams> globalSwitchingChainParams;
|
||||
|
||||
const CChainParams &Params() {
|
||||
assert(globalChainParams);
|
||||
@ -351,12 +350,6 @@ std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
}
|
||||
|
||||
const CChainParams& Params(const std::string& chain)
|
||||
{
|
||||
globalSwitchingChainParams = CreateChainParams(chain);
|
||||
return *globalSwitchingChainParams;
|
||||
}
|
||||
|
||||
void SelectParams(const std::string& network)
|
||||
{
|
||||
SelectBaseParams(network);
|
||||
|
@ -109,11 +109,6 @@ std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain);
|
||||
*/
|
||||
const CChainParams &Params();
|
||||
|
||||
/**
|
||||
* @returns CChainParams for the given BIP70 chain name.
|
||||
*/
|
||||
const CChainParams& Params(const std::string& chain);
|
||||
|
||||
/**
|
||||
* Sets the params returned by Params() to those for the given BIP70 chain name.
|
||||
* @throws std::runtime_error when the chain is not supported.
|
||||
|
12
src/init.cpp
12
src/init.cpp
@ -330,6 +330,8 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
{
|
||||
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
|
||||
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
|
||||
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||
const bool showDebug = GetBoolArg("-help-debug", false);
|
||||
|
||||
// When adding new options to the categories, please keep and ensure alphabetical ordering.
|
||||
@ -341,7 +343,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
|
||||
if (showDebug)
|
||||
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
|
||||
strUsage +=HelpMessageOpt("-assumevalid=<hex>", strprintf(_("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)"), Params(CBaseChainParams::MAIN).GetConsensus().defaultAssumeValid.GetHex(), Params(CBaseChainParams::TESTNET).GetConsensus().defaultAssumeValid.GetHex()));
|
||||
strUsage +=HelpMessageOpt("-assumevalid=<hex>", strprintf(_("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)"), defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()));
|
||||
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
|
||||
if (mode == HMM_BITCOIND)
|
||||
{
|
||||
@ -395,7 +397,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
|
||||
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), DEFAULT_PERMIT_BAREMULTISIG));
|
||||
strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), DEFAULT_PEERBLOOMFILTERS));
|
||||
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), Params(CBaseChainParams::MAIN).GetDefaultPort(), Params(CBaseChainParams::TESTNET).GetDefaultPort()));
|
||||
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort()));
|
||||
strUsage += HelpMessageOpt("-proxy=<ip:port>", _("Connect through SOCKS5 proxy"));
|
||||
strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), DEFAULT_PROXYRANDOMIZE));
|
||||
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
|
||||
@ -432,8 +434,8 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
{
|
||||
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), DEFAULT_CHECKBLOCKS));
|
||||
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), DEFAULT_CHECKLEVEL));
|
||||
strUsage += HelpMessageOpt("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. Also sets -checkmempool (default: %u)", Params(CBaseChainParams::MAIN).DefaultConsistencyChecks()));
|
||||
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", Params(CBaseChainParams::MAIN).DefaultConsistencyChecks()));
|
||||
strUsage += HelpMessageOpt("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. Also sets -checkmempool (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
|
||||
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
|
||||
strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED));
|
||||
strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", DEFAULT_DISABLE_SAFEMODE));
|
||||
strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE));
|
||||
@ -474,7 +476,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
|
||||
strUsage += HelpMessageGroup(_("Node relay options:"));
|
||||
if (showDebug) {
|
||||
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
|
||||
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", defaultChainParams->RequireStandard()));
|
||||
strUsage += HelpMessageOpt("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)));
|
||||
strUsage += HelpMessageOpt("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to defined dust, the value of an output such that it will cost about 1/3 of its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)));
|
||||
}
|
||||
|
@ -219,14 +219,16 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
|
||||
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
|
||||
{
|
||||
CBitcoinAddress address(r.address.toStdString());
|
||||
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
|
||||
if (address.IsValid(Params(CBaseChainParams::MAIN)))
|
||||
if (address.IsValid(*tempChainParams))
|
||||
{
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
}
|
||||
else if (address.IsValid(Params(CBaseChainParams::TESTNET)))
|
||||
{
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
else {
|
||||
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||
if (address.IsValid(*tempChainParams))
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,17 +39,18 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
||||
{
|
||||
TestBlockSubsidyHalvings(Params(CBaseChainParams::MAIN).GetConsensus()); // As in main
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
|
||||
TestBlockSubsidyHalvings(150); // As in regtest
|
||||
TestBlockSubsidyHalvings(1000); // Just another interval
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
|
||||
{
|
||||
const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
CAmount nSum = 0;
|
||||
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
|
||||
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
||||
CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
|
||||
BOOST_CHECK(nSubsidy <= 50 * COIN);
|
||||
nSum += nSubsidy * 1000;
|
||||
BOOST_CHECK(MoneyRange(nSum));
|
||||
|
@ -194,7 +194,8 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
|
||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
{
|
||||
// Note that by default, these tests run with size accounting enabled.
|
||||
const CChainParams& chainparams = Params(CBaseChainParams::MAIN);
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const CChainParams& chainparams = *chainParams;
|
||||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate;
|
||||
CMutableTransaction tx,tx2;
|
||||
|
@ -209,7 +209,8 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
|
||||
}
|
||||
|
||||
// Sanity checks of version bit deployments
|
||||
const Consensus::Params &mainnetParams = Params(CBaseChainParams::MAIN).GetConsensus();
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
|
||||
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||
uint32_t bitmask = VersionBitsMask(mainnetParams, (Consensus::DeploymentPos)i);
|
||||
// Make sure that no deployment tries to set an invalid bit.
|
||||
@ -235,7 +236,8 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
|
||||
{
|
||||
// Check that ComputeBlockVersion will set the appropriate bit correctly
|
||||
// on mainnet.
|
||||
const Consensus::Params &mainnetParams = Params(CBaseChainParams::MAIN).GetConsensus();
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
|
||||
|
||||
// Use the TESTDUMMY deployment for testing purposes.
|
||||
int64_t bit = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit;
|
||||
|
Loading…
Reference in New Issue
Block a user