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
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
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.exhausted_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
3 changes: 1 addition & 2 deletions core/client/src/block_builder/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use super::api::BlockBuilder as BlockBuilderApi;
use std::vec::Vec;
use codec::Encode;
use sr_primitives::ApplyOutcome;
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{
Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef, DigestFor,
Expand Down Expand Up @@ -104,7 +103,7 @@ where
ExecutionContext::BlockConstruction,
xt.clone()
)? {
Ok(ApplyOutcome::Success) | Ok(ApplyOutcome::Fail) => {
Ok(_) => {
extrinsics.push(xt);
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions core/rpc/api/src/author/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,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::UnknownTransaction(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 @@ -133,7 +133,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()),
},
Error::UnsupportedKeyType => rpc::Error {
Expand Down
8 changes: 7 additions & 1 deletion core/sr-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ pub mod offchain;
/// Trait for things which can be printed.
pub trait Printable {
/// Print the object.
fn print(self);
fn print(&self);
}

impl Printable for u8 {
fn print(&self) {
u64::from(*self).print()
}
}

/// Converts a public trait definition into a private trait and set of public functions
Expand Down
8 changes: 4 additions & 4 deletions core/sr-io/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,19 @@ pub fn with_storage<R, F: FnOnce() -> R>(
}

impl<'a> Printable for &'a [u8] {
fn print(self) {
println!("Runtime: {}", HexDisplay::from(&self));
fn print(&self) {
println!("Runtime: {}", HexDisplay::from(self));
}
}

impl<'a> Printable for &'a str {
fn print(self) {
fn print(&self) {
println!("Runtime: {}", self);
}
}

impl Printable for u64 {
fn print(self) {
fn print(&self) {
println!("Runtime: {}", self);
}
}
Expand Down
9 changes: 5 additions & 4 deletions core/sr-io/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,23 +1220,24 @@ unsafe fn from_raw_parts(ptr: *mut u8, len: u32) -> Option<Vec<u8>> {
impl Api for () {}

impl<'a> Printable for &'a [u8] {
fn print(self) {
fn print(&self) {
unsafe {
ext_print_hex.get()(self.as_ptr(), self.len() as u32);
}
}
}

impl<'a> Printable for &'a str {
fn print(self) {
fn print(&self) {
unsafe {
ext_print_utf8.get()(self.as_ptr() as *const u8, self.len() as u32);
}
}
}

impl Printable for u64 {
fn print(self) {
unsafe { ext_print_num.get()(self); }
fn print(&self) {
unsafe { ext_print_num.get()(*self); }
}
}

26 changes: 10 additions & 16 deletions core/sr-primitives/src/generic/checked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
//! Generic implementation of an extrinsic that has passed the verification
//! stage.

use rstd::result::Result;
use crate::traits::{
self, Member, MaybeDisplay, SignedExtension, DispatchError, Dispatchable, DispatchResult,
ValidateUnsigned
self, Member, MaybeDisplay, SignedExtension, Dispatchable, ValidateUnsigned,
};
use crate::weights::{GetDispatchInfo, DispatchInfo};
use crate::transaction_validity::TransactionValidity;
Expand Down Expand Up @@ -55,28 +53,24 @@ where
self.signed.as_ref().map(|x| &x.0)
}

fn validate<U: ValidateUnsigned<Call=Self::Call>>(&self,
fn validate<U: ValidateUnsigned<Call = Self::Call>>(
&self,
info: DispatchInfo,
len: usize,
) -> TransactionValidity {
if let Some((ref id, ref extra)) = self.signed {
Extra::validate(extra, id, &self.function, info, len).into()
Extra::validate(extra, id, &self.function, info, len)
} else {
match Extra::validate_unsigned(&self.function, info, len) {
Ok(extra) => match U::validate_unsigned(&self.function) {
TransactionValidity::Valid(v) =>
TransactionValidity::Valid(v.combine_with(extra)),
x => x,
},
x => x.into(),
}
let valid = Extra::validate_unsigned(&self.function, info, len)?;
Ok(valid.combine_with(U::validate_unsigned(&self.function)?))
}
}

fn dispatch(self,
fn apply(
self,
info: DispatchInfo,
len: usize,
) -> Result<DispatchResult, DispatchError> {
) -> crate::ApplyResult {
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {
let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
(Some(id), pre)
Expand All @@ -86,7 +80,7 @@ where
};
let res = self.function.dispatch(Origin::from(maybe_who));
Extra::post_dispatch(pre, info, len);
Ok(res)
Ok(res.map_err(Into::into))
}
}

Expand Down
55 changes: 30 additions & 25 deletions core/sr-primitives/src/generic/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ use std::fmt;

use rstd::prelude::*;
use runtime_io::blake2_256;
use crate::codec::{Decode, Encode, Input, Error};
use crate::traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic};
use super::CheckedExtrinsic;
use codec::{Decode, Encode, Input, Error};
use crate::{
traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic},
generic::CheckedExtrinsic, transaction_validity::{TransactionValidityError, InvalidTransaction},
};

const TRANSACTION_VERSION: u8 = 3;

Expand Down Expand Up @@ -101,19 +103,19 @@ where
Signature: Member + traits::Verify<Signer=AccountId>,
Extra: SignedExtension<AccountId=AccountId>,
AccountId: Member + MaybeDisplay,
Lookup: traits::Lookup<Source=Address, Target=AccountId>
Lookup: traits::Lookup<Source=Address, Target=AccountId>,
{
type Checked = CheckedExtrinsic<AccountId, Call, Extra>;

fn check(self, lookup: &Lookup) -> Result<Self::Checked, &'static str> {
fn check(self, lookup: &Lookup) -> Result<Self::Checked, TransactionValidityError> {
Ok(match self.signature {
Some((signed, signature, extra)) => {
let signed = lookup.lookup(signed)?;
let raw_payload = SignedPayload::new(self.function, extra)?;
if !raw_payload.using_encoded(|payload| {
signature.verify(payload, &signed)
}) {
return Err(crate::BAD_SIGNATURE)
return Err(InvalidTransaction::BadProof.into())
}

let (function, extra, _) = raw_payload.deconstruct();
Expand All @@ -136,9 +138,9 @@ where
/// is going to be different than the `SignaturePayload` - so the thing the extrinsic
/// actually contains.
pub struct SignedPayload<Call, Extra: SignedExtension>((
Call,
Extra,
Extra::AdditionalSigned,
Call,
Extra,
Extra::AdditionalSigned,
));

impl<Call, Extra> SignedPayload<Call, Extra> where
Expand All @@ -148,7 +150,7 @@ impl<Call, Extra> SignedPayload<Call, Extra> where
/// Create new `SignedPayload`.
///
/// This function may fail if `additional_signed` of `Extra` is not available.
pub fn new(call: Call, extra: Extra) -> Result<Self, &'static str> {
pub fn new(call: Call, extra: Extra) -> Result<Self, TransactionValidityError> {
let additional_signed = extra.additional_signed()?;
let raw_payload = (call, extra, additional_signed);
Ok(Self(raw_payload))
Expand Down Expand Up @@ -256,7 +258,12 @@ where
Extra: SignedExtension,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "UncheckedExtrinsic({:?}, {:?})", self.signature.as_ref().map(|x| (&x.0, &x.2)), self.function)
write!(
f,
"UncheckedExtrinsic({:?}, {:?})",
self.signature.as_ref().map(|x| (&x.0, &x.2)),
self.function,
)
}
}

Expand All @@ -265,15 +272,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;
fn lookup(&self, s: u64) -> Result<u64, &'static str> { Ok(s) }
}
type TestContext = IdentityLookup<u64>;

#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, Encode, Decode)]
struct TestSig(u64, Vec<u8>);
Expand All @@ -298,7 +300,7 @@ mod tests {
type AdditionalSigned = ();
type Pre = ();

fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
}

type Ex = UncheckedExtrinsic<TestAccountId, TestCall, TestSig, TestExtra>;
Expand Down Expand Up @@ -340,7 +342,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 @@ -349,10 +351,13 @@ mod tests {
vec![0u8; 0],
TEST_ACCOUNT,
TestSig(TEST_ACCOUNT, vec![0u8; 0]),
TestExtra
TestExtra,
);
assert!(ux.is_signed().unwrap_or(false));
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err(crate::BAD_SIGNATURE));
assert_eq!(
<Ex as Checkable<TestContext>>::check(ux, &Default::default()),
Err(InvalidTransaction::BadProof.into()),
);
}

#[test]
Expand All @@ -361,12 +366,12 @@ mod tests {
vec![0u8; 0],
TEST_ACCOUNT,
TestSig(TEST_ACCOUNT, (vec![0u8; 0], TestExtra).encode()),
TestExtra
TestExtra,
);
assert!(ux.is_signed().unwrap_or(false));
assert_eq!(
<Ex as Checkable<TestContext>>::check(ux, &TestContext),
Ok(CEx { signed: Some((TEST_ACCOUNT, TestExtra)), function: vec![0u8; 0] })
<Ex as Checkable<TestContext>>::check(ux, &Default::default()),
Ok(CEx { signed: Some((TEST_ACCOUNT, TestExtra)), function: vec![0u8; 0] }),
);
}

Expand Down
Loading