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

Bad data may be generated due to error returned during the execution of evm transaction #669

Closed
summerpro opened this issue Dec 22, 2020 · 1 comment

Comments

@summerpro
Copy link
Contributor

summerpro commented Dec 22, 2020

System info: [Include Ethermint commit, operating system name, and other relevant details]

  • development

Steps to reproduce:

  1. An evm transaction is executed, and the evm.Create or evm.Call method is successfully executed, the "storage" data and "code" data in CommitStateDB have been modified.
  2. Function "csdb.Finalise" failed to execute and return error, transaction execution failed
  3. The data set to Store (Keeper) will be rolled back, but the "storage" data and "code" data from CommitStateDB will remain in CommitStateDB.
  4. Then, the problem encountered is Similar to issue667issue668
@summerpro
Copy link
Contributor Author

summerpro commented Dec 29, 2020

solution 1

  • We can create a new snapshot of CommitStateDB before executing the handler. If the handler fails to execute and returns an error, then the Keeper.CommitStateDB will be rolled back to the old state.
// NewHandler returns a handler for Ethermint type messages.
func NewHandler(k Keeper) sdk.Handler {
	return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
		snapshotStateDB := k.CommitStateDB.Copy()
		ctx = ctx.WithEventManager(sdk.NewEventManager())
		switch msg := msg.(type) {
		case types.MsgEthereumTx:
			result, err = handleMsgEthereumTx(ctx, k, msg)
		case types.MsgEthermint:
			result, err = handleMsgEthermint(ctx, k, msg)
		default:
			return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
		}
		if err != nil {
			types.CopyCommitStateDB(snapshotStateDB, k.CommitStateDB)
		}
		return result, err
	}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant