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 BigToCompact(n *big.Int) uint32
- func Check(err error) bool
- func CompactToBig(compact uint32) *big.Int
- func Debug(a ...interface{})
- func Debugc(fn func() string)
- func Debugf(format string, a ...interface{})
- func Debugs(a interface{})
- func Error(a ...interface{})
- func Errorc(fn func() string)
- func Errorf(format string, a ...interface{})
- func Errors(a interface{})
- func Fatal(a ...interface{})
- func Fatalc(fn func() string)
- func Fatalf(format string, a ...interface{})
- func Fatals(a interface{})
- func GetAlgoID(algoname string, height int32) uint32
- func GetAlgoName(algoVer int32, height int32) (name string)
- func GetAlgoVer(name string, height int32) (version int32)
- 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 GetRandomVersion(height int32) int32
- func GetTargetTimePerBlock(height int32) (r int64)
- func Info(a ...interface{})
- func Infoc(fn func() string)
- func Infof(format string, a ...interface{})
- func Infos(a interface{})
- func Trace(a ...interface{})
- func Tracec(fn func() string)
- func Tracef(format string, a ...interface{})
- func Traces(a interface{})
- func Warn(a ...interface{})
- func Warnc(fn func() string)
- func Warnf(format string, a ...interface{})
- func Warns(a interface{})
- 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 = 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: 1, }, } // 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 = 101 // P9Algos is the algorithm specifications after the hard fork P9Algos = make(map[string]AlgoParams) P9AlgosNumeric = map[int32]AlgoParams{ 5: {5, FirstPowLimitBits, 0, IntervalBase * P9PrimeSequence[0] / IntervalDivisor}, 6: {6, FirstPowLimitBits, 1, IntervalBase * P9PrimeSequence[1] / IntervalDivisor}, 7: {7, FirstPowLimitBits, 2, IntervalBase * P9PrimeSequence[2] / IntervalDivisor}, 8: {8, FirstPowLimitBits, 3, IntervalBase * P9PrimeSequence[3] / IntervalDivisor}, 9: {9, FirstPowLimitBits, 4, IntervalBase * P9PrimeSequence[4] / IntervalDivisor}, 10: {10, FirstPowLimitBits, 5, IntervalBase * P9PrimeSequence[5] / IntervalDivisor}, 11: {11, FirstPowLimitBits, 7, IntervalBase * P9PrimeSequence[7] / IntervalDivisor}, 12: {12, FirstPowLimitBits, 6, IntervalBase * P9PrimeSequence[6] / IntervalDivisor}, 13: {13, FirstPowLimitBits, 8, IntervalBase * P9PrimeSequence[8] / IntervalDivisor}, } P9Average float64 // SecondPowLimit is SecondPowLimit = func() big.Int { mplb, _ := hex.DecodeString( "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") return *big.NewInt(0).SetBytes(mplb) }() SecondPowLimitBits = BigToCompact(&SecondPowLimit) MainPowLimit = func() big.Int { mplb, _ := hex.DecodeString( "00000fffff000000000000000000000000000000000000000000000000000000") return *big.NewInt(0).SetBytes(mplb) }() MainPowLimitBits = BigToCompact(&MainPowLimit) )
Functions ¶
func BigToCompact ¶
BigToCompact converts a whole number N to a compact representation using an unsigned 32-bit number. The compact representation only provides 23 bits of precision, so values larger than (2^23 - 1) only encode the most significant digits of the number. See CompactToBig for details.
func CompactToBig ¶
CompactToBig converts a compact representation of a whole number N to an unsigned 32-bit number. The representation is similar to IEEE754 floating point numbers. Like IEEE754 floating point, there are three basic components: the sign, the exponent, and the mantissa. They are broken out as follows:
- the most significant 8 bits represent the unsigned base 256 exponent
- bit 23 (the 24th bit) represents the sign bit
- the least significant 23 bits represent the mantissa ------------------------------------------------- | Exponent | Sign | Mantissa | ------------------------------------------------- | 8 bits [31-24] | 1 bit [23] | 23 bits [22-00] | -------------------------------------------------
The formula to calculate N is:
N = (-1^sign) * mantissa * 256^(exponent-3)
This compact form is only used in bitcoin to encode unsigned 256-bit numbers which represent difficulty targets, thus there really is not a need for a sign bit, but it is implemented here to stay consistent with bitcoind.
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 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 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