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

feat: add pagination to sensitive endpoints #1601

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

zale144
Copy link
Contributor

@zale144 zale144 commented Dec 2, 2024

Description


Closes #1591

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here


For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

@zale144 zale144 self-assigned this Dec 2, 2024
@zale144 zale144 requested a review from a team as a code owner December 2, 2024 18:45
keruch
keruch previously approved these changes Dec 3, 2024
Copy link
Contributor

@keruch keruch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job! left just a few minor comments

Comment on lines 82 to 99
// GetPendingPacketsByAddressPaginated retrieves rollapp packets from the KVStore by their receiver with pagination.
func (k Keeper) GetPendingPacketsByAddressPaginated(ctx sdk.Context, receiver string, pageReq *query.PageRequest) (packets []commontypes.RollappPacket, pageResp *query.PageResponse, err error) {
_, pageResp, err = collcompat.CollectionPaginate(ctx, k.pendingPacketsByAddress, pageReq,
func(key collections.Pair[string, []byte], _ collections.NoValue) (bool, error) {
packet, err := k.GetRollappPacket(ctx, string(key.K2()))
if err != nil {
return true, err
}
packets = append(packets, *packet)
return false, nil
}, collcompat.WithCollectionPaginationPairPrefix[string, []byte](receiver),
)
if err != nil {
return nil, nil, err
}

return packets, pageResp, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simpler. you can directly return commontypes.RollappPacket in transformFunc while paginating.

Suggested change
// GetPendingPacketsByAddressPaginated retrieves rollapp packets from the KVStore by their receiver with pagination.
func (k Keeper) GetPendingPacketsByAddressPaginated(ctx sdk.Context, receiver string, pageReq *query.PageRequest) (packets []commontypes.RollappPacket, pageResp *query.PageResponse, err error) {
_, pageResp, err = collcompat.CollectionPaginate(ctx, k.pendingPacketsByAddress, pageReq,
func(key collections.Pair[string, []byte], _ collections.NoValue) (bool, error) {
packet, err := k.GetRollappPacket(ctx, string(key.K2()))
if err != nil {
return true, err
}
packets = append(packets, *packet)
return false, nil
}, collcompat.WithCollectionPaginationPairPrefix[string, []byte](receiver),
)
if err != nil {
return nil, nil, err
}
return packets, pageResp, nil
}
// GetPendingPacketsByAddressPaginated retrieves rollapp packets from the KVStore by their receiver with pagination.
func (k Keeper) GetPendingPacketsByAddressPaginated(ctx sdk.Context, receiver string, pageReq *query.PageRequest) ([]commontypes.RollappPacket, *query.PageResponse, error) {
return collcompat.CollectionPaginate(ctx, k.pendingPacketsByAddress, pageReq,
func(key collections.Pair[string, []byte], _ collections.NoValue) (commontypes.RollappPacket, error) {
packet, err := k.GetRollappPacket(ctx, string(key.K2()))
return *packet, err
}, collcompat.WithCollectionPaginationPairPrefix[string, []byte](receiver),
)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packet, err := k.GetRollappPacket(ctx, string(key.K2()))
return *packet, err

packet could be nil though

Comment on lines 21 to 32
func (k Keeper) GetAllRegisteredDenomsPaginated(ctx sdk.Context, rollappID string, pageReq *query.PageRequest) ([]string, *query.PageResponse, error) {
denoms, pageRes, err := collcompat.CollectionPaginate(ctx, k.registeredRollappDenoms, pageReq,
func(key collections.Pair[string, string], _ collections.NoValue) (string, error) {
return key.K1(), nil
}, collcompat.WithCollectionPaginationPairPrefix[string, string](rollappID),
)
if err != nil {
return nil, nil, fmt.Errorf("paginate registered denoms: %w", err)
}

return denoms, pageRes, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can skip the error check here

Suggested change
func (k Keeper) GetAllRegisteredDenomsPaginated(ctx sdk.Context, rollappID string, pageReq *query.PageRequest) ([]string, *query.PageResponse, error) {
denoms, pageRes, err := collcompat.CollectionPaginate(ctx, k.registeredRollappDenoms, pageReq,
func(key collections.Pair[string, string], _ collections.NoValue) (string, error) {
return key.K1(), nil
}, collcompat.WithCollectionPaginationPairPrefix[string, string](rollappID),
)
if err != nil {
return nil, nil, fmt.Errorf("paginate registered denoms: %w", err)
}
return denoms, pageRes, nil
}
func (k Keeper) GetAllRegisteredDenomsPaginated(ctx sdk.Context, rollappID string, pageReq *query.PageRequest) ([]string, *query.PageResponse, error) {
return collcompat.CollectionPaginate(ctx, k.registeredRollappDenoms, pageReq,
func(key collections.Pair[string, string], _ collections.NoValue) (string, error) {
return key.K1(), nil
}, collcompat.WithCollectionPaginationPairPrefix[string, string](rollappID),
)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't I think of that

@keruch
Copy link
Contributor

keruch commented Dec 3, 2024

also, tests and linter are failing

@omritoptix omritoptix merged commit df0a417 into main Dec 3, 2024
5 checks passed
@omritoptix omritoptix deleted the zale144/1591-paginateify-DOSable-list-queries branch December 3, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add paginations to Dosable queries
3 participants