From d0d128dd746c6df8204d73e40195401f37d495a8 Mon Sep 17 00:00:00 2001 From: "Kim, JinSan" Date: Tue, 5 Jan 2021 16:33:34 +0900 Subject: [PATCH 1/4] feat: impl `validateGasWanted()` --- baseapp/baseapp.go | 5 +++-- x/auth/ante/setup.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 9cda1ab19e..41e8322c14 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -394,8 +394,9 @@ func (app *BaseApp) IsSealed() bool { return app.sealed } func (app *BaseApp) setCheckState(header abci.Header) { ms := app.cms.CacheMultiStore() app.checkState = &state{ - ms: ms, - ctx: sdk.NewContext(ms, header, true, app.logger).WithMinGasPrices(app.minGasPrices), + ms: ms, + ctx: sdk.NewContext(ms, header, true, app.logger). + WithMinGasPrices(app.minGasPrices).WithConsensusParams(app.consensusParams), } } diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 1e3e8eb68d..f85a1ab14a 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -41,6 +41,11 @@ 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 @@ -74,3 +79,29 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context { return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit)) } + +func validateGasWanted(ctx sdk.Context) error { + // validate gasWanted only when checkTx + if !ctx.IsCheckTx() || ctx.IsReCheckTx() { + return nil + } + + gasWanted := 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 + // TODO: Should revise type + // reference: https://github.com/line/cosmos-sdk/blob/fd6d941cc429fc2a58154dbace3bbaec4beef445/baseapp/abci.go#L189 + if int64(gasWanted) > maxGas { + return fmt.Errorf("gas wanted %d is greater than max gas %d", gasWanted, maxGas) + } + + return nil +} From 40663b42d5ad4b8d9b8fdfb2ebe0c816ddb49ffb Mon Sep 17 00:00:00 2001 From: "Kim, JinSan" Date: Tue, 5 Jan 2021 16:43:08 +0900 Subject: [PATCH 2/4] fix: lint error --- x/auth/ante/setup.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index f85a1ab14a..da11be8171 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -86,7 +86,9 @@ func validateGasWanted(ctx sdk.Context) error { return nil } - gasWanted := ctx.GasMeter().Limit() + // 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) } @@ -97,9 +99,7 @@ func validateGasWanted(ctx sdk.Context) error { } maxGas := consParams.Block.MaxGas - // TODO: Should revise type - // reference: https://github.com/line/cosmos-sdk/blob/fd6d941cc429fc2a58154dbace3bbaec4beef445/baseapp/abci.go#L189 - if int64(gasWanted) > maxGas { + if gasWanted > maxGas { return fmt.Errorf("gas wanted %d is greater than max gas %d", gasWanted, maxGas) } From b47a55de57a52b8c92b3c0de35318733364ba840 Mon Sep 17 00:00:00 2001 From: "Kim, JinSan" Date: Wed, 6 Jan 2021 15:20:29 +0900 Subject: [PATCH 3/4] chore: bump up tendermint --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b31ff1c26e..8c0c0d4c00 100644 --- a/go.mod +++ b/go.mod @@ -47,5 +47,5 @@ require ( replace ( github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 github.com/tendermint/iavl => github.com/line/iavl v0.14.4-0.20201217063301-6b67687bfae9 - github.com/tendermint/tendermint => github.com/line/tendermint v0.33.10-0.20201215041755-c81005d8468b + github.com/tendermint/tendermint => github.com/line/tendermint v0.33.10-0.20210106061749-b557e0c9a76c ) diff --git a/go.sum b/go.sum index 332f07e0dd..febcb62e67 100644 --- a/go.sum +++ b/go.sum @@ -265,8 +265,8 @@ github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-b github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/line/iavl v0.14.4-0.20201217063301-6b67687bfae9 h1:n6YHVdTld8D0dAogBUcXTaqhk1ZMTAR9Phy4xdMVWDY= github.com/line/iavl v0.14.4-0.20201217063301-6b67687bfae9/go.mod h1:eG6hI8RbMxL1nR+nJBykXD//gKjUpKCAT2tvi9V93sA= -github.com/line/tendermint v0.33.10-0.20201215041755-c81005d8468b h1:iIGlUondhI/bf/05Q1XZ2FDgnP3TiktfGURNtfJivsI= -github.com/line/tendermint v0.33.10-0.20201215041755-c81005d8468b/go.mod h1:0yUs9eIuuDq07nQql9BmI30FtYGcEC60Tu5JzB5IezM= +github.com/line/tendermint v0.33.10-0.20210106061749-b557e0c9a76c h1:BLKoXsi7V+y1Neb9FcYgV+9UWKeJM1KLsoJBy/GAg3w= +github.com/line/tendermint v0.33.10-0.20210106061749-b557e0c9a76c/go.mod h1:0yUs9eIuuDq07nQql9BmI30FtYGcEC60Tu5JzB5IezM= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= From 2c4919c7dc8242aa136e1f3b46713bd037af740a Mon Sep 17 00:00:00 2001 From: "Kim, JinSan" Date: Wed, 6 Jan 2021 15:55:13 +0900 Subject: [PATCH 4/4] fix: tests to use `grpc` instead of `socket` --- server/start.go | 2 +- x/genutil/client/cli/init_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/start.go b/server/start.go index ea14aeaf40..890ad5ca6b 100644 --- a/server/start.go +++ b/server/start.go @@ -131,7 +131,7 @@ func startStandAlone(ctx *Context, appCreator AppCreator) error { app := appCreator(ctx.Logger, db, traceWriter) - svr, err := server.NewServer(addr, "socket", app) + svr, err := server.NewServer(addr, "grpc", app) if err != nil { return fmt.Errorf("error creating listener: %v", err) } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 6ab1ef208a..b19a5ddcd7 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -110,7 +110,7 @@ func TestStartStandAlone(t *testing.T) { require.Nil(t, err) svrAddr, _, err := server.FreeTCPAddr() require.Nil(t, err) - svr, err := abciServer.NewServer(svrAddr, "socket", app) + svr, err := abciServer.NewServer(svrAddr, "grpc", app) require.Nil(t, err, "error creating listener") svr.SetLogger(logger.With("module", "abci-server")) svr.Start()