Skip to content

Commit

Permalink
refactor(evm): remove evm postprocessing hooks (#1965)
Browse files Browse the repository at this point in the history
* refactor(evm): remove evm postprocessing hooks

* Update CHANGELOG.md
  • Loading branch information
k-yang authored Jul 13, 2024
1 parent fc1edd9 commit a666e08
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 52 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1950](https://github.com/NibiruChain/nibiru/pull/1950) - feat(evm): Tx to create FunToken mapping from ERC20, contract embeds, and ERC20 queries.
- [#1956](https://github.com/NibiruChain/nibiru/pull/1956) - feat(evm): msg to send bank coin to erc20
- [#1958](https://github.com/NibiruChain/nibiru/pull/1958) - chore(evm): wiped deprecated evm apis: miner, personal
- [#1959](https://github.com/NibiruChain/nibiru/pull/1959) - feat(evm): Add precompile to the EVM that enables trasnfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions
- [#1959](https://github.com/NibiruChain/nibiru/pull/1959) - feat(evm): Add precompile to the EVM that enables transfers of ERC20 tokens to "nibi" accounts as regular Ethereum transactions
- [#1960](https://github.com/NibiruChain/nibiru/pull/1960) - test(network): graceful cleanup for more consistent CI runs
- [#1961](https://github.com/NibiruChain/nibiru/pull/1961) - chore(test): reverted funtoken precompile test back to the isolated state
- [#1962](https://github.com/NibiruChain/nibiru/pull/1962) - chore(evm): code cleanup, unused code, typos, styles, warnings
- [#1963](https://github.com/NibiruChain/nibiru/pull/1963) - feat(evm): Deduct a fee during the creation of a FunToken mapping. Implemented by `deductCreateFunTokenFee` inside of the `eth.evm.v1.MsgCreateFunToken` transaction.
- [#1965](https://github.com/NibiruChain/nibiru/pull/1965) - refactor(evm): remove evm post-processing hooks

#### Dapp modules: perp, spot, oracle, etc

Expand Down
13 changes: 0 additions & 13 deletions x/evm/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gethcore "github.com/ethereum/go-ethereum/core"
gethcoretypes "github.com/ethereum/go-ethereum/core/types"
)

// AccountKeeper defines the expected account keeper interface
Expand Down Expand Up @@ -51,14 +49,3 @@ type StakingKeeper interface {
GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool)
GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (validator stakingtypes.Validator, found bool)
}

// EvmHooks: Ethereum transaction processing callbacks/hooks.
type EvmHooks interface {
// PostTxProcessing: Called after default tx processing. If the hook errors,
// the tx is reverted.
PostTxProcessing(
ctx sdk.Context,
msg gethcore.Message,
receipt *gethcoretypes.Receipt,
) error
}
13 changes: 0 additions & 13 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/core"
gethcore "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
gethparams "github.com/ethereum/go-ethereum/params"

Expand Down Expand Up @@ -46,7 +45,6 @@ type Keeper struct {

// Integer for the Ethereum EIP155 Chain ID
// eip155ChainIDInt *big.Int
hooks evm.EvmHooks //nolint:unused
precompiles map[gethcommon.Address]vm.PrecompiledContract //nolint:unused
// tracer: Configures the output type for a geth `vm.EVMLogger`. Tracer types
// include "access_list", "json", "struct", and "markdown". If any other
Expand Down Expand Up @@ -141,14 +139,3 @@ func (k Keeper) Tracer(
) vm.EVMLogger {
return evm.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight())
}

// PostTxProcessing: Called after tx is processed successfully. If it errors,
// the tx will revert.
func (k *Keeper) PostTxProcessing(
ctx sdk.Context, msg core.Message, receipt *gethcore.Receipt,
) error {
if k.hooks == nil {
return nil
}
return k.hooks.PostTxProcessing(ctx, msg, receipt)
}
28 changes: 3 additions & 25 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,7 @@ func (k *Keeper) ApplyEvmTx(
return nil, errors.Wrap(err, "failed to return ethereum transaction as core message")
}

// snapshot to contain the tx processing and post-processing in same scope
var commit func()
tmpCtx := ctx
if k.hooks != nil {
// Create a cache context to revert state when tx hooks fails,
// the cache context is only committed when both tx and hooks executed successfully.
// Didn't use `Snapshot` because the context stack has exponential complexity on certain operations,
// thus restricted to be used only inside `ApplyMessage`.
tmpCtx, commit = ctx.CacheContext()
}
tmpCtx, commit := ctx.CacheContext()

// pass true to commit the StateDB
res, err := k.ApplyEvmMsg(tmpCtx, msg, nil, true, cfg, txConfig)
Expand Down Expand Up @@ -170,21 +161,8 @@ func (k *Keeper) ApplyEvmTx(

if !res.Failed() {
receipt.Status = gethcore.ReceiptStatusSuccessful
// Only call hooks if tx executed successfully.
if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil {
// If hooks return error, revert the whole tx.
res.VmError = evm.ErrPostTxProcessing.Error()
k.Logger(ctx).Error("tx post processing failed", "error", err)

// If the tx failed in post-processing hooks, we should clear the logs
res.Logs = nil
} else if commit != nil {
// PostTxProcessing is successful, commit the tmpCtx
commit()
// Since the post-processing can alter the log, we need to update the result
res.Logs = evm.NewLogsFromEth(receipt.Logs)
ctx.EventManager().EmitEvents(tmpCtx.EventManager().Events())
}
commit()
ctx.EventManager().EmitEvents(tmpCtx.EventManager().Events())
}

// refund gas in order to match the Ethereum gas consumption instead of the default SDK one.
Expand Down

0 comments on commit a666e08

Please sign in to comment.