-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: generalize query response with height #4573
R4R: generalize query response with height #4573
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4573 +/- ##
==========================================
+ Coverage 52.65% 52.66% +0.01%
==========================================
Files 261 261
Lines 16410 16410
==========================================
+ Hits 8640 8642 +2
+ Misses 7124 7122 -2
Partials 646 646 |
Codecov Report
@@ Coverage Diff @@
## master #4573 +/- ##
=========================================
+ Coverage 53.62% 53.72% +0.1%
=========================================
Files 260 260
Lines 16177 16197 +20
=========================================
+ Hits 8675 8702 +27
+ Misses 6856 6846 -10
- Partials 646 649 +3 |
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'd appreciate some test cases
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 is API breaking for all endpoints that will do this. Is this intended? If so, we must make sure swagger is also updated.
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.
Tested. There is nothing that actually sets the height @colin-axner.
e.g.
res, _, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs)
if err != nil {
return nil, err
}
Where do we set the height when returning the result?
@alexanderbez ohh yea... There are a few other places this happens as well where a helper function does the data retrieval and just returns the result/error. Seems to me, if you want height to be returned in a response, then it it needs to be passed all the way down to the client. This would mean changing GetAccount to return height, as well as any other data retrieval functions to always return |
@colin-axner not sure I completely follow, but this is what needs to happen I think:
res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cliCtx, res) Now becomes: res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res) I know (2) will be a huge PIA, but this is how we get the responses to have the height. Does this make sense? |
@alexanderbez Both those have been done, I think the issue is here where you have: account, err := accGetter.GetAccount(addr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cliCtx, account) because |
@colin-axner phenomenal, just checked and you're correct -- my mistake! Wrt to the account query, I guess this is a special case huh? No biggie, let's update |
@alexanderbez updated, the only issue is not all of the gov endpoints will return the query height. I can't find a work around for querying with tags without rewriting a lot of code. If these endpoints query for a specific height then the height will be included in the response. If they are querying using the latest height then the height won't be included because it is not set. Specifically in QueryByTxsTags can't return height because: resTxs, err := node.TxSearch(query, prove, page, limit)
if err != nil {
return nil, err
} does not return height. Furthermore, a lot of the gov endpoint code is intermixed with searching by tags like the following: if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) {
res, err = gcutils.QueryDepositsByTxQuery(cliCtx, params) // calls QueryByTxsTags
} else {
res, _, err = cliCtx.QueryWithData("custom/gov/deposits", bz)
} |
@colin-axner yeah, we need to refactor those queries |
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.
LGTM
Co-Authored-By: Federico Kunze <[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.
ACK -- great job @colin-axner!
wrt to the specific governance queries, there is nothing we can do. Those specific type of queries were requested by the community and are "special" because they're ad-hoc and do tag (event) based queries underneath the hood. By definition the results can all have various heights. This PR is good as-is 👍
is this PR blocked? |
Nope, just need another ACK from @alessio |
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.
Something major needs fixing
types/rest/rest_test.go
Outdated
"github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" |
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.
Top level packages must not depend on x
sub packages.
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.
Offf, good catch -- I missed this!
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.
We can probably remove this test all together @colin-axner and move it to the LCD tests in Gaia.
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.
We don’t need LCD tests for queries as those are covered by the contract tests
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.
Makes sense, should I remove and move the tests elsewhere or should I refactor the test to use a mock version of account?
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 like the latter
types/rest/rest_test.go
Outdated
"github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" |
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.
Offf, good catch -- I missed this!
types/rest/rest_test.go
Outdated
"github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" |
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.
We can probably remove this test all together @colin-axner and move it to the LCD tests in Gaia.
…ner/cosmos-sdk into colin/generalize-height-queries
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.
ACK
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.
Nice one!
Addition to #4536, no longer specific to account queries. Allows for validator endpoints to return height in the response. closes #4609
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 a relevant changelog entry:
clog add [section] [stanza] [message]
rereviewed
Files changed
in the github PR explorerFor Admin Use: