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

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