-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
R4R: Querier - Get all delegations to validator #2565
Conversation
Codecov Report
@@ 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 |
There was a problem hiding this 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
There was a problem hiding this 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 👍
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. |
I’d instead remove every line that has to do with redelegation to avoid blocking this PR from being merged |
There was a problem hiding this 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
8cf3e23
to
9961f64
Compare
@sunnya97 status on this ? |
0d76f0f
to
4c3ac3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK.
There was a problem hiding this 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
Co-Authored-By: sunnya97 <[email protected]>
There was a problem hiding this 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
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() |
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split this line up?
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
@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? |
@rigelrozanski it'll be useful to have this endpoint. Check this use case from voyager: https://github.com/cosmos/voyager/issues/1015 |
We need a |
…/github.com/cosmos/cosmos-sdk into sunny/get_all_delegations_validator_querier Merge
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 explorerFor Admin Use: