cpuminer

package
v0.0.0-...-020e20f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

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

func HashBlock

func HashBlock(data []byte, nonce Uint256) hash.Hash

HashBlock calculate the hash of MiningBlock.

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 NewCPUMiner

func NewCPUMiner(quit chan struct{}) *CPUMiner

NewCPUMiner init A new CPU miner.

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

func Uint256FromBytes(b []byte) (*Uint256, error)

Uint256FromBytes converts []byte to Uint256.

func (*Uint256) Bytes

func (i *Uint256) Bytes() []byte

Bytes converts Uint256 to []byte.

func (*Uint256) Inc

func (i *Uint256) Inc() (ret *Uint256)

Inc makes i = i + 1.

func (*Uint256) MarshalHash

func (i *Uint256) MarshalHash() (o []byte, err error)

MarshalHash marshals for hash.

func (*Uint256) Msgsize

func (i *Uint256) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message.

Jump to

Keyboard shortcuts

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