Documentation ¶
Index ¶
- Variables
- func ApplyMessage(accountDB *accountmanager.AccountManager, evm *vm.EVM, action *types.Action, ...) ([]byte, uint64, bool, error, error)
- func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash
- func NewEVMContext(sender common.Name, assetID uint64, gasPrice *big.Int, header *types.Header, ...) vm.Context
- type BlockValidator
- type ChainContext
- type EgnineContext
- type EvmContext
- type GenesisMismatchError
- type Processor
- type StateProcessor
- type StateTransition
- type Validator
Constants ¶
This section is empty.
Variables ¶
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 EgnineContext) ([]byte, uint64, bool, error, error)
ApplyMessage computes the new state by applying the given message against the old state within the environment.
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.IEngine) *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 // CalcGasLimit computes the gas limit of the next block after parent. CalcGasLimit(parent *types.Block) uint64 // 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 EgnineContext ¶
type EgnineContext interface { // Author retrieves the name 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(header *types.Header) (common.Name, error) ProcessAction(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) GetLatestEpcho(state *state.StateDB) (epcho uint64, err error) GetPrevEpcho(state *state.StateDB, epcho uint64) (pecho uint64, err error) GetActivedCandidateSize(state *state.StateDB, epcho uint64) (size uint64, err error) GetActivedCandidate(state *state.StateDB, epcho uint64, index uint64) (name string, stake *big.Int, counter uint64, actualCounter uint64, replace uint64, err error) GetCandidateStake(state *state.StateDB, epcho uint64, candidate string) (stake *big.Int, err error) GetVoterStake(state *state.StateDB, epcho uint64, voter string, candidate string) (stake *big.Int, err error) }
type EvmContext ¶
type EvmContext struct { ChainContext EgnineContext }
type GenesisMismatchError ¶
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 EgnineContext) *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.