Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7937af9
runtime: refactor Checkable and BlindCheckable traits
snd Jul 5, 2018
cf080b0
fix impl BlindCheckable for Extrinsic
snd Jul 5, 2018
0b2ff34
fix impl Checkable for TestXt
snd Jul 5, 2018
d277169
fix impl Checkable for UncheckedExtrinsic
snd Jul 5, 2018
60a9e0c
fix tabs
snd Jul 5, 2018
02eb103
add ::Address to system::Trait since its no longer in Checkable trait
snd Jul 6, 2018
b42b484
replace tab by space in comment
snd Jul 6, 2018
05fe805
replace occurences of Checkable::check with ::check_with
snd Jul 6, 2018
6a90ab5
tx-pool: replace CheckedIntrinsic type alias since it now would requi…
snd Jul 6, 2018
de69b7a
make more uses of Checkable compile
snd Jul 6, 2018
574b2a8
adapt Executive impl to new Checkable trait
snd Jul 6, 2018
8da0a5a
fix that CheckedExtrinsic takes AccountId not Address as first type p…
snd Jul 6, 2018
7cccc1d
Checkable trait: return error again since it's required in some cases
snd Jul 6, 2018
b147c0a
Checkable: improve docstrings
snd Jul 6, 2018
7642b81
consistent punctuation and capitalization in docstrings
snd Jul 7, 2018
70ab210
Ctx -> Context
snd Jul 9, 2018
f4fcebb
reduce trait bounds for impl Checkable for TestXt
snd Jul 9, 2018
21676fe
use <UncheckedExtrinsic as Checkable>::Checked
snd Jul 9, 2018
2e3e4a8
Revert "add ::Address to system::Trait since its no longer in Checkab…
snd Jul 9, 2018
6e550d8
runtime/executive: properly fix that Address no longer in Checkable
snd Jul 9, 2018
eef85e1
return `Result<Self::Checked, &'static str>` from `Checkable::check`
snd Jul 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polkadot/runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 2 additions & 2 deletions polkadot/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransacti
pub use error::{Error, ErrorKind, Result};

/// Type alias for convenience.
pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable>::Checked;
pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable<fn(Address) -> std::result::Result<AccountId, &'static str>>>::Checked;

/// A verified transaction which should be includable and non-inherent.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'a, A> txpool::Verifier<UncheckedExtrinsic> 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,
Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/council/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl<T: Trait> Module<T> {
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct GenesisConfig<T: Trait> {
// 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,
Expand Down
9 changes: 5 additions & 4 deletions substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ pub struct Executive<
>(PhantomData<(System, Block, Lookup, Payment, Finalisation)>);

impl<
Address,
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=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(Address) -> Result<System::AccountId, &'static str>> + Slicable,
<Block::Extrinsic as Checkable<fn(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) {
Expand Down Expand Up @@ -172,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<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
Expand Down
13 changes: 3 additions & 10 deletions substrate/runtime/primitives/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<Address, AccountId, Index, Call, Signature> UncheckedExtrinsic<Address, Ind
}
}

impl<Address, AccountId, Index, Call, Signature> traits::Checkable
impl<Address, AccountId, Index, Call, Signature, ThisLookup> traits::Checkable<ThisLookup>
for UncheckedExtrinsic<Address, Index, Call, ::MaybeUnsigned<Signature>>
where
Address: Member + Default + MaybeDisplay,
Expand All @@ -106,18 +106,11 @@ where
AccountId: Member + Default + MaybeDisplay,
::MaybeUnsigned<Signature>: Member,
Extrinsic<AccountId, Index, Call>: Slicable,
ThisLookup: FnOnce(Address) -> Result<AccountId, &'static str>,
{
type Address = Address;
type AccountId = AccountId;
type Checked = CheckedExtrinsic<AccountId, Index, Call>;

fn sender(&self) -> &Address {
&self.extrinsic.signed
}

fn check<ThisLookup>(self, lookup: ThisLookup) -> Result<Self::Checked, &'static str> where
ThisLookup: FnOnce(Address) -> Result<AccountId, &'static str>,
{
fn check_with(self, lookup: ThisLookup) -> Result<Self::Checked, &'static str> {
if !self.is_signed() {
Ok(CheckedExtrinsic(Extrinsic {
signed: Default::default(),
Expand Down
7 changes: 2 additions & 5 deletions substrate/runtime/primitives/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ 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: Slicable + Sync + Send + Serialize + AuxDispatchable, Context> Checkable<Context> for TestXt<Call> {
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, _: Context) -> Result<Self::Checked, &'static str> { Ok(self) }
}
impl<Call: AuxDispatchable<Aux = u64> + Slicable + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> Applyable for TestXt<Call> {
type AccountId = u64;
Expand Down
35 changes: 18 additions & 17 deletions substrate/runtime/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,31 +371,32 @@ 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 `Context` in order to be
/// checked.
pub trait Checkable<Context>: Sized {
/// Returned if `check_with` succeeds.
type Checked;

fn check_with(self, context: Context) -> Result<Self::Checked, &'static str>;
}

/// 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;
/// 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;

fn check(self) -> Result<Self::Checked, &'static str>;
}

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`.
impl<T: BlindCheckable, Context> Checkable<Context> 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) }
fn check_with(self, _: Context) -> Result<Self::Checked, &'static str> {
BlindCheckable::check(self)
}
}

/// An "executable" piece of information, used by the standard Substrate Executive in order to
Expand Down
4 changes: 0 additions & 4 deletions substrate/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ 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<Self, &'static str> {
if ::runtime_primitives::verify_encoded_lazy(&self.signature, &self.transfer, &self.transfer.from) {
Ok(self)
Expand Down