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

Allow rpc to query final result #1890

Closed
wants to merge 2 commits into from
Closed

Allow rpc to query final result #1890

wants to merge 2 commits into from

Conversation

bowenwang1996
Copy link
Collaborator

For query rpc allow specifying whether to query from finalized blocks only. Need to change nearlib correspondingly.

@codecov
Copy link

codecov bot commented Dec 21, 2019

Codecov Report

Merging #1890 into staging will decrease coverage by 0.03%.
The diff coverage is 90.9%.

Impacted file tree graph

@@             Coverage Diff             @@
##           staging    #1890      +/-   ##
===========================================
- Coverage    87.03%   86.99%   -0.04%     
===========================================
  Files          166      166              
  Lines        31506    31491      -15     
===========================================
- Hits         27422    27397      -25     
- Misses        4084     4094      +10
Impacted Files Coverage Δ
chain/jsonrpc/client/src/lib.rs 82.85% <ø> (-0.48%) ⬇️
near/src/runtime.rs 72.23% <ø> (ø) ⬆️
near/tests/stake_nodes.rs 96.26% <ø> (-0.04%) ⬇️
chain/client/tests/catching_up.rs 11.62% <ø> (-1.23%) ⬇️
chain/network/src/peer.rs 77.95% <100%> (+1.37%) ⬆️
near/tests/rpc_nodes.rs 95.66% <100%> (-0.03%) ⬇️
chain/jsonrpc/tests/rpc_query.rs 98.45% <100%> (-0.01%) ⬇️
chain/client/src/types.rs 83.18% <100%> (-1.77%) ⬇️
chain/jsonrpc/src/lib.rs 76.14% <100%> (ø) ⬆️
chain/chain/src/types.rs 97.33% <100%> (-0.64%) ⬇️
... and 39 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c71a0a9...e6234af. Read the comment docs.

@bowenwang1996 bowenwang1996 changed the base branch from master to staging December 21, 2019 00:40
Copy link
Contributor

@MaksymZavershynskyi MaksymZavershynskyi left a comment

Choose a reason for hiding this comment

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

If we make turn this flag on by the default on nearlib side lots of stuff is going to timeout. CC @vgrichina @frol .

@@ -248,7 +248,7 @@ impl JsonRpcHandler {
}

async fn query(&self, params: Option<Value>) -> Result<Value, RpcError> {
let (path, data) = parse_params::<(String, String)>(params)?;
let (path, data, is_final) = parse_params::<(String, String, bool)>(params)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a breaking change to the API, right? This API is going out of our hands and introducing it this way we just keep breaking things further. Besides, booleans are rarely a good idea for APIs as we ask people to send something that is e.g. ["account/frol.near", "", false] (meh...).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you suggest we do instead? My understanding is that the raw API is rarely used directly and people will most likely use it through nearlib, which means we can make it backward compatible by providing a default value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nearlib is a JS library, and I assume some may rely on the raw API as they simply implement it in another language.

I suggest creating a separate endpoint (e.g. query-finalized / query-final / ...) and internally, we can reuse the query method by adding a function argument to it.

}

impl Query {
pub fn new(path: String, data: Vec<u8>) -> Self {
Query { path, data, id: generate_random_string(10) }
pub fn new(path: String, data: Vec<u8>, is_final: bool) -> Self {
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
Contributor

Choose a reason for hiding this comment

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

I don't know it it could be applied as a general rule, but it makes sense to use enum in this case

@frol
Copy link
Collaborator

frol commented Dec 26, 2019

@nearmax This exact change will not lead to timeouts right away as it will break the APIs first, and only when this is fixed, this may lead to timeouts if a requesting code calls this endpoint with true set to is_final.

@frol
Copy link
Collaborator

frol commented Jan 30, 2020

I will finish this up in the upcoming days.

@frol
Copy link
Collaborator

frol commented Feb 13, 2020

Superseded by #2127

@frol frol closed this Feb 13, 2020
@ilblackdragon ilblackdragon deleted the rpc-final branch April 16, 2020 08:25
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.

5 participants