From adaa3a8c69093be1de300c48177f58d75d739059 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 15 Jul 2022 12:04:58 +0800 Subject: [PATCH 1/6] Problem: auto gas don't work Closes: #12588 Solution: - allow zero gas in simulation mode --- CHANGELOG.md | 1 + x/auth/ante/fee.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64fbb955c6d8..3b96e0dbb0b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. * [#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` +* [#12589](https://github.com/cosmos/cosmos-sdk/pull/12589) Allow zero gas in simulation mode. ### State Machine Breaking diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index fb433241f254..d47d8236d366 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -42,7 +42,7 @@ 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") } From 5813149cccdb1138ba4955d027dd5c538953c1ab Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 15 Jul 2022 14:31:50 +0800 Subject: [PATCH 2/6] don't check gas price in simulation mode --- x/auth/ante/fee.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index d47d8236d366..23742ede8aae 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -46,9 +46,14 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } - fee, priority, err := dfd.txFeeChecker(ctx, tx) - if err != nil { - return ctx, err + var err error + var priority int64 + fee := feeTx.GetFee() + if !simulate { + fee, priority, err = dfd.txFeeChecker(ctx, tx) + if err != nil { + return ctx, err + } } if err := dfd.checkDeductFee(ctx, tx, fee); err != nil { return ctx, err From 15320c4054e5a12181960bbe9c82958d817a8fc4 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 15 Jul 2022 14:35:49 +0800 Subject: [PATCH 3/6] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b96e0dbb0b7..6b1e1955717e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,13 +45,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#12589](https://github.com/cosmos/cosmos-sdk/pull/12589) Allow zero gas in simulation mode. * [#12576](https://github.com/cosmos/cosmos-sdk/pull/12576) Remove dependency on cosmos/keyring and upgrade to 99designs/keyring v1.2.1 * [#12089](https://github.com/cosmos/cosmos-sdk/pull/12089) Mark the `TipDecorator` as beta, don't include it in simapp by default. * [#12153](https://github.com/cosmos/cosmos-sdk/pull/12153) Add a new `NewSimulationManagerFromAppModules` constructor, to simplify simulation wiring. * [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module. * [#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` -* [#12589](https://github.com/cosmos/cosmos-sdk/pull/12589) Allow zero gas in simulation mode. ### State Machine Breaking From a7ef88cc77308e5bef3d12989551b9757d5a5efa Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 15 Jul 2022 15:00:00 +0800 Subject: [PATCH 4/6] add unit tests --- x/auth/ante/fee_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x/auth/ante/fee_test.go b/x/auth/ante/fee_test.go index c8ad40f3f511..4d2fdac56e46 100644 --- a/x/auth/ante/fee_test.go +++ b/x/auth/ante/fee_test.go @@ -36,6 +36,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() { @@ -74,6 +78,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) From 9cde1e4698debf676c08725d13dd3502cd39aac2 Mon Sep 17 00:00:00 2001 From: yihuang Date: Sun, 17 Jul 2022 00:25:10 +0800 Subject: [PATCH 5/6] Update x/auth/ante/fee.go Co-authored-by: Aleksandr Bezobchuk --- x/auth/ante/fee.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 23742ede8aae..e0d0477d72ae 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -46,8 +46,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } - var err error - var priority int64 + var ( + priority int64 + err error + ) + + fee := feeTx.GetFee() if !simulate { fee, priority, err = dfd.txFeeChecker(ctx, tx) From 4919f4d402b78b068d801ea4df735f44c35b1af6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 16 Jul 2022 19:31:08 +0200 Subject: [PATCH 6/6] Update x/auth/ante/fee.go --- x/auth/ante/fee.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index e0d0477d72ae..0f10041c3733 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -51,7 +51,6 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo err error ) - fee := feeTx.GetFee() if !simulate { fee, priority, err = dfd.txFeeChecker(ctx, tx)