Skip to content

Commit

Permalink
fix: remove max gas validation (#895)
Browse files Browse the repository at this point in the history
* Remove max gas validation

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Feb 13, 2023
1 parent 4776b03 commit 302cb11
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server) [\#821](https://github.com/line/lbm-sdk/pull/821) Get validator pubkey considering KMS
* (client) [\#890](https://github.com/line/lbm-sdk/pull/890) Map Ostracon:ErrTxInMap to lbm-sdk:ErrTxInMempoolCache
* (x/collection) [\#894](https://github.com/line/lbm-sdk/pull/894) Change the default params of x/collection
* (ante) [\#895](https://github.com/line/lbm-sdk/pull/895) Remove max gas validation

### Bug Fixes
* (client) [\#817](https://github.com/line/lbm-sdk/pull/817) remove support for composite (BLS) type
Expand Down
3 changes: 1 addition & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ func (app *BaseApp) BeginBlock(req ocabci.RequestBeginBlock) (res abci.ResponseB
if app.checkState != nil {
app.checkState.ctx = app.checkState.ctx.
WithBlockGasMeter(gasMeter).
WithHeaderHash(req.Hash).
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx))
WithHeaderHash(req.Hash)
}

if app.beginBlocker != nil {
Expand Down
30 changes: 0 additions & 30 deletions x/auth/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())

err = validateGasWanted(newCtx)
if err != nil {
return newCtx, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, err.Error())
}

// Decorator will catch an OutOfGasPanic caused in the next antehandler
// AnteHandlers must have their own defer/recover in order for the BaseApp
// to know how much gas was used! This is because the GasMeter is created in
Expand Down Expand Up @@ -77,28 +72,3 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {

return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))
}

func validateGasWanted(ctx sdk.Context) error {
if !ctx.IsCheckTx() {
return nil
}

// TODO: Should revise type
// reference: https://github.com/line/cosmos-sdk/blob/fd6d941cc429fc2a58154dbace3bbaec4beef445/baseapp/abci.go#L189
gasWanted := int64(ctx.GasMeter().Limit())
if gasWanted < 0 {
return fmt.Errorf("gas wanted %d is negative", gasWanted)
}

consParams := ctx.ConsensusParams()
if consParams == nil || consParams.Block == nil || consParams.Block.MaxGas == -1 {
return nil
}

maxGas := consParams.Block.MaxGas
if gasWanted > maxGas {
return fmt.Errorf("gas wanted %d is greater than max gas %d", gasWanted, maxGas)
}

return nil
}
17 changes: 0 additions & 17 deletions x/auth/ante/setup_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ante_test

import (
abci "github.com/tendermint/tendermint/abci/types"

cryptotypes "github.com/line/lbm-sdk/crypto/types"
"github.com/line/lbm-sdk/testutil/testdata"
sdk "github.com/line/lbm-sdk/types"
Expand Down Expand Up @@ -43,21 +41,6 @@ func (suite *AnteTestSuite) TestSetup() {

// Context GasMeter Limit should be set after SetUpContextDecorator runs
suite.Require().Equal(gasLimit, newCtx.GasMeter().Limit(), "GasMeter not set correctly")

// Set MaxGas lower than the tx's gasWanted
consensusParams := &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxGas: int64(gasLimit) - 1,
},
}
suite.ctx = suite.ctx.WithConsensusParams(consensusParams)

// for both of CheckTx and ReCheckTx
for _, isRecheck := range []bool{false, true} {
suite.ctx = suite.ctx.WithIsReCheckTx(isRecheck)
_, err = antehandler(suite.ctx, tx, false)
suite.Require().Error(err)
}
}

func (suite *AnteTestSuite) TestRecoverPanic() {
Expand Down

0 comments on commit 302cb11

Please sign in to comment.