Documentation ¶
Overview ¶
Package fork handles tracking the hard fork status and is used to determine which consensus rules apply on a block TODO: add trailing auto-checkpoint system and hard fork block time change
Index ¶
- Variables
- func Argon2i(bytes []byte) []byte
- func BigToCompact(n *big.Int) uint32
- func Blake14lr(bytes []byte) []byte
- func Blake2b(bytes []byte) []byte
- func Blake2s(bytes []byte) []byte
- func CompactToBig(compact uint32) *big.Int
- func Cryptonight7v2(bytes []byte) []byte
- 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 int64)
- func GetCurrent(height int32) (curr int)
- func GetMinBits(algoname string, height int32) (mb uint32)
- func GetMinDiff(algoname string, height int32) (md *big.Int)
- func GetTargetTimePerBlock(height int32) (r int64)
- func Hash(bytes []byte, name string, height int32) (out chainhash.Hash)
- func Keccak(bytes []byte) []byte
- func Lyra2REv2(bytes []byte) []byte
- func SHA256D(bytes []byte) []byte
- func Scrypt(bytes []byte) []byte
- func Skein(bytes []byte) []byte
- func Stribog(bytes []byte) []byte
- func X11(bytes []byte) []byte
- type AlgoParams
- type HardForks
Constants ¶
This section is empty.
Variables ¶
var AlgoVers = map[int32]string{
2: "sha256d",
514: "scrypt",
}
AlgoVers is the lookup for pre hardfork
var Algos = map[string]AlgoParams{ AlgoVers[2]: {2, mainPowLimitBits, 0, 824}, AlgoVers[514]: {514, mainPowLimitBits, 1, 740839}, }
Algos are the specifications identifying the algorithm used in the block proof
var FirstPowLimit = func() big.Int { mplb, _ := hex.DecodeString("0fffffff00000000000000000000000000000000000000000000000000000000") return *big.NewInt(0).SetBytes(mplb) }()
FirstPowLimit is
var FirstPowLimitBits = BigToCompact(&FirstPowLimit)
FirstPowLimitBits is
var IsTestnet bool
IsTestnet is set at startup here to be accessible to all other libraries
var List = []HardForks{ { Number: 0, Name: "Halcyon days", ActivationHeight: 0, Algos: Algos, AlgoVers: AlgoVers, WorkBase: func() (out int64) { for i := range Algos { out += Algos[i].NSperOp } out /= int64(len(Algos)) return }(), TargetTimePerBlock: 3 * time.Minute, AveragingInterval: 10, TestnetStart: 0, }, { Number: 1, Name: "Plan 9 from Crypto Space", ActivationHeight: 250000, Algos: P9Algos, AlgoVers: P9AlgoVers, WorkBase: func() (out int64) { for i := range P9Algos { out += P9Algos[i].NSperOp } out /= int64(len(P9Algos)) return }(), TargetTimePerBlock: 9 * time.Second, AveragingInterval: 9600, TestnetStart: 100, }, }
List is the list of existing hard forks and when they activate
var P9AlgoVers = map[int32]string{
0: "blake2b",
1: "blake14lr",
2: "blake2s",
3: "keccak",
4: "scrypt",
5: "sha256d",
6: "skein",
7: "stribog",
8: "x11",
}
P9AlgoVers is the lookup for after 1st hardfork
var P9Algos = map[string]AlgoParams{ P9AlgoVers[0]: {0, FirstPowLimitBits, 0, 69495444}, P9AlgoVers[1]: {1, FirstPowLimitBits, 1, 79734306}, P9AlgoVers[2]: {2, FirstPowLimitBits, 2, 69968425}, P9AlgoVers[3]: {3, FirstPowLimitBits, 3, 71988313}, P9AlgoVers[4]: {4, FirstPowLimitBits, 4, 68395274}, P9AlgoVers[5]: {5, FirstPowLimitBits, 5, 67460443}, P9AlgoVers[6]: {6, FirstPowLimitBits, 7, 64433603}, P9AlgoVers[7]: {7, FirstPowLimitBits, 6, 69987634}, P9AlgoVers[8]: {8, FirstPowLimitBits, 8, 64936544}, }
P9Algos is the algorithm specifications after the hard fork
var SecondPowLimit = func() big.Int { mplb, _ := hex.DecodeString("07fffffff0000000000000000000000000000000000000000000000000000000") return *big.NewInt(0).SetBytes(mplb) }()
SecondPowLimit is
var SecondPowLimitBits = BigToCompact(&SecondPowLimit)
SecondPowLimitBits is
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 Cryptonight7v2 ¶
Cryptonight7v2 takes bytes and returns a cryptonight 7 v2 256 bit hash
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 GetTargetTimePerBlock ¶
GetTargetTimePerBlock returns the active block interval target based on hard fork status