Documentation ¶
Overview ¶
Package fork handles tracking the hard fork status and is used to determine which consensus rules apply on a block
Index ¶
- Constants
- Variables
- func AlgoVerIterator(height int32) (next func(), curr func() int32, more func() bool)
- func GetAlgoID(algoname string, height int32) uint32
- func GetAlgoName(algoVer int32, height int32) (name string)
- func GetAlgoVer(name string, height int32) (version int32)
- func GetAlgoVerSlice(height int32) (o []int32)
- func GetAlgos(height int32) (o map[string]AlgoParams)
- func GetAveragingInterval(height int32) (r int32)
- func GetCurrent(height int32) (curr int)
- func GetMinBits(algoname string, height int32) (mb uint32)
- func GetMinDiff(algoname string, height int32) (md *big.Int)
- func GetNumAlgos(height int32) (numAlgos int)
- func GetRandomVersion(height int32) int32
- func GetTargetTimePerBlock(height int32) (r int64)
- type AlgoParams
- type AlgoSpec
- type AlgoSpecs
- type HardForks
Constants ¶
const ( Scrypt = "scrypt" SHA256d = "sha256d" )
Variables ¶
var ( AlgoSlices []AlgoSpecs // AlgoVers is the lookup for pre hardfork // AlgoVers = map[int32]string{ 2: SHA256d, 514: Scrypt, } // Algos are the specifications identifying the algorithm used in the // block proof Algos = map[string]AlgoParams{ AlgoVers[2]: { Version: 2, MinBits: MainPowLimitBits, }, AlgoVers[514]: { Version: 514, MinBits: MainPowLimitBits, AlgoID: 1, }, } // FirstPowLimit is FirstPowLimit = func() big.Int { mplb, _ := hex.DecodeString( "0fffff0000000000000000000000000000000000000000000000000000000000", ) return *big.NewInt(0).SetBytes(mplb) }() // FirstPowLimitBits is FirstPowLimitBits = bits.BigToCompact(&FirstPowLimit) // IsTestnet is set at startup here to be accessible to all other libraries IsTestnet bool // List is the list of existing hard forks and when they activate List = []HardForks{ { Number: 0, Name: "Halcyon days", ActivationHeight: 0, Algos: Algos, AlgoVers: AlgoVers, TargetTimePerBlock: 300, AveragingInterval: 10, TestnetStart: 0, }, { Number: 1, Name: "Plan 9 from Crypto Space", ActivationHeight: 2500000, Algos: P9Algos, AlgoVers: P9AlgoVers, TargetTimePerBlock: 36, AveragingInterval: 3600, TestnetStart: 0, }, } // P9AlgoVers is the lookup for after 1st hardfork P9AlgoVers = make(map[int32]string) P9PrimeSequence = []int{2, 3, 5, 7, 11, 13, 17, 19, 23} IntervalDivisor = 1 IntervalBase = 9 // P9Algos is the algorithm specifications after the hard fork P9Algos = make(map[string]AlgoParams) P9AlgosNumeric = map[int32]AlgoParams{ 5: {5, p9PowLimitBits, 0, IntervalBase * P9PrimeSequence[0] / IntervalDivisor}, 6: {6, p9PowLimitBits, 1, IntervalBase * P9PrimeSequence[1] / IntervalDivisor}, 7: {7, p9PowLimitBits, 2, IntervalBase * P9PrimeSequence[2] / IntervalDivisor}, 8: {8, p9PowLimitBits, 3, IntervalBase * P9PrimeSequence[3] / IntervalDivisor}, 9: {9, p9PowLimitBits, 4, IntervalBase * P9PrimeSequence[4] / IntervalDivisor}, 10: {10, p9PowLimitBits, 5, IntervalBase * P9PrimeSequence[5] / IntervalDivisor}, 11: {11, p9PowLimitBits, 7, IntervalBase * P9PrimeSequence[7] / IntervalDivisor}, 12: {12, p9PowLimitBits, 6, IntervalBase * P9PrimeSequence[6] / IntervalDivisor}, 13: {13, p9PowLimitBits, 8, IntervalBase * P9PrimeSequence[8] / IntervalDivisor}, } P9Average float64 // SecondPowLimit is SecondPowLimit = func() big.Int { mplb, _ := hex.DecodeString( "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", ) return *big.NewInt(0).SetBytes(mplb) }() SecondPowLimitBits = bits.BigToCompact(&SecondPowLimit) MainPowLimit = func() big.Int { mplb, _ := hex.DecodeString( "00000fffff000000000000000000000000000000000000000000000000000000", ) return *big.NewInt(0).SetBytes(mplb) }() MainPowLimitBits = bits.BigToCompact(&MainPowLimit) )
var F, E, W, I, D, T logg.LevelPrinter = logg.GetLogPrinterSet(subsystem)
Functions ¶
func AlgoVerIterator ¶
AlgoVerIterator returns a next and more function to use in a for loop to iterate over block versions at current height
func GetAlgoID ¶
GetAlgoID returns the 'algo_id' which in pre-hardfork is not the same as the block version number, but is afterwards
func GetAlgoName ¶
GetAlgoName returns the string identifier of an algorithm depending on hard fork activation status
func GetAlgoVer ¶
GetAlgoVer returns the version number for a given algorithm (by string name) at a given height. If "random" is given, a random number is taken from the system secure random source (for randomised cpu mining)
func GetAlgoVerSlice ¶
func GetAlgos ¶
func GetAlgos(height int32) (o map[string]AlgoParams)
GetAlgos returns the map of names and algorithm parameters
func GetAveragingInterval ¶
GetAveragingInterval returns the active block interval target based on hard fork status
func GetCurrent ¶
GetCurrent returns the hardfork number code
func GetMinBits ¶
GetMinBits returns the minimum diff bits based on height and testnet
func GetMinDiff ¶
GetMinDiff returns the minimum difficulty in uint256 form
func GetNumAlgos ¶
GetNumAlgos returns the number of algos at a given height
func GetRandomVersion ¶
GetRandomVersion returns a random version relevant to the current hard fork state and height
func GetTargetTimePerBlock ¶
GetTargetTimePerBlock returns the active block interval target based on hard fork status
Types ¶
type AlgoParams ¶
AlgoParams are the identifying block version number and their minimum target bits