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 API
- type Config
- type Ethash
- func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API
- func (ethash *Ethash) Author(header *types.Header) (common.Address, error)
- func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (ethash *Ethash) Close() error
- func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (ethash *Ethash) Hashrate() float64
- func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, ...) error
- func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash)
- func (ethash *Ethash) SetThreads(threads int)
- func (ethash *Ethash) Threads() int
- func (ethash *Ethash) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (ethash *Ethash) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Mode
Constants ¶
This section is empty.
Variables ¶
var ( FrontierBlockReward = big.NewInt(0e+18) // Block reward in wei for successfully mining a block ByzantiumBlockReward = big.NewInt(0e+18) // Block reward in wei for successfully mining a block upward from Byzantium ConstantinopleBlockReward = big.NewInt(0e+18) // Block reward in wei for successfully mining a block upward from Constantinople BlockReward2019 = big.NewInt(52) // Block reward in wei for 2019 Premine2019Supply = big.NewInt(9680857) // Premine Reward for 2019 PremineStop = big.NewInt(0) // Stop Allocation of Premine Supply BlockReward2020 = big.NewInt(30) // Block reward 2020 Premine2020Supply = big.NewInt(11350000) // Premine Supply for 2020 BlockReward2021 = big.NewInt(25) // Block reward 2021 Premine2021Supply = big.NewInt(14450000) // Premine Supply for 2021 BlockReward2022 = big.NewInt(21) // Block reward 2022 Premine2022Supply = big.NewInt(15550000) // Premine Supply for 2022 BlockReward2023 = big.NewInt(16) // Block reward 2023 Premine2023Supply = big.NewInt(16650000) // Premine Supply for 2023 BlockReward2024 = big.NewInt(11) // Block reward 2024 Premine2024Supply = big.NewInt(17750000) // Premine Supply for 2024 BlockReward2025 = big.NewInt(11) // Block reward 2025 Premine2025Supply = big.NewInt(18750000) // Premine Supply for 2025 BlockReward2026 = big.NewInt(11) // Block reward 2026 Premine2026Supply = big.NewInt(19750000) // Premine Supply for 2026 BlockReward2027 = big.NewInt(11) // Block reward 2027 Premine2027Supply = big.NewInt(19750000) // Premine Supply for 2027 BlockReward2028 = big.NewInt(11) // Block reward 2028 Premine2028Supply = big.NewInt(19750000) // Premine Supply for 2028 BlockReward2029 = big.NewInt(11) // Block reward 2029 Premine2029Supply = big.NewInt(20750000) // Premine Supply for 2029 BlockReward2030 = big.NewInt(11) // Block reward 2030 Premine2030Supply = big.NewInt(20750000) // Premine Supply for 2030 BlockReward2031 = big.NewInt(11) // Block reward 2031 Premine2031Supply = big.NewInt(20750000) // Premine Supply for 2031 BlockReward2032 = big.NewInt(11) // Block reward 2032 Premine2032Supply = big.NewInt(21750000) // Premine Supply for 2032 BlockReward2033 = big.NewInt(11) // Block reward 2033 Premine2033Supply = big.NewInt(21750000) // Premine Supply for 2033 BlockReward2034 = big.NewInt(11) // Block reward 2034 Premine2034Supply = big.NewInt(21750000) // Premine Supply for 2034 BlockReward2035 = big.NewInt(11) // Block reward 2035 Premine2035Supply = big.NewInt(22750000) // Premine Supply for 2035 BlockReward2036 = big.NewInt(11) // Block reward 2036 Premine2036Supply = big.NewInt(22750000) // Premine Supply for 2036 BlockReward2037 = big.NewInt(11) // Block reward 2037 Premine2037Supply = big.NewInt(22750000) // Premine Supply for 2037 BlockReward2038 = big.NewInt(11) // Block reward 2038 Premine2038Supply = big.NewInt(22750000) // Premine Supply for 2038 BlockReward2039 = big.NewInt(11) // Block reward 2039 Premine2039Supply = big.NewInt(23750000) // Premine Supply for 2039 BlockReward2040 = big.NewInt(11) // Block reward 2040 Premine2040Supply = big.NewInt(25750000) // Premine Supply for 2040 BlockReward2041 = big.NewInt(11) // Block reward 2041 Premine2041Supply = big.NewInt(25750000) // Premine Supply for 2041 BlockReward2042 = big.NewInt(11) // Block reward 2042 Premine2042Supply = big.NewInt(25750000) // Premine Supply for 2042 BlockReward2043 = big.NewInt(11) // Block reward 2043 Premine2043Supply = big.NewInt(25750000) // Premine Supply for 2043 BlockReward2044 = big.NewInt(11) // Block reward 2044 Premine2044Supply = big.NewInt(25750000) // Premine Supply for 2044 BlockReward2045 = big.NewInt(11) // Block reward 2045 Premine2045Supply = big.NewInt(25750000) // Premine Supply for 2045 BlockReward2046 = big.NewInt(11) // Block reward 2046 Premine2046Supply = big.NewInt(25750000) // Premine Supply for 2046 BlockReward2047 = big.NewInt(11) // Block reward 2047 Premine2047Supply = big.NewInt(25750000) // Premine Supply for 2047 BlockReward2048 = big.NewInt(11) // Block reward 2048 Premine2048Supply = big.NewInt(25750000) // Premine Supply for 2048 BlockReward2049 = big.NewInt(11) // Block reward 2049 Premine2049Supply = big.NewInt(25750000) // Premine Supply for 2049 BlockReward2050 = big.NewInt(11) // Block reward 2050 Premine2050Supply = big.NewInt(25750000) // Premine Supply for 2050 BlockReward2051 = big.NewInt(11) // Block reward 2051 Premine2051Supply = big.NewInt(25750000) // Premine Supply for 2051 BlockReward2052 = big.NewInt(11) // Block reward 2052 Premine2052Supply = big.NewInt(25750000) // Premine Supply for 2052 BlockReward2053 = big.NewInt(11) // Block reward 2053 Premine2053Supply = big.NewInt(25750000) // Premine Supply for 2053 BlockReward2054 = big.NewInt(11) // Block reward 2054 Premine2054Supply = big.NewInt(25750000) // Premine Supply for 2054 BlockReward2055 = big.NewInt(11) // Block reward 2055 Premine2055Supply = big.NewInt(25750000) // Premine Supply for 2055 BlockReward2056 = big.NewInt(11) // Block reward 2056 Premine2056Supply = big.NewInt(25750000) // Premine Supply for 2056 BlockReward2057 = big.NewInt(11) // Block reward 2057 Premine2057Supply = big.NewInt(25750000) // Premine Supply for 2057 BlockReward2058 = big.NewInt(11) // Block reward 2058 Premine2058Supply = big.NewInt(25750000) // Premine Supply for 2058 BlockReward2059 = big.NewInt(11) // Block reward 2059 Premine2059Supply = big.NewInt(25750000) // Premine Supply for 2059 BlockReward2060 = big.NewInt(11) // Block reward 2060 Premine2060Supply = big.NewInt(25750000) // Premine Supply for 2060 BlockReward2061 = big.NewInt(11) // Block reward 2061 Premine2061Supply = big.NewInt(25750000) // Premine Supply for 2061 BlockReward2062 = big.NewInt(11) // Block reward 2062 Premine2062Supply = big.NewInt(15750000) // Premine Supply for 2062 BlockRewardEnd = big.NewInt(0) // End Block Reward PremineEnd = big.NewInt(0) // End Premine Supply )
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 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 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 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 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.ChainReader) []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.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 (*Ethash) Finalize ¶
func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
Finalize 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.ChainReader, 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) 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.ChainReader, 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.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 (*Ethash) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.
func (*Ethash) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.