mithash

package
v0.0.0-...-8f2729b Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
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

	//add the new params
	BaseBlockNumber       *big.Int = big.NewInt(3200000)    //for pow+pos block epoch number
	BaseBlockRewardString string   = "12500000000000000000" //for baseBlockReward

)

Mithash proof-of-work protocol constants.

View Source
var (
	// limit for pow+pos
	BaseLimitBalanceNumber *big.Int = big.NewInt(1600000) //the epoch number
	BaselimitPosBalance    *big.Int = big.NewInt(1e+7)    //the first balance limit
	BaselimitSubBalance    *big.Int = big.NewInt(1e+6)    //the minuend
	LastLimitBalance       *big.Int = big.NewInt(1e5)     //the last limitbalance is 100000
)
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 mithash cache and optionally stores it to disk.

func MakeDataset

func MakeDataset(block uint64, dir string)

MakeDataset generates a new mithash 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 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 mithash.

type Mithash

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

Mithash is a consensus engine based on proot-of-work implementing the mithash algorithm.

func New

func New(config Config) *Mithash

New creates a full sized mithash PoW scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Mithash

NewFakeDelayer creates a mithash 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 Mit consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Mithash

NewFakeFailer creates a mithash 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 Mit consensus rules.

func NewFaker

func NewFaker() *Mithash

NewFaker creates a mithash consensus engine with a fake PoW scheme that accepts all blocks' seal as valid, though they still have to conform to the Mit consensus rules.

func NewFullFaker

func NewFullFaker() *Mithash

NewFullFaker creates an mithash consensus engine with a full fake scheme that accepts all blocks as valid, without checking any consensus rules whatsoever.

func NewShared

func NewShared() *Mithash

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

func NewTester

func NewTester() *Mithash

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

func (*Mithash) APIs

func (mithash *Mithash) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC APIs. Currently that is empty.

func (*Mithash) Author

func (mithash *Mithash) 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 (*Mithash) CalcDifficulty

func (mithash *Mithash) 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 (*Mithash) Finalize

func (mithash *Mithash) 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 (*Mithash) Hashrate

func (mithash *Mithash) Hashrate() float64

Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.

func (*Mithash) NewSeal

func (mithash *Mithash) NewSeal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}, stateDb *state.StateDB) (*types.Block, error)

Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.

func (*Mithash) Prepare

func (mithash *Mithash) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the mithash protocol. The changes are done inline.

func (*Mithash) Seal

func (mithash *Mithash) Seal(chain consensus.ChainReader, 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 (*Mithash) SetThreads

func (mithash *Mithash) 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 (*Mithash) Threads

func (mithash *Mithash) Threads() int

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

func (*Mithash) VerifyHeader

func (mithash *Mithash) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules of the stock Mit mithash engine.

func (*Mithash) VerifyHeaders

func (mithash *Mithash) 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 (*Mithash) VerifyPOSPOWSeal

func (mithash *Mithash) VerifyPOSPOWSeal(chain consensus.ChainReader, header *types.Header) error

add the new pos+pow VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.

func (*Mithash) VerifySeal

func (mithash *Mithash) VerifySeal(chain consensus.ChainReader, header *types.Header) error

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

func (*Mithash) VerifyUncles

func (mithash *Mithash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

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

type Mode

type Mode uint

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

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL