go-ethereum: github.com/ethereum/go-ethereum/consensus/ethash Index | Files

package ethash

import "github.com/ethereum/go-ethereum/consensus/ethash"

Package ethash implements the ethash proof-of-work consensus engine.

Index

Package Files

algorithm.go api.go consensus.go ethash.go sealer.go

Variables

var (
    FrontierBlockReward       = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
    ByzantiumBlockReward      = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
    ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople

)

Ethash proof-of-work protocol constants.

var ErrInvalidDumpMagic = errors.New("invalid dump magic")

func CalcDifficulty Uses

func CalcDifficulty(config *params.ChainConfig, 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 MakeCache Uses

func MakeCache(block uint64, dir string)

MakeCache generates a new ethash cache and optionally stores it to disk.

func MakeDataset Uses

func MakeDataset(block uint64, dir string)

MakeDataset generates a new ethash dataset and optionally stores it to disk.

func SeedHash Uses

func SeedHash(block uint64) []byte

SeedHash is the seed to use for generating a verification cache and the mining dataset.

type API Uses

type API struct {
    // contains filtered or unexported fields
}

API exposes ethash related methods for the RPC interface.

func (*API) GetHashrate Uses

func (api *API) GetHashrate() uint64

GetHashrate returns the current hashrate for local CPU miner and remote miner.

func (*API) GetWork Uses

func (api *API) GetWork() ([3]string, error)

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 Uses

func (api *API) SubmitHashRate(rate hexutil.Uint64, id common.Hash) bool

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 Uses

func (api *API) SubmitWork(nonce types.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 Config Uses

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 Uses

type Ethash struct {
    // contains filtered or unexported fields
}

Ethash is a consensus engine based on proof-of-work implementing the ethash algorithm.

func New Uses

func New(config Config, notify []string, noverify bool) *Ethash

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 Uses

func NewFakeDelayer(delay time.Duration) *Ethash

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 Uses

func NewFakeFailer(fail uint64) *Ethash

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 Uses

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 Uses

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 Uses

func NewShared() *Ethash

NewShared creates a full sized ethash PoW shared between all requesters running in the same process.

func NewTester Uses

func NewTester(notify []string, noverify bool) *Ethash

NewTester creates a small sized ethash PoW scheme useful only for testing purposes.

func (*Ethash) APIs Uses

func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC APIs.

func (*Ethash) Author Uses

func (ethash *Ethash) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.

func (*Ethash) CalcDifficulty Uses

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) Close Uses

func (ethash *Ethash) Close() error

Close closes the exit channel to notify all backend threads exiting.

func (*Ethash) Finalize Uses

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 Uses

func (ethash *Ethash) Hashrate() float64

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 Uses

func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header) 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 Uses

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) SealHash Uses

func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

func (*Ethash) SetThreads Uses

func (ethash *Ethash) SetThreads(threads int)

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 Uses

func (ethash *Ethash) Threads() int

Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!

func (*Ethash) VerifyHeader Uses

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 Uses

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 Uses

func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.

func (*Ethash) VerifyUncles Uses

func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.

type Mode Uses

type Mode uint

Mode defines the type and amount of PoW verification an ethash engine makes.

const (
    ModeNormal Mode = iota
    ModeShared
    ModeTest
    ModeFake
    ModeFullFake
)

Package ethash imports 38 packages (graph) and is imported by 68 packages. Updated 2018-09-17. Refresh now. Tools for package owners.