ongash

package
v0.0.0-...-fb1a044 Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// by cici block reward
	InitReward                = big.NewInt(5e+18)
	BaseReward                = big.NewInt(1e+1)
	SetReward                 = BaseReward.Mul(BaseReward, InitReward)
	FrontierBlockReward       = SetReward         // Block reward in wei for successfully mining a block
	ByzantiumBlockReward      = SetReward         // Block reward in wei for successfully mining a block upward from Byzantium
	ConstantinopleBlockReward = SetReward         // Block reward in wei for successfully mining a block upward from Constantinople
	CiCiBlockReward           = big.NewInt(0e+18) // Block reward in wei for successfully mining a block upward from Constantinople

)

Ongash proof-of-work protocol constants.

View Source
var DynamicDifficultyCalculator = makeDifficultyCalculator
View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
View Source
var FrontierDifficultyCalulator = calcDifficultyFrontier

Exported for fuzzing

View Source
var HomesteadDifficultyCalulator = calcDifficultyHomestead

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 CalcDifficultyFrontierU256

func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int

CalcDifficultyFrontierU256 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. The calculation uses the Frontier rules.

func CalcDifficultyHomesteadU256

func CalcDifficultyHomesteadU256(time uint64, parent *types.Header) *big.Int

CalcDifficultyHomesteadU256 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. The calculation uses the Homestead rules.

func MakeCache

func MakeCache(block uint64, dir string)

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

func MakeDataset

func MakeDataset(block uint64, dir string)

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

func MakeDifficultyCalculatorU256

func MakeDifficultyCalculatorU256(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int

MakeDifficultyCalculatorU256 creates a difficultyCalculator with the given bomb-delay. the difficulty is calculated with Byzantium rules, which differs from Homestead in how uncles affect the calculation

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 ongash 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
	CachesLockMmap   bool
	DatasetDir       string
	DatasetsInMem    int
	DatasetsOnDisk   int
	DatasetsLockMmap bool
	PowMode          Mode

	Log log.Logger `toml:"-"`
}

Config are the configuration parameters of the ongash.

type Mode

type Mode uint

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

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

type Ongash

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

Ongash is a consensus engine based on proof-of-work implementing the ongash algorithm.

func New

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

New creates a full sized ongash PoW scheme and starts a background thread for remote mining, also optionally notifying a batch of remote services of new work packages.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Ongash

NewFakeDelayer creates a ongash 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 Orange consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Ongash

NewFakeFailer creates a ongash 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 Orange consensus rules.

func NewFaker

func NewFaker() *Ongash

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

func NewFullFaker

func NewFullFaker() *Ongash

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

func NewShared

func NewShared() *Ongash

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

func NewTester

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

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

func (*Ongash) APIs

func (ongash *Ongash) APIs(chain consensus.ChainHeaderReader) []rpc.API

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

func (*Ongash) Author

func (ongash *Ongash) 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 (*Ongash) CalcDifficulty

func (ongash *Ongash) CalcDifficulty(chain consensus.ChainHeaderReader, 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 (*Ongash) Close

func (ongash *Ongash) Close() error

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

func (*Ongash) Finalize

func (ongash *Ongash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)

Finalize implements consensus.Engine, accumulating the block and uncle rewards, setting the final state on the header

func (*Ongash) FinalizeAndAssemble

func (ongash *Ongash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

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

func (*Ongash) Hashrate

func (ongash *Ongash) 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 (*Ongash) Prepare

func (ongash *Ongash) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error

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

func (*Ongash) Seal

func (ongash *Ongash) Seal(chain consensus.ChainHeaderReader, 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 (*Ongash) SealHash

func (ongash *Ongash) SealHash(header *types.Header) (hash common.Hash)

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

func (*Ongash) SetThreads

func (ongash *Ongash) 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 (*Ongash) Threads

func (ongash *Ongash) Threads() int

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

func (*Ongash) VerifyHeader

func (ongash *Ongash) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error

VerifyHeader checks whonger a header conforms to the consensus rules of the stock Orange ongash engine.

func (*Ongash) VerifyHeaders

func (ongash *Ongash) VerifyHeaders(chain consensus.ChainHeaderReader, 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 (*Ongash) VerifyUncles

func (ongash *Ongash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

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

Jump to

Keyboard shortcuts

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