diff --git a/src/extra.rs b/src/extra.rs index a7278c98a2..059d6ddeab 100644 --- a/src/extra.rs +++ b/src/extra.rs @@ -43,18 +43,48 @@ use crate::frame::{ /// This is modified from the substrate version to allow passing in of the version, which is /// returned via `additional_signed()`. #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)] -pub struct CheckVersion( +pub struct CheckSpecVersion( pub PhantomData, /// Local version to be used for `AdditionalSigned` #[codec(skip)] pub u32, ); -impl SignedExtension for CheckVersion +impl SignedExtension for CheckSpecVersion where T: System + Clone + Debug + Eq + Send + Sync, { - const IDENTIFIER: &'static str = "CheckVersion"; + const IDENTIFIER: &'static str = "CheckSpecVersion"; + type AccountId = u64; + type Call = (); + type AdditionalSigned = u32; + type Pre = (); + fn additional_signed( + &self, + ) -> Result { + Ok(self.1) + } +} + +/// Ensure the transaction version registered in the transaction is the same as at present. +/// +/// # Note +/// +/// This is modified from the substrate version to allow passing in of the version, which is +/// returned via `additional_signed()`. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)] +pub struct CheckTxVersion( + pub PhantomData, + /// Local version to be used for `AdditionalSigned` + #[codec(skip)] + pub u32, +); + +impl SignedExtension for CheckTxVersion +where + T: System + Clone + Debug + Eq + Send + Sync, +{ + const IDENTIFIER: &'static str = "CheckTxVersion"; type AccountId = u64; type Call = (); type AdditionalSigned = u32; @@ -215,7 +245,12 @@ pub trait SignedExtra { type Extra: SignedExtension; /// Creates a new `SignedExtra`. - fn new(version: u32, nonce: T::Index, genesis_hash: T::Hash) -> Self; + fn new( + spec_version: u32, + tx_version: u32, + nonce: T::Index, + genesis_hash: T::Hash, + ) -> Self; /// Returns the transaction extra. fn extra(&self) -> Self::Extra; @@ -224,7 +259,8 @@ pub trait SignedExtra { /// Default `SignedExtra` for substrate runtimes. #[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)] pub struct DefaultExtra { - version: u32, + spec_version: u32, + tx_version: u32, nonce: T::Index, genesis_hash: T::Hash, } @@ -233,7 +269,8 @@ impl SignedExtra for DefaultExtra { type Extra = ( - CheckVersion, + CheckSpecVersion, + CheckTxVersion, CheckGenesis, CheckEra, CheckNonce, @@ -242,9 +279,15 @@ impl SignedExtra CheckBlockGasLimit, ); - fn new(version: u32, nonce: T::Index, genesis_hash: T::Hash) -> Self { + fn new( + spec_version: u32, + tx_version: u32, + nonce: T::Index, + genesis_hash: T::Hash, + ) -> Self { DefaultExtra { - version, + spec_version, + tx_version, nonce, genesis_hash, } @@ -252,7 +295,8 @@ impl SignedExtra fn extra(&self) -> Self::Extra { ( - CheckVersion(PhantomData, self.version), + CheckSpecVersion(PhantomData, self.spec_version), + CheckTxVersion(PhantomData, self.tx_version), CheckGenesis(PhantomData, self.genesis_hash), CheckEra((Era::Immortal, PhantomData), self.genesis_hash), CheckNonce(self.nonce), diff --git a/src/lib.rs b/src/lib.rs index eb7b7256a6..9d38535627 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,13 +314,14 @@ where } else { self.account(account_id).await?.nonce }; - let version = self.runtime_version.spec_version; + let spec_version = self.runtime_version.spec_version; + let tx_version = self.runtime_version.transaction_version; let genesis_hash = self.genesis_hash; let call = self .metadata() .module_with_calls(C::MODULE) .and_then(|module| module.call(C::FUNCTION, call))?; - let extra: E = E::new(version, account_nonce, genesis_hash); + let extra: E = E::new(spec_version, tx_version, account_nonce, genesis_hash); let raw_payload = SignedPayload::new(call, extra.extra())?; Ok(raw_payload) }