Documentation ¶
Overview ¶
Package ethash implements the ethash proof-of-work consensus engine.
Index ¶
- Variables
- func MakeCache(block uint64, dir string)
- func MakeDataset(block uint64, dir string)
- func SeedHash(block uint64) []byte
- func SetWitness(header *types.BlockHeader, nonce uint64, digest []byte)
- func SetWitnessStraight(header *types.BlockHeader, nonce BlockNonce, mixDigest common.Hash)
- type API
- type BlockNonce
- type Config
- type Ethash
- func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API
- func (ethash *Ethash) Close() error
- func (ethash *Ethash) Hashrate() float64
- func (ethash *Ethash) Prepare(reader consensus.ChainReader, header *types.BlockHeader) error
- func (ethash *Ethash) Seal(reader consensus.ChainReader, block *types.Block, stop <-chan struct{}, ...) error
- func (ethash *Ethash) SetThreads(threads int)
- func (ethash *Ethash) Threads() int
- func (ethash *Ethash) VerifyHeader(reader consensus.ChainReader, header *types.BlockHeader) error
- func (ethash *Ethash) VerifySeal(reader consensus.ChainReader, header *types.BlockHeader) error
- type EthashWitness
- type Mode
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
Functions ¶
func MakeDataset ¶
MakeDataset generates a new ethash dataset and optionally stores it to disk.
func SeedHash ¶
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 ¶
GetHashrate returns the current hashrate for local CPU miner and remote miner.
func (*API) GetThreads ¶
GetThreads returns the thread number of the miner engine
func (*API) GetWork ¶
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 ¶
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 ¶
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 ¶
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) Hashrate ¶
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 ¶
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 ¶
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 }