btcd: github.com/btcsuite/btcd/mining/cpuminer Index | Files

package cpuminer

import "github.com/btcsuite/btcd/mining/cpuminer"

Index

Package Files

cpuminer.go log.go

func DisableLog Uses

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger Uses

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

type CPUMiner Uses

type CPUMiner struct {
    sync.Mutex
    // contains filtered or unexported fields
}

CPUMiner provides facilities for solving blocks (mining) using the CPU in a concurrency-safe manner. It consists of two main goroutines -- a speed monitor and a controller for worker goroutines which generate and solve blocks. The number of goroutines can be set via the SetMaxGoRoutines function, but the default is based on the number of processor cores in the system which is typically sufficient.

func New Uses

func New(cfg *Config) *CPUMiner

New returns a new instance of a CPU miner for the provided configuration. Use Start to begin the mining process. See the documentation for CPUMiner type for more details.

func (*CPUMiner) GenerateNBlocks Uses

func (m *CPUMiner) GenerateNBlocks(n uint32) ([]*chainhash.Hash, error)

GenerateNBlocks generates the requested number of blocks. It is self contained in that it creates block templates and attempts to solve them while detecting when it is performing stale work and reacting accordingly by generating a new block template. When a block is solved, it is submitted. The function returns a list of the hashes of generated blocks.

func (*CPUMiner) HashesPerSecond Uses

func (m *CPUMiner) HashesPerSecond() float64

HashesPerSecond returns the number of hashes per second the mining process is performing. 0 is returned if the miner is not currently running.

This function is safe for concurrent access.

func (*CPUMiner) IsMining Uses

func (m *CPUMiner) IsMining() bool

IsMining returns whether or not the CPU miner has been started and is therefore currenting mining.

This function is safe for concurrent access.

func (*CPUMiner) NumWorkers Uses

func (m *CPUMiner) NumWorkers() int32

NumWorkers returns the number of workers which are running to solve blocks.

This function is safe for concurrent access.

func (*CPUMiner) SetNumWorkers Uses

func (m *CPUMiner) SetNumWorkers(numWorkers int32)

SetNumWorkers sets the number of workers to create which solve blocks. Any negative values will cause a default number of workers to be used which is based on the number of processor cores in the system. A value of 0 will cause all CPU mining to be stopped.

This function is safe for concurrent access.

func (*CPUMiner) Start Uses

func (m *CPUMiner) Start()

Start begins the CPU mining process as well as the speed monitor used to track hashing metrics. Calling this function when the CPU miner has already been started will have no effect.

This function is safe for concurrent access.

func (*CPUMiner) Stop Uses

func (m *CPUMiner) Stop()

Stop gracefully stops the mining process by signalling all workers, and the speed monitor to quit. Calling this function when the CPU miner has not already been started will have no effect.

This function is safe for concurrent access.

type Config Uses

type Config struct {
    // ChainParams identifies which chain parameters the cpu miner is
    // associated with.
    ChainParams *chaincfg.Params

    // BlockTemplateGenerator identifies the instance to use in order to
    // generate block templates that the miner will attempt to solve.
    BlockTemplateGenerator *mining.BlkTmplGenerator

    // MiningAddrs is a list of payment addresses to use for the generated
    // blocks.  Each generated block will randomly choose one of them.
    MiningAddrs []btcutil.Address

    // ProcessBlock defines the function to call with any solved blocks.
    // It typically must run the provided block through the same set of
    // rules and handling as any other block coming from the network.
    ProcessBlock func(*btcutil.Block, blockchain.BehaviorFlags) (bool, error)

    // ConnectedCount defines the function to use to obtain how many other
    // peers the server is connected to.  This is used by the automatic
    // persistent mining routine to determine whether or it should attempt
    // mining.  This is useful because there is no point in mining when not
    // connected to any peers since there would no be anyone to send any
    // found blocks to.
    ConnectedCount func() int32

    // IsCurrent defines the function to use to obtain whether or not the
    // block chain is current.  This is used by the automatic persistent
    // mining routine to determine whether or it should attempt mining.
    // This is useful because there is no point in mining if the chain is
    // not current since any solved blocks would be on a side chain and and
    // up orphaned anyways.
    IsCurrent func() bool
}

Config is a descriptor containing the cpu miner configuration.

Package cpuminer imports 13 packages (graph) and is imported by 52 packages. Updated 2018-10-23. Refresh now. Tools for package owners.