Documentation ¶
Overview ¶
Package ethash implements the ethash proof-of-work consensus engine.
Index ¶
- Variables
- func AccumulateRewards(config *chain.Config, header *types.Header, uncles []*types.Header) (uint256.Int, []uint256.Int)
- func CalcDifficulty(config *chain.Config, time, parentTime uint64, parentDifficulty *big.Int, ...) *big.Int
- func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int
- func CalcDifficultyHomesteadU256(time uint64, parent *types.Header) *big.Int
- func MakeDifficultyCalculatorU256(bombDelay uint64) func(time uint64, parent *types.Header) *big.Int
- func SeedHash(block uint64) []byte
- func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types.Header, ...) error
- type API
- type Ethash
- func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (ethash *Ethash) Author(header *types.Header) (libcommon.Address, error)
- func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time, parentTime uint64, ...) *big.Int
- func (ethash *Ethash) CalculateRewards(config *chain.Config, header *types.Header, uncles []*types.Header, ...) ([]consensus.Reward, error)
- func (ethash *Ethash) Close() error
- func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, ...) (types.Transactions, types.Receipts, types.FlatRequests, error)
- func (ethash *Ethash) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState, ...) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error)
- func (ethash *Ethash) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc
- func (ethash *Ethash) GetTransferFunc() evmtypes.TransferFunc
- func (ethash *Ethash) Hashrate() float64
- func (ethash *Ethash) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header, ...)
- func (ethash *Ethash) IsServiceTransaction(sender libcommon.Address, syscall consensus.SystemCall) bool
- func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.Header, ...) error
- func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.BlockWithReceipts, ...) error
- func (ethash *Ethash) SealHash(header *types.Header) (hash libcommon.Hash)
- func (ethash *Ethash) Type() chain.ConsensusName
- func (ethash *Ethash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (ethash *Ethash) VerifySeal(_ consensus.ChainHeaderReader, header *types.Header) error
- func (ethash *Ethash) VerifyUncle(chain consensus.ChainHeaderReader, header *types.Header, uncle *types.Header, ...) error
- func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
- type FakeEthash
- func (f *FakeEthash) Seal(_ consensus.ChainHeaderReader, blockWithReceipts *types.BlockWithReceipts, ...) error
- func (f *FakeEthash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (f *FakeEthash) VerifySeal(_ consensus.ChainHeaderReader, header *types.Header) error
- func (f *FakeEthash) VerifyUncle(chain consensus.ChainHeaderReader, block *types.Header, uncle *types.Header, ...) error
- func (f *FakeEthash) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
- type FullFakeEthash
Constants ¶
This section is empty.
Variables ¶
var ( FrontierBlockReward = uint256.NewInt(5e+18) // Block reward in wei for successfully mining a block ByzantiumBlockReward = uint256.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium ConstantinopleBlockReward = uint256.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople )
Ethash proof-of-work protocol constants.
var DynamicDifficultyCalculator = makeDifficultyCalculator
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
var FrontierDifficultyCalulator = calcDifficultyFrontier
Exported for fuzzing
var HomesteadDifficultyCalulator = calcDifficultyHomestead
Functions ¶
func AccumulateRewards ¶
func AccumulateRewards(config *chain.Config, header *types.Header, uncles []*types.Header) (uint256.Int, []uint256.Int)
AccumulateRewards returns rewards for a given block. The mining reward consists of the static blockReward plus a reward for each included uncle (if any). Individual uncle rewards are also returned in an array.
func CalcDifficulty ¶
func CalcDifficulty(config *chain.Config, time, parentTime uint64, parentDifficulty *big.Int, parentNumber uint64, parentUncleHash libcommon.Hash) *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 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 MakeDifficultyCalculatorU256 ¶
func MakeDifficultyCalculatorU256(bombDelay uint64) 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
func SeedHash ¶
SeedHash is the seed to use for generating a verification cache and the mining dataset.
func VerifyHeaderBasics ¶
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 Ethash ¶
type Ethash struct {
// contains filtered or unexported fields
}
Ethash is a consensus engine based on proof-of-work implementing the ethash algorithm.
func GetSharedEthash ¶
func GetSharedEthash() *Ethash
sharedEthash is a full instance that can be shared between multiple users.
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 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. This is thread-safe (only access the header.Coinbase)
func (*Ethash) CalcDifficulty ¶
func (ethash *Ethash) CalcDifficulty(chain consensus.ChainHeaderReader, time, parentTime uint64, parentDifficulty *big.Int, parentNumber uint64, _, parentUncleHash libcommon.Hash, _ uint64) *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) CalculateRewards ¶
func (*Ethash) Finalize ¶
func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger, ) (types.Transactions, types.Receipts, types.FlatRequests, error)
Finalize implements consensus.Engine, accumulating the block and uncle rewards, setting the final state on the header
func (*Ethash) FinalizeAndAssemble ¶
func (ethash *Ethash) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger, ) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error)
FinalizeAndAssemble implements consensus.Engine, accumulating the block and uncle rewards, setting the final state and assembling the block.
func (*Ethash) GetPostApplyMessageFunc ¶
func (ethash *Ethash) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc
func (*Ethash) GetTransferFunc ¶
func (ethash *Ethash) GetTransferFunc() evmtypes.TransferFunc
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) Initialize ¶
func (ethash *Ethash) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header, state *state.IntraBlockState, syscall consensus.SysCallCustom, logger log.Logger, tracer *tracing.Hooks)
func (*Ethash) IsServiceTransaction ¶
func (*Ethash) Prepare ¶
func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.Header, state *state.IntraBlockState) 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(chain consensus.ChainHeaderReader, block *types.BlockWithReceipts, results chan<- *types.BlockWithReceipts, stop <-chan struct{}) error
Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.
func (*Ethash) Type ¶
func (ethash *Ethash) Type() chain.ConsensusName
Type returns underlying consensus engine
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) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.
func (*Ethash) VerifyUncle ¶
func (*Ethash) VerifyUncles ¶
func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.
type FakeEthash ¶
type FakeEthash struct { Ethash // contains filtered or unexported fields }
func NewFakeDelayer ¶
func NewFakeDelayer(delay time.Duration) *FakeEthash
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) *FakeEthash
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() *FakeEthash
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 (*FakeEthash) Seal ¶
func (f *FakeEthash) Seal(_ consensus.ChainHeaderReader, blockWithReceipts *types.BlockWithReceipts, results chan<- *types.BlockWithReceipts, stop <-chan struct{}) error
If we're running a fake PoW, simply return a 0 nonce immediately
func (*FakeEthash) VerifyHeader ¶
func (f *FakeEthash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
func (*FakeEthash) VerifySeal ¶
func (f *FakeEthash) VerifySeal(_ consensus.ChainHeaderReader, header *types.Header) error
If we're running a fake PoW, accept any seal as valid
func (*FakeEthash) VerifyUncle ¶
func (*FakeEthash) VerifyUncles ¶
func (f *FakeEthash) VerifyUncles(chain consensus.ChainReader, header *types.Header, uncles []*types.Header) error
type FullFakeEthash ¶
type FullFakeEthash FakeEthash
func NewFullFaker ¶
func NewFullFaker() *FullFakeEthash
NewFullFaker creates an ethash consensus engine with a full fake scheme that accepts all blocks as valid, without checking any consensus rules whatsoever.
func (*FullFakeEthash) VerifyHeader ¶
func (f *FullFakeEthash) VerifyHeader(_ consensus.ChainHeaderReader, _ *types.Header, _ bool) error
If we're running a full engine faking, accept any input as valid
func (*FullFakeEthash) VerifyUncles ¶
func (f *FullFakeEthash) VerifyUncles(_ consensus.ChainReader, _ *types.Header, _ []*types.Header) error