Documentation ¶
Overview ¶
Package cpuminer implements CPU based PoW functions.
Index ¶
Constants ¶
View Source
const (
// Uint256Size is the Uint256 byte size.
Uint256Size = 8 * 4
)
Variables ¶
View Source
var ( // ErrBytesLen is an error type ErrBytesLen = errors.New("byte length should be 32 for Uint256") // ErrEmptyIPv6Addr is an error type ErrEmptyIPv6Addr = errors.New("nil or zero length IPv6") )
Functions ¶
Types ¶
type CPUMiner ¶
type CPUMiner struct {
// contains filtered or unexported fields
}
CPUMiner provides concurrency-safe PoW worker group to solve hash puzzle Inspired by:
"S/Kademlia: A Practicable Approach Towards Secure Key-Based Routing" - Section 4.1. Secure nodeID assignment. - Figure 3. Static (left) and dynamic (right) crypto puzzles for nodeID generation.
func (*CPUMiner) ComputeBlockNonce ¶
func (miner *CPUMiner) ComputeBlockNonce( block MiningBlock, startNonce Uint256, difficulty int, ) (err error)
ComputeBlockNonce find nonce make HashBlock() match the MiningBlock Difficulty from the startNonce if interrupted or stopped highest difficulty nonce will be sent to the NonceCh
HACK(auxten): make calculation parallel.
type MiningBlock ¶
type MiningBlock struct { Data []byte // NonceChan is used to notify the got nonce NonceChan chan NonceInfo // Stop chan is used to stop mining and return the max difficult nonce Stop chan struct{} }
MiningBlock contains Data tobe mined.
type NonceInfo ¶
type NonceInfo struct { Nonce Uint256 Difficulty int Hash hash.Hash // Hash can be used as raw NodeID }
NonceInfo contains nonce and the difficulty to the block.
type Uint256 ¶
type Uint256 struct { A uint64 // Bits 63..0. B uint64 // Bits 127..64. C uint64 // Bits 191..128. D uint64 // Bits 255..192. }
Uint256 is an unsigned 256 bit integer.
func Uint256FromBytes ¶
Uint256FromBytes converts []byte to Uint256.
func (*Uint256) MarshalHash ¶
MarshalHash marshals for hash.
Click to show internal directories.
Click to hide internal directories.