forked from cerc-io/laconicd-deprecated
fix: don't revert gas refund logic when transaction reverted (#751)
* fix gas consumption when reverted Apply suggestions from code review changelog * comments * Update x/evm/keeper/state_transition.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
Federico Kunze Küllmer
parent
e96a4b9f9d
commit
b7e8dd8216
@@ -218,12 +218,6 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
|
||||
return nil, stacktrace.Propagate(err, "failed to apply ethereum core message")
|
||||
}
|
||||
|
||||
// refund gas prior to handling the vm error in order to match the Ethereum gas consumption instead of the default SDK one.
|
||||
err = k.RefundGas(msg, msg.Gas()-res.GasUsed, cfg.Params.EvmDenom)
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "failed to refund gas leftover gas to sender %s", msg.From())
|
||||
}
|
||||
|
||||
res.Hash = txHash.Hex()
|
||||
|
||||
logs := k.GetTxLogsTransient(txHash)
|
||||
@@ -241,6 +235,14 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
|
||||
}
|
||||
}
|
||||
|
||||
// change to original context
|
||||
k.WithContext(ctx)
|
||||
|
||||
// refund gas according to Ethereum gas accounting rules.
|
||||
if err := k.RefundGas(msg, msg.Gas()-res.GasUsed, cfg.Params.EvmDenom); err != nil {
|
||||
return nil, stacktrace.Propagate(err, "failed to refund gas leftover gas to sender %s", msg.From())
|
||||
}
|
||||
|
||||
if len(logs) > 0 {
|
||||
res.Logs = types.NewLogsFromEth(logs)
|
||||
// Update transient block bloom filter
|
||||
|
||||
Reference in New Issue
Block a user