CovenantSQL: github.com/CovenantSQL/CovenantSQL/pow/cpuminer Index | Files

package cpuminer

import "github.com/CovenantSQL/CovenantSQL/pow/cpuminer"

Package cpuminer implements CPU based PoW functions.

Index

Package Files

miner.go uint256.go

Constants

const (
    // Uint256Size is the Uint256 byte size.
    Uint256Size = 8 * 4
)

Variables

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")
)

func HashBlock Uses

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

HashBlock calculate the hash of MiningBlock.

type CPUMiner Uses

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 Uses

func NewCPUMiner(quit chan struct{}) *CPUMiner

NewCPUMiner init A new CPU miner.

func (*CPUMiner) ComputeBlockNonce Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

Uint256FromBytes converts []byte to Uint256.

func (*Uint256) Bytes Uses

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

Bytes converts Uint256 to []byte.

func (*Uint256) Inc Uses

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

Inc makes i = i + 1.

func (*Uint256) MarshalHash Uses

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

MarshalHash marshals for hash.

func (*Uint256) Msgsize Uses

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

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

Package cpuminer imports 6 packages (graph) and is imported by 12 packages. Updated 2019-05-03. Refresh now. Tools for package owners.