From 7937af9919e7520d0c49e8a11cdfb8f78d400953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Thu, 5 Jul 2018 18:22:06 +0200 Subject: [PATCH 01/21] runtime: refactor Checkable and BlindCheckable traits --- substrate/runtime/primitives/src/traits.rs | 34 ++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 218fbc12769f6..5f75ff3f3cf43 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -371,31 +371,29 @@ pub type HashingFor = <::Header as Header>::Hashing; /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. -pub trait Checkable: Sized + Send + Sync { - type Address: Member + MaybeDisplay; - type AccountId: Member + MaybeDisplay; - type Checked: Member; - fn sender(&self) -> &Self::Address; - fn check Result>(self, lookup: ThisLookup) -> Result; +/// for things that can be checked by providing additional context `Ctx` +pub trait Checkable: Sized { + type Checked; + + fn check_with(self, ctx: Ctx) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. -/// -/// This does that checking without requiring a lookup argument. -pub trait BlindCheckable: Sized + Send + Sync { - type Address: Member + MaybeDisplay; - type Checked: Member; - fn sender(&self) -> &Self::Address; - fn check(self) -> Result; +/// for things that can be checked without additional context. +pub trait BlindCheckable: Sized { + type Checked; + + /// gives back in case of an error. + fn check(self) -> Result; } -impl Checkable for T { - type Address = ::Address; - type AccountId = ::Address; +// every BlindCheckable is also a Checkable for arbitrary context `Ctx` +impl Checkable for T { type Checked = ::Checked; - fn sender(&self) -> &Self::Address { BlindCheckable::sender(self) } - fn check Result>(self, _: ThisLookup) -> Result { BlindCheckable::check(self) } + fn check_with(self, _: Ctx) -> Result { + BlindCheckable::check(self) + } } /// An "executable" piece of information, used by the standard Substrate Executive in order to From cf080b099fe6989749f7582df89b970217fc20d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Thu, 5 Jul 2018 18:22:55 +0200 Subject: [PATCH 02/21] fix impl BlindCheckable for Extrinsic --- substrate/test-runtime/src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/substrate/test-runtime/src/lib.rs b/substrate/test-runtime/src/lib.rs index 1b07035e966e8..6f9da3a93d8ed 100644 --- a/substrate/test-runtime/src/lib.rs +++ b/substrate/test-runtime/src/lib.rs @@ -119,16 +119,12 @@ impl Slicable for Extrinsic { impl BlindCheckable for Extrinsic { type Checked = Self; - type Address = AccountId; - fn sender(&self) -> &Self::Address { - &self.transfer.from - } - fn check(self) -> Result { + fn check(self) -> Result { if ::runtime_primitives::verify_encoded_lazy(&self.signature, &self.transfer, &self.transfer.from) { Ok(self) } else { - Err("bad signature") + Err(self) } } } From 0b2ff34f7bcad5fcd3d11c7f33773fa44a6146f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Thu, 5 Jul 2018 18:23:18 +0200 Subject: [PATCH 03/21] fix impl Checkable for TestXt --- substrate/runtime/primitives/src/testing.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/substrate/runtime/primitives/src/testing.rs b/substrate/runtime/primitives/src/testing.rs index 7c712b40105e6..2b36ec8d057cf 100644 --- a/substrate/runtime/primitives/src/testing.rs +++ b/substrate/runtime/primitives/src/testing.rs @@ -157,12 +157,9 @@ impl Checkable for TestXt { +impl Checkable for TestXt { type Checked = Self; - type Address = u64; - type AccountId = u64; - fn sender(&self) -> &u64 { &(self.0).0 } - fn check Result>(self, _lookup: ThisLookup) -> Result { Ok(self) } + fn check_with(self, _: Ctx) -> Result { Ok(self) } } impl + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt { type AccountId = u64; From d2771697cf26dbbf3a3194fa5df2475f6959db7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Thu, 5 Jul 2018 18:28:02 +0200 Subject: [PATCH 04/21] fix impl Checkable for UncheckedExtrinsic --- substrate/runtime/primitives/src/generic.rs | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/substrate/runtime/primitives/src/generic.rs b/substrate/runtime/primitives/src/generic.rs index 6f8a46841c748..20b733f9c9897 100644 --- a/substrate/runtime/primitives/src/generic.rs +++ b/substrate/runtime/primitives/src/generic.rs @@ -96,7 +96,7 @@ impl UncheckedExtrinsic traits::Checkable +impl traits::Checkable for UncheckedExtrinsic> where Address: Member + Default + MaybeDisplay, @@ -106,18 +106,11 @@ where AccountId: Member + Default + MaybeDisplay, ::MaybeUnsigned: Member, Extrinsic: Slicable, + ThisLookup: FnOnce(&Address) -> Result, { - type Address = Address; - type AccountId = AccountId; type Checked = CheckedExtrinsic; - fn sender(&self) -> &Address { - &self.extrinsic.signed - } - - fn check(self, lookup: ThisLookup) -> Result where - ThisLookup: FnOnce(Address) -> Result, - { + fn check_with(self, lookup: ThisLookup) -> Result { if !self.is_signed() { Ok(CheckedExtrinsic(Extrinsic { signed: Default::default(), @@ -127,14 +120,17 @@ where } else { let extrinsic: Extrinsic = Extrinsic { - signed: lookup(self.extrinsic.signed)?, - index: self.extrinsic.index, - function: self.extrinsic.function, + signed: match lookup(&self.extrinsic.signed) { + Ok(x) => x, + Err(_) => return Err(self) + }, + index: self.extrinsic.index.clone(), + function: self.extrinsic.function.clone(), }; if ::verify_encoded_lazy(&self.signature, &extrinsic, &extrinsic.signed) { Ok(CheckedExtrinsic(extrinsic)) } else { - Err("bad signature in extrinsic") + Err(self) } } } From 60a9e0c6b20190a8edb5db451ddd14bc139f48d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Thu, 5 Jul 2018 18:28:37 +0200 Subject: [PATCH 05/21] fix tabs --- substrate/runtime/primitives/src/traits.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 5f75ff3f3cf43..56a45a1556d08 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -373,27 +373,27 @@ pub type HashingFor = <::Header as Header>::Hashing; /// check the validity of a piece of extrinsic information, usually by verifying the signature. /// for things that can be checked by providing additional context `Ctx` pub trait Checkable: Sized { - type Checked; + type Checked; - fn check_with(self, ctx: Ctx) -> Result; + fn check_with(self, ctx: Ctx) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. /// for things that can be checked without additional context. pub trait BlindCheckable: Sized { - type Checked; + type Checked; - /// gives back in case of an error. - fn check(self) -> Result; + /// gives back in case of an error. + fn check(self) -> Result; } // every BlindCheckable is also a Checkable for arbitrary context `Ctx` impl Checkable for T { type Checked = ::Checked; fn check_with(self, _: Ctx) -> Result { - BlindCheckable::check(self) - } + BlindCheckable::check(self) + } } /// An "executable" piece of information, used by the standard Substrate Executive in order to From 02eb103015b833c995c9f9067aac2542bb7ce5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:07:47 +0200 Subject: [PATCH 06/21] add ::Address to system::Trait since its no longer in Checkable trait --- demo/runtime/src/lib.rs | 1 + polkadot/runtime/src/lib.rs | 1 + polkadot/runtime/src/parachains.rs | 1 + substrate/runtime/council/src/lib.rs | 1 + substrate/runtime/democracy/src/lib.rs | 1 + substrate/runtime/executive/src/lib.rs | 1 + substrate/runtime/session/src/lib.rs | 1 + substrate/runtime/staking/src/mock.rs | 1 + substrate/runtime/system/src/lib.rs | 1 + substrate/runtime/timestamp/src/lib.rs | 1 + 10 files changed, 10 insertions(+) diff --git a/demo/runtime/src/lib.rs b/demo/runtime/src/lib.rs index 938bcbbfa2be3..f65d21e5868a7 100644 --- a/demo/runtime/src/lib.rs +++ b/demo/runtime/src/lib.rs @@ -89,6 +89,7 @@ impl system::Trait for Concrete { type Hashing = BlakeTwo256; type Digest = generic::Digest>; type AccountId = AccountId; + type Address = Address; type Header = generic::Header>; } diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 532de07cd76ef..746607a932f39 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -132,6 +132,7 @@ impl system::Trait for Concrete { type Hashing = BlakeTwo256; type Digest = generic::Digest; type AccountId = AccountId; + type Address = Address; type Header = Header; } /// System module for this concrete runtime. diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs index 3625633adf392..9486be6c92cc8 100644 --- a/polkadot/runtime/src/parachains.rs +++ b/polkadot/runtime/src/parachains.rs @@ -254,6 +254,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index a40a64b27b84f..52df49f3f100e 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -647,6 +647,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index c20d60d2de359..393a478b46ee9 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -389,6 +389,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index e5a8a1a19e29a..dcc68e5c73ea2 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -248,6 +248,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/session/src/lib.rs b/substrate/runtime/session/src/lib.rs index 74debe5a84e24..7a301bd14bc39 100644 --- a/substrate/runtime/session/src/lib.rs +++ b/substrate/runtime/session/src/lib.rs @@ -283,6 +283,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl timestamp::Trait for Test { diff --git a/substrate/runtime/staking/src/mock.rs b/substrate/runtime/staking/src/mock.rs index c2cf48dbd19ab..254276a2a3322 100644 --- a/substrate/runtime/staking/src/mock.rs +++ b/substrate/runtime/staking/src/mock.rs @@ -43,6 +43,7 @@ impl system::Trait for Test { type Hashing = ::primitives::traits::BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/system/src/lib.rs b/substrate/runtime/system/src/lib.rs index e5e0b47a29b9f..dce921f6d8f5f 100644 --- a/substrate/runtime/system/src/lib.rs +++ b/substrate/runtime/system/src/lib.rs @@ -69,6 +69,7 @@ pub trait Trait: Eq + Clone { type Hashing: Hashing; type Digest: Parameter + Member + Default + traits::Digest; type AccountId: Parameter + Member + MaybeDisplay + Ord + Default; + type Address: Parameter + Member + MaybeDisplay; type Header: Parameter + traits::Header< Number = Self::BlockNumber, Hashing = Self::Hashing, diff --git a/substrate/runtime/timestamp/src/lib.rs b/substrate/runtime/timestamp/src/lib.rs index f541e0a11f30a..497bf6f06819f 100644 --- a/substrate/runtime/timestamp/src/lib.rs +++ b/substrate/runtime/timestamp/src/lib.rs @@ -158,6 +158,7 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; + type Address = u64; type Header = Header; } impl consensus::Trait for Test { From b42b484a36efcd1a2e0d09ed7e48c393cb3013b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:08:22 +0200 Subject: [PATCH 07/21] replace tab by space in comment --- substrate/runtime/council/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index 52df49f3f100e..6e955c712792a 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -549,7 +549,7 @@ impl Module { #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] pub struct GenesisConfig { - // for the voting onto the council + // for the voting onto the council pub candidacy_bond: T::Balance, pub voter_bond: T::Balance, pub present_slash_per_voter: T::Balance, From 05fe805185cb78427a6780568ec48d79b6c4adc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:13:34 +0200 Subject: [PATCH 08/21] replace occurences of Checkable::check with ::check_with --- polkadot/runtime/src/utils.rs | 2 +- polkadot/transaction-pool/src/lib.rs | 2 +- substrate/runtime/executive/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/src/utils.rs b/polkadot/runtime/src/utils.rs index 4c16e215bab7e..1531590ff5fca 100644 --- a/polkadot/runtime/src/utils.rs +++ b/polkadot/runtime/src/utils.rs @@ -47,5 +47,5 @@ pub fn inherent_extrinsics(timestamp: ::primitives::Timestamp, parachain_heads: /// Checks an unchecked extrinsic for validity. pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool { - xt.check(Staking::lookup).is_ok() + xt.check_with(Staking::lookup).is_ok() } diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index 5f344035cec0a..e8ff48aa44fe4 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -281,7 +281,7 @@ impl<'a, A> txpool::Verifier for Verifier<'a, A> where } let (encoded_size, hash) = uxt.using_encoded(|e| (e.len(), BlakeTwo256::hash(e))); - let inner = match uxt.clone().check(|a| self.lookup(a)) { + let inner = match uxt.clone().check_with(|a| self.lookup(a)) { Ok(xt) => Some(xt), // keep the transaction around in the future pool and attempt to promote it later. Err(Self::NO_ACCOUNT) => None, diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index dcc68e5c73ea2..9ccf3c77c80d3 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -172,7 +172,7 @@ impl< /// Actually apply an extrinsic given its `encoded_len`; this doesn't note its hash. fn apply_extrinsic_no_note_with_len(uxt: Block::Extrinsic, encoded_len: usize) -> result::Result { // Verify the signature is good. - let xt = uxt.check(Lookup::lookup).map_err(internal::ApplyError::BadSignature)?; + let xt = uxt.check_with(Lookup::lookup).map_err(|_| internal::ApplyError::BadSignature(""))?; if xt.sender() != &Default::default() { // check index From 6a90ab5d79bccc3178995b8d30dc8f2efb51429b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:14:31 +0200 Subject: [PATCH 09/21] tx-pool: replace CheckedIntrinsic type alias since it now would require type param --- polkadot/runtime/src/lib.rs | 2 ++ polkadot/transaction-pool/src/lib.rs | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 746607a932f39..37611e388cb7d 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -92,6 +92,8 @@ pub type Address = staking::Address; pub type BlockId = generic::BlockId; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +/// Checked extrinsic type as expected by this runtime. +pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Extrinsic type as expected by this runtime. This is not the type that is signed. pub type Extrinsic = generic::Extrinsic; /// Extrinsic type that is signed. diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index e8ff48aa44fe4..a08332ceb5dc6 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -48,15 +48,12 @@ use extrinsic_pool::{Pool, Listener, txpool::{self, Readiness, scoring::{Change, use extrinsic_pool::api::ExtrinsicPool; use polkadot_api::PolkadotApi; use primitives::{AccountId, BlockId, Hash, Index, UncheckedExtrinsic as FutureProofUncheckedExtrinsic}; -use runtime::{Address, UncheckedExtrinsic}; +use runtime::{Address, UncheckedExtrinsic, CheckedExtrinsic}; use substrate_runtime_primitives::traits::{Bounded, Checkable, Hashing, BlakeTwo256}; pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps}; pub use error::{Error, ErrorKind, Result}; -/// Type alias for convenience. -pub type CheckedExtrinsic = ::Checked; - /// A verified transaction which should be includable and non-inherent. #[derive(Clone, Debug)] pub struct VerifiedTransaction { From de69b7a4c47b4a3b9ff9dc7560319695d9269013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:15:42 +0200 Subject: [PATCH 10/21] make more uses of Checkable compile --- substrate/runtime/primitives/src/generic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/runtime/primitives/src/generic.rs b/substrate/runtime/primitives/src/generic.rs index 20b733f9c9897..62722beb8c32b 100644 --- a/substrate/runtime/primitives/src/generic.rs +++ b/substrate/runtime/primitives/src/generic.rs @@ -106,7 +106,7 @@ where AccountId: Member + Default + MaybeDisplay, ::MaybeUnsigned: Member, Extrinsic: Slicable, - ThisLookup: FnOnce(&Address) -> Result, + ThisLookup: FnOnce(Address) -> Result, { type Checked = CheckedExtrinsic; @@ -120,7 +120,7 @@ where } else { let extrinsic: Extrinsic = Extrinsic { - signed: match lookup(&self.extrinsic.signed) { + signed: match lookup(self.extrinsic.signed.clone()) { Ok(x) => x, Err(_) => return Err(self) }, From 574b2a8338749c9008179cb45b8282677af86cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:17:16 +0200 Subject: [PATCH 11/21] adapt Executive impl to new Checkable trait --- substrate/runtime/executive/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index 9ccf3c77c80d3..6349b7f38b2ac 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -84,12 +84,12 @@ pub struct Executive< impl< System: system::Trait, Block: traits::Block, - Lookup: AuxLookup::Address, Target=System::AccountId>, + Lookup: AuxLookup, Payment: MakePayment, Finalisation: Executable, > Executive where - Block::Extrinsic: Checkable + Slicable, - ::Checked: Applyable + Block::Extrinsic: Checkable Result> + Slicable, + Result>>::Checked: Applyable { /// Start the execution of a particular block. pub fn initialise_block(header: &System::Header) { From 8da0a5a5f07cd6aab59cf52752d59a250099deac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 21:45:51 +0200 Subject: [PATCH 12/21] fix that CheckedExtrinsic takes AccountId not Address as first type param --- polkadot/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 37611e388cb7d..450db7288ab7e 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -93,7 +93,7 @@ pub type BlockId = generic::BlockId; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Checked extrinsic type as expected by this runtime. -pub type CheckedExtrinsic = generic::CheckedExtrinsic; +pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Extrinsic type as expected by this runtime. This is not the type that is signed. pub type Extrinsic = generic::Extrinsic; /// Extrinsic type that is signed. From 7cccc1d70447df8732acb610471788f5a8688e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 22:46:10 +0200 Subject: [PATCH 13/21] Checkable trait: return error again since it's required in some cases --- polkadot/transaction-pool/src/lib.rs | 4 ++-- substrate/runtime/primitives/src/generic.rs | 9 +++++---- substrate/runtime/primitives/src/testing.rs | 3 ++- substrate/runtime/primitives/src/traits.rs | 13 ++++++++++--- substrate/test-runtime/src/lib.rs | 5 +++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index a08332ceb5dc6..c9a7ab169c4e5 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -281,8 +281,8 @@ impl<'a, A> txpool::Verifier for Verifier<'a, A> where let inner = match uxt.clone().check_with(|a| self.lookup(a)) { Ok(xt) => Some(xt), // keep the transaction around in the future pool and attempt to promote it later. - Err(Self::NO_ACCOUNT) => None, - Err(e) => bail!(e), + Err((_, Self::NO_ACCOUNT)) => None, + Err((_, e)) => bail!(e), }; let sender = inner.as_ref().map(|x| x.signed.clone()); diff --git a/substrate/runtime/primitives/src/generic.rs b/substrate/runtime/primitives/src/generic.rs index 62722beb8c32b..2487e7afeb4b2 100644 --- a/substrate/runtime/primitives/src/generic.rs +++ b/substrate/runtime/primitives/src/generic.rs @@ -109,8 +109,9 @@ where ThisLookup: FnOnce(Address) -> Result, { type Checked = CheckedExtrinsic; + type Error = &'static str; - fn check_with(self, lookup: ThisLookup) -> Result { + fn check_with(self, lookup: ThisLookup) -> Result { if !self.is_signed() { Ok(CheckedExtrinsic(Extrinsic { signed: Default::default(), @@ -121,8 +122,8 @@ where let extrinsic: Extrinsic = Extrinsic { signed: match lookup(self.extrinsic.signed.clone()) { - Ok(x) => x, - Err(_) => return Err(self) + Ok(success) => success, + Err(error) => return Err((self, error)), }, index: self.extrinsic.index.clone(), function: self.extrinsic.function.clone(), @@ -130,7 +131,7 @@ where if ::verify_encoded_lazy(&self.signature, &extrinsic, &extrinsic.signed) { Ok(CheckedExtrinsic(extrinsic)) } else { - Err(self) + Err((self, "bad signature in extrinsic")) } } } diff --git a/substrate/runtime/primitives/src/testing.rs b/substrate/runtime/primitives/src/testing.rs index 2b36ec8d057cf..77788b2925979 100644 --- a/substrate/runtime/primitives/src/testing.rs +++ b/substrate/runtime/primitives/src/testing.rs @@ -158,8 +158,9 @@ impl Checkable for TestXt { + type Error = (); type Checked = Self; - fn check_with(self, _: Ctx) -> Result { Ok(self) } + fn check_with(self, _: Ctx) -> Result { Ok(self) } } impl + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt { type AccountId = u64; diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 56a45a1556d08..2cc84f03c6db6 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -373,25 +373,32 @@ pub type HashingFor = <::Header as Header>::Hashing; /// check the validity of a piece of extrinsic information, usually by verifying the signature. /// for things that can be checked by providing additional context `Ctx` pub trait Checkable: Sized { + /// returned in case the check succeeds type Checked; + /// returned in case the check fails + type Error; - fn check_with(self, ctx: Ctx) -> Result; + fn check_with(self, ctx: Ctx) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. /// for things that can be checked without additional context. pub trait BlindCheckable: Sized { + /// returned in case the check succeeds type Checked; + /// returned in case the check fails + type Error; /// gives back in case of an error. - fn check(self) -> Result; + fn check(self) -> Result; } // every BlindCheckable is also a Checkable for arbitrary context `Ctx` impl Checkable for T { type Checked = ::Checked; - fn check_with(self, _: Ctx) -> Result { + type Error = T::Error; + fn check_with(self, _: Ctx) -> Result { BlindCheckable::check(self) } } diff --git a/substrate/test-runtime/src/lib.rs b/substrate/test-runtime/src/lib.rs index 6f9da3a93d8ed..ddf2d40d2c7bf 100644 --- a/substrate/test-runtime/src/lib.rs +++ b/substrate/test-runtime/src/lib.rs @@ -119,12 +119,13 @@ impl Slicable for Extrinsic { impl BlindCheckable for Extrinsic { type Checked = Self; + type Error = &'static str; - fn check(self) -> Result { + fn check(self) -> Result { if ::runtime_primitives::verify_encoded_lazy(&self.signature, &self.transfer, &self.transfer.from) { Ok(self) } else { - Err(self) + Err((self, "bad signature")) } } } From b147c0a43fc3044d44203691da99e76be8533fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Fri, 6 Jul 2018 22:59:02 +0200 Subject: [PATCH 14/21] Checkable: improve docstrings --- substrate/runtime/primitives/src/traits.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 2cc84f03c6db6..45323ba5159c5 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -378,6 +378,7 @@ pub trait Checkable: Sized { /// returned in case the check fails type Error; + /// gives back unchanged `self` in case of an error. fn check_with(self, ctx: Ctx) -> Result; } @@ -390,7 +391,7 @@ pub trait BlindCheckable: Sized { /// returned in case the check fails type Error; - /// gives back in case of an error. + /// gives back unchanged `self` in case of an error. fn check(self) -> Result; } From 7642b81b2468fe4d04be1f3868364c6b7005b32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Sun, 8 Jul 2018 00:53:50 +0200 Subject: [PATCH 15/21] consistent punctuation and capitalization in docstrings --- substrate/runtime/primitives/src/traits.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 45323ba5159c5..e7ffcb1d8066d 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -371,31 +371,33 @@ pub type HashingFor = <::Header as Header>::Hashing; /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. -/// for things that can be checked by providing additional context `Ctx` +/// Implement for pieces of information that require some additional context `Ctx` in order to be +/// checked. pub trait Checkable: Sized { - /// returned in case the check succeeds + /// Returned if `check_with` succeeds. type Checked; - /// returned in case the check fails + /// Returned if `check_with` fails. type Error; - /// gives back unchanged `self` in case of an error. + /// Gives back ownership of unchanged `self` in case of an error. fn check_with(self, ctx: Ctx) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. -/// for things that can be checked without additional context. +/// Implement for pieces of information that don't require additional context in order to be +/// checked. pub trait BlindCheckable: Sized { - /// returned in case the check succeeds + /// Returned if `check` succeeds. type Checked; - /// returned in case the check fails + /// Returned if `check` fails. type Error; - /// gives back unchanged `self` in case of an error. + /// Gives back ownership of unchanged `self` in case of an error. fn check(self) -> Result; } -// every BlindCheckable is also a Checkable for arbitrary context `Ctx` +// Every `BlindCheckable` is also a `Checkable` for arbitrary context `Ctx`. impl Checkable for T { type Checked = ::Checked; type Error = T::Error; From 70ab21073b63e65347cfdd4e732f9d97d231bd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Mon, 9 Jul 2018 20:13:00 +0200 Subject: [PATCH 16/21] Ctx -> Context addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200956240 --- substrate/runtime/primitives/src/testing.rs | 4 ++-- substrate/runtime/primitives/src/traits.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/substrate/runtime/primitives/src/testing.rs b/substrate/runtime/primitives/src/testing.rs index 77788b2925979..5438e80c5bc1f 100644 --- a/substrate/runtime/primitives/src/testing.rs +++ b/substrate/runtime/primitives/src/testing.rs @@ -157,10 +157,10 @@ impl Checkable for TestXt { +impl Checkable for TestXt { type Error = (); type Checked = Self; - fn check_with(self, _: Ctx) -> Result { Ok(self) } + fn check_with(self, _: Context) -> Result { Ok(self) } } impl + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt { type AccountId = u64; diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index e7ffcb1d8066d..28a09bc9fdde0 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -371,16 +371,16 @@ pub type HashingFor = <::Header as Header>::Hashing; /// A "checkable" piece of information, used by the standard Substrate Executive in order to /// check the validity of a piece of extrinsic information, usually by verifying the signature. -/// Implement for pieces of information that require some additional context `Ctx` in order to be +/// Implement for pieces of information that require some additional context `Context` in order to be /// checked. -pub trait Checkable: Sized { +pub trait Checkable: Sized { /// Returned if `check_with` succeeds. type Checked; /// Returned if `check_with` fails. type Error; /// Gives back ownership of unchanged `self` in case of an error. - fn check_with(self, ctx: Ctx) -> Result; + fn check_with(self, context: Context) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to @@ -397,11 +397,11 @@ pub trait BlindCheckable: Sized { fn check(self) -> Result; } -// Every `BlindCheckable` is also a `Checkable` for arbitrary context `Ctx`. -impl Checkable for T { +// Every `BlindCheckable` is also a `Checkable` for arbitrary `Context`. +impl Checkable for T { type Checked = ::Checked; type Error = T::Error; - fn check_with(self, _: Ctx) -> Result { + fn check_with(self, _: Context) -> Result { BlindCheckable::check(self) } } From f4fcebb8d3700a2642560cb7b4e486eecb8d5977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Mon, 9 Jul 2018 20:33:03 +0200 Subject: [PATCH 17/21] reduce trait bounds for impl Checkable for TestXt addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200839303 --- substrate/runtime/primitives/src/testing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/runtime/primitives/src/testing.rs b/substrate/runtime/primitives/src/testing.rs index 5438e80c5bc1f..a8436bd2d4ff3 100644 --- a/substrate/runtime/primitives/src/testing.rs +++ b/substrate/runtime/primitives/src/testing.rs @@ -157,7 +157,7 @@ impl Checkable for TestXt { +impl Checkable for TestXt { type Error = (); type Checked = Self; fn check_with(self, _: Context) -> Result { Ok(self) } From 21676fe8a80c52fb68c8b1d0e2f5dd5811f2c529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Mon, 9 Jul 2018 22:46:50 +0200 Subject: [PATCH 18/21] use ::Checked addresses https://github.com/paritytech/polkadot/pull/287#discussion_r200955165 --- polkadot/runtime/src/lib.rs | 2 -- polkadot/transaction-pool/src/lib.rs | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 450db7288ab7e..746607a932f39 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -92,8 +92,6 @@ pub type Address = staking::Address; pub type BlockId = generic::BlockId; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; -/// Checked extrinsic type as expected by this runtime. -pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Extrinsic type as expected by this runtime. This is not the type that is signed. pub type Extrinsic = generic::Extrinsic; /// Extrinsic type that is signed. diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index c9a7ab169c4e5..38d3096f02768 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -48,12 +48,15 @@ use extrinsic_pool::{Pool, Listener, txpool::{self, Readiness, scoring::{Change, use extrinsic_pool::api::ExtrinsicPool; use polkadot_api::PolkadotApi; use primitives::{AccountId, BlockId, Hash, Index, UncheckedExtrinsic as FutureProofUncheckedExtrinsic}; -use runtime::{Address, UncheckedExtrinsic, CheckedExtrinsic}; +use runtime::{Address, UncheckedExtrinsic}; use substrate_runtime_primitives::traits::{Bounded, Checkable, Hashing, BlakeTwo256}; pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps}; pub use error::{Error, ErrorKind, Result}; +/// Type alias for convenience. +pub type CheckedExtrinsic = std::result::Result>>::Checked; + /// A verified transaction which should be includable and non-inherent. #[derive(Clone, Debug)] pub struct VerifiedTransaction { From 2e3e4a89e46135f2c7dd2f39411c92025bb42e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Mon, 9 Jul 2018 23:04:26 +0200 Subject: [PATCH 19/21] Revert "add ::Address to system::Trait since its no longer in Checkable trait" This reverts commit 02eb103015b833c995c9f9067aac2542bb7ce5ea. --- demo/runtime/src/lib.rs | 1 - polkadot/runtime/src/lib.rs | 1 - polkadot/runtime/src/parachains.rs | 1 - substrate/runtime/council/src/lib.rs | 1 - substrate/runtime/democracy/src/lib.rs | 1 - substrate/runtime/executive/src/lib.rs | 1 - substrate/runtime/session/src/lib.rs | 1 - substrate/runtime/staking/src/mock.rs | 1 - substrate/runtime/system/src/lib.rs | 1 - substrate/runtime/timestamp/src/lib.rs | 1 - 10 files changed, 10 deletions(-) diff --git a/demo/runtime/src/lib.rs b/demo/runtime/src/lib.rs index f65d21e5868a7..938bcbbfa2be3 100644 --- a/demo/runtime/src/lib.rs +++ b/demo/runtime/src/lib.rs @@ -89,7 +89,6 @@ impl system::Trait for Concrete { type Hashing = BlakeTwo256; type Digest = generic::Digest>; type AccountId = AccountId; - type Address = Address; type Header = generic::Header>; } diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 746607a932f39..532de07cd76ef 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -132,7 +132,6 @@ impl system::Trait for Concrete { type Hashing = BlakeTwo256; type Digest = generic::Digest; type AccountId = AccountId; - type Address = Address; type Header = Header; } /// System module for this concrete runtime. diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs index 9486be6c92cc8..3625633adf392 100644 --- a/polkadot/runtime/src/parachains.rs +++ b/polkadot/runtime/src/parachains.rs @@ -254,7 +254,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index 6e955c712792a..e6c3c9b4164d4 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -647,7 +647,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index 393a478b46ee9..c20d60d2de359 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -389,7 +389,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index 6349b7f38b2ac..bd918df94f806 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -248,7 +248,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/session/src/lib.rs b/substrate/runtime/session/src/lib.rs index 7a301bd14bc39..74debe5a84e24 100644 --- a/substrate/runtime/session/src/lib.rs +++ b/substrate/runtime/session/src/lib.rs @@ -283,7 +283,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl timestamp::Trait for Test { diff --git a/substrate/runtime/staking/src/mock.rs b/substrate/runtime/staking/src/mock.rs index 254276a2a3322..c2cf48dbd19ab 100644 --- a/substrate/runtime/staking/src/mock.rs +++ b/substrate/runtime/staking/src/mock.rs @@ -43,7 +43,6 @@ impl system::Trait for Test { type Hashing = ::primitives::traits::BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl session::Trait for Test { diff --git a/substrate/runtime/system/src/lib.rs b/substrate/runtime/system/src/lib.rs index dce921f6d8f5f..e5e0b47a29b9f 100644 --- a/substrate/runtime/system/src/lib.rs +++ b/substrate/runtime/system/src/lib.rs @@ -69,7 +69,6 @@ pub trait Trait: Eq + Clone { type Hashing: Hashing; type Digest: Parameter + Member + Default + traits::Digest; type AccountId: Parameter + Member + MaybeDisplay + Ord + Default; - type Address: Parameter + Member + MaybeDisplay; type Header: Parameter + traits::Header< Number = Self::BlockNumber, Hashing = Self::Hashing, diff --git a/substrate/runtime/timestamp/src/lib.rs b/substrate/runtime/timestamp/src/lib.rs index 497bf6f06819f..f541e0a11f30a 100644 --- a/substrate/runtime/timestamp/src/lib.rs +++ b/substrate/runtime/timestamp/src/lib.rs @@ -158,7 +158,6 @@ mod tests { type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; - type Address = u64; type Header = Header; } impl consensus::Trait for Test { From 6e550d889fbbd2104368443d3251bdc639c95a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Mon, 9 Jul 2018 23:10:22 +0200 Subject: [PATCH 20/21] runtime/executive: properly fix that Address no longer in Checkable --- substrate/runtime/executive/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index bd918df94f806..67baf12ea4aee 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -82,14 +82,15 @@ pub struct Executive< >(PhantomData<(System, Block, Lookup, Payment, Finalisation)>); impl< + Address, System: system::Trait, Block: traits::Block, - Lookup: AuxLookup, + Lookup: AuxLookup, Payment: MakePayment, Finalisation: Executable, > Executive where - Block::Extrinsic: Checkable Result> + Slicable, - Result>>::Checked: Applyable + Block::Extrinsic: Checkable Result> + Slicable, + Result>>::Checked: Applyable { /// Start the execution of a particular block. pub fn initialise_block(header: &System::Header) { From eef85e1c5a024f99a94cea9a4f84bd9391e1339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kru=CC=88ger?= Date: Tue, 10 Jul 2018 20:24:36 +0200 Subject: [PATCH 21/21] return `Result` from `Checkable::check` --- polkadot/transaction-pool/src/lib.rs | 4 ++-- substrate/runtime/executive/src/lib.rs | 2 +- substrate/runtime/primitives/src/generic.rs | 14 +++++--------- substrate/runtime/primitives/src/testing.rs | 3 +-- substrate/runtime/primitives/src/traits.rs | 13 +++---------- substrate/test-runtime/src/lib.rs | 5 ++--- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index 38d3096f02768..85b06698b0179 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -284,8 +284,8 @@ impl<'a, A> txpool::Verifier for Verifier<'a, A> where let inner = match uxt.clone().check_with(|a| self.lookup(a)) { Ok(xt) => Some(xt), // keep the transaction around in the future pool and attempt to promote it later. - Err((_, Self::NO_ACCOUNT)) => None, - Err((_, e)) => bail!(e), + Err(Self::NO_ACCOUNT) => None, + Err(e) => bail!(e), }; let sender = inner.as_ref().map(|x| x.signed.clone()); diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index 67baf12ea4aee..fd4e9a0c0e3a7 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -173,7 +173,7 @@ impl< /// Actually apply an extrinsic given its `encoded_len`; this doesn't note its hash. fn apply_extrinsic_no_note_with_len(uxt: Block::Extrinsic, encoded_len: usize) -> result::Result { // Verify the signature is good. - let xt = uxt.check_with(Lookup::lookup).map_err(|_| internal::ApplyError::BadSignature(""))?; + let xt = uxt.check_with(Lookup::lookup).map_err(internal::ApplyError::BadSignature)?; if xt.sender() != &Default::default() { // check index diff --git a/substrate/runtime/primitives/src/generic.rs b/substrate/runtime/primitives/src/generic.rs index 2487e7afeb4b2..0c50b2d8f7b01 100644 --- a/substrate/runtime/primitives/src/generic.rs +++ b/substrate/runtime/primitives/src/generic.rs @@ -109,9 +109,8 @@ where ThisLookup: FnOnce(Address) -> Result, { type Checked = CheckedExtrinsic; - type Error = &'static str; - fn check_with(self, lookup: ThisLookup) -> Result { + fn check_with(self, lookup: ThisLookup) -> Result { if !self.is_signed() { Ok(CheckedExtrinsic(Extrinsic { signed: Default::default(), @@ -121,17 +120,14 @@ where } else { let extrinsic: Extrinsic = Extrinsic { - signed: match lookup(self.extrinsic.signed.clone()) { - Ok(success) => success, - Err(error) => return Err((self, error)), - }, - index: self.extrinsic.index.clone(), - function: self.extrinsic.function.clone(), + signed: lookup(self.extrinsic.signed)?, + index: self.extrinsic.index, + function: self.extrinsic.function, }; if ::verify_encoded_lazy(&self.signature, &extrinsic, &extrinsic.signed) { Ok(CheckedExtrinsic(extrinsic)) } else { - Err((self, "bad signature in extrinsic")) + Err("bad signature in extrinsic") } } } diff --git a/substrate/runtime/primitives/src/testing.rs b/substrate/runtime/primitives/src/testing.rs index a8436bd2d4ff3..12e347e1e3a8b 100644 --- a/substrate/runtime/primitives/src/testing.rs +++ b/substrate/runtime/primitives/src/testing.rs @@ -158,9 +158,8 @@ impl Checkable for TestXt { - type Error = (); type Checked = Self; - fn check_with(self, _: Context) -> Result { Ok(self) } + fn check_with(self, _: Context) -> Result { Ok(self) } } impl + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt { type AccountId = u64; diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index 28a09bc9fdde0..aafbcc56be57a 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -376,11 +376,8 @@ pub type HashingFor = <::Header as Header>::Hashing; pub trait Checkable: Sized { /// Returned if `check_with` succeeds. type Checked; - /// Returned if `check_with` fails. - type Error; - /// Gives back ownership of unchanged `self` in case of an error. - fn check_with(self, context: Context) -> Result; + fn check_with(self, context: Context) -> Result; } /// A "checkable" piece of information, used by the standard Substrate Executive in order to @@ -390,18 +387,14 @@ pub trait Checkable: Sized { pub trait BlindCheckable: Sized { /// Returned if `check` succeeds. type Checked; - /// Returned if `check` fails. - type Error; - /// Gives back ownership of unchanged `self` in case of an error. - fn check(self) -> Result; + fn check(self) -> Result; } // Every `BlindCheckable` is also a `Checkable` for arbitrary `Context`. impl Checkable for T { type Checked = ::Checked; - type Error = T::Error; - fn check_with(self, _: Context) -> Result { + fn check_with(self, _: Context) -> Result { BlindCheckable::check(self) } } diff --git a/substrate/test-runtime/src/lib.rs b/substrate/test-runtime/src/lib.rs index ddf2d40d2c7bf..ee4357aaeee76 100644 --- a/substrate/test-runtime/src/lib.rs +++ b/substrate/test-runtime/src/lib.rs @@ -119,13 +119,12 @@ impl Slicable for Extrinsic { impl BlindCheckable for Extrinsic { type Checked = Self; - type Error = &'static str; - fn check(self) -> Result { + fn check(self) -> Result { if ::runtime_primitives::verify_encoded_lazy(&self.signature, &self.transfer, &self.transfer.from) { Ok(self) } else { - Err((self, "bad signature")) + Err("bad signature") } } }