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 1 commit
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
Prev Previous commit
return Result<Self::Checked, &'static str> from Checkable::check
  • Loading branch information
snd committed Jul 10, 2018
commit eef85e1c5a024f99a94cea9a4f84bd9391e1339b
4 changes: 2 additions & 2 deletions polkadot/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ impl<'a, A> txpool::Verifier<UncheckedExtrinsic> 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());

Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<internal::ApplyOutcome, internal::ApplyError> {
// 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
Expand Down
14 changes: 5 additions & 9 deletions substrate/runtime/primitives/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ where
ThisLookup: FnOnce(Address) -> Result<AccountId, &'static str>,
{
type Checked = CheckedExtrinsic<AccountId, Index, Call>;
type Error = &'static str;

fn check_with(self, lookup: ThisLookup) -> Result<Self::Checked, (Self, Self::Error)> {
fn check_with(self, lookup: ThisLookup) -> Result<Self::Checked, &'static str> {
if !self.is_signed() {
Ok(CheckedExtrinsic(Extrinsic {
signed: Default::default(),
Expand All @@ -121,17 +120,14 @@ where
} else {
let extrinsic: Extrinsic<AccountId, Index, Call>
= 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")
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions substrate/runtime/primitives/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ impl<Call: AuxDispatchable + Slicable + Sized + Send + Sync + Serialize + Deseri
}
}
impl<Call: Slicable + Sync + Send + Serialize + AuxDispatchable, Context> Checkable<Context> for TestXt<Call> {
type Error = ();
type Checked = Self;
fn check_with(self, _: Context) -> Result<Self::Checked, (Self, ())> { 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
13 changes: 3 additions & 10 deletions substrate/runtime/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,8 @@ pub type HashingFor<B> = <<B as Block>::Header as Header>::Hashing;
pub trait Checkable<Context>: 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<Self::Checked, (Self, Self::Error)>;
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
Expand All @@ -390,18 +387,14 @@ pub trait Checkable<Context>: 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<Self::Checked, (Self, Self::Error)>;
fn check(self) -> Result<Self::Checked, &'static str>;
}

// Every `BlindCheckable` is also a `Checkable` for arbitrary `Context`.
impl<T: BlindCheckable, Context> Checkable<Context> for T {
type Checked = <Self as BlindCheckable>::Checked;
type Error = T::Error;
fn check_with(self, _: Context) -> Result<Self::Checked, (Self, Self::Error)> {
fn check_with(self, _: Context) -> Result<Self::Checked, &'static str> {
BlindCheckable::check(self)
}
}
Expand Down
5 changes: 2 additions & 3 deletions substrate/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ impl Slicable for Extrinsic {

impl BlindCheckable for Extrinsic {
type Checked = Self;
type Error = &'static str;

fn check(self) -> Result<Self, (Self, Self::Error)> {
fn check(self) -> Result<Self, &'static str> {
if ::runtime_primitives::verify_encoded_lazy(&self.signature, &self.transfer, &self.transfer.from) {
Ok(self)
} else {
Err((self, "bad signature"))
Err("bad signature")
}
}
}
Expand Down