Prepare 0.37.1 patch release with rudimentory V5 extrinsic support (#1834)

* Add basic support for V5 extrinsics

* Add changelog entry and tweak comment

* fix check warnings

* , -> .
This commit is contained in:
James Wilson
2024-10-22 15:04:02 +01:00
committed by GitHub
parent 44517aabfc
commit bac72b556a
6 changed files with 63 additions and 50 deletions
+4
View File
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.37.1] - 2024-10-22
This patch release adds basic support for V5 extrinsics into `subxt-core`. We only bump `subxt-core` in this release; other crates should then take this patch automatically but you may need to `cargo update` to get the change.
## [0.37.0] - 2024-05-28
This release mainly adds support for the sign extension `CheckMetadataHash` and fixes a regression introduced in v0.36.0
Generated
+15 -15
View File
@@ -327,7 +327,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "artifacts"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"substrate-runner",
]
@@ -1812,7 +1812,7 @@ dependencies = [
[[package]]
name = "generate-custom-metadata"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"frame-metadata 16.0.0",
"parity-scale-codec",
@@ -2309,7 +2309,7 @@ dependencies = [
[[package]]
name = "integration-tests"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"assert_matches",
"cfg_aliases",
@@ -4745,7 +4745,7 @@ dependencies = [
[[package]]
name = "substrate-runner"
version = "0.36.1"
version = "0.37.0"
[[package]]
name = "subtle"
@@ -4755,7 +4755,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "subxt"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"assert_matches",
"async-trait",
@@ -4798,7 +4798,7 @@ dependencies = [
[[package]]
name = "subxt-cli"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"clap 4.5.4",
"color-eyre",
@@ -4827,7 +4827,7 @@ dependencies = [
[[package]]
name = "subxt-codegen"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"frame-metadata 16.0.0",
"getrandom",
@@ -4847,7 +4847,7 @@ dependencies = [
[[package]]
name = "subxt-core"
version = "0.36.1"
version = "0.37.1"
dependencies = [
"assert_matches",
"base58",
@@ -4879,7 +4879,7 @@ dependencies = [
[[package]]
name = "subxt-lightclient"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"futures",
"futures-timer",
@@ -4904,7 +4904,7 @@ dependencies = [
[[package]]
name = "subxt-macro"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"darling 0.20.8",
"parity-scale-codec",
@@ -4917,7 +4917,7 @@ dependencies = [
[[package]]
name = "subxt-metadata"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"assert_matches",
"bitvec",
@@ -4931,7 +4931,7 @@ dependencies = [
[[package]]
name = "subxt-signer"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"bip32",
"bip39",
@@ -4958,7 +4958,7 @@ dependencies = [
[[package]]
name = "subxt-test-macro"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"quote",
"syn 2.0.60",
@@ -5021,7 +5021,7 @@ dependencies = [
[[package]]
name = "test-runtime"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"hex",
"impl-serde",
@@ -5446,7 +5446,7 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "ui-tests"
version = "0.36.1"
version = "0.37.0"
dependencies = [
"frame-metadata 16.0.0",
"generate-custom-metadata",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "subxt-core"
version.workspace = true
version = "0.37.1"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
+39 -23
View File
@@ -149,7 +149,9 @@ pub struct SignedExtrinsicDetails {
address_end_idx: usize,
/// end index of the range in `bytes` of `ExtrinsicDetails` that encodes the signature. Equivalent to extra_start_idx.
signature_end_idx: usize,
/// end index of the range in `bytes` of `ExtrinsicDetails` that encodes the signature.
/// start index of the range in `bytes` of `ExtrinsicDetails` that encodes the extensions.
extra_start_idx: usize,
/// end index of the range in `bytes` of `ExtrinsicDetails` that encodes the extensions.
extra_end_idx: usize,
}
@@ -165,25 +167,26 @@ where
metadata: Metadata,
ids: ExtrinsicPartTypeIds,
) -> Result<ExtrinsicDetails<T>, Error> {
const SIGNATURE_MASK: u8 = 0b1000_0000;
const VERSION_MASK: u8 = 0b0111_1111;
const LATEST_EXTRINSIC_VERSION: u8 = 4;
const SIGNATURE_MASK: u8 = 0b1100_0000;
const VERSION_MASK: u8 = 0b0011_1111;
// removing the compact encoded prefix:
let bytes: Arc<[u8]> = strip_compact_prefix(extrinsic_bytes)?.1.into();
// Extrinsic are encoded in memory in the following way:
// - first byte: abbbbbbb (a = 0 for unsigned, 1 for signed, b = version)
// - first byte: aabbbbbb (a = 00 for unsigned, 10 for signed, 01 for general, b = version)
// - signature: [unknown TBD with metadata].
// - extrinsic data
let first_byte: u8 = Decode::decode(&mut &bytes[..])?;
let version = first_byte & VERSION_MASK;
if version != LATEST_EXTRINSIC_VERSION {
if version != 4 && version != 5 {
return Err(BlockError::UnsupportedVersion(version).into());
}
let is_signed = first_byte & SIGNATURE_MASK != 0;
// Hack in rudimentory support for V5 extrinsics..
let is_signed = first_byte & SIGNATURE_MASK == 0b1000_0000;
let is_general = first_byte & SIGNATURE_MASK == 0b0100_0000;
// Skip over the first byte which denotes the version and signing.
let cursor = &mut &bytes[1..];
@@ -191,25 +194,37 @@ where
let signed_details = is_signed
.then(|| -> Result<SignedExtrinsicDetails, Error> {
let address_start_idx = bytes.len() - cursor.len();
// Skip over the address, signature and extra fields.
scale_decode::visitor::decode_with_visitor(
cursor,
ids.address,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
.map_err(scale_decode::Error::from)?;
// Skip over the address, signature and extra fields. If V5 general
// extrinsic then there is no address and signature so skip nothing.
if !is_general {
scale_decode::visitor::decode_with_visitor(
cursor,
ids.address,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
.map_err(scale_decode::Error::from)?;
}
let address_end_idx = bytes.len() - cursor.len();
scale_decode::visitor::decode_with_visitor(
cursor,
ids.signature,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
.map_err(scale_decode::Error::from)?;
if !is_general {
scale_decode::visitor::decode_with_visitor(
cursor,
ids.signature,
metadata.types(),
scale_decode::visitor::IgnoreVisitor::new(),
)
.map_err(scale_decode::Error::from)?;
}
let signature_end_idx = bytes.len() - cursor.len();
if is_general {
// V5 general extrinsics have an extension version byte.
// For now we just ignore it as a hack to decode V5 exts.
let _extension_version = u8::decode(cursor)?;
}
let extra_start_idx = bytes.len() - cursor.len();
scale_decode::visitor::decode_with_visitor(
cursor,
ids.extra,
@@ -223,6 +238,7 @@ where
address_start_idx,
address_end_idx,
signature_end_idx,
extra_start_idx,
extra_end_idx,
})
})
@@ -320,7 +336,7 @@ where
pub fn signed_extensions_bytes(&self) -> Option<&[u8]> {
self.signed_details
.as_ref()
.map(|e| &self.bytes[e.signature_end_idx..e.extra_end_idx])
.map(|e| &self.bytes[e.extra_start_idx..e.extra_end_idx])
}
/// Returns `None` if the extrinsic is not signed.
+1 -2
View File
@@ -332,8 +332,7 @@ impl<T: Config> LegacyRpcMethods<T> {
public: Vec<u8>,
) -> Result<(), Error> {
let params = rpc_params![key_type, suri, Bytes(public)];
self.client.request("author_insertKey", params).await?;
Ok(())
self.client.request("author_insertKey", params).await
}
/// Generate new session keys and returns the corresponding public keys.
+3 -9
View File
@@ -77,9 +77,7 @@ impl<T: Config> UnstableRpcMethods<T> {
"chainHead_v1_continue",
rpc_params![follow_subscription, operation_id],
)
.await?;
Ok(())
.await
}
/// Stops an operation started with `chainHead_v1_body`, `chainHead_v1_call`, or
@@ -97,9 +95,7 @@ impl<T: Config> UnstableRpcMethods<T> {
"chainHead_v1_stopOperation",
rpc_params![follow_subscription, operation_id],
)
.await?;
Ok(())
.await
}
/// Call the `chainHead_v1_body` method and return an operation ID to obtain the block's body.
@@ -222,9 +218,7 @@ impl<T: Config> UnstableRpcMethods<T> {
) -> Result<(), Error> {
self.client
.request("chainHead_v1_unpin", rpc_params![subscription_id, hash])
.await?;
Ok(())
.await
}
/// Return the genesis hash.