fork

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: ISC Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var AlgoVers = map[int32]string{
	2:   "sha256d",
	514: "scrypt",
}

AlgoVers is the lookup for pre hardfork

View Source
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

View Source
var FirstPowLimit = func() big.Int {

	mplb, _ := hex.DecodeString("0fffffff00000000000000000000000000000000000000000000000000000000")
	return *big.NewInt(0).SetBytes(mplb)
}()

FirstPowLimit is

View Source
var FirstPowLimitBits = BigToCompact(&FirstPowLimit)

FirstPowLimitBits is

View Source
var IsTestnet bool

IsTestnet is set at startup here to be accessible to all other libraries

View Source
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

View Source
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

View Source
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

View Source
var SecondPowLimit = func() big.Int {

	mplb, _ := hex.DecodeString("07fffffff0000000000000000000000000000000000000000000000000000000")
	return *big.NewInt(0).SetBytes(mplb)
}()

SecondPowLimit is

View Source
var SecondPowLimitBits = BigToCompact(&SecondPowLimit)

SecondPowLimitBits is

Functions

func Argon2i

func Argon2i(
	bytes []byte) []byte

Argon2i takes bytes, generates a Lyra2REv2 hash as salt, generates an argon2i key

func BigToCompact

func BigToCompact(
	n *big.Int) uint32

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 Blake14lr

func Blake14lr(
	bytes []byte) []byte

Blake14lr takes bytes and returns a blake14lr 256 bit hash

func Blake2b

func Blake2b(
	bytes []byte) []byte

Blake2b takes bytes and returns a blake2b 256 bit hash

func Blake2s

func Blake2s(
	bytes []byte) []byte

Blake2s takes bytes and returns a blake2s 256 bit hash

func CompactToBig

func CompactToBig(
	compact uint32) *big.Int

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

func Cryptonight7v2(
	bytes []byte) []byte

Cryptonight7v2 takes bytes and returns a cryptonight 7 v2 256 bit hash

func GetAlgoID

func GetAlgoID(algoname string, height int32) uint32

GetAlgoID returns the 'algo_id' which in pre-hardfork is not the same as the block version number, but is afterwards

func GetAlgoName

func GetAlgoName(algoVer int32, height int32) (name string)

GetAlgoName returns the string identifier of an algorithm depending on hard fork activation status

func GetAlgoVer

func GetAlgoVer(name string, height int32) (version int32)

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

func GetAveragingInterval(height int32) (r int64)

GetAveragingInterval returns the active block interval target based on hard fork status

func GetCurrent

func GetCurrent(height int32) (curr int)

GetCurrent returns the hardfork number code

func GetMinBits

func GetMinBits(algoname string, height int32) (mb uint32)

GetMinBits returns the minimum diff bits based on height and testnet

func GetMinDiff

func GetMinDiff(algoname string, height int32) (md *big.Int)

GetMinDiff returns the minimum difficulty in uint256 form

func GetTargetTimePerBlock

func GetTargetTimePerBlock(height int32) (r int64)

GetTargetTimePerBlock returns the active block interval target based on hard fork status

func Hash

func Hash(
	bytes []byte, name string, height int32) (out chainhash.Hash)

Hash computes the hash of bytes using the named hash

func Keccak

func Keccak(bytes []byte) []byte

Keccak takes bytes and returns a keccak (sha-3) 256 bit hash

func Lyra2REv2

func Lyra2REv2(bytes []byte) []byte

Lyra2REv2 takes bytes and returns a lyra2rev2 256 bit hash

func SHA256D

func SHA256D(bytes []byte) []byte

SHA256D takes bytes and returns a double SHA256 hash

func Scrypt

func Scrypt(bytes []byte) []byte

Scrypt takes bytes and returns a scrypt 256 bit hash

func Skein

func Skein(bytes []byte) []byte

Skein takes bytes and returns a skein 256 bit hash

func Stribog

func Stribog(bytes []byte) []byte

Stribog takes bytes and returns a double GOST Stribog 256 bit hash

func X11

func X11(bytes []byte) []byte

X11 takes bytes and returns an x11 256 bit hash

Types

type AlgoParams

type AlgoParams struct {
	Version int32
	MinBits uint32
	AlgoID  uint32
	NSperOp int64
}

type HardForks

type HardForks struct {
	Number             uint32
	ActivationHeight   int32
	Name               string
	Algos              map[string]AlgoParams
	AlgoVers           map[int32]string
	WorkBase           int64
	TargetTimePerBlock time.Duration
	AveragingInterval  int64
	TestnetStart       int32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL