Documentation ¶
Index ¶
- func ApplyTransaction(config *params.ChainConfig, bc abstract.ChainContext, author *common.Address, ...) (*types.Receipt, error)
- func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool
- func GetHashFn(ref *types.Header, chain abstract.ChainContext) func(n uint64) common.Hash
- func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, ...) (uint64, error)
- func NewEVMBlockContext(header *types.Header, chain abstract.ChainContext, author *common.Address) vm.BlockContext
- func NewEVMTxContext(msg Message) vm.TxContext
- func NewStatePrefetcher(config *params.ChainConfig, bc abstract.ChainContext, engine consensus.Engine) *statePrefetcher
- func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)
- type ExecutionResult
- type Message
- type StateProcessor
- type StateTransition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTransaction ¶
func ApplyTransaction(config *params.ChainConfig, bc abstract.ChainContext, author *common.Address, gp *core.GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, 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 CanTransfer ¶
CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.
func IntrinsicGas ¶
func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, isHomestead, isEIP2028 bool) (uint64, error)
IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func NewEVMBlockContext ¶
func NewEVMBlockContext(header *types.Header, chain abstract.ChainContext, author *common.Address) vm.BlockContext
NewEVMBlockContext creates a new context for use in the EVM.
func NewEVMTxContext ¶
NewEVMTxContext creates a new transaction context for a single transaction.
func NewStatePrefetcher ¶
func NewStatePrefetcher(config *params.ChainConfig, bc abstract.ChainContext, engine consensus.Engine) *statePrefetcher
NewStatePrefetcher initialises a new statePrefetcher.
Types ¶
type ExecutionResult ¶
type ExecutionResult struct { UsedGas uint64 // Total used gas but include the refunded gas Err error // Any error encountered during the execution(listed in core/vm/errors.go) ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode) }
ExecutionResult includes all output after executing given evm message no matter the execution itself is successful or not.
func ApplyMessage ¶
ApplyMessage computes the new state by applying the given message against the old state within the environment.
ApplyMessage returns the bytes returned by any EVM execution (if it took place), the gas used (which includes gas refunds) and an error if it failed. An error always indicates a core error meaning that the message would always fail for that particular state and would never be accepted within a block.
func (*ExecutionResult) Failed ¶
func (result *ExecutionResult) Failed() bool
Failed returns the indicator whether the execution is successful or not
func (*ExecutionResult) Return ¶
func (result *ExecutionResult) Return() []byte
Return is a helper function to help caller distinguish between revert reason and function return. Return returns the data after execution if no error occurs.
func (*ExecutionResult) Revert ¶
func (result *ExecutionResult) Revert() []byte
Revert returns the concrete revert reason if the execution is aborted by `REVERT` opcode. Note the reason can be nil if no data supplied with revert opcode.
func (*ExecutionResult) Unwrap ¶
func (result *ExecutionResult) Unwrap() error
Unwrap returns the internal evm error which allows us for further analysis outside.
type Message ¶
type Message interface { From() common.Address To() *common.Address GasPrice() *big.Int Gas() uint64 Value() *big.Int Nonce() uint64 CheckNonce() bool Data() []byte AccessList() types.AccessList }
Message represents a message sent to a contract.
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(config *params.ChainConfig, bc abstract.ChainProcessor, engine consensus.Engine) *StateProcessor
NewStateProcessor initialises a new StateProcessor.
func (*StateProcessor) Process ¶
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error)
Process processes the state changes according to the Ethereum 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
}
The State Transitioning Model
A state transition is a change made when a transaction is applied to the current world state The state transitioning model does all the necessary work to work out a valid new state root.
1) Nonce handling 2) Pre pay gas 3) Create a new state object if the recipient is \0*32 4) Value transfer == If contract creation ==
4a) Attempt to run transaction data 4b) If valid, use result as code for the new state object
== end == 5) Run Script section 6) Derive new state root
func NewStateTransition ¶
NewStateTransition initialises and returns a new state transition object.
func (*StateTransition) TransitionDb ¶
func (st *StateTransition) TransitionDb() (*ExecutionResult, error)
TransitionDb will transition the state by applying the current message and returning the evm execution result with following fields.
- used gas: total gas used (including gas being refunded)
- returndata: the returned data from evm
- concrete execution error: various **EVM** error which aborts the execution, e.g. ErrOutOfGas, ErrExecutionReverted
However if any consensus issue encountered, return the error directly with nil evm execution result.