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

refactor(jsonrpc): Add structured errors to query method in ViewClient and RPC #3944

Merged

Conversation

khorolets
Copy link
Member

@khorolets khorolets commented Feb 10, 2021

  • add some errors to runtime/runtime/state_viewer
  • introduce QueryError into chain primitives
  • refactor runtime query method implementation in neard
  • refactor view_client handle_query method
  • remove routing for query 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.

@khorolets khorolets requested a review from frol February 10, 2021 16:52
@khorolets khorolets force-pushed the refactor/structured-errors-view-client-jsonrpc-query branch 2 times, most recently from e913cef to 4131a6a Compare February 11, 2021 16:18
Copy link
Collaborator

@frol frol left a 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!

chain/chain/src/lib.rs Outdated Show resolved Hide resolved
chain/jsonrpc-primitives/src/types/query.rs Outdated Show resolved Hide resolved
chain/jsonrpc-primitives/src/types/query.rs Outdated Show resolved Hide resolved
chain/jsonrpc-primitives/src/types/query.rs Outdated Show resolved Hide resolved
chain/jsonrpc-primitives/src/types/query.rs Outdated Show resolved Hide resolved
neard/src/runtime/errors.rs Outdated Show resolved Hide resolved
runtime/runtime/src/state_viewer/errors.rs Outdated Show resolved Hide resolved
runtime/runtime/src/state_viewer/errors.rs Outdated Show resolved Hide resolved
runtime/runtime/src/state_viewer/mod.rs Outdated Show resolved Hide resolved
chain/client-primitives/src/types.rs Outdated Show resolved Hide resolved
@frol
Copy link
Collaborator

frol commented Feb 16, 2021

@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 neard/tests/rpc_nodes.rs

Copy link
Collaborator

@frol frol left a 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!

chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/rosetta-rpc/src/utils.rs Outdated Show resolved Hide resolved
chain/rosetta-rpc/src/utils.rs Outdated Show resolved Hide resolved
neard/src/runtime/mod.rs Outdated Show resolved Hide resolved
@khorolets
Copy link
Member Author

Backward compatible messages from jsonrpc needs to be done to finish this PR

chain/client-primitives/src/types.rs Outdated Show resolved Hide resolved
chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/client/src/view_client.rs Outdated Show resolved Hide resolved
chain/client/src/view_client.rs Outdated Show resolved Hide resolved
chain/chain-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/jsonrpc-primitives/src/types/receipts.rs Outdated Show resolved Hide resolved
Comment on lines 750 to 764
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();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo for @frol: This is blocked on #3901

runtime/runtime/src/state_viewer/errors.rs Outdated Show resolved Hide resolved
near-bulldozer bot pushed a commit that referenced this pull request Feb 18, 2021
…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.
@khorolets khorolets changed the title refactor (rpc): Add structured errors to query method in ViewClient and RPC refactor(jsonrpc): Add structured errors to query method in ViewClient and RPC Feb 19, 2021
@khorolets
Copy link
Member Author

@frol I hope I've finalized error structs according to your suggestions. I'm going to deal with backward now.

chain/client-primitives/src/types.rs Outdated Show resolved Hide resolved
chain/client/src/view_client.rs Outdated Show resolved Hide resolved
chain/jsonrpc/src/lib.rs Outdated Show resolved Hide resolved
neard/src/runtime/errors.rs Outdated Show resolved Hide resolved
bowenwang1996 pushed a commit that referenced this pull request Feb 23, 2021
…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.
@khorolets khorolets force-pushed the refactor/structured-errors-view-client-jsonrpc-query branch 2 times, most recently from 28427f5 to 09744a6 Compare February 24, 2021 19:16
Copy link
Collaborator

@frol frol left a 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.

Comment on lines 579 to 580
// This match is used here to give backward compatible error message for specific
// error variants. Should be refactored once structured errors fully shipped
Copy link
Collaborator

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)

Copy link
Collaborator

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?

Copy link
Collaborator

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)

Comment on lines 66 to 82
pub struct RpcQueryResponse {
#[serde(flatten)]
pub query_response: near_primitives::views::QueryResponse,
}
Copy link
Collaborator

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.

@khorolets khorolets force-pushed the refactor/structured-errors-view-client-jsonrpc-query branch 2 times, most recently from 0312acf to e94101f Compare February 26, 2021 09:53
@khorolets khorolets marked this pull request as ready for review February 26, 2021 11:21
}

Ok(None)
if self.runtime_adapter.cares_about_shard(
Copy link
Collaborator

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.

Copy link
Member Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

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 Show resolved Hide resolved
Comment on lines 579 to 580
// This match is used here to give backward compatible error message for specific
// error variants. Should be refactored once structured errors fully shipped
Copy link
Collaborator

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?

@khorolets khorolets force-pushed the refactor/structured-errors-view-client-jsonrpc-query branch from e94101f to 459c1df Compare February 28, 2021 08:44
Comment on lines 579 to 580
// This match is used here to give backward compatible error message for specific
// error variants. Should be refactored once structured errors fully shipped
Copy link
Collaborator

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)

Comment on lines 735 to 737
System::builder()
.stop_on_panic(true)
.run(move || {
Copy link
Collaborator

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)

}

Ok(None)
if self.runtime_adapter.cares_about_shard(
Copy link
Collaborator

Choose a reason for hiding this comment

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

@khorolets khorolets force-pushed the refactor/structured-errors-view-client-jsonrpc-query branch from 7efe70c to efde9e0 Compare March 9, 2021 14:55
@khorolets khorolets merged commit f68140e into master Mar 9, 2021
@khorolets khorolets deleted the refactor/structured-errors-view-client-jsonrpc-query branch March 9, 2021 16:18
near-bulldozer bot pushed a commit that referenced this pull request Mar 16, 2021
…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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View query times out for older block
3 participants