Skip to content

Commit

Permalink
chore: make max limit a variable (cosmos#16041)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored and rllola committed May 11, 2023
1 parent c5d55fb commit 5cc0d79
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions types/query/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// PaginationMaxLimit 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 PaginationMaxLimit uint64 = math.MaxUint64

// ParsePagination validate PageRequest and returns page number & limit.
func ParsePagination(pageReq *PageRequest) (page, limit int, err error) {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.PaginationMaxLimit})
if err != nil {
panic(fmt.Errorf("unable to fetch total supply %v", err))
}
Expand Down
6 changes: 3 additions & 3 deletions x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.PaginationMaxLimit})
suite.Require().NoError(err)
expTotalSupply = expTotalSupply.Add(genesisSupply...)

Expand Down Expand Up @@ -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.PaginationMaxLimit})
suite.Require().NoError(err)

testcases := []struct {
Expand Down Expand Up @@ -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.PaginationMaxLimit})
suite.Require().NoError(err)

// adding genesis supply to expected supply
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.PaginationMaxLimit})
if err != nil {
return sdk.FormatInvariant(types.ModuleName, "query supply",
fmt.Sprintf("error querying total supply %v", err)), false
Expand Down

0 comments on commit 5cc0d79

Please sign in to comment.