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

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