Skip to content

Commit

Permalink
evm tx when outofgas not refund (#3136)
Browse files Browse the repository at this point in the history
* evm tx when outofgas not refund

* fix runtx venus6 height

* when not refund, make gasUsed=gasLimit

* add func SetGas

* fix log

* fix log

---------

Co-authored-by: BananaLF <[email protected]>
  • Loading branch information
chengzhinei and BananaLF authored May 16, 2023
1 parent eadf4c6 commit df53fe2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
12 changes: 10 additions & 2 deletions app/refund/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ func gasRefund(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.Sup
return nil, nil
}

if tx.GetType() == sdk.StdTxType && ctx.GetOutOfGas() {
return nil, nil
if tmtypes.HigherThanVenus6(ctx.BlockHeight()) {
if ctx.GetOutOfGas() {
ctx.GasMeter().SetGas(ctx.GasMeter().Limit())
currentGasMeter.SetGas(gasLimit)
return nil, nil
}
} else {
if tx.GetType() == sdk.StdTxType && ctx.GetOutOfGas() {
return nil, nil
}
}

feeTx, ok := tx.(ante.FeeTx)
Expand Down
6 changes: 4 additions & 2 deletions libs/cosmos-sdk/baseapp/baseapp_runtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ func (app *BaseApp) runtxWithInfo(info *runTxInfo, mode runTxMode, txBytes []byt
}
app.pin(trace.Refund, true, mode)
defer app.pin(trace.Refund, false, mode)
if types2.HigherThanVenus6(height) {
if types2.HigherThanVenus6(info.ctx.BlockHeight()) {
if (tx.GetType() == sdk.StdTxType && isAnteSucceed && err == nil) ||
tx.GetType() == sdk.EvmTxType {
handler.handleDeferRefund(info)
} else {
info.ctx.GasMeter().SetGas(info.ctx.GasMeter().Limit())
}
} else {
handler.handleDeferRefund(info)
Expand Down Expand Up @@ -406,7 +408,7 @@ func (app *BaseApp) runTx_defer_recover(r interface{}, info *runTxInfo) error {
err = sdkerrors.Wrap(
sdkerrors.ErrOutOfGas, fmt.Sprintf(
"out of gas in location: %v; gasWanted: %d, gasUsed: %d",
rType.Descriptor, info.gasWanted, info.ctx.GasMeter().GasConsumed(),
rType.Descriptor, info.gasWanted, info.gasWanted,
),
)

Expand Down
9 changes: 9 additions & 0 deletions libs/cosmos-sdk/store/types/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type GasMeter interface {
GasConsumedToLimit() Gas
Limit() Gas
ConsumeGas(amount Gas, descriptor string)
SetGas(val Gas)
IsPastLimit() bool
IsOutOfGas() bool
}
Expand Down Expand Up @@ -96,6 +97,10 @@ func (g *basicGasMeter) ConsumeGas(amount Gas, descriptor string) {
}
}

func (g *basicGasMeter) SetGas(val Gas) {
g.consumed = val
}

func (g *basicGasMeter) IsPastLimit() bool {
return g.consumed > g.limit
}
Expand Down Expand Up @@ -148,6 +153,10 @@ func (g *infiniteGasMeter) ConsumeGas(amount Gas, descriptor string) {
}
}

func (g *infiniteGasMeter) SetGas(val Gas) {
g.consumed = val
}

func (g *infiniteGasMeter) IsPastLimit() bool {
return false
}
Expand Down

0 comments on commit df53fe2

Please sign in to comment.