rpow

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: GPL-3.0 Imports: 22 Imported by: 6

Documentation

Overview

Package rpow implements the random-proof-of-work consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	CommonDifficulty = big.NewInt(1)
)

Genesis difficulty

View Source
var (
	// Block reward in hui for successfully mining a block upward from Sapphir
	SapphireBlockReward *big.Int = big.NewInt(0).Mul(big.NewInt(1e+18), big.NewInt(15))
)

random-proof-of-work protocol constants.

Functions

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 {
	RpowMode Mode
}

Config are the configuration parameters of the rpow.

type Mode

type Mode uint

Mode defines the type and amount of PoW verification a rpow engine makes.

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

type Rpow

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

Rpow is a consensus engine based on proot-of-work implementing the rpow algorithm.

func New

func New(config Config) *Rpow

New creates a full sized rpow scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Rpow

NewFakeDelayer creates a rpow 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

func NewFakeFailer(fail uint64) *Rpow

NewFakeFailer creates a rpow 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() *Rpow

NewFaker creates a rpow 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 NewFakerUsechain

func NewFakerUsechain(db ethdb.Database) *Rpow

NewFakerUsechain creates a rpow 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() *Rpow

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

func NewFullFakerUse

func NewFullFakerUse(db ethdb.Database) *Rpow

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

func NewTester

func NewTester() *Rpow

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

func NewTesterUse

func NewTesterUse(db ethdb.Database) *Rpow

func (*Rpow) APIs

func (rpow *Rpow) APIs(chain consensus.ChainReader) []rpc.API

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

func (*Rpow) Author

func (rpow *Rpow) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the header's coinbase as the rpow verified author of the block.

func (*Rpow) CalcDifficulty

func (rpow *Rpow) CalcDifficulty(chain consensus.ChainReader, time uint64, header *types.Header, 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 (*Rpow) Finalize

func (rpow *Rpow) 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 (*Rpow) Prepare

func (rpow *Rpow) Prepare(chain consensus.ChainReader, header *types.Header, state *state.StateDB) error

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

func (*Rpow) Seal

func (rpow *Rpow) 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 (*Rpow) SetThreads

func (rpow *Rpow) 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 (*Rpow) Threads

func (rpow *Rpow) Threads() int

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

func (*Rpow) VerifyHeader

func (rpow *Rpow) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool, state *state.StateDB) error

VerifyHeader checks whether a header conforms to the consensus rules of the stock Usechain rpow engine.

func (*Rpow) VerifyHeaders

func (rpow *Rpow) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool, state *state.StateDB) (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 (*Rpow) VerifySeal

func (rpow *Rpow) VerifySeal(chain consensus.ChainReader, header *types.Header) error

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

func (*Rpow) VerifyUncles

func (rpow *Rpow) VerifyUncles(chain consensus.ChainReader, block *types.Block, state *state.StateDB) error

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

Jump to

Keyboard shortcuts

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