diff --git a/CHANGELOG.md b/CHANGELOG.md index 59d1d02a30..e33ecc2827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## v0.2.4-alpha.1 +This release includes 4 features and 1 bugfix. + +Features: +* [#256](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/256) feat: add Nagqu fork name for upcoming upgrading +* [#258](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/258) feat: add flag to enable or disable heavy queries +* [#263](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/263) feat: add MsgRenewGroupMember to renew storage group member +* [#262](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/262) feat: add MsgUpdateStorageProviderStatus to update sp status + +Fix: +* [#257](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/257) fix: add bls proof in proposal description + +## v0.2.3 +This is a official release for v0.2.3, includes all the changes since v0.2.2. + ## v0.2.3-alpha.5 This is a maintenance release. diff --git a/baseapp/abci.go b/baseapp/abci.go index 2ae558f5ef..f99fc47fd7 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -954,7 +954,8 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool, path ...string) // branch the commit-multistore for safety ctx := sdk.NewContext(cacheMS, qs.ctx.BlockHeader(), true, app.upgradeChecker, app.logger). WithMinGasPrices(app.minGasPrices). - WithBlockHeight(height) + WithBlockHeight(height). + WithEnableUnsafeQuery(app.enableUnsafeQuery) if height != lastBlockHeight { rms, ok := app.cms.(*rootmulti.Store) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 2a04d0bcb4..cc73a85000 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -163,8 +163,11 @@ type BaseApp struct { //nolint: maligned // upgradeChecker is a hook function from the upgrade module to check upgrade is executed or not. upgradeChecker func(ctx sdk.Context, name string) bool - // Signatures of recent blocks to speed up + // sigCache caches the signatures of recent blocks to speed up sigCache *lru.ARCCache + + // enableUnsafeQuery defines whether the unsafe queries will be enabled or not + enableUnsafeQuery bool } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a diff --git a/baseapp/options.go b/baseapp/options.go index e57bee6a25..4fee55e7c6 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -102,6 +102,11 @@ func SetChainID(chainID string) func(*BaseApp) { return func(app *BaseApp) { app.chainID = chainID } } +// SetEnableUnsafeQuery sets the flag to enable unsafe query in BaseApp. +func SetEnableUnsafeQuery(enabled bool) func(*BaseApp) { + return func(app *BaseApp) { app.enableUnsafeQuery = enabled } +} + func (app *BaseApp) SetName(name string) { if app.sealed { panic("SetName() on sealed BaseApp") diff --git a/go.mod b/go.mod index a53ab64a29..39dfa665f8 100644 --- a/go.mod +++ b/go.mod @@ -169,9 +169,9 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0 - github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.2-alpha.2 + github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.2 github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 - github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1 + github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1 // Downgraded to avoid bugs in following commits which caused simulations to fail. // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index 7a0022ffc4..ea4d8e3b36 100644 --- a/go.sum +++ b/go.sum @@ -228,12 +228,12 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsy github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/greenfield-cometbft v0.0.2-alpha.2 h1:ys9kmgtRx04wcCextE6CrVmbL1bJDklWr+hWgm1y2k4= -github.com/bnb-chain/greenfield-cometbft v0.0.2-alpha.2/go.mod h1:EBmwmUdaNbGPyGjf1cMuoN3pAeM2tQu7Lfg95813EAw= +github.com/bnb-chain/greenfield-cometbft v0.0.2 h1:bRamS8Lq1lA3ttRLZBha22uiNG5tqN+diD3hapdUCYI= +github.com/bnb-chain/greenfield-cometbft v0.0.2/go.mod h1:EBmwmUdaNbGPyGjf1cMuoN3pAeM2tQu7Lfg95813EAw= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU= github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI= -github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1 h1:ZnIcvkkQVurg0OaAwmUGn2cK5bZbffjVChFyhh86HMk= -github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1/go.mod h1:oLksTs8dfh7DYIKBro7hbRQ+ewls7ghJ27pIXlbEXyI= +github.com/bnb-chain/greenfield-iavl v0.20.1 h1:y3L64GU99otNp27/xLVBTDbv4eroR6CzoYz0rbaVotM= +github.com/bnb-chain/greenfield-iavl v0.20.1/go.mod h1:oLksTs8dfh7DYIKBro7hbRQ+ewls7ghJ27pIXlbEXyI= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bombsimon/wsl/v3 v3.3.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= diff --git a/server/config/config.go b/server/config/config.go index 732d785ec0..27939deb7a 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -98,6 +98,9 @@ type BaseConfig struct { // AppDBBackend defines the type of Database to use for the application and snapshots databases. // An empty string indicates that the Tendermint config's DBBackend value should be used. AppDBBackend string `mapstructure:"app-db-backend"` + + // EnableUnsafeQuery enable/disable unsafe query apis. + EnableUnsafeQuery bool `mapstructure:"enable-unsafe-query"` } // APIConfig defines the API listener configuration. @@ -279,6 +282,7 @@ func DefaultConfig() *Config { IAVLDisableFastNode: false, IAVLLazyLoading: false, AppDBBackend: "", + EnableUnsafeQuery: false, }, Telemetry: telemetry.Config{ Enabled: false, diff --git a/server/config/toml.go b/server/config/toml.go index 7636434c0b..6c66a5a1d8 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -91,6 +91,10 @@ iavl-lazy-loading = {{ .BaseConfig.IAVLLazyLoading }} # Second fallback (if the types.DBBackend also isn't set), is the db-backend value set in Tendermint's config.toml. app-db-backend = "{{ .BaseConfig.AppDBBackend }}" +# EnableUnsafeQuery enables or disables the unsafe queries. +# Default is false. +enable-unsafe-query = "{{ .BaseConfig.EnableUnsafeQuery }}" + ############################################################################### ### Upgrade Configuration ### ############################################################################### diff --git a/server/start.go b/server/start.go index 2d387ba92e..dee5d2527f 100644 --- a/server/start.go +++ b/server/start.go @@ -60,6 +60,8 @@ const ( FlagDisableIAVLFastNode = "iavl-disable-fastnode" FlagIAVLLazyLoading = "iavl-lazy-loading" + FlagEnableUnsafeQuery = "enable-unsafe-query" + // state sync-related flags FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" FlagStateSyncSnapshotKeepRecent = "state-sync.snapshot-keep-recent" @@ -186,6 +188,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks") cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") cmd.Flags().String(FlagEventing, sdk.EventingOptionEverything, "Eventing strategy (everything|nothing)") + cmd.Flags().Bool(FlagEnableUnsafeQuery, false, "Define if unsafe query should be enabled (unsafe - use it at your own risk)") cmd.Flags().Bool(FlagAPIEnable, false, "Define if the API server should be enabled") cmd.Flags().Bool(FlagAPISwagger, false, "Define if swagger documentation should automatically be registered (Note: the API must also be enabled)") diff --git a/server/util.go b/server/util.go index ed37b5784e..d4798cbc78 100644 --- a/server/util.go +++ b/server/util.go @@ -498,6 +498,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { ), baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), baseapp.SetChainID(chainID), + baseapp.SetEnableUnsafeQuery(cast.ToBool(appOpts.Get(FlagEnableUnsafeQuery))), } } diff --git a/types/context.go b/types/context.go index 87c1ae5f6a..956765fc8d 100644 --- a/types/context.go +++ b/types/context.go @@ -44,6 +44,7 @@ type Context struct { upgradeChecker func(ctx Context, name string) bool txSize uint64 // The tx bytes length sigCache *lru.ARCCache + enableUnsafeQuery bool } // Proposed rename, not done to avoid API breakage @@ -76,6 +77,10 @@ func (c Context) IsUpgraded(name string) bool { return c.upgradeChecker(c, name) } +func (c Context) IsEnableUnsafeQuery() bool { + return c.enableUnsafeQuery +} + // clone the header before returning func (c Context) BlockHeader() tmproto.Header { msg := proto.Clone(&c.header).(*tmproto.Header) @@ -279,6 +284,12 @@ func (c Context) WithSigCache(cache *lru.ARCCache) Context { return c } +// WithEnableUnsafeQuery returns a Context with unsafe query enabled +func (c Context) WithEnableUnsafeQuery(enabled bool) Context { + c.enableUnsafeQuery = enabled + return c +} + // TODO: remove??? func (c Context) IsZero() bool { return c.ms == nil diff --git a/types/query/pagination.go b/types/query/pagination.go index 730741afc5..de984dd2f8 100644 --- a/types/query/pagination.go +++ b/types/query/pagination.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc/status" "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultPage is the default `page` number for queries. @@ -23,6 +24,14 @@ const DefaultLimit = 100 // which equals the maximum value that can be stored in uint64 const MaxLimit = math.MaxUint64 +// CheckOffsetQueryNotAllowed is used for checking query which offset/count total parameter is not allowed +func CheckOffsetQueryNotAllowed(ctx sdk.Context, req *PageRequest) error { + if req != nil && (req.Offset > 0 || req.CountTotal) && !ctx.IsEnableUnsafeQuery() { + return status.Error(codes.InvalidArgument, "query with offset/count total is not allowed") + } + return nil +} + // ParsePagination validate PageRequest and returns page number & limit. func ParsePagination(pageReq *PageRequest) (page, limit int, err error) { offset := 0 diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 04d4599769..306e1cce2d 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "encoding/hex" + "github.com/cosmos/cosmos-sdk/types/query" "sort" "testing" @@ -129,7 +130,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccounts() { numAccs := rapid.IntRange(1, 10).Draw(t, "accounts") accs := suite.createAndSetAccounts(t, numAccs) - req := &types.QueryAccountsRequest{Pagination: testdata.PaginationGenerator(t, uint64(numAccs)).Draw(t, "accounts")} + req := &types.QueryAccountsRequest{Pagination: &query.PageRequest{}} testdata.DeterministicIterations(suite.ctx, suite.Require(), req, suite.queryClient.Accounts, 0, true) for i := 0; i < numAccs; i++ { diff --git a/x/auth/keeper/grpc_query.go b/x/auth/keeper/grpc_query.go index 1fb96654d5..debd049271 100644 --- a/x/auth/keeper/grpc_query.go +++ b/x/auth/keeper/grpc_query.go @@ -45,6 +45,12 @@ func (ak AccountKeeper) Accounts(c context.Context, req *types.QueryAccountsRequ } ctx := sdk.UnwrapSDKContext(c) + + // offset query is not allowed + if err := query.CheckOffsetQueryNotAllowed(ctx, req.Pagination); err != nil { + return nil, err + } + store := ctx.KVStore(ak.storeKey) accountsStore := prefix.NewStore(store, types.AddressStoreKeyPrefix) diff --git a/x/evidence/keeper/grpc_query.go b/x/evidence/keeper/grpc_query.go index 369b38eab7..ed677d1756 100644 --- a/x/evidence/keeper/grpc_query.go +++ b/x/evidence/keeper/grpc_query.go @@ -62,7 +62,9 @@ func (k Keeper) AllEvidence(c context.Context, req *types.QueryAllEvidenceReques } ctx := sdk.UnwrapSDKContext(c) - k.GetAllEvidence(ctx) + if err := query.CheckOffsetQueryNotAllowed(ctx, req.Pagination); err != nil { + return nil, err + } var evidence []*codectypes.Any store := ctx.KVStore(k.storeKey) diff --git a/x/gashub/types/genesis.go b/x/gashub/types/genesis.go index 3a1458ba41..5a2a83cbd0 100644 --- a/x/gashub/types/genesis.go +++ b/x/gashub/types/genesis.go @@ -83,6 +83,7 @@ func DefaultGenesisState() *GenesisState { *NewMsgGasParamsWithFixedGas("/greenfield.sp.MsgDeposit", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.sp.MsgEditStorageProvider", 2e7), *NewMsgGasParamsWithFixedGas("/greenfield.sp.MsgUpdateSpStoragePrice", 2e7), + *NewMsgGasParamsWithFixedGas("/greenfield.sp.MsgUpdateStorageProviderStatus", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgCreateBucket", 2.4e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgDeleteBucket", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgMirrorBucket", 1.2e3), @@ -102,6 +103,7 @@ func DefaultGenesisState() *GenesisState { *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgLeaveGroup", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgUpdateGroupMember", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgUpdateGroupExtra", 1.2e3), + *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgRenewGroupMember", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgMirrorGroup", 1.2e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgPutPolicy", 2.4e3), *NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgDeletePolicy", 1.2e3), diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index d8cacbf4e0..c2942edb23 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -101,7 +101,8 @@ Where create_validator_proposal.json contains: "from": "0x7b5Fe22B5446f7C62Ea27B8BD71CeF94e03f3dF2", "relayer_address": "${RELAYER_ADDR}", "challenger_address": "${CHALLENGER_ADDR}", - "bls_key": "${VALIDATOR_BLS}" + "bls_key": "${VALIDATOR_BLS}", + "bls_proof": "${VALIDATOR_BLS_PROOF}" } ], "metadata": "", diff --git a/x/upgrade/types/upgrade_config.go b/x/upgrade/types/upgrade_config.go index e8ff84bc35..4e65fd6bf8 100644 --- a/x/upgrade/types/upgrade_config.go +++ b/x/upgrade/types/upgrade_config.go @@ -7,6 +7,9 @@ import ( const ( // EnablePublicDelegationUpgrade is the upgrade name for enabling public delegation EnablePublicDelegationUpgrade = "EnablePublicDelegationUpgrade" + + // Nagqu is the upgrade name for following features: + Nagqu = "Nagqu" ) // The default upgrade config for networks