ethash

package
v0.0.0-...-9b2c719 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

Package ethash implements the ethash proof-of-work consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrInvalidChain const
	ErrInvalidChain = errors.New("invalid header chain")

	//ErrTooManyUncles const
	ErrTooManyUncles = errors.New("too many uncles")

	//ErrDuplicateUncle const
	ErrDuplicateUncle = errors.New("duplicate uncle")

	//ErrUncleIsAncestor const
	ErrUncleIsAncestor = errors.New("uncle is ancestor")

	//ErrDanglingUncle const
	ErrDanglingUncle = errors.New("uncle's parent is not ancestor")

	//ErrNonceOutOfRange const
	ErrNonceOutOfRange = errors.New("nonce out of range")

	//ErrInvalidDifficulty const
	ErrInvalidDifficulty = errors.New("non-positive difficulty")

	//ErrInvalidMixDigest const
	ErrInvalidMixDigest = errors.New("invalid mix digest")

	//ErrInvalidPoW const
	ErrInvalidPoW = errors.New("invalid proof-of-work")
)
View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")

ErrInvalidDumpMagic variable

View Source
var (
	// MaxUint256 is a big integer representing 2^256-1
	MaxUint256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0))
)

Functions

func DefaultDataSetDir

func DefaultDataSetDir() string

DefaultDataSetDir return defaut data set directory

func MakeCache

func MakeCache(block uint64, dir string)

MakeCache generates a new ethash cache and optionally stores it to disk.

func MakeDataset

func MakeDataset(block uint64, dir string)

MakeDataset generates a new ethash dataset and optionally stores it to disk.

func Number

func Number(seedHash common.Hash) (int64, error)

Number is find the block number from epoch with seed hash

func SeedHash

func SeedHash(block uint64) []byte

SeedHash is the seed to use for generating a verification cache and the mining dataset.

Types

type Ethash

type Ethash struct {
	// contains filtered or unexported fields
}

Ethash is a consensus engine based on proot-of-work implementing the ethash algorithm.

func New

func New(cachedir string, cachesinmem, cachesondisk int, dagdir string, dagsinmem, dagsondisk int) *Ethash

New creates a full sized ethash PoW scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Ethash

NewFakeDelayer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid, but delays verifications by some time, though they still have to conform to the Ethereum consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Ethash

NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid apart from the single one specified, though they still have to conform to the Ethereum consensus rules.

func NewFaker

func NewFaker() *Ethash

NewFaker creates a ethash consensus engine with a fake PoW scheme that accepts all blocks' seal as valid, though they still have to conform to the Ethereum consensus rules.

func NewFullFaker

func NewFullFaker() *Ethash

NewFullFaker creates an ethash consensus engine with a full fake scheme that accepts all blocks as valid, without checking any consensus rules whatsoever.

func NewShared

func NewShared() *Ethash

NewShared creates a full sized ethash PoW shared between all requesters running in the same process.

func NewTester

func NewTester() *Ethash

NewTester creates a small sized ethash PoW scheme useful only for testing purposes.

func (*Ethash) APIs

func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC APIs. Currently that is empty.

func (*Ethash) Hashrate

func (ethash *Ethash) Hashrate() float64

Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.

func (*Ethash) Seal

func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.

func (*Ethash) SetThreads

func (ethash *Ethash) SetThreads(threads int)

SetThreads updates the number of mining threads currently enabled. Calling this method does not start mining, only sets the thread count. If zero is specified, the miner will use all cores of the machine. Setting a thread count below zero is allowed and will cause the miner to idle, without any work being done.

func (*Ethash) Threads

func (ethash *Ethash) Threads() int

Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!

func (*Ethash) Verify

func (ethash *Ethash) Verify(header *types.Header) error

Verify implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.

type OpenCLDevice

type OpenCLDevice struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

OpenCLDevice struct

type OpenCLMiner

type OpenCLMiner struct {
	sync.RWMutex

	Work *Work

	SolutionsHashRate metrics.Meter
	FoundSolutions    metrics.Histogram
	RejectedSolutions metrics.Counter
	InvalidSolutions  metrics.Counter
	// contains filtered or unexported fields
}

OpenCLMiner struct

func NewCL

func NewCL(deviceIds []int, workerName string, binary bool, version string) *OpenCLMiner

NewCL func

func (*OpenCLMiner) ChangeDAGOnAllDevices

func (c *OpenCLMiner) ChangeDAGOnAllDevices() (err error)

ChangeDAGOnAllDevices generate dag on all devices

func (*OpenCLMiner) CmpDagSize

func (c *OpenCLMiner) CmpDagSize(work *Work) bool

CmpDagSize based on block number

func (*OpenCLMiner) Destroy

func (c *OpenCLMiner) Destroy()

Destroy miner

func (*OpenCLMiner) GetFanPercent

func (c *OpenCLMiner) GetFanPercent(deviceID int) float64

GetFanPercent for device

func (*OpenCLMiner) GetHashrate

func (c *OpenCLMiner) GetHashrate(deviceID int) float64

GetHashrate for device

func (*OpenCLMiner) GetTemperature

func (c *OpenCLMiner) GetTemperature(deviceID int) float64

GetTemperature for device

func (*OpenCLMiner) InitCL

func (c *OpenCLMiner) InitCL() error

InitCL func

func (*OpenCLMiner) LowMemDevice

func (c *OpenCLMiner) LowMemDevice() bool

LowMemDevice looking low mem devices

func (*OpenCLMiner) MarshalJSON

func (c *OpenCLMiner) MarshalJSON() ([]byte, error)

MarshalJSON for json encoding

func (*OpenCLMiner) Poll

func (c *OpenCLMiner) Poll()

Poll get some useful data from devices

func (*OpenCLMiner) Release

func (c *OpenCLMiner) Release(deviceID int)

Release selected device

func (*OpenCLMiner) ReleaseAll

func (c *OpenCLMiner) ReleaseAll()

ReleaseAll device

func (*OpenCLMiner) Resume

func (c *OpenCLMiner) Resume()

Resume mining

func (*OpenCLMiner) Seal

func (c *OpenCLMiner) Seal(stop <-chan struct{}, deviceID int, onSolutionFound func(common.Hash, uint64, []byte, uint64)) error

Seal hashes on GPU

func (*OpenCLMiner) SetEngineClock

func (c *OpenCLMiner) SetEngineClock(values []int)

SetEngineClock set engine clock for selected devices

func (*OpenCLMiner) SetFanPercent

func (c *OpenCLMiner) SetFanPercent(percents []int)

SetFanPercent set fan speed percent for selected devices

func (*OpenCLMiner) SetIntensity

func (c *OpenCLMiner) SetIntensity(values []int)

SetIntensity for each device

func (*OpenCLMiner) SetKernel

func (c *OpenCLMiner) SetKernel(values []int)

SetKernel for each device

func (*OpenCLMiner) SetMemoryClock

func (c *OpenCLMiner) SetMemoryClock(values []int)

SetMemoryClock set memory clock for selected devices

func (*OpenCLMiner) TotalHashRate

func (c *OpenCLMiner) TotalHashRate() (total float64)

TotalHashRate on all GPUs

func (*OpenCLMiner) TotalHashRate1

func (c *OpenCLMiner) TotalHashRate1() (total float64)

TotalHashRate1 on all GPUs

func (*OpenCLMiner) TotalHashRateMean

func (c *OpenCLMiner) TotalHashRateMean() float64

TotalHashRateMean on all GPUs

func (*OpenCLMiner) WorkChanged

func (c *OpenCLMiner) WorkChanged()

WorkChanged function

type Work

type Work struct {
	BlockNumber *big.Int

	HeaderHash common.Hash
	SeedHash   common.Hash

	Target256   *big.Int
	MinerTarget *big.Int

	FixedDifficulty bool

	ExtraNonce uint64
	SizeBits   int

	Time time.Time
}

Work struct

func NewWork

func NewWork(number int64, hh, sh common.Hash, target *big.Int, fixedDiff bool) *Work

NewWork func

func (*Work) BlockNumberU64

func (w *Work) BlockNumberU64() uint64

BlockNumberU64 func

func (*Work) Difficulty

func (w *Work) Difficulty() *big.Int

Difficulty calc

func (*Work) MarshalJSON

func (w *Work) MarshalJSON() ([]byte, error)

MarshalJSON for json encoding

func (*Work) MinerDifficulty

func (w *Work) MinerDifficulty() *big.Int

MinerDifficulty calc

Directories

Path Synopsis
Code generated by go-bindata.
Code generated by go-bindata.
Code generated by go-bindata.
Code generated by go-bindata.

Jump to

Keyboard shortcuts

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