github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/coinparam/bitcoin.go (about)

     1  package coinparam
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/mit-dci/lit/btcutil/chaincfg/chainhash"
     7  	"github.com/mit-dci/lit/wire"
     8  )
     9  
    10  // MainNetParams defines the network parameters for the main Bitcoin network.
    11  var BitcoinParams = Params{
    12  	Name:          "bitcoin",
    13  	NetMagicBytes: 0xd9b4bef9,
    14  	DefaultPort:   "8333",
    15  	DNSSeeds: []string{
    16  		"seed.bitcoin.sipa.be",
    17  		"dnsseed.bluematt.me",
    18  		"dnsseed.bitcoin.dashjr.org",
    19  		"seed.bitcoinstats.com",
    20  		"seed.bitnodes.io",
    21  		"bitseed.xf2.org",
    22  		"seed.bitcoin.jonasschnelli.ch",
    23  	},
    24  
    25  	// Chain parameters
    26  	GenesisBlock: &genesisBlock,
    27  	GenesisHash:  &genesisHash,
    28  	PoWFunction: func(b []byte, height int32) chainhash.Hash {
    29  		return chainhash.DoubleHashH(b)
    30  	},
    31  	DiffCalcFunction:         diffBitcoin,
    32  	FeePerByte:               80,
    33  	PowLimit:                 mainPowLimit,
    34  	PowLimitBits:             0x1d00ffff,
    35  	CoinbaseMaturity:         100,
    36  	SubsidyReductionInterval: 210000,
    37  	TargetTimespan:           time.Hour * 24 * 14, // 14 days
    38  	TargetTimePerBlock:       time.Minute * 10,    // 10 minutes
    39  	RetargetAdjustmentFactor: 4,                   // 25% less, 400% more
    40  	ReduceMinDifficulty:      false,
    41  	MinDiffReductionTime:     0,
    42  	GenerateSupported:        false,
    43  
    44  	// Checkpoints ordered from oldest to newest.
    45  	Checkpoints: []Checkpoint{
    46  		{11111, newHashFromStr("0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")},
    47  		{33333, newHashFromStr("000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")},
    48  		{74000, newHashFromStr("0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")},
    49  		{105000, newHashFromStr("00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")},
    50  		{134444, newHashFromStr("00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")},
    51  		{168000, newHashFromStr("000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")},
    52  		{193000, newHashFromStr("000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")},
    53  		{210000, newHashFromStr("000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")},
    54  		{216116, newHashFromStr("00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")},
    55  		{225430, newHashFromStr("00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")},
    56  		{250000, newHashFromStr("000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")},
    57  		{267300, newHashFromStr("000000000000000a83fbd660e918f218bf37edd92b748ad940483c7c116179ac")},
    58  		{279000, newHashFromStr("0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")},
    59  		{300255, newHashFromStr("0000000000000000162804527c6e9b9f0563a280525f9d08c12041def0a0f3b2")},
    60  		{319400, newHashFromStr("000000000000000021c6052e9becade189495d1c539aa37c58917305fd15f13b")},
    61  		{343185, newHashFromStr("0000000000000000072b8bf361d01a6ba7d445dd024203fafc78768ed4368554")},
    62  		{352940, newHashFromStr("000000000000000010755df42dba556bb72be6a32f3ce0b6941ce4430152c9ff")},
    63  		{382320, newHashFromStr("00000000000000000a8dc6ed5b133d0eb2fd6af56203e4159789b092defd8ab2")},
    64  	},
    65  
    66  	// Enforce current block version once majority of the network has
    67  	// upgraded.
    68  	// 75% (750 / 1000)
    69  	// Reject previous block versions once a majority of the network has
    70  	// upgraded.
    71  	// 95% (950 / 1000)
    72  	BlockEnforceNumRequired: 750,
    73  	BlockRejectNumRequired:  950,
    74  	BlockUpgradeNumToCheck:  1000,
    75  
    76  	// Mempool parameters
    77  	RelayNonStdTxs: false,
    78  
    79  	// Address encoding magics
    80  	PubKeyHashAddrID: 0x00, // starts with 1
    81  	ScriptHashAddrID: 0x05, // starts with 3
    82  	PrivateKeyID:     0x80, // starts with 5 (uncompressed) or K (compressed)
    83  	Bech32Prefix:     "bc", // starts with bc1
    84  
    85  	// BIP32 hierarchical deterministic extended key magics
    86  	HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, // starts with xprv
    87  	HDPublicKeyID:  [4]byte{0x04, 0x88, 0xb2, 0x1e}, // starts with xpub
    88  
    89  	// BIP44 coin type used in the hierarchical deterministic path for
    90  	// address generation.
    91  	HDCoinType: 0,
    92  }
    93  
    94  // TestNet3Params defines the network parameters for the test Bitcoin network
    95  // (version 3).  Not to be confused with the regression test network, this
    96  // network is sometimes simply called "testnet".
    97  var TestNet3Params = Params{
    98  	Name:          "testnet3",
    99  	NetMagicBytes: 0x0709110b,
   100  	DefaultPort:   "18333",
   101  	DNSSeeds: []string{
   102  		"testnet-seed.bitcoin.jonasschnelli.ch",
   103  		"seed.tbtc.petertodd.org",
   104  		"seed.testnet.bitcoin.sprovoost.nl",
   105  		"testnet-seed.bluematt.me",
   106  	},
   107  
   108  	// Chain parameters
   109  	GenesisBlock: &testNet3GenesisBlock,
   110  	GenesisHash:  &testNet3GenesisHash,
   111  	PoWFunction: func(b []byte, height int32) chainhash.Hash {
   112  		return chainhash.DoubleHashH(b)
   113  	},
   114  	DiffCalcFunction: diffBitcoin,
   115  	StartHeader: newHeaderFromStr("00000020b39e2c241c3fff2c7bf20bc5c5477dc7cedb" +
   116  		"2154ccede1944800000000000000b767d1cb09db9e355835b7e94a385a4f82accea85c" +
   117  		"ac5e6b067096bbd5dcf055fba7415aa313081a91ffefce"),
   118  	StartHeight:              1255968,
   119  	FeePerByte:               80,
   120  	PowLimit:                 testNet3PowLimit,
   121  	PowLimitBits:             0x1d00ffff,
   122  	CoinbaseMaturity:         100,
   123  	SubsidyReductionInterval: 210000,
   124  	TargetTimespan:           time.Hour * 24 * 14, // 14 days
   125  	TargetTimePerBlock:       time.Minute * 10,    // 10 minutes
   126  	RetargetAdjustmentFactor: 4,                   // 25% less, 400% more
   127  	ReduceMinDifficulty:      true,
   128  	MinDiffReductionTime:     time.Minute * 20, // TargetTimePerBlock * 2
   129  	GenerateSupported:        false,
   130  
   131  	// Checkpoints ordered from oldest to newest.
   132  	Checkpoints: []Checkpoint{
   133  		{546, newHashFromStr("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
   134  	},
   135  
   136  	// Enforce current block version once majority of the network has
   137  	// upgraded.
   138  	// 51% (51 / 100)
   139  	// Reject previous block versions once a majority of the network has
   140  	// upgraded.
   141  	// 75% (75 / 100)
   142  	BlockEnforceNumRequired: 51,
   143  	BlockRejectNumRequired:  75,
   144  	BlockUpgradeNumToCheck:  100,
   145  
   146  	// Mempool parameters
   147  	RelayNonStdTxs: true,
   148  
   149  	// Address encoding magics
   150  	PubKeyHashAddrID: 0x6f, // starts with m or n
   151  	ScriptHashAddrID: 0xc4, // starts with 2
   152  	Bech32Prefix:     "tb",
   153  	PrivateKeyID:     0xef, // starts with 9 (uncompressed) or c (compressed)
   154  
   155  	// BIP32 hierarchical deterministic extended key magics
   156  	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
   157  	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
   158  
   159  	// BIP44 coin type used in the hierarchical deterministic path for
   160  	// address generation.
   161  	HDCoinType: 1,
   162  	TestCoin:   true,
   163  }
   164  
   165  // RegressionNetParams defines the network parameters for the regression test
   166  // Bitcoin network.  Not to be confused with the test Bitcoin network (version
   167  // 3), this network is sometimes simply called "testnet".
   168  var RegressionNetParams = Params{
   169  	Name:          "regtest",
   170  	NetMagicBytes: 0xdab5bffa,
   171  	DefaultPort:   "18444",
   172  	DNSSeeds:      []string{},
   173  
   174  	// Chain parameters
   175  	GenesisBlock: &regTestGenesisBlock,
   176  	GenesisHash:  &regTestGenesisHash,
   177  	PoWFunction: func(b []byte, height int32) chainhash.Hash {
   178  		return chainhash.DoubleHashH(b)
   179  	},
   180  	DiffCalcFunction: diffBitcoin,
   181  	//	func(r io.ReadSeeker, height, startheight int32, p *Params) (uint32, error) {
   182  	//		return diffBTC(r, height, startheight, p, false)
   183  	//	},
   184  	FeePerByte:               80,
   185  	PowLimit:                 regressionPowLimit,
   186  	PowLimitBits:             0x207fffff,
   187  	CoinbaseMaturity:         100,
   188  	SubsidyReductionInterval: 150,
   189  	TargetTimespan:           time.Hour * 24 * 14, // 14 days
   190  	TargetTimePerBlock:       time.Minute * 10,    // 10 minutes
   191  	RetargetAdjustmentFactor: 4,                   // 25% less, 400% more
   192  	ReduceMinDifficulty:      true,
   193  	MinDiffReductionTime:     time.Minute * 20, // TargetTimePerBlock * 2
   194  	GenerateSupported:        true,
   195  
   196  	// Checkpoints ordered from oldest to newest.
   197  	Checkpoints: nil,
   198  
   199  	// Enforce current block version once majority of the network has
   200  	// upgraded.
   201  	// 75% (750 / 1000)
   202  	// Reject previous block versions once a majority of the network has
   203  	// upgraded.
   204  	// 95% (950 / 1000)
   205  	BlockEnforceNumRequired: 750,
   206  	BlockRejectNumRequired:  950,
   207  	BlockUpgradeNumToCheck:  1000,
   208  
   209  	// Mempool parameters
   210  	RelayNonStdTxs: true,
   211  
   212  	// Address encoding magics
   213  	PubKeyHashAddrID: 0x6f, // starts with m or n
   214  	ScriptHashAddrID: 0xc4, // starts with 2
   215  	PrivateKeyID:     0xef, // starts with 9 (uncompressed) or c (compressed)
   216  	Bech32Prefix:     "bcrt",
   217  
   218  	// BIP32 hierarchical deterministic extended key magics
   219  	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
   220  	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
   221  
   222  	// BIP44 coin type used in the hierarchical deterministic path for
   223  	// address generation.
   224  	HDCoinType: 257,
   225  	TestCoin:   true,
   226  }
   227  
   228  // genesisCoinbaseTx is the coinbase transaction for the genesis blocks for
   229  // the main network, regression test network, and test network (version 3).
   230  var genesisCoinbaseTx = wire.MsgTx{
   231  	Version: 1,
   232  	TxIn: []*wire.TxIn{
   233  		{
   234  			PreviousOutPoint: wire.OutPoint{
   235  				Hash:  chainhash.Hash{},
   236  				Index: 0xffffffff,
   237  			},
   238  			SignatureScript: []byte{
   239  				0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x45, /* |.......E| */
   240  				0x54, 0x68, 0x65, 0x20, 0x54, 0x69, 0x6d, 0x65, /* |The Time| */
   241  				0x73, 0x20, 0x30, 0x33, 0x2f, 0x4a, 0x61, 0x6e, /* |s 03/Jan| */
   242  				0x2f, 0x32, 0x30, 0x30, 0x39, 0x20, 0x43, 0x68, /* |/2009 Ch| */
   243  				0x61, 0x6e, 0x63, 0x65, 0x6c, 0x6c, 0x6f, 0x72, /* |ancellor| */
   244  				0x20, 0x6f, 0x6e, 0x20, 0x62, 0x72, 0x69, 0x6e, /* | on brin| */
   245  				0x6b, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x65, 0x63, /* |k of sec|*/
   246  				0x6f, 0x6e, 0x64, 0x20, 0x62, 0x61, 0x69, 0x6c, /* |ond bail| */
   247  				0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, /* |out for |*/
   248  				0x62, 0x61, 0x6e, 0x6b, 0x73, /* |banks| */
   249  			},
   250  			Sequence: 0xffffffff,
   251  		},
   252  	},
   253  	TxOut: []*wire.TxOut{
   254  		{
   255  			Value: 0x12a05f200,
   256  			PkScript: []byte{
   257  				0x41, 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, /* |A.g....U| */
   258  				0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, /* |H'.g..q0| */
   259  				0xb7, 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, /* |..\..(.9| */
   260  				0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, /* |..yb...a| */
   261  				0xde, 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, /* |..I..?L.| */
   262  				0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, /* |8..U....| */
   263  				0x12, 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, /* |..\8M...| */
   264  				0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, /* |.W.Lp+k.| */
   265  				0x1d, 0x5f, 0xac, /* |._.| */
   266  			},
   267  		},
   268  	},
   269  	LockTime: 0,
   270  }
   271  
   272  // genesisHash is the hash of the first block in the block chain for the main
   273  // network (genesis block).
   274  var genesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
   275  	0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
   276  	0xc1, 0xa6, 0xa2, 0x46, 0xae, 0x63, 0xf7, 0x4f,
   277  	0x93, 0x1e, 0x83, 0x65, 0xe1, 0x5a, 0x08, 0x9c,
   278  	0x68, 0xd6, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
   279  })
   280  
   281  // genesisMerkleRoot is the hash of the first transaction in the genesis block
   282  // for the main network.
   283  var genesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
   284  	0x3b, 0xa3, 0xed, 0xfd, 0x7a, 0x7b, 0x12, 0xb2,
   285  	0x7a, 0xc7, 0x2c, 0x3e, 0x67, 0x76, 0x8f, 0x61,
   286  	0x7f, 0xc8, 0x1b, 0xc3, 0x88, 0x8a, 0x51, 0x32,
   287  	0x3a, 0x9f, 0xb8, 0xaa, 0x4b, 0x1e, 0x5e, 0x4a,
   288  })
   289  
   290  // genesisBlock defines the genesis block of the block chain which serves as the
   291  // public transaction ledger for the main network.
   292  var genesisBlock = wire.MsgBlock{
   293  	Header: wire.BlockHeader{
   294  		Version:    1,
   295  		PrevBlock:  chainhash.Hash{},         // 0000000000000000000000000000000000000000000000000000000000000000
   296  		MerkleRoot: genesisMerkleRoot,        // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
   297  		Timestamp:  time.Unix(0x495fab29, 0), // 2009-01-03 18:15:05 +0000 UTC
   298  		Bits:       0x1d00ffff,               // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000]
   299  		Nonce:      0x7c2bac1d,               // 2083236893
   300  	},
   301  	Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
   302  }
   303  
   304  // regTestGenesisHash is the hash of the first block in the block chain for the
   305  // regression test network (genesis block).
   306  var regTestGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
   307  	0x06, 0x22, 0x6e, 0x46, 0x11, 0x1a, 0x0b, 0x59,
   308  	0xca, 0xaf, 0x12, 0x60, 0x43, 0xeb, 0x5b, 0xbf,
   309  	0x28, 0xc3, 0x4f, 0x3a, 0x5e, 0x33, 0x2a, 0x1f,
   310  	0xc7, 0xb2, 0xb7, 0x3c, 0xf1, 0x88, 0x91, 0x0f,
   311  })
   312  
   313  // regTestGenesisMerkleRoot is the hash of the first transaction in the genesis
   314  // block for the regression test network.  It is the same as the merkle root for
   315  // the main network.
   316  var regTestGenesisMerkleRoot = genesisMerkleRoot
   317  
   318  // regTestGenesisBlock defines the genesis block of the block chain which serves
   319  // as the public transaction ledger for the regression test network.
   320  var regTestGenesisBlock = wire.MsgBlock{
   321  	Header: wire.BlockHeader{
   322  		Version:    1,
   323  		PrevBlock:  chainhash.Hash{},         // 0000000000000000000000000000000000000000000000000000000000000000
   324  		MerkleRoot: regTestGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
   325  		Timestamp:  time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC
   326  		Bits:       0x207fffff,               // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
   327  		Nonce:      2,
   328  	},
   329  	Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
   330  }
   331  
   332  // testNet3GenesisHash is the hash of the first block in the block chain for the
   333  // test network (version 3).
   334  var testNet3GenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
   335  	0x43, 0x49, 0x7f, 0xd7, 0xf8, 0x26, 0x95, 0x71,
   336  	0x08, 0xf4, 0xa3, 0x0f, 0xd9, 0xce, 0xc3, 0xae,
   337  	0xba, 0x79, 0x97, 0x20, 0x84, 0xe9, 0x0e, 0xad,
   338  	0x01, 0xea, 0x33, 0x09, 0x00, 0x00, 0x00, 0x00,
   339  })
   340  
   341  // testNet3GenesisMerkleRoot is the hash of the first transaction in the genesis
   342  // block for the test network (version 3).  It is the same as the merkle root
   343  // for the main network.
   344  var testNet3GenesisMerkleRoot = genesisMerkleRoot
   345  
   346  // testNet3GenesisBlock defines the genesis block of the block chain which
   347  // serves as the public transaction ledger for the test network (version 3).
   348  var testNet3GenesisBlock = wire.MsgBlock{
   349  	Header: wire.BlockHeader{
   350  		Version:    1,
   351  		PrevBlock:  chainhash.Hash{},          // 0000000000000000000000000000000000000000000000000000000000000000
   352  		MerkleRoot: testNet3GenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
   353  		Timestamp:  time.Unix(1296688602, 0),  // 2011-02-02 23:16:42 +0000 UTC
   354  		Bits:       0x1d00ffff,                // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000]
   355  		Nonce:      0x18aea41a,                // 414098458
   356  	},
   357  	Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
   358  }