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

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
summerpro committed Dec 30, 2020
1 parent 04de4b8 commit d7143b5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ import (
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
snapshotStateDB := k.CommitStateDB.Copy()

// The "recover" code here is used to solve the problem of dirty data
// in CommitStateDB due to insufficient gas.

// The following is a detailed description:
// If the gas is insufficient during the execution of the "handler",
// panic will be thrown from the function "ConsumeGas" and finally
// caught by the function "runTx" from Cosmos. The function "runTx"
// will think that the execution of Msg has failed and the modified
// data in the Store will not take effect.
// The fault is that the modified data in CommitStateDB has not been
// rolled back, resulting in bad data.

// Stacktrace:runTx->runMsgs->handler->...->gaskv.Store.Set->ConsumeGas

// The problem is that when the modified data in the Store does not take
// effect, the data in the modified CommitStateDB is not rolled back,
// they take effect, and dirty data is generated.
// Therefore, the code here specifically deals with this situation.
// See https://github.com/cosmos/ethermint/issues/668 for more information.
defer func() {
if r := recover(); r != nil {
// We first used "k.CommitStateDB = snapshotStateDB" to roll back
// CommitStateDB, but this can only change the CommitStateDB in the
// current Keeper object, tut the Keeper object will be destroyed
// soon, it is not a global variable, so the content pointed to by
// the CommitStateDB pointer can be modified to take effect.
types.CopyCommitStateDB(snapshotStateDB, k.CommitStateDB)
panic(r)
}
Expand Down

0 comments on commit d7143b5

Please sign in to comment.