keeper

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

type Keeper struct {
	*evmkeeper.Keeper
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(ek *evmkeeper.Keeper, ak types.AccountKeeper) *Keeper

func (*Keeper) ApplyMessage

func (k *Keeper) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*types.MsgEthereumTxResponse, error)

ApplyMessage calls ApplyMessageWithConfig with default EVMConfig

func (*Keeper) ApplyMessageWithConfig

func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool, cfg *types.EVMConfig, txConfig statedb.TxConfig) (*types.MsgEthereumTxResponse, error)

ApplyMessageWithConfig computes the new state by applying the given message against the existing state. If the message fails, the VM execution error with the reason will be returned to the client and the transaction won't be committed to the store.

Reverted state

The snapshot and rollback are supported by the `statedb.StateDB`.

Different Callers

It's called in three scenarios: 1. `ApplyTransaction`, in the transaction processing flow. 2. `EthCall/EthEstimateGas` grpc query handler. 3. Called by other native modules directly.

Prechecks and Preprocessing

All relevant state transition prechecks for the MsgEthereumTx are performed on the AnteHandler, prior to running the transaction against the state. The prechecks run are the following:

1. the nonce of the message caller is correct 2. caller has enough balance to cover transaction fee(gaslimit * gasprice) 3. the amount of gas required is available in the block 4. the purchased gas is enough to cover intrinsic usage 5. there is no overflow when calculating intrinsic gas 6. caller has enough balance to cover asset transfer for **topmost** call

The preprocessing steps performed by the AnteHandler are:

1. set up the initial access list (iff fork > Berlin)

Tracer parameter

It should be a `vm.Tracer` object or nil, if pass `nil`, it'll create a default one based on keeper options.

Commit parameter

If commit is true, the `StateDB` will be committed, otherwise discarded.

func (*Keeper) ApplyTransaction

func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*types.MsgEthereumTxResponse, error)

ApplyTransaction runs and attempts to perform a state transition with the given transaction (i.e Message), that will only be persisted (committed) to the underlying KVStore if the transaction does not fail.

Gas tracking

Ethereum consumes gas according to the EVM opcodes instead of general reads and writes to store. Because of this, the state transition needs to ignore the SDK gas consumption mechanism defined by the GasKVStore and instead consume the amount of gas used by the VM execution. The amount of gas used is tracked by the EVM and returned in the execution result.

Prior to the execution, the starting tx gas meter is saved and replaced with an infinite gas meter in a new context in order to ignore the SDK gas consumption config values (read, write, has, delete). After the execution, the gas used from the message execution will be added to the starting gas consumed, taking into consideration the amount of gas returned. Finally, the context is updated with the EVM gas consumed value prior to returning.

For relevant discussion see: https://github.com/cosmos/cosmos-sdk/discussions/9072

func (*Keeper) BeginBlock

func (k *Keeper) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock sets the sdk Context and EIP155 chain id to the Keeper.

func (*Keeper) CallEVMWithData

func (k *Keeper) CallEVMWithData(
	ctx sdk.Context,
	from common.Address,
	contract *common.Address,
	data []byte,
	commit bool,
) (*types.MsgEthereumTxResponse, error)

CallEVMWithData performs a smart contract method call using contract data

func (*Keeper) CreateContractWithCode

func (k *Keeper) CreateContractWithCode(ctx sdk.Context, address common.Address, code []byte) error

CreateContractWithCode create contract account and set code

func (*Keeper) EstimateGas

EstimateGas implements eth_estimateGas rpc api.

func (*Keeper) EstimateGasWithoutHook

func (k *Keeper) EstimateGasWithoutHook(c context.Context, req *types.EthCallRequest) (*types.EstimateGasResponse, error)

EstimateGasWithoutHook implements eth_estimateGas rpc api without evm hook.

func (*Keeper) EthCall

EthCall implements eth_call rpc api.

func (*Keeper) EthereumTx

func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error)

EthereumTx implements the gRPC MsgServer interface. It receives a transaction which is then executed (i.e applied) against the go-ethereum EVM. The provided SDK Context is set to the Keeper so that it can implements and call the StateDB methods without receiving it as a function parameter.

func (*Keeper) InitGenesis

func (k *Keeper) InitGenesis(ctx sdk.Context, accountKeeper types.AccountKeeper, data types.GenesisState) []abci.ValidatorUpdate

InitGenesis initializes genesis state based on exported genesis

func (*Keeper) SetAccount

func (k *Keeper) SetAccount(ctx sdk.Context, addr common.Address, account statedb.Account) error

SetAccount updates nonce/balance/codeHash together.

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(eh types.EvmHooks) *Keeper

SetHooks sets the hooks for the EVM module It should be called only once during initialization, it panic if called more than once.

func (*Keeper) TraceTx

TraceTx configures a new tracer according to the provided configuration, and executes the given message in the provided environment. The return value will be tracer dependent.

func (*Keeper) UpdateContractCode

func (k *Keeper) UpdateContractCode(ctx sdk.Context, address common.Address, contractCode []byte) error

UpdateContractCode update contract code and code-hash

type Migrator

type Migrator struct {
	keeper.Migrator
	// contains filtered or unexported fields
}

Migrator is a struct for handling in-place store migrations.

func NewMigrator

func NewMigrator(k *Keeper, legacyAmino *codec.LegacyAmino, paramsStoreKey sdk.StoreKey) Migrator

NewMigrator returns a new Migrator.

func (Migrator) Migrate2to3

func (m Migrator) Migrate2to3(ctx sdk.Context) error

Migrate2to3 migrates the store from consensus version v2 to v3

Jump to

Keyboard shortcuts

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