Skip to content

Commit

Permalink
Update to latest Substrate master (paritytech#703)
Browse files Browse the repository at this point in the history
* Update to latest Substrate master

* Fix tests
  • Loading branch information
bkchr committed Dec 19, 2019
1 parent f76665b commit 7f1881c
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 223 deletions.
319 changes: 151 additions & 168 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions runtime/src/attestations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use rstd::prelude::*;
use codec::{Encode, Decode};
use frame_support::{decl_storage, decl_module, ensure, dispatch::Result, traits::Get};
use frame_support::{decl_storage, decl_module, ensure, dispatch::DispatchResult, traits::Get};

use primitives::{Hash, parachain::{AttestedCandidate, CandidateReceipt, Id as ParaId}};
use sp_runtime::RuntimeDebug;
Expand Down Expand Up @@ -110,7 +110,7 @@ decl_module! {
/// Parachain-attestations module.
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
/// Provide candidate receipts for parachains, in ascending order by id.
fn more_attestations(origin, _more: MoreAttestations) -> Result {
fn more_attestations(origin, _more: MoreAttestations) -> DispatchResult {
ensure_none(origin)?;
ensure!(!<DidUpdate>::exists(), "More attestations can be added only once in a block.");
<DidUpdate>::put(true);
Expand Down
7 changes: 4 additions & 3 deletions runtime/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ mod tests {
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type ModuleToIndex = ();
}

parameter_types! {
Expand Down Expand Up @@ -407,7 +408,7 @@ mod tests {
new_test_ext().execute_with(|| {
assert_noop!(
Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, None),
"RequireRootOrigin"
sp_runtime::traits::BadOrigin,
);
assert_eq!(Balances::free_balance(&42), 0);
assert_noop!(
Expand All @@ -426,7 +427,7 @@ mod tests {
new_test_ext().execute_with(|| {
assert_noop!(
Claims::mint_claim(Origin::signed(42), eth(&bob()), 200, Some((50, 10, 1))),
"RequireRootOrigin"
sp_runtime::traits::BadOrigin,
);
assert_eq!(Balances::free_balance(&42), 0);
assert_noop!(
Expand All @@ -446,7 +447,7 @@ mod tests {
assert_eq!(Balances::free_balance(&42), 0);
assert_err!(
Claims::claim(Origin::signed(42), 42, sig(&alice(), &42u64.encode())),
"RequireNoOrigin",
sp_runtime::traits::BadOrigin,
);
});
}
Expand Down
9 changes: 6 additions & 3 deletions runtime/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sp_runtime::{
Perbill, Permill, testing::Header,
Perbill, Permill, testing::Header, DispatchResult,
traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup},
};
use crate::registrar::Registrar;
Expand Down Expand Up @@ -542,6 +542,7 @@ mod tests {
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
Expand Down Expand Up @@ -594,12 +595,13 @@ mod tests {
(*p.borrow() - 1).into()
})
}

fn register_para(
id: ParaId,
_info: ParaInfo,
code: Vec<u8>,
initial_head_data: Vec<u8>
) -> Result<(), &'static str> {
) -> DispatchResult {
PARACHAINS.with(|p| {
if p.borrow().contains_key(&id.into()) {
panic!("ID already exists")
Expand All @@ -608,7 +610,8 @@ mod tests {
Ok(())
})
}
fn deregister_para(id: ParaId) -> Result<(), &'static str> {

fn deregister_para(id: ParaId) -> DispatchResult {
PARACHAINS.with(|p| {
if !p.borrow().contains_key(&id.into()) {
panic!("ID doesn't exist")
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2,
spec_version: 1031,
spec_version: 1032,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
Expand Down Expand Up @@ -163,6 +163,7 @@ impl system::Trait for Runtime {
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
type ModuleToIndex = ModuleToIndex;
}

parameter_types! {
Expand Down
55 changes: 28 additions & 27 deletions runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use codec::{Encode, Decode};

use sp_runtime::traits::{
Hash as HashT, BlakeTwo256, Saturating, One, Zero, Dispatchable,
AccountIdConversion,
AccountIdConversion, BadOrigin,
};
use frame_support::weights::SimpleDispatchInfo;
use primitives::{
Expand All @@ -34,7 +34,7 @@ use primitives::{
},
};
use frame_support::{
Parameter, dispatch::Result, decl_storage, decl_module, ensure,
Parameter, dispatch::DispatchResult, decl_storage, decl_module, ensure,
traits::{Currency, Get, WithdrawReason, ExistenceRequirement, Randomness},
};

Expand Down Expand Up @@ -74,7 +74,7 @@ fn number_range<N>(low: N, high: N) -> BlockNumberRange<N> {
// doesn't work.`
pub trait ParachainCurrency<AccountId> {
fn free_balance(para_id: ParaId) -> Balance;
fn deduct(para_id: ParaId, amount: Balance) -> Result;
fn deduct(para_id: ParaId, amount: Balance) -> DispatchResult;
}

impl<AccountId, T: Currency<AccountId>> ParachainCurrency<AccountId> for T where
Expand All @@ -86,7 +86,7 @@ impl<AccountId, T: Currency<AccountId>> ParachainCurrency<AccountId> for T where
T::free_balance(&para_account).into()
}

fn deduct(para_id: ParaId, amount: Balance) -> Result {
fn deduct(para_id: ParaId, amount: Balance) -> DispatchResult {
let para_account = para_id.into_account();

// burn the fee.
Expand Down Expand Up @@ -197,7 +197,7 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
/// Provide candidate receipts for parachains, in ascending order by id.
#[weight = SimpleDispatchInfo::FixedNormal(1_000_000)]
pub fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
pub fn set_heads(origin, heads: Vec<AttestedCandidate>) -> DispatchResult {
ensure_none(origin)?;
ensure!(!<DidUpdate>::exists(), "Parachain heads must be updated only once in the block");

Expand Down Expand Up @@ -350,7 +350,7 @@ impl<T: Trait> Module<T> {
upward_messages: &[UpwardMessage],
max_queue_count: usize,
watermark_queue_size: usize,
) -> Result {
) -> DispatchResult {
// Either there are no more messages to add...
if !upward_messages.is_empty() {
let (count, size) = <RelayDispatchQueueSize>::get(id);
Expand Down Expand Up @@ -616,32 +616,32 @@ impl<T: Trait> Module<T> {
fn check_egress_queue_roots(
head: &AttestedCandidate,
active_parachains: &[(ParaId, Option<(CollatorId, Retriable)>)]
) -> Result {
) -> DispatchResult {
let mut last_egress_id = None;
let mut iter = active_parachains.iter().map(|x| x.0);
for (egress_para_id, root) in &head.candidate.egress_queue_roots {
// egress routes should be ascending order by parachain ID without duplicate.
ensure!(
last_egress_id.as_ref().map_or(true, |x| x < &egress_para_id),
"Egress routes out of order by ID"
"Egress routes out of order by ID",
);

// a parachain can't route to self
ensure!(
*egress_para_id != head.candidate.parachain_index,
"Parachain routing to self"
"Parachain routing to self",
);

// no empty trie roots
ensure!(
*root != EMPTY_TRIE_ROOT.into(),
"Empty trie root included"
"Empty trie root included",
);

// can't route to a parachain which doesn't exist
ensure!(
iter.find(|x| x == egress_para_id).is_some(),
"Routing to non-existent parachain"
"Routing to non-existent parachain",
);

last_egress_id = Some(egress_para_id)
Expand All @@ -654,7 +654,7 @@ impl<T: Trait> Module<T> {
fn check_candidates(
attested_candidates: &[AttestedCandidate],
active_parachains: &[(ParaId, Option<(CollatorId, Retriable)>)]
) -> rstd::result::Result<IncludedBlocks<T>, &'static str>
) -> rstd::result::Result<IncludedBlocks<T>, sp_runtime::DispatchError>
{
use primitives::parachain::ValidityAttestation;
use sp_runtime::traits::AppVerify;
Expand Down Expand Up @@ -739,12 +739,12 @@ impl<T: Trait> Module<T> {

ensure!(
candidate.validity_votes.len() >= majority_of(validator_group.len()),
"Not enough validity attestations"
"Not enough validity attestations",
);

ensure!(
candidate.validity_votes.len() <= authorities.len(),
"The number of attestations exceeds the number of authorities"
"The number of attestations exceeds the number of authorities",
);

let fees = candidate.candidate().fees;
Expand All @@ -762,15 +762,15 @@ impl<T: Trait> Module<T> {
.enumerate()
{
let validity_attestation = match candidate.validity_votes.get(vote_index) {
None => return Err("Not enough validity votes"),
None => Err("Not enough validity votes")?,
Some(v) => {
expected_votes_len = vote_index + 1;
v
}
};

if validator_group.iter().find(|&(idx, _)| *idx == auth_index).is_none() {
return Err("Attesting validator not on this chain's validation duty.");
Err("Attesting validator not on this chain's validation duty.")?
}

let (payload, sig) = match validity_attestation {
Expand All @@ -796,15 +796,15 @@ impl<T: Trait> Module<T> {

ensure!(
sig.verify(&payload[..], &authorities[auth_index]),
"Candidate validity attestation signature is bad."
"Candidate validity attestation signature is bad.",
);
}

para_block_hashes.push(candidate_hash.unwrap_or_else(|| candidate.candidate().hash()));

ensure!(
ensure!(
candidate.validity_votes.len() == expected_votes_len,
"Extra untagged validity votes along with candidate"
"Extra untagged validity votes along with candidate",
);
}

Expand Down Expand Up @@ -887,12 +887,12 @@ impl<T: Trait> ProvideInherent for Module<T> {

/// Ensure that the origin `o` represents a parachain.
/// Returns `Ok` with the parachain ID that effected the extrinsic or an `Err` otherwise.
pub fn ensure_parachain<OuterOrigin>(o: OuterOrigin) -> result::Result<ParaId, &'static str>
pub fn ensure_parachain<OuterOrigin>(o: OuterOrigin) -> result::Result<ParaId, BadOrigin>
where OuterOrigin: Into<result::Result<Origin, OuterOrigin>>
{
match o.into() {
Ok(Origin::Parachain(id)) => Ok(id),
_ => Err("bad origin: expected to be a parachain origin"),
_ => Err(BadOrigin),
}
}

Expand Down Expand Up @@ -961,6 +961,7 @@ mod tests {
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
}

parameter_types! {
Expand Down Expand Up @@ -1516,7 +1517,7 @@ mod tests {
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
"Messages added when queue full",
);
});
}
Expand All @@ -1537,7 +1538,7 @@ mod tests {
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
"Messages added when queue full",
);
});
}
Expand Down Expand Up @@ -1967,7 +1968,7 @@ mod tests {
Origin::NONE,
);

assert_eq!(Err("Routing to non-existent parachain"), result);
assert_eq!(Err("Routing to non-existent parachain".into()), result);
});
}

Expand All @@ -1992,7 +1993,7 @@ mod tests {
Origin::NONE,
);

assert_eq!(Err("Parachain routing to self"), result);
assert_eq!(Err("Parachain routing to self".into()), result);
});
}

Expand All @@ -2017,7 +2018,7 @@ mod tests {
Origin::NONE,
);

assert_eq!(Err("Egress routes out of order by ID"), result);
assert_eq!(Err("Egress routes out of order by ID".into()), result);
});
}

Expand All @@ -2042,7 +2043,7 @@ mod tests {
Origin::NONE,
);

assert_eq!(Err("Empty trie root included"), result);
assert_eq!(Err("Empty trie root included".into()), result);
});
}

Expand Down
Loading

0 comments on commit 7f1881c

Please sign in to comment.