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

Split RPCs into a separate crate #1910

Merged
merged 36 commits into from
Feb 18, 2025
Merged

Split RPCs into a separate crate #1910

merged 36 commits into from
Feb 18, 2025

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Jan 27, 2025

Create a new crate, subxt-rpcs. This crate exposes:

  • methods: legacy and chainHead RPCs are exposed (the same set that were available in subxt), and archive methods will be added here later.
  • client: a set of clients are exposed: jsonrpsee, reconnecting-rpc-client, unstable-light-client and mock-rpc-client. Any of these can be used to call the methods. Subxt makes use of each of these.

Basically, we get all of the low level network communication/serialization/deserialization/typing handled for us, without any of the additional abstraction that Subxt places on top. Useful if you want to interact directly with the RPCs but don't want any other features provided by Subxt.

@jsdw jsdw marked this pull request as ready for review February 10, 2025 15:48
@jsdw jsdw requested review from a team as code owners February 10, 2025 15:48
pub mod chain_head;
pub mod legacy;

pub use chain_head::ChainHeadRpcMethods;
Copy link
Member

Choose a reason for hiding this comment

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

The question is whether we shall support more rpc methods such as rpc v2 archieve and similar.

I think no, but we could open an issue for it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I def think we should add support for archive methods, but ended up deciding to leave it for a separate PR

vec![
Ok(Json(runtime_version(4))),
Ok(Json(runtime_version(5))),
Err(subxt_rpcs::Error::Client("..".into())),
Copy link
Member

Choose a reason for hiding this comment

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

This error variant Rejected was removed/cleanup in this by why "..".

Is the DisconnectedWillReconnect converted to a Client error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I just used ".." because it's just test code so not really relevant what the reason text is :)

IIRC The RequestRejected error was only ever used in the case that we got a LimitReached response back from the chainHead RPCs, so I renamed it to be LimitReached as it's a bit of a special case error (ie the MethodResponse::LimitReached we get back isn't an error from the API, but we want to turn it into one in Subxt).

In this particular test I just think that any error was good enough to show that after an error the stream returns None

assert!(matches!(
results.next().await.unwrap(),
Err(Error::Rpc(RpcError::ClientError(
subxt_rpcs::Error::Client(_)
Copy link
Member

Choose a reason for hiding this comment

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

again, rejected was refactored to a client error instead?

when are we using LimitReached now? Only for the chainhead backend?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah; LimitReached is an error that signals that the chainHead backend returned the non-error response LimitReached, which we treat as an error in Subxt and so turn into one.

I don't remember explicitly changing any errors from Rejected to ClientError (should be form Rejected to LimitReached), but in some of these tests it doesn't matter, so I might have opted for an error that didn't have any "special" retry consequences!

.unwrap();
tx.send(operation_continue("Id1")).unwrap();
});
Ok(Json(response_started("Id1")))
Copy link
Member

Choose a reason for hiding this comment

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

Technically, we should ensure that response_started was sent "before" the messages in the tokio::spawn above.

if the tests passes it's not a big deal but you use a oneshot for that here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I don't mind if some data comes back before the "response started" because, owing to races, there's a chance that could happen in real life too, so this checks that the client is ready to receive such messages before the response comes back (which I think we do; we subscribe before making the call to buffer any responses)

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

Looks great so far, it's definitely a nice cleanup of the error handling.

I got tired now and I'll finish the review tomorrow.

@jsdw jsdw merged commit 816a864 into master Feb 18, 2025
13 checks passed
@jsdw jsdw deleted the jsdw-subxt-rpcs branch February 18, 2025 12:07
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.

2 participants