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
This commit is contained in:
parent
175d68ac21
commit
50652674b5
@ -38,7 +38,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
|||||||
char a = '\0';
|
char a = '\0';
|
||||||
stream.write(&a, 1); // Prevent compaction
|
stream.write(&a, 1); // Prevent compaction
|
||||||
|
|
||||||
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
|
|
||||||
while (state.KeepRunning()) {
|
while (state.KeepRunning()) {
|
||||||
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
||||||
@ -46,7 +46,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
|||||||
assert(stream.Rewind(sizeof(raw_bench::block813851)));
|
assert(stream.Rewind(sizeof(raw_bench::block813851)));
|
||||||
|
|
||||||
CValidationState validationState;
|
CValidationState validationState;
|
||||||
assert(CheckBlock(block, validationState, params, block.GetBlockTime()));
|
assert(CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,32 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
|
|||||||
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CChainParams::UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold)
|
||||||
|
{
|
||||||
|
consensus.vDeployments[d].nStartTime = nStartTime;
|
||||||
|
consensus.vDeployments[d].nTimeout = nTimeout;
|
||||||
|
if (nWindowSize != -1) {
|
||||||
|
consensus.vDeployments[d].nWindowSize = nWindowSize;
|
||||||
|
}
|
||||||
|
if (nThreshold != -1) {
|
||||||
|
consensus.vDeployments[d].nThreshold = nThreshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChainParams::UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
|
||||||
|
{
|
||||||
|
consensus.DIP0003Height = nActivationHeight;
|
||||||
|
consensus.DIP0003EnforcementHeight = nEnforcementHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CChainParams::UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock)
|
||||||
|
{
|
||||||
|
consensus.nMasternodePaymentsStartBlock = nMasternodePaymentsStartBlock;
|
||||||
|
consensus.nBudgetPaymentsStartBlock = nBudgetPaymentsStartBlock;
|
||||||
|
consensus.nSuperblockStartBlock = nSuperblockStartBlock;
|
||||||
|
}
|
||||||
|
|
||||||
static CBlock FindDevNetGenesisBlock(const Consensus::Params& params, const CBlock &prevBlock, const CAmount& reward)
|
static CBlock FindDevNetGenesisBlock(const Consensus::Params& params, const CBlock &prevBlock, const CAmount& reward)
|
||||||
{
|
{
|
||||||
std::string devNetName = GetDevNetName();
|
std::string devNetName = GetDevNetName();
|
||||||
@ -370,7 +396,6 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CMainParams mainParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testnet (v3)
|
* Testnet (v3)
|
||||||
@ -529,7 +554,6 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CTestNetParams testNetParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Devnet
|
* Devnet
|
||||||
@ -823,54 +847,26 @@ public:
|
|||||||
consensus.llmqChainLocks = Consensus::LLMQ_5_60;
|
consensus.llmqChainLocks = Consensus::LLMQ_5_60;
|
||||||
consensus.llmqForInstantSend = Consensus::LLMQ_5_60;
|
consensus.llmqForInstantSend = Consensus::LLMQ_5_60;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold)
|
|
||||||
{
|
|
||||||
consensus.vDeployments[d].nStartTime = nStartTime;
|
|
||||||
consensus.vDeployments[d].nTimeout = nTimeout;
|
|
||||||
if (nWindowSize != -1) {
|
|
||||||
consensus.vDeployments[d].nWindowSize = nWindowSize;
|
|
||||||
}
|
|
||||||
if (nThreshold != -1) {
|
|
||||||
consensus.vDeployments[d].nThreshold = nThreshold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
|
|
||||||
{
|
|
||||||
consensus.DIP0003Height = nActivationHeight;
|
|
||||||
consensus.DIP0003EnforcementHeight = nEnforcementHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock)
|
|
||||||
{
|
|
||||||
consensus.nMasternodePaymentsStartBlock = nMasternodePaymentsStartBlock;
|
|
||||||
consensus.nBudgetPaymentsStartBlock = nBudgetPaymentsStartBlock;
|
|
||||||
consensus.nSuperblockStartBlock = nSuperblockStartBlock;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
static CRegTestParams regTestParams;
|
|
||||||
|
|
||||||
static CChainParams *pCurrentParams = 0;
|
static std::unique_ptr<CChainParams> globalChainParams;
|
||||||
|
|
||||||
const CChainParams &Params() {
|
const CChainParams &Params() {
|
||||||
assert(pCurrentParams);
|
assert(globalChainParams);
|
||||||
return *pCurrentParams;
|
return *globalChainParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
CChainParams& Params(const std::string& chain)
|
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
|
||||||
{
|
{
|
||||||
if (chain == CBaseChainParams::MAIN)
|
if (chain == CBaseChainParams::MAIN)
|
||||||
return mainParams;
|
return std::unique_ptr<CChainParams>(new CMainParams());
|
||||||
else if (chain == CBaseChainParams::TESTNET)
|
else if (chain == CBaseChainParams::TESTNET)
|
||||||
return testNetParams;
|
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
||||||
else if (chain == CBaseChainParams::DEVNET) {
|
else if (chain == CBaseChainParams::DEVNET) {
|
||||||
assert(devNetParams);
|
return std::unique_ptr<CChainParams>(new CDevNetParams());
|
||||||
return *devNetParams;
|
|
||||||
} else if (chain == CBaseChainParams::REGTEST)
|
} else if (chain == CBaseChainParams::REGTEST)
|
||||||
return regTestParams;
|
return std::unique_ptr<CChainParams>(new CRegTestParams());
|
||||||
else
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectParams(const std::string& network)
|
void SelectParams(const std::string& network)
|
||||||
@ -882,22 +878,22 @@ void SelectParams(const std::string& network)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SelectBaseParams(network);
|
SelectBaseParams(network);
|
||||||
pCurrentParams = &Params(network);
|
globalChainParams = CreateChainParams(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold)
|
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold)
|
||||||
{
|
{
|
||||||
regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout, nWindowSize, nThreshold);
|
globalChainParams->UpdateBIP9Parameters(d, nStartTime, nTimeout, nWindowSize, nThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateRegtestDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
|
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
|
||||||
{
|
{
|
||||||
regTestParams.UpdateDIP3Parameters(nActivationHeight, nEnforcementHeight);
|
globalChainParams->UpdateDIP3Parameters(nActivationHeight, nEnforcementHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock)
|
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock)
|
||||||
{
|
{
|
||||||
regTestParams.UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock);
|
globalChainParams->UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDevnetSubsidyAndDiffParams(int nMinimumDifficultyBlocks, int nHighSubsidyBlocks, int nHighSubsidyFactor)
|
void UpdateDevnetSubsidyAndDiffParams(int nMinimumDifficultyBlocks, int nHighSubsidyBlocks, int nHighSubsidyFactor)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "primitives/block.h"
|
#include "primitives/block.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct CDNSSeedData {
|
struct CDNSSeedData {
|
||||||
@ -83,6 +84,9 @@ public:
|
|||||||
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
|
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
|
||||||
const CCheckpointData& Checkpoints() const { return checkpointData; }
|
const CCheckpointData& Checkpoints() const { return checkpointData; }
|
||||||
const ChainTxData& TxData() const { return chainTxData; }
|
const ChainTxData& TxData() const { return chainTxData; }
|
||||||
|
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold);
|
||||||
|
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight);
|
||||||
|
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock);
|
||||||
int PoolMinParticipants() const { return nPoolMinParticipants; }
|
int PoolMinParticipants() const { return nPoolMinParticipants; }
|
||||||
int PoolMaxParticipants() const { return nPoolMaxParticipants; }
|
int PoolMaxParticipants() const { return nPoolMaxParticipants; }
|
||||||
int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; }
|
int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; }
|
||||||
@ -119,17 +123,19 @@ protected:
|
|||||||
bool fBIP9CheckMasternodesUpgraded;
|
bool fBIP9CheckMasternodesUpgraded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
|
||||||
|
* @returns a CChainParams* of the chosen chain.
|
||||||
|
* @throws a std::runtime_error if the chain is not supported.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently selected parameters. This won't change after app
|
* Return the currently selected parameters. This won't change after app
|
||||||
* startup, except for unit tests.
|
* startup, except for unit tests.
|
||||||
*/
|
*/
|
||||||
const CChainParams &Params();
|
const CChainParams &Params();
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns CChainParams for the given BIP70 chain name.
|
|
||||||
*/
|
|
||||||
CChainParams& Params(const std::string& chain);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the params returned by Params() to those for the given BIP70 chain name.
|
* Sets the params returned by Params() to those for the given BIP70 chain name.
|
||||||
* @throws std::runtime_error when the chain is not supported.
|
* @throws std::runtime_error when the chain is not supported.
|
||||||
@ -139,17 +145,17 @@ void SelectParams(const std::string& chain);
|
|||||||
/**
|
/**
|
||||||
* Allows modifying the BIP9 regtest parameters.
|
* Allows modifying the BIP9 regtest parameters.
|
||||||
*/
|
*/
|
||||||
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold);
|
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThreshold);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows modifying the DIP3 activation and enforcement height
|
* Allows modifying the DIP3 activation and enforcement height
|
||||||
*/
|
*/
|
||||||
void UpdateRegtestDIP3Parameters(int nActivationHeight, int nEnforcementHeight);
|
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows modifying the budget regtest parameters.
|
* Allows modifying the budget regtest parameters.
|
||||||
*/
|
*/
|
||||||
void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock);
|
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows modifying the subsidy and difficulty devnet parameters.
|
* Allows modifying the subsidy and difficulty devnet parameters.
|
||||||
|
@ -37,7 +37,6 @@ public:
|
|||||||
nRPCPort = 9998;
|
nRPCPort = 9998;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CBaseMainParams mainParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testnet (v3)
|
* Testnet (v3)
|
||||||
@ -51,7 +50,6 @@ public:
|
|||||||
strDataDir = "testnet3";
|
strDataDir = "testnet3";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CBaseTestNetParams testNetParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Devnet
|
* Devnet
|
||||||
@ -65,7 +63,6 @@ public:
|
|||||||
strDataDir = dataDir;
|
strDataDir = dataDir;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CBaseDevNetParams *devNetParams;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Regression test
|
* Regression test
|
||||||
@ -79,43 +76,32 @@ public:
|
|||||||
strDataDir = "regtest";
|
strDataDir = "regtest";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CBaseRegTestParams regTestParams;
|
|
||||||
|
|
||||||
static CBaseChainParams* pCurrentBaseParams = 0;
|
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
|
||||||
|
|
||||||
const CBaseChainParams& BaseParams()
|
const CBaseChainParams& BaseParams()
|
||||||
{
|
{
|
||||||
assert(pCurrentBaseParams);
|
assert(globalChainBaseParams);
|
||||||
return *pCurrentBaseParams;
|
return *globalChainBaseParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBaseChainParams& BaseParams(const std::string& chain)
|
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
|
||||||
{
|
{
|
||||||
if (chain == CBaseChainParams::MAIN)
|
if (chain == CBaseChainParams::MAIN)
|
||||||
return mainParams;
|
return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
|
||||||
else if (chain == CBaseChainParams::TESTNET)
|
else if (chain == CBaseChainParams::TESTNET)
|
||||||
return testNetParams;
|
return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
|
||||||
else if (chain == CBaseChainParams::DEVNET) {
|
else if (chain == CBaseChainParams::DEVNET) {
|
||||||
assert(devNetParams);
|
return std::unique_ptr<CBaseChainParams>(new CBaseDevNetParams(GetDevNetName()));
|
||||||
return *devNetParams;
|
|
||||||
} else if (chain == CBaseChainParams::REGTEST)
|
} else if (chain == CBaseChainParams::REGTEST)
|
||||||
return regTestParams;
|
return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
|
||||||
else
|
else
|
||||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectBaseParams(const std::string& chain)
|
void SelectBaseParams(const std::string& chain)
|
||||||
{
|
{
|
||||||
if (chain == CBaseChainParams::DEVNET) {
|
globalChainBaseParams = CreateBaseChainParams(chain);
|
||||||
std::string devNetName = GetDevNetName();
|
|
||||||
assert(!devNetName.empty());
|
|
||||||
|
|
||||||
devNetParams = (CBaseDevNetParams*)new uint8_t[sizeof(CBaseDevNetParams)];
|
|
||||||
memset(devNetParams, 0, sizeof(CBaseDevNetParams));
|
|
||||||
new (devNetParams) CBaseDevNetParams(devNetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
pCurrentBaseParams = &BaseParams(chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ChainNameFromCommandLine()
|
std::string ChainNameFromCommandLine()
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef BITCOIN_CHAINPARAMSBASE_H
|
#ifndef BITCOIN_CHAINPARAMSBASE_H
|
||||||
#define BITCOIN_CHAINPARAMSBASE_H
|
#define BITCOIN_CHAINPARAMSBASE_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -31,6 +32,13 @@ protected:
|
|||||||
std::string strDataDir;
|
std::string strDataDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain.
|
||||||
|
* @returns a CBaseChainParams* of the chosen chain.
|
||||||
|
* @throws a std::runtime_error if the chain is not supported.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append the help messages for the chainparams options to the
|
* Append the help messages for the chainparams options to the
|
||||||
* parameter string.
|
* parameter string.
|
||||||
@ -43,8 +51,6 @@ void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
|
|||||||
*/
|
*/
|
||||||
const CBaseChainParams& BaseParams();
|
const CBaseChainParams& BaseParams();
|
||||||
|
|
||||||
CBaseChainParams& BaseParams(const std::string& chain);
|
|
||||||
|
|
||||||
/** Sets the params returned by Params() to those for the given network. */
|
/** Sets the params returned by Params() to those for the given network. */
|
||||||
void SelectBaseParams(const std::string& chain);
|
void SelectBaseParams(const std::string& chain);
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ static const int CONTINUE_EXECUTION=-1;
|
|||||||
|
|
||||||
std::string HelpMessageCli()
|
std::string HelpMessageCli()
|
||||||
{
|
{
|
||||||
|
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
|
||||||
|
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
|
||||||
std::string strUsage;
|
std::string strUsage;
|
||||||
strUsage += HelpMessageGroup(_("Options:"));
|
strUsage += HelpMessageGroup(_("Options:"));
|
||||||
strUsage += HelpMessageOpt("-?", _("This help message"));
|
strUsage += HelpMessageOpt("-?", _("This help message"));
|
||||||
@ -40,7 +42,7 @@ std::string HelpMessageCli()
|
|||||||
AppendParamsHelpMessages(strUsage);
|
AppendParamsHelpMessages(strUsage);
|
||||||
strUsage += HelpMessageOpt("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED));
|
strUsage += HelpMessageOpt("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED));
|
||||||
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
|
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
|
||||||
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), BaseParams(CBaseChainParams::MAIN).RPCPort(), BaseParams(CBaseChainParams::TESTNET).RPCPort()));
|
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
|
||||||
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
|
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
|
||||||
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
|
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
|
||||||
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
|
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
|
||||||
|
@ -27,7 +27,7 @@ static bool CheckService(const uint256& proTxHash, const ProTx& proTx, CValidati
|
|||||||
return state.DoS(10, false, REJECT_INVALID, "bad-protx-addr");
|
return state.DoS(10, false, REJECT_INVALID, "bad-protx-addr");
|
||||||
}
|
}
|
||||||
|
|
||||||
int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort();
|
int mainnetDefaultPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPort();
|
||||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
|
||||||
if (proTx.addr.GetPort() != mainnetDefaultPort) {
|
if (proTx.addr.GetPort() != mainnetDefaultPort) {
|
||||||
return state.DoS(10, false, REJECT_INVALID, "bad-protx-addr-port");
|
return state.DoS(10, false, REJECT_INVALID, "bad-protx-addr-port");
|
||||||
|
22
src/init.cpp
22
src/init.cpp
@ -434,6 +434,10 @@ void OnRPCPreCommand(const CRPCCommand& cmd)
|
|||||||
|
|
||||||
std::string HelpMessage(HelpMessageMode mode)
|
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 = gArgs.GetBoolArg("-help-debug", false);
|
const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
|
||||||
|
|
||||||
// When adding new options to the categories, please keep and ensure alphabetical ordering.
|
// When adding new options to the categories, please keep and ensure alphabetical ordering.
|
||||||
@ -445,7 +449,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)"));
|
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
|
||||||
if (showDebug)
|
if (showDebug)
|
||||||
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
|
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));
|
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
|
||||||
if (mode == HMM_BITCOIND)
|
if (mode == HMM_BITCOIND)
|
||||||
{
|
{
|
||||||
@ -502,7 +506,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
|
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("-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("-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("-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("-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"));
|
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
|
||||||
@ -547,8 +551,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("-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("-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("-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)", Params(CBaseChainParams::MAIN).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("-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("-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));
|
strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE));
|
||||||
@ -617,7 +621,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
|
|
||||||
strUsage += HelpMessageGroup(_("Node relay options:"));
|
strUsage += HelpMessageGroup(_("Node relay options:"));
|
||||||
if (showDebug) {
|
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("-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)));
|
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)));
|
||||||
}
|
}
|
||||||
@ -643,7 +647,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
|
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
|
||||||
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
|
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
|
||||||
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"));
|
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"));
|
||||||
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()));
|
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
|
||||||
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"));
|
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"));
|
||||||
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
|
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
|
||||||
if (showDebug) {
|
if (showDebug) {
|
||||||
@ -1348,7 +1352,7 @@ bool AppInitParameterInteraction()
|
|||||||
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j)
|
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j)
|
||||||
{
|
{
|
||||||
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[j].name) == 0) {
|
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[j].name) == 0) {
|
||||||
UpdateRegtestBIP9Parameters(Consensus::DeploymentPos(j), nStartTime, nTimeout, nWindowSize, nThreshold);
|
UpdateBIP9Parameters(Consensus::DeploymentPos(j), nStartTime, nTimeout, nWindowSize, nThreshold);
|
||||||
found = true;
|
found = true;
|
||||||
LogPrintf("Setting BIP9 activation parameters for %s to start=%ld, timeout=%ld, window=%ld, threshold=%ld\n", vDeploymentParams[0], nStartTime, nTimeout, nWindowSize, nThreshold);
|
LogPrintf("Setting BIP9 activation parameters for %s to start=%ld, timeout=%ld, window=%ld, threshold=%ld\n", vDeploymentParams[0], nStartTime, nTimeout, nWindowSize, nThreshold);
|
||||||
break;
|
break;
|
||||||
@ -1378,7 +1382,7 @@ bool AppInitParameterInteraction()
|
|||||||
if (!ParseInt32(vDIP3Params[1], &nDIP3EnforcementHeight)) {
|
if (!ParseInt32(vDIP3Params[1], &nDIP3EnforcementHeight)) {
|
||||||
return InitError(strprintf("Invalid nDIP3EnforcementHeight (%s)", vDIP3Params[1]));
|
return InitError(strprintf("Invalid nDIP3EnforcementHeight (%s)", vDIP3Params[1]));
|
||||||
}
|
}
|
||||||
UpdateRegtestDIP3Parameters(nDIP3ActivationHeight, nDIP3EnforcementHeight);
|
UpdateDIP3Parameters(nDIP3ActivationHeight, nDIP3EnforcementHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-budgetparams")) {
|
if (gArgs.IsArgSet("-budgetparams")) {
|
||||||
@ -1403,7 +1407,7 @@ bool AppInitParameterInteraction()
|
|||||||
if (!ParseInt32(vBudgetParams[2], &nSuperblockStartBlock)) {
|
if (!ParseInt32(vBudgetParams[2], &nSuperblockStartBlock)) {
|
||||||
return InitError(strprintf("Invalid nSuperblockStartBlock (%s)", vBudgetParams[2]));
|
return InitError(strprintf("Invalid nSuperblockStartBlock (%s)", vBudgetParams[2]));
|
||||||
}
|
}
|
||||||
UpdateRegtestBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock);
|
UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chainparams.NetworkIDString() == CBaseChainParams::DEVNET) {
|
if (chainparams.NetworkIDString() == CBaseChainParams::DEVNET) {
|
||||||
|
@ -220,14 +220,16 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
|
|||||||
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
|
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
|
||||||
{
|
{
|
||||||
CBitcoinAddress address(r.address.toStdString());
|
CBitcoinAddress address(r.address.toStdString());
|
||||||
|
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
|
|
||||||
if (address.IsValid(Params(CBaseChainParams::MAIN)))
|
if (address.IsValid(*tempChainParams))
|
||||||
{
|
{
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
SelectParams(CBaseChainParams::MAIN);
|
||||||
}
|
}
|
||||||
else if (address.IsValid(Params(CBaseChainParams::TESTNET)))
|
else {
|
||||||
{
|
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
|
||||||
SelectParams(CBaseChainParams::TESTNET);
|
if (address.IsValid(*tempChainParams))
|
||||||
|
SelectParams(CBaseChainParams::TESTNET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,8 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
|
|||||||
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
|
||||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||||
{
|
{
|
||||||
const CChainParams& chainparams = Params(CBaseChainParams::MAIN);
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
|
const CChainParams& chainparams = *chainParams;
|
||||||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||||
std::unique_ptr<CBlockTemplate> pblocktemplate, pemptyblocktemplate;
|
std::unique_ptr<CBlockTemplate> pblocktemplate, pemptyblocktemplate;
|
||||||
CMutableTransaction tx,tx2;
|
CMutableTransaction tx,tx2;
|
||||||
|
@ -16,8 +16,7 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
|
|||||||
/* Test calculation of next difficulty target with DGW */
|
/* Test calculation of next difficulty target with DGW */
|
||||||
BOOST_AUTO_TEST_CASE(get_next_work)
|
BOOST_AUTO_TEST_CASE(get_next_work)
|
||||||
{
|
{
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
|
||||||
|
|
||||||
// build the chain of 24 blocks
|
// build the chain of 24 blocks
|
||||||
CBlockIndex blockIndexLast;
|
CBlockIndex blockIndexLast;
|
||||||
@ -119,81 +118,75 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
|||||||
|
|
||||||
CBlockHeader blockHeader;
|
CBlockHeader blockHeader;
|
||||||
blockHeader.nTime = 1408732505; // Block #123457
|
blockHeader.nTime = 1408732505; // Block #123457
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, params), 0x1b1441de); // Block #123457 has 0x1b1441de
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParams->GetConsensus()), 0x1b1441de); // Block #123457 has 0x1b1441de
|
||||||
|
|
||||||
// test special rules for slow blocks on devnet/testnet
|
// test special rules for slow blocks on devnet/testnet
|
||||||
gArgs.SoftSetBoolArg("-devnet", true);
|
gArgs.SoftSetBoolArg("-devnet", true);
|
||||||
SelectParams(CBaseChainParams::DEVNET);
|
const auto chainParamsDev = CreateChainParams(CBaseChainParams::DEVNET);
|
||||||
const Consensus::Params& paramsdev = Params().GetConsensus();
|
|
||||||
|
|
||||||
// make sure normal rules apply
|
// make sure normal rules apply
|
||||||
blockHeader.nTime = 1408732505; // Block #123457
|
blockHeader.nTime = 1408732505; // Block #123457
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1b1441de); // Block #123457 has 0x1b1441de
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1b1441de); // Block #123457 has 0x1b1441de
|
||||||
|
|
||||||
// 10x higher target
|
// 10x higher target
|
||||||
blockHeader.nTime = 1408733090; // Block #123457 (10m+1sec)
|
blockHeader.nTime = 1408733090; // Block #123457 (10m+1sec)
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
|
||||||
blockHeader.nTime = 1408733689; // Block #123457 (20m)
|
blockHeader.nTime = 1408733689; // Block #123457 (20m)
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
|
||||||
// lowest diff possible
|
// lowest diff possible
|
||||||
blockHeader.nTime = 1408739690; // Block #123457 (2h+1sec)
|
blockHeader.nTime = 1408739690; // Block #123457 (2h+1sec)
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x207fffff); // Block #123457 has 0x207fffff
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x207fffff); // Block #123457 has 0x207fffff
|
||||||
blockHeader.nTime = 1408743289; // Block #123457 (3h)
|
blockHeader.nTime = 1408743289; // Block #123457 (3h)
|
||||||
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x207fffff); // Block #123457 has 0x207fffff
|
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x207fffff); // Block #123457 has 0x207fffff
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the upper bound for next work */
|
/* Test the constraint on the upper bound for next work */
|
||||||
// BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
// BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
||||||
// {
|
// {
|
||||||
// SelectParams(CBaseChainParams::MAIN);
|
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
// const Consensus::Params& params = Params().GetConsensus();
|
|
||||||
|
|
||||||
// int64_t nLastRetargetTime = 1231006505; // Block #0
|
// int64_t nLastRetargetTime = 1231006505; // Block #0
|
||||||
// CBlockIndex pindexLast;
|
// CBlockIndex pindexLast;
|
||||||
// pindexLast.nHeight = 2015;
|
// pindexLast.nHeight = 2015;
|
||||||
// pindexLast.nTime = 1233061996; // Block #2015
|
// pindexLast.nTime = 1233061996; // Block #2015
|
||||||
// pindexLast.nBits = 0x1d00ffff;
|
// pindexLast.nBits = 0x1d00ffff;
|
||||||
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00ffff);
|
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00ffff);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* Test the constraint on the lower bound for actual time taken */
|
/* Test the constraint on the lower bound for actual time taken */
|
||||||
// BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
// BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
||||||
// {
|
// {
|
||||||
// SelectParams(CBaseChainParams::MAIN);
|
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
// const Consensus::Params& params = Params().GetConsensus();
|
|
||||||
|
|
||||||
// int64_t nLastRetargetTime = 1279008237; // Block #66528
|
// int64_t nLastRetargetTime = 1279008237; // Block #66528
|
||||||
// CBlockIndex pindexLast;
|
// CBlockIndex pindexLast;
|
||||||
// pindexLast.nHeight = 68543;
|
// pindexLast.nHeight = 68543;
|
||||||
// pindexLast.nTime = 1279297671; // Block #68543
|
// pindexLast.nTime = 1279297671; // Block #68543
|
||||||
// pindexLast.nBits = 0x1c05a3f4;
|
// pindexLast.nBits = 0x1c05a3f4;
|
||||||
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fd);
|
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1c0168fd);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* Test the constraint on the upper bound for actual time taken */
|
/* Test the constraint on the upper bound for actual time taken */
|
||||||
// BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
// BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
||||||
// {
|
// {
|
||||||
// SelectParams(CBaseChainParams::MAIN);
|
// const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
// const Consensus::Params& params = Params().GetConsensus();
|
|
||||||
|
|
||||||
// int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
// int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
||||||
// CBlockIndex pindexLast;
|
// CBlockIndex pindexLast;
|
||||||
// pindexLast.nHeight = 46367;
|
// pindexLast.nHeight = 46367;
|
||||||
// pindexLast.nTime = 1269211443; // Block #46367
|
// pindexLast.nTime = 1269211443; // Block #46367
|
||||||
// pindexLast.nBits = 0x1c387f6f;
|
// pindexLast.nBits = 0x1c387f6f;
|
||||||
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00e1fd);
|
// BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00e1fd);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||||
{
|
{
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
|
||||||
|
|
||||||
std::vector<CBlockIndex> blocks(10000);
|
std::vector<CBlockIndex> blocks(10000);
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
blocks[i].pprev = i ? &blocks[i - 1] : NULL;
|
blocks[i].pprev = i ? &blocks[i - 1] : NULL;
|
||||||
blocks[i].nHeight = i;
|
blocks[i].nHeight = i;
|
||||||
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
|
blocks[i].nTime = 1269211443 + i * chainParams->GetConsensus().nPowTargetSpacing;
|
||||||
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
|
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
|
||||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||||
}
|
}
|
||||||
@ -203,7 +196,7 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
|||||||
CBlockIndex *p2 = &blocks[GetRand(10000)];
|
CBlockIndex *p2 = &blocks[GetRand(10000)];
|
||||||
CBlockIndex *p3 = &blocks[GetRand(10000)];
|
CBlockIndex *p3 = &blocks[GetRand(10000)];
|
||||||
|
|
||||||
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params);
|
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, chainParams->GetConsensus());
|
||||||
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());
|
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ BOOST_FIXTURE_TEST_SUITE(subsidy_tests, TestingSetup)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
||||||
{
|
{
|
||||||
const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||||
|
|
||||||
uint32_t nPrevBits;
|
uint32_t nPrevBits;
|
||||||
int32_t nPrevHeight;
|
int32_t nPrevHeight;
|
||||||
@ -22,43 +22,43 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
|||||||
// details for block 4249 (subsidy returned will be for block 4250)
|
// details for block 4249 (subsidy returned will be for block 4250)
|
||||||
nPrevBits = 0x1c4a47c4;
|
nPrevBits = 0x1c4a47c4;
|
||||||
nPrevHeight = 4249;
|
nPrevHeight = 4249;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 50000000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 50000000000ULL);
|
||||||
|
|
||||||
// details for block 4501 (subsidy returned will be for block 4502)
|
// details for block 4501 (subsidy returned will be for block 4502)
|
||||||
nPrevBits = 0x1c4a47c4;
|
nPrevBits = 0x1c4a47c4;
|
||||||
nPrevHeight = 4501;
|
nPrevHeight = 4501;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 5600000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 5600000000ULL);
|
||||||
|
|
||||||
// details for block 5464 (subsidy returned will be for block 5465)
|
// details for block 5464 (subsidy returned will be for block 5465)
|
||||||
nPrevBits = 0x1c29ec00;
|
nPrevBits = 0x1c29ec00;
|
||||||
nPrevHeight = 5464;
|
nPrevHeight = 5464;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 2100000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 2100000000ULL);
|
||||||
|
|
||||||
// details for block 5465 (subsidy returned will be for block 5466)
|
// details for block 5465 (subsidy returned will be for block 5466)
|
||||||
nPrevBits = 0x1c29ec00;
|
nPrevBits = 0x1c29ec00;
|
||||||
nPrevHeight = 5465;
|
nPrevHeight = 5465;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 12200000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 12200000000ULL);
|
||||||
|
|
||||||
// details for block 17588 (subsidy returned will be for block 17589)
|
// details for block 17588 (subsidy returned will be for block 17589)
|
||||||
nPrevBits = 0x1c08ba34;
|
nPrevBits = 0x1c08ba34;
|
||||||
nPrevHeight = 17588;
|
nPrevHeight = 17588;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 6100000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 6100000000ULL);
|
||||||
|
|
||||||
// details for block 99999 (subsidy returned will be for block 100000)
|
// details for block 99999 (subsidy returned will be for block 100000)
|
||||||
nPrevBits = 0x1b10cf42;
|
nPrevBits = 0x1b10cf42;
|
||||||
nPrevHeight = 99999;
|
nPrevHeight = 99999;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
|
||||||
|
|
||||||
// details for block 210239 (subsidy returned will be for block 210240)
|
// details for block 210239 (subsidy returned will be for block 210240)
|
||||||
nPrevBits = 0x1b11548e;
|
nPrevBits = 0x1b11548e;
|
||||||
nPrevHeight = 210239;
|
nPrevHeight = 210239;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
|
||||||
|
|
||||||
// 1st subsidy reduction happens here
|
// 1st subsidy reduction happens here
|
||||||
@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test)
|
|||||||
// details for block 210240 (subsidy returned will be for block 210241)
|
// details for block 210240 (subsidy returned will be for block 210241)
|
||||||
nPrevBits = 0x1b10d50b;
|
nPrevBits = 0x1b10d50b;
|
||||||
nPrevHeight = 210240;
|
nPrevHeight = 210240;
|
||||||
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false);
|
nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, chainParams->GetConsensus(), false);
|
||||||
BOOST_CHECK_EQUAL(nSubsidy, 464285715ULL);
|
BOOST_CHECK_EQUAL(nSubsidy, 464285715ULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,8 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sanity checks of version bit deployments
|
// 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++) {
|
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||||
uint32_t bitmask = VersionBitsMask(mainnetParams, (Consensus::DeploymentPos)i);
|
uint32_t bitmask = VersionBitsMask(mainnetParams, (Consensus::DeploymentPos)i);
|
||||||
// Make sure that no deployment tries to set an invalid bit.
|
// 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
|
// Check that ComputeBlockVersion will set the appropriate bit correctly
|
||||||
// on mainnet.
|
// 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.
|
// Use the TESTDUMMY deployment for testing purposes.
|
||||||
int64_t bit = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit;
|
int64_t bit = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit;
|
||||||
|
Loading…
Reference in New Issue
Block a user