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: Redelegation Querier #2559

Merged
merged 17 commits into from
Dec 18, 2018
Merged

R4R: Redelegation Querier #2559

merged 17 commits into from
Dec 18, 2018

Conversation

sunnya97
Copy link
Member

@sunnya97 sunnya97 commented Oct 23, 2018

closes #2182

  • 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 #2559 into develop will decrease coverage by 0.01%.
The diff coverage is 76.78%.

@@             Coverage Diff             @@
##           develop    #2559      +/-   ##
===========================================
- Coverage    55.05%   55.04%   -0.02%     
===========================================
  Files          133      133              
  Lines         9430     9438       +8     
===========================================
+ Hits          5192     5195       +3     
- Misses        3921     3923       +2     
- Partials       317      320       +3

@sunnya97 sunnya97 changed the title WIP: Redelegation Querier R4R: Redelegation Querier Oct 23, 2018
@jackzampolin
Copy link
Member

Let's push some of that REALLY LONG URL into query params. I think there has been some conversation on the issue to reflect this.

client/lcd/lcd_test.go Outdated Show resolved Hide resolved
@sunnya97 sunnya97 force-pushed the sunny/redelegationquerier branch from 9074212 to 163e628 Compare October 23, 2018 20:06
@sunnya97
Copy link
Member Author

sunnya97 commented Oct 23, 2018

I'm going to switch this PR to implement Option 2 from #2182 (comment).

I think it makes the whole thing a lot cleaner.

@sunnya97 sunnya97 force-pushed the sunny/redelegationquerier branch from 100dcd0 to 011e180 Compare November 4, 2018 06:02
@sunnya97 sunnya97 requested a review from jaekwon as a code owner November 4, 2018 06:02
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.

Minor comments, substance looks fine.

x/stake/keeper/query_utils.go Outdated Show resolved Hide resolved
x/stake/keeper/query_utils.go Outdated Show resolved Hide resolved

var redels []types.Redelegation

if !params.DelegatorAddr.Empty() && !params.SrcValidatorAddr.Empty() && !params.DstValidatorAddr.Empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a switch would be easier to read here.

Copy link
Contributor

Choose a reason for hiding this comment

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

++

Copy link
Contributor

Choose a reason for hiding this comment

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

++

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, it's three different options that are being checked in weird configs

if !option1 && !option2 && !option3

else if option1 && !option2 && option 3

else

How do I write that cleanly in a switch statement? 3 tiered switch statements?

x/stake/client/rest/query.go Show resolved Hide resolved
@alexanderbez
Copy link
Contributor

@jackzampolin I think the endpoint structure was resolved. Any other feedback?

@jackzampolin
Copy link
Member

Did we get the documentation updated? Doesn't look like the swagger.yaml file got entries added for these new routes yet.

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.

🍾 🥇 🐎

endpoint := "/stake/redelegations?"

if !delegatorAddr.Empty() {
endpoint += fmt.Sprintf("delegator=%s&", delegatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm interesting - yeah seems like it would make the code a bit smaller - but I don't see builders often so might just be more confusing for new devs... but then again maybe we should all learn!

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in this situation, it is simple enough that we can just use the += for the test. But I agree, in more important places, where we want to reduce memory copying, a String builder is good to use.

x/stake/client/rest/utils.go Show resolved Hide resolved
x/stake/client/rest/utils.go Show resolved Hide resolved
Copy link
Contributor

@faboweb faboweb left a comment

Choose a reason for hiding this comment

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

Let's hold off until our next meeting with this change

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.

/stake/validators/{validatorAddr}/redelegations and /stake/delegators/{validatorAddr}/redelegations should stay the same, and we should only add query params to the latter. Alternativerly we could add query params for outgoing or incoming redelegations to the validator redelegations endpoint.

var res *http.Response
var body string

endpoint := "/stake/redelegations?"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think this is a terrible design, we should only add the query parameters to /stake/delegators/{delegatorAddr}/redelegations, not changing the current structure. cc: @faboweb

Copy link
Member Author

@sunnya97 sunnya97 Nov 30, 2018

Choose a reason for hiding this comment

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

The thing I don't like about /stake/delegators/{delegatorAddr}/redelegations is that it's trying to put a fake structure on data that is not actually structured like in the state. Redelegations are not attributes of a delegator, but rather delegator, srcValidator, and dstValidator are attributes of a redelegation.

Copy link
Member

Choose a reason for hiding this comment

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

I would agree with @fedekunze here. I don't think how we have the data structured internally matters to users. Presenting the data in a way that is logically consistent (delegators have redelegations) is a great idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

What are /stake/delegators/<>/redelegations vs /stake/validators/<>/redelegations?

I think over-emphasis on the URL design of API endpoints often leads to premature design constraints that end up causing more headache down the line. It is simpler to model the API after what is modeled in the implementation.

REST isn't just about pretty URLs... there's nothing wrong with query parameters, esp given a context where we will want to provide filters etc. I favor Sunny's approach here, it's faster to execute and less brittle going into the future.

The end users here are developers who can deal with query parameters. We're not talking about website URLs, which is a different story.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is simpler to model the API after what is modeled in the implementation.

I think simple to implement is not what we want with an API. An API should be consistent for quiet some time so developers don't need to adjust to constant changes (this is frustrating from experience). We should come up with a design that reflects the expectation of the developers that want to use the API. Let's invite more of them to stakeholder meetings and discuss together with them the API design.

@@ -1254,17 +1273,6 @@ func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr s
return ubds
}

func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.Redelegation {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/redelegations", validatorAddr.String()), nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should stay the same, see comment above

@@ -753,15 +753,25 @@ paths:
description: Invalid delegator address
500:
description: Internal Server Error
/stake/delegators/{delegatorAddr}/redelegations:
/stake/redelegations:
Copy link
Collaborator

Choose a reason for hiding this comment

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

why would you want to get all the redelegations in the state ? there's no use case for that

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe not in Voyager? But that totally seems like something some block explorer might want.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but you can still go through the list of validators and do that

Copy link
Contributor

Choose a reason for hiding this comment

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

and through the /txs endpoint

Copy link
Collaborator

Choose a reason for hiding this comment

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

and through the /txs endpoint

Either through that or with the GET /stake/validators/{validatorAddr}/redelegations endpoint

@cwgoes
Copy link
Contributor

cwgoes commented Dec 12, 2018

Checking on this PR, I think we had come to the conclusion to leave the endpoints as-is.

@sunnya97 Am I right? Should we dismiss the outstanding reviews and merge this?

cc also @fedekunze @faboweb - we're not trying to make Voyager's life terrible, but we think structuring the REST like you describe will lead to confusion, because that's not how the underlying data is related.

@fedekunze
Copy link
Collaborator

fedekunze commented Dec 12, 2018

because that's not how the underlying data is related

That might be the case, but then then most of the endpoints we've implemented and discussed multiple times on #2113 and on the individual issues will fall under the same argument.

@jackzampolin
Copy link
Member

@cwgoes This is failing build and has merge conflicts so we should get that fixed first too.

@cwgoes
Copy link
Contributor

cwgoes commented Dec 12, 2018

That might be the case, but then then most of the endpoints we've implemented and discussed multiple times on #2113 and on the individual issues will fall under the same argument.

OK. Maybe this merits a dedicated discussion between Voyager / SDK, lest we simply come to opposite conclusions in separate meetings.

@alexanderbez
Copy link
Contributor

Something we can discuss next Tuesday @cwgoes ?

@fedekunze fedekunze dismissed their stale review December 12, 2018 18:40

discussed on SDK <> Voyager meeting

@jackzampolin
Copy link
Member

This just needs a rebase then can be merged!

@cwgoes cwgoes dismissed faboweb’s stale review December 13, 2018 11:22

Discussed at SDK-Voyager meeting.

@sunnya97
Copy link
Member Author

That might be the case, but then then most of the endpoints we've implemented and discussed multiple times on #2113 and on the individual issues will fall under the same argument.

Agreed. I personally think we should probably rethink these.

@faboweb
Copy link
Contributor

faboweb commented Dec 17, 2018

structuring the REST like you describe will lead to confusion, because that's not how the underlying data is related

this is actually the purpose! the API does not reflect the underlying data structure as it serves the purpose of making the data understandable and convenient to use. Imo the API should reflect more the use-cases of the people using it.

@jackzampolin jackzampolin merged commit f4fb360 into develop Dec 18, 2018
@jackzampolin jackzampolin deleted the sunny/redelegationquerier branch December 18, 2018 21:43
@@ -16,11 +16,16 @@ BREAKING CHANGES
FEATURES

* Gaia REST API (`gaiacli advanced rest-server`)
* [gaia-lite] [\#2182] Added LCD endpoint for querying redelegations
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should have been in breaking changes cc: @sunnya97 @jackzampolin. I'll update it

@@ -16,11 +16,16 @@ BREAKING CHANGES
FEATURES

* Gaia REST API (`gaiacli advanced rest-server`)
* [gaia-lite] [\#2182] Added LCD endpoint for querying redelegations
* [gov] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance parameter
Copy link
Collaborator

Choose a reason for hiding this comment

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

not related to this PR

@@ -16,11 +16,16 @@ BREAKING CHANGES
FEATURES

* Gaia REST API (`gaiacli advanced rest-server`)
* [gaia-lite] [\#2182] Added LCD endpoint for querying redelegations
* [gov] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance parameter
query REST endpoints.
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

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 GET redelegation endpoint and querier
9 participants