From 4ff6f862b4de85bd9f4d91e32c0465c0ccb04a47 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Mon, 29 Jul 2019 14:02:47 +1200 Subject: [PATCH 1/8] add post_dispatch --- .../sr-primitives/src/generic/checked_extrinsic.rs | 4 +++- core/sr-primitives/src/traits.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/sr-primitives/src/generic/checked_extrinsic.rs b/core/sr-primitives/src/generic/checked_extrinsic.rs index 04ccd1162c6c6..dbb0d47d8fd5e 100644 --- a/core/sr-primitives/src/generic/checked_extrinsic.rs +++ b/core/sr-primitives/src/generic/checked_extrinsic.rs @@ -85,7 +85,9 @@ where Extra::pre_dispatch_unsigned(info, len)?; None }; - Ok(self.function.dispatch(Origin::from(maybe_who))) + let res = self.function.dispatch(Origin::from(maybe_who)); + Extra::post_dispatch(info, len); + Ok(res) } } diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 670f8d181d1b5..318f639902bd7 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -839,7 +839,7 @@ pub trait SignedExtension: /// also perform any pre-signature-verification checks and return an error if needed. fn additional_signed(&self) -> Result; - /// Validate a signed transaction for the transaction queue. + /// Validate a signed transaction for the transaction queue. fn validate( &self, _who: &Self::AccountId, @@ -868,6 +868,12 @@ pub trait SignedExtension: info: DispatchInfo, len: usize, ) -> Result<(), DispatchError> { Self::validate_unsigned(info, len).map(|_| ()) } + + /// Do any post-flight stuff for a transaction. + fn post_dispatch( + _info: DispatchInfo, + _len: usize, + ) { } } macro_rules! tuple_impl_indexed { @@ -916,6 +922,12 @@ macro_rules! tuple_impl_indexed { $($direct::pre_dispatch_unsigned(info, len)?;)+ Ok(()) } + fn post_dispatch( + info: DispatchInfo, + len: usize, + ) { + $($direct::post_dispatch(info, len);)+ + } } }; From 533da4fa9b87b2955e344b25b97796f4579008ef Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 7 Aug 2019 21:13:22 +0200 Subject: [PATCH 2/8] Update traits.rs --- core/sr-primitives/src/traits.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 28dbe7b99fe9d..35775c4ef39a4 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -854,6 +854,7 @@ pub trait SignedExtension: /// Do any post-flight stuff for a transaction. fn post_dispatch( + _call: &Self::Call _info: DispatchInfo, _len: usize, ) { } @@ -912,10 +913,11 @@ macro_rules! tuple_impl_indexed { Ok(()) } fn post_dispatch( + call: &Self::Call, info: DispatchInfo, len: usize, ) { - $($direct::post_dispatch(info, len);)+ + $($direct::post_dispatch(call, info, len);)+ } } From 108b6c62fa10459a0bdfc9bb5431c45723ceba47 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 7 Aug 2019 21:15:47 +0200 Subject: [PATCH 3/8] Update checked_extrinsic.rs --- core/sr-primitives/src/generic/checked_extrinsic.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/sr-primitives/src/generic/checked_extrinsic.rs b/core/sr-primitives/src/generic/checked_extrinsic.rs index d33f2f896abfd..08d7b10386721 100644 --- a/core/sr-primitives/src/generic/checked_extrinsic.rs +++ b/core/sr-primitives/src/generic/checked_extrinsic.rs @@ -77,15 +77,15 @@ where info: DispatchInfo, len: usize, ) -> Result { - let maybe_who = if let Some((id, extra)) = self.signed { - Extra::pre_dispatch(extra, &id, &self.function, info, len)?; - Some(id) + let (maybe_who, pre) = if let Some((id, extra)) = self.signed { + let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?; + (Some(id), pre) } else { - Extra::pre_dispatch_unsigned(&self.function, info, len)?; - None + let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?; + (None, pre) }; let res = self.function.dispatch(Origin::from(maybe_who)); - Extra::post_dispatch(info, len); + Extra::post_dispatch(pre, info, len); Ok(res) } } From 0d12b4fac9bda089c4db046ff6c94cea8d267851 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 7 Aug 2019 21:18:16 +0200 Subject: [PATCH 4/8] Update traits.rs --- core/sr-primitives/src/traits.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 35775c4ef39a4..3d13ca995b7c1 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -807,6 +807,9 @@ pub trait SignedExtension: /// Any additional data that will go into the signed payload. This may be created dynamically /// from the transaction using the `additional_signed` function. type AdditionalSigned: Encode; + + /// The type that encodes information that can be passed from pre_dispatch to post-dispatch. + type Pre: Default; /// Construct any additional data that should be in the signed payload of the transaction. Can /// also perform any pre-signature-verification checks and return an error if needed. @@ -830,8 +833,8 @@ pub trait SignedExtension: call: &Self::Call, info: DispatchInfo, len: usize, - ) -> Result<(), DispatchError> { - self.validate(who, call, info, len).map(|_| ()) + ) -> Result { + self.validate(who, call, info, len).map(|_| Self::Pre::default()) } /// Validate an unsigned transaction for the transaction queue. Normally the default @@ -848,13 +851,13 @@ pub trait SignedExtension: call: &Self::Call, info: DispatchInfo, len: usize, - ) -> Result<(), DispatchError> { - Self::validate_unsigned(call, info, len).map(|_| ()) + ) -> Result { + Self::validate_unsigned(call, info, len).map(|_| Self::Pre::default()) } /// Do any post-flight stuff for a transaction. fn post_dispatch( - _call: &Self::Call + _pre: Self::Pre, _info: DispatchInfo, _len: usize, ) { } From 2831e3d3ed9e290ee998bdc66d1898ece3cb771b Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Wed, 7 Aug 2019 21:19:13 +0200 Subject: [PATCH 5/8] Update traits.rs --- core/sr-primitives/src/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 3d13ca995b7c1..4e5eba3a2672b 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -916,7 +916,7 @@ macro_rules! tuple_impl_indexed { Ok(()) } fn post_dispatch( - call: &Self::Call, + pre: &Self::Pre, info: DispatchInfo, len: usize, ) { From cf8a5c240e33e3e4d26a764ff75a426fe5665fce Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Thu, 8 Aug 2019 16:14:05 +1200 Subject: [PATCH 6/8] fix build issue --- core/sr-primitives/src/traits.rs | 18 +++++++++--------- srml/balances/src/lib.rs | 1 + srml/system/src/lib.rs | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 4e5eba3a2672b..7272bd3488bc7 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -807,7 +807,7 @@ pub trait SignedExtension: /// Any additional data that will go into the signed payload. This may be created dynamically /// from the transaction using the `additional_signed` function. type AdditionalSigned: Encode; - + /// The type that encodes information that can be passed from pre_dispatch to post-dispatch. type Pre: Default; @@ -876,6 +876,7 @@ macro_rules! tuple_impl_indexed { type AccountId = AccountId; type Call = Call; type AdditionalSigned = ($($direct::AdditionalSigned,)+); + type Pre = ($($direct::Pre,)+); fn additional_signed(&self) -> Result { Ok(( $(self.$index.additional_signed()?,)+ )) } @@ -895,9 +896,8 @@ macro_rules! tuple_impl_indexed { call: &Self::Call, info: DispatchInfo, len: usize, - ) -> Result<(), DispatchError> { - $(self.$index.pre_dispatch(who, call, info, len)?;)+ - Ok(()) + ) -> Result { + Ok(($(self.$index.pre_dispatch(who, call, info, len)?,)+)) } fn validate_unsigned( call: &Self::Call, @@ -911,16 +911,15 @@ macro_rules! tuple_impl_indexed { call: &Self::Call, info: DispatchInfo, len: usize, - ) -> Result<(), DispatchError> { - $($direct::pre_dispatch_unsigned(call, info, len)?;)+ - Ok(()) + ) -> Result { + Ok(($($direct::pre_dispatch_unsigned(call, info, len)?,)+)) } fn post_dispatch( - pre: &Self::Pre, + pre: Self::Pre, info: DispatchInfo, len: usize, ) { - $($direct::post_dispatch(call, info, len);)+ + $($direct::post_dispatch(pre.$index, info, len);)+ } } @@ -948,6 +947,7 @@ impl SignedExtension for () { type AccountId = u64; type AdditionalSigned = (); type Call = (); + type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) } } diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index 4d0306af28e31..66d0ee028495f 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -1216,6 +1216,7 @@ impl, I: Instance + Clone + Eq> SignedExtension for TakeFees { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) } fn validate( diff --git a/srml/system/src/lib.rs b/srml/system/src/lib.rs index f41a566724cfc..571ec6ad6ceb0 100644 --- a/srml/system/src/lib.rs +++ b/srml/system/src/lib.rs @@ -881,6 +881,7 @@ impl SignedExtension for CheckWeight { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) } @@ -944,6 +945,7 @@ impl SignedExtension for CheckNonce { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) } @@ -1017,6 +1019,8 @@ impl SignedExtension for CheckEra { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = T::Hash; + type Pre = (); + fn additional_signed(&self) -> Result { let current_u64 = >::block_number().saturated_into::(); let n = (self.0).0.birth(current_u64).saturated_into::(); @@ -1047,6 +1051,8 @@ impl SignedExtension for CheckGenesis { type AccountId = T::AccountId; type Call = ::Call; type AdditionalSigned = T::Hash; + type Pre = (); + fn additional_signed(&self) -> Result { Ok(>::block_hash(T::BlockNumber::zero())) } From 17e165844dc3a6240fee3c3fe851a912d7aa6664 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Thu, 8 Aug 2019 16:16:50 +1200 Subject: [PATCH 7/8] update runtime version --- node/runtime/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 9f247c63203ac..05d6845a5703b 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 134, - impl_version: 134, + spec_version: 135, + impl_version: 135, apis: RUNTIME_API_VERSIONS, }; From e0a59034548a89dc673cfcf1542f0c651dbdcbd1 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Thu, 8 Aug 2019 16:24:10 +1200 Subject: [PATCH 8/8] fix test build issue --- core/sr-primitives/src/generic/unchecked_extrinsic.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/sr-primitives/src/generic/unchecked_extrinsic.rs b/core/sr-primitives/src/generic/unchecked_extrinsic.rs index 17157c4a19b0e..cb9330cfaaff0 100644 --- a/core/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/core/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -236,6 +236,8 @@ mod tests { type AccountId = u64; type Call = (); type AdditionalSigned = (); + type Pre = (); + fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) } }