Skip to content

Commit

Permalink
fix: move commit after gas refund calculation so that we can return a…
Browse files Browse the repository at this point in the history
… valid evmResp
  • Loading branch information
k-yang committed Jan 27, 2025
1 parent 9947330 commit 53c1500
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,6 @@ func (k *Keeper) ApplyEvmMsg(
vmError = vmErr.Error()
}

// The dirty states in `StateDB` is either committed or discarded after return
if commit {
if err := evmObj.StateDB.(*statedb.StateDB).Commit(); err != nil {
return nil, errors.Wrap(err, "ApplyEvmMsg: failed to commit stateDB")
}
}

// TODO: UD-DEBUG: Clarify text below.
// GAS REFUND
// If msg.Gas() > gasUsed, we need to refund extra gas.
Expand Down Expand Up @@ -387,6 +380,14 @@ func (k *Keeper) ApplyEvmMsg(
if gasRemaining > msg.Gas() {
return evmResp, errors.Wrapf(core.ErrGasUintOverflow, "ApplyEvmMsg: message gas limit (%d) < leftover gas (%d)", msg.Gas(), gasRemaining)
}

// The dirty states in `StateDB` is either committed or discarded after return
if commit {
if err := evmObj.StateDB.(*statedb.StateDB).Commit(); err != nil {
return evmResp, errors.Wrap(err, "ApplyEvmMsg: failed to commit stateDB")
}
}

return evmResp, nil
}

Expand Down

0 comments on commit 53c1500

Please sign in to comment.