Documentation ¶
Overview ¶
Package ethash implements the ethash proof-of-work consensus engine.
Index ¶
- Variables
- func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int
- func MakeCache(block uint64, dir string)
- func MakeDataset(block uint64, dir string)
- func SeedHash(block uint64) []byte
- type Config
- type Mode
- type Truepow
- func (ethash *Truepow) APIs(chain consensus.ChainReader) []rpc.API
- func (ethash *Truepow) Author(header *types.Header) (common.Address, error)
- func (ethash *Truepow) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (ethash *Truepow) ConSeal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}, ...)
- func (ethash *Truepow) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (ethash *Truepow) Hashrate() float64
- func (ethash *Truepow) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (ethash *Truepow) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (ethash *Truepow) SetThreads(threads int)
- func (ethash *Truepow) Threads() int
- func (ethash *Truepow) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (ethash *Truepow) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (ethash *Truepow) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (ethash *Truepow) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
Constants ¶
This section is empty.
Variables ¶
var ( FrontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium FruitReward *big.Int = big.NewInt(3.333e+16) BlockReward *big.Int = new(big.Int).Mul(big.NewInt(2e+18), big10) FruitBlockRatio *big.Int = big.NewInt(64) // difficulty ratio between fruit and block )
Ethash proof-of-work protocol constants.
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
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 MakeDataset ¶
MakeDataset generates a new ethash dataset and optionally stores it to disk.
Types ¶
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.
type Mode ¶
type Mode uint
Mode defines the type and amount of PoW verification an ethash engine makes.
type Truepow ¶
type Truepow struct {
// contains filtered or unexported fields
}
Truepow is a consensus engine based on proot-of-work implementing the truechain fpow algorithm.
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() *Truepow
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() *Truepow
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() *Truepow
NewShared creates a full sized ethash PoW shared between all requesters running in the same process.
func NewTester ¶
func NewTester() *Truepow
NewTester creates a small sized ethash PoW scheme useful only for testing purposes.
func (*Truepow) APIs ¶
func (ethash *Truepow) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC APIs. Currently that is empty.
func (*Truepow) Author ¶
Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.
func (*Truepow) CalcDifficulty ¶
func (ethash *Truepow) CalcDifficulty(chain consensus.ChainReader, 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 (*Truepow) ConSeal ¶
func (ethash *Truepow) ConSeal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}, send chan *types.Block)
Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.
func (*Truepow) Finalize ¶
func (ethash *Truepow) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, fruits []*types.Block) (*types.Block, error)
Finalize implements consensus.Engine, accumulating the block fruit and uncle rewards, setting the final state and assembling the block.
func (*Truepow) Hashrate ¶
Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.
func (*Truepow) Prepare ¶
Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the ethash protocol. The changes are done inline.
func (*Truepow) 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 (*Truepow) Threads ¶
Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!
func (*Truepow) VerifyHeader ¶
func (ethash *Truepow) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules of the stock Ethereum ethash engine.
func (*Truepow) VerifyHeaders ¶
func (ethash *Truepow) VerifyHeaders(chain consensus.ChainReader, 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 (*Truepow) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.
func (*Truepow) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.