processor

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKnownBlock is returned when a block to import is already known locally.
	ErrKnownBlock = errors.New("block already known")

	// ErrUnknownAncestor is returned when validating a block requires an ancestor
	// that is unknown.
	ErrUnknownAncestor = errors.New("unknown ancestor")

	// ErrPrunedAncestor is returned when validating a block requires an ancestor
	// that is known, but the state of which is not available.
	ErrPrunedAncestor = errors.New("pruned 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")

	// ErrNonceTooHigh is returned if the nonce of a transaction is higher than the
	// next one expected based on the local chain.
	ErrNonceTooHigh = errors.New("nonce too high")

	// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
	// one present in the local chain.
	ErrNonceTooLow = errors.New("nonce too low")

	//
	ErrActionInvalid = errors.New("action field invalid")
)

Functions

func ApplyMessage

func ApplyMessage(accountDB *accountmanager.AccountManager, evm *vm.EVM,
	action *types.Action, gp *common.GasPool, gasPrice *big.Int,
	assetID uint64, config *params.ChainConfig, engine EngineContext) ([]byte, uint64, bool, error, error)

ApplyMessage computes the new state by applying the given message against the old state within the environment.

func GetHashFn

func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func NewEVMContext

func NewEVMContext(sender common.Name, to common.Name, assetID uint64, gasPrice *big.Int, header *types.Header, chain *EvmContext, author *common.Name) vm.Context

NewEVMContext creates a new context for use in the EVM.

Types

type BlockValidator

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

BlockValidator is responsible for validating block headers, body and processed state.

BlockValidator implements Validator.

func NewBlockValidator

func NewBlockValidator(blockchain ChainContext, engine consensus.IValidator) *BlockValidator

NewBlockValidator returns a new block validator which is safe for re-use

func (*BlockValidator) ValidateBody

func (v *BlockValidator) ValidateBody(block *types.Block) error

ValidateBody verifies the the block header's transaction roots. The headers are assumed to be already validated at this point.

func (*BlockValidator) ValidateHeader

func (v *BlockValidator) ValidateHeader(header *types.Header, seal bool) error

ValidateHeader checks whether a header conforms to the consensus rules of the stock engine.

func (*BlockValidator) ValidateState

func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts []*types.Receipt, usedGas uint64) error

ValidateState validates the various changes that happen after a state transition, such as amount of used gas, the receipt roots and the state root itself. ValidateState returns a database batch if the validation was a success otherwise nil and an error is returned.

type ChainContext

type ChainContext interface {
	Config() *params.ChainConfig

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

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

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

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

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

	// HasBlockAndState checks if a block and associated state trie is fully present
	// in the database or not, caching it if present.
	HasBlockAndState(hash common.Hash, number uint64) bool

	// HasBlock checks if a block is fully present in the database or not.
	HasBlock(hash common.Hash, number uint64) bool

	// StateAt retrieves a block state from the database by hash.
	StateAt(hash common.Hash) (*state.StateDB, error)

	// WriteBlockWithState writes the block and all associated state to the database.
	WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) (bool, error)

	// CheckForkID checks the validity of forkID
	CheckForkID(header *types.Header) error

	// FillForkID fills the current and next forkID
	FillForkID(header *types.Header, statedb *state.StateDB) error

	// ForkUpdate checks and records the fork information
	ForkUpdate(block *types.Block, statedb *state.StateDB) error
}

ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type EngineContext added in v0.0.13

type EngineContext interface {
	Author(header *types.Header) (common.Name, error)

	ProcessAction(fid uint64, number uint64, chainCfg *params.ChainConfig, state *state.StateDB, action *types.Action) ([]*types.InternalAction, error)

	GetDelegatedByTime(state *state.StateDB, candidate string, timestamp uint64) (stake *big.Int, err error)

	GetEpoch(state *state.StateDB, t uint64, curEpoch uint64) (epoch uint64, time uint64, err error)

	GetActivedCandidateSize(state *state.StateDB, epoch uint64) (size uint64, err error)

	GetActivedCandidate(state *state.StateDB, epoch uint64, index uint64) (name string, stake *big.Int, totalVote *big.Int, counter uint64, actualCounter uint64, replace uint64, isbad bool, err error)

	GetVoterStake(state *state.StateDB, epoch uint64, voter string, candidate string) (stake *big.Int, err error)
}

type EvmContext

type EvmContext struct {
	ChainContext
	EngineContext
}

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New common.Hash
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

type Processor

type Processor interface {
	Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) ([]*types.Receipt, []*types.Log, uint64, error)
	ApplyTransaction(author *common.Name, gp *common.GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error)
}

Processor is an interface for processing blocks using a given initial state.

type StateProcessor

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

StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.

StateProcessor implements Processor.

func NewStateProcessor

func NewStateProcessor(bc ChainContext, engine consensus.IEngine) *StateProcessor

NewStateProcessor initialises a new StateProcessor.

func (*StateProcessor) ApplyTransaction

func (p *StateProcessor) ApplyTransaction(author *common.Name, gp *common.GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error)

ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment. It returns the receipt for the transaction, gas used and an error if the transaction failed, indicating the block was invalid.

func (*StateProcessor) Process

func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) ([]*types.Receipt, []*types.Log, uint64, error)

Process processes the state changes according to the rules by running the transaction messages using the statedb and applying any rewards to both the processor (coinbase) and any included uncles.

Process returns the receipts and logs accumulated during the process and returns the amount of gas that was used in the process. If any of the transactions failed to execute due to insufficient gas it will return an error.

type StateTransition

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

func NewStateTransition

func NewStateTransition(accountDB *accountmanager.AccountManager, evm *vm.EVM,
	action *types.Action, gp *common.GasPool, gasPrice *big.Int, assetID uint64,
	config *params.ChainConfig, engine EngineContext) *StateTransition

NewStateTransition initialises and returns a new state transition object.

func (*StateTransition) TransitionDb

func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bool,
	err error, vmerr error)

TransitionDb will transition the state by applying the current message and returning the result including the the used gas. It returns an error if it failed. An error indicates a consensus issue.

type Validator

type Validator interface {
	// ValidateHeader validates the given header's content.
	ValidateHeader(header *types.Header, seal bool) error

	// ValidateBody validates the given block's content.
	ValidateBody(block *types.Block) error

	// ValidateState validates the given statedb and optionally the receipts and
	// gas used.
	ValidateState(block, parent *types.Block, state *state.StateDB, receipts []*types.Receipt, usedGas uint64) error
}

Validator is an interface which defines the standard for block validation. It is only responsible for validating block contents, as the header validation is done by the specific consensus engines.

Directories

Path Synopsis
vm

Jump to

Keyboard shortcuts

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