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

Use frame-decode for core extrinsic decode logic #1785

Merged
merged 19 commits into from
Oct 1, 2024
Merged

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Sep 26, 2024

frame-decode is a crate to handle decoding historic or modern extrinsics and storage keys/values. (https://docs.rs/frame-decode/latest/frame_decode/)

  • Here, we integrate it into Subxt for extrinsic decoding so that the decode logic lives in one place.
  • A possible next step would be to see if it's worth integrating storage key decoding too!

_marker: core::marker::PhantomData<T>,
}

impl<T: Config> Extrinsics<T> {
/// Instantiate a new [`Extrinsics`] object, given a vector containing
/// each extrinsic hash (in the form of bytes) and some metadata that
/// we'll use to decode them.
pub fn decode_from(extrinsics: Vec<Vec<u8>>, metadata: Metadata) -> Result<Self, BlockError> {
let ids = ExtrinsicPartTypeIds::new(&metadata)?;
pub fn decode_from(extrinsics: Vec<Vec<u8>>, metadata: Metadata) -> Result<Self, Error> {
Copy link
Collaborator Author

@jsdw jsdw Sep 30, 2024

Choose a reason for hiding this comment

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

I moved the decoding work to this initial step.

This means that on the downside we:

  • try to decode everything straight away, even if the user doesn't care (though I suspect they usually would)
  • an error decoding an extrinsic will lead to a failure early on, preventing eg getting the extrinsic bytes

On the plus side, we:

  • Can iterate over or find or whatever multiple times without re-doing the decoding work each time we do these things.
  • Don't need to handle Results in a couple of places, since we did the work once up front.

@@ -61,6 +65,63 @@ pub struct Metadata {
custom: frame_metadata::v15::CustomMetadata<PortableForm>,
}

// Since we've abstracted away from frame-metadatas, we impl this on our custom Metadata
// so that it can be used by `frame-decode` to obtain the relevant extrinsic info.
impl frame_decode::extrinsics::ExtrinsicTypeInfo for Metadata {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We wouldn't normally need this if we used frame_metadata's RuntimeMetadataV15 or whatever directly, but since we abstracted it into our own Metadata crate so as to not care about the underlying version, we need to be able to get the info we need from this via the impl here.

@jsdw jsdw marked this pull request as ready for review September 30, 2024 16:44
@jsdw jsdw requested review from a team as code owners September 30, 2024 16:44
@jsdw jsdw changed the title WIP using frame-decode for core extrinsic decode logic Use frame-decode for core extrinsic decode logic Sep 30, 2024
Copy link
Collaborator

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Copy link
Contributor

@pkhry pkhry left a comment

Choose a reason for hiding this comment

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

LGTM

@jsdw jsdw merged commit b5209a1 into master Oct 1, 2024
14 checks passed
@jsdw jsdw deleted the jsdw-frame-decode branch October 1, 2024 10:21
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/decoding-old-and-new-blocks-and-storage-entries-in-rust-october-2024-update/10276/1

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