Documentation ¶
Overview ¶
Package ethash implements the ethash proof-of-work consensus engine.
Index ¶
- Constants
- Variables
- func CurPowReward(baseReward *big.Int, blockNumber uint64) *big.Int
- func GHash(data []byte) []byte
- func IsInBlocks(hash common.Hash, blocks []*types.Block) bool
- func IsInPreEpoch(hash common.Hash, ancestors []*types.Block) bool
- func IsTopoPrepared(block *types.Block, ancestors []*types.Block, refBlocks []*types.Block) bool
- type Config
- type Ethash
- func (ethash *Ethash) APIs(chain consensus.BlockReader) []rpc.API
- func (ethash *Ethash) Author(header *types.Header) (common.Address, error)
- func (ethash *Ethash) CalcDifficulty(chain consensus.BlockReader, time uint64, parent *types.Header, ...) *big.Int
- func (ethash *Ethash) CalcLastCyclePosSupply(chain consensus.BlockReader, header *types.Header, parent *types.Header, ...) *big.Int
- func (ethash *Ethash) CalcLastCyclePowSupply(chain consensus.BlockReader, header *types.Header, parent *types.Header, ...) *big.Int
- func (ethash *Ethash) CalcTarget(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
- func (ethash *Ethash) CheckSupplies(chain consensus.BlockReader, header *types.Header, parent *types.Header, ...) bool
- func (ethash *Ethash) Finalize(chain consensus.BlockReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (ethash *Ethash) FindInHeaders(header *types.Header, headers []*types.Header) bool
- func (ethash *Ethash) FindInHeadersByNum(blockNum uint64, buf []*types.Header) *types.Header
- func (ethash *Ethash) GetPosMatureTotalSupply(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
- func (ethash *Ethash) GetPowMatureTotalSupply(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
- func (ethash *Ethash) HashimotoforHeader(hash []byte, nonce uint64) []byte
- func (ethash *Ethash) Hashrate() float64
- func (ethash *Ethash) PosWeight(chain consensus.BlockReader, header *types.Header, parent *types.Header, ...) uint32
- func (ethash *Ethash) Prepare(chain consensus.BlockReader, header *types.Header) error
- func (ethash *Ethash) Seal(chain consensus.BlockReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (ethash *Ethash) SetThreads(threads int)
- func (ethash *Ethash) Threads() int
- func (ethash *Ethash) UpdateSupplies(chain consensus.BlockReader, header *types.Header, parent *types.Header, ...)
- func (ethash *Ethash) VerifyHeader(chain consensus.BlockReader, header *types.Header, seal bool, ...) error
- func (ethash *Ethash) VerifyHeaders(chain consensus.BlockReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (ethash *Ethash) VerifySeal(chain consensus.BlockReader, header *types.Header, headers []*types.Header) error
- func (ethash *Ethash) VerifyUncles(chain consensus.BlockReader, block *types.Block) error
- type Mode
Constants ¶
const ( TesterThreads = 1 PowTargetSpacing = 15 DifficultyAdjustCycles = 1 // how many cycles to adjust MinDifficulty = 131072 )
Variables ¶
var ( PulsarBlockReward *big.Int = new(big.Int).Mul(big.NewInt(128), big.NewInt(1e18)) // Block reward in wei for successfully mining a block FrontierBlockReward *big.Int = PulsarBlockReward // Block reward in wei for successfully mining a block ByzantiumBlockReward *big.Int = PulsarBlockReward // Block reward in wei for successfully mining a block upward from Byzantium //InterestRate *big.Int = big.NewInt(100) //InterestRatePrecision *big.Int = big.NewInt(10000000000) FeeRatioPrecision *big.Int = big.NewInt(1000000) PosSupplyLimit *big.Int = new(big.Int).Mul(new(big.Int).SetUint64(128*core.FixedHalveInterval(halveIntervalGoal)*2), big.NewInt(1e18)) // The PosSupplyLimit is equal to PowSupplyLimit PosSupplyN *big.Int = new(big.Int).SetUint64(core.FixedHalveInterval(halveIntervalGoal) * 10) // doubled after about 20 years, so 5% every year PowRewardRatioUncles *big.Int = big.NewInt(3000) PowRewardRatioPrecision *big.Int = big.NewInt(10000) )
Ethash proof-of-work protocol constants.
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
Functions ¶
Types ¶
type Config ¶
type Config struct {
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 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 ¶
func NewTester() *Ethash
NewTester creates a small sized ethash PoW scheme useful only for testing purposes.
func (*Ethash) APIs ¶
func (ethash *Ethash) APIs(chain consensus.BlockReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC APIs. Currently that is empty.
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) CalcLastCyclePosSupply ¶
func (*Ethash) CalcLastCyclePowSupply ¶
func (*Ethash) CalcTarget ¶
func (ethash *Ethash) CalcTarget(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
calculate the pos target.
func (*Ethash) CheckSupplies ¶
func (ethash *Ethash) CheckSupplies(chain consensus.BlockReader, header *types.Header, parent *types.Header, headers []*types.Header) bool
sanity check the supplies in this header
func (*Ethash) Finalize ¶
func (ethash *Ethash) Finalize(chain consensus.BlockReader, 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) FindInHeaders ¶
func (*Ethash) FindInHeadersByNum ¶
func (*Ethash) GetPosMatureTotalSupply ¶
func (ethash *Ethash) GetPosMatureTotalSupply(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
returns the total supply of pos in all previous mature cycles.
func (*Ethash) GetPowMatureTotalSupply ¶
func (ethash *Ethash) GetPowMatureTotalSupply(chain consensus.BlockReader, header *types.Header, headers []*types.Header) *big.Int
returns the total supply of pow in all previous mature cycles.
func (*Ethash) HashimotoforHeader ¶
func (*Ethash) Hashrate ¶
Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.
func (*Ethash) PosWeight ¶
func (ethash *Ethash) PosWeight(chain consensus.BlockReader, header *types.Header, parent *types.Header, headers []*types.Header) uint32
returns the pos weight in a certain cycle.
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.BlockReader, block *types.Block, stop <-chan struct{}) (*types.Block, 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) UpdateSupplies ¶
func (ethash *Ethash) UpdateSupplies(chain consensus.BlockReader, header *types.Header, parent *types.Header, headers []*types.Header)
update the supplies
func (*Ethash) VerifyHeader ¶
func (ethash *Ethash) VerifyHeader(chain consensus.BlockReader, header *types.Header, seal bool, headers []*types.Header) 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.BlockReader, 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 ¶
func (*Ethash) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ethash engine.