ethash

package
v0.0.0-...-4097cb8 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: LGPL-3.0 Imports: 36 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 ErrInvalidDumpMagic = errors.New("invalid dump magic")

Functions

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 SeedHash

func SeedHash(block uint64) []byte

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

func SetWitness

func SetWitness(header *types.BlockHeader, nonce uint64, digest []byte)

func SetWitnessStraight

func SetWitnessStraight(header *types.BlockHeader, nonce BlockNonce, mixDigest common.Hash)

Types

type API

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

API exposes ethash related methods for the RPC interface.

func (*API) GetHashrate

func (api *API) GetHashrate() uint64

GetHashrate returns the current hashrate for local CPU miner and remote miner.

func (*API) GetThreads

func (api *API) GetThreads() int

GetThreads returns the thread number of the miner engine

func (*API) GetWork

func (api *API) GetWork() ([3]string, error)

GetWork returns a work package for external miner.

The work package consists of 3 strings:

result[0] - 32 bytes hex encoded current block header pow-hash
result[1] - 32 bytes hex encoded seed hash used for DAG
result[2] - 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty

func (*API) SubmitHashRate

func (api *API) SubmitHashRate(rate hexutil.Uint64, id common.Hash) bool

SubmitHashrate can be used for remote miners to submit their hash rate. This enables the node to report the combined hash rate of all miners which submit work through this node.

It accepts the miner hash rate and an identifier which must be unique between nodes.

func (*API) SubmitWork

func (api *API) SubmitWork(nonce BlockNonce, hash, digest common.Hash) bool

SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was accepted. Note either an invalid solution, a stale work a non-existent work will return false.

type BlockNonce

type BlockNonce [8]byte

A BlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

func (BlockNonce) MarshalText

func (n BlockNonce) MarshalText() ([]byte, error)

MarshalText encodes n as a hex string with 0x prefix.

func (BlockNonce) Uint64

func (n BlockNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*BlockNonce) UnmarshalText

func (n *BlockNonce) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Config

type Config struct {
	CacheDir       string
	CachesInMem    int
	CachesOnDisk   int
	DatasetDir     string
	DatasetsInMem  int
	DatasetsOnDisk int
	PowMode        Mode
}

Config are the configuration parameters of the ethash.

func GetDefaultConfig

func GetDefaultConfig() Config

type Ethash

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

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

func New

func New(config Config, notify []string, noverify bool) *Ethash

New creates a full sized ethash PoW scheme and starts a background thread for remote mining, also optionally notifying a batch of remote services of new work packages.

func NewTester

func NewTester(notify []string, noverify bool) *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.

func (*Ethash) Close

func (ethash *Ethash) Close() error

Close closes the exit channel to notify all backend threads exiting.

func (*Ethash) GetPrivateKey

func (ethash *Ethash) GetPrivateKey() *ecdsa.PrivateKey

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. Note the returned hashrate includes local hashrate, but also includes the total hashrate of all remote miner.

func (*Ethash) Prepare

func (ethash *Ethash) Prepare(reader consensus.ChainReader, header *types.BlockHeader) error

Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the ethash protocol. The changes are done inline.

func (*Ethash) Seal

func (ethash *Ethash) Seal(reader consensus.ChainReader, block *types.Block, stop <-chan struct{}, results chan<- *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) VerifyHeader

func (ethash *Ethash) VerifyHeader(reader consensus.ChainReader, header *types.BlockHeader) error

VerifyHeader checks whether a header conforms to the consensus rules of the stock Ethereum ethash engine.

func (*Ethash) VerifySeal

func (ethash *Ethash) VerifySeal(reader consensus.ChainReader, header *types.BlockHeader) error

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

type EthashWitness

type EthashWitness struct {
	Nonce     BlockNonce
	MixDigest common.Hash
}

type Mode

type Mode uint

Mode defines the type and amount of PoW verification an ethash engine makes.

const (
	ModeNormal Mode = iota
	ModeTest
)

Jump to

Keyboard shortcuts

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