From 34315c4032f2b31b9a0b3cb7e11cc2f83c22c29e Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 20 May 2023 17:50:36 +0200 Subject: [PATCH 01/12] WIP on adding query gas limit --- baseapp/baseapp.go | 3 +++ baseapp/options.go | 22 ++++++++++++++++++++++ server/config/config.go | 5 +++++ server/config/toml.go | 5 +++++ server/start.go | 2 ++ server/util.go | 1 + 6 files changed, 38 insertions(+) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index bffe143f6d54..36ea0aa5b11e 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -95,6 +95,9 @@ type BaseApp struct { // application parameter store. paramStore ParamStore + // max gas for remote query. + // unbounded if 0. + queryGasLimit uint64 // The minimum gas prices a validator is willing to accept for processing a // transaction. This is mainly used for DoS and spam prevention. minGasPrices sdk.DecCoins diff --git a/baseapp/options.go b/baseapp/options.go index c30488df4ee7..8ab5c94be919 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -3,6 +3,9 @@ package baseapp import ( "fmt" "io" + "math" + "strconv" + "strings" "cosmossdk.io/store/metrics" pruningtypes "cosmossdk.io/store/pruning/types" @@ -34,6 +37,25 @@ func SetMinGasPrices(gasPricesStr string) func(*BaseApp) { return func(bapp *BaseApp) { bapp.setMinGasPrices(gasPrices) } } +// SetQueryGasLimit returns an option that sets a gas limit for queries. +func SetQueryGasLimit(queryGasLimitStr string) func(*BaseApp) { + queryGasLimitStr = strings.TrimSpace(queryGasLimitStr) + queryGasLimit := uint64(0) + var err error + if queryGasLimitStr != "" { + queryGasLimit, err = strconv.ParseUint(queryGasLimitStr, 10, 64) + if err != nil { + panic(fmt.Sprintf("invalid query gas limit: %v", err)) + } + + } + if queryGasLimit == 0 { + queryGasLimit = math.MaxUint64 + } + + return func(bapp *BaseApp) { bapp.queryGasLimit = queryGasLimit } +} + // SetHaltHeight returns a BaseApp option function that sets the halt block height. func SetHaltHeight(blockHeight uint64) func(*BaseApp) { return func(bapp *BaseApp) { bapp.setHaltHeight(blockHeight) } diff --git a/server/config/config.go b/server/config/config.go index 5cf1313b6673..8afa7d4c75df 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -39,6 +39,10 @@ type BaseConfig struct { // specified in this config (e.g. 0.25token1;0.0001token2). MinGasPrices string `mapstructure:"minimum-gas-prices"` + // The maximum amount of gas a grpc/Rest query may consume. + // If set to 0, it is unbounded. + QueryGasLimit uint64 `mapstructure:"query-gas-limit"` + Pruning string `mapstructure:"pruning"` PruningKeepRecent string `mapstructure:"pruning-keep-recent"` PruningInterval string `mapstructure:"pruning-interval"` @@ -228,6 +232,7 @@ func DefaultConfig() *Config { return &Config{ BaseConfig: BaseConfig{ MinGasPrices: defaultMinGasPrices, + QueryGasLimit: 0, InterBlockCache: true, Pruning: pruningtypes.PruningOptionDefault, PruningKeepRecent: "0", diff --git a/server/config/toml.go b/server/config/toml.go index de846d8f8575..a1f1f4d0c7cb 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -21,6 +21,11 @@ const DefaultConfigTemplate = `# This is a TOML config file. # specified in this config (e.g. 0.25token1;0.0001token2). minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" +# The maximum gas a query coming over rest/grpc may consume. +# If this is set to zero, the query can consume an unbounded amount of gas. +query-gas-limit = "{{ .BaseConfig.QueryGasLimit }}" + + # default: the last 362880 states are kept, pruning at 10 block intervals # nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) # everything: 2 latest states will be kept; pruning at 10 block intervals. diff --git a/server/start.go b/server/start.go index 76f27d5caecd..2d309b724021 100644 --- a/server/start.go +++ b/server/start.go @@ -49,6 +49,7 @@ const ( flagTraceStore = "trace-store" flagCPUProfile = "cpu-profile" FlagMinGasPrices = "minimum-gas-prices" + FlagQueryGasLimit = "query-gas-limit" FlagHaltHeight = "halt-height" FlagHaltTime = "halt-time" FlagInterBlockCache = "inter-block-cache" @@ -184,6 +185,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().String(flagTransport, "socket", "Transport protocol: socket, grpc") cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file") cmd.Flags().String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)") + cmd.Flags().Uint64(FlagQueryGasLimit, 0, "Maximum gas a Rest/Grpc query can consume. Blank and 0 imply unbounded.") cmd.Flags().IntSlice(FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary") cmd.Flags().Uint64(FlagHaltHeight, 0, "Block height at which to gracefully halt the chain and shutdown the node") cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") diff --git a/server/util.go b/server/util.go index 16cd9a9fe4b7..0b966e33a19a 100644 --- a/server/util.go +++ b/server/util.go @@ -503,6 +503,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { defaultMempool, baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), baseapp.SetChainID(chainID), + baseapp.SetQueryGasLimit(cast.ToString(appOpts.Get(FlagQueryGasLimit))), } } From c516c662054ff654269d10d6522f924185531acf Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 20 May 2023 19:49:44 +0200 Subject: [PATCH 02/12] Add baseapp test --- baseapp/abci.go | 3 +- baseapp/baseapp_test.go | 79 +++++++++++++++++++++++++++++++++++------ baseapp/options.go | 14 +------- server/util.go | 2 +- 4 files changed, 73 insertions(+), 25 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 123f23197039..b074a437af51 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -824,7 +824,8 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e // branch the commit-multistore for safety ctx := sdk.NewContext(cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger). WithMinGasPrices(app.minGasPrices). - WithBlockHeight(height) + WithBlockHeight(height). + WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)) if height != lastBlockHeight { rms, ok := app.cms.(*rootmulti.Store) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index f5fe99d10881..c8432952a523 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -81,6 +81,20 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite } } +func getQueryBaseapp(t *testing.T) *baseapp.BaseApp { + db := dbm.NewMemDB() + name := t.Name() + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) + + app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 1}}) + app.Commit() + + app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 2}}) + app.Commit() + + return app +} + func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...func(*baseapp.BaseApp)) *BaseAppSuite { snapshotTimeout := 1 * time.Minute snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t)) @@ -545,16 +559,7 @@ func TestBaseAppAnteHandler(t *testing.T) { // - https://github.com/cosmos/cosmos-sdk/issues/7662 func TestABCI_CreateQueryContext(t *testing.T) { t.Parallel() - - db := dbm.NewMemDB() - name := t.Name() - app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) - - app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 1}}) - app.Commit() - - app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 2}}) - app.Commit() + app := getQueryBaseapp(t) testCases := []struct { name string @@ -588,6 +593,60 @@ func TestSetMinGasPrices(t *testing.T) { require.Equal(t, minGasPrices, ctx.MinGasPrices()) } +type ctxType string + +const ( + QueryCtx ctxType = "query" + CheckTxCtx ctxType = "checkTx" + DeliverTxCtx ctxType = "deliverTx" +) + +var ctxTypes = []ctxType{QueryCtx, CheckTxCtx} + +func (c ctxType) GetCtx(t *testing.T, bapp *baseapp.BaseApp) sdk.Context { + if c == QueryCtx { + ctx, err := bapp.CreateQueryContext(1, false) + require.NoError(t, err) + return ctx + } else if c == CheckTxCtx { + return getCheckStateCtx(bapp) + } + // TODO: Not supported yet + return getDeliverStateCtx(bapp) +} + +func TestQueryGasLimit(t *testing.T) { + testCases := []struct { + queryGasLimit uint64 + gasActuallyUsed uint64 + shouldQueryErr bool + }{ + {queryGasLimit: 100, gasActuallyUsed: 50, shouldQueryErr: false}, // Valid case + {queryGasLimit: 100, gasActuallyUsed: 150, shouldQueryErr: true}, // gasActuallyUsed > queryGasLimit + {queryGasLimit: 0, gasActuallyUsed: 50, shouldQueryErr: false}, // fuzzing with queryGasLimit = 0 + {queryGasLimit: 0, gasActuallyUsed: 0, shouldQueryErr: false}, // both queryGasLimit and gasActuallyUsed are 0 + {queryGasLimit: 200, gasActuallyUsed: 200, shouldQueryErr: false}, // gasActuallyUsed == queryGasLimit + {queryGasLimit: 100, gasActuallyUsed: 1000, shouldQueryErr: true}, // gasActuallyUsed > queryGasLimit + } + + for _, tc := range testCases { + for _, ctxType := range ctxTypes { + t.Run(fmt.Sprintf("%s: %d - %d", ctxType, tc.queryGasLimit, tc.gasActuallyUsed), func(t *testing.T) { + app := getQueryBaseapp(t) + baseapp.SetQueryGasLimit(tc.queryGasLimit)(app) + ctx := ctxType.GetCtx(t, app) + + // query gas limit should have no effect when CtxType != QueryCtx + if tc.shouldQueryErr && ctxType == QueryCtx { + require.Panics(t, func() { ctx.GasMeter().ConsumeGas(tc.gasActuallyUsed, "test") }) + } else { + require.NotPanics(t, func() { ctx.GasMeter().ConsumeGas(tc.gasActuallyUsed, "test") }) + } + }) + } + } +} + func TestGetMaximumBlockGas(t *testing.T) { suite := NewBaseAppSuite(t) suite.baseApp.InitChain(abci.RequestInitChain{}) diff --git a/baseapp/options.go b/baseapp/options.go index 8ab5c94be919..3261f067135f 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -4,8 +4,6 @@ import ( "fmt" "io" "math" - "strconv" - "strings" "cosmossdk.io/store/metrics" pruningtypes "cosmossdk.io/store/pruning/types" @@ -38,17 +36,7 @@ func SetMinGasPrices(gasPricesStr string) func(*BaseApp) { } // SetQueryGasLimit returns an option that sets a gas limit for queries. -func SetQueryGasLimit(queryGasLimitStr string) func(*BaseApp) { - queryGasLimitStr = strings.TrimSpace(queryGasLimitStr) - queryGasLimit := uint64(0) - var err error - if queryGasLimitStr != "" { - queryGasLimit, err = strconv.ParseUint(queryGasLimitStr, 10, 64) - if err != nil { - panic(fmt.Sprintf("invalid query gas limit: %v", err)) - } - - } +func SetQueryGasLimit(queryGasLimit uint64) func(*BaseApp) { if queryGasLimit == 0 { queryGasLimit = math.MaxUint64 } diff --git a/server/util.go b/server/util.go index 0b966e33a19a..91701998103a 100644 --- a/server/util.go +++ b/server/util.go @@ -503,7 +503,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { defaultMempool, baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), baseapp.SetChainID(chainID), - baseapp.SetQueryGasLimit(cast.ToString(appOpts.Get(FlagQueryGasLimit))), + baseapp.SetQueryGasLimit(cast.ToUint64(appOpts.Get(FlagQueryGasLimit))), } } From c9cfccaa270ef7185dde38fe9cd92e1b42623f24 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 20 May 2023 19:52:07 +0200 Subject: [PATCH 03/12] Add default --- baseapp/baseapp.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 36ea0aa5b11e..c5508a6f041a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -2,6 +2,7 @@ package baseapp import ( "fmt" + "math" "sort" "strconv" @@ -167,6 +168,7 @@ func NewBaseApp( msgServiceRouter: NewMsgServiceRouter(), txDecoder: txDecoder, fauxMerkleMode: false, + queryGasLimit: math.MaxUint64, } for _, option := range options { From b8dccc1acebe1ffa0bef5b05477677b050f11fb7 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 20 May 2023 19:54:35 +0200 Subject: [PATCH 04/12] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da675eba7f17..26a9ed800a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (tx) [#15992](https://github.com/cosmos/cosmos-sdk/pull/15992) Add `WithExtensionOptions` in tx Factory to allow `SetExtensionOptions` with given extension options. * (types/simulation) [#16074](https://github.com/cosmos/cosmos-sdk/pull/16074) Add generic SimulationStoreDecoder for modules using collections. * (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Make `StartCmd` more customizable. +* (baseapp) [#16239](https://github.com/cosmos/cosmos-sdk/pull/16239) Add Gas Limits to allow node operators to resource bound queries. ### Improvements From 320607c110bf5777cde403dfde1a752233fb922a Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 20 May 2023 19:59:23 +0200 Subject: [PATCH 05/12] Delete extra newline --- server/config/toml.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/config/toml.go b/server/config/toml.go index a1f1f4d0c7cb..65ec658f5ce3 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -25,7 +25,6 @@ minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" # If this is set to zero, the query can consume an unbounded amount of gas. query-gas-limit = "{{ .BaseConfig.QueryGasLimit }}" - # default: the last 362880 states are kept, pruning at 10 block intervals # nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) # everything: 2 latest states will be kept; pruning at 10 block intervals. From 056ea695169c2f009606466a0a96ec45800e71e8 Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 7 Aug 2023 12:43:28 +0200 Subject: [PATCH 06/12] Update baseapp/baseapp.go Co-authored-by: Aleksandr Bezobchuk --- baseapp/baseapp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index c5508a6f041a..866f9383743a 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -96,9 +96,9 @@ type BaseApp struct { // application parameter store. paramStore ParamStore - // max gas for remote query. - // unbounded if 0. + // queryGasLimit defines the maximum gas for queries; unbounded if 0. queryGasLimit uint64 + // The minimum gas prices a validator is willing to accept for processing a // transaction. This is mainly used for DoS and spam prevention. minGasPrices sdk.DecCoins From 8af0a3d66295b98336264466cee23c5ba486cb9e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 7 Aug 2023 12:47:41 +0200 Subject: [PATCH 07/12] add .50-app.toml --- tools/confix/data/v0.50-app.toml | 237 +++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 tools/confix/data/v0.50-app.toml diff --git a/tools/confix/data/v0.50-app.toml b/tools/confix/data/v0.50-app.toml new file mode 100644 index 000000000000..311f940eda86 --- /dev/null +++ b/tools/confix/data/v0.50-app.toml @@ -0,0 +1,237 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +############################################################################### +### Base Configuration ### +############################################################################### + +# The minimum gas prices a validator is willing to accept for processing a +# transaction. A transaction's fees must meet the minimum of any denomination +# specified in this config (e.g. 0.25token1;0.0001token2). +minimum-gas-prices = "0stake" + +# The maximum gas a query coming over rest/grpc may consume. +# If this is set to zero, the query can consume an unbounded amount of gas. +query-gas-limit = "0" + +# default: the last 362880 states are kept, pruning at 10 block intervals +# nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) +# everything: 2 latest states will be kept; pruning at 10 block intervals. +# custom: allow pruning options to be manually specified through 'pruning-keep-recent', and 'pruning-interval' +pruning = "default" + +# These are applied if and only if the pruning strategy is custom. +pruning-keep-recent = "0" +pruning-interval = "0" + +# HaltHeight contains a non-zero block height at which a node will gracefully +# halt and shutdown that can be used to assist upgrades and testing. +# +# Note: Commitment of state will be attempted on the corresponding block. +halt-height = 0 + +# HaltTime contains a non-zero minimum block time (in Unix seconds) at which +# a node will gracefully halt and shutdown that can be used to assist upgrades +# and testing. +# +# Note: Commitment of state will be attempted on the corresponding block. +halt-time = 0 + +# MinRetainBlocks defines the minimum block height offset from the current +# block being committed, such that all blocks past this offset are pruned +# from CometBFT. It is used as part of the process of determining the +# ResponseCommit.RetainHeight value during ABCI Commit. A value of 0 indicates +# that no blocks should be pruned. +# +# This configuration value is only responsible for pruning CometBFT blocks. +# It has no bearing on application state pruning which is determined by the +# "pruning-*" configurations. +# +# Note: CometBFT block pruning is dependant on this parameter in conjunction +# with the unbonding (safety threshold) period, state pruning and state sync +# snapshot parameters to determine the correct minimum value of +# ResponseCommit.RetainHeight. +min-retain-blocks = 0 + +# InterBlockCache enables inter-block caching. +inter-block-cache = true + +# IndexEvents defines the set of events in the form {eventType}.{attributeKey}, +# which informs CometBFT what to index. If empty, all events will be indexed. +# +# Example: +# ["message.sender", "message.recipient"] +index-events = [] + +# IavlCacheSize set the size of the iavl tree cache (in number of nodes). +iavl-cache-size = 781250 + +# IAVLDisableFastNode enables or disables the fast node feature of IAVL. +# Default is false. +iavl-disable-fastnode = false + +# IAVLLazyLoading enable/disable the lazy loading of iavl store. +# Default is false. +iavl-lazy-loading = false + +# AppDBBackend defines the database backend type to use for the application and snapshots DBs. +# An empty string indicates that a fallback will be used. +# First fallback is the deprecated compile-time types.DBBackend value. +# Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in CometBFT's config.toml. +app-db-backend = "" + +############################################################################### +### Telemetry Configuration ### +############################################################################### + +[telemetry] + +# Prefixed with keys to separate services. +service-name = "" + +# Enabled enables the application telemetry functionality. When enabled, +# an in-memory sink is also enabled by default. Operators may also enabled +# other sinks such as Prometheus. +enabled = false + +# Enable prefixing gauge values with hostname. +enable-hostname = false + +# Enable adding hostname to labels. +enable-hostname-label = false + +# Enable adding service to labels. +enable-service-label = false + +# PrometheusRetentionTime, when positive, enables a Prometheus metrics sink. +prometheus-retention-time = 0 + +# GlobalLabels defines a global set of name/value label tuples applied to all +# metrics emitted using the wrapper functions defined in telemetry package. +# +# Example: +# [["chain_id", "cosmoshub-1"]] +global-labels = [ +] + +############################################################################### +### API Configuration ### +############################################################################### + +[api] + +# Enable defines if the API server should be enabled. +enable = false + +# Swagger defines if swagger documentation should automatically be registered. +swagger = false + +# Address defines the API server to listen on. +address = "tcp://localhost:1317" + +# MaxOpenConnections defines the number of maximum open connections. +max-open-connections = 1000 + +# RPCReadTimeout defines the CometBFT RPC read timeout (in seconds). +rpc-read-timeout = 10 + +# RPCWriteTimeout defines the CometBFT RPC write timeout (in seconds). +rpc-write-timeout = 0 + +# RPCMaxBodyBytes defines the CometBFT maximum request body (in bytes). +rpc-max-body-bytes = 1000000 + +# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk). +enabled-unsafe-cors = false + +############################################################################### +### gRPC Configuration ### +############################################################################### + +[grpc] + +# Enable defines if the gRPC server should be enabled. +enable = true + +# Address defines the gRPC server address to bind to. +address = "localhost:9090" + +# MaxRecvMsgSize defines the max message size in bytes the server can receive. +# The default value is 10MB. +max-recv-msg-size = "10485760" + +# MaxSendMsgSize defines the max message size in bytes the server can send. +# The default value is math.MaxInt32. +max-send-msg-size = "2147483647" + +############################################################################### +### gRPC Web Configuration ### +############################################################################### + +[grpc-web] + +# GRPCWebEnable defines if the gRPC-web should be enabled. +# NOTE: gRPC must also be enabled, otherwise, this configuration is a no-op. +# NOTE: gRPC-Web uses the same address as the API server. +enable = true + +############################################################################### +### State Sync Configuration ### +############################################################################### + +# State sync snapshots allow other nodes to rapidly join the network without replaying historical +# blocks, instead downloading and applying a snapshot of the application state at a given height. +[state-sync] + +# snapshot-interval specifies the block interval at which local state sync snapshots are +# taken (0 to disable). +snapshot-interval = 0 + +# snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). +snapshot-keep-recent = 2 + +############################################################################### +### State Streaming ### +############################################################################### + +# Streaming allows nodes to stream state to external systems. +[streaming] + +# streaming.abci specifies the configuration for the ABCI Listener streaming service. +[streaming.abci] + +# List of kv store keys to stream out via gRPC. +# The store key names MUST match the module's StoreKey name. +# +# Example: +# ["acc", "bank", "gov", "staking", "mint"[,...]] +# ["*"] to expose all keys. +keys = [] + +# The plugin name used for streaming via gRPC. +# Streaming is only enabled if this is set. +# Supported plugins: abci +plugin = "" + +# stop-node-on-err specifies whether to stop the node on message delivery error. +stop-node-on-err = true + +############################################################################### +### Mempool ### +############################################################################### + +[mempool] +# Setting max-txs to 0 will allow for a unbounded amount of transactions in the mempool. +# Setting max_txs to negative 1 (-1) will disable transactions from being inserted into the mempool. +# Setting max_txs to a positive number (> 0) will limit the number of transactions in the mempool, by the specified amount. +# +# Note, this configuration only applies to SDK built-in app-side mempool +# implementations. +max-txs = "5000" + +[wasm] +# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries +query_gas_limit = 300000 +# This is the number of wasm vm instances we keep cached in memory for speed-up +# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally +lru_size = 0 From ccedbf67fa3d658be907fe00e1fffb93b7f2918e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 7 Aug 2023 12:50:58 +0200 Subject: [PATCH 08/12] regenerate app.toml --- tools/confix/data/v0.50-app.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/confix/data/v0.50-app.toml b/tools/confix/data/v0.50-app.toml index 275adb6e8fc5..311f940eda86 100644 --- a/tools/confix/data/v0.50-app.toml +++ b/tools/confix/data/v0.50-app.toml @@ -228,3 +228,10 @@ stop-node-on-err = true # Note, this configuration only applies to SDK built-in app-side mempool # implementations. max-txs = "5000" + +[wasm] +# This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries +query_gas_limit = 300000 +# This is the number of wasm vm instances we keep cached in memory for speed-up +# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally +lru_size = 0 From 04b014b7c7ca26fb18c84ac9dabb86e4f1a08622 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 7 Aug 2023 12:53:36 +0200 Subject: [PATCH 09/12] regenerate app.toml --- tools/confix/data/v0.50-app.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/confix/data/v0.50-app.toml b/tools/confix/data/v0.50-app.toml index 311f940eda86..5e01e120d8b0 100644 --- a/tools/confix/data/v0.50-app.toml +++ b/tools/confix/data/v0.50-app.toml @@ -70,10 +70,6 @@ iavl-cache-size = 781250 # Default is false. iavl-disable-fastnode = false -# IAVLLazyLoading enable/disable the lazy loading of iavl store. -# Default is false. -iavl-lazy-loading = false - # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. # First fallback is the deprecated compile-time types.DBBackend value. From 561c96e19ef0cd5782cd0f9a6e0856f63603b451 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 7 Aug 2023 12:56:07 +0200 Subject: [PATCH 10/12] fix tests --- baseapp/baseapp_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 1721ce73215e..71abc2427b59 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -87,14 +87,16 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite } func getQueryBaseapp(t *testing.T) *baseapp.BaseApp { + t.Helper() + db := dbm.NewMemDB() name := t.Name() app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) - app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 1}}) + app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 2}}) + app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2}) app.Commit() return app @@ -646,6 +648,7 @@ const ( var ctxTypes = []ctxType{QueryCtx, CheckTxCtx} func (c ctxType) GetCtx(t *testing.T, bapp *baseapp.BaseApp) sdk.Context { + t.Helper() if c == QueryCtx { ctx, err := bapp.CreateQueryContext(1, false) require.NoError(t, err) @@ -654,7 +657,7 @@ func (c ctxType) GetCtx(t *testing.T, bapp *baseapp.BaseApp) sdk.Context { return getCheckStateCtx(bapp) } // TODO: Not supported yet - return getDeliverStateCtx(bapp) + return getFinalizeBlockStateCtx(bapp) } func TestQueryGasLimit(t *testing.T) { From bbab8cbcf65681a81c011fd2e659f7ffe4584f47 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 7 Aug 2023 12:58:52 +0200 Subject: [PATCH 11/12] fix tests --- baseapp/baseapp_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 71abc2427b59..3aa64defe31f 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -93,11 +93,15 @@ func getQueryBaseapp(t *testing.T) *baseapp.BaseApp { name := t.Name() app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) - app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) - app.Commit() + _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) + require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) - app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2}) - app.Commit() + _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 2}) + require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) return app } @@ -590,11 +594,10 @@ func TestBaseAppAnteHandler(t *testing.T) { // - https://github.com/cosmos/cosmos-sdk/issues/7662 func TestABCI_CreateQueryContext(t *testing.T) { t.Parallel() - app := getQueryBaseapp(t) db := dbm.NewMemDB() name := t.Name() - app = baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1}) require.NoError(t, err) From 36c6f0aacaf27eeaf9ef2c6ad837fabe8413766c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 8 Aug 2023 22:18:24 +0200 Subject: [PATCH 12/12] nits --- CHANGELOG.md | 2 +- baseapp/baseapp_test.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54a9487cefd6..37376d22922e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (x/bank) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16852) Add `DenomMetadataByQueryString` query in bank module to support metadata query by query string. +* (baseapp) [#16239](https://github.com/cosmos/cosmos-sdk/pull/16239) Add Gas Limits to allow node operators to resource bound queries. ### Improvements @@ -152,7 +153,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (core) [#14860](https://github.com/cosmos/cosmos-sdk/pull/14860) Add `Precommit` and `PrepareCheckState` AppModule callbacks. * (types/simulation) [#16074](https://github.com/cosmos/cosmos-sdk/pull/16074) Add generic SimulationStoreDecoder for modules using collections. * (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Make `StartCmd` more customizable. -* (baseapp) [#16239](https://github.com/cosmos/cosmos-sdk/pull/16239) Add Gas Limits to allow node operators to resource bound queries. * (types) [#16257](https://github.com/cosmos/cosmos-sdk/pull/16257) Allow setting the base denom in the denom registry. * (genutil) [#16046](https://github.com/cosmos/cosmos-sdk/pull/16046) Add "module-name" flag to genutil `add-genesis-account` to enable intializing module accounts at genesis. diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 3aa64defe31f..0fef6903b776 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -643,9 +643,8 @@ func TestSetMinGasPrices(t *testing.T) { type ctxType string const ( - QueryCtx ctxType = "query" - CheckTxCtx ctxType = "checkTx" - DeliverTxCtx ctxType = "deliverTx" + QueryCtx ctxType = "query" + CheckTxCtx ctxType = "checkTx" ) var ctxTypes = []ctxType{QueryCtx, CheckTxCtx}