github.com/lbryio/lbcd@v0.22.119/blockchain/fullblocktests/params.go (about)

     1  // Copyright (c) 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 fullblocktests
     6  
     7  import (
     8  	"encoding/hex"
     9  	"math/big"
    10  	"time"
    11  
    12  	"github.com/lbryio/lbcd/chaincfg"
    13  	"github.com/lbryio/lbcd/chaincfg/chainhash"
    14  	"github.com/lbryio/lbcd/wire"
    15  )
    16  
    17  // newHashFromStr converts the passed big-endian hex string into a
    18  // wire.Hash.  It only differs from the one available in chainhash in that
    19  // it panics on an error since it will only (and must only) be called with
    20  // hard-coded, and therefore known good, hashes.
    21  func newHashFromStr(hexStr string) *chainhash.Hash {
    22  	hash, err := chainhash.NewHashFromStr(hexStr)
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  	return hash
    27  }
    28  
    29  // fromHex converts the passed hex string into a byte slice and will panic if
    30  // there is an error.  This is only provided for the hard-coded constants so
    31  // errors in the source code can be detected. It will only (and must only) be
    32  // called for initialization purposes.
    33  func fromHex(s string) []byte {
    34  	r, err := hex.DecodeString(s)
    35  	if err != nil {
    36  		panic("invalid hex in source file: " + s)
    37  	}
    38  	return r
    39  }
    40  
    41  var (
    42  	// bigOne is 1 represented as a big.Int.  It is defined here to avoid
    43  	// the overhead of creating it multiple times.
    44  	bigOne = big.NewInt(1)
    45  
    46  	// regressionPowLimit is the highest proof of work value a Bitcoin block
    47  	// can have for the regression test network.  It is the value 2^255 - 1.
    48  	regressionPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)
    49  
    50  	// regTestGenesisBlock defines the genesis block of the block chain which serves
    51  	// as the public transaction ledger for the regression test network.
    52  	regTestGenesisBlock = wire.MsgBlock{
    53  		Header: wire.BlockHeader{
    54  			Version:    1,
    55  			PrevBlock:  *newHashFromStr("0000000000000000000000000000000000000000000000000000000000000000"),
    56  			MerkleRoot: *newHashFromStr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"),
    57  			ClaimTrie:  chainhash.Hash{1},        // EmptyTrieHash
    58  			Timestamp:  time.Unix(1296688602, 0), // 2011-02-02 23:16:42 +0000 UTC
    59  			Bits:       0x207fffff,               // 545259519 [7fffff0000000000000000000000000000000000000000000000000000000000]
    60  			Nonce:      2,
    61  		},
    62  		Transactions: []*wire.MsgTx{{
    63  			Version: 1,
    64  			TxIn: []*wire.TxIn{{
    65  				PreviousOutPoint: wire.OutPoint{
    66  					Hash:  chainhash.Hash{},
    67  					Index: 0xffffffff,
    68  				},
    69  				SignatureScript: fromHex("04ffff001d010445" +
    70  					"5468652054696d65732030332f4a616e2f" +
    71  					"32303039204368616e63656c6c6f72206f" +
    72  					"6e206272696e6b206f66207365636f6e64" +
    73  					"206261696c6f757420666f72206261686b73"),
    74  				Sequence: 0xffffffff,
    75  			}},
    76  			TxOut: []*wire.TxOut{{
    77  				Value: 0,
    78  				PkScript: fromHex("4104678afdb0fe5548271967f1" +
    79  					"a67130b7105cd6a828e03909a67962e0ea1f" +
    80  					"61deb649f6bc3f4cef38c4f35504e51ec138" +
    81  					"c4f35504e51ec112de5c384df7ba0b8d578a" +
    82  					"4c702b6bf11d5fac"),
    83  			}},
    84  			LockTime: 0,
    85  		}},
    86  	}
    87  
    88  	regTestGenesisBlockHash = regTestGenesisBlock.BlockHash()
    89  )
    90  
    91  // FbRegressionNetParams defines the network parameters for the regression test
    92  // network.
    93  //
    94  // NOTE: The test generator intentionally does not use the existing definitions
    95  // in the chaincfg package since the intent is to be able to generate known
    96  // good tests which exercise that code.  Using the chaincfg parameters would
    97  // allow them to change out from under the tests potentially invalidating them.
    98  var FbRegressionNetParams = &chaincfg.Params{
    99  	Name:        "regtest",
   100  	Net:         wire.TestNet,
   101  	DefaultPort: "18444",
   102  
   103  	// Chain parameters
   104  	GenesisBlock:             &regTestGenesisBlock,
   105  	GenesisHash:              &regTestGenesisBlockHash,
   106  	PowLimit:                 regressionPowLimit,
   107  	PowLimitBits:             0x207fffff,
   108  	CoinbaseMaturity:         100,
   109  	BIP0034Height:            100000000, // Not active - Permit ver 1 blocks
   110  	BIP0065Height:            1351,      // Used by regression tests
   111  	BIP0066Height:            1251,      // Used by regression tests
   112  	SubsidyReductionInterval: 150,
   113  	TargetTimespan:           time.Hour * 24 * 14, // 14 days
   114  	TargetTimePerBlock:       time.Minute * 10,    // 10 minutes
   115  	RetargetAdjustmentFactor: 4,                   // 25% less, 400% more
   116  	ReduceMinDifficulty:      true,
   117  	MinDiffReductionTime:     time.Minute * 20, // TargetTimePerBlock * 2
   118  	GenerateSupported:        true,
   119  	MinerConfirmationWindow:  1,
   120  
   121  	// Checkpoints ordered from oldest to newest.
   122  	Checkpoints: nil,
   123  
   124  	// Mempool parameters
   125  	RelayNonStdTxs: true,
   126  
   127  	// Address encoding magics
   128  	PubKeyHashAddrID: 0x6f, // starts with m or n
   129  	ScriptHashAddrID: 0xc4, // starts with 2
   130  	PrivateKeyID:     0xef, // starts with 9 (uncompressed) or c (compressed)
   131  
   132  	// BIP32 hierarchical deterministic extended key magics
   133  	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
   134  	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
   135  
   136  	// BIP44 coin type used in the hierarchical deterministic path for
   137  	// address generation.
   138  	HDCoinType: 1,
   139  }