Documentation ¶
Index ¶
- Constants
- Variables
- func BTCCalcWork(bits uint32) *big.Int
- func BeaconEpoch(height int32) int32
- func BigToCompact(n *big.Int) uint32
- func CalcPowWeight(powLimit *big.Int, bits uint32, hashSortingBits uint32) uint64
- func CalcWork(bits uint32) *big.Int
- func CompactToBig(compact uint32) *big.Int
- func GetDifficultyRatio(genesisBits, bits uint32) *big.Int
- func HashSortingLastBits(powHash *big.Int, hashSortingSlotNumber uint32) uint32
- func HashToBig(hash *chainhash.Hash) *big.Int
- func KValFloatToInt(val *big.Float) *big.Int
- func KValIntToFloat(nVal *big.Int) *big.Float
- func MultBitsAndK(bits, k uint32) float64
- func PackK(val *big.Float) uint32
- func ShardEpoch(height int32) int32
- func UnpackK(val uint32) *big.Float
- func ValidateHashSortingRule(powHash *big.Int, hashSortingSlotNumber, chainID uint32) bool
Constants ¶
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 // SmallK1 is supplementary reward coefficient for the first mining epoch. // SmallK1 = Lambda ^ 12 SmallK1 = LambdaPow12 // BigK1 is inflation coefficient for the first mining epoch. BigK1 = 3.552713678800501e-15 // 2^−48 DifficultyBeaconEpochLen = 2048 KBeaconEpochLen = 4096 ShardEpochLen = 16 * 4096 )
Variables ¶
Functions ¶
func BTCCalcWork ¶ added in v0.4.0
func BeaconEpoch ¶
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 CalcPowWeight ¶ added in v0.4.2
func CalcWork ¶
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*2^hash_sorting_bits.
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 jaxnetd.
func GetDifficultyRatio ¶ added in v0.4.0
GetDifficultyRatio this is ration of initial difficulty and current.
func HashSortingLastBits ¶ added in v0.4.0
func HashToBig ¶
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 ShardEpoch ¶
func ValidateHashSortingRule ¶ added in v0.4.0
ValidateHashSortingRule checks if chain ID equals to chainIDCount or equals to remainder of modulo operation with chain ID as dividend and chainIDCount as divisor.
Types ¶
This section is empty.