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

Unstable Backend: add back the old chainHead RPCs/tests #1137

Merged
merged 13 commits into from
Aug 29, 2023

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Aug 24, 2023

This PR isn't as big as it looks; new rustfmt understands let ... else statements now, and otherwise seemed to want to reformat quite a lot! See below for actual changes.

  • I put back the chainHead methods and tests.
  • I also added back any legacy RPCs that I removed in the last PR; I decided that there's probably enough breaking changes already, and so want to give people using those RPCs a slightly smoother migration.
  • I also added some other of the new APIs including to submit transactions, and the now stable chainSpec methods.

The only real changes in terms of files are:

  • subxt/src/backend/unstable/ - add unstable RPC methods back
  • testing/integration-tests/src/full_client/client/legacy_rpcs.rs - for the tests

I also removed the #[deny(unused_dependencies)] thing from the integration-tests crate, because IMO it's not really important there and we had more and more use foo as _; things depending on different features being enabled or not.

@jsdw jsdw requested a review from a team as a code owner August 24, 2023 16:05
@jsdw jsdw marked this pull request as draft August 24, 2023 16:20
@jsdw jsdw marked this pull request as ready for review August 25, 2023 17:00
Copy link
Contributor

@tadeohepperle tadeohepperle left a comment

Choose a reason for hiding this comment

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

Looks very nice, just left a few comments :)

subxt/src/backend/unstable/rpc_methods.rs Outdated Show resolved Hide resolved
///
/// # Note
///
/// This is present only if the `with_runtime` flag is set for
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean with with_runtime the argument runtime_updates: bool that is passed to chainhead_unstable_follow()? I think we should use a uniform name adressing it throughout the code.
Since it has an effect on the data in many struct, we could also think about making the FollowEvent generic over this flag (maybe with const generics). Just an idea. :)

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; we should prolly call it with_runtime elsewhere too because the spec calls it withRuntime!

I guess generics could be used to "guarantee" that we get a RuntimeEvent if we ask for it, and not if we don't, maybe? But the generics might complicate things more than it's worth because they would bleed out to anything else that cared about this stuff :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree that we should not complicate it more.

niklasad1 and others added 2 commits August 29, 2023 10:11
Co-authored-by: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com>
use super::*;

#[test]
fn can_deserialize_apis_from_tuple_or_object() {
Copy link
Member

Choose a reason for hiding this comment

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

👍


/// Attempt to deserialize either a string or integer into an integer.
/// See <https://github.com/paritytech/json-rpc-interface-spec/issues/83>
pub(crate) mod unsigned_number_as_string {
Copy link
Member

Choose a reason for hiding this comment

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

add a simple test for this as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup I should def do this!

@@ -82,7 +82,7 @@ pub trait Hasher {
}

/// This represents the block header type used by a node.
pub trait Header: Sized + Encode {
pub trait Header: Sized + Encode + Decode {
Copy link
Member

Choose a reason for hiding this comment

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

why is Decode needed now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the old API methods, header came back as JSON, but in the new one it comes back as hex encoded SCALE encoded bytes instead :)

@@ -35,19 +35,6 @@ use subxt::{
};
use subxt_metadata::Metadata;

// We don't use these dependencies.
use assert_matches as _;
Copy link
Member

Choose a reason for hiding this comment

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

👍

///
/// # Panics
///
/// Panics if `self.type_id` is not registered in the provided type registry
Copy link
Member

Choose a reason for hiding this comment

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

Is this not true anymore?

Can't find anything in this PR about this :P

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 the pub fn get_type_hash would still panic if the id passed as param is not present in the PortableRegistry 🤔

I belive the CustomValueMetadata could only panic in practice here if the metadata is broken, since that's where our value is coming from

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The comment was left over from when this call was taking in a PortableRegistry as an argument (which might then have different types from what he metadata knew about and thus could panic). That was since removed but I noticed that the comment wasn't updated so I tweaked it :)

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 good

pub async fn author_rotate_keys(&self) -> Result<Vec<u8>, Error> {
let bytes: Bytes = self
.client
.request("author_rotateKeys", rpc_params![])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, are we adding those back to the legacy API since they might be useful for validators? 🤔

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 just added back anything that I had removed earlier basically, so that if anybody happened to be using them then there is an easy migration path. I'd like to remove some of these again eventually, but ideally as part of a smaller change!

/// Failure to do so will result in the subscription being stopped by generating the `Stop` event.
pub async fn chainhead_unstable_follow(
&self,
runtime_updates: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think this is now named with_runtime from spec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup; I renamed it :)

@jsdw jsdw merged commit a3d25db into master Aug 29, 2023
9 checks passed
@jsdw jsdw deleted the jsdw-unstable-backend-rpcs branch August 29, 2023 11:35
@jsdw jsdw mentioned this pull request Sep 27, 2023
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.

4 participants