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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 = 1493596800; // May 1 Monday, 2017
  70. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1525132800; // May 1 Tuesday, 2018
  71. // Deployment of BIP68, BIP112, and BIP113.
  72. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  73. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1496275200; // June 1 Thursday, 2017
  74. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1527811200; // June 1 Friday, 2018
  75. // Deployment of SegWit (BIP141, BIP143, and BIP147)
  76. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  77. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1498867200; // July 1 Saturday, 2017
  78. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1530403200; // July 1 Sunday, 2018
  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. {4096, uint256S("0x0000000002a47ec40e87c18501786717cbebb96efa3bb05505e1c24cce51689e")},
  113. {8192, uint256S("0x00000000041f1f4c7d09c2ce6d656293b0217093a005f19799d3042b83267418")},
  114. {16384, uint256S("0x00000000000d596ae3c31ca582245d29435d98720d55283a7f3d6bb92a1afc98")},
  115. }
  116. };
  117. chainTxData = ChainTxData{
  118. // Data as of block 000000000000059d570e7eb57c53c49a9106580305510c091f6df8c07695a092 (height 32768).
  119. 1523273405, // * UNIX timestamp of last known number of transactions
  120. 33144, // * total number of transactions between genesis and that timestamp
  121. // (the tx=... number in the SetBestChain debug.log lines)
  122. 3.1 // * estimated number of transactions per second after that timestamp
  123. };
  124. }
  125. };
  126. /**
  127. * Starwels Ai Main Network
  128. */
  129. class CTestNetParams : public CChainParams {
  130. public:
  131. CTestNetParams() {
  132. strNetworkID = "main";
  133. consensus.nSubsidyHalvingInterval = 210000;
  134. consensus.BIP34Height = 227931;
  135. consensus.BIP34Hash = uint256S("0x00");
  136. consensus.BIP65Height = 388381;
  137. consensus.BIP66Height = 363725;
  138. consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
  139. consensus.nPowTargetTimespan = 2 * 24 * 84;
  140. consensus.nPowTargetSpacing = 2; // 2 second
  141. consensus.fPowAllowMinDifficultyBlocks = false;
  142. consensus.fPowNoRetargeting = false;
  143. consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
  144. consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
  145. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
  146. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1498867200; // July 1 Saturday, 2017
  147. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1530403200; // July 1 Sunday, 2018
  148. // Deployment of BIP68, BIP112, and BIP113.
  149. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  150. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1501545600; // August 1 Tuesday, 2017
  151. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1533081600; // August 1 Wednesday, 2018
  152. // Deployment of SegWit (BIP141, BIP143, and BIP147)
  153. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  154. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1504224000; // September 1 Friday, 2017
  155. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1535760000; // September 1 Saturday, 2018
  156. // The best chain should have at least this much work.
  157. consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000100110011001");
  158. // By default assume that the signatures in ancestors of this block are valid.
  159. consensus.defaultAssumeValid = uint256S("0x00000000d7674ad1e7703e7ba02b7611c12fe74de27b6a414cf6e906cc3599e9"); // 4096
  160. pchMessageStart[0] = 0xf9;
  161. pchMessageStart[1] = 0xbe;
  162. pchMessageStart[2] = 0xb4;
  163. pchMessageStart[3] = 0xd9;
  164. nDefaultPort = 8343;
  165. nPruneAfterHeight = 100000;
  166. genesis = CreateGenesisBlock(1484870400, 2121032621, 0x1d00ffff, 1, 50 * COIN);
  167. consensus.hashGenesisBlock = genesis.GetHash();
  168. assert(consensus.hashGenesisBlock == uint256S("0x000000003d69a915e9da53348c5c272978bb743442e3a6341c11061c125811a2"));
  169. assert(genesis.hashMerkleRoot == uint256S("0x7e2c59b1404833991962e7e6d95a1d4f81f03fffeaf79c0d25d97d24182db485"));
  170. vFixedSeeds.clear();
  171. vSeeds.clear();
  172. // nodes with support for servicebits filtering should be at the top
  173. base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
  174. base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
  175. base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
  176. base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
  177. base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
  178. vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
  179. fDefaultConsistencyChecks = false;
  180. fRequireStandard = true;
  181. fMineBlocksOnDemand = false;
  182. checkpointData = (CCheckpointData) {
  183. {
  184. {1024, uint256S("0x00000000fb559851169e0d915093533d31af0d963e06a7d80a20496f9cfd2b9f")},
  185. {2048, uint256S("0x00000000a753b360bb5d54908378d999132fbeb415279ef530b397ae249cbef4")},
  186. }
  187. };
  188. chainTxData = ChainTxData{
  189. // Data as of block 00000000d7674ad1e7703e7ba02b7611c12fe74de27b6a414cf6e906cc3599e9 (height 4096).
  190. 1529914513, // * UNIX timestamp of last known number of transactions
  191. 4172, // * total number of transactions between genesis and that timestamp
  192. // (the tx=... number in the SetBestChain debug.log lines)
  193. 3.1 // * estimated number of transactions per second after that timestamp
  194. };
  195. }
  196. };
  197. /**
  198. * Regression test
  199. */
  200. class CRegTestParams : public CChainParams {
  201. public:
  202. CRegTestParams() {
  203. strNetworkID = "regtest";
  204. consensus.nSubsidyHalvingInterval = 150;
  205. consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
  206. consensus.BIP34Hash = uint256();
  207. consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
  208. consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
  209. consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
  210. consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
  211. consensus.nPowTargetSpacing = 10 * 60;
  212. consensus.fPowAllowMinDifficultyBlocks = true;
  213. consensus.fPowNoRetargeting = true;
  214. consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
  215. consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
  216. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
  217. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
  218. consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 999999999999ULL;
  219. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
  220. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
  221. consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 999999999999ULL;
  222. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
  223. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 0;
  224. consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 999999999999ULL;
  225. // The best chain should have at least this much work.
  226. consensus.nMinimumChainWork = uint256S("0x00");
  227. // By default assume that the signatures in ancestors of this block are valid.
  228. consensus.defaultAssumeValid = uint256S("0x00");
  229. pchMessageStart[0] = 0xfa;
  230. pchMessageStart[1] = 0xbf;
  231. pchMessageStart[2] = 0xb5;
  232. pchMessageStart[3] = 0xda;
  233. nDefaultPort = 18444;
  234. nPruneAfterHeight = 1000;
  235. genesis = CreateGenesisBlock(1484956800, 0, 0x207fffff, 1, 50 * COIN);
  236. consensus.hashGenesisBlock = genesis.GetHash();
  237. assert(consensus.hashGenesisBlock == uint256S("0x79a6a4d5e19d4e5c6783691ba9ad75c7c352f906275b93dcad27ea0c3017ec80"));
  238. assert(genesis.hashMerkleRoot == uint256S("0x7e2c59b1404833991962e7e6d95a1d4f81f03fffeaf79c0d25d97d24182db485"));
  239. vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
  240. vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
  241. fDefaultConsistencyChecks = true;
  242. fRequireStandard = false;
  243. fMineBlocksOnDemand = true;
  244. checkpointData = (CCheckpointData) {
  245. {
  246. {0, uint256S("79a6a4d5e19d4e5c6783691ba9ad75c7c352f906275b93dcad27ea0c3017ec80")},
  247. }
  248. };
  249. chainTxData = ChainTxData{
  250. 0,
  251. 0,
  252. 0
  253. };
  254. base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
  255. base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
  256. base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
  257. base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
  258. base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
  259. }
  260. };
  261. static std::unique_ptr<CChainParams> globalChainParams;
  262. const CChainParams &Params() {
  263. assert(globalChainParams);
  264. return *globalChainParams;
  265. }
  266. std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
  267. {
  268. if (chain == CBaseChainParams::MAIN)
  269. return std::unique_ptr<CChainParams>(new CMainParams());
  270. else if (chain == CBaseChainParams::AI)
  271. return std::unique_ptr<CChainParams>(new CTestNetParams());
  272. else if (chain == CBaseChainParams::REGTEST)
  273. return std::unique_ptr<CChainParams>(new CRegTestParams());
  274. throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  275. }
  276. void SelectParams(const std::string& network)
  277. {
  278. SelectBaseParams(network);
  279. globalChainParams = CreateChainParams(network);
  280. }
  281. void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
  282. {
  283. globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout);
  284. }