-
Notifications
You must be signed in to change notification settings - Fork 653
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
refactor(jsonrpc): Add structured errors to query method in ViewClient and RPC #3944
refactor(jsonrpc): Add structured errors to query method in ViewClient and RPC #3944
Conversation
e913cef
to
4131a6a
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.
We are on the right track!
@khorolets Another reminder as we discussed last week: Add tests covering the error responses (at least the legal ones, no need to test IOErrors and Unexpected errors); see |
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.
Just a few nits, and we are ready to merge it!
ac2b912
to
1cb0e04
Compare
Backward compatible messages from jsonrpc needs to be done to finish this PR |
neard/tests/rpc_nodes.rs
Outdated
actix::spawn(async move { | ||
let client = new_client(&format!("http://{}", rpc_addrs[0])); | ||
let query_response = client | ||
.query(near_jsonrpc_primitives::types::query::RpcQueryRequest { | ||
block_reference: near_primitives::types::BlockReference::Finality( | ||
Finality::Final, | ||
), | ||
request: near_primitives::views::QueryRequest::ViewAccount { | ||
account_id: "test.near".to_string(), | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
assert_eq!(false, true); | ||
System::current().stop(); | ||
}); |
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.
…ppen (#3969) Closes #3951 Doesn't affect #3938 because that particular method (`query`) is being refactored right now in #3944 As for the `query` timeout can appear there because of network routing but in my PR which refactors `query` method we totally removed routing (decision made by @bowenwang1996 and @frol) so it seems like timeout from jsonrpc side wouldn't be possible.
@frol I hope I've finalized error structs according to your suggestions. I'm going to deal with backward now. |
…ppen (#3969) Closes #3951 Doesn't affect #3938 because that particular method (`query`) is being refactored right now in #3944 As for the `query` timeout can appear there because of network routing but in my PR which refactors `query` method we totally removed routing (decision made by @bowenwang1996 and @frol) so it seems like timeout from jsonrpc side wouldn't be possible.
28427f5
to
09744a6
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.
It is a massive effort! Given there is only one comment from me, I think it is time to mark it is ready for further review.
chain/jsonrpc/src/lib.rs
Outdated
// This match is used here to give backward compatible error message for specific | ||
// error variants. Should be refactored once structured errors fully shipped |
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 our only option going forward would be to return both result
and error
in the same JSON RPC response. (result
for backward compatibility, and error
for future sanity)
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 couldn't we get rid of QueryResponseKind::Error
and emulate it here instead?
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.
@bowenwang1996 good point.
@khorolets Can we get rid of the Error
variant and move this handling to a separate backward-compatibility-wrapper called on the process_request
level? (serde_json::to_value(query_response)
can moved into this wrapper)
pub struct RpcQueryResponse { | ||
#[serde(flatten)] | ||
pub query_response: near_primitives::views::QueryResponse, | ||
} |
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 that the nesting is completely unnecessary here. We should either (1) implement our own RpcQueryResponse
or (2) just type-alias the views::QueryResponse
. For clear separation of concerns and following our previous style, we should consider (1) and also removing the serde serialization from view::QueryResponse
.
0312acf
to
e94101f
Compare
chain/client/src/view_client.rs
Outdated
} | ||
|
||
Ok(None) | ||
if self.runtime_adapter.cares_about_shard( |
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 am sorry but please do not try to change the logic here. What you did is not an equivalent transformation.
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.
@bowenwang1996 can you assist here to transform it equivalent, please?
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.
@bowenwang1996 we removed query-routing here following your take in https://github.com/near/nearcore/pull/3204/files#diff-34fd63bb882408a6cd040297ab48d277c848f434f9f72da6696aa17e86099405R212-R230
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.
@khorolets simply use get_chunk_extra
as the old code and do not use cares_about_shard
to determine whether this node has the latest information about the shard
chain/jsonrpc/src/lib.rs
Outdated
// This match is used here to give backward compatible error message for specific | ||
// error variants. Should be refactored once structured errors fully shipped |
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 couldn't we get rid of QueryResponseKind::Error
and emulate it here instead?
e94101f
to
459c1df
Compare
chain/jsonrpc/src/lib.rs
Outdated
// This match is used here to give backward compatible error message for specific | ||
// error variants. Should be refactored once structured errors fully shipped |
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.
@bowenwang1996 good point.
@khorolets Can we get rid of the Error
variant and move this handling to a separate backward-compatibility-wrapper called on the process_request
level? (serde_json::to_value(query_response)
can moved into this wrapper)
neard/tests/rpc_nodes.rs
Outdated
System::builder() | ||
.stop_on_panic(true) | ||
.run(move || { |
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.
hint: see #4013 on how to use run_actix_until_stop
(after the PR is merged)
chain/client/src/view_client.rs
Outdated
} | ||
|
||
Ok(None) | ||
if self.runtime_adapter.cares_about_shard( |
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.
@bowenwang1996 we removed query-routing here following your take in https://github.com/near/nearcore/pull/3204/files#diff-34fd63bb882408a6cd040297ab48d277c848f434f9f72da6696aa17e86099405R212-R230
…, view state and access key methods return typical errors instead of QueryError
…rror instead of RpcQueryError
7efe70c
to
efde9e0
Compare
…g to dropped routing in handle_query ViewClient method (#4120) In merged PR #3944 I've dropped routing for the `Query` handler in ViewClient (@frol and @bowenwang1996 discussed it and approved this change). After that test `pytest/tests/sanity/transactions.py` started failing. @frol and I investigated it and found out that the fails related to the attempts to test transactions between shards, all the test relies on the querying jsonrpc `query` method to get accounts from different shards and check their balances, but since routing is not present there anymore it's impossible to do it. In this PR I've made the smallest change introducing only one shard and all the accounts on that shard so the test is not failing anymore, but I'm not sure if it not brakes the main idea of the test. @bowenwang1996 @SkidanovAlex could you assist in refactoring this test so it could still be useful by checking what it supposed to be checking, please?
runtime/runtime/state_viewer
QueryError
into chain primitivesquery
method implementation inneard
view_client
handle_query
methodquery
method (resolves View query times out for older block #3848)Still need to implement errors on the RPC and Rosetta side. Work in progress.
I'm creating this draft PR to ask for a review of error structs and error messages.