]>
Commit | Line | Data |
---|---|---|
0e4b3175 | 1 | // Copyright (c) 2010 Satoshi Nakamoto |
57702541 | 2 | // Copyright (c) 2009-2014 The Bitcoin developers |
f2e03ffa | 3 | // Distributed under the MIT software license, see the accompanying |
0e4b3175 MH |
4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | ||
0e4b3175 | 6 | #include "chainparams.h" |
51ed9ec9 | 7 | |
6354935c | 8 | #include "random.h" |
0e4b3175 | 9 | #include "util.h" |
85c579e3 | 10 | #include "utilstrencodings.h" |
0e4b3175 | 11 | |
187115c0 PK |
12 | #include <assert.h> |
13 | ||
8388289e PW |
14 | #include <boost/assign/list_of.hpp> |
15 | ||
09eb201b | 16 | using namespace std; |
8388289e PW |
17 | using namespace boost::assign; |
18 | ||
a60120e9 WL |
19 | struct SeedSpec6 { |
20 | uint8_t addr[16]; | |
21 | uint16_t port; | |
22 | }; | |
23 | ||
24 | #include "chainparamsseeds.h" | |
25 | ||
f2e03ffa MF |
26 | /** |
27 | * Main network | |
28 | */ | |
0e4b3175 | 29 | |
f2e03ffa | 30 | //! Convert the pnSeeds6 array into usable address objects. |
a60120e9 | 31 | static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count) |
0e4b3175 | 32 | { |
a60120e9 WL |
33 | // It'll only connect to one or two seed nodes because once it connects, |
34 | // it'll get a pile of addresses with newer timestamps. | |
35 | // Seed nodes are given a random 'last seen time' of between one and two | |
36 | // weeks ago. | |
37 | const int64_t nOneWeek = 7*24*60*60; | |
38 | for (unsigned int i = 0; i < count; i++) | |
39 | { | |
40 | struct in6_addr ip; | |
41 | memcpy(&ip, data[i].addr, sizeof(ip)); | |
42 | CAddress addr(CService(ip, data[i].port)); | |
43 | addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek; | |
44 | vSeedsOut.push_back(addr); | |
45 | } | |
46 | } | |
0e4b3175 | 47 | |
f2e03ffa MF |
48 | /** |
49 | * What makes a good checkpoint block? | |
50 | * + Is surrounded by blocks with reasonable timestamps | |
51 | * (no blocks before with a timestamp after, none after with | |
52 | * timestamp before) | |
53 | * + Contains no strange transactions | |
54 | */ | |
e11712df | 55 | static Checkpoints::MapCheckpoints mapCheckpoints = |
56 | boost::assign::map_list_of | |
57 | ( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) | |
58 | ( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) | |
59 | ( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) | |
60 | (105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) | |
61 | (134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")) | |
62 | (168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")) | |
63 | (193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")) | |
64 | (210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")) | |
65 | (216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")) | |
66 | (225430, uint256("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")) | |
67 | (250000, uint256("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")) | |
68 | (279000, uint256("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")) | |
69 | (295000, uint256("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")) | |
70 | ; | |
71 | static const Checkpoints::CCheckpointData data = { | |
72 | &mapCheckpoints, | |
73 | 1397080064, // * UNIX timestamp of last checkpoint block | |
74 | 36544669, // * total number of transactions between genesis and last checkpoint | |
75 | // (the tx=... number in the SetBestChain debug.log lines) | |
76 | 60000.0 // * estimated number of transactions per day after checkpoint | |
77 | }; | |
78 | ||
79 | static Checkpoints::MapCheckpoints mapCheckpointsTestnet = | |
80 | boost::assign::map_list_of | |
81 | ( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")) | |
82 | ; | |
83 | static const Checkpoints::CCheckpointData dataTestnet = { | |
84 | &mapCheckpointsTestnet, | |
85 | 1337966069, | |
86 | 1488, | |
87 | 300 | |
88 | }; | |
89 | ||
90 | static Checkpoints::MapCheckpoints mapCheckpointsRegtest = | |
91 | boost::assign::map_list_of | |
92 | ( 0, uint256("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")) | |
93 | ; | |
94 | static const Checkpoints::CCheckpointData dataRegtest = { | |
95 | &mapCheckpointsRegtest, | |
96 | 0, | |
97 | 0, | |
98 | 0 | |
99 | }; | |
100 | ||
0e4b3175 MH |
101 | class CMainParams : public CChainParams { |
102 | public: | |
103 | CMainParams() { | |
84ce18ca | 104 | networkID = CBaseChainParams::MAIN; |
f5ae6c98 | 105 | strNetworkID = "main"; |
f2e03ffa MF |
106 | /** |
107 | * The message start string is designed to be unlikely to occur in normal data. | |
108 | * The characters are rarely used upper ASCII, not valid as UTF-8, and produce | |
109 | * a large 4-byte int at any alignment. | |
110 | */ | |
0e4b3175 MH |
111 | pchMessageStart[0] = 0xf9; |
112 | pchMessageStart[1] = 0xbe; | |
113 | pchMessageStart[2] = 0xb4; | |
114 | pchMessageStart[3] = 0xd9; | |
115 | vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"); | |
116 | nDefaultPort = 8333; | |
df9eb5e1 | 117 | bnProofOfWorkLimit = ~uint256(0) >> 32; |
0e4b3175 | 118 | nSubsidyHalvingInterval = 210000; |
d754f34e | 119 | nEnforceBlockUpgradeMajority = 750; |
120 | nRejectBlockOutdatedMajority = 950; | |
121 | nToCheckBlockUpgradeMajority = 1000; | |
2595b9ac | 122 | nMinerThreads = 0; |
fd704c7b | 123 | nTargetTimespan = 14 * 24 * 60 * 60; // two weeks |
124 | nTargetSpacing = 10 * 60; | |
0e4b3175 | 125 | |
f2e03ffa MF |
126 | /** |
127 | * Build the genesis block. Note that the output of the genesis coinbase cannot | |
128 | * be spent as it did not originally exist in the database. | |
129 | * | |
130 | * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1) | |
131 | * CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0) | |
132 | * CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73) | |
133 | * CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B) | |
134 | * vMerkleTree: 4a5e1e | |
135 | */ | |
0e4b3175 | 136 | const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"; |
4949004d | 137 | CMutableTransaction txNew; |
0e4b3175 MH |
138 | txNew.vin.resize(1); |
139 | txNew.vout.resize(1); | |
4f497cd9 | 140 | txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); |
0e4b3175 MH |
141 | txNew.vout[0].nValue = 50 * COIN; |
142 | txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; | |
143 | genesis.vtx.push_back(txNew); | |
144 | genesis.hashPrevBlock = 0; | |
145 | genesis.hashMerkleRoot = genesis.BuildMerkleTree(); | |
146 | genesis.nVersion = 1; | |
147 | genesis.nTime = 1231006505; | |
148 | genesis.nBits = 0x1d00ffff; | |
149 | genesis.nNonce = 2083236893; | |
150 | ||
151 | hashGenesisBlock = genesis.GetHash(); | |
152 | assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")); | |
153 | assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")); | |
154 | ||
155 | vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be")); | |
156 | vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me")); | |
157 | vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org")); | |
cdc11b32 | 158 | vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com")); |
89d72f3d | 159 | vSeeds.push_back(CDNSSeedData("bitnodes.io", "seed.bitnodes.io")); |
0e4b3175 MH |
160 | vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org")); |
161 | ||
8388289e PW |
162 | base58Prefixes[PUBKEY_ADDRESS] = list_of(0); |
163 | base58Prefixes[SCRIPT_ADDRESS] = list_of(5); | |
164 | base58Prefixes[SECRET_KEY] = list_of(128); | |
eb2c9990 PW |
165 | base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E); |
166 | base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4); | |
0e4b3175 | 167 | |
a60120e9 | 168 | convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main)); |
0e4b3175 | 169 | |
c8c52de3 | 170 | fRequireRPCPassword = true; |
171 | fMiningRequiresPeers = true; | |
172 | fDefaultCheckMemPool = false; | |
173 | fAllowMinDifficultyBlocks = false; | |
174 | fRequireStandard = true; | |
c8c52de3 | 175 | fMineBlocksOnDemand = false; |
fbd36d8f | 176 | fSkipProofOfWorkCheck = false; |
cc972107 | 177 | fTestnetToBeDeprecatedFieldRPC = false; |
0e4b3175 | 178 | } |
e11712df | 179 | |
180 | const Checkpoints::CCheckpointData& Checkpoints() const | |
181 | { | |
182 | return data; | |
183 | } | |
0e4b3175 MH |
184 | }; |
185 | static CMainParams mainParams; | |
186 | ||
f2e03ffa MF |
187 | /** |
188 | * Testnet (v3) | |
189 | */ | |
0e4b3175 MH |
190 | class CTestNetParams : public CMainParams { |
191 | public: | |
192 | CTestNetParams() { | |
84ce18ca | 193 | networkID = CBaseChainParams::TESTNET; |
f5ae6c98 | 194 | strNetworkID = "test"; |
0e4b3175 MH |
195 | pchMessageStart[0] = 0x0b; |
196 | pchMessageStart[1] = 0x11; | |
197 | pchMessageStart[2] = 0x09; | |
198 | pchMessageStart[3] = 0x07; | |
199 | vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"); | |
200 | nDefaultPort = 18333; | |
d754f34e | 201 | nEnforceBlockUpgradeMajority = 51; |
202 | nRejectBlockOutdatedMajority = 75; | |
203 | nToCheckBlockUpgradeMajority = 100; | |
fd704c7b | 204 | nMinerThreads = 0; |
f2e03ffa | 205 | nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks |
fd704c7b | 206 | nTargetSpacing = 10 * 60; |
0e4b3175 | 207 | |
f2e03ffa | 208 | //! Modify the testnet genesis block so the timestamp is valid for a later start. |
0e4b3175 MH |
209 | genesis.nTime = 1296688602; |
210 | genesis.nNonce = 414098458; | |
211 | hashGenesisBlock = genesis.GetHash(); | |
2b6a8993 | 212 | assert(hashGenesisBlock == uint256("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); |
0e4b3175 MH |
213 | |
214 | vFixedSeeds.clear(); | |
215 | vSeeds.clear(); | |
c30329ad | 216 | vSeeds.push_back(CDNSSeedData("alexykot.me", "testnet-seed.alexykot.me")); |
0e4b3175 MH |
217 | vSeeds.push_back(CDNSSeedData("bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org")); |
218 | vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me")); | |
45a4baf1 | 219 | vSeeds.push_back(CDNSSeedData("bitcoin.schildbach.de", "testnet-seed.bitcoin.schildbach.de")); |
0e4b3175 | 220 | |
8388289e PW |
221 | base58Prefixes[PUBKEY_ADDRESS] = list_of(111); |
222 | base58Prefixes[SCRIPT_ADDRESS] = list_of(196); | |
223 | base58Prefixes[SECRET_KEY] = list_of(239); | |
eb2c9990 PW |
224 | base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF); |
225 | base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94); | |
21913a9a | 226 | |
a60120e9 WL |
227 | convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test)); |
228 | ||
c8c52de3 | 229 | fRequireRPCPassword = true; |
230 | fMiningRequiresPeers = true; | |
231 | fDefaultCheckMemPool = false; | |
232 | fAllowMinDifficultyBlocks = true; | |
233 | fRequireStandard = false; | |
c8c52de3 | 234 | fMineBlocksOnDemand = false; |
cc972107 | 235 | fTestnetToBeDeprecatedFieldRPC = true; |
c8c52de3 | 236 | } |
e11712df | 237 | const Checkpoints::CCheckpointData& Checkpoints() const |
238 | { | |
239 | return dataTestnet; | |
240 | } | |
0e4b3175 MH |
241 | }; |
242 | static CTestNetParams testNetParams; | |
243 | ||
f2e03ffa MF |
244 | /** |
245 | * Regression test | |
246 | */ | |
0e4b3175 MH |
247 | class CRegTestParams : public CTestNetParams { |
248 | public: | |
249 | CRegTestParams() { | |
84ce18ca | 250 | networkID = CBaseChainParams::REGTEST; |
f5ae6c98 | 251 | strNetworkID = "regtest"; |
0e4b3175 MH |
252 | pchMessageStart[0] = 0xfa; |
253 | pchMessageStart[1] = 0xbf; | |
254 | pchMessageStart[2] = 0xb5; | |
255 | pchMessageStart[3] = 0xda; | |
256 | nSubsidyHalvingInterval = 150; | |
d754f34e | 257 | nEnforceBlockUpgradeMajority = 750; |
258 | nRejectBlockOutdatedMajority = 950; | |
259 | nToCheckBlockUpgradeMajority = 1000; | |
2595b9ac | 260 | nMinerThreads = 1; |
f2e03ffa | 261 | nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks |
fd704c7b | 262 | nTargetSpacing = 10 * 60; |
df9eb5e1 | 263 | bnProofOfWorkLimit = ~uint256(0) >> 1; |
0e4b3175 MH |
264 | genesis.nTime = 1296688602; |
265 | genesis.nBits = 0x207fffff; | |
266 | genesis.nNonce = 2; | |
267 | hashGenesisBlock = genesis.GetHash(); | |
268 | nDefaultPort = 18444; | |
0e4b3175 MH |
269 | assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); |
270 | ||
f2e03ffa MF |
271 | vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds. |
272 | vSeeds.clear(); //! Regtest mode doesn't have any DNS seeds. | |
0e4b3175 | 273 | |
c8c52de3 | 274 | fRequireRPCPassword = false; |
275 | fMiningRequiresPeers = false; | |
276 | fDefaultCheckMemPool = true; | |
277 | fAllowMinDifficultyBlocks = true; | |
278 | fRequireStandard = false; | |
c8c52de3 | 279 | fMineBlocksOnDemand = true; |
cc972107 | 280 | fTestnetToBeDeprecatedFieldRPC = false; |
c8c52de3 | 281 | } |
e11712df | 282 | const Checkpoints::CCheckpointData& Checkpoints() const |
283 | { | |
284 | return dataRegtest; | |
285 | } | |
0e4b3175 MH |
286 | }; |
287 | static CRegTestParams regTestParams; | |
288 | ||
f2e03ffa MF |
289 | /** |
290 | * Unit test | |
291 | */ | |
f0fd00cb S |
292 | class CUnitTestParams : public CMainParams, public CModifiableParams { |
293 | public: | |
294 | CUnitTestParams() { | |
295 | networkID = CBaseChainParams::UNITTEST; | |
296 | strNetworkID = "unittest"; | |
297 | nDefaultPort = 18445; | |
f2e03ffa MF |
298 | vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds. |
299 | vSeeds.clear(); //! Unit test mode doesn't have any DNS seeds. | |
f0fd00cb S |
300 | |
301 | fRequireRPCPassword = false; | |
302 | fMiningRequiresPeers = false; | |
303 | fDefaultCheckMemPool = true; | |
304 | fAllowMinDifficultyBlocks = false; | |
305 | fMineBlocksOnDemand = true; | |
f0fd00cb | 306 | } |
e11712df | 307 | |
308 | const Checkpoints::CCheckpointData& Checkpoints() const | |
309 | { | |
310 | // UnitTest share the same checkpoints as MAIN | |
311 | return data; | |
312 | } | |
313 | ||
f2e03ffa | 314 | //! Published setters to allow changing values in unit test cases |
f0fd00cb S |
315 | virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval=anSubsidyHalvingInterval; } |
316 | virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) { nEnforceBlockUpgradeMajority=anEnforceBlockUpgradeMajority; } | |
317 | virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) { nRejectBlockOutdatedMajority=anRejectBlockOutdatedMajority; } | |
318 | virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) { nToCheckBlockUpgradeMajority=anToCheckBlockUpgradeMajority; } | |
319 | virtual void setDefaultCheckMemPool(bool afDefaultCheckMemPool) { fDefaultCheckMemPool=afDefaultCheckMemPool; } | |
320 | virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) { fAllowMinDifficultyBlocks=afAllowMinDifficultyBlocks; } | |
321 | virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; } | |
322 | }; | |
323 | static CUnitTestParams unitTestParams; | |
324 | ||
325 | ||
84ce18ca | 326 | static CChainParams *pCurrentParams = 0; |
0e4b3175 | 327 | |
f0fd00cb S |
328 | CModifiableParams *ModifiableParams() |
329 | { | |
330 | assert(pCurrentParams); | |
331 | assert(pCurrentParams==&unitTestParams); | |
332 | return (CModifiableParams*)&unitTestParams; | |
333 | } | |
334 | ||
0e4b3175 | 335 | const CChainParams &Params() { |
84ce18ca | 336 | assert(pCurrentParams); |
0e4b3175 MH |
337 | return *pCurrentParams; |
338 | } | |
339 | ||
e84843c0 | 340 | CChainParams &Params(CBaseChainParams::Network network) { |
0e4b3175 | 341 | switch (network) { |
84ce18ca | 342 | case CBaseChainParams::MAIN: |
e84843c0 | 343 | return mainParams; |
84ce18ca | 344 | case CBaseChainParams::TESTNET: |
e84843c0 | 345 | return testNetParams; |
84ce18ca | 346 | case CBaseChainParams::REGTEST: |
e84843c0 | 347 | return regTestParams; |
f0fd00cb S |
348 | case CBaseChainParams::UNITTEST: |
349 | return unitTestParams; | |
0e4b3175 MH |
350 | default: |
351 | assert(false && "Unimplemented network"); | |
e84843c0 | 352 | return mainParams; |
0e4b3175 MH |
353 | } |
354 | } | |
355 | ||
e84843c0 RN |
356 | void SelectParams(CBaseChainParams::Network network) { |
357 | SelectBaseParams(network); | |
358 | pCurrentParams = &Params(network); | |
359 | } | |
360 | ||
ca3ce0fa | 361 | bool SelectParamsFromCommandLine() |
3fdb9e8c | 362 | { |
b796cb08 | 363 | CBaseChainParams::Network network = NetworkIdFromCommandLine(); |
3fdb9e8c | 364 | if (network == CBaseChainParams::MAX_NETWORK_TYPES) |
0e4b3175 | 365 | return false; |
0e4b3175 | 366 | |
3fdb9e8c | 367 | SelectParams(network); |
0e4b3175 MH |
368 | return true; |
369 | } |