ethash

package
v2.0.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2019 License: GPL-3.0, LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	FrontierBlockReward       = new(big.Int).Mul(big.NewInt(1e+18), big.NewInt(9028)) // Block reward in wei for successfully mining a block
	ByzantiumBlockReward      = new(big.Int).Mul(big.NewInt(1e+18), big.NewInt(2500)) // Block reward in wei for successfully mining a block upward from Byzantium
	ConstantinopleBlockReward = new(big.Int).Mul(big.NewInt(1e+18), big.NewInt(1000)) // Block reward in wei for successfully mining a block upward from Constantinople

)

Ethash proof-of-work protocol constants.

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

Functions

func CalcDifficulty

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

func MakeCache(block uint64, dir string)

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

func MakeDataset

func MakeDataset(block uint64, dir string)

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

func SeedHash

func SeedHash(block uint64) []byte

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

Types

type API

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

API exposes ethash related methods for the RPC interface.

func (*API) GetHashrate

func (api *API) GetHashrate() uint64

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

func (*API) GetWork

func (api *API) GetWork() ([4]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
result[3] - hex encoded block number

func (*API) SubmitHashRate

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

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

type Config struct {
	CacheDir       string
	CachesInMem    int
	CachesOnDisk   int
	DatasetDir