From 2368c7ee02e419a54650a624268aacafbf3aa362 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 21 Feb 2022 14:46:36 +0300 Subject: [PATCH] impl Decode for SignedExtensions (otherwise transaction resubmitter panicks) (#1325) --- bridges/primitives/polkadot-core/src/lib.rs | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bridges/primitives/polkadot-core/src/lib.rs b/bridges/primitives/polkadot-core/src/lib.rs index ce27d22b240b9..2f7f6289a3eeb 100644 --- a/bridges/primitives/polkadot-core/src/lib.rs +++ b/bridges/primitives/polkadot-core/src/lib.rs @@ -250,7 +250,11 @@ pub type AdditionalSigned = (u32, u32, Hash, Hash, (), (), ()); #[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)] pub struct SignedExtensions { encode_payload: SignedExtra, - additional_signed: AdditionalSigned, + // It may be set to `None` if extensions are decoded. We are never reconstructing transactions + // (and it makes no sense to do that) => decoded version of `SignedExtensions` is only used to + // read fields of `encode_payload`. And when resigning transaction, we're reconstructing + // `SignedExtensions` from the scratch. + additional_signed: Option, _data: sp_std::marker::PhantomData, } @@ -262,9 +266,13 @@ impl parity_scale_codec::Encode for SignedExtensions { impl parity_scale_codec::Decode for SignedExtensions { fn decode( - _input: &mut I, + input: &mut I, ) -> Result { - unimplemented!("SignedExtensions are never meant to be decoded, they are only used to create transaction"); + SignedExtra::decode(input).map(|encode_payload| SignedExtensions { + encode_payload, + additional_signed: None, + _data: Default::default(), + }) } } @@ -287,7 +295,7 @@ impl SignedExtensions { (), // Check weight tip.into(), // transaction payment / tip (compact encoding) ), - additional_signed: ( + additional_signed: Some(( spec_version, transaction_version, genesis_hash, @@ -295,7 +303,7 @@ impl SignedExtensions { (), (), (), - ), + )), _data: Default::default(), } } @@ -335,7 +343,14 @@ where fn additional_signed( &self, ) -> Result { - Ok(self.additional_signed) + // we shall not ever see this error in relay, because we are never signing decoded + // transactions. Instead we're constructing and signing new transactions. So the error code + // is kinda random here + self.additional_signed.ok_or_else(|| { + frame_support::unsigned::TransactionValidityError::Unknown( + frame_support::unsigned::UnknownTransaction::Custom(0xFF), + ) + }) } fn pre_dispatch(