Skip to content

Commit c973cc5

Browse files
committed
Merge #8855: Use a proper factory for creating chainparams
c1082a7 Chainparams: Use the factory for pow tests (Jorge Timón) 2351a06 Chainparams: Get rid of CChainParams& Params(std::string) (Jorge Timón) f87f362 Chainparams: Use a regular factory for creating chainparams (Jorge Timón) Tree-SHA512: 359c8a2a1bc9d02db7856d02810240ada28048ac088f878b575597a7255cdb0ffdd1a647085ee67a34c6a7e7ed9e6cfdb61240cf6e75139619b640dbb096072c
2 parents 08a7316 + c1082a7 commit c973cc5

12 files changed

+86
-81
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/bitcoin-cli.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static const int CONTINUE_EXECUTION=-1;
3030

3131
std::string HelpMessageCli()
3232
{
33+
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
34+
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
3335
std::string strUsage;
3436
strUsage += HelpMessageGroup(_("Options:"));
3537
strUsage += HelpMessageOpt("-?", _("This help message"));
@@ -38,7 +40,7 @@ std::string HelpMessageCli()
3840
AppendParamsHelpMessages(strUsage);
3941
strUsage += HelpMessageOpt("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED));
4042
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
41-
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), BaseParams(CBaseChainParams::MAIN).RPCPort(), BaseParams(CBaseChainParams::TESTNET).RPCPort()));
43+
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
4244
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
4345
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
4446
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));

src/chainparams.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
5555
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
5656
}
5757

58+
void CChainParams::UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
59+
{
60+
consensus.vDeployments[d].nStartTime = nStartTime;
61+
consensus.vDeployments[d].nTimeout = nTimeout;
62+
}
63+
5864
/**
5965
* Main network
6066
*/
@@ -165,7 +171,6 @@ class CMainParams : public CChainParams {
165171
};
166172
}
167173
};
168-
static CMainParams mainParams;
169174

170175
/**
171176
* Testnet (v3)
@@ -253,7 +258,6 @@ class CTestNetParams : public CChainParams {
253258

254259
}
255260
};
256-
static CTestNetParams testNetParams;
257261

258262
/**
259263
* Regression test
@@ -326,42 +330,34 @@ class CRegTestParams : public CChainParams {
326330
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
327331
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
328332
}
329-
330-
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
331-
{
332-
consensus.vDeployments[d].nStartTime = nStartTime;
333-
consensus.vDeployments[d].nTimeout = nTimeout;
334-
}
335333
};
336-
static CRegTestParams regTestParams;
337334

338-
static CChainParams *pCurrentParams = 0;
335+
static std::unique_ptr<CChainParams> globalChainParams;
339336

340337
const CChainParams &Params() {
341-
assert(pCurrentParams);
342-
return *pCurrentParams;
338+
assert(globalChainParams);
339+
return *globalChainParams;
343340
}
344341

345-
CChainParams& Params(const std::string& chain)
342+
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
346343
{
347344
if (chain == CBaseChainParams::MAIN)
348-
return mainParams;
345+
return std::unique_ptr<CChainParams>(new CMainParams());
349346
else if (chain == CBaseChainParams::TESTNET)
350-
return testNetParams;
347+
return std::unique_ptr<CChainParams>(new CTestNetParams());
351348
else if (chain == CBaseChainParams::REGTEST)
352-
return regTestParams;
353-
else
354-
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
349+
return std::unique_ptr<CChainParams>(new CRegTestParams());
350+
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
355351
}
356352

357353
void SelectParams(const std::string& network)
358354
{
359355
SelectBaseParams(network);
360-
pCurrentParams = &Params(network);
356+
globalChainParams = CreateChainParams(network);
361357
}
362358

363-
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
359+
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
364360
{
365-
regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout);
361+
globalChainParams->UpdateBIP9Parameters(d, nStartTime, nTimeout);
366362
}
367363

src/chainparams.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "primitives/block.h"
1212
#include "protocol.h"
1313

14+
#include <memory>
1415
#include <vector>
1516

1617
struct CDNSSeedData {
@@ -75,6 +76,7 @@ class CChainParams
7576
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
7677
const CCheckpointData& Checkpoints() const { return checkpointData; }
7778
const ChainTxData& TxData() const { return chainTxData; }
79+
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout);
7880
protected:
7981
CChainParams() {}
8082

@@ -95,15 +97,17 @@ class CChainParams
9597
};
9698

9799
/**
98-
* Return the currently selected parameters. This won't change after app
99-
* startup, except for unit tests.
100+
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
101+
* @returns a CChainParams* of the chosen chain.
102+
* @throws a std::runtime_error if the chain is not supported.
100103
*/
101-
const CChainParams &Params();
104+
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain);
102105

103106
/**
104-
* @returns CChainParams for the given BIP70 chain name.
107+
* Return the currently selected parameters. This won't change after app
108+
* startup, except for unit tests.
105109
*/
106-
CChainParams& Params(const std::string& chain);
110+
const CChainParams &Params();
107111

108112
/**
109113
* Sets the params returned by Params() to those for the given BIP70 chain name.
@@ -114,6 +118,6 @@ void SelectParams(const std::string& chain);
114118
/**
115119
* Allows modifying the BIP9 regtest parameters.
116120
*/
117-
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout);
121+
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout);
118122

119123
#endif // BITCOIN_CHAINPARAMS_H

src/chainparamsbase.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class CBaseMainParams : public CBaseChainParams
3535
nRPCPort = 8332;
3636
}
3737
};
38-
static CBaseMainParams mainParams;
3938

4039
/**
4140
* Testnet (v3)
@@ -49,7 +48,6 @@ class CBaseTestNetParams : public CBaseChainParams
4948
strDataDir = "testnet3";
5049
}
5150
};
52-
static CBaseTestNetParams testNetParams;
5351

5452
/*
5553
* Regression test
@@ -63,31 +61,30 @@ class CBaseRegTestParams : public CBaseChainParams
6361
strDataDir = "regtest";
6462
}
6563
};
66-
static CBaseRegTestParams regTestParams;
6764

68-
static CBaseChainParams* pCurrentBaseParams = 0;
65+
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
6966

7067
const CBaseChainParams& BaseParams()
7168
{
72-
assert(pCurrentBaseParams);
73-
return *pCurrentBaseParams;
69+
assert(globalChainBaseParams);
70+
return *globalChainBaseParams;
7471
}
7572

76-
CBaseChainParams& BaseParams(const std::string& chain)
73+
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
7774
{
7875
if (chain == CBaseChainParams::MAIN)
79-
return mainParams;
76+
return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
8077
else if (chain == CBaseChainParams::TESTNET)
81-
return testNetParams;
78+
return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
8279
else if (chain == CBaseChainParams::REGTEST)
83-
return regTestParams;
80+
return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
8481
else
8582
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
8683
}
8784

8885
void SelectBaseParams(const std::string& chain)
8986
{
90-
pCurrentBaseParams = &BaseParams(chain);
87+
globalChainBaseParams = CreateBaseChainParams(chain);
9188
}
9289

9390
std::string ChainNameFromCommandLine()

src/chainparamsbase.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_CHAINPARAMSBASE_H
66
#define BITCOIN_CHAINPARAMSBASE_H
77

8+
#include <memory>
89
#include <string>
910
#include <vector>
1011

@@ -30,6 +31,13 @@ class CBaseChainParams
3031
std::string strDataDir;
3132
};
3233

34+
/**
35+
* Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain.
36+
* @returns a CBaseChainParams* of the chosen chain.
37+
* @throws a std::runtime_error if the chain is not supported.
38+
*/
39+
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);
40+
3341
/**
3442
* Append the help messages for the chainparams options to the
3543
* parameter string.
@@ -42,8 +50,6 @@ void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
4250
*/
4351
const CBaseChainParams& BaseParams();
4452

45-
CBaseChainParams& BaseParams(const std::string& chain);
46-
4753
/** Sets the params returned by Params() to those for the given network. */
4854
void SelectBaseParams(const std::string& chain);
4955

src/init.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ void OnRPCPreCommand(const CRPCCommand& cmd)
329329

330330
std::string HelpMessage(HelpMessageMode mode)
331331
{
332+
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
333+
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
334+
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
335+
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
332336
const bool showDebug = GetBoolArg("-help-debug", false);
333337

334338
// When adding new options to the categories, please keep and ensure alphabetical ordering.
@@ -340,7 +344,7 @@ std::string HelpMessage(HelpMessageMode mode)
340344
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
341345
if (showDebug)
342346
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
343-
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()));
347+
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()));
344348
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
345349
if (mode == HMM_BITCOIND)
346350
{
@@ -394,7 +398,7 @@ std::string HelpMessage(HelpMessageMode mode)
394398
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
395399
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), DEFAULT_PERMIT_BAREMULTISIG));
396400
strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), DEFAULT_PEERBLOOMFILTERS));
397-
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), Params(CBaseChainParams::MAIN).GetDefaultPort(), Params(CBaseChainParams::TESTNET).GetDefaultPort()));
401+
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort()));
398402
strUsage += HelpMessageOpt("-proxy=<ip:port>", _("Connect through SOCKS5 proxy"));
399403
strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), DEFAULT_PROXYRANDOMIZE));
400404
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
@@ -431,8 +435,8 @@ std::string HelpMessage(HelpMessageMode mode)
431435
{
432436
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), DEFAULT_CHECKBLOCKS));
433437
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), DEFAULT_CHECKLEVEL));
434-
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()));
435-
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", Params(CBaseChainParams::MAIN).DefaultConsistencyChecks()));
438+
strUsage += HelpMessageOpt("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. Also sets -checkmempool (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
439+
strUsage += HelpMessageOpt("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u)", defaultChainParams->DefaultConsistencyChecks()));
436440
strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED));
437441
strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", DEFAULT_DISABLE_SAFEMODE));
438442
strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE));
@@ -473,7 +477,7 @@ std::string HelpMessage(HelpMessageMode mode)
473477

474478
strUsage += HelpMessageGroup(_("Node relay options:"));
475479
if (showDebug) {
476-
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !Params(CBaseChainParams::TESTNET).RequireStandard()));
480+
strUsage += HelpMessageOpt("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", defaultChainParams->RequireStandard()));
477481
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)));
478482
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)));
479483
}
@@ -501,7 +505,7 @@ std::string HelpMessage(HelpMessageMode mode)
501505
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
502506
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
503507
strUsage += HelpMessageOpt("-rpcauth=<userpw>", _("Username and hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcuser. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times"));
504-
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), BaseParams(CBaseChainParams::MAIN).RPCPort(), BaseParams(CBaseChainParams::TESTNET).RPCPort()));
508+
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
505509
strUsage += HelpMessageOpt("-rpcallowip=<ip>", _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times"));
506510
strUsage += HelpMessageOpt("-rpcserialversion", strprintf(_("Sets the serialization of raw transaction or block hex returned in non-verbose mode, non-segwit(0) or segwit(1) (default: %d)"), DEFAULT_RPC_SERIALIZE_VERSION));
507511
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
@@ -1124,7 +1128,7 @@ bool AppInitParameterInteraction()
11241128
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j)
11251129
{
11261130
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[j].name) == 0) {
1127-
UpdateRegtestBIP9Parameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
1131+
UpdateBIP9Parameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
11281132
found = true;
11291133
LogPrintf("Setting BIP9 activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
11301134
break;

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));

0 commit comments

Comments
 (0)