Documentation ¶
Overview ¶
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Copyright (c) 2020-2021 The bitcoinpay developers license that can be found in the LICENSE file. Reference resources of rust bitVector
Index ¶
- Constants
- Variables
- func BigToCompact(n *big.Int) uint32
- func CalcCuckooDiff(scale uint64, blockHash hash.Hash) *big.Int
- func CalcWork(bits uint32, powType PowType) *big.Int
- func CompactToBig(compact uint32) *big.Int
- func ConvertBytesToUint32Array(data []byte) []uint32
- func CuckooDiffToTarget(scale uint64, diff *big.Int) string
- func HashToBig(hash *hash.Hash) *big.Int
- type BitcoinpayKeccak256
- func (this *BitcoinpayKeccak256) BlockData() PowBytes
- func (this *BitcoinpayKeccak256) Bytes() PowBytes
- func (this *BitcoinpayKeccak256) CheckAvailable() bool
- func (this *BitcoinpayKeccak256) CompareDiff(newTarget *big.Int, target *big.Int) bool
- func (this *BitcoinpayKeccak256) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *BitcoinpayKeccak256) GetPowResult() json.PowResult
- func (this *BitcoinpayKeccak256) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *BitcoinpayKeccak256) PowPercent() *big.Int
- func (this *BitcoinpayKeccak256) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type Blake2bd
- func (this *Blake2bd) BlockData() PowBytes
- func (this *Blake2bd) Bytes() PowBytes
- func (this *Blake2bd) CheckAvailable() bool
- func (this *Blake2bd) CompareDiff(newTarget *big.Int, target *big.Int) bool
- func (this *Blake2bd) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *Blake2bd) GetPowResult() json.PowResult
- func (this *Blake2bd) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *Blake2bd) PowPercent() *big.Int
- func (this *Blake2bd) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type Cuckaroo
- func (this *Cuckaroo) CheckAvailable() bool
- func (this *Cuckaroo) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *Cuckaroo) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *Cuckaroo) GraphWeight() uint64
- func (this *Cuckaroo) PowPercent() *big.Int
- func (this *Cuckaroo) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type Cuckaroom
- func (this *Cuckaroom) CheckAvailable() bool
- func (this *Cuckaroom) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *Cuckaroom) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *Cuckaroom) GraphWeight() uint64
- func (this *Cuckaroom) PowPercent() *big.Int
- func (this *Cuckaroom) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type Cuckatoo
- func (this *Cuckatoo) CheckAvailable() bool
- func (this *Cuckatoo) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *Cuckatoo) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *Cuckatoo) GraphWeight() uint64
- func (this *Cuckatoo) PowPercent() *big.Int
- func (this *Cuckatoo) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type Cuckoo
- func (this *Cuckoo) BlockData() PowBytes
- func (this *Cuckoo) Bytes() PowBytes
- func (this *Cuckoo) CompareDiff(newTarget *big.Int, target *big.Int) bool
- func (this *Cuckoo) GetCircleNonces() (nonces [cuckoo.ProofSize]uint32)
- func (this *Cuckoo) GetEdgeBits() uint8
- func (this *Cuckoo) GetPowResult() json.PowResult
- func (this *Cuckoo) GetSipHash(headerData []byte) hash.Hash
- func (this *Cuckoo) GraphWeight() uint64
- func (this *Cuckoo) SetCircleEdges(edges []uint32)
- func (this *Cuckoo) SetEdgeBits(edge_bits uint8)
- type IPow
- type Percent
- type Pow
- func (this *Pow) GetNonce() uint32
- func (this *Pow) GetPowType() PowType
- func (this *Pow) GetProofData() string
- func (this *Pow) SetMainHeight(mainHeight int64)
- func (this *Pow) SetNonce(nonce uint32)
- func (this *Pow) SetParams(params *PowConfig)
- func (this *Pow) SetPowType(powType PowType)
- func (this *Pow) SetProofData(data []byte)
- type PowBytes
- type PowConfig
- type PowType
- type ProofDataType
- type X16rv3
- func (this *X16rv3) BlockData() PowBytes
- func (this *X16rv3) Bytes() PowBytes
- func (this *X16rv3) CheckAvailable() bool
- func (this *X16rv3) CompareDiff(newTarget *big.Int, target *big.Int) bool
- func (this *X16rv3) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *X16rv3) GetPowResult() json.PowResult
- func (this *X16rv3) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *X16rv3) PowPercent() *big.Int
- func (this *X16rv3) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
- type X8r16
- func (this *X8r16) BlockData() PowBytes
- func (this *X8r16) Bytes() PowBytes
- func (this *X8r16) CheckAvailable() bool
- func (this *X8r16) CompareDiff(newTarget *big.Int, target *big.Int) bool
- func (this *X8r16) GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int
- func (this *X8r16) GetPowResult() json.PowResult
- func (this *X8r16) GetSafeDiff(cur_reduce_diff uint64) *big.Int
- func (this *X8r16) PowPercent() *big.Int
- func (this *X8r16) Verify(headerData []byte, blockHash hash.Hash, targetDiffBits uint32) error
Constants ¶
const ( PROOF_DATA_EDGE_BITS_START = 0 PROOF_DATA_EDGE_BITS_END = 1 PROOF_DATA_CIRCLE_NONCE_END = 169 )
const MAX_CUCKAROOEDGEBITS = 32
const MAX_CUCKAROOMMEDGEBITS = 29
const MAX_CUCKATOOEDGEBITS = 32
const MIN_CUCKAROOEDGEBITS = 24
const MIN_CUCKAROOMMEDGEBITS = 29
const MIN_CUCKATOOEDGEBITS = 29
const POW_LENGTH = 174
proof data length 188
const PROOFDATA_LENGTH = 169
except pow type 4bytes and nonce 8 bytes 176 bytes
Variables ¶
var ( // oneLsh256 is 1 shifted left 256 bits. It is defined here to avoid // the overhead of creating it multiple times. OneLsh256 = new(big.Int).Lsh(bigOne, 256) )
var PowMapString = map[PowType]interface{}{ BLAKE2BD: "blake2bd", CUCKAROO: "cuckaroo", CUCKATOO: "cuckatoo", CUCKAROOM: "cuckaroom", X16RV3: "x16rv3", X8R16: "x8r16", BITCOINPAYKECCAK256: "bitcoinpay_keccak256", }
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 CalcCuckooDiff ¶
calc cuckoo diff
func CalcWork ¶
CalcWork calculates a work value from difficulty bits. it 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 ¶
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 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. TODO, revisit the compact difficulty form design
func CuckooDiffToTarget ¶
calc cuckoo diff convert to target hash like 7fff000000000000000000000000000000000000000000000000000000000000
Types ¶
type BitcoinpayKeccak256 ¶
type BitcoinpayKeccak256 struct {
Pow
}
func (*BitcoinpayKeccak256) BlockData ¶
func (this *BitcoinpayKeccak256) BlockData() PowBytes
pow proof data
func (*BitcoinpayKeccak256) Bytes ¶
func (this *BitcoinpayKeccak256) Bytes() PowBytes
pow proof data
func (*BitcoinpayKeccak256) CheckAvailable ¶
func (this *BitcoinpayKeccak256) CheckAvailable() bool
check pow is available
func (*BitcoinpayKeccak256) CompareDiff ¶
compare the target wether target match the target diff
func (*BitcoinpayKeccak256) GetNextDiffBig ¶
func (*BitcoinpayKeccak256) GetPowResult ¶
func (this *BitcoinpayKeccak256) GetPowResult() json.PowResult
func (*BitcoinpayKeccak256) GetSafeDiff ¶
func (this *BitcoinpayKeccak256) GetSafeDiff(cur_reduce_diff uint64) *big.Int
func (*BitcoinpayKeccak256) PowPercent ¶
func (this *BitcoinpayKeccak256) PowPercent() *big.Int
type Blake2bd ¶
type Blake2bd struct {
Pow
}
func (*Blake2bd) CheckAvailable ¶
check pow is available
func (*Blake2bd) CompareDiff ¶
compare the target wether target match the target diff
func (*Blake2bd) GetNextDiffBig ¶
func (*Blake2bd) GetPowResult ¶
func (*Blake2bd) PowPercent ¶
type Cuckaroo ¶
type Cuckaroo struct {
Cuckoo
}
func (*Cuckaroo) CheckAvailable ¶
check pow is available
func (*Cuckaroo) GetNextDiffBig ¶
func (*Cuckaroo) GraphWeight ¶
calc scale the edge_bits is bigger ,then scale is bigger Reference resources https://eprint.iacr.org/2014/059.pdf 9. Difficulty control page 6 while the average number of cycles found increases slowly with size; from 2 at 2^20 to 3 at 2^30 Less times of hash calculation with the same difficulty 24 => 48 25 => 100 26 => 208 27 => 432 28 => 896 29 => 1856 30 => 3840 31 => 7936 assume init difficulty is 1000 24 target is 0c49ba5e353f7ced000000000000000000000000000000000000000000000000 (The meaning of difficulty needs to be found 1000/48 * 50 ≈ 1000 times in edge_bits 24, and the answer may be obtained once.) why * 50 , because the when edge_count/nodes = 1/2,to find 42 cycles the probality is 2.2% 29 target is db22d0e560418937000000000000000000000000000000000000000000000000 (The difficulty needs to be found 1000/1856 * 50 ≈ 26 times in edge_bits 29, and the answer may be obtained once.) so In order to ensure the fairness of different edge indexes, the mining difficulty is different.
func (*Cuckaroo) PowPercent ¶
type Cuckaroom ¶
type Cuckaroom struct {
Cuckoo
}
func (*Cuckaroom) CheckAvailable ¶
check pow is available
func (*Cuckaroom) GetNextDiffBig ¶
func (*Cuckaroom) GraphWeight ¶
calc scale the edge_bits is bigger ,then scale is bigger Reference resources https://eprint.iacr.org/2014/059.pdf 9. Difficulty control page 6 while the average number of cycles found increases slowly with size; from 2 at 2^20 to 3 at 2^30 Less times of hash calculation with the same difficulty 24 => 48 25 => 100 26 => 208 27 => 432 28 => 896 29 => 1856 30 => 3840 31 => 7936 assume init difficulty is 1000 24 target is 0c49ba5e353f7ced000000000000000000000000000000000000000000000000 (The meaning of difficulty needs to be found 1000/48 * 50 ≈ 1000 times in edge_bits 24, and the answer may be obtained once.) why * 50 , because the when edge_count/nodes = 1/2,to find 42 cycles the probality is 2.2% 29 target is db22d0e560418937000000000000000000000000000000000000000000000000 (The difficulty needs to be found 1000/1856 * 50 ≈ 26 times in edge_bits 29, and the answer may be obtained once.) so In order to ensure the fairness of different edge indexes, the mining difficulty is different.
func (*Cuckaroom) PowPercent ¶
type Cuckatoo ¶
type Cuckatoo struct {
Cuckoo
}
func (*Cuckatoo) CheckAvailable ¶
check pow is available
func (*Cuckatoo) GetNextDiffBig ¶
func (*Cuckatoo) GraphWeight ¶
calc scale the edge_bits is bigger ,then scale is bigger Reference resources https://eprint.iacr.org/2014/059.pdf 9. Difficulty control page 6 while the average number of cycles found increases slowly with size; from 2 at 2^20 to 3 at 2^30 Less times of hash calculation with the same difficulty 24 => 48 25 => 100 26 => 208 27 => 432 28 => 896 29 => 1856 30 => 3840 31 => 7936 assume init difficulty is 1000 24 target is 0c49ba5e353f7ced000000000000000000000000000000000000000000000000 (The meaning of difficulty needs to be found 1000/48 * 50 ≈ 1000 times in edge_bits 24, and the answer may be obtained once.) why * 50 , because the when edge_count/nodes = 1/2,to find 42 cycles the probality is 2.2% 29 target is db22d0e560418937000000000000000000000000000000000000000000000000 (The difficulty needs to be found 1000/1856 * 50 ≈ 26 times in edge_bits 29, and the answer may be obtained once.) so In order to ensure the fairness of different edge indexes, the mining difficulty is different.
func (*Cuckatoo) PowPercent ¶
type Cuckoo ¶
type Cuckoo struct {
Pow
}
func (*Cuckoo) CompareDiff ¶
compare the target wether target match the target diff
func (*Cuckoo) GetCircleNonces ¶
func (*Cuckoo) GetPowResult ¶
func (*Cuckoo) GetSipHash ¶
get sip hash first header data 113 bytes hash
func (*Cuckoo) GraphWeight ¶
type IPow ¶
type IPow interface { // verify result difficulty Verify(headerData []byte, blockHash hash.Hash, targetDiff uint32) error //set header nonce SetNonce(nonce uint32) //calc next diff GetNextDiffBig(weightedSumDiv *big.Int, oldDiffBig *big.Int, currentPowPercent *big.Int) *big.Int GetNonce() uint32 GetPowType() PowType //set pow type SetPowType(powType PowType) GetProofData() string //set proof data SetProofData([]byte) Bytes() PowBytes BlockData() PowBytes //if cur_reduce_diff > 0 compare cur_reduce_diff with powLimitBits or minDiff ,the cur_reduce_diff should less than powLimitBits , and should more than min diff //if cur_reduce_diff <=0 return powLimit or min diff GetSafeDiff(cur_reduce_diff uint64) *big.Int // pow percent PowPercent() *big.Int //pow result GetPowResult() json.PowResult //SetParams SetParams(params *PowConfig) //SetHeight SetMainHeight(height int64) CheckAvailable() bool CompareDiff(newtarget *big.Int, target *big.Int) bool }
type Pow ¶
type Pow struct { PowType PowType //header pow type 1 bytes Nonce uint32 //header nonce 4 bytes ProofData ProofDataType // 1 edge_bits 168 bytes circle length total 169 bytes // contains filtered or unexported fields }
func (*Pow) GetPowType ¶
func (*Pow) GetProofData ¶
func (*Pow) SetMainHeight ¶
func (*Pow) SetPowType ¶
func (*Pow) SetProofData ¶
set proof data except pow type
type PowConfig ¶
type PowConfig struct { // PowLimit defines the highest allowed proof of work value for a block // as a uint256. Blake2bdPowLimit *big.Int // PowLimitBits defines the highest allowed proof of work value for a // block in compact form. // highest value is mean min difficulty Blake2bdPowLimitBits uint32 X16rv3PowLimit *big.Int X16rv3PowLimitBits uint32 X8r16PowLimit *big.Int X8r16PowLimitBits uint32 BitcoinpayKeccak256PowLimit *big.Int BitcoinpayKeccak256PowLimitBits uint32 // cuckoo difficulty calc params min difficulty CuckarooMinDifficulty uint32 CuckaroomMinDifficulty uint32 CuckatooMinDifficulty uint32 Percent []Percent AdjustmentStartMainHeight int64 // contains filtered or unexported fields }
var PowConfigInstance *PowConfig
func (*PowConfig) GetPercentByHeight ¶
get Percent By height
type ProofDataType ¶
type ProofDataType [PROOFDATA_LENGTH]byte
func (*ProofDataType) Bytes ¶
func (this *ProofDataType) Bytes() []byte
func (*ProofDataType) String ¶
func (this *ProofDataType) String() string
type X16rv3 ¶
type X16rv3 struct {
Pow
}
func (*X16rv3) CompareDiff ¶
compare the target wether target match the target diff
func (*X16rv3) GetNextDiffBig ¶
func (*X16rv3) GetPowResult ¶
func (*X16rv3) PowPercent ¶
type X8r16 ¶
type X8r16 struct {
Pow
}
func (*X8r16) CompareDiff ¶
compare the target wether target match the target diff