Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Roll back CommitStateDB after failing to execute handler in evm module #677

Merged
merged 8 commits into from
Jan 8, 2021
17 changes: 14 additions & 3 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ import (

// NewHandler returns a handler for Ethermint type messages.
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
snapshotStateDB := k.CommitStateDB.Copy()
defer func() {
if r := recover(); r != nil {
k.CommitStateDB = snapshotStateDB
panic(r)
}
}()
summerpro marked this conversation as resolved.
Show resolved Hide resolved
ctx = ctx.WithEventManager(sdk.NewEventManager())
switch msg := msg.(type) {
case types.MsgEthereumTx:
return handleMsgEthereumTx(ctx, k, msg)
result, err = handleMsgEthereumTx(ctx, k, msg)
case types.MsgEthermint:
return handleMsgEthermint(ctx, k, msg)
result, err = handleMsgEthermint(ctx, k, msg)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
}
if err != nil {
k.CommitStateDB = snapshotStateDB
}
return result, err
}
}

Expand Down