From 2555d72ee136d0fda3041d577c1679ac0d260052 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 17 Jul 2022 00:40:44 -0400 Subject: [PATCH] fix: auto gas don't work (backport #12590) (#12602) --- CHANGELOG.md | 1 + x/auth/ante/fee.go | 16 ++++++++++++---- x/auth/ante/fee_test.go | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93917a24046..af4c7ef4700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ It is strongly recommended to upgrade to these releases as well. ### Improvements +* [#12589](https://github.com/cosmos/cosmos-sdk/pull/12589) Allow zero gas in simulation mode. * [#12453](https://github.com/cosmos/cosmos-sdk/pull/12453) Add `NewInMemoryWithKeyring` function which allows the creation of in memory `keystore` instances with a specified set of existing items. * [#11390](https://github.com/cosmos/cosmos-sdk/pull/11390) `LatestBlockResponse` & `BlockByHeightResponse` types' `Block` filed has been deprecated and they now contains new field `sdk_block` with `proposer_address` as `string` diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 02c9b085738..42ace10a888 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -52,13 +52,21 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } - if ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { + if !simulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } - fee, priority, err := dfd.txFeeChecker(ctx, tx) - if err != nil { - return ctx, err + var ( + priority int64 + err error + ) + + fee := feeTx.GetFee() + if !simulate { + fee, priority, err = dfd.txFeeChecker(ctx, tx) + if err != nil { + return ctx, err + } } newCtx := ctx.WithPriority(txPriority) diff --git a/x/auth/ante/fee_test.go b/x/auth/ante/fee_test.go index 46aa2799665..6e54ec588c7 100644 --- a/x/auth/ante/fee_test.go +++ b/x/auth/ante/fee_test.go @@ -45,6 +45,10 @@ func (s *AnteTestSuite) TestDeductFeeDecorator_ZeroGas() { _, err = antehandler(s.ctx, tx, false) s.Require().Error(err) + + // zero gas is accepted in simulation mode + _, err = antehandler(s.ctx, tx, true) + s.Require().NoError(err) } func (s *AnteTestSuite) TestEnsureMempoolFees() { @@ -83,6 +87,11 @@ func (s *AnteTestSuite) TestEnsureMempoolFees() { _, err = antehandler(s.ctx, tx, false) s.Require().NotNil(err, "Decorator should have errored on too low fee for local gasPrice") + // antehandler should not error since we do not check minGasPrice in simulation mode + cacheCtx, _ := s.ctx.CacheContext() + _, err = antehandler(cacheCtx, tx, true) + s.Require().Nil(err, "Decorator should not have errored in simulation mode") + // Set IsCheckTx to false s.ctx = s.ctx.WithIsCheckTx(false)