UNPKG

mxbit

Version:
947 lines (747 loc) 17.9 kB
/*! * network.js - bitcoin networks for bcoin * Copyright (c) 2014-2015, Fedor Indutny (MIT License) * Copyright (c) 2014-2017, Christopher Jeffrey (MIT License). * https://github.com/bcoin-org/bcoin */ 'use strict'; /** * @module protocol/networks */ const BN = require('bcrypto/lib/bn.js'); const network = exports; /* * Helpers */ function b(hash) { return Buffer.from(hash, 'hex'); } /** * Network type list. * @memberof module:protocol/networks * @const {String[]} * @default */ network.types = ['main', 'testnet', 'regtest', 'simnet']; /** * Mainnet * @static * @lends module:protocol/networks * @type {Object} */ const main = {}; /** * Symbolic network type. * @const {String} * @default */ main.type = 'main'; /** * Default DNS seeds. * @const {String[]} * @default */ main.seeds = ['66.42.49.229:7888']; /** * Packet magic number. * @const {Number} * @default */ main.magic = 0xf9beb4d9; /** * Default network port. * @const {Number} * @default */ main.port = 7888; /** * Checkpoint block list. * @const {Object} */ main.checkpointMap = {0: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000')}; /** * Last checkpoint height. * @const {Number} * @default */ main.lastCheckpoint = 0; /** * @const {Number} * @default */ main.halvingInterval = 210000; /** * Genesis block header. * @const {Object} */ main.genesis = { version: 1, hash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), prevBlock: b('0000000000000000000000000000000000000000000000000000000000000000'), merkleRoot: b('d5109ae6160cd7653bc2856dd9db5828b77c51951b2078423b3e6483e78f6a6d'), time: 1549908188, bits: 504365040, nonce: 1178027, height: 0 }; /** * The network's genesis block in a hex string. * @const {String} */ main.genesisBlock = '010000000000000000000000000000000000000000000000000000000000000000000000d51' + '09ae6160cd7653bc2856dd9db5828b77c51951b2078423b3e6483e78f6a6ddcb8615cf0ff0f1' + 'eabf911000101000000010000000000000000000000000000000000000000000000000000000' + '000000000ffffffff4704f0ff0f1e01043f31312f4665622f3230313920426974636f696e204' + '57965732024332e384b20416674657220486967682d566f6c756d652050726963652042726561' + '6b6f7574ffffffff0100f2052a010000004341045eb3a9e4920eba4373e3a4d442f1946a5b10b' + '12fdf41914e434cdcdfde0cf11210fc1f0c17048154fe943fa44b9b0f70eea6ce2b0e5a52847d' + '7681c7248cc3fbac00000000'; /** * POW-related constants. * @enum {Number} * @default */ main.pow = { /** * Default target. * @const {BN} */ limit: new BN( '00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), /** * Compact pow limit. * @const {Number} * @default 504365055 */ bits: 504365040, /** * Minimum chainwork for best chain. * @const {BN} */ chainwork: new BN( '0', 'hex' ), /** * Desired retarget period in seconds. * @const {Number} * @default */ targetTimespan: 24 * 60 * 60, /** * Average block time. * @const {Number} * @default */ targetSpacing: 1.5 * 60, targetTimespanDigishield: 1.5 * 60, /** * Retarget interval in blocks. * @const {Number} * @default */ retargetInterval: 2016, /** * Whether to reset target if a block * has not been mined recently. * @const {Boolean} * @default */ targetReset: false, /** * Do not allow retargetting. * @const {Boolean} * @default */ noRetargeting: false }; /** * Block constants. * @enum {Number} * @default */ main.block = { /** * Height at which bip34 was activated. * Used for avoiding bip30 checks. */ bip34height: 0, /** * Hash of the block that activated bip34. */ bip34hash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), /** * Height at which bip65 was activated. */ bip65height: 0, /** * Hash of the block that activated bip65. */ bip65hash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), /** * Height at which bip66 was activated. */ bip66height: 0, /** * Hash of the block that activated bip66. */ bip66hash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), /** * Height at which UAHF was activated. */ uahfHeight: 0, /** * Hash of the block that activated UAHF. */ uahfHash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), /** * Height at which DAA was activated. * November 13, 2017 hard fork */ daaHeight: 0, /** * Hash of the block that activated DAA */ daaHash: b('fb42c209902eee87b9992aacf46d10d70019992f561caf024d58805a1b010000'), /** * Magnetic anomaly activation time * Nov 15, 2018 hard fork */ magneticAnomalyActivationTime: 1549909000, /** * Great wall activation time * Wed, 15 May 2019 12:00:00 UTC hard fork */ greatWallActivationTime: 1549909000, /** * Safe height to start pruning. */ pruneAfterHeight: 1000, /** * Safe number of blocks to keep. */ keepBlocks: 288, /** * Age used for the time delta to * determine whether the chain is synced. */ maxTipAge: 24 * 60 * 60, /** * Height at which block processing is * slow enough that we can output * logs without spamming. */ slowHeight: 325000 }; /** * Map of historical blocks which create duplicate transactions hashes. * @see https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki * @const {Object} * @default */ main.bip30 = {}; /** * For versionbits. * @const {Number} * @default */ main.activationThreshold = 1916; // 95% of 2016 /** * Confirmation window for versionbits. * @const {Number} * @default */ main.minerWindow = 5760; // nPowTargetTimespan / nPowTargetSpacing /** * Deployments for versionbits. * @const {Object} * @default */ main.deployments = { csv: { name: 'csv', bit: 0, startTime: 1462060800, // May 1st, 2016 timeout: 1493596800, // May 1st, 2017 threshold: -1, window: -1, required: false, force: true }, testdummy: { name: 'testdummy', bit: 28, startTime: 1199145601, // January 1, 2008 timeout: 1230767999, // December 31, 2008 threshold: -1, window: -1, required: false, force: true } }; /** * Deployments for versionbits (array form, sorted). * @const {Array} * @default */ main.deploys = [ main.deployments.csv, main.deployments.testdummy ]; /** * Key prefixes. * @enum {Number} * @default */ main.keyPrefix = { privkey: 0x80, xpubkey: 0x0488b21e, xprivkey: 0x0488ade4, xpubkey58: 'xpub', xprivkey58: 'xprv', coinType: 0 }; /** * {@link Address} prefixes. * @enum {Number} */ main.addressPrefix = { pubkeyhash: 0x00, scripthash: 0x05, cashaddr: 'matrixbit' }; /** * Default value for whether the mempool * accepts non-standard transactions. * @const {Boolean} * @default */ main.requireStandard = true; /** * Default http port. * @const {Number} * @default */ main.rpcPort = 7887; /** * Default wallet port. * @const {Number} * @default */ main.walletPort = 7334; /** * Default min relay rate. * @const {Rate} * @default */ main.minRelay = 1000; /** * Default normal relay rate. * @const {Rate} * @default */ main.feeRate = 100000; /** * Maximum normal relay rate. * @const {Rate} * @default */ main.maxFeeRate = 400000; /** * Whether to allow self-connection. * @const {Boolean} */ main.selfConnect = false; /** * Whether to request mempool on sync. * @const {Boolean} */ main.requestMempool = false; /* * Testnet (v3) * https://en.bitcoin.it/wiki/Testnet */ const testnet = {}; testnet.type = 'testnet'; testnet.seeds = []; testnet.magic = 0x0b110907; testnet.port = 17888; testnet.checkpointMap = {}; testnet.lastCheckpoint = 0; testnet.halvingInterval = 210000; testnet.genesis = { version: 1, hash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), prevBlock: b('0000000000000000000000000000000000000000000000000000000000000000'), merkleRoot: b('d5109ae6160cd7653bc2856dd9db5828b77c51951b2078423b3e6483e78f6a6d'), time: 1549910012, bits: 504365040, nonce: 1236328, height: 0 }; testnet.genesisBlock = '010000000000000000000000000000000000000000000000000000000000' + '000000000000d5109ae6160cd7653bc2856dd9db5828b77c51951b207842' + '3b3e6483e78f6a6ddae5494df0ff0f1e68dd120001010000000100000000' + '00000000000000000000000000000000000000000000000000000000ffff' + 'ffff4704f0ff0f1e01043f31312f4665622f3230313920426974636f696e' + '20457965732024332e384b20416674657220486967682d566f6c756d6520' + '507269636520427265616b6f7574ffffffff0100f2052a01000000434104' + '5eb3a9e4920eba4373e3a4d442f1946a5b10b12fdf41914e434cdcdfde0c' + 'f11210fc1f0c17048154fe943fa44b9b0f70eea6ce2b0e5a52847d7681c7' + '248cc3fbac00000000'; testnet.pow = { limit: new BN( '00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), bits: 504365040, chainwork: new BN( '00', 'hex' ), targetTimespan: 24 * 60 * 60, targetSpacing: 1.5 * 60, targetTimespanDigishield: 1.5 * 60, retargetInterval: 2016, targetReset: true, noRetargeting: false }; testnet.block = { bip34height: 0, bip34hash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), bip65height: 0, bip65hash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), bip66height: 0, bip66hash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), uahfHeight: 0, uahfHash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), daaHeight: 0, daaHash: b('62175a27931049a428fa38ec90079108a14c207f28c3f99c2ad3d5948d030000'), magneticAnomalyActivationTime: 1542300000, greatWallActivationTime: 1557921600, pruneAfterHeight: 1000, keepBlocks: 10000, maxTipAge: 24 * 60 * 60, slowHeight: 950000 }; testnet.bip30 = {}; testnet.activationThreshold = 1512; // 75% for testchains testnet.minerWindow = 100; // nPowTargetTimespan / nPowTargetSpacing testnet.deployments = { csv: { name: 'csv', bit: 0, startTime: 1456790400, // March 1st, 2016 timeout: 1493596800, // May 1st, 2017 threshold: -1, window: -1, required: false, force: true }, testdummy: { name: 'testdummy', bit: 28, startTime: 1199145601, // January 1, 2008 timeout: 1230767999, // December 31, 2008 threshold: -1, window: -1, required: false, force: true } }; testnet.deploys = [ testnet.deployments.csv, testnet.deployments.testdummy ]; testnet.keyPrefix = { privkey: 0xef, xpubkey: 0x043587cf, xprivkey: 0x04358394, xpubkey58: 'tpub', xprivkey58: 'tprv', coinType: 1 }; testnet.addressPrefix = { pubkeyhash: 0x6f, scripthash: 0xc4, cashaddr: 'mxtest' }; testnet.requireStandard = false; testnet.rpcPort = 17887; testnet.walletPort = 17334; testnet.minRelay = 1000; testnet.feeRate = 20000; testnet.maxFeeRate = 60000; testnet.selfConnect = false; testnet.requestMempool = false; /* * Regtest */ const regtest = {}; regtest.type = 'regtest'; regtest.seeds = [ '127.0.0.1' ]; regtest.magic = 0xfabfb5da; regtest.port = 17999; regtest.checkpointMap = {}; regtest.lastCheckpoint = 0; regtest.halvingInterval = 150; regtest.genesis = { version: 1, hash: b('b4c4173bd70ba4cc665c29bfcca70cbf19240a16388c50ea7377c73d1c698d61'), prevBlock: b('0000000000000000000000000000000000000000000000000000000000000000'), merkleRoot: b('d5109ae6160cd7653bc2856dd9db5828b77c51951b2078423b3e6483e78f6a6d'), time: 1549910012, bits: 545259519, nonce: 2, height: 0 }; regtest.genesisBlock = '0100000000000000000000000000000000000000000000000000000000' + '00000000000000d5109ae6160cd7653bc2856dd9db5828b77c51951b20' + '78423b3e6483e78f6a6ddae5494dffff7f200200000001010000000100' + '0000000000000000000000000000000000000000000000000000000000' + '0000ffffffff4704f0ff0f1e01043f31312f4665622f32303139204269' + '74636f696e20457965732024332e384b20416674657220486967682d56' + '6f6c756d6520507269636520427265616b6f7574ffffffff0100f2052a' + '010000004341045eb3a9e4920eba4373e3a4d442f1946a5b10b12fdf41' + '914e434cdcdfde0cf11210fc1f0c17048154fe943fa44b9b0f70eea6ce' + '2b0e5a52847d7681c7248cc3fbac00000000'; regtest.pow = { limit: new BN( '7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'hex' ), bits: 545259519, chainwork: new BN( '0000000000000000000000000000000000000000000000000000000000000002', 'hex' ), targetTimespan: 2.8 * 24 * 60 * 60, targetSpacing: 2 * 60, targetTimespanDigishield: 2 * 60, retargetInterval: 2016, targetReset: true, noRetargeting: true }; regtest.block = { bip34height: 0, bip34hash: null, bip65height: 0, bip65hash: null, bip66height: 0, bip66hash: null, uahfHeight: 0, uahfHash: null, daaHeight: 0, daaHash: null, magneticAnomalyActivationTime: 1542300000, greatWallActivationTime: 1557921600, pruneAfterHeight: 1000, keepBlocks: 10000, maxTipAge: 0xffffffff, slowHeight: 0 }; regtest.bip30 = {}; regtest.activationThreshold = 108; // 75% for testchains regtest.minerWindow = 144; // Faster than normal for regtest regtest.deployments = { csv: { name: 'csv', bit: 0, startTime: 0, timeout: 0xffffffff, threshold: -1, window: -1, required: false, force: true }, testdummy: { name: 'testdummy', bit: 28, startTime: 0, timeout: 0xffffffff, threshold: -1, window: -1, required: false, force: true } }; regtest.deploys = [ regtest.deployments.csv, regtest.deployments.testdummy ]; regtest.keyPrefix = { privkey: 0x5a, xpubkey: 0xeab4fa05, xprivkey: 0xeab404c7, xpubkey58: 'rpub', xprivkey58: 'rprv', coinType: 1 }; regtest.addressPrefix = { pubkeyhash: 0x3c, scripthash: 0x26, cashaddr: 'mxreg' }; regtest.requireStandard = false; regtest.rpcPort = 17998; regtest.walletPort = 47334; regtest.minRelay = 1000; regtest.feeRate = 20000; regtest.maxFeeRate = 60000; regtest.selfConnect = true; regtest.requestMempool = true; /* * Simnet (btcd) */ const simnet = {}; simnet.type = 'simnet'; simnet.seeds = [ '127.0.0.1' ]; simnet.magic = 0xf2faede4; simnet.port = 18555; simnet.checkpointMap = {}; simnet.lastCheckpoint = 0; simnet.halvingInterval = 210000; simnet.genesis = { version: 1, hash: b('69e2d922b7f19a28b491b3712fccefb71782591df26aa094dfcb94ce9afaac20'), prevBlock: b('0000000000000000000000000000000000000000000000000000000000000000'), merkleRoot: b('3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a'), time: 1401292357, bits: 545259519, nonce: 2, height: 0 }; simnet.genesisBlock = '0100000000000000000000000000000000000000000000000000000000000000000000' + '003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a4506' + '8653ffff7f200200000001010000000100000000000000000000000000000000000000' + '00000000000000000000000000ffffffff4d04ffff001d0104455468652054696d6573' + '2030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66' + '207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01' + '000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f' + '61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f' + 'ac00000000'; simnet.pow = { limit: new BN( // High target of 0x207fffff (545259519) '7fffff0000000000000000000000000000000000000000000000000000000000', 'hex' ), bits: 545259519, chainwork: new BN( '0000000000000000000000000000000000000000000000000000000000000002', 'hex' ), targetTimespan: 2.8 * 24 * 60 * 60, targetSpacing: 2 * 60, targetTimespanDigishield: 2 * 60, retargetInterval: 2016, targetReset: true, noRetargeting: false }; simnet.block = { bip34height: 0, bip34hash: b('f67ad7695d9b662a72ff3d8edbbb2de0bfa67b13974bb9910d116d5cbd863e68'), bip65height: 0, bip65hash: b('f67ad7695d9b662a72ff3d8edbbb2de0bfa67b13974bb9910d116d5cbd863e68'), bip66height: 0, bip66hash: b('f67ad7695d9b662a72ff3d8edbbb2de0bfa67b13974bb9910d116d5cbd863e68'), uahfHeight: 0, uahfHash: null, daaHeight: 0, daaHash: null, magneticAnomalyActivationTime: 1542300000, greatWallActivationTime: 1557921600, pruneAfterHeight: 1000, keepBlocks: 10000, maxTipAge: 0xffffffff, slowHeight: 0 }; simnet.bip30 = {}; simnet.activationThreshold = 75; // 75% for testchains simnet.minerWindow = 100; // nPowTargetTimespan / nPowTargetSpacing simnet.deployments = { csv: { name: 'csv', bit: 0, startTime: 0, // March 1st, 2016 timeout: 0xffffffff, // May 1st, 2017 threshold: -1, window: -1, required: false, force: true }, testdummy: { name: 'testdummy', bit: 28, startTime: 1199145601, // January 1, 2008 timeout: 1230767999, // December 31, 2008 threshold: -1, window: -1, required: false, force: true } }; simnet.deploys = [ simnet.deployments.csv, simnet.deployments.testdummy ]; simnet.keyPrefix = { privkey: 0x64, xpubkey: 0x0420bd3a, xprivkey: 0x0420b900, xpubkey58: 'spub', xprivkey58: 'sprv', coinType: 115 }; simnet.addressPrefix = { pubkeyhash: 0x3f, scripthash: 0x7b, cashaddr: 'bchsim' }; simnet.requireStandard = false; simnet.rpcPort = 18556; simnet.walletPort = 18558; simnet.minRelay = 1000; simnet.feeRate = 20000; simnet.maxFeeRate = 60000; simnet.selfConnect = false; simnet.requestMempool = false; /* * Expose */ network.main = main; network.testnet = testnet; network.regtest = regtest; network.simnet = simnet;