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

R4R: Querier - Get all delegations to validator #2565

Merged
merged 19 commits into from
Nov 13, 2018

Conversation

sunnya97
Copy link
Member

@sunnya97 sunnya97 commented Oct 23, 2018

closes #2027

  • 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.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added entries in PENDING.md with issue #

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Oct 23, 2018

Codecov Report

Merging #2565 into develop will increase coverage by 0.09%.
The diff coverage is 87.09%.

@@             Coverage Diff             @@
##           develop    #2565      +/-   ##
===========================================
+ Coverage    56.65%   56.75%   +0.09%     
===========================================
  Files          156      156              
  Lines         9783     9814      +31     
===========================================
+ Hits          5543     5570      +27     
- Misses        3863     3865       +2     
- Partials       377      379       +2

@sunnya97 sunnya97 changed the title WIP: Querier - Get all delegations to validator R4R: Querier - Get all delegations to validator Oct 23, 2018
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Thanks @sunnya97 ! let's add the command to the docs so we don't forget later on. Also the single redelegation query is still under discussion so I'd leave it for another PR

x/stake/querier/queryable.go Outdated Show resolved Hide resolved
x/stake/querier/queryable.go Outdated Show resolved Hide resolved
x/stake/querier/queryable.go Outdated Show resolved Hide resolved
x/stake/querier/queryable.go Outdated Show resolved Hide resolved
x/stake/client/cli/query.go Show resolved Hide resolved
x/stake/keeper/delegation.go Outdated Show resolved Hide resolved
x/stake/querier/queryable_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks @sunnya97 -- left some minor feedback 👍

cmd/gaia/cmd/gaiacli/main.go Outdated Show resolved Hide resolved
x/stake/client/cli/query.go Show resolved Hide resolved
x/stake/querier/queryable.go Outdated Show resolved Hide resolved
x/stake/keeper/delegation.go Outdated Show resolved Hide resolved
@sunnya97
Copy link
Member Author

sunnya97 commented Oct 23, 2018

Oops, I probably accidentally branched off my redelegations PR instead of develop. Let's get that one merged to develop first, then I'll rebase this off of develop and fix any conflicts.

@fedekunze
Copy link
Collaborator

I’d instead remove every line that has to do with redelegation to avoid blocking this PR from being merged

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

utACK. Need to resolve/address @alexanderbez's renaming suggestions

@sunnya97 sunnya97 force-pushed the sunny/get_all_delegations_validator_querier branch from 8cf3e23 to 9961f64 Compare October 23, 2018 20:42
@fedekunze
Copy link
Collaborator

fedekunze commented Oct 24, 2018

@sunnya97 can you add the cmd to docs/sdk/clients.md ? (see 905718f for reference).

Also it'd be cool if you could add a test case for keeper.GetValidatorDelegations to increase coverage

@fedekunze
Copy link
Collaborator

@sunnya97 status on this ?

@sunnya97 sunnya97 force-pushed the sunny/get_all_delegations_validator_querier branch from 0d76f0f to 4c3ac3f Compare November 4, 2018 05:58
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

utACK.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK - leaving to @jaekwon to merge

x/stake/client/rest/query.go Outdated Show resolved Hide resolved
x/stake/keeper/delegation_test.go Outdated Show resolved Hide resolved
fedekunze and others added 2 commits November 5, 2018 16:42
Co-Authored-By: sunnya97 <sunnya97@gmail.com>
Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

So the code looks good (few minor comments)
but I am wondering why we want this function at all. It's an extra query which might be nice to have I suppose however I can't see any protocol reason as to why we would ever need to know the list of all delegators for a validator, which was why this was never included to begin with. So I mean I'm okay with the idea of having it, but I want us to really consider whether or not we need this code, and maybe drop it if it doesn't seem absolutely necessary to have

x/stake/client/cli/query.go Outdated Show resolved Hide resolved
func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, DelegationKey)
defer iterator.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

because this is such a simple function, we should probably just close the iterator after the for loop and avoid using a defer call


res, errRes = codec.MarshalJSONIndent(cdc, delegations)
if errRes != nil {
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

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

split this line up?

x/stake/querier/queryable.go Show resolved Hide resolved
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

🍫 🍵

@@ -1206,6 +1210,17 @@ func getValidator(t *testing.T, port string, validatorAddr sdk.ValAddress) stake
return validator
}

func getValidatorDelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.Delegation {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/delegations", validatorAddr.String()), 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 feel like there should be a helper function like StakeValidatorsDelegationsPath(validatorAddr.String())

https://guides.rubyonrails.org/routing.html#path-and-url-helpers

In Ruby, you can use magic to create such functions on the fly. In Go, we'd need to write them ourselves. Still, there may be a benefit in having them.

@sunnya97
Copy link
Member Author

sunnya97 commented Nov 8, 2018

@rigelrozanski This seems like a very useful query for a validator to know what delegations there are to him. Maybe they want to build a UI interface specifically for their delegators?

@fedekunze
Copy link
Collaborator

@rigelrozanski it'll be useful to have this endpoint. Check this use case from voyager: https://github.com/cosmos/voyager/issues/1015

@jackzampolin
Copy link
Member

We need a swagger.yaml update to add the new route here @sunnya97

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 cmd and endpoints to get validator delegations
7 participants