difficulty

package
v0.0.0-...-46f88e6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: ISC Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 GetAgedAnnTarget

func GetAgedAnnTarget(target, annAgeBlocks uint32, packetCryptVersion int) uint32

GetAgedAnnTarget returns the target which will be used for valuing the announcement. The minAnnWork committed in the coinbase must not be less work (higher number) than the highest (least work) aged target for any announcement mined in that block. If the announcement is not valid for adding to the block, return 0xffffffff

func GetEffectiveTarget

func GetEffectiveTarget(blockHeaderTarget uint32, minAnnTarget uint32, annCount uint64, packetCryptVersion int) uint32

GetEffectiveTarget gives the effective target to beat based on the target in the block header, the minimum work (highest target) of any announcement and the number of announcements which were mined with.

func IsAnnMinDiffOk

func IsAnnMinDiffOk(target uint32, packetCryptVersion int) bool

IsAnnMinDiffOk is kind of a sanity check to make sure that the miner doesn't provide "silly" results which might trigger wrong behavior from the diff computation

func IsOk

func IsOk(hash []byte, target uint32) bool

IsOk will return true if the hash is ok given the target number

func Pc2AnnSoftNonceMax

func Pc2AnnSoftNonceMax(target uint32) uint32

func TargetForWork

func TargetForWork(work *big.Int) *big.Int

TargetForWork produces a target to meet based on a desired number of hashes of work to achieve it.

func WorkForTarget

func WorkForTarget(target *big.Int) *big.Int

WorkForTarget calculates an estimated number of hashes which must take place in order to meet a particular target

Types

This section is empty.

Jump to

Keyboard shortcuts

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