Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: don't cap page size in unsafe mode #6329

Merged
merged 5 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
### FEATURES

- [config] Add `--mode` flag and config variable. See [ADR-52](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-052-tendermint-mode.md) @dongsam
- [rpc] /#6329 Don't cap page size in unsafe mode (@gotjoshua, @cmwaters)

### IMPROVEMENTS

Expand Down
4 changes: 3 additions & 1 deletion rpc/core/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func validatePerPage(perPagePtr *int) int {
perPage := *perPagePtr
if perPage < 1 {
return defaultPerPage
} else if perPage > maxPerPage {
// in unsafe mode there is no max on the page size but in safe mode
// we cap it to maxPerPage
} else if perPage > maxPerPage && !env.Config.Unsafe {
return maxPerPage
}
return perPage
Expand Down
22 changes: 14 additions & 8 deletions rpc/core/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ func TestPaginationPage(t *testing.T) {

func TestPaginationPerPage(t *testing.T) {
cases := []struct {
totalCount int
perPage int
newPerPage int
}{
{5, 0, defaultPerPage},
{5, 1, 1},
{5, 2, 2},
{5, defaultPerPage, defaultPerPage},
{5, maxPerPage - 1, maxPerPage - 1},
{5, maxPerPage, maxPerPage},
{5, maxPerPage + 1, maxPerPage},
{0, defaultPerPage},
{1, 1},
{2, 2},
{defaultPerPage, defaultPerPage},
{maxPerPage - 1, maxPerPage - 1},
{maxPerPage, maxPerPage},
{maxPerPage + 1, maxPerPage},
}

for _, c := range cases {
Expand All @@ -79,4 +78,11 @@ func TestPaginationPerPage(t *testing.T) {
// nil case
p := validatePerPage(nil)
assert.Equal(t, defaultPerPage, p)

// test in unsafe mode
env.Config.Unsafe = true
perPage := 1000
p = validatePerPage(&perPage)
assert.Equal(t, perPage, p)
env.Config.Unsafe = false
}