Documentation ¶
Overview ¶
Copyright 2019 The multi-geth Authors This file is part of the multi-geth library.
The multi-geth library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The multi-geth library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the multi-geth library. If not, see <http://www.gnu.org/licenses/>.
Package ethash implements the ethash proof-of-work consensus engine.
Index ¶
- Variables
- func CalcDifficulty(config ctypes.ChainConfigurator, time uint64, parent *types.Header) *big.Int
- func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int
- func CalcDifficultyHomesteadU256(time uint64, parent *types.Header) *big.Int
- func CalcEpoch(block uint64, epochLength uint64) uint64
- func CalcEpochLength(block uint64, ecip1099FBlock *uint64) uint64
- func HashimotoFull(dataset []uint32, hash []byte, nonce uint64) ([]byte, []byte)
- func HashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]byte, []byte)
- func MakeCache(block uint64, epochLength uint64, dir string)
- func MakeDataset(block uint64, epochLength uint64, dir string)
- func MakeDifficultyCalculatorU256(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int
- func SeedHash(epoch uint64, epochLength uint64) []byte
- type API
- type Cache
- type Config
- type Ethash
- func New(config Config, notify []string, noverify bool) *Ethash
- func NewFakeDelayer(delay time.Duration) *Ethash
- func NewFakeFailer(fail uint64) *Ethash
- func NewFaker() *Ethash
- func NewFullFaker() *Ethash
- func NewPoissonFaker() *Ethash
- func NewShared() *Ethash
- func NewTester(notify []string, noverify bool) *Ethash
- func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (ethash *Ethash) Author(header *types.Header) (common.Address, error)
- func (ethash *Ethash) Cache(block uint64) *Cache
- func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (ethash *Ethash) Close() error
- func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...)
- func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (ethash *Ethash) Hashrate() float64
- func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash)
- func (ethash *Ethash) SetThreads(threads int)
- func (ethash *Ethash) StopRemoteSealer() error
- func (ethash *Ethash) Threads() int
- func (ethash *Ethash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (ethash *Ethash) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Mode
Constants ¶
This section is empty.
Variables ¶
var DynamicDifficultyCalculator = MakeDifficultyCalculatorU256
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
var FrontierDifficultyCalculator = CalcDifficultyFrontierU256
Exported for fuzzing
var HomesteadDifficultyCalculator = CalcDifficultyHomesteadU256
Functions ¶
func CalcDifficulty ¶
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty.
func CalcDifficultyFrontierU256 ¶
CalcDifficultyFrontierU256 is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty. The calculation uses the Frontier rules.
func CalcDifficultyHomesteadU256 ¶
CalcDifficultyHomesteadU256 is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty. The calculation uses the Homestead rules.
func CalcEpochLength ¶
CalcEpochLength returns the epoch length for a given block number (ECIP-1099)
func HashimotoFull ¶ added in v0.0.6
func HashimotoLight ¶ added in v0.0.2
func MakeDataset ¶
MakeDataset generates a new ethash dataset and optionally stores it to disk.
func MakeDifficultyCalculatorU256 ¶
func MakeDifficultyCalculatorU256(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int
MakeDifficultyCalculatorU256 creates a difficultyCalculator with the given bomb-delay. the difficulty is calculated with Byzantium rules, which differs from Homestead in how uncles affect the calculation
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) 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 result[3] - hex encoded block number
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 ¶
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 Cache ¶ added in v0.0.4
type Cache struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { CacheDir string CachesInMem int CachesOnDisk int CachesLockMmap bool DatasetDir string DatasetsInMem int DatasetsOnDisk int DatasetsLockMmap bool PowMode Mode // When set, notifications sent by the remote sealer will // be block header JSON objects instead of work package arrays. NotifyFull bool Log log.Logger `toml:"-"` // ECIP-1099 ECIP1099Block *uint64 `toml:"-"` }
Config are the configuration parameters of the ethash.
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 NewFakeDelayer ¶
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 ¶
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 NewPoissonFaker ¶
func NewPoissonFaker() *Ethash
NewPoissonFaker creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid, but delays mining by some time based on miner.threads, though they still have to conform to the Ethereum consensus rules.
func NewShared ¶
func NewShared() *Ethash
NewShared creates a full sized ethash PoW shared between all requesters running in the same process.
func NewTester ¶
NewTester creates a small sized ethash PoW scheme useful only for testing purposes.
func (*Ethash) APIs ¶
func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC APIs.
func (*Ethash) Author ¶
Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.
func (*Ethash) CalcDifficulty ¶
func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty.
func (*Ethash) Finalize ¶
func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal)
Finalize implements consensus.Engine, accumulating the block and uncle rewards.
func (*Ethash) FinalizeAndAssemble ¶
func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, withdrawals []*types.Withdrawal) (*types.Block, error)
FinalizeAndAssemble implements consensus.Engine, accumulating the block and uncle rewards, setting the final state and assembling the block.
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 ¶
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(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) 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) StopRemoteSealer ¶
StopRemoteSealer stops the remote sealer
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(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules of the stock Ethereum ethash engine.
func (*Ethash) VerifyHeaders ¶
func (ethash *Ethash) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications.
func (*Ethash) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.