-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
Codecov Report
@@ 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 |
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. |
9074212
to
163e628
Compare
I'm going to switch this PR to implement Option 2 from #2182 (comment). I think it makes the whole thing a lot cleaner. |
100dcd0
to
011e180
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.
Minor comments, substance looks fine.
x/stake/querier/queryable.go
Outdated
|
||
var redels []types.Redelegation | ||
|
||
if !params.DelegatorAddr.Empty() && !params.SrcValidatorAddr.Empty() && !params.DstValidatorAddr.Empty() { |
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.
Maybe a switch
would be easier to read here.
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.
++
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.
++
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.
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?
@jackzampolin I think the endpoint structure was resolved. Any other feedback? |
Did we get the documentation updated? Doesn't look like the |
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.
🍾 🥇 🐎
client/lcd/lcd_test.go
Outdated
endpoint := "/stake/redelegations?" | ||
|
||
if !delegatorAddr.Empty() { | ||
endpoint += fmt.Sprintf("delegator=%s&", delegatorAddr) |
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.
consider using https://golang.org/pkg/strings/#Builder
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.
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!
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 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.
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.
Let's hold off until our next meeting with this change
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.
/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.
client/lcd/lcd_test.go
Outdated
var res *http.Response | ||
var body string | ||
|
||
endpoint := "/stake/redelegations?" |
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 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
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.
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
.
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 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.
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.
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.
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.
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.
client/lcd/lcd_test.go
Outdated
@@ -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) |
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.
this should stay the same, see comment above
client/lcd/swagger-ui/swagger.yaml
Outdated
@@ -753,15 +753,25 @@ paths: | |||
description: Invalid delegator address | |||
500: | |||
description: Internal Server Error | |||
/stake/delegators/{delegatorAddr}/redelegations: | |||
/stake/redelegations: |
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.
why would you want to get all the redelegations in the state ? there's no use case for that
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.
Maybe not in Voyager? But that totally seems like something some block explorer might want.
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.
but you can still go through the list of validators and do that
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.
and through the /txs
endpoint
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.
and through the /txs endpoint
Either through that or with the GET /stake/validators/{validatorAddr}/redelegations
endpoint
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. |
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. |
@cwgoes This is failing build and has merge conflicts so we should get that fixed first too. |
OK. Maybe this merits a dedicated discussion between Voyager / SDK, lest we simply come to opposite conclusions in separate meetings. |
Something we can discuss next Tuesday @cwgoes ? |
This just needs a rebase then can be merged! |
Agreed. I personally think we should probably rethink these. |
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. |
@@ -16,11 +16,16 @@ BREAKING CHANGES | |||
FEATURES | |||
|
|||
* Gaia REST API (`gaiacli advanced rest-server`) | |||
* [gaia-lite] [\#2182] Added LCD endpoint for querying redelegations |
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.
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 |
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.
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. |
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.
?
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 explorerFor Admin Use: