Skip to content

Commit

Permalink
fix: auto gas don't work (#12590)
Browse files Browse the repository at this point in the history
## Description

Closes: #12588
Solution:
- allow zero gas in simulation mode
- don't check min-gas-price in simulation mode

Please backport to 0.46.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 0a3c597)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
yihuang authored and mergify[bot] committed Jul 16, 2022
1 parent ebbcfd0 commit bcb00d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -43,6 +43,14 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

<<<<<<< HEAD
=======
* [#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.
>>>>>>> 0a3c597ce (fix: auto gas don't work (#12590))
* [#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`

Expand Down
16 changes: 12 additions & 4 deletions x/auth/ante/fee.go
Expand Up @@ -42,13 +42,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
}
}
if err := dfd.checkDeductFee(ctx, tx, fee); err != nil {
return ctx, err
Expand Down
9 changes: 9 additions & 0 deletions x/auth/ante/fee_test.go
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit bcb00d2

Please sign in to comment.