Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto gas don't work #12590

Merged
merged 8 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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.
Expand Down
16 changes: 12 additions & 4 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
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
)

julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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