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: remove max gas validation #895

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cosmovisor) [\#792](https://github.com/line/lbm-sdk/pull/792) Use upstream's cosmovisor
* (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
* (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 {
0Tech marked this conversation as resolved.
Show resolved Hide resolved
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