From df53fe2c7853b5b1a2cb76c469f1be87682b8496 Mon Sep 17 00:00:00 2001 From: chengzhinei Date: Tue, 16 May 2023 14:24:28 +0800 Subject: [PATCH] evm tx when outofgas not refund (#3136) * 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 <864685021@qq.com> --- app/refund/refund.go | 12 ++++++++++-- libs/cosmos-sdk/baseapp/baseapp_runtx.go | 6 ++++-- libs/cosmos-sdk/store/types/gas.go | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/refund/refund.go b/app/refund/refund.go index c325556e98..e52f271697 100644 --- a/app/refund/refund.go +++ b/app/refund/refund.go @@ -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) diff --git a/libs/cosmos-sdk/baseapp/baseapp_runtx.go b/libs/cosmos-sdk/baseapp/baseapp_runtx.go index f34ce8d897..2771f8e28a 100644 --- a/libs/cosmos-sdk/baseapp/baseapp_runtx.go +++ b/libs/cosmos-sdk/baseapp/baseapp_runtx.go @@ -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) @@ -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, ), ) diff --git a/libs/cosmos-sdk/store/types/gas.go b/libs/cosmos-sdk/store/types/gas.go index 37c60b01f4..882c2ec14d 100644 --- a/libs/cosmos-sdk/store/types/gas.go +++ b/libs/cosmos-sdk/store/types/gas.go @@ -36,6 +36,7 @@ type GasMeter interface { GasConsumedToLimit() Gas Limit() Gas ConsumeGas(amount Gas, descriptor string) + SetGas(val Gas) IsPastLimit() bool IsOutOfGas() bool } @@ -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 } @@ -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 }