github.com/lbryio/lbcd@v0.22.119/chaincfg/params.go (about) 1 // Copyright (c) 2014-2016 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package chaincfg 6 7 import ( 8 "encoding/binary" 9 "encoding/hex" 10 "errors" 11 "math" 12 "math/big" 13 "strings" 14 "time" 15 16 "github.com/lbryio/lbcd/chaincfg/chainhash" 17 "github.com/lbryio/lbcd/wire" 18 ) 19 20 // These variables are the chain proof-of-work limit parameters for each default 21 // network. 22 var ( 23 // bigOne is 1 represented as a big.Int. It is defined here to avoid 24 // the overhead of creating it multiple times. 25 bigOne = big.NewInt(1) 26 27 // mainPowLimit is the highest proof of work value a Bitcoin block can 28 // have for the main network. It is the value 2^240 - 1. 29 mainPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 240), bigOne) 30 31 // regressionPowLimit is the highest proof of work value a Bitcoin block 32 // can have for the regression test network. It is the value 2^255 - 1. 33 regressionPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne) 34 35 // testNet3PowLimit is the highest proof of work value a Bitcoin block 36 // can have for the test network (version 3). It is the value 37 // 2^240 - 1. 38 testNet3PowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 240), bigOne) 39 40 // simNetPowLimit is the highest proof of work value a Bitcoin block 41 // can have for the simulation test network. It is the value 2^255 - 1. 42 simNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne) 43 44 // sigNetPowLimit is the highest proof of work value a bitcoin block can 45 // have for the signet test network. It is the value 0x0377ae << 216. 46 sigNetPowLimit = new(big.Int).Lsh(new(big.Int).SetInt64(0x0377ae), 216) 47 48 // DefaultSignetChallenge is the byte representation of the signet 49 // challenge for the default (public, Taproot enabled) signet network. 50 // This is the binary equivalent of the bitcoin script 51 // 1 03ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430 52 // 0359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c4 2 53 // OP_CHECKMULTISIG 54 DefaultSignetChallenge, _ = hex.DecodeString( 55 "512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d" + 56 "1e086be430210359ef5021964fe22d6f8e05b2463c9540ce9688" + 57 "3fe3b278760f048f5189f2e6c452ae", 58 ) 59 60 // DefaultSignetDNSSeeds is the list of seed nodes for the default 61 // (public, Taproot enabled) signet network. 62 DefaultSignetDNSSeeds = []DNSSeed{ 63 {"178.128.221.177", false}, 64 {"2a01:7c8:d005:390::5", false}, 65 {"v7ajjeirttkbnt32wpy3c6w3emwnfr3fkla7hpxcfokr3ysd3kqtzmqd.onion:39246", false}, 66 } 67 ) 68 69 // Checkpoint identifies a known good point in the block chain. Using 70 // checkpoints allows a few optimizations for old blocks during initial download 71 // and also prevents forks from old blocks. 72 // 73 // Each checkpoint is selected based upon several factors. See the 74 // documentation for blockchain.IsCheckpointCandidate for details on the 75 // selection criteria. 76 type Checkpoint struct { 77 Height int32 78 Hash *chainhash.Hash 79 } 80 81 // DNSSeed identifies a DNS seed. 82 type DNSSeed struct { 83 // Host defines the hostname of the seed. 84 Host string 85 86 // HasFiltering defines whether the seed supports filtering 87 // by service flags (wire.ServiceFlag). 88 HasFiltering bool 89 } 90 91 // ConsensusDeployment defines details related to a specific consensus rule 92 // change that is voted in. This is part of BIP0009. 93 type ConsensusDeployment struct { 94 // BitNumber defines the specific bit number within the block version 95 // this particular soft-fork deployment refers to. 96 BitNumber uint8 97 98 // StartTime is the median block time after which voting on the 99 // deployment starts. 100 StartTime uint64 101 102 // ExpireTime is the median block time after which the attempted 103 // deployment expires. 104 ExpireTime uint64 105 106 // ForceActiveAt is added by LBRY to bypass consensus. Features are activated via hard-fork instead. 107 ForceActiveAt int32 108 } 109 110 // Constants that define the deployment offset in the deployments field of the 111 // parameters for each deployment. This is useful to be able to get the details 112 // of a specific deployment by name. 113 const ( 114 // DeploymentTestDummy defines the rule change deployment ID for testing 115 // purposes. 116 DeploymentTestDummy = iota 117 118 // DeploymentCSV defines the rule change deployment ID for the CSV 119 // soft-fork package. The CSV package includes the deployment of BIPS 120 // 68, 112, and 113. 121 DeploymentCSV 122 123 // DeploymentSegwit defines the rule change deployment ID for the 124 // Segregated Witness (segwit) soft-fork package. The segwit package 125 // includes the deployment of BIPS 141, 142, 144, 145, 147 and 173. 126 DeploymentSegwit 127 128 // DeploymentTaproot defines the rule change deployment ID for the 129 // Taproot (+Schnorr) soft-fork package. The taproot package includes 130 // the deployment of BIPS 340, 341 and 342. 131 DeploymentTaproot 132 133 // NOTE: DefinedDeployments must always come last since it is used to 134 // determine how many defined deployments there currently are. 135 136 // DefinedDeployments is the number of currently defined deployments. 137 DefinedDeployments 138 ) 139 140 // Params defines a Bitcoin network by its parameters. These parameters may be 141 // used by Bitcoin applications to differentiate networks as well as addresses 142 // and keys for one network from those intended for use on another network. 143 type Params struct { 144 // Name defines a human-readable identifier for the network. 145 Name string 146 147 // Net defines the magic bytes used to identify the network. 148 Net wire.BitcoinNet 149 150 // DefaultPort defines the default peer-to-peer port for the network. 151 DefaultPort string 152 153 // DNSSeeds defines a list of DNS seeds for the network that are used 154 // as one method to discover peers. 155 DNSSeeds []DNSSeed 156 157 // GenesisBlock defines the first block of the chain. 158 GenesisBlock *wire.MsgBlock 159 160 // GenesisHash is the starting block hash. 161 GenesisHash *chainhash.Hash 162 163 // PowLimit defines the highest allowed proof of work value for a block 164 // as a uint256. 165 PowLimit *big.Int 166 167 // PowLimitBits defines the highest allowed proof of work value for a 168 // block in compact form. 169 PowLimitBits uint32 170 171 // These fields define the block heights at which the specified softfork 172 // BIP became active. 173 BIP0034Height int32 174 BIP0065Height int32 175 BIP0066Height int32 176 177 // CoinbaseMaturity is the number of blocks required before newly mined 178 // coins (coinbase transactions) can be spent. 179 CoinbaseMaturity uint16 180 181 // SubsidyReductionInterval is the interval of blocks before the subsidy 182 // is reduced. 183 SubsidyReductionInterval int32 184 185 // TargetTimespan is the desired amount of time that should elapse 186 // before the block difficulty requirement is examined to determine how 187 // it should be changed in order to maintain the desired block 188 // generation rate. 189 TargetTimespan time.Duration 190 191 // TargetTimePerBlock is the desired amount of time to generate each 192 // block. 193 TargetTimePerBlock time.Duration 194 195 // RetargetAdjustmentFactor is the adjustment factor used to limit 196 // the minimum and maximum amount of adjustment that can occur between 197 // difficulty retargets. 198 RetargetAdjustmentFactor int64 199 200 // ReduceMinDifficulty defines whether the network should reduce the 201 // minimum required difficulty after a long enough period of time has 202 // passed without finding a block. This is really only useful for test 203 // networks and should not be set on a main network. 204 ReduceMinDifficulty bool 205 206 // MinDiffReductionTime is the amount of time after which the minimum 207 // required difficulty should be reduced when a block hasn't been found. 208 // 209 // NOTE: This only applies if ReduceMinDifficulty is true. 210 MinDiffReductionTime time.Duration 211 212 // GenerateSupported specifies whether or not CPU mining is allowed. 213 GenerateSupported bool 214 215 // Checkpoints ordered from oldest to newest. 216 Checkpoints []Checkpoint 217 218 // These fields are related to voting on consensus rule changes as 219 // defined by BIP0009. 220 // 221 // RuleChangeActivationThreshold is the number of blocks in a threshold 222 // state retarget window for which a positive vote for a rule change 223 // must be cast in order to lock in a rule change. It should typically 224 // be 95% for the main network and 75% for test networks. 225 // 226 // MinerConfirmationWindow is the number of blocks in each threshold 227 // state retarget window. 228 // 229 // Deployments define the specific consensus rule changes to be voted 230 // on. 231 RuleChangeActivationThreshold uint32 232 MinerConfirmationWindow uint32 233 Deployments [DefinedDeployments]ConsensusDeployment 234 235 // Mempool parameters 236 RelayNonStdTxs bool 237 238 // Human-readable part for Bech32 encoded segwit addresses, as defined 239 // in BIP 173. 240 Bech32HRPSegwit string 241 242 // Address encoding magics 243 PubKeyHashAddrID byte // First byte of a P2PKH address 244 ScriptHashAddrID byte // First byte of a P2SH address 245 PrivateKeyID byte // First byte of a WIF private key 246 247 // BIP32 hierarchical deterministic extended key magics 248 HDPrivateKeyID [4]byte 249 HDPublicKeyID [4]byte 250 251 // BIP44 coin type used in the hierarchical deterministic path for 252 // address generation. 253 HDCoinType uint32 254 } 255 256 // MainNetParams defines the network parameters for the main Bitcoin network. 257 var MainNetParams = Params{ 258 Name: "mainnet", 259 Net: wire.MainNet, 260 DefaultPort: "9246", 261 DNSSeeds: []DNSSeed{ 262 {"dnsseed1.lbry.com", true}, 263 {"dnsseed2.lbry.com", true}, 264 {"dnsseed3.lbry.com", true}, 265 {"seed.lbry.grin.io", true}, 266 {"seed.allaboutlbc.com", true}, 267 }, 268 269 // Chain parameters 270 GenesisBlock: &genesisBlock, 271 GenesisHash: &genesisHash, 272 PowLimit: mainPowLimit, 273 PowLimitBits: 0x1f00ffff, 274 BIP0034Height: 1, 275 BIP0065Height: 200000, 276 BIP0066Height: 200000, 277 CoinbaseMaturity: 100, 278 SubsidyReductionInterval: 1 << 5, 279 TargetTimespan: time.Second * 150, // retarget every block 280 TargetTimePerBlock: time.Second * 150, // 150 seconds 281 RetargetAdjustmentFactor: 4, // 25% less, 400% more 282 ReduceMinDifficulty: false, 283 MinDiffReductionTime: 0, 284 GenerateSupported: false, 285 286 // Checkpoints ordered from oldest to newest. 287 Checkpoints: []Checkpoint{ 288 {40000, newHashFromStr("4c55584b068108b15c0066a010d11971aa92f46b0a73d479f1b7fa57df8b05f4")}, 289 {80000, newHashFromStr("6e9facdfb87ba8394a46c61a7c093f7f00b1397a2dabc6a04f2911e0efdcf50a")}, 290 {120000, newHashFromStr("6a9dba420ec544b927769765dccec8b29e214e6ca9f82b54a52bf20ca517b75a")}, 291 {160000, newHashFromStr("87b2913a509d857401f7587903c90214db7847af1a1ad63a3b6f245936e3ae9d")}, 292 {200000, newHashFromStr("0fe8ed6019a83028006435e47be4e37a0d3ed48019cde1dc7ede6562e5829839")}, 293 {240000, newHashFromStr("cb3c2342afbe7291012f2288403a9d105f46987f78b279d516db2deb4d35b0b7")}, 294 {280000, newHashFromStr("9835d03eb527ea4ce45c217350c68042926d497c21fb31413b2f7824ff6fc6c3")}, 295 {320000, newHashFromStr("ad80c7cb91ca1d9c9b7bf68ca1b6d4ba217fe25ca5ded6a7e8acbaba663b143f")}, 296 {360000, newHashFromStr("f9fd013252439663c1e729a8afb27187a8b9cc63a253336060f867e3cfbe4dcb")}, 297 {400000, newHashFromStr("f0e56e70782af63ccb49c76e852540688755869ba59ec68cac9c04a6b4d9f5ca")}, 298 {440000, newHashFromStr("52760e00c369b40781a2ced32836711fab82a720fafb121118c815bb46afd996")}, 299 {480000, newHashFromStr("cecacaf4d1a8d1ef60da39343540781115abb91f5f0c976bb08afc4d4e3218ac")}, 300 {520000, newHashFromStr("fa5e9d6dcf9ad57ba60d8ba26fb05585741098d10f42ed9d5e6b5e90ebc278d6")}, 301 {560000, newHashFromStr("95c6229bd9b40f03a8426b2fec740026b3f06b1628cfb87527b0cbd0da328c0c")}, 302 {600000, newHashFromStr("532657a97d480feb2d0423bb736cbfd7400b3ac8311e81ac749a2f29103a6c6b")}, 303 {640000, newHashFromStr("68b69e3e8765e1ddbac63cbfbbf12e1a920da994d242a26fd07624f067743080")}, 304 {680000, newHashFromStr("7b9f30c959405b5b96d0b0c2ba8fc7c5586cd0ce40df51427de4b8a217859c45")}, 305 {720000, newHashFromStr("42084d5f88c71c0ae09b8677070969df9c3ef875c5f434133f552d863204f0cb")}, 306 {760000, newHashFromStr("1887cd8b50375a9ac0dc9686c98fa8ac69bca618eab6254310647057f6fe4fc9")}, 307 {800000, newHashFromStr("d34bb871b21e6fda4bd9d9e530ebf12e044814004007f088415035c651ecf322")}, 308 {840000, newHashFromStr("d0e73c5ce3ad5d6fdb4483aa450f0b1cf7e4570987ee3a3806ace4ad2f7cc9af")}, 309 {880000, newHashFromStr("806a95f26bab603f1d9132b5d4ea72aab9d1198ad55ae18dac1e149f6cb70ce4")}, 310 {920000, newHashFromStr("83bc84555105436c51728ab200e8da4d9b3a365fd3d1d47a60048ad0f977c55b")}, 311 {960000, newHashFromStr("60e37b1c2d1f8771290b7f84865cbadf22b5b89d3ce1201d454b09f0775b42c2")}, 312 }, 313 314 // Consensus rule change deployments. 315 // 316 // The miner confirmation window is defined as: 317 // target proof of work timespan / target proof of work spacing 318 RuleChangeActivationThreshold: 1916, // 95% of MinerConfirmationWindow 319 MinerConfirmationWindow: 2016, // 320 Deployments: [DefinedDeployments]ConsensusDeployment{ 321 DeploymentTestDummy: { 322 BitNumber: 28, 323 StartTime: 1199145601, // January 1, 2008 UTC 324 ExpireTime: 1230767999, // December 31, 2008 UTC 325 }, 326 DeploymentCSV: { 327 BitNumber: 0, 328 StartTime: 1462060800, // May 1st, 2016 329 ExpireTime: 1493596800, // May 1st, 2017 330 ForceActiveAt: 200000, 331 }, 332 DeploymentSegwit: { 333 BitNumber: 1, 334 StartTime: 1547942400, // Jan 20, 2019 335 ExpireTime: 1548288000, // Jan 24, 2019 336 ForceActiveAt: 680770, 337 }, 338 }, 339 340 // Mempool parameters 341 RelayNonStdTxs: false, 342 343 // Human-readable part for Bech32 encoded segwit addresses, as defined in 344 // BIP 173. 345 Bech32HRPSegwit: "lbc", 346 347 // Address encoding magics 348 PubKeyHashAddrID: 0x55, 349 ScriptHashAddrID: 0x7a, 350 PrivateKeyID: 0x1c, 351 352 // BIP32 hierarchical deterministic extended key magics 353 HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4}, 354 HDPublicKeyID: [4]byte{0x04, 0x88, 0xb2, 0x1e}, 355 356 // BIP44 coin type used in the hierarchical deterministic path for 357 // address generation. 358 HDCoinType: 0, 359 } 360 361 // RegressionNetParams defines the network parameters for the regression test 362 // Bitcoin network. Not to be confused with the test Bitcoin network (version 363 // 3), this network is sometimes simply called "testnet". 364 var RegressionNetParams = Params{ 365 Name: "regtest", 366 Net: wire.TestNet, 367 DefaultPort: "29246", 368 DNSSeeds: []DNSSeed{}, 369 370 // Chain parameters 371 GenesisBlock: ®TestGenesisBlock, 372 GenesisHash: ®TestGenesisHash, 373 PowLimit: regressionPowLimit, 374 PowLimitBits: 0x207fffff, 375 CoinbaseMaturity: 100, 376 BIP0034Height: 1000, 377 BIP0065Height: 1351, // Used by regression tests 378 BIP0066Height: 1251, // Used by regression tests 379 SubsidyReductionInterval: 1 << 5, 380 TargetTimespan: time.Second, 381 TargetTimePerBlock: time.Second, 382 RetargetAdjustmentFactor: 4, // 25% less, 400% more 383 ReduceMinDifficulty: false, 384 MinDiffReductionTime: 0, 385 GenerateSupported: true, 386 387 // Checkpoints ordered from oldest to newest. 388 Checkpoints: nil, 389 390 // Consensus rule change deployments. 391 // 392 // The miner confirmation window is defined as: 393 // target proof of work timespan / target proof of work spacing 394 RuleChangeActivationThreshold: 108, // 75% of MinerConfirmationWindow 395 MinerConfirmationWindow: 144, 396 Deployments: [DefinedDeployments]ConsensusDeployment{ 397 DeploymentTestDummy: { 398 BitNumber: 28, 399 StartTime: 0, // Always available for vote 400 ExpireTime: math.MaxInt64, // Never expires 401 }, 402 DeploymentCSV: { 403 BitNumber: 0, 404 StartTime: 0, // Always available for vote 405 ExpireTime: math.MaxInt64, // Never expires 406 ForceActiveAt: 1, 407 }, 408 DeploymentSegwit: { 409 BitNumber: 1, 410 StartTime: 0, 411 ExpireTime: math.MaxInt64, 412 ForceActiveAt: 150, 413 }, 414 }, 415 416 // Mempool parameters 417 RelayNonStdTxs: true, 418 419 // Human-readable part for Bech32 encoded segwit addresses, as defined in 420 // BIP 173. 421 Bech32HRPSegwit: "rlbc", 422 423 // Address encoding magics 424 PubKeyHashAddrID: 111, // starts with m or n 425 ScriptHashAddrID: 196, // starts with 2 426 PrivateKeyID: 239, // starts with 9 (uncompressed) or c (compressed) 427 428 // BIP32 hierarchical deterministic extended key magics 429 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 430 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 431 432 // BIP44 coin type used in the hierarchical deterministic path for 433 // address generation. 434 HDCoinType: 1, 435 } 436 437 // TestNet3Params defines the network parameters for the test Bitcoin network 438 // (version 3). Not to be confused with the regression test network, this 439 // network is sometimes simply called "testnet". 440 var TestNet3Params = Params{ 441 Name: "testnet3", 442 Net: wire.TestNet3, 443 DefaultPort: "19246", 444 DNSSeeds: []DNSSeed{ 445 {"testdnsseed1.lbry.com", true}, 446 {"testdnsseed2.lbry.com", true}, 447 }, 448 449 // Chain parameters 450 GenesisBlock: &testNet3GenesisBlock, 451 GenesisHash: &testNet3GenesisHash, 452 PowLimit: testNet3PowLimit, 453 PowLimitBits: 0x1f00ffff, 454 BIP0034Height: 21111, // 0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8 455 BIP0065Height: 1200000, 456 BIP0066Height: 1200000, 457 CoinbaseMaturity: 100, 458 SubsidyReductionInterval: 1 << 5, 459 TargetTimespan: time.Second * 150, // retarget every block 460 TargetTimePerBlock: time.Second * 150, // 150 seconds 461 RetargetAdjustmentFactor: 4, // 25% less, 400% more 462 ReduceMinDifficulty: false, 463 MinDiffReductionTime: 0, 464 GenerateSupported: true, 465 466 // Checkpoints ordered from oldest to newest. 467 Checkpoints: []Checkpoint{}, 468 469 // Consensus rule change deployments. 470 // 471 // The miner confirmation window is defined as: 472 // target proof of work timespan / target proof of work spacing 473 RuleChangeActivationThreshold: 1512, // 75% of MinerConfirmationWindow 474 MinerConfirmationWindow: 2016, 475 Deployments: [DefinedDeployments]ConsensusDeployment{ 476 DeploymentTestDummy: { 477 BitNumber: 28, 478 StartTime: 1199145601, // January 1, 2008 UTC 479 ExpireTime: 1230767999, // December 31, 2008 UTC 480 }, 481 DeploymentCSV: { 482 BitNumber: 0, 483 StartTime: 1456790400, // March 1st, 2016 484 ExpireTime: 1493596800, // May 1st, 2017 485 }, 486 DeploymentSegwit: { 487 BitNumber: 1, 488 StartTime: 1462060800, // May 1st 2016 489 ExpireTime: 1493596800, // May 1st 2017 490 ForceActiveAt: 1198600, 491 }, 492 }, 493 494 // Mempool parameters 495 RelayNonStdTxs: true, 496 497 // Human-readable part for Bech32 encoded segwit addresses, as defined in 498 // BIP 173. 499 Bech32HRPSegwit: "tlbc", 500 501 // Address encoding magics 502 PubKeyHashAddrID: 111, 503 ScriptHashAddrID: 196, 504 PrivateKeyID: 239, 505 506 // BIP32 hierarchical deterministic extended key magics 507 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 508 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 509 510 // BIP44 coin type used in the hierarchical deterministic path for 511 // address generation. 512 HDCoinType: 1, 513 } 514 515 // SimNetParams defines the network parameters for the simulation test Bitcoin 516 // network. This network is similar to the normal test network except it is 517 // intended for private use within a group of individuals doing simulation 518 // testing. The functionality is intended to differ in that the only nodes 519 // which are specifically specified are used to create the network rather than 520 // following normal discovery rules. This is important as otherwise it would 521 // just turn into another public testnet. 522 var SimNetParams = Params{ 523 Name: "simnet", 524 Net: wire.SimNet, 525 DefaultPort: "39246", 526 DNSSeeds: []DNSSeed{}, // NOTE: There must NOT be any seeds. 527 528 // Chain parameters 529 GenesisBlock: &simNetGenesisBlock, 530 GenesisHash: &simNetGenesisHash, 531 PowLimit: simNetPowLimit, 532 PowLimitBits: 0x207fffff, 533 BIP0034Height: 0, // Always active on simnet 534 BIP0065Height: 0, // Always active on simnet 535 BIP0066Height: 0, // Always active on simnet 536 CoinbaseMaturity: 100, 537 SubsidyReductionInterval: 210000, 538 TargetTimespan: time.Second * 150, 539 TargetTimePerBlock: time.Second * 150, 540 RetargetAdjustmentFactor: 4, // 25% less, 400% more 541 ReduceMinDifficulty: true, 542 MinDiffReductionTime: 0, 543 GenerateSupported: true, 544 545 // Checkpoints ordered from oldest to newest. 546 Checkpoints: nil, 547 548 // Consensus rule change deployments. 549 // 550 // The miner confirmation window is defined as: 551 // target proof of work timespan / target proof of work spacing 552 RuleChangeActivationThreshold: 75, // 75% of MinerConfirmationWindow 553 MinerConfirmationWindow: 100, 554 Deployments: [DefinedDeployments]ConsensusDeployment{ 555 DeploymentTestDummy: { 556 BitNumber: 28, 557 StartTime: 0, // Always available for vote 558 ExpireTime: math.MaxInt64, // Never expires 559 }, 560 DeploymentCSV: { 561 BitNumber: 0, 562 StartTime: 0, // Always available for vote 563 ExpireTime: math.MaxInt64, // Never expires 564 }, 565 DeploymentSegwit: { 566 BitNumber: 1, 567 StartTime: 0, 568 ExpireTime: math.MaxInt64, 569 }, 570 }, 571 572 // Mempool parameters 573 RelayNonStdTxs: true, 574 575 // Human-readable part for Bech32 encoded segwit addresses, as defined in 576 // BIP 173. 577 Bech32HRPSegwit: "slbc", 578 579 // Address encoding magics 580 PubKeyHashAddrID: 111, 581 ScriptHashAddrID: 196, 582 PrivateKeyID: 239, 583 584 // BIP32 hierarchical deterministic extended key magics 585 HDPrivateKeyID: [4]byte{0x04, 0x20, 0xb9, 0x00}, // starts with sprv 586 HDPublicKeyID: [4]byte{0x04, 0x20, 0xbd, 0x3a}, // starts with spub 587 588 // BIP44 coin type used in the hierarchical deterministic path for 589 // address generation. 590 HDCoinType: 115, // ASCII for s 591 } 592 593 // SigNetParams defines the network parameters for the default public signet 594 // Bitcoin network. Not to be confused with the regression test network, this 595 // network is sometimes simply called "signet" or "taproot signet". 596 var SigNetParams = CustomSignetParams( 597 DefaultSignetChallenge, DefaultSignetDNSSeeds, 598 ) 599 600 // CustomSignetParams creates network parameters for a custom signet network 601 // from a challenge. The challenge is the binary compiled version of the block 602 // challenge script. 603 func CustomSignetParams(challenge []byte, dnsSeeds []DNSSeed) Params { 604 // The message start is defined as the first four bytes of the sha256d 605 // of the challenge script, as a single push (i.e. prefixed with the 606 // challenge script length). 607 challengeLength := byte(len(challenge)) 608 hashDouble := chainhash.DoubleHashB( 609 append([]byte{challengeLength}, challenge...), 610 ) 611 612 // We use little endian encoding of the hash prefix to be in line with 613 // the other wire network identities. 614 net := binary.LittleEndian.Uint32(hashDouble[0:4]) 615 return Params{ 616 Name: "signet", 617 Net: wire.BitcoinNet(net), 618 DefaultPort: "39246", 619 DNSSeeds: dnsSeeds, 620 621 // Chain parameters 622 GenesisBlock: &sigNetGenesisBlock, 623 GenesisHash: &sigNetGenesisHash, 624 PowLimit: sigNetPowLimit, 625 PowLimitBits: 0x1e0377ae, 626 BIP0034Height: 1, 627 BIP0065Height: 1, 628 BIP0066Height: 1, 629 CoinbaseMaturity: 100, 630 SubsidyReductionInterval: 210000, 631 TargetTimespan: time.Hour * 24 * 14, // 14 days 632 TargetTimePerBlock: time.Minute * 10, // 10 minutes 633 RetargetAdjustmentFactor: 4, // 25% less, 400% more 634 ReduceMinDifficulty: false, 635 MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2 636 GenerateSupported: false, 637 638 // Checkpoints ordered from oldest to newest. 639 Checkpoints: nil, 640 641 // Consensus rule change deployments. 642 // 643 // The miner confirmation window is defined as: 644 // target proof of work timespan / target proof of work spacing 645 RuleChangeActivationThreshold: 1916, // 95% of 2016 646 MinerConfirmationWindow: 2016, 647 Deployments: [DefinedDeployments]ConsensusDeployment{ 648 DeploymentTestDummy: { 649 BitNumber: 28, 650 StartTime: 1199145601, // January 1, 2008 UTC 651 ExpireTime: 1230767999, // December 31, 2008 UTC 652 }, 653 DeploymentCSV: { 654 BitNumber: 29, 655 StartTime: 0, // Always available for vote 656 ExpireTime: math.MaxInt64, // Never expires 657 }, 658 DeploymentSegwit: { 659 BitNumber: 29, 660 StartTime: 0, // Always available for vote 661 ExpireTime: math.MaxInt64, // Never expires. 662 }, 663 DeploymentTaproot: { 664 BitNumber: 29, 665 StartTime: 0, // Always available for vote 666 ExpireTime: math.MaxInt64, // Never expires. 667 }, 668 }, 669 670 // Mempool parameters 671 RelayNonStdTxs: false, 672 673 // Human-readable part for Bech32 encoded segwit addresses, as defined in 674 // BIP 173. 675 Bech32HRPSegwit: "slbc", 676 677 // Address encoding magics 678 PubKeyHashAddrID: 0x6f, // starts with m or n 679 ScriptHashAddrID: 0xc4, // starts with 2 680 PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed) 681 682 // BIP32 hierarchical deterministic extended key magics 683 HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv 684 HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub 685 686 // BIP44 coin type used in the hierarchical deterministic path for 687 // address generation. 688 HDCoinType: 1, 689 } 690 } 691 692 var ( 693 // ErrDuplicateNet describes an error where the parameters for a Bitcoin 694 // network could not be set due to the network already being a standard 695 // network or previously-registered into this package. 696 ErrDuplicateNet = errors.New("duplicate Bitcoin network") 697 698 // ErrUnknownHDKeyID describes an error where the provided id which 699 // is intended to identify the network for a hierarchical deterministic 700 // private extended key is not registered. 701 ErrUnknownHDKeyID = errors.New("unknown hd private extended key bytes") 702 703 // ErrInvalidHDKeyID describes an error where the provided hierarchical 704 // deterministic version bytes, or hd key id, is malformed. 705 ErrInvalidHDKeyID = errors.New("invalid hd extended key version bytes") 706 ) 707 708 var ( 709 registeredNets = make(map[wire.BitcoinNet]struct{}) 710 pubKeyHashAddrIDs = make(map[byte]struct{}) 711 scriptHashAddrIDs = make(map[byte]struct{}) 712 bech32SegwitPrefixes = make(map[string]struct{}) 713 hdPrivToPubKeyIDs = make(map[[4]byte][]byte) 714 ) 715 716 // String returns the hostname of the DNS seed in human-readable form. 717 func (d DNSSeed) String() string { 718 return d.Host 719 } 720 721 // Register registers the network parameters for a Bitcoin network. This may 722 // error with ErrDuplicateNet if the network is already registered (either 723 // due to a previous Register call, or the network being one of the default 724 // networks). 725 // 726 // Network parameters should be registered into this package by a main package 727 // as early as possible. Then, library packages may lookup networks or network 728 // parameters based on inputs and work regardless of the network being standard 729 // or not. 730 func Register(params *Params) error { 731 if _, ok := registeredNets[params.Net]; ok { 732 return ErrDuplicateNet 733 } 734 registeredNets[params.Net] = struct{}{} 735 pubKeyHashAddrIDs[params.PubKeyHashAddrID] = struct{}{} 736 scriptHashAddrIDs[params.ScriptHashAddrID] = struct{}{} 737 738 err := RegisterHDKeyID(params.HDPublicKeyID[:], params.HDPrivateKeyID[:]) 739 if err != nil { 740 return err 741 } 742 743 // A valid Bech32 encoded segwit address always has as prefix the 744 // human-readable part for the given net followed by '1'. 745 bech32SegwitPrefixes[params.Bech32HRPSegwit+"1"] = struct{}{} 746 return nil 747 } 748 749 // mustRegister performs the same function as Register except it panics if there 750 // is an error. This should only be called from package init functions. 751 func mustRegister(params *Params) { 752 if err := Register(params); err != nil { 753 panic("failed to register network: " + err.Error()) 754 } 755 } 756 757 // IsPubKeyHashAddrID returns whether the id is an identifier known to prefix a 758 // pay-to-pubkey-hash address on any default or registered network. This is 759 // used when decoding an address string into a specific address type. It is up 760 // to the caller to check both this and IsScriptHashAddrID and decide whether an 761 // address is a pubkey hash address, script hash address, neither, or 762 // undeterminable (if both return true). 763 func IsPubKeyHashAddrID(id byte) bool { 764 _, ok := pubKeyHashAddrIDs[id] 765 return ok 766 } 767 768 // IsScriptHashAddrID returns whether the id is an identifier known to prefix a 769 // pay-to-script-hash address on any default or registered network. This is 770 // used when decoding an address string into a specific address type. It is up 771 // to the caller to check both this and IsPubKeyHashAddrID and decide whether an 772 // address is a pubkey hash address, script hash address, neither, or 773 // undeterminable (if both return true). 774 func IsScriptHashAddrID(id byte) bool { 775 _, ok := scriptHashAddrIDs[id] 776 return ok 777 } 778 779 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit 780 // addresses on any default or registered network. This is used when decoding 781 // an address string into a specific address type. 782 func IsBech32SegwitPrefix(prefix string) bool { 783 prefix = strings.ToLower(prefix) 784 _, ok := bech32SegwitPrefixes[prefix] 785 return ok 786 } 787 788 // RegisterHDKeyID registers a public and private hierarchical deterministic 789 // extended key ID pair. 790 // 791 // Non-standard HD version bytes, such as the ones documented in SLIP-0132, 792 // should be registered using this method for library packages to lookup key 793 // IDs (aka HD version bytes). When the provided key IDs are invalid, the 794 // ErrInvalidHDKeyID error will be returned. 795 // 796 // Reference: 797 // 798 // SLIP-0132 : Registered HD version bytes for BIP-0032 799 // https://github.com/satoshilabs/slips/blob/master/slip-0132.md 800 func RegisterHDKeyID(hdPublicKeyID []byte, hdPrivateKeyID []byte) error { 801 if len(hdPublicKeyID) != 4 || len(hdPrivateKeyID) != 4 { 802 return ErrInvalidHDKeyID 803 } 804 805 var keyID [4]byte 806 copy(keyID[:], hdPrivateKeyID) 807 hdPrivToPubKeyIDs[keyID] = hdPublicKeyID 808 809 return nil 810 } 811 812 // HDPrivateKeyToPublicKeyID accepts a private hierarchical deterministic 813 // extended key id and returns the associated public key id. When the provided 814 // id is not registered, the ErrUnknownHDKeyID error will be returned. 815 func HDPrivateKeyToPublicKeyID(id []byte) ([]byte, error) { 816 if len(id) != 4 { 817 return nil, ErrUnknownHDKeyID 818 } 819 820 var key [4]byte 821 copy(key[:], id) 822 pubBytes, ok := hdPrivToPubKeyIDs[key] 823 if !ok { 824 return nil, ErrUnknownHDKeyID 825 } 826 827 return pubBytes, nil 828 } 829 830 // newHashFromStr converts the passed big-endian hex string into a 831 // chainhash.Hash. It only differs from the one available in chainhash in that 832 // it panics on an error since it will only (and must only) be called with 833 // hard-coded, and therefore known good, hashes. 834 func newHashFromStr(hexStr string) *chainhash.Hash { 835 hash, err := chainhash.NewHashFromStr(hexStr) 836 if err != nil { 837 // Ordinarily I don't like panics in library code since it 838 // can take applications down without them having a chance to 839 // recover which is extremely annoying, however an exception is 840 // being made in this case because the only way this can panic 841 // is if there is an error in the hard-coded hashes. Thus it 842 // will only ever potentially panic on init and therefore is 843 // 100% predictable. 844 panic(err) 845 } 846 return hash 847 } 848 849 func init() { 850 // Register all default networks when the package is initialized. 851 mustRegister(&MainNetParams) 852 mustRegister(&TestNet3Params) 853 mustRegister(&RegressionNetParams) 854 mustRegister(&SimNetParams) 855 }