You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chainparams.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. // Copyright (c) 2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #include "chainparams.h"
  6. #include "consensus/merkle.h"
  7. #include "tinyformat.h"
  8. #include "util.h"
  9. #include "utilstrencodings.h"
  10. #include <assert.h>
  11. #include "chainparamsseeds.h"
  12. static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
  13. {
  14. CMutableTransaction txNew;
  15. txNew.nVersion = 1;
  16. txNew.vin.resize(1);
  17. txNew.vout.resize(1);
  18. txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
  19. txNew.vout[0].nValue = genesisReward;
  20. txNew.vout[0].scriptPubKey = genesisOutputScript;
  21. CBlock genesis;
  22. genesis.nTime = nTime;
  23. genesis.nBits = nBits;
  24. genesis.nNonce = nNonce;
  25. genesis.nVersion = nVersion;
  26. genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
  27. genesis.hashPrevBlock.SetNull();
  28. genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
  29. return genesis;
  30. }
  31. static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
  32. {
  33. const char* pszTimestamp = "January/20/2017 45th President of the United States of America Donald Trump";
  34. const CScript genesisOutputScript = CScript() << ParseHex("04ea1e6e7cace7b63b88949a3f43f0144b0032eaa9ee6c9627fc58bfb51163a262542fd8cdd3cc40186a1aeeb4857c15954e6f15f789bfdcf9cec59863cdfc6e14") << OP_CHECKSIG;
  35. return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
  36. }
  37. void CChainParams::UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
  38. {
  39. consensus.vDeployments[d].nStartTime = nStartTime;
  40. consensus.vDeployments[d].nTimeout = nTimeout;
  41. }
  42. /**
  43. * Main network
  44. */
  45. /**
  46. * What makes a good checkpoint block?
  47. * + Is surrounded by blocks with reasonable timestamps
  48. * (no blocks before with a timestamp after, none after with
  49. * timestamp before)
  50. * + Contains no strange transactions
  51. */
  52. class CMainParams : public CChainParams {
  53. public:
  54. CMainParams() {
  55. strNetworkID = "main";
  56. consensus.nSubsidyHalvingInterval = 210000;
  57. consensus.BIP34Height = 227931;
  58. consensus.BIP34Hash = uint256S("0x00");
  59. consensus.BIP65Height = 388381;
  60. consensus.BIP66Height = 363725;
  61. consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
  62. consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  63. consensus.nPowTargetSpacing = 10 * 60;
  64. consensus.fPowAllowMinDifficultyBlocks = false;
  65. consensus.fPowNoRetargeting = false;
  66. consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
  67. consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
  68. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
  69. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
  70. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
  71. // Deployment of BIP68, BIP112, and BIP113.
  72. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  73. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1462060800; // May 1st, 2016
  74. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
  75. // Deployment of SegWit (BIP141, BIP143, and BIP147)
  76. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  77. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1479168000; // November 15th, 2016.
  78. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1510704000; // November 15th, 2017.
  79. // The best chain should have at least this much work.
  80. consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000010c410c410c4");
  81. // By default assume that the signatures in ancestors of this block are valid.
  82. consensus.defaultAssumeValid = uint256S("0x0000000002a47ec40e87c18501786717cbebb96efa3bb05505e1c24cce51689e"); //4096
  83. /**
  84. * The message start string is designed to be unlikely to occur in normal data.
  85. * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
  86. * a large 32-bit integer with any alignment.
  87. */
  88. pchMessageStart[0] = 0xf9;
  89. pchMessageStart[1] = 0xbe;
  90. pchMessageStart[2] = 0xb4;
  91. pchMessageStart[3] = 0xd9;
  92. nDefaultPort = 8353;
  93. nPruneAfterHeight = 100000;
  94. genesis = CreateGenesisBlock(1484870400, 2121032621, 0x1d00ffff, 1, 50 * COIN);
  95. consensus.hashGenesisBlock = genesis.GetHash();
  96. assert(consensus.hashGenesisBlock == uint256S("0x000000003d69a915e9da53348c5c272978bb743442e3a6341c11061c125811a2"));
  97. assert(genesis.hashMerkleRoot == uint256S("0x7e2c59b1404833991962e7e6d95a1d4f81f03fffeaf79c0d25d97d24182db485"));
  98. // Note that of those with the service bits flag, most only support a subset of possible options
  99. base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
  100. base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
  101. base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
  102. base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
  103. base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
  104. vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
  105. fDefaultConsistencyChecks = false;
  106. fRequireStandard = true;
  107. fMineBlocksOnDemand = false;
  108. checkpointData = (CCheckpointData) {
  109. {
  110. {1024, uint256S("0x00000000fb559851169e0d915093533d31af0d963e06a7d80a20496f9cfd2b9f")},
  111. {2048, uint256S("0x00000000a753b360bb5d54908378d999132fbeb415279ef530b397ae249cbef4")},
  112. }
  113. };
  114. chainTxData = ChainTxData{
  115. // Data as of block 0000000002a47ec40e87c18501786717cbebb96efa3bb05505e1c24cce51689e (height 4096).
  116. 1517574356, // * UNIX timestamp of last known number of transactions
  117. 4172, // * total number of transactions between genesis and that timestamp
  118. // (the tx=... number in the SetBestChain debug.log lines)
  119. 3.1 // * estimated number of transactions per second after that timestamp
  120. };
  121. }
  122. };
  123. /**
  124. * Testnet (v3)
  125. */
  126. class CTestNetParams : public CChainParams {
  127. public:
  128. CTestNetParams() {
  129. strNetworkID = "test";
  130. consensus.nSubsidyHalvingInterval = 210000;
  131. consensus.BIP34Height = 21111;
  132. consensus.BIP34Hash = uint256S("0x00");
  133. consensus.BIP65Height = 581885;
  134. consensus.BIP66Height = 330776;
  135. consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
  136. consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  137. consensus.nPowTargetSpacing = 10 * 60;
  138. consensus.fPowAllowMinDifficultyBlocks = true;
  139. consensus.fPowNoRetargeting = false;
  140. consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
  141. consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
  142. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
  143. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
  144. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
  145. // Deployment of BIP68, BIP112, and BIP113.
  146. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  147. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1456790400; // March 1st, 2016
  148. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
  149. // Deployment of SegWit (BIP141, BIP143, and BIP147)
  150. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  151. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
  152. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
  153. // The best chain should have at least this much work.
  154. consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000020102010201");
  155. // By default assume that the signatures in ancestors of this block are valid.
  156. consensus.defaultAssumeValid = uint256S("0x00000000bf9f221b2acc9bd6ae001ccd5640615a5e4d9ed94bbb3564d3e372bd"); //512
  157. pchMessageStart[0] = 0x0b;
  158. pchMessageStart[1] = 0x11;
  159. pchMessageStart[2] = 0x09;
  160. pchMessageStart[3] = 0x07;
  161. nDefaultPort = 18353;
  162. nPruneAfterHeight = 1000;
  163. genesis = CreateGenesisBlock(1484956800, 2266491446, 0x1d00ffff, 1, 50 * COIN);
  164. consensus.hashGenesisBlock = genesis.GetHash();
  165. assert(consensus.hashGenesisBlock == uint256S("0x00000000c5a2df98ed0b29d576af8b99b3c6b65052614da34292aa4a109b3004"));
  166. assert(genesis.hashMerkleRoot == uint256S("0x7e2c59b1404833991962e7e6d95a1d4f81f03fffeaf79c0d25d97d24182db485"));
  167. vFixedSeeds.clear();
  168. vSeeds.clear();
  169. // nodes with support for servicebits filtering should be at the top
  170. base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
  171. base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
  172. base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
  173. base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
  174. base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
  175. vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
  176. fDefaultConsistencyChecks = false;
  177. fRequireStandard = false;
  178. fMineBlocksOnDemand = false;
  179. checkpointData = (CCheckpointData) {
  180. {
  181. {256, uint256S("00000000284f483ce4d56f4f1a026363d2d0daf2c18f77cd5e8969166ca16212")},
  182. }
  183. };
  184. chainTxData = ChainTxData{
  185. // Data as of block 00000000bf9f221b2acc9bd6ae001ccd5640615a5e4d9ed94bbb3564d3e372bd (height 512)
  186. 1518787878,
  187. 536,
  188. 0.15
  189. };
  190. }
  191. };
  192. /**
  193. * Regression test
  194. */
  195. class CRegTestParams : public CChainParams {
  196. public:
  197. CRegTestParams() {
  198. strNetworkID = "regtest";
  199. consensus.nSubsidyHalvingInterval = 150;
  200. consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
  201. consensus.BIP34Hash = uint256();
  202. consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
  203. consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
  204. consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
  205. consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  206. consensus.nPowTargetSpacing = 10 * 60;
  207. consensus.fPowAllowMinDifficultyBlocks = true;
  208. consensus.fPowNoRetargeting = true;
  209. consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
  210. consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
  211. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
  212. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
  213. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 999999999999ULL;
  214. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  215. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
  216. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 999999999999ULL;
  217. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  218. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 0;
  219. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 999999999999ULL;
  220. // The best chain should have at least this much work.
  221. consensus.nMinimumChainWork = uint256S("0x00");
  222. // By default assume that the signatures in ancestors of this block are valid.
  223. consensus.defaultAssumeValid = uint256S("0x00");
  224. pchMessageStart[0] = 0xfa;
  225. pchMessageStart[1] = 0xbf;
  226. pchMessageStart[2] = 0xb5;
  227. pchMessageStart[3] = 0xda;
  228. nDefaultPort = 18444;
  229. nPruneAfterHeight = 1000;
  230. genesis = CreateGenesisBlock(1484956800, 0, 0x207fffff, 1, 50 * COIN);
  231. consensus.hashGenesisBlock = genesis.GetHash();
  232. assert(consensus.hashGenesisBlock == uint256S("0x79a6a4d5e19d4e5c6783691ba9ad75c7c352f906275b93dcad27ea0c3017ec80"));
  233. assert(genesis.hashMerkleRoot == uint256S("0x7e2c59b1404833991962e7e6d95a1d4f81f03fffeaf79c0d25d97d24182db485"));
  234. vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
  235. vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
  236. fDefaultConsistencyChecks = true;
  237. fRequireStandard = false;
  238. fMineBlocksOnDemand = true;
  239. checkpointData = (CCheckpointData) {
  240. {
  241. {0, uint256S("79a6a4d5e19d4e5c6783691ba9ad75c7c352f906275b93dcad27ea0c3017ec80")},
  242. }
  243. };
  244. chainTxData = ChainTxData{
  245. 0,
  246. 0,
  247. 0
  248. };
  249. base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
  250. base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
  251. base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
  252. base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
  253. base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
  254. }
  255. };
  256. static std::unique_ptr<CChainParams> globalChainParams;
  257. const CChainParams &Params() {
  258. assert(globalChainParams);
  259. return *globalChainParams;
  260. }
  261. std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
  262. {
  263. if (chain == CBaseChainParams::MAIN)
  264. return std::unique_ptr<CChainParams>(new CMainParams());
  265. else if (chain == CBaseChainParams::TESTNET)
  266. return std::unique_ptr<CChainParams>(new CTestNetParams());
  267. else if (chain == CBaseChainParams::REGTEST)
  268. return std::unique_ptr<CChainParams>(new CRegTestParams());
  269. throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  270. }
  271. void SelectParams(const std::string& network)
  272. {
  273. SelectBaseParams(network);
  274. globalChainParams = CreateChainParams(network);
  275. }
  276. void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
  277. {
  278. globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout);
  279. }