Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ba48a0a
srml-system checks
xlc Jun 17, 2019
52c6b90
wip
xlc Jun 18, 2019
bd7228f
more modules compiles
xlc Jun 18, 2019
c0cece1
node-runtime checks
xlc Jun 18, 2019
a93fedd
build.sh passes
xlc Jun 19, 2019
3039e7c
include dispatch error in failed event
xlc Jun 19, 2019
c5c2e5a
revert some unnecessary changes
xlc Jun 19, 2019
1198fb7
refactor based on comments
xlc Jun 19, 2019
ed20244
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 19, 2019
1f964d1
more compile error fixes
xlc Jun 20, 2019
83975c0
avoid unnecessary into
xlc Jun 20, 2019
e03db0c
reorder code
xlc Jun 20, 2019
7e01497
fixes some tests
xlc Jun 21, 2019
a6c989b
manually implement encode & decode to avoid i8 workaround
xlc Jun 21, 2019
9d2dbbb
more test fixes
xlc Jun 21, 2019
31c9c84
more fixes
xlc Jun 21, 2019
6cad33a
more error fixes
xlc Jun 22, 2019
ba42e6a
Apply suggestions from code review
xlc Jun 22, 2019
0f01cc4
address comments
xlc Jun 22, 2019
cce7c08
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 22, 2019
c7ae1b1
test for DispatchError encoding
xlc Jun 22, 2019
0e424c1
tyep alias for democracy
xlc Jun 22, 2019
a145f27
make error printable
xlc Jun 22, 2019
ef4eecd
line width
xlc Jun 22, 2019
33668d8
fix balances tests
xlc Jun 22, 2019
d128a1a
fix executive test
xlc Jun 22, 2019
a4a8cdc
fix system tests
xlc Jun 22, 2019
f4387fb
bump version
xlc Jun 22, 2019
ef2eaa6
ensure consistent method signature
xlc Jun 22, 2019
31c998f
Apply suggestions from code review
xlc Jun 26, 2019
d6b94b0
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 26, 2019
51ec628
changes based on review
xlc Jun 26, 2019
88887ee
Add issue number for TODOs
xlc Jun 26, 2019
550c1e0
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 26, 2019
e8324c2
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jun 29, 2019
c147a8e
fix
xlc Jun 29, 2019
633a482
line width
xlc Jun 29, 2019
b61e137
fix test
xlc Jun 29, 2019
1ca74ed
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 8, 2019
3d2c850
Update core/sr-primitives/src/lib.rs
xlc Jul 10, 2019
8330acf
Update core/sr-primitives/src/traits.rs
xlc Jul 10, 2019
d41955a
Update srml/council/src/motions.rs
xlc Jul 10, 2019
66187b3
Update srml/council/src/motions.rs
xlc Jul 10, 2019
7489d3a
update based on review
xlc Jul 10, 2019
57f7958
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 10, 2019
6e5c3ce
More concrete macro matching
xlc Jul 10, 2019
2d9794a
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 11, 2019
1f5faac
Merge remote-tracking branch 'upstream/master' into improve-error-res…
xlc Jul 18, 2019
efe953a
fix test build issue
xlc Jul 18, 2019
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
Next Next commit
node-runtime checks
  • Loading branch information
xlc committed Jun 19, 2019
commit c0cece1c76f0230dd5695834d4ba4e330a765b40
4 changes: 2 additions & 2 deletions core/sr-primitives/src/generic/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
Call: Encode + Member,
Signature: Member + traits::Verify<Signer=AccountId> + Codec,
AccountId: Member + MaybeDisplay,
Context: Lookup<Source=Address, Target=AccountId, Error=Error>,
Context: Lookup<Source=Address, Target=AccountId, Error=&'static str>
{
type Checked = CheckedExtrinsic<AccountId, Index, Call>;
type Error = Error;
Expand All @@ -93,7 +93,7 @@ where
Ok(match self.signature {
Some(SignatureContent{signed, signature, index}) => {
let payload = (index, self.function);
let signed = context.lookup(signed)?;
let signed = context.lookup(signed).map_err(Into::into)?;
if !crate::verify_encoded_lazy(&signature, &payload, &signed) {
return Err(Error::BadSignature)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
AccountId: Member + MaybeDisplay,
BlockNumber: SimpleArithmetic,
Hash: Encode,
Context: Lookup<Source=Address, Target=AccountId, Error=Error>
Context: Lookup<Source=Address, Target=AccountId, Error=&'static str>
+ CurrentHeight<BlockNumber=BlockNumber>
+ BlockNumberToHash<BlockNumber=BlockNumber, Hash=Hash>,
{
Expand All @@ -89,7 +89,7 @@ where
let current_u64 = context.current_height().saturated_into::<u64>();
let h = context.block_number_to_hash(era.birth(current_u64).saturated_into())
.ok_or(Error::Unknown("transaction birth block ancient"))?;
let signed = context.lookup(signed)?;
let signed = context.lookup(signed).map_err(Into::into)?;
let raw_payload = (index, self.function, era, h);
if !raw_payload.using_encoded(|payload| {
if payload.len() > 256 {
Expand Down
4 changes: 2 additions & 2 deletions core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
AccountId: Member + MaybeDisplay,
BlockNumber: SimpleArithmetic,
Hash: Encode,
Context: Lookup<Source=Address, Target=AccountId, Error=Error>
Context: Lookup<Source=Address, Target=AccountId, Error=&'static str>
+ CurrentHeight<BlockNumber=BlockNumber>
+ BlockNumberToHash<BlockNumber=BlockNumber, Hash=Hash>,
{
Expand All @@ -90,7 +90,7 @@ where
let current_u64 = context.current_height().saturated_into::<u64>();
let h = context.block_number_to_hash(era.birth(current_u64).saturated_into())
.ok_or(Error::Unknown("transaction birth block ancient"))?;
let signed = context.lookup(signed)?;
let signed = context.lookup(signed).map_err(Into::into)?;
let raw_payload = (index, self.function, era, h);

if !raw_payload.using_encoded(|payload| {
Expand Down
6 changes: 6 additions & 0 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ impl From<Error> for &str {
}
}

impl Into<Error> for &'static str {
fn into(self) -> Error {
Error::Unknown(self)
}
}

/// Justification type.
pub type Justification = Vec<u8>;

Expand Down
1 change: 1 addition & 0 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl system::Trait for Runtime {
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type Error = Error;
}

impl aura::Trait for Runtime {
Expand Down
18 changes: 9 additions & 9 deletions srml/council/src/motions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use rstd::{prelude::*, result};
use substrate_primitives::u32_trait::Value as U32;
use primitives::traits::{Hash, EnsureOrigin, EnsureOriginError};
use primitives::traits::{Hash, EnsureOrigin};
use srml_support::{
dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode},
StorageValue, StorageMap, decl_module, decl_event, decl_storage, ensure
Expand Down Expand Up @@ -259,11 +259,11 @@ pub fn ensure_council_members<OuterOrigin, AccountId>(o: OuterOrigin, n: MemberC

pub struct EnsureMember<AccountId>(::rstd::marker::PhantomData<AccountId>);
impl<
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>> + EnsureOriginError,
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
AccountId
> EnsureOrigin<O> for EnsureMember<AccountId> {
type Success = AccountId;
type Error = O;
type Error = &'static str;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Member(id) => Ok(id),
Expand All @@ -274,12 +274,12 @@ impl<

pub struct EnsureMembers<N: U32, AccountId>(::rstd::marker::PhantomData<(N, AccountId)>);
impl<
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>> + EnsureOriginError,
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
N: U32,
AccountId,
> EnsureOrigin<O> for EnsureMembers<N, AccountId> {
type Success = (MemberCount, MemberCount);
type Error = O;
type Error = &'static str;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n >= N::VALUE => Ok((n, m)),
Expand All @@ -292,13 +292,13 @@ pub struct EnsureProportionMoreThan<N: U32, D: U32, AccountId>(
::rstd::marker::PhantomData<(N, D, AccountId)>
);
impl<
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>> + EnsureOriginError,
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
N: U32,
D: U32,
AccountId,
> EnsureOrigin<O> for EnsureProportionMoreThan<N, D, AccountId> {
type Success = ();
type Error = O;
type Error = &'static str;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n * D::VALUE > N::VALUE * m => Ok(()),
Expand All @@ -311,13 +311,13 @@ pub struct EnsureProportionAtLeast<N: U32, D: U32, AccountId>(
::rstd::marker::PhantomData<(N, D, AccountId)>
);
impl<
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>> + EnsureOriginError,
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
N: U32,
D: U32,
AccountId,
> EnsureOrigin<O> for EnsureProportionAtLeast<N, D, AccountId> {
type Success = ();
type Error = O;
type Error = &'static str;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n * D::VALUE >= N::VALUE * m => Ok(()),
Expand Down
14 changes: 8 additions & 6 deletions srml/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use rstd::prelude::*;
use rstd::marker::PhantomData;
use rstd::convert::TryInto;
use primitives::{
generic::Digest, ApplyResult, ApplyError, DispatchError,
generic::Digest, ApplyResult, ApplyError, DispatchError, Error as PrimitiveError,
traits::{
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize,
OnInitialize, NumberFor, Block as BlockT, OffchainWorker,
Expand Down Expand Up @@ -116,10 +116,11 @@ impl<
Payment: MakePayment<System::AccountId>,
UnsignedValidator,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
CheckableError: Into<PrimitiveError>,
Error: Into<DispatchError> + TryInto<system::Error>,
> ExecuteBlock<Block> for Executive<System, Block, Context, Payment, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context, Error=Error> + Codec,
Block::Extrinsic: Checkable<Context, Error=CheckableError> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable<Index=System::Index, AccountId=System::AccountId> + Weighable,
CallOf<Block::Extrinsic, Context>: Dispatchable<Error=Error>,
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
Expand All @@ -137,10 +138,11 @@ impl<
Payment: MakePayment<System::AccountId>,
UnsignedValidator,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
CheckableError: Into<PrimitiveError>,
Error: Into<DispatchError> + TryInto<system::Error>,
> Executive<System, Block, Context, Payment, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context, Error=Error> + Codec,
Block::Extrinsic: Checkable<Context, Error=CheckableError> + Codec,
CheckedOf<Block::Extrinsic, Context>: Applyable<Index=System::Index, AccountId=System::AccountId> + Weighable,
CallOf<Block::Extrinsic, Context>: Dispatchable<Error=Error>,
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
Expand Down Expand Up @@ -343,14 +345,14 @@ where
// Checks out. Carry on.
Ok(xt) => xt,
Err(err) => {
match err.try_into() {
match err.into() {
// An unknown account index implies that the transaction may yet become valid.
// TODO: avoid hardcoded error string here
Ok(system::Error::Unknown("invalid account index")) =>
PrimitiveError::Unknown("invalid account index") =>
return TransactionValidity::Unknown(INVALID_INDEX),
// Technically a bad signature could also imply an out-of-date account index, but
// that's more of an edge case.
Ok(system::Error::BadSignature) =>
PrimitiveError::BadSignature =>
return TransactionValidity::Invalid(ApplyError::BadSignature as i8),
_ => return TransactionValidity::Invalid(UNKNOWN_ERROR),
}
Expand Down
2 changes: 1 addition & 1 deletion srml/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ macro_rules! impl_outer_dispatch {
type Error = $error_type;
fn dispatch(self, origin: $origin) -> $crate::dispatch::DispatchResult<Self::Error> {
match self {
$( $call_type::$camelcase(call) => call.dispatch(origin), )*
$( $call_type::$camelcase(call) => call.dispatch(origin).map_err(Into::into), )*
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions srml/support/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ macro_rules! impl_outer_error {
}
}

impl From<&'static str> for $name {
fn from(err: &'static str) -> Self {
$name::system($system::Error::Unknown(err))
}
}

impl $crate::rstd::convert::TryInto<$system::Error> for $name {
type Error = Self;
fn try_into(self) -> $crate::dispatch::result::Result<$system::Error, Self::Error> {
Expand All @@ -95,11 +101,11 @@ macro_rules! impl_outer_error {
$crate::runtime_primitives::DispatchError {
module: 0,
error: 0,
message: msg,
message: Some(msg),
},
_ => $crate::runtime_primitives::DispatchError {
module: 0,
error: err.into(),
error: Into::<u8>::into(err) as i8,
message: None,
},
},
Expand All @@ -109,11 +115,11 @@ macro_rules! impl_outer_error {
$crate::runtime_primitives::DispatchError {
module: $crate::codec::Encode.using_encoded(&self, |s| s[0]),
error: 0,
message: msg,
message: Some(msg),
},
_ => $crate::runtime_primitives::DispatchError {
module: $crate::codec::Encode.using_encoded(&self, |s| s[0]),
error: err.into(),
error: Into::<u8>::into(err) as i8,
message: None,
},
},
Expand Down
2 changes: 1 addition & 1 deletion srml/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub trait Trait: 'static + Eq + Clone {
type Event: Parameter + Member + From<Event>;

/// The aggregated error type of the runtime.
type Error: Parameter + Member + From<Error>;
type Error: Member + From<Error>;
}

pub type DigestOf<T> = generic::Digest<<T as Trait>::Hash>;
Expand Down