gxhash

package
v1.10.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: GPL-3.0 Imports: 30 Imported by: 24

Documentation

Overview

Package gxhash implements the gxhash proof-of-work consensus engine. gxhash is a renamed version of ethash in Ethereum which implements consensus/Engine interface.

gxhash is no longer used in Klaytn except for some test codes which uses gxhash's fakemode.

Index

Constants

This section is empty.

Variables

View Source
var (
	ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in peb for successfully mining a block upward from Byzantium

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

Functions

func CalcBlockScore

func CalcBlockScore(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int

CalcBlockScore is the blockscore adjustment algorithm. It returns the blockscore that a new block should have when created at time given the parent block's time and blockscore.

func MakeCache

func MakeCache(block uint64, dir string)

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

func MakeDataset

func MakeDataset(block uint64, dir string)

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

type Gxhash

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

Gxhash is a consensus engine based on proot-of-work implementing the gxhash algorithm.

func New

func New(config Config) *Gxhash

New creates a full sized gxhash PoW scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Gxhash

NewFakeDelayer creates a gxhash 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 Klaytn consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Gxhash

NewFakeFailer creates a gxhash 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 Klaytn consensus rules.

func NewFaker

func NewFaker() *Gxhash

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

func NewFullFaker

func NewFullFaker() *Gxhash

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

func NewShared

func NewShared() *Gxhash

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

func NewTester

func NewTester() *Gxhash

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

func (*Gxhash) APIs

func (gxhash *Gxhash) APIs(chain consensus.ChainReader) []rpc.API

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

func (*Gxhash) Author

func (gxhash *Gxhash) 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 (*Gxhash) CalcBlockScore

func (gxhash *Gxhash) CalcBlockScore(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int

CalcBlockScore is the blockscore adjustment algorithm. It returns the blockscore that a new block should have when created at time given the parent block's time and blockscore.

func (*Gxhash) CanVerifyHeadersConcurrently added in v1.7.0

func (gxhash *Gxhash) CanVerifyHeadersConcurrently() bool

CanVerifyHeadersConcurrently returns true if concurrent header verification possible, otherwise returns false.

func (*Gxhash) CreateSnapshot added in v1.7.3

func (gxhash *Gxhash) CreateSnapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) error

CreateSnapshot is not used for PoW engine.

func (*Gxhash) Finalize

func (gxhash *Gxhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, accumulating the block rewards, setting the final state and assembling the block.

func (*Gxhash) GetConsensusInfo added in v1.10.0

func (gxhash *Gxhash) GetConsensusInfo(block *types.Block) (consensus.ConsensusInfo, error)

GetConsensusInfo is not used for PoW engine.

func (*Gxhash) Hashrate

func (gxhash *Gxhash) Hashrate() float64

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

func (*Gxhash) Prepare

func (gxhash *Gxhash) Prepare(chain consensus.ChainReader, header *types.Header) error

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

func (*Gxhash) PreprocessHeaderVerification added in v1.7.0

func (gxhash *Gxhash) PreprocessHeaderVerification(headers []*types.Header) (chan<- struct{}, <-chan error)

PreprocessHeaderVerification prepares header verification for heavy computation before synchronous header verification such as ecrecover.

func (*Gxhash) Protocol

func (gxhash *Gxhash) Protocol() consensus.Protocol

Protocol implements consensus.Engine.Protocol

func (*Gxhash) Seal

func (gxhash *Gxhash) 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 blockscore requirements.

func (*Gxhash) SetThreads

func (gxhash *Gxhash) 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 (*Gxhash) Threads

func (gxhash *Gxhash) Threads() int

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

func (*Gxhash) VerifyHeader

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

VerifyHeader checks whether a header conforms to the consensus rules of the stock Klaytn gxhash engine.

func (*Gxhash) VerifyHeaders

func (gxhash *Gxhash) 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 (*Gxhash) VerifySeal

func (gxhash *Gxhash) VerifySeal(chain consensus.ChainReader, header *types.Header) error

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

type Mode

type Mode uint

Mode defines the type and amount of PoW verification an gxhash 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