params-defs.go raw

   1  package chaincfg
   2  
   3  import (
   4  	"encoding/hex"
   5  	"errors"
   6  	"math/big"
   7  	"time"
   8  	
   9  	"github.com/p9c/p9/pkg/chainhash"
  10  	"github.com/p9c/p9/pkg/wire"
  11  )
  12  
  13  var (
  14  	// ErrDuplicateNet describes an error where the parameters for a Bitcoin network could not be set due to the network
  15  	// already being a standard network or previously-registered into this package.
  16  	ErrDuplicateNet = errors.New("duplicate Bitcoin network")
  17  	// ErrUnknownHDKeyID describes an error where the provided id which is intended to identify the network for a
  18  	// hierarchical deterministic private extended key is not registered.
  19  	ErrUnknownHDKeyID    = errors.New("unknown hd private extended key bytes")
  20  	registeredNets       = make(map[wire.BitcoinNet]struct{})
  21  	pubKeyHashAddrIDs    = make(map[byte]struct{})
  22  	scriptHashAddrIDs    = make(map[byte]struct{})
  23  	bech32SegwitPrefixes = make(map[string]struct{})
  24  	hdPrivToPubKeyIDs    = make(map[[4]byte][]byte)
  25  	// allOnes is 32 bytes of 0xff, the maximum target
  26  	allOnes = func() big.Int {
  27  		b := big.NewInt(1)
  28  		t := make([]byte, 32)
  29  		for i := range t {
  30  			t[i] = ^byte(0)
  31  		}
  32  		b.SetBytes(t)
  33  		return *b
  34  	}()
  35  	// mainPowLimit is the highest proof of work value a Parallelcoin block can have for the main network.
  36  	mainPowLimit = func() big.Int {
  37  		mplb, _ := hex.DecodeString("00000fffff000000000000000000000000000000000000000000000000000000")
  38  		return *big.NewInt(0).SetBytes(mplb) // AllOnes.Rsh(&AllOnes, 0)
  39  	}()
  40  	// MainPowLimit is the pre-hardfork pow limit
  41  	MainPowLimit = mainPowLimit
  42  	// MainPowLimitBits is the bits version of the above
  43  	MainPowLimitBits = BigToCompact(&MainPowLimit)
  44  	scryptPowLimit   = func() big.Int {
  45  		mplb, _ := hex.DecodeString("0000fffff0000000000000000000000000000000000000000000000000000000")
  46  		return *big.NewInt(0).SetBytes(mplb) // AllOnes.Rsh(&AllOnes, 0)
  47  	}()
  48  	// ScryptPowLimit is the pre-hardfork maximum hash for Scrypt algorithm
  49  	ScryptPowLimit = scryptPowLimit
  50  	// ScryptPowLimitBits is the bits version of the above
  51  	ScryptPowLimitBits = BigToCompact(&scryptPowLimit)
  52  	// regressionPowLbimit is the highest proof of work value a Bitcoin block can have for the regression test network.
  53  	// It is the value 2^255 - 1, all ones, 256 bits.
  54  	regressionPowLimit = &allOnes
  55  	// testnetBits = ScryptPowLimitBits testNet3PowLimit = ScryptPowLimit simNetPowLimit is the highest proof of work
  56  	// value a Bitcoin block can have for the simulation test network. It is the value 2^255 - 1, all ones, 256 bits.
  57  	simNetPowLimit = &allOnes
  58  	// Interval is the number of blocks in the averaging window
  59  	Interval int64 = 100
  60  	// MaxAdjustDown is the percentage hard limit for downwards difficulty adjustment (ie 90%)
  61  	MaxAdjustDown int64 = 10
  62  	// MaxAdjustUp is the percentage hard limit for upwards (ie 120%)
  63  	MaxAdjustUp int64 = 20
  64  	// TargetTimePerBlock is the pre hardfork target time for blocks
  65  	TargetTimePerBlock int64 = 300
  66  	// AveragingInterval is the number of blocks to average (per algorithm)
  67  	AveragingInterval int64 = 10
  68  	// AveragingTargetTimespan is how many seconds for the averaging target interval
  69  	AveragingTargetTimespan = TargetTimePerBlock * AveragingInterval
  70  	// TargetTimespan is the base for adjustment
  71  	TargetTimespan = Interval * TargetTimePerBlock
  72  	// TestnetInterval is the number of blocks in the averaging window
  73  	TestnetInterval int64 = 100
  74  	// TestnetMaxAdjustDown is the percentage hard limit for downwards difficulty adjustment (ie 90%)
  75  	TestnetMaxAdjustDown int64 = 10
  76  	// TestnetMaxAdjustUp is the percentage hard limit for upwards (ie 120%)
  77  	TestnetMaxAdjustUp int64 = 20
  78  	// TestnetTargetTimePerBlock is the pre hardfork target time for blocks
  79  	TestnetTargetTimePerBlock int64 = 9
  80  	// TestnetAveragingInterval is the number of blocks to average (per algorithm)
  81  	TestnetAveragingInterval int64 = 1600
  82  	// TestnetAveragingTargetTimespan is how many seconds for the averaging target interval
  83  	TestnetAveragingTargetTimespan = TestnetTargetTimePerBlock * TestnetAveragingInterval
  84  	// TestnetTargetTimespan is the base for adjustment
  85  	TestnetTargetTimespan = TestnetInterval * TestnetTargetTimePerBlock
  86  )
  87  
  88  // Checkpoint identifies a known good point in the block chain. Using checkpoints allows a few optimizations for old
  89  // blocks during initial download and also prevents forks from old blocks. Each checkpoint is selected based upon
  90  // several factors. See the documentation for blockchain.IsCheckpointCandidate for details on the selection criteria.
  91  type Checkpoint struct {
  92  	Height int32
  93  	Hash   *chainhash.Hash
  94  }
  95  
  96  // DNSSeed identifies a DNS seed.
  97  type DNSSeed struct {
  98  	// Host defines the hostname of the seed.
  99  	Host string
 100  	// HasFiltering defines whether the seed supports filtering by service flags (wire.ServiceFlag).
 101  	HasFiltering bool
 102  }
 103  
 104  // // ConsensusDeployment defines details related to a specific consensus rule change that is voted in. This is part of
 105  // // BIP0009.
 106  // type ConsensusDeployment struct {
 107  // 	// BitNumber defines the specific bit number within the block version this particular soft-fork deployment refers
 108  // 	// to.
 109  // 	BitNumber uint8
 110  // 	// StartTime is the median block time after which voting on the deployment starts.
 111  // 	StartTime uint64
 112  // 	// ExpireTime is the median block time after which the attempted deployment expires.
 113  // 	ExpireTime uint64
 114  // }
 115  
 116  // // Constants that define the deployment offset in the deployments field of the
 117  // // parameters for each deployment. This is useful to be able to get the details
 118  // // of a specific deployment by name.
 119  // const (
 120  // 	// DeploymentTestDummy defines the rule change deployment ID for testing
 121  // 	// purposes.
 122  // 	DeploymentTestDummy = iota
 123  // 	// DeploymentCSV defines the rule change deployment ID for the CSV soft-fork
 124  // 	// package. The CSV package includes the deployment of BIPS 68, 112, and 113.
 125  // 	DeploymentCSV
 126  // 	// DeploymentSegwit defines the rule change deployment ID for the Segregated
 127  // 	// Witness (segwit) soft-fork package. The segwit package includes the
 128  // 	// deployment of BIPS 141, 142, 144, 145, 147 and 173.
 129  // 	DeploymentSegwit
 130  // 	// DefinedDeployments is the number of currently defined deployments.
 131  // 	//
 132  // 	// NOTE: DefinedDeployments must always come last since it is used to determine
 133  // 	// how many defined deployments there currently are.
 134  // 	DefinedDeployments
 135  // )
 136  
 137  // Params defines a Bitcoin network by its parameters. These parameters may be
 138  // used by Bitcoin applications to differentiate networks as well as addresses
 139  // and keys for one network from those intended for use on another network.
 140  type Params struct {
 141  	// Name defines a human-readable identifier for the network.
 142  	Name string
 143  	// Net defines the magic bytes used to identify the network.
 144  	Net wire.BitcoinNet
 145  	// DefaultPort defines the default peer-to-peer port for the network.
 146  	DefaultPort         string
 147  	RPCClientPort       string
 148  	WalletRPCServerPort string
 149  	// DNSSeeds defines a list of DNS seeds for the network that are used
 150  	// as one method to discover peers.
 151  	DNSSeeds []DNSSeed
 152  	// GenesisBlock defines the first block of the chain.
 153  	GenesisBlock *wire.Block
 154  	// GenesisHash is the starting block hash.
 155  	GenesisHash *chainhash.Hash
 156  	// PowLimit defines the highest allowed proof of work value for a // as a uint256.
 157  	PowLimit *big.Int
 158  	// PowLimitBits defines the highest allowed proof of work value for a block in compact form.
 159  	PowLimitBits uint32
 160  	// // These fields define the block heights at which the specified softfork BIP became active.
 161  	// BIP0034Height int32
 162  	// BIP0065Height int32
 163  	// BIP0066Height int32
 164  	// CoinbaseMaturity is the number of blocks required before newly mined coins (coinbase transactions) can be spent.
 165  	CoinbaseMaturity uint16
 166  	// SubsidyReductionInterval is the interval of blocks before the subsidy is reduced.
 167  	SubsidyReductionInterval int32
 168  	// TargetTimespan is the desired amount of time that should elapse before the block difficulty requirement is
 169  	// examined to determine how it should be changed in order to maintain the desired block generation rate.
 170  	TargetTimespan int64
 171  	// TargetTimePerBlock is the desired amount of time to generate each block. Same as TargetSpacing in legacy client.
 172  	TargetTimePerBlock int64
 173  	// RetargetAdjustmentFactor is the adjustment factor used to limit the minimum and maximum amount of adjustment that
 174  	// can occur between difficulty retargets.
 175  	RetargetAdjustmentFactor int64
 176  	// ReduceMinDifficulty defines whether the network should reduce the minimum required difficulty after a long enough
 177  	// period of time has passed without finding a block. This is really only useful for test networks and should not be
 178  	// set on a main network.
 179  	ReduceMinDifficulty bool
 180  	// MinDiffReductionTime is the amount of time after which the minimum required difficulty should be reduced when a
 181  	// block hasn't been found. NOTE: This only applies if ReduceMinDifficulty is true.
 182  	MinDiffReductionTime time.Duration
 183  	// GenerateSupported specifies whether or not CPU mining is allowed.
 184  	GenerateSupported bool
 185  	// Checkpoints ordered from oldest to newest.
 186  	Checkpoints []Checkpoint
 187  	// These fields are related to voting on consensus rule changes as defined by BIP0009.
 188  	//
 189  	// RuleChangeActivationThreshold is the number of blocks in a threshold state retarget window for which a positive
 190  	// vote for a rule change must be cast in order to lock in a rule change. It should typically be 95% for the main
 191  	// network and 75% for test networks.
 192  	RuleChangeActivationThreshold uint32
 193  	// MinerConfirmationWindow is the number of blocks in each threshold state retarget window.
 194  	MinerConfirmationWindow uint32
 195  	// // Deployments define the specific consensus rule changes to be voted on.
 196  	// Deployments [DefinedDeployments]ConsensusDeployment
 197  	// Mempool parameters
 198  	RelayNonStdTxs bool
 199  	// // Human-readable part for Bech32 encoded segwit addresses, as defined in BIP 173.
 200  	// Bech32HRPSegwit string
 201  	// Address encoding magics
 202  	PubKeyHashAddrID byte // First byte of a P2PKH address
 203  	ScriptHashAddrID byte // First byte of a P2SH address
 204  	PrivateKeyID     byte // First byte of a WIF private key
 205  	// WitnessPubKeyHashAddrID byte // First byte of a P2WPKH address
 206  	// WitnessScriptHashAddrID byte // First byte of a P2WSH address
 207  	// BIP32 hierarchical deterministic extended key magics
 208  	HDPrivateKeyID [4]byte
 209  	HDPublicKeyID  [4]byte
 210  	// BIP44 coin type used in the hierarchical deterministic path for address generation.
 211  	HDCoinType uint32
 212  	// Parallelcoin specific difficulty adjustment parameters
 213  	Interval                int64
 214  	AveragingInterval       int64
 215  	AveragingTargetTimespan int64
 216  	MaxAdjustDown           int64
 217  	MaxAdjustUp             int64
 218  	TargetTimespanAdjDown   int64
 219  	MinActualTimespan       int64
 220  	MaxActualTimespan       int64
 221  	// PowLimit defines the highest allowed proof of work value for a scrypt block as a uint256.
 222  	ScryptPowLimit     *big.Int
 223  	ScryptPowLimitBits uint32
 224  }
 225