core

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-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")

	// ErrBannedHash is returned if a block to import is on the banned list.
	ErrBannedHash = errors.New("banned hash")

	// ErrNoGenesis is returned when there is no Genesis Block.
	ErrNoGenesis = errors.New("genesis not found in chain")
)
View Source
var (
	// 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")

	// 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")

	// ErrNonceMax is returned if the nonce of a transaction sender account has
	// maximum allowed value and would become invalid if incremented.
	ErrNonceMax = errors.New("nonce has max value")

	// ErrGasLimitReached is returned by the gas pool if the amount of gas required
	// by a transaction is higher than what's left in the block.
	ErrGasLimitReached = errors.New("gas limit reached")

	// ErrInsufficientFundsForTransfer is returned if the transaction sender doesn't
	// have enough funds for transfer(topmost call only).
	ErrInsufficientFundsForTransfer = errors.New("insufficient funds for transfer")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")

	// ErrGasUintOverflow is returned when calculating gas usage.
	ErrGasUintOverflow = errors.New("gas uint64 overflow")

	// ErrIntrinsicGas is returned if the transaction is specified to use less gas
	// than required to start the invocation.
	ErrIntrinsicGas = errors.New("intrinsic gas too low")

	// ErrTxTypeNotSupported is returned if a transaction is not supported in the
	// current network configuration.
	ErrTxTypeNotSupported = types.ErrTxTypeNotSupported

	// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
	// transaction with a tip higher than the total fee cap.
	ErrTipAboveFeeCap = errors.New("max priority fee per gas higher than max fee per gas")

	// ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified
	// in the tip field.
	ErrTipVeryHigh = errors.New("max priority fee per gas higher than 2^256-1")

	// ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified
	// in the fee cap field.
	ErrFeeCapVeryHigh = errors.New("max fee per gas higher than 2^256-1")

	// ErrFeeCapTooLow is returned if the transaction fee cap is less than the
	// the base fee of the block.
	ErrFeeCapTooLow = errors.New("max fee per gas less than block base fee")

	// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
	ErrSenderNoEOA = errors.New("sender not an eoa")
)

List of evm-call-message pre-checking errors. All state transition messages will be pre-checked before execution. If any invalidation detected, the corresponding error should be returned which is defined here.

- If the pre-checking happens in the miner, then the transaction won't be packed. - If the pre-checking happens in the block processing procedure, then a "BAD BLOCk" error should be emitted.

View Source
var DefaultTxPoolConfig = TxPoolConfig{}

DefaultTxPoolConfig contains the default configurations for the transaction pool.

View Source
var (
	// ErrOversizedData is returned if the input data of a transaction is greater
	// than some meaningful limit a user might use. This is not a consensus error
	// making the transaction invalid, rather a DOS protection.
	ErrOversizedData = errors.New("oversized data")
)

Functions

func ApplyTransaction

func ApplyTransaction(statedb istate.IStateDB, tx *etypes.Transaction) (*etypes.Receipt, []*ctypes.Event, 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 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 NewEVMTxContext

func NewEVMTxContext(msg Message) vm.TxContext

NewEVMTxContext creates a new transaction context for a single transaction.

func ValidateTx

func ValidateTx(tx *types.Transaction, local bool) error

validateTx checks whether a transaction is valid according to the consensus rules and adheres to some heuristic limits of the local node (price and size).

Types

type ChainContext

type ChainContext struct{}

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

func ApplyMessage(evm *vm.EVM, msg Message, gp *core.GasPool) (*ExecutionResult, error)

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 GasPool

type GasPool uint64

GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

AddGas makes gas available for execution.

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

Gas returns the amount of gas remaining in the pool.

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error

SubGas deducts the given amount from the pool if enough gas is available and returns an error otherwise.

type Message

type Message interface {
	From() common.Address
	To() *common.Address

	GasPrice() *big.Int
	GasFeeCap() *big.Int
	GasTipCap() *big.Int
	Gas() uint64
	Value() *big.Int

	Nonce() uint64
	IsFake() bool
	Data() []byte
	AccessList() types.AccessList
}

Message represents a message sent to a contract.

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

func NewStateTransition(evm *vm.EVM, msg Message, gp *core.GasPool) *StateTransition

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.

type TxPool

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

TxPool contains all currently known transactions. Transactions enter the pool when they are received from the network or submitted locally. They exit the pool when they are included in the blockchain.

The pool separates processable transactions (which can be applied to the current state) and future transactions. Transactions move between those two states over time as they are received and processed.

func NewTxPool

func NewTxPool() *TxPool

NewTxPool creates a new transaction pool to gather, sort and filter inbound transactions from the network.

type TxPoolConfig

type TxPoolConfig struct{}

TxPoolConfig are the configuration parameters of the transaction pool.

Directories

Path Synopsis
Package bloombits implements bloom filtering on batches of data.
Package bloombits implements bloom filtering on batches of data.
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.

Jump to

Keyboard shortcuts

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