fork

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: Unlicense Imports: 9 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

Index

Constants

View Source
const (
	Scrypt  = "scrypt"
	SHA256d = "sha256d"
)

Variables

View Source
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:   25000000,
			Algos:              P9Algos,
			AlgoVers:           P9AlgoVers,
			TargetTimePerBlock: 36,
			AveragingInterval:  3600,
			TestnetStart:       0,
		},
	}
	// P9AlgoVers is the lookup for after 1st hardfork
	P9AlgoVers = make(map[int32]string)

	// DoublingSequence is the differential between different block versions and
	// their relative block timing
	DoublingSequence = []int{2, 4, 8, 16, 32, 64, 128, 256, 512}
	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 * DoublingSequence[0] / IntervalDivisor,
		},
		6: {
			6, p9PowLimitBits, 1,
			IntervalBase * DoublingSequence[1] / IntervalDivisor,
		},
		7: {
			7, p9PowLimitBits, 2,
			IntervalBase * DoublingSequence[2] / IntervalDivisor,
		},
		8: {
			8, p9PowLimitBits, 3,
			IntervalBase * DoublingSequence[3] / IntervalDivisor,
		},
		9: {
			9, p9PowLimitBits, 4,
			IntervalBase * DoublingSequence[4] / IntervalDivisor,
		},
		10: {
			10, p9PowLimitBits, 5,
			IntervalBase * DoublingSequence[5] / IntervalDivisor,
		},
		11: {
			11, p9PowLimitBits, 7,
			IntervalBase * DoublingSequence[7] / IntervalDivisor,
		},
		12: {
			12, p9PowLimitBits, 6,
			IntervalBase * DoublingSequence[6] / IntervalDivisor,
		},
		13: {
			13, p9PowLimitBits, 8,
			IntervalBase * DoublingSequence[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)
)
View Source
var F, E, W, I, D, T log.LevelPrinter = log.GetLogPrinterSet(subsystem)

Functions

func AlgoVerIterator

func AlgoVerIterator(height int32) (
	next func(), curr func() int32,
	more func() bool,
)

AlgoVerIterator returns a next and more function to use in a for loop to iterate over block versions at current height

func ForkCalc

func ForkCalc()

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 GetAlgoVerSlice

func GetAlgoVerSlice(height int32) (o []int32)

func GetAlgos

func GetAlgos(height int32) (o map[string]AlgoParams)

GetAlgos returns the map of names and algorithm parameters

func GetAveragingInterval

func GetAveragingInterval(height int32) (r int32)

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 GetNumAlgos

func GetNumAlgos(height int32) (numAlgos int)

GetNumAlgos returns the number of algos at a given height

func GetRandomVersion

func GetRandomVersion(height int32) int32

GetRandomVersion returns a random version relevant to the current hard fork state and height

func GetTargetTimePerBlock

func GetTargetTimePerBlock(height int32) (r int64)

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

Types

type AlgoParams

type AlgoParams struct {
	Version         int32
	MinBits         uint32
	AlgoID          uint32
	VersionInterval int
}

AlgoParams are the identifying block version number and their minimum target bits

type AlgoSpec

type AlgoSpec struct {
	Version int32
	Name    string
}

type AlgoSpecs

type AlgoSpecs []AlgoSpec

func (AlgoSpecs) Len

func (a AlgoSpecs) Len() int

func (AlgoSpecs) Less

func (a AlgoSpecs) Less(i, j int) bool

func (AlgoSpecs) Swap

func (a AlgoSpecs) Swap(i, j int)

type HardForks

type HardForks struct {
	Number             int
	ActivationHeight   int32
	Name               string
	Algos              map[string]AlgoParams
	AlgoVers           map[int32]string
	TargetTimePerBlock int32
	AveragingInterval  int32
	TestnetStart       int32
}

HardForks is the details related to a hard fork, number, name and activation height

Jump to

Keyboard shortcuts

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