Skip to content

Commit 2351a06

Browse files
committed
Chainparams: Get rid of CChainParams& Params(std::string)
1 parent f87f362 commit 2351a06

File tree

8 files changed

+25
-29
lines changed

8 files changed

+25
-29
lines changed

src/bench/checkblock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
4040
char a = '\0';
4141
stream.write(&a, 1); // Prevent compaction
4242

43-
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
43+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
4444

4545
while (state.KeepRunning()) {
4646
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
4747
stream >> block;
4848
assert(stream.Rewind(sizeof(block_bench::block413567)));
4949

5050
CValidationState validationState;
51-
assert(CheckBlock(block, validationState, params));
51+
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
5252
}
5353
}
5454

src/chainparams.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ class CRegTestParams : public CChainParams {
333333
};
334334

335335
static std::unique_ptr<CChainParams> globalChainParams;
336-
static std::unique_ptr<CChainParams> globalSwitchingChainParams;
337336

338337
const CChainParams &Params() {
339338
assert(globalChainParams);
@@ -351,12 +350,6 @@ std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
351350
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
352351
}
353352

354-
const CChainParams& Params(const std::string& chain)
355-
{
356-
globalSwitchingChainParams = CreateChainParams(chain);
357-
return *globalSwitchingChainParams;
358-
}
359-
360353
void SelectParams(const std::string& network)
361354
{
362355
SelectBaseParams(network);

src/chainparams.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain);
109109
*/
110110
const CChainParams &Params();
111111

112-
/**
113-
* @returns CChainParams for the given BIP70 chain name.
114-
*/
115-
const CChainParams& Params(const std::string& chain);
116-
117112
/**
118113
* Sets the params returned by Params() to those for the given BIP70 chain name.
119114
* @throws std::runtime_error when the chain is not supported.

src/init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ std::string HelpMessage(HelpMessageMode mode)
330330
{
331331
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
332332
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
333+
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
334+
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
333335
const bool showDebug = GetBoolArg("-help-debug", false);
334336

335337
// When adding new options to the categories, please keep and ensure alphabetical ordering.
@@ -341,7 +343,7 @@ std::string HelpMessage(HelpMessageMode mode)
341343
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
342344
if (showDebug)
343345
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
344-
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()));
346+
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()));
345347
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
346348
if (mode == HMM_BITCOIND)
347349
{
@@ -395,7 +397,7 @@ std::string HelpMessage(HelpMessageMode mode)
395397
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
396398
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), DEFAULT_PERMIT_BAREMULTISIG));
397399
strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), DEFAULT_PEERBLOOMFILTERS));
398-
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), Params(CBaseChainParams::MAIN).GetDefaultPort(), Params(CBaseChainParams::TESTNET).GetDefaultPort()));
400+
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort()));
399401
strUsage += HelpMessageOpt("-proxy=<ip:port>", _("Connect through SOCKS5 proxy"));
400402
strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), DEFAULT_PROXYRANDOMIZE));
401403
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
@@ -432,8 +434,8 @@ std::string HelpMessage(HelpMessageMode mode)
432434
{
433435
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), DEFAULT_CHECKBLOCKS));
434436
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), DEFAULT_CHECKLEVEL));
435-
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()));
436-
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", Params(CBaseChainParams::MAIN).DefaultConsistencyChecks()));
437+
strUsage += HelpMessageOpt("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. Also sets -checkmempool (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
438+
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
437439
strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED));
438440
strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", DEFAULT_DISABLE_SAFEMODE));
439441
strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE));
@@ -474,7 +476,7 @@ std::string HelpMessage(HelpMessageMode mode)
474476

475477
strUsage += HelpMessageGroup(_("Node relay options:"));
476478
if (showDebug) {
477-
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
479+
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", defaultChainParams->RequireStandard()));
478480
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)));
479481
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)));
480482
}

src/qt/paymentserver.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
219219
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
220220
{
221221
CBitcoinAddress address(r.address.toStdString());
222+
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
222223

223-
if (address.IsValid(Params(CBaseChainParams::MAIN)))
224+
if (address.IsValid(*tempChainParams))
224225
{
225226
SelectParams(CBaseChainParams::MAIN);
226227
}
227-
else if (address.IsValid(Params(CBaseChainParams::TESTNET)))
228-
{
229-
SelectParams(CBaseChainParams::TESTNET);
228+
else {
229+
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
230+
if (address.IsValid(*tempChainParams))
231+
SelectParams(CBaseChainParams::TESTNET);
230232
}
231233
}
232234
}

src/test/main_tests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
3939

4040
BOOST_AUTO_TEST_CASE(block_subsidy_test)
4141
{
42-
TestBlockSubsidyHalvings(Params(CBaseChainParams::MAIN).GetConsensus()); // As in main
42+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
43+
TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
4344
TestBlockSubsidyHalvings(150); // As in regtest
4445
TestBlockSubsidyHalvings(1000); // Just another interval
4546
}
4647

4748
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
4849
{
49-
const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
50+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
5051
CAmount nSum = 0;
5152
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
52-
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
53+
CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
5354
BOOST_CHECK(nSubsidy <= 50 * COIN);
5455
nSum += nSubsidy * 1000;
5556
BOOST_CHECK(MoneyRange(nSum));

src/test/miner_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
194194
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
195195
{
196196
// Note that by default, these tests run with size accounting enabled.
197-
const CChainParams& chainparams = Params(CBaseChainParams::MAIN);
197+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
198+
const CChainParams& chainparams = *chainParams;
198199
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
199200
std::unique_ptr<CBlockTemplate> pblocktemplate;
200201
CMutableTransaction tx,tx2;

src/test/versionbits_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
209209
}
210210

211211
// Sanity checks of version bit deployments
212-
const Consensus::Params &mainnetParams = Params(CBaseChainParams::MAIN).GetConsensus();
212+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
213+
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
213214
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
214215
uint32_t bitmask = VersionBitsMask(mainnetParams, (Consensus::DeploymentPos)i);
215216
// Make sure that no deployment tries to set an invalid bit.
@@ -235,7 +236,8 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
235236
{
236237
// Check that ComputeBlockVersion will set the appropriate bit correctly
237238
// on mainnet.
238-
const Consensus::Params &mainnetParams = Params(CBaseChainParams::MAIN).GetConsensus();
239+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
240+
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
239241

240242
// Use the TESTDUMMY deployment for testing purposes.
241243
int64_t bit = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit;

0 commit comments

Comments
 (0)