-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Issue 212 - refactor Checkable trait to be more generic #287
Changes from 15 commits
7937af9
cf080b0
0b2ff34
d277169
60a9e0c
02eb103
b42b484
05fe805
6a90ab5
de69b7a
574b2a8
8da0a5a
7cccc1d
b147c0a
7642b81
70ab210
f4fcebb
21676fe
2e3e4a8
6e550d8
eef85e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,12 +84,12 @@ pub struct Executive< | |
| impl< | ||
| System: system::Trait, | ||
| Block: traits::Block<Header=System::Header, Hash=System::Hash>, | ||
| Lookup: AuxLookup<Source=<Block::Extrinsic as Checkable>::Address, Target=System::AccountId>, | ||
| Lookup: AuxLookup<Source=System::Address, Target=System::AccountId>, | ||
| Payment: MakePayment<System::AccountId>, | ||
| Finalisation: Executable, | ||
| > Executive<System, Block, Lookup, Payment, Finalisation> where | ||
| Block::Extrinsic: Checkable<AccountId=System::AccountId> + Slicable, | ||
| <Block::Extrinsic as Checkable>::Checked: Applyable<Index=System::Index, AccountId=System::AccountId> | ||
| Block::Extrinsic: Checkable<fn(System::Address) -> Result<System::AccountId, &'static str>> + Slicable, | ||
| <Block::Extrinsic as Checkable<fn(System::Address) -> Result<System::AccountId, &'static str>>>::Checked: Applyable<Index=System::Index, AccountId=System::AccountId> | ||
| { | ||
| /// Start the execution of a particular block. | ||
| pub fn initialise_block(header: &System::Header) { | ||
|
|
@@ -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<internal::ApplyOutcome, internal::ApplyError> { | ||
| // 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 | ||
|
|
@@ -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 { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,12 +157,10 @@ impl<Call: AuxDispatchable + Slicable + Sized + Send + Sync + Serialize + Deseri | |
| self.0.encode() | ||
| } | ||
| } | ||
| impl<Call: 'static + AuxDispatchable + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Checkable for TestXt<Call> { | ||
| impl<Call: 'static + AuxDispatchable + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug, Ctx> Checkable<Ctx> for TestXt<Call> { | ||
|
||
| type Error = (); | ||
| type Checked = Self; | ||
| type Address = u64; | ||
| type AccountId = u64; | ||
| fn sender(&self) -> &u64 { &(self.0).0 } | ||
| fn check<ThisLookup: FnOnce(Self::Address) -> Result<Self::AccountId, &'static str>>(self, _lookup: ThisLookup) -> Result<Self::Checked, &'static str> { Ok(self) } | ||
| fn check_with(self, _: Ctx) -> Result<Self::Checked, (Self, ())> { Ok(self) } | ||
| } | ||
| impl<Call: AuxDispatchable<Aux = u64> + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt<Call> { | ||
| type AccountId = u64; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,31 +371,39 @@ pub type HashingFor<B> = <<B as Block>::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<ThisLookup: FnOnce(Self::Address) -> Result<Self::AccountId, &'static str>>(self, lookup: ThisLookup) -> Result<Self::Checked, &'static str>; | ||
| /// Implement for pieces of information that require some additional context `Ctx` in order to be | ||
| /// checked. | ||
| pub trait Checkable<Ctx>: 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<Self::Checked, (Self, Self::Error)>; | ||
| } | ||
|
|
||
| /// 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<Self::Checked, &'static str>; | ||
| /// Implement for pieces of information that don't require additional context in order to be | ||
| /// checked. | ||
| 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<Self::Checked, (Self, Self::Error)>; | ||
| } | ||
|
|
||
| impl<T: BlindCheckable> Checkable for T { | ||
| type Address = <Self as BlindCheckable>::Address; | ||
| type AccountId = <Self as BlindCheckable>::Address; | ||
| // Every `BlindCheckable` is also a `Checkable` for arbitrary context `Ctx`. | ||
| impl<T: BlindCheckable, Ctx> Checkable<Ctx> for T { | ||
| type Checked = <Self as BlindCheckable>::Checked; | ||
| fn sender(&self) -> &Self::Address { BlindCheckable::sender(self) } | ||
| fn check<ThisLookup: FnOnce(Self::Address) -> Result<Self::AccountId, &'static str>>(self, _: ThisLookup) -> Result<Self::Checked, &'static str> { BlindCheckable::check(self) } | ||
| type Error = T::Error; | ||
| fn check_with(self, _: Ctx) -> Result<Self::Checked, (Self, Self::Error)> { | ||
| BlindCheckable::check(self) | ||
| } | ||
| } | ||
|
|
||
| /// An "executable" piece of information, used by the standard Substrate Executive in order to | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ pub trait Trait: Eq + Clone { | |
| type Hashing: Hashing<Output = Self::Hash>; | ||
| 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, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to derive as
<UncheckedExtrinsic as Checkable>::Checked, otherwise we might end up with crazy error messages when the types diverge.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed this because<UncheckedExtrinsic as Checkable>::Checkedhttps://github.com/paritytech/polkadot/pull/287/files#diff-c7bae7b0ef067fe57fc5ad9bab233f29L57 no longer compiles asCheckablenow takes the type paramContext. could change this topub type CheckedExtrinsic<Context> = <UncheckedExtrinsic as Checkable<Context>>::Checked;but then the type param would be required all throughout https://github.com/paritytech/polkadot/blob/master/polkadot/transaction-pool/src/lib.rs since https://github.com/paritytech/polkadot/blob/master/polkadot/transaction-pool/src/lib.rs#L64 and then for everything that usesVerifiedTransaction. how should i proceed on this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in paritytech/polkadot@21676fe