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

Paginate supply queries #8798

Merged
merged 31 commits into from
Apr 6, 2021
Merged

Paginate supply queries #8798

merged 31 commits into from
Apr 6, 2021

Conversation

sahith-narahari
Copy link
Contributor

@sahith-narahari sahith-narahari commented Mar 5, 2021

Description

ref: #8761


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@lgtm-com
Copy link

lgtm-com bot commented Mar 5, 2021

This pull request introduces 1 alert when merging baef976 into 6520997 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@amaury1093
Copy link
Contributor

amaury1093 commented Mar 17, 2021

Hey @sahith-narahari, any progress on this PR? Is this r4r (even in draft)?

@orijbot
Copy link

orijbot commented Mar 19, 2021

@orijbot
Copy link

orijbot commented Mar 19, 2021

@orijbot
Copy link

orijbot commented Mar 19, 2021

@orijbot
Copy link

orijbot commented Mar 19, 2021

@orijbot
Copy link

orijbot commented Mar 19, 2021

@@ -50,7 +51,11 @@ func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant {
func TotalSupply(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
expectedTotal := sdk.Coins{}
supply := k.GetTotalSupply(ctx)
supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AmauryM do you think we should have empty page request or use alternative defaults

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 we can keep calling GetTotalSupply, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel it's better not to expose the method, not a strong opinion though. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel it's better not to expose the method

Not sure I understand. GetTotalSupply still exists in the keeper. Should we actually remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I'm in favour of removing it.

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

lgtm overall!

@@ -50,7 +51,11 @@ func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant {
func TotalSupply(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
expectedTotal := sdk.Coins{}
supply := k.GetTotalSupply(ctx)
supply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
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 we can keep calling GetTotalSupply, no?

Copy link
Contributor

@fdymylja fdymylja left a comment

Choose a reason for hiding this comment

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

lgtm, changelog is missing

@clevinson clevinson linked an issue Mar 22, 2021 that may be closed by this pull request
6 tasks
@sahith-narahari
Copy link
Contributor Author

@aaronc if we use paginations for internal queries, I feel we're increasing complexity as the number of iterations for the pagination increase. Whereas using GetTotalSupply fetches values in one interation over the store. Is there any particular case you see where pagination helps even for internal functions?

cc @jgimeno @AmauryM

@orijbot
Copy link

orijbot commented Mar 29, 2021

@cyberbono3 cyberbono3 self-requested a review March 31, 2021 00:23
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

if we use paginations for internal queries, I feel we're increasing complexity as the number of iterations for the pagination increase. Whereas using GetTotalSupply fetches values in one interation over the store.

From my understanding, GetTotalSupply == GetPaginatedTotalSupply(PageRequest{Limit: max_uint64}). If that's correct, then I think we can keep GetTotalSupply deleted.

Blocking because @jgimeno's comment needs to be fixed #8798 (comment)

supply := sdk.NewCoins()

pageRes, err := query.Paginate(supplyStore, pagination, func(key, value []byte) error {
amount, ok := sdk.NewIntFromString(string(value))
Copy link
Collaborator

Choose a reason for hiding this comment

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

?? why the amount is stored as a string??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fwiu it's because sdk.Int doesn't implement proto message. @jgimeno should know better

Copy link
Collaborator

Choose a reason for hiding this comment

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

but it has Bytes() tho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, opened a pr for this #9051

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

LGTM, except that we should probably wait for #9051, right? (ref: #8798 (comment))

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

nice 🎉

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Apr 6, 2021
@mergify mergify bot merged commit 0effd3a into master Apr 6, 2021
@mergify mergify bot deleted the sahith/paginate-supply branch April 6, 2021 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paginate supply and balances methods
9 participants