pow

package
v0.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: ISC Imports: 4 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// Lambda is λ = exp(ln(0.8)/144) = 0.99845159 is some parameter that is determined
	// based on our estimates for technological progress in mining hardware.
	Lambda        = 0.99845159  // λ
	LambdaPow2    = 0.996905578 // λ^2
	LambdaPow4    = 0.993820731 // λ^4
	LambdaPow12   = 0.981576506 // λ^12
	LambdaPowMin2 = 1.003104028 // λ^-2

	// M is a number of blocks on SC that correspond to the one block on BC.
	// In other words, in JaxNet blocks on SC are set to be less difficult than blocks BC.
	// On average, blocks on any SC are generated M times more often than on BC.
	M = int64(40)

	// L is a length of the mining epoch on BC.So for m > 0,
	// m-th mining epoch starts with a BC block with index [(m−1)·L+1] and
	// ends with a block [m·L]. Genesis block has an index 0. It belongs to any 0-th epoch.
	// The reward the genesis block is not determined by this algorithm.
	// Subsequent blocks on BC are indexed in ascending order with a step 1.
	L = int64(4096)
	// LM is a length of the mining epoch on any SC.
	LM = L * M

	// SupplementaryK1 is supplementary reward coefficient for the first mining epoch.
	// SupplementaryK1 = Lambda ^ 12
	SupplementaryK1 = LambdaPow12
	// K1 is inflation coefficient for the first mining epoch.
	K1 = 3.552713678800501e-15 // 2^−48

	BeaconEpochLen = 2048
	ShardEpochLen  = 4 * 60 * 24
)

Variables

This section is empty.

Functions

func BeaconEpoch

func BeaconEpoch(height int32) int32

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 CalcKCoefficient

func CalcKCoefficient(height int32, prevK uint32) uint32

func CalcShardBlockSubsidy added in v0.3.8

func CalcShardBlockSubsidy(height int32, shards, bits, k uint32) int64

CalcShardBlockSubsidy returns reward for shard block. - height is block height; - shards is a number of shards that were mined by a miner at the time; - bits is current target; - k is inflation-fix-coefficient.

func CalcWork

func CalcWork(bits uint32) *big.Int

CalcWork calculates a work value from difficulty bits. Bitcoin increases the difficulty for generating a block by decreasing the value which the generated hash must be less than. This difficulty target is stored in each block header using a compact representation as described in the documentation for CompactToBig. The main chain is selected by choosing the chain that has the most proof of work (highest difficulty). Since a lower target difficulty value equates to higher actual difficulty, the work value which will be accumulated must be the inverse of the difficulty. Also, in order to avoid potential division by zero and really small floating point numbers, the result adds 1 to the denominator and multiplies the numerator by 2^256.

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 jaxnetd.

func GetDifficulty

func GetDifficulty(bits uint32) *big.Rat

func GetDifficultyF

func GetDifficultyF(bits uint32) (float64, error)

func HashSortingLastBits added in v0.4.0

func HashSortingLastBits(diff *big.Int, chainIDCount uint32) uint32

func HashToBig

func HashToBig(hash *chainhash.Hash) *big.Int

HashToBig converts a chainhash.Hash into a big.Int that can be used to perform math comparisons.

func MultBitsAndK added in v0.3.8

func MultBitsAndK(bits, k uint32) float64

func PackRat

func PackRat(val *big.Rat) uint32

func ShardEpoch

func ShardEpoch(height int32) int32

func UnpackRat

func UnpackRat(val uint32) *big.Rat

func ValidateHashSortingRule added in v0.4.0

func ValidateHashSortingRule(headerTarget *big.Int, chainIDCount, chainID uint32) bool

ValidateHashSortingRule checks if chain ID equals chainIDCount or equals remainder of modulo operation with chain ID as dividend and chainIDCount as divisor.

Types

This section is empty.

Jump to

Keyboard shortcuts

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