231 lines
9.2 KiB
C++
231 lines
9.2 KiB
C++
// Copyright (c) 2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <arith_uint256.h>
|
|
#include <chainparamsseeds.h>
|
|
#include <consensus/merkle.h>
|
|
#include <tinyformat.h>
|
|
#include <util/system.h>
|
|
#include <util/strencodings.h>
|
|
#include <versionbitsinfo.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
|
{
|
|
CMutableTransaction txNew;
|
|
txNew.nVersion = 1;
|
|
txNew.vin.resize(1);
|
|
txNew.vout.resize(1);
|
|
txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
|
|
txNew.vout[0].nValue = genesisReward;
|
|
txNew.vout[0].scriptPubKey = genesisOutputScript;
|
|
|
|
CBlock genesis;
|
|
genesis.nTime = nTime;
|
|
genesis.nBits = nBits;
|
|
genesis.nNonce = nNonce;
|
|
genesis.nVersion = nVersion;
|
|
genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
|
|
genesis.hashPrevBlock.SetNull();
|
|
genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
|
|
return genesis;
|
|
}
|
|
|
|
/**
|
|
* Build the genesis block. Note that the output of its generation
|
|
* transaction cannot be spent since it did not originally exist in the
|
|
* database.
|
|
*
|
|
* CBlock(hash=17e7131a4eb39658cca55c136f59d2cf795db379f3cb4fa640b171ee4ae90e9a, ver=0x00000001,
|
|
* hashPrevBlock=0000000000000000000000000000000000000000000000000000000000000000,
|
|
* hashMerkleRoot=dfd0e8579d4f22ce8fb4a7c2e372469d027e2a4954b6a3ef302c698052bdae1f,
|
|
* nTime=1559078000, nBits=1f00ffff, nNonce=26552, vtx=1)
|
|
*/
|
|
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
|
{
|
|
const char* pszTimestamp = "nyc3 2019";
|
|
const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
|
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
|
}
|
|
|
|
/**
|
|
* Main network
|
|
*/
|
|
class CMainParams : public CChainParams {
|
|
public:
|
|
CMainParams() {
|
|
strNetworkID = "main";
|
|
consensus.powLimit = uint256S("0000fffff0000000000000000000000000000000000000000000000000000000");
|
|
consensus.nPowTargetTimespan = 10; // you read correctly..
|
|
consensus.nPowTargetSpacing = consensus.nPowTargetTimespan;
|
|
consensus.fPowAllowMinDifficultyBlocks = false;
|
|
consensus.fPowNoRetargeting = false;
|
|
consensus.nRuleChangeActivationThreshold = 1916;
|
|
consensus.nMinerConfirmationWindow = 2016;
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
|
|
|
|
// Deployment of BIP68, BIP112, and BIP113.
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1462060800; // May 1st, 2016
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
|
|
|
|
// Deployment of SegWit (BIP141, BIP143, and BIP147)
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
|
|
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
|
|
|
|
// The best chain should have at least this much work.
|
|
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
|
|
// By default assume that the signatures in ancestors of this block are valid.
|
|
consensus.defaultAssumeValid = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
|
|
/**
|
|
* The message start string is designed to be unlikely to occur in normal data.
|
|
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
|
|
* a large 32-bit integer with any alignment.
|
|
*/
|
|
pchMessageStart[0] = 0x1f;
|
|
pchMessageStart[1] = 0xbe;
|
|
pchMessageStart[2] = 0xef;
|
|
pchMessageStart[3] = 0xf1;
|
|
nDefaultPort = 55555;
|
|
nPruneAfterHeight = 100000;
|
|
m_assumed_blockchain_size = 240;
|
|
m_assumed_chain_state_size = 3;
|
|
|
|
genesis = CreateGenesisBlock(1559078000, 26552, 0x1f00ffff, 1, 0 * COIN);
|
|
consensus.hashGenesisBlock = genesis.GetHash();
|
|
assert(consensus.hashGenesisBlock == uint256S("0x17e7131a4eb39658cca55c136f59d2cf795db379f3cb4fa640b171ee4ae90e9a"));
|
|
assert(genesis.hashMerkleRoot == uint256S("0xdfd0e8579d4f22ce8fb4a7c2e372469d027e2a4954b6a3ef302c698052bdae1f"));
|
|
|
|
// vSeeds.emplace_back("");
|
|
|
|
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,53);
|
|
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
|
|
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,181);
|
|
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
|
|
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
|
|
|
|
bech32_hrp = "ny";
|
|
|
|
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
|
|
|
|
fDefaultConsistencyChecks = false;
|
|
fRequireStandard = true;
|
|
fMineBlocksOnDemand = false;
|
|
|
|
checkpointData = {
|
|
{
|
|
{ 0, consensus.hashGenesisBlock }
|
|
}
|
|
};
|
|
|
|
chainTxData = ChainTxData{
|
|
/* nTime */ 1559078000,
|
|
/* nTxCount */ 1,
|
|
/* dTxRate */ 1,
|
|
};
|
|
|
|
/* disable fallback fee on mainnet */
|
|
m_fallback_fee_enabled = true;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Testnet (v3)
|
|
*/
|
|
class CTestNetParams : public CChainParams {
|
|
public:
|
|
CTestNetParams() {
|
|
strNetworkID = "test";
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Regression test
|
|
*/
|
|
class CRegTestParams : public CChainParams {
|
|
public:
|
|
explicit CRegTestParams(const ArgsManager& args) {
|
|
strNetworkID = "regtest";
|
|
|
|
}
|
|
|
|
/**
|
|
* Allows modifying the Version Bits regtest parameters.
|
|
*/
|
|
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
|
|
{
|
|
consensus.vDeployments[d].nStartTime = nStartTime;
|
|
consensus.vDeployments[d].nTimeout = nTimeout;
|
|
}
|
|
void UpdateVersionBitsParametersFromArgs(const ArgsManager& args);
|
|
};
|
|
|
|
void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args)
|
|
{
|
|
if (!args.IsArgSet("-vbparams")) return;
|
|
|
|
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
|
|
std::vector<std::string> vDeploymentParams;
|
|
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
|
|
if (vDeploymentParams.size() != 3) {
|
|
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end");
|
|
}
|
|
int64_t nStartTime, nTimeout;
|
|
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
|
|
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
|
|
}
|
|
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
|
|
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
|
|
}
|
|
bool found = false;
|
|
for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
|
|
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
|
|
UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
|
|
found = true;
|
|
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
|
|
}
|
|
}
|
|
}
|
|
|
|
static std::unique_ptr<const CChainParams> globalChainParams;
|
|
|
|
const CChainParams &Params() {
|
|
assert(globalChainParams);
|
|
return *globalChainParams;
|
|
}
|
|
|
|
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
|
|
{
|
|
if (chain == CBaseChainParams::MAIN)
|
|
return std::unique_ptr<CChainParams>(new CMainParams());
|
|
else if (chain == CBaseChainParams::TESTNET)
|
|
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
|
else if (chain == CBaseChainParams::REGTEST)
|
|
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
|
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
|
}
|
|
|
|
void SelectParams(const std::string& network)
|
|
{
|
|
SelectBaseParams(network);
|
|
globalChainParams = CreateChainParams(network);
|
|
}
|