keeper

package
v12.3.0-cosmos47 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: LGPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSenderBalance

func CheckSenderBalance(
	balance sdkmath.Int,
	txData evmtypes.TxData,
) error

CheckSenderBalance validates that the tx cost value is positive and that the sender has enough funds to pay for the fees and value of the transaction.

func GasToRefund

func GasToRefund(availableRefund, gasConsumed, refundQuotient uint64) uint64

GasToRefund calculates the amount of gas the state machine should refund to the sender. It is capped by the refund quotient value. Note: do not pass 0 to refundQuotient

func GetProposerAddress

func GetProposerAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) sdk.ConsAddress

GetProposerAddress returns current block proposer's address when provided proposer address is empty.

func VerifyFee

func VerifyFee(
	txData evmtypes.TxData,
	denom string,
	baseFee *big.Int,
	homestead, istanbul, isCheckTx bool,
) (sdk.Coins, error)

VerifyFee is used to return the fee for the given transaction data in sdk.Coins. It checks that the gas limit is not reached, the gas limit is higher than the intrinsic gas and that the base fee is higher than the gas fee cap.

Types

type Keeper

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

Keeper grants access to the EVM module state and implements the go-ethereum StateDB interface.

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey, transientKey storetypes.StoreKey,
	authority sdk.AccAddress,
	ak evmtypes.AccountKeeper,
	bankKeeper evmtypes.BankKeeper,
	sk evmtypes.StakingKeeper,
	fmk evmtypes.FeeMarketKeeper,
	tracer string,
	ss paramstypes.Subspace,
) *Keeper

NewKeeper generates new evm module keeper

func (Keeper) Account

Account implements the Query/Account gRPC method

func (*Keeper) ApplyMessage

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

ApplyMessage calls ApplyMessageWithConfig with an empty TxConfig.

func (*Keeper) ApplyMessageWithConfig

func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
	msg core.Message,
	tracer vm.EVMLogger,
	commit bool,
	cfg *statedb.EVMConfig,
	txConfig statedb.TxConfig,
) (*evmtypes.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) (*evmtypes.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) Balance

Balance implements the Query/Balance gRPC method

func (Keeper) BaseFee

BaseFee implements the Query/BaseFee gRPC method

func (*Keeper) BeginBlock

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

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

func (Keeper) ChainID

func (k Keeper) ChainID() *big.Int

ChainID returns the EIP155 chain ID for the EVM context

func (Keeper) Code

Code implements the Query/Code gRPC method

func (*Keeper) DeductTxCostsFromUserBalance

func (k *Keeper) DeductTxCostsFromUserBalance(
	ctx sdk.Context,
	fees sdk.Coins,
	from common.Address,
) error

DeductTxCostsFromUserBalance deducts the fees from the user balance. Returns an error if the specified sender address does not exist or the account balance is not sufficient.

func (*Keeper) DeleteAccount

func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error

DeleteAccount handles contract's suicide call: - clear balance - remove code - remove states - remove auth account

func (*Keeper) DeleteCodeHash

func (k *Keeper) DeleteCodeHash(ctx sdk.Context, addr []byte)

DeleteCodeHash delete the code hash for the given address.

func (*Keeper) EVMConfig

func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, chainID *big.Int) (*statedb.EVMConfig, error)

EVMConfig creates the EVMConfig based on current state

func (Keeper) EmitBlockBloomEvent

func (k Keeper) EmitBlockBloomEvent(ctx sdk.Context, bloom ethtypes.Bloom)

EmitBlockBloomEvent emit block bloom events

func (*Keeper) EndBlock

func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate

EndBlock also retrieves the bloom filter value from the transient store and commits it to the KVStore. The EVM end block logic doesn't update the validator set, thus it returns an empty slice.

func (Keeper) EstimateGas

EstimateGas implements eth_estimateGas rpc api.

func (Keeper) EthCall

EthCall implements eth_call rpc api.

func (*Keeper) EthereumTx

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) ForEachStorage

func (k *Keeper) ForEachStorage(ctx sdk.Context, addr common.Address, cb func(key, value common.Hash) bool)

ForEachStorage iterate contract storage, callback return false to break early

func (*Keeper) GetAccount

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

GetAccount returns nil if account is not exist

func (*Keeper) GetAccountOrEmpty

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

GetAccountOrEmpty returns empty account if not exist

func (Keeper) GetAccountStorage

func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) evmtypes.Storage

GetAccountStorage return state storage associated with an account

func (*Keeper) GetAccountWithoutBalance

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

GetAccountWithoutBalance load nonce and codehash without balance, more efficient in cases where balance is not needed.

func (Keeper) GetAuthority

func (k Keeper) GetAuthority() sdk.AccAddress

GetAuthority returns the x/evm module authority address

func (*Keeper) GetBalance

func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int

GetBalance load account's balance of gas token

func (Keeper) GetBaseFee

func (k Keeper) GetBaseFee(ctx sdk.Context, ethCfg *ethparams.ChainConfig) *big.Int

GetBaseFee returns current base fee, return values: - `nil`: london hardfork not enabled. - `0`: london hardfork enabled but feemarket is not enabled. - `n`: both london hardfork and feemarket are enabled.

func (Keeper) GetChainConfig

func (k Keeper) GetChainConfig(ctx sdk.Context) *ethparams.ChainConfig

func (*Keeper) GetCode

func (k *Keeper) GetCode(ctx sdk.Context, codeHash common.Hash) []byte

GetCode loads contract code from database, implements `statedb.Keeper` interface.

func (*Keeper) GetCodeHash

func (k *Keeper) GetCodeHash(ctx sdk.Context, addr []byte) common.Hash

GetCodeHash returns the code hash for the corresponding account address.

func (Keeper) GetCoinbaseAddress

func (k Keeper) GetCoinbaseAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) (common.Address, error)

GetCoinbaseAddress returns the block proposer's validator operator address.

func (Keeper) GetCumulativeLogCountTransient

func (k Keeper) GetCumulativeLogCountTransient(ctx sdk.Context, exceptCurrent bool) uint64

GetCumulativeLogCountTransient returns the total log count for all transactions in the current block.

func (*Keeper) GetEthIntrinsicGas

func (k *Keeper) GetEthIntrinsicGas(ctx sdk.Context, msg core.Message, cfg *ethparams.ChainConfig, isContractCreation bool) (uint64, error)

GetEthIntrinsicGas returns the intrinsic gas cost for the transaction

func (Keeper) GetGasUsedForTdxIndexTransient

func (k Keeper) GetGasUsedForTdxIndexTransient(ctx sdk.Context, txIdx uint64) uint64

GetGasUsedForTdxIndexTransient returns gas used for tx by index from the transient store.

func (Keeper) GetHashFn

func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc

GetHashFn implements vm.GetHashFunc for Ethermint. It handles 3 cases:

  1. The requested height matches the current height from context (and thus same epoch number)
  2. The requested height is from an previous height from the same chain epoch
  3. The requested height is from a height greater than the latest one

func (Keeper) GetLogCountForTdxIndexTransient

func (k Keeper) GetLogCountForTdxIndexTransient(ctx sdk.Context, txIdx uint64) uint64

GetLogCountForTdxIndexTransient returns log count for tx by index from the transient store.

func (*Keeper) GetNonce

func (k *Keeper) GetNonce(ctx sdk.Context, addr common.Address) uint64

GetNonce returns the sequence number of an account, returns 0 if not exists.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params evmtypes.Params)

GetParams returns the total set of evm parameters.

func (Keeper) GetRawTxCountTransient

func (k Keeper) GetRawTxCountTransient(ctx sdk.Context) uint64

GetRawTxCountTransient returns the raw count of transaction being processed in the current block.

func (*Keeper) GetState

func (k *Keeper) GetState(ctx sdk.Context, addr common.Address, key common.Hash) common.Hash

GetState loads contract state from database, implements `statedb.Keeper` interface.

func (Keeper) GetTxCountTransient

func (k Keeper) GetTxCountTransient(ctx sdk.Context) uint64

GetTxCountTransient returns the count of transaction being processed in the current block. Notice: if not set, it returns 1

func (Keeper) GetTxReceiptsTransient

func (k Keeper) GetTxReceiptsTransient(ctx sdk.Context) (receipts ethtypes.Receipts)

GetTxReceiptsTransient returns the receipts for all transactions in the current block.

func (Keeper) IncreaseTxCountTransient

func (k Keeper) IncreaseTxCountTransient(ctx sdk.Context)

IncreaseTxCountTransient increase the count of transaction being processed in the current block

func (Keeper) IterateContracts

func (k Keeper) IterateContracts(ctx sdk.Context, callback func(addr common.Address, codeHash common.Hash) (stop bool))

IterateContracts iterating through all code hash, represents for all smart contracts

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (*Keeper) NewEVM

func (k *Keeper) NewEVM(
	ctx sdk.Context,
	msg core.Message,
	cfg *statedb.EVMConfig,
	tracer vm.EVMLogger,
	stateDB vm.StateDB,
) *vm.EVM

func (Keeper) Params

Params implements the Query/Params gRPC method

func (*Keeper) ResetGasMeterAndConsumeGas

func (k *Keeper) ResetGasMeterAndConsumeGas(ctx sdk.Context, gasUsed uint64)

ResetGasMeterAndConsumeGas reset first the gas meter consumed value to zero and set it back to the new value 'gasUsed'

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) SetBalance

func (k *Keeper) SetBalance(ctx sdk.Context, addr common.Address, amount *big.Int) error

SetBalance update account's balance, compare with current balance first, then decide to mint or burn.

func (*Keeper) SetCode

func (k *Keeper) SetCode(ctx sdk.Context, codeHash, code []byte)

SetCode set contract code, delete if code is empty.

func (*Keeper) SetCodeHash

func (k *Keeper) SetCodeHash(ctx sdk.Context, addr common.Address, codeHash common.Hash)

SetCodeHash sets the code hash for the given address.

func (Keeper) SetGasUsedForCurrentTxTransient

func (k Keeper) SetGasUsedForCurrentTxTransient(ctx sdk.Context, gas uint64)

SetGasUsedForCurrentTxTransient sets the gas used for the current transaction in the transient store, based on the transient tx counter.

func (Keeper) SetLogCountForCurrentTxTransient

func (k Keeper) SetLogCountForCurrentTxTransient(ctx sdk.Context, count uint64)

SetLogCountForCurrentTxTransient sets the log count for the current transaction in the transient store, based on the transient tx counter.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params evmtypes.Params) error

SetParams sets the EVM params each in their individual key for better get performance

func (*Keeper) SetState

func (k *Keeper) SetState(ctx sdk.Context, addr common.Address, key common.Hash, value []byte)

SetState update contract storage, delete if value is empty.

func (Keeper) SetTxReceiptForCurrentTxTransient

func (k Keeper) SetTxReceiptForCurrentTxTransient(ctx sdk.Context, receiptBz []byte)

SetTxReceiptForCurrentTxTransient sets the receipt for the current transaction in the transient store.

func (Keeper) SetupExecutionContext

func (k Keeper) SetupExecutionContext(ctx sdk.Context, txGas uint64, txType uint8) sdk.Context

SetupExecutionContext setups the execution context for the EVM transaction execution:

  • Use zero gas config
  • Increase the count of transaction being processed in the current block
  • Set the gas used for the current transaction, assume tx failed so gas used = tx gas
  • Set the failed receipt for the current transaction, assume tx failed

func (Keeper) Storage

Storage implements the Query/Storage gRPC method

func (Keeper) TraceBlock

TraceBlock configures a new tracer according to the provided configuration, and executes the given message in the provided environment for all the transactions in the queried block. The return value will be tracer dependent.

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) Tracer

func (k Keeper) Tracer(ctx sdk.Context, msg core.Message, ethCfg *ethparams.ChainConfig) vm.EVMLogger

Tracer return a default vm.Tracer based on current keeper state

func (*Keeper) TxConfig

func (k *Keeper) TxConfig(ctx sdk.Context, txHash common.Hash) statedb.TxConfig

TxConfig loads `TxConfig` from current transient storage

func (*Keeper) UpdateParams

UpdateParams implements the gRPC MsgServer interface. When an UpdateParams proposal passes, it updates the module parameters. The update can only be performed if the requested authority is the Cosmos SDK governance module account.

func (Keeper) VMConfig

func (k Keeper) VMConfig(ctx sdk.Context, _ core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger) vm.Config

VMConfig creates an EVM configuration from the debug setting and the extra EIPs enabled on the module parameters. The config generated uses the default JumpTable from the EVM.

func (Keeper) ValidatorAccount

ValidatorAccount implements the Query/Balance gRPC method

func (*Keeper) WithChainID

func (k *Keeper) WithChainID(ctx sdk.Context)

WithChainID sets the chain id to the local variable in the keeper

type Migrator

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

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

func NewMigrator

func NewMigrator(keeper Keeper, legacySubspace evmtypes.Subspace) Migrator

NewMigrator returns a new Migrator.

func (Migrator) NoOpMigrate

func (m Migrator) NoOpMigrate(_ sdk.Context) error

Jump to

Keyboard shortcuts

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