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

Support multiple extension versions in V5 extrinsics #4

Merged
merged 5 commits into from
Oct 22, 2024
Merged

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Oct 21, 2024

Split the trait to get extrinsic info apart a little so that we can separately get transaction extensions given a version.

Only allow extension version 0 for <V16 metadatas at the moment. When it's possible for another version to exist, we'll need to tighten up on this and require V16 metadata to decode any verioned extensions properly.

Also remove support for V5 signed extrinsics, since they no longer exist as of the PR merging.

Testing:

  • I integrated it into Subxt and tested against a newly build substrate-node as well as an older one.
  • I updated polkadot-historic-decoding-example to check that it could decode V5 txs from the new Substrate node as well as general old/new blocks from polkadot RPCs

src/decoding/extrinsic_decoder.rs Outdated Show resolved Hide resolved
src/decoding/extrinsic_type_info.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
write!(
f,
"This extrinsic version type ({version_ty}) is not supported; only Bare, Signed and General types are supported."
"The extrinsic type {extrinsic_type:02b} is not supported (given extrinsic version {version})."
Copy link
Member

@niklasad1 niklasad1 Oct 22, 2024

Choose a reason for hiding this comment

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

You think folks will understand binary representation of this better than decimal?

I would probably add "0b{extrinsic_type:02b}" to be sure that it isn't interpreted as decimal

Copy link
Collaborator Author

@jsdw jsdw Oct 22, 2024

Choose a reason for hiding this comment

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

Yeah; it's only ever represented as binary in the code, so I think most likely people won't understand it, but we will be able to diagnose the issue given the error hopefully! I added the 0b for clarity :)

@@ -634,7 +659,7 @@ where
}

Ok::<_, ExtrinsicDecodeError>(ExtrinsicExtensions {
transaction_extensions_version,
transaction_extensions_version: transaction_extensions_version.unwrap_or(0),
Copy link
Member

Choose a reason for hiding this comment

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

So this doesn't exist for ExtrinsicType::Bare AFAIU, cool

A bit hard to understand with optio, maybe that could be improved with separate types from Bare, Signed and General to avoid this transaction_extensions_version: Option but fine for 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.

I pondered separate types but didn't offhand because we don't know the extrinsic version until later so it'd end up with an Option anyways or getting messier converting from one type to another :)

// Dev note: If we see a V5 GEneral extrinsic, it will have a byte for the version of the transaction extensions.
// In V15 or below metadata, we don't know which set of transaction extensions we're being told about though. Is it
// the set that corresponds to the version byte we see or not?
write!(f, "The extrinsic contains an extension version (here, {extension_version}), but in metadata <=V15 it's not clear if we can decode this version or not.")
Copy link
Member

@niklasad1 niklasad1 Oct 22, 2024

Choose a reason for hiding this comment

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

I think it would useful with some info such as Note: Metadata <=V15 only supports transaction extension version 0

I find but in metadata <=V15 it's not clear if we can decode this version or not a bit tricky to understand as user

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Metadata V15 doesn't necessarily only support version 0 though. The actual issue is that in V15 metadata we are told about the current latest version of signed extensions, but we don't know what that version is.

So right now, there is only one version (0) so it's all good. When the code allows for more than one version, we'll actually have to disallow any version from decoding via V15 and below metadata becasue we don't know if the version aligns with what metadata is telling us or not.

(that's why it's ahrd to explain; more tricky than just "0 works in <V16" :D)

write!(f, "Could not find the extrinsic signature type.")
}
ExtrinsicInfoError::ExtrinsicExtensionVersionNotSupported { extension_version } => {
// Dev note: If we see a V5 GEneral extrinsic, it will have a byte for the version of the transaction extensions.
Copy link
Member

Choose a reason for hiding this comment

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

You could clarify in the comment that is possible that metadata < v16 can have the transaction extension version == 0 which we know how to decode but metadata >= v16 i.e, "V5 General extrinsic" we don't know how to decode yet...

However, you added a similar comment in err_if_bad_extension_version which was easier for me to understand.

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 had a go at tweaking the wording, but yeah it's a bit tricky to word correctly :D

@jsdw jsdw merged commit 01bc0f6 into main Oct 22, 2024
8 checks passed
@jsdw jsdw deleted the jsdw-v5-updates branch October 22, 2024 14:28
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.

3 participants