From a26e92963ab2c6c70d017c4da3d22d65655a0752 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 5 May 2023 13:15:00 +0200 Subject: [PATCH 1/3] make max limit a variable --- types/query/pagination.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/query/pagination.go b/types/query/pagination.go index 3eeb3a297aec..0746fde73f16 100644 --- a/types/query/pagination.go +++ b/types/query/pagination.go @@ -21,7 +21,7 @@ const DefaultLimit = 100 // MaxLimit is the maximum limit the paginate function can handle // which equals the maximum value that can be stored in uint64 -const MaxLimit = math.MaxUint64 +var MaxLimit uint64 = math.MaxUint64 // ParsePagination validate PageRequest and returns page number & limit. func ParsePagination(pageReq *PageRequest) (page, limit int, err error) { From 766c117b8276db0f0531533277ac130a036cf9b2 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 5 May 2023 16:01:26 +0200 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 1 + types/query/pagination.go | 4 ++-- x/bank/keeper/genesis.go | 2 +- x/bank/keeper/genesis_test.go | 6 +++--- x/bank/keeper/invariants.go | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b0a16134260..1b2047d56ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/consensus) [#15553](https://github.com/cosmos/cosmos-sdk/pull/15553) Migrate consensus module to use collections * (x/bank) [#15764](https://github.com/cosmos/cosmos-sdk/pull/15764) Speedup x/bank InitGenesis * (x/auth) [#15867](https://github.com/cosmos/cosmos-sdk/pull/15867) Support better logging for signature verification failure. +* (types/query) [#16041](https://github.com/cosmos/cosmos-sdk/pull/16041) change pagination max limit to a variable in order to be modifed by application devs ### State Machine Breaking diff --git a/types/query/pagination.go b/types/query/pagination.go index 0746fde73f16..22fcead51f4f 100644 --- a/types/query/pagination.go +++ b/types/query/pagination.go @@ -19,9 +19,9 @@ const DefaultPage = 1 // if the `limit` is not supplied, paginate will use `DefaultLimit` const DefaultLimit = 100 -// MaxLimit is the maximum limit the paginate function can handle +// PAGINATION_MAX_LIMIT is the maximum limit the paginate function can handle // which equals the maximum value that can be stored in uint64 -var MaxLimit uint64 = math.MaxUint64 +var PAGINATION_MAX_LIMIT uint64 = math.MaxUint64 // ParsePagination validate PageRequest and returns page number & limit. func ParsePagination(pageReq *PageRequest) (page, limit int, err error) { diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index eaee07c4843d..e4d3b524c4b1 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -53,7 +53,7 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat // ExportGenesis returns the bank module's genesis state. func (k BaseKeeper) ExportGenesis(ctx context.Context) *types.GenesisState { - totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit}) + totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) if err != nil { panic(fmt.Errorf("unable to fetch total supply %v", err)) } diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index ac04a6232c7a..d2326d830514 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -16,7 +16,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { expectedBalances, expTotalSupply := suite.getTestBalancesAndSupply() // Adding genesis supply to the expTotalSupply - genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) suite.Require().NoError(err) expTotalSupply = expTotalSupply.Add(genesisSupply...) @@ -85,7 +85,7 @@ func (suite *KeeperTestSuite) TestTotalSupply() { } totalSupply := sdk.NewCoins(sdk.NewCoin("foocoin", sdkmath.NewInt(11)), sdk.NewCoin("barcoin", sdkmath.NewInt(21))) - genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) suite.Require().NoError(err) testcases := []struct { @@ -119,7 +119,7 @@ func (suite *KeeperTestSuite) TestTotalSupply() { suite.PanicsWithError(tc.expPanicMsg, func() { suite.bankKeeper.InitGenesis(suite.ctx, tc.genesis) }) } else { suite.bankKeeper.InitGenesis(suite.ctx, tc.genesis) - totalSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit}) + totalSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) suite.Require().NoError(err) // adding genesis supply to expected supply diff --git a/x/bank/keeper/invariants.go b/x/bank/keeper/invariants.go index 5db22af69f81..1859adac1e72 100644 --- a/x/bank/keeper/invariants.go +++ b/x/bank/keeper/invariants.go @@ -51,7 +51,7 @@ func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant { func TotalSupply(k Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { expectedTotal := sdk.Coins{} - supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit}) + supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) if err != nil { return sdk.FormatInvariant(types.ModuleName, "query supply", fmt.Sprintf("error querying total supply %v", err)), false From d23456ab9dcbe61688d5dc53807f7d8f02f65582 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sun, 7 May 2023 12:21:08 +0200 Subject: [PATCH 3/3] linting --- types/query/pagination.go | 4 ++-- x/bank/keeper/genesis.go | 2 +- x/bank/keeper/genesis_test.go | 6 +++--- x/bank/keeper/invariants.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/query/pagination.go b/types/query/pagination.go index 22fcead51f4f..61e3c0679e50 100644 --- a/types/query/pagination.go +++ b/types/query/pagination.go @@ -19,9 +19,9 @@ const DefaultPage = 1 // if the `limit` is not supplied, paginate will use `DefaultLimit` const DefaultLimit = 100 -// PAGINATION_MAX_LIMIT is the maximum limit the paginate function can handle +// PaginationMaxLimit is the maximum limit the paginate function can handle // which equals the maximum value that can be stored in uint64 -var PAGINATION_MAX_LIMIT uint64 = math.MaxUint64 +var PaginationMaxLimit uint64 = math.MaxUint64 // ParsePagination validate PageRequest and returns page number & limit. func ParsePagination(pageReq *PageRequest) (page, limit int, err error) { diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index e4d3b524c4b1..a74208b05b7d 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -53,7 +53,7 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat // ExportGenesis returns the bank module's genesis state. func (k BaseKeeper) ExportGenesis(ctx context.Context) *types.GenesisState { - totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) + totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PaginationMaxLimit}) if err != nil { panic(fmt.Errorf("unable to fetch total supply %v", err)) } diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index d2326d830514..251f0180ba99 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -16,7 +16,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() { expectedBalances, expTotalSupply := suite.getTestBalancesAndSupply() // Adding genesis supply to the expTotalSupply - genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) + genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PaginationMaxLimit}) suite.Require().NoError(err) expTotalSupply = expTotalSupply.Add(genesisSupply...) @@ -85,7 +85,7 @@ func (suite *KeeperTestSuite) TestTotalSupply() { } totalSupply := sdk.NewCoins(sdk.NewCoin("foocoin", sdkmath.NewInt(11)), sdk.NewCoin("barcoin", sdkmath.NewInt(21))) - genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) + genesisSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PaginationMaxLimit}) suite.Require().NoError(err) testcases := []struct { @@ -119,7 +119,7 @@ func (suite *KeeperTestSuite) TestTotalSupply() { suite.PanicsWithError(tc.expPanicMsg, func() { suite.bankKeeper.InitGenesis(suite.ctx, tc.genesis) }) } else { suite.bankKeeper.InitGenesis(suite.ctx, tc.genesis) - totalSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) + totalSupply, _, err := suite.bankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.PaginationMaxLimit}) suite.Require().NoError(err) // adding genesis supply to expected supply diff --git a/x/bank/keeper/invariants.go b/x/bank/keeper/invariants.go index 1859adac1e72..72240a1ac387 100644 --- a/x/bank/keeper/invariants.go +++ b/x/bank/keeper/invariants.go @@ -51,7 +51,7 @@ func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant { func TotalSupply(k Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { expectedTotal := sdk.Coins{} - supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PAGINATION_MAX_LIMIT}) + supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.PaginationMaxLimit}) if err != nil { return sdk.FormatInvariant(types.ModuleName, "query supply", fmt.Sprintf("error querying total supply %v", err)), false