keeper

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 31 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 {
	// contains filtered or unexported fields
}

Keeper wraps the CommitStateDB, allowing us to pass in SDK context while adhering to the StateDB interface.

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace,
	ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper,
	debug bool,
) *Keeper

NewKeeper generates new evm module keeper

func (Keeper) Account

Account implements the Query/Account gRPC method

func (*Keeper) AddAddressToAccessList

func (k *Keeper) AddAddressToAccessList(addr common.Address)

AddAddressToAccessList adds the given address to the access list. If the address is already in the access list, this function performs a no-op.

func (*Keeper) AddBalance

func (k *Keeper) AddBalance(addr common.Address, amount *big.Int)

AddBalance calls CommitStateDB.AddBalance using the passed in context

func (*Keeper) AddLog

func (k *Keeper) AddLog(log *ethtypes.Log)

AddLog appends the given ethereum Log to the list of Logs associated with the transaction hash kept in the current context. This function also fills in the tx hash, block hash, tx index and log index fields before setting the log to store.

func (*Keeper) AddPreimage

func (k *Keeper) AddPreimage(_ common.Hash, _ []byte)

AddPreimage performs a no-op since the EnablePreimageRecording flag is disabled on the vm.Config during state transitions. No store trie preimages are written to the database.

func (*Keeper) AddRefund

func (k *Keeper) AddRefund(gas uint64)

AddRefund adds the given amount of gas to the refund cached value.

func (*Keeper) AddSlotToAccessList

func (k *Keeper) AddSlotToAccessList(addr common.Address, slot common.Hash)

AddSlotToAccessList adds the given (address, slot) to the access list. If the address and slot are already in the access list, this function performs a no-op.

func (*Keeper) AddressInAccessList

func (k *Keeper) AddressInAccessList(addr common.Address) bool

AddressInAccessList returns true if the address is registered on the transient store.

func (*Keeper) ApplyMessage

func (k *Keeper) ApplyMessage(evm *vm.EVM, msg core.Message, cfg *params.ChainConfig) (*types.MsgEthereumTxResponse, error)

ApplyMessage 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 transaction is never "reverted" since there is no snapshot + rollback performed on the StateDB. Only successful transactions are written to the store during DeliverTx mode.

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)

func (*Keeper) ApplyTransaction

func (k *Keeper) ApplyTransaction(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 to the underlying KVStore if the transaction does not error.

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

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

BeginBlock sets the block hash -> block height map for the previous block height and resets the Bloom filter and the transaction count to 0.

func (Keeper) BlockBloom

BlockBloom implements the Query/BlockBloom gRPC method

func (Keeper) BlockLogs

BlockLogs implements the Query/BlockLogs gRPC method

func (Keeper) ChainConfig

ChainConfig implements the Query/ChainConfig gRPC method

func (Keeper) ChainID

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

ChainID returns the EIP155 chain ID for the EVM context

func (Keeper) ClearBalance

func (k Keeper) ClearBalance(addr sdk.AccAddress) (prevBalance sdk.Coin, err error)

ClearBalance subtracts the EVM all the balance denomination from the address balance while also updating the total supply.

func (Keeper) Code

Code implements the Query/Code gRPC method

func (*Keeper) CreateAccount

func (k *Keeper) CreateAccount(addr common.Address)

CreateAccount creates a new EthAccount instance from the provided address and sets the value to store.

func (Keeper) DeleteAccountStorage

func (k Keeper) DeleteAccountStorage(addr common.Address)

DeleteAccountStorage clears all the storage state associated with the given address.

func (Keeper) DeleteCode

func (k Keeper) DeleteCode(addr common.Address)

DeleteCode removes the contract code byte array from the store associated with the given address.

func (Keeper) DeleteState

func (k Keeper) DeleteState(addr common.Address, key common.Hash)

func (Keeper) DeleteTxLogs

func (k Keeper) DeleteTxLogs(ctx sdk.Context, txHash common.Hash)

DeleteLogs removes the logs from the KVStore. It is used during journal.Revert.

func (*Keeper) Empty

func (k *Keeper) Empty(addr common.Address) bool

Empty returns true if the address meets the following conditions:

  • nonce is 0
  • balance amount for evm denom is 0
  • account code hash is empty

Non-ethereum accounts are considered not empty

func (*Keeper) EndBlock

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

EndBlock updates the accounts and commits state objects to the KV Store, while deleting the empty ones. It also sets the bloom filers for the request block to the store. The EVM end block logic doesn't update the validator set, thus it returns an empty slice.

func (*Keeper) EthereumTx

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

func (*Keeper) Exist

func (k *Keeper) Exist(addr common.Address) bool

Exist returns true if the given account exists in store or if it has been marked as suicided in the transient store.

func (*Keeper) ForEachStorage

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

ForEachStorage calls CommitStateDB.ForEachStorage using passed in context

func (Keeper) GetAccountStorage

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

GetAccountStorage return state storage associated with an account

func (Keeper) GetAllTxLogs

func (k Keeper) GetAllTxLogs(ctx sdk.Context) []types.TransactionLogs

GetAllTxLogs return all the transaction logs from the store.

func (*Keeper) GetBalance

func (k *Keeper) GetBalance(addr common.Address) *big.Int

GetBalance calls CommitStateDB.GetBalance using the passed in context

func (Keeper) GetBlockBloom

func (k Keeper) GetBlockBloom(ctx sdk.Context, height int64) (ethtypes.Bloom, bool)

GetBlockBloom gets bloombits from block height

func (Keeper) GetBlockBloomTransient

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

GetBlockBloomTransient returns bloom bytes for the current block height

func (Keeper) GetChainConfig

func (k Keeper) GetChainConfig(ctx sdk.Context) (types.ChainConfig, bool)

GetChainConfig gets block height from block consensus hash

func (*Keeper) GetCode

func (k *Keeper) GetCode(addr common.Address) []byte

GetCode calls CommitStateDB.GetCode using the passed in context

func (*Keeper) GetCodeHash

func (k *Keeper) GetCodeHash(addr common.Address) common.Hash

GetCodeHash calls CommitStateDB.GetCodeHash using the passed in context

func (*Keeper) GetCodeSize

func (k *Keeper) GetCodeSize(addr common.Address) int

GetCodeSize returns the size of the contract code associated with this object, or zero if none.

func (*Keeper) GetCommittedState

func (k *Keeper) GetCommittedState(addr common.Address, hash common.Hash) common.Hash

GetCommittedState returns the value set in store for the given key hash. If the key is not registered this function returns the empty hash.

func (*Keeper) GetEthIntrinsicGas

func (k *Keeper) GetEthIntrinsicGas(msg core.Message, cfg *params.ChainConfig, isContractCreation bool) (uint64, error)

GetEthIntrinsicGas get the transaction intrinsic gas cost

func (Keeper) GetHashFn

func (k Keeper) GetHashFn() 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) GetNonce

func (k *Keeper) GetNonce(addr common.Address) uint64

GetNonce calls CommitStateDB.GetNonce using the passed in context

func (Keeper) GetParams

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

GetParams returns the total set of evm parameters.

func (*Keeper) GetRefund

func (k *Keeper) GetRefund() uint64

GetRefund returns the amount of gas available for return after the tx execution finalises. This value is reset to 0 on every transaction.

func (*Keeper) GetState

func (k *Keeper) GetState(addr common.Address, hash common.Hash) common.Hash

GetState returns the committed state for the given key hash, as all changes are committed directly to the KVStore.

func (Keeper) GetTxHashTransient

func (k Keeper) GetTxHashTransient() common.Hash

GetTxHashTransient returns the hash of current processing transaction

func (Keeper) GetTxIndexTransient

func (k Keeper) GetTxIndexTransient() uint64

GetTxIndexTransient returns EVM transaction index on the current block.

func (Keeper) GetTxLogs

func (k Keeper) GetTxLogs(txHash common.Hash) []*ethtypes.Log

GetLogs returns the current logs for a given transaction hash from the KVStore. This function returns an empty, non-nil slice if no logs are found.

func (*Keeper) HasSuicided

func (k *Keeper) HasSuicided(addr common.Address) bool

HasSuicided queries the transient store to check if the account has been marked as suicided in the current block. Accounts that are suicided will be returned as non-nil during queries and "cleared" after the block has been committed.

func (Keeper) IncreaseTxIndexTransient

func (k Keeper) IncreaseTxIndexTransient()

IncreaseTxIndexTransient fetches the current EVM tx index from the transient store, increases its value by one and then sets the new index back to the transient store.

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(msg core.Message, config *params.ChainConfig) *vm.EVM

NewEVM generates an ethereum VM from the provided Message fields and the ChainConfig.

func (Keeper) Params

Params implements the Query/Params gRPC method

func (*Keeper) PrepareAccessList

func (k *Keeper) PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses ethtypes.AccessList)

PrepareAccessList handles the preparatory steps for executing a state transition with regards to both EIP-2929 and EIP-2930:

  • Add sender to access list (2929)
  • Add destination to access list (2929)
  • Add precompiles to access list (2929)
  • Add the contents of the optional tx access list (2930)

This method should only be called if Yolov3/Berlin/2929+2930 is applicable at the current number.

func (*Keeper) RefundGas

func (k *Keeper) RefundGas(msg core.Message, leftoverGas uint64) (uint64, error)

RefundGas transfers the leftover gas to the sender of the message, caped to half of the total gas consumed in the transaction. Additionally, the function sets the total gas consumed to the value returned by the EVM execution, thus ignoring the previous intrinsic gas consumed during in the AnteHandler.

func (Keeper) ResetAccount

func (k Keeper) ResetAccount(addr common.Address)

ResetAccount removes the code, storage state and evm denom balance coins stored with the given address.

func (Keeper) ResetRefundTransient

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

ResetRefundTransient resets the available refund amount to 0

func (*Keeper) RevertToSnapshot

func (k *Keeper) RevertToSnapshot(_ int)

RevertToSnapshot performs a no-op because when a transaction execution fails on the EVM, the state won't be persisted during ABCI DeliverTx.

func (Keeper) SetBlockBloom

func (k Keeper) SetBlockBloom(ctx sdk.Context, height int64, bloom ethtypes.Bloom)

SetBlockBloom sets the mapping from block height to bloom bits

func (Keeper) SetBlockBloomTransient

func (k Keeper) SetBlockBloomTransient(bloom *big.Int)

SetBlockBloomTransient sets the given bloom bytes to the transient store. This value is reset on every block.

func (Keeper) SetChainConfig

func (k Keeper) SetChainConfig(ctx sdk.Context, config types.ChainConfig)

SetChainConfig sets the mapping from block consensus hash to block height

func (*Keeper) SetCode

func (k *Keeper) SetCode(addr common.Address, code []byte)

SetCode calls CommitStateDB.SetCode using the passed in context

func (Keeper) SetLogs

func (k Keeper) SetLogs(txHash common.Hash, logs []*ethtypes.Log)

SetLogs sets the logs for a transaction in the KVStore.

func (*Keeper) SetNonce

func (k *Keeper) SetNonce(addr common.Address, nonce uint64)

SetNonce sets the given nonce as the sequence of the address' account. If the account doesn't exist, a new one will be created from the address.

func (Keeper) SetParams

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

SetParams sets the evm parameters to the param space.

func (*Keeper) SetState

func (k *Keeper) SetState(addr common.Address, key, value common.Hash)

SetState sets the given hashes (key, value) to the KVStore. If the value hash is empty, this function deletes the key from the store.

func (Keeper) SetTxHashTransient

func (k Keeper) SetTxHashTransient(hash common.Hash)

SetTxHashTransient set the hash of processing transaction

func (*Keeper) SlotInAccessList

func (k *Keeper) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)

SlotInAccessList checks if the address and the slots are registered in the transient store

func (*Keeper) Snapshot

func (k *Keeper) Snapshot() int

Snapshot return zero as the state changes won't be committed if the state transition fails. So there is no need to snapshot before the VM execution. See Cosmos SDK docs for more info: https://docs.cosmos.network/master/core/baseapp.html#delivertx-state-updates

func (Keeper) StaticCall

StaticCall implements Query/StaticCall gRPCP method

func (Keeper) Storage

Storage implements the Query/Storage gRPC method

func (*Keeper) SubBalance

func (k *Keeper) SubBalance(addr common.Address, amount *big.Int)

SubBalance calls CommitStateDB.SubBalance using the passed in context

func (*Keeper) SubRefund

func (k *Keeper) SubRefund(gas uint64)

SubRefund subtracts the given amount of gas from the refund value. This function will panic if gas amount is greater than the stored refund.

func (*Keeper) Suicide

func (k *Keeper) Suicide(addr common.Address) bool

Suicide marks the given account as suicided and clears the account balance of the EVM tokens.

func (Keeper) TxLogs

TxLogs implements the Query/TxLogs gRPC method

func (Keeper) VMConfig

func (k Keeper) VMConfig() vm.Config

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

func (*Keeper) WithChainID

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

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

func (*Keeper) WithContext

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

WithContext sets an updated SDK context to the keeper

Jump to

Keyboard shortcuts

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