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
99 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
bec7926
Update hex-literal dependency version. (#3141)
kianenigma Jul 18, 2019
9a68a71
Start to rework the new error handling
bkchr Aug 7, 2019
35f9ebc
More work to get it back compiling
bkchr Aug 12, 2019
d542efc
Merge remote-tracking branch 'origin/master' into new_error_handling
bkchr Aug 13, 2019
a3b5693
Start to fix after master merge
bkchr Aug 13, 2019
6784605
The great transaction error handling refactoring
bkchr Aug 15, 2019
7424908
Make `decl_error` errors convertible to `&'static str`
bkchr Aug 15, 2019
cc862ef
Make srml-executive build again
bkchr Aug 16, 2019
3b809f2
Fix `sr-primitives` tests
bkchr Aug 16, 2019
ddd630a
More fixes
bkchr Aug 16, 2019
f611efc
Last round of fix ups
bkchr Aug 18, 2019
c181c6c
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 18, 2019
89a04a5
Fix build
bkchr Aug 18, 2019
46dc7be
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 18, 2019
86ce38b
Fix build
bkchr Aug 18, 2019
41a176a
Apply suggestions from code review
bkchr Aug 26, 2019
a644a6e
Rename some stuff
bkchr Aug 26, 2019
66f3da5
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 26, 2019
80a07b0
Fixes after master merge
bkchr Aug 26, 2019
31cd048
Adds `CheckBlockGasLimit` signed extension
bkchr Aug 26, 2019
513702c
Remove debug stuff
bkchr Aug 27, 2019
c81d17e
Fix srml-balances test
bkchr Aug 27, 2019
9df261b
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 27, 2019
e48d2b5
Rename `InvalidIndex` to `CannotLookup`
bkchr Aug 27, 2019
1f16b00
Remove weird generic parameters
bkchr Aug 27, 2019
ed0761c
Rename function again
bkchr Aug 27, 2019
c0496ec
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 27, 2019
20c6706
Fix import
bkchr Aug 27, 2019
28bbc86
Document the signed extension
bkchr Aug 27, 2019
92cec3c
Change from `Into` to `From`
bkchr Aug 27, 2019
442db38
Update srml/contracts/src/lib.rs
bkchr Aug 28, 2019
e48e66f
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Aug 30, 2019
257684e
Fix compilation
bkchr Aug 30, 2019
1470875
Update srml/contracts/src/lib.rs
bkchr Aug 30, 2019
23d5a93
Update core/sr-primitives/src/transaction_validity.rs
bkchr Aug 30, 2019
39d9d47
Remove unused code
bkchr Aug 30, 2019
7990a97
Fix compilation
bkchr Aug 30, 2019
7ecba8d
Some cleanups
bkchr Aug 30, 2019
448f4da
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 2, 2019
3d7abc0
Fix compile errors
bkchr Sep 2, 2019
f93f9d3
Make `TransactionValidity` a `Result`
bkchr Sep 2, 2019
91b0869
Apply suggestions from code review
bkchr Sep 2, 2019
86ef4eb
Beautify the code a little bit and fix test
bkchr Sep 2, 2019
354e05f
Make `CannotLookup` an inherent error declared by `decl_error!`
bkchr Sep 3, 2019
6743719
Adds some documentation
bkchr Sep 3, 2019
b9fc817
Make `ApplyOutcome` a result
bkchr Sep 3, 2019
d5dc034
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 3, 2019
e1bd019
Up the spec_version
bkchr Sep 3, 2019
e0fa417
Apply suggestions from code review
bkchr Sep 4, 2019
c25ac83
Merge remote-tracking branch 'origin/master' into bkchr-runtime-error…
bkchr Sep 4, 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
Last round of fix ups
  • Loading branch information
bkchr committed Aug 18, 2019
commit f611efcb61d3007ff1d2038c9cfe788633127498
9 changes: 5 additions & 4 deletions core/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ use inherents::InherentData;
use log::{error, info, debug, trace};
use primitives::{H256, Blake2Hasher, ExecutionContext};
use sr_primitives::{
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, DigestFor, BlakeTwo256},
traits::{
Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, DigestFor, BlakeTwo256
},
generic::BlockId,
ApplyError,
};
use transaction_pool::txpool::{self, Pool as TransactionPool};
use substrate_telemetry::{telemetry, CONSENSUS_INFO};
Expand Down Expand Up @@ -170,15 +171,15 @@ impl<Block, B, E, RA, A> Proposer<Block, SubstrateClient<B, E, Block, RA>, A> wh
Ok(()) => {
debug!("[{:?}] Pushed to the block.", pending.hash);
}
Err(error::Error::ApplyExtrinsicFailed(ApplyError::FullBlock)) => {
Err(error::Error::ApplyExtrinsicFailed(e)) if e.exhaust_resources() => {
if is_first {
debug!("[{:?}] Invalid transaction: FullBlock on empty block", pending.hash);
unqueue_invalid.push(pending.hash.clone());
} else if skipped < MAX_SKIPPED_TRANSACTIONS {
skipped += 1;
debug!(
"Block seems full, but will try {} more transactions before quitting.",
MAX_SKIPPED_TRANSACTIONS - skipped
MAX_SKIPPED_TRANSACTIONS - skipped,
);
} else {
debug!("Block is full, proceed with proposing.");
Expand Down
10 changes: 5 additions & 5 deletions core/rpc/src/author/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ impl From<Error> for rpc::Error {
message: format!("Verification Error: {}", e).into(),
data: Some(format!("{:?}", e).into()),
},
Error::Pool(PoolError::InvalidTransaction(code)) => rpc::Error {
Error::Pool(PoolError::InvalidTransaction(e)) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_INVALID_TX),
message: "Invalid Transaction".into(),
data: Some(code.into()),
data: serde_json::to_value(e).ok(),
},
Error::Pool(PoolError::UnknownTransactionValidity(code)) => rpc::Error {
Error::Pool(PoolError::UnknownTransactionValidity(e)) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_UNKNOWN_VALIDITY),
message: "Unknown Transaction Validity".into(),
data: Some(code.into()),
data: serde_json::to_value(e).ok(),
},
Error::Pool(PoolError::TemporarilyBanned) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_TEMPORARILY_BANNED),
Expand All @@ -131,7 +131,7 @@ impl From<Error> for rpc::Error {
},
Error::Pool(PoolError::ImmediatelyDropped) => rpc::Error {
code: rpc::ErrorCode::ServerError(POOL_IMMEDIATELY_DROPPED),
message: "Immediately Dropped" .into(),
message: "Immediately Dropped".into(),
data: Some("The transaction couldn't enter the pool because of the limit".into()),
},
e => errors::internal(e),
Expand Down
23 changes: 9 additions & 14 deletions core/sr-primitives/src/generic/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use codec::{Decode, Encode, Input, Error};
use crate::{
traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic},
generic::CheckedExtrinsic,
transaction_validity::{TransactionValidityError, InvalidTransactionValidity},
transaction_validity::{
TransactionValidityError, InvalidTransactionValidity, UnknownTransactionValidity,
},
};

const TRANSACTION_VERSION: u8 = 3;
Expand Down Expand Up @@ -95,7 +97,6 @@ where
Extra: SignedExtension<AccountId=AccountId>,
AccountId: Member + MaybeDisplay,
Lookup: traits::Lookup<Source=Address, Target=AccountId>,
TransactionValidityError: From<Lookup::Error>,
{
type Checked = CheckedExtrinsic<AccountId, Call, Extra>;

Expand All @@ -104,7 +105,7 @@ where
Some((signed, signature, extra)) => {
let additional_signed = extra.additional_signed()?;
let raw_payload = (self.function, extra, additional_signed);
let signed = lookup.lookup(signed)?;
let signed = lookup.lookup(signed).ok_or(UnknownTransactionValidity::InvalidIndex)?;
if !raw_payload.using_encoded(|payload| {
if payload.len() > 256 {
signature.verify(&blake2_256(payload)[..], &signed)
Expand Down Expand Up @@ -214,16 +215,10 @@ mod tests {
use super::*;
use runtime_io::blake2_256;
use crate::codec::{Encode, Decode};
use crate::traits::{SignedExtension, Lookup};
use crate::traits::{SignedExtension, IdentityLookup};
use serde::{Serialize, Deserialize};

struct TestContext;
impl Lookup for TestContext {
type Source = u64;
type Target = u64;
type Error = TransactionValidityError;
fn lookup(&self, s: u64) -> Result<u64, TransactionValidityError> { Ok(s) }
}
type TestContext = IdentityLookup<u64>;

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Encode, Decode)]
struct TestSig(u64, Vec<u8>);
Expand Down Expand Up @@ -290,7 +285,7 @@ mod tests {
fn unsigned_check_should_work() {
let ux = Ex::new_unsigned(vec![0u8; 0]);
assert!(!ux.is_signed().unwrap_or(false));
assert!(<Ex as Checkable<TestContext>>::check(ux, &TestContext).is_ok());
assert!(<Ex as Checkable<TestContext>>::check(ux, &Default::default()).is_ok());
}

#[test]
Expand All @@ -303,7 +298,7 @@ mod tests {
);
assert!(ux.is_signed().unwrap_or(false));
assert_eq!(
<Ex as Checkable<TestContext>>::check(ux, &TestContext),
<Ex as Checkable<TestContext>>::check(ux, &Default::default()),
Err(InvalidTransactionValidity::BadProof.into()),
);
}
Expand All @@ -318,7 +313,7 @@ mod tests {
);
assert!(ux.is_signed().unwrap_or(false));
assert_eq!(
<Ex as Checkable<TestContext>>::check(ux, &TestContext),
<Ex as Checkable<TestContext>>::check(ux, &Default::default()),
Ok(CEx { signed: Some((TEST_ACCOUNT, TestExtra)), function: vec![0u8; 0] }),
);
}
Expand Down
14 changes: 10 additions & 4 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,19 +621,25 @@ pub enum ApplyError {
/// General error to do with the state of the system in general.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this? "Bad state" sounds a bit ambigious...

For example:

  1. is a corrupted storage value counts as example of BadState?
  2. What if an extrinsic tries to transfer balance from an account that doesn't have enough funds (although it has funds to cover fees), should it also be BadState?

Copy link
Member

@gavofyork gavofyork Aug 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. no - that would be CorruptedState.

  2. yeah that's the sort of thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gavofyork Should CorruptedState be added?

BadState,

/// General error to do with the exhaustion of block resources.
Exhausted,

/// Any error to do with the transaction validity.
Validity(transaction_validity::TransactionValidityError),
}

impl ApplyError {
/// Returns if the reason for the error was block resource exhaustion.
pub fn exhaust_resources(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn exhaust_resources(&self) -> bool {
pub fn exhausted_resources(&self) -> bool {

?

match self {
Self::Validity(e) => e.exhaust_resources(),
_ => false,
}
}
}

impl Into<&'static str> for ApplyError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impl Into<&'static str> for ApplyError {
impl From<ApplyError> for &'static str {

?

fn into(self) -> &'static str {
match self {
ApplyError::NoPermission => "Transaction does not have required permissions",
ApplyError::BadState => "System in bad state",
ApplyError::Exhausted => "Transaction exhausted block limits",
ApplyError::Validity(v) => v.into(),
}
}
Expand Down
41 changes: 15 additions & 26 deletions core/sr-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,44 +93,36 @@ impl<
}
}

/// EnsureOrigin Error type
pub trait EnsureOriginError {
/// Indicates invalid origin
fn invalid_origin() -> Self;
/// An error type that indicates that the origin is invalid.
#[derive(Encode, Decode)]
pub struct InvalidOrigin;

impl From<InvalidOrigin> for &'static str {
fn from(_: InvalidOrigin) -> &'static str {
"Invalid origin"
}
}

/// Some sort of check on the origin is performed by this object.
pub trait EnsureOrigin<OuterOrigin> {
/// A return type.
type Success;
/// Error type
type Error: EnsureOriginError;
/// Perform the origin check.
fn ensure_origin(o: OuterOrigin) -> result::Result<Self::Success, Self::Error> {
Self::try_origin(o).map_err(|_| Self::Error::invalid_origin())
fn ensure_origin(o: OuterOrigin) -> result::Result<Self::Success, InvalidOrigin> {
Self::try_origin(o).map_err(|_| InvalidOrigin)
}
/// Perform the origin check.
fn try_origin(o: OuterOrigin) -> result::Result<Self::Success, OuterOrigin>;
}

impl EnsureOriginError for () {
fn invalid_origin() -> () {}
}

impl EnsureOriginError for &'static str {
fn invalid_origin() -> &'static str { "Invalid origin" }
}

/// Means of changing one type into another in a manner dependent on the source type.
pub trait Lookup {
/// Type to lookup from.
type Source;
/// Type to lookup into.
type Target;
/// Error type
type Error;
/// Attempt a lookup.
fn lookup(&self, s: Self::Source) -> result::Result<Self::Target, Self::Error>;
fn lookup(&self, s: Self::Source) -> Option<Self::Target>;
}

/// Means of changing one type into another in a manner dependent on the source type.
Expand All @@ -141,10 +133,8 @@ pub trait StaticLookup {
type Source: Codec + Clone + PartialEq + MaybeDebug;
/// Type to lookup into.
type Target;
/// Error type.
type Error;
/// Attempt a lookup.
fn lookup(s: Self::Source) -> result::Result<Self::Target, Self::Error>;
fn lookup(s: Self::Source) -> Option<Self::Target>;
/// Convert from Target back to Source.
fn unlookup(t: Self::Target) -> Self::Source;
}
Expand All @@ -155,15 +145,14 @@ pub struct IdentityLookup<T>(PhantomData<T>);
impl<T: Codec + Clone + PartialEq + MaybeDebug> StaticLookup for IdentityLookup<T> {
type Source = T;
type Target = T;
type Error = &'static str;
fn lookup(x: T) -> result::Result<T, Self::Error> { Ok(x) }
fn lookup(x: T) -> Option<T> { Some(x) }
fn unlookup(x: T) -> T { x }
}

impl<T> Lookup for IdentityLookup<T> {
type Source = T;
type Target = T;
type Error = &'static str;
fn lookup(&self, x: T) -> result::Result<T, Self::Error> { Ok(x) }
fn lookup(&self, x: T) -> Option<T> { Some(x) }
}

/// Extensible conversion trait. Generic over both source and destination types.
Expand Down
39 changes: 31 additions & 8 deletions core/sr-primitives/src/transaction_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub type TransactionTag = Vec<u8>;
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy)]
#[cfg_attr(feature = "std", derive(Debug, serde::Serialize))]
pub enum InvalidTransactionValidity {
/// The call of the transaction is not expected.
Call,
/// General error to do with the inability to pay some fees (e.g. account balance too low).
Payment,
/// General error to do with the transaction not yet being valid (e.g. nonce too high).
Expand All @@ -49,9 +51,20 @@ pub enum InvalidTransactionValidity {
Custom(u8),
}

impl InvalidTransactionValidity {
/// Returns if the reason for the invalidity was block resource exhaustion.
pub fn exhaust_resources(&self) -> bool {
match self {
Self::ExhaustResources => true,
_ => false,
}
}
}

impl Into<&'static str> for InvalidTransactionValidity {
fn into(self) -> &'static str {
match self {
InvalidTransactionValidity::Call => "Transaction call is not expected",
InvalidTransactionValidity::Future => "Transaction will be valid in the future",
InvalidTransactionValidity::Stale => "Transaction is outdated",
InvalidTransactionValidity::BadProof => "Transaction has a bad signature",
Expand Down Expand Up @@ -99,6 +112,16 @@ pub enum TransactionValidityError {
Unknown(UnknownTransactionValidity),
}

impl TransactionValidityError {
/// Returns if the reason for the error was block resource exhaustion.
pub fn exhaust_resources(&self) -> bool {
match self {
Self::Invalid(e) => e.exhaust_resources(),
Self::Unknown(_) => false,
}
}
}

impl Into<&'static str> for TransactionValidityError {
fn into(self) -> &'static str {
match self {
Expand All @@ -108,27 +131,27 @@ impl Into<&'static str> for TransactionValidityError {
}
}

impl Into<TransactionValidityError> for InvalidTransactionValidity {
fn into(self) -> TransactionValidityError {
TransactionValidityError::Invalid(self)
impl From<InvalidTransactionValidity> for TransactionValidityError {
fn from(err: InvalidTransactionValidity) -> Self {
TransactionValidityError::Invalid(err)
}
}

impl Into<TransactionValidityError> for UnknownTransactionValidity {
fn into(self) -> TransactionValidityError {
TransactionValidityError::Unknown(self)
impl From<UnknownTransactionValidity> for TransactionValidityError {
fn from(err: UnknownTransactionValidity) -> Self {
TransactionValidityError::Unknown(err)
}
}

impl Into<crate::ApplyError> for InvalidTransactionValidity {
fn into(self) -> crate::ApplyError {
TransactionValidityError::from(self.into()).into()
TransactionValidityError::from(self).into()
}
}

impl Into<crate::ApplyError> for UnknownTransactionValidity {
fn into(self) -> crate::ApplyError {
TransactionValidityError::from(self.into()).into()
TransactionValidityError::from(self).into()
}
}

Expand Down
Loading