consensus

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockTime = errors.New("timestamp less than or equal parent's timestamp")
	ErrSignature = errors.New("signature is not right")
)
View Source
var (
	// ErrUnknownAncestor is returned when validating a block requires an ancestor
	// that is unknown.
	ErrUnknownAncestor = errors.New("unknown ancestor")

	// ErrFutureBlock is returned when a block's timestamp is in the future according
	// to the current node.
	ErrFutureBlock = errors.New("block in the future")

	// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
	// plus one.
	ErrInvalidNumber = errors.New("invalid block number")
)

Functions

This section is empty.

Types

type ChainReader

type ChainReader interface {
	// Config retrieves the blockchain's chain configuration.
	Config() *params.ChainConfig

	// CurrentHeader retrieves the current header from the local chain.
	CurrentHeader() *block.Header

	// GetHeader retrieves a block header from the database by hash and number.
	GetHeader(hash types.Hash, number uint64) *block.Header

	// GetHeaderByNumber retrieves a block header from the database by number.
	GetHeaderByNumber(number uint64) *block.Header

	// GetHeaderByHash retrieves a block header from the database by its hash.
	GetHeaderByHash(hash types.Hash) *block.Header

	// GetBlock retrieves a block from the database by hash and number.
	GetBlock(hash types.Hash, number uint64) *block.Block
}

ChainReader defines a small collection of methods needed to access the local blockchain during header

type Engine

type Engine interface {
	// Author retrieves the Bchain address of the account that minted the given
	// block, which may be different from the header's coinbase if a consensus
	// engine is based on signatures.
	Author(chain ChainReader, header *block.Header) (types.Address, error)

	// VerifyHeader checks whether a header conforms to the consensus rules of a
	// given engine. Verifying the seal may be done optionally here, or explicitly
	// via the VerifySeal method.
	VerifyHeader(chain ChainReader, header *block.Header, seal bool) 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 (the order is that of
	// the input slice).
	VerifyHeaders(chain ChainReader, headers []*block.Header, seals []bool) (chan<- struct{}, <-chan error)

	// VerifySeal checks whether the crypto seal on a header is valid according to
	// the consensus rules of the given engine.
	VerifySeal(chain ChainReader, header *block.Header) error

	// Prepare initializes the consensus fields of a block header according to the
	// rules of a particular engine. The changes are executed inline.
	Prepare(chain ChainReader, header *block.Header) error

	// Finalize runs any post-transaction state modifications (e.g. block rewards)
	// and assembles the final block.
	// Note: The block header and state database might be updated to reflect any
	// consensus rules that happen at finalization (e.g. block rewards).
	Finalize(chain ChainReader, header *block.Header, state *state.StateDB, txs []*transaction.Transaction, receipts []*transaction.Receipt, sign bool) (*block.Block, error)

	// Seal generates a new block for the given input block with the local blockproducer's
	// seal place on top.
	Seal(chain ChainReader, block *block.Block, stop <-chan struct{}) (*block.Block, error)

	// Incentive generates consensus transaction which only affect block state
	Incentive(producer types.Address, state *state.StateDB, header *block.Header) (*transaction.Transaction, error)
}

Engine is an algorithm agnostic consensus engine.

type Engine_basic

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

func NewBasicEngine

func NewBasicEngine(prv *ecdsa.PrivateKey) *Engine_basic

func (*Engine_basic) Author

func (basic *Engine_basic) Author(chain ChainReader, header *block.Header) (types.Address, error)

func (*Engine_basic) Finalize

func (basic *Engine_basic) Finalize(chain ChainReader, header *block.Header, state *state.StateDB, txs []*transaction.Transaction, receipts []*transaction.Receipt, sign bool) (*block.Block, error)

todo this need interpreter process interpreter need change state

func (*Engine_basic) Incentive

func (basic *Engine_basic) Incentive(producer types.Address, state *state.StateDB, header *block.Header) (*transaction.Transaction, error)

func (*Engine_basic) Prepare

func (basic *Engine_basic) Prepare(chain ChainReader, header *block.Header) error

func (*Engine_basic) Seal

func (basic *Engine_basic) Seal(chain ChainReader, block *block.Block, stop <-chan struct{}) (*block.Block, error)

todo fill header ConsensusData

func (*Engine_basic) SetKey

func (basic *Engine_basic) SetKey(prv *ecdsa.PrivateKey)

func (*Engine_basic) VerifyHeader

func (basic *Engine_basic) VerifyHeader(chain ChainReader, header *block.Header, seal bool) error

func (*Engine_basic) VerifyHeaders

func (basic *Engine_basic) VerifyHeaders(chain ChainReader, headers []*block.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 (*Engine_basic) VerifySeal

func (basic *Engine_basic) VerifySeal(chain ChainReader, header *block.Header) error

todo this need interpreter process ConsensusData

type Engine_empty

type Engine_empty struct {
}

func (*Engine_empty) Author

func (empty *Engine_empty) Author(chain ChainReader, header *block.Header) (types.Address, error)

func (*Engine_empty) Finalize

func (empty *Engine_empty) Finalize(chain ChainReader, header *block.Header, state *state.StateDB, txs []*transaction.Transaction, receipts []*transaction.Receipt, sign bool) (*block.Block, error)

func (*Engine_empty) Incentive

func (empty *Engine_empty) Incentive(producer types.Address, state *state.StateDB, header *block.Header) (*transaction.Transaction, error)

func (*Engine_empty) Prepare

func (empty *Engine_empty) Prepare(chain ChainReader, header *block.Header) error

func (*Engine_empty) Seal

func (empty *Engine_empty) Seal(chain ChainReader, block *block.Block, stop <-chan struct{}) (*block.Block, error)

func (*Engine_empty) VerifyHeader

func (empty *Engine_empty) VerifyHeader(chain ChainReader, header *block.Header, seal bool) error

func (*Engine_empty) VerifyHeaders

func (empty *Engine_empty) VerifyHeaders(chain ChainReader, headers []*block.Header, seals []bool) (chan<- struct{}, <-chan error)

func (*Engine_empty) VerifySeal

func (empty *Engine_empty) VerifySeal(chain ChainReader, header *block.Header) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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