Unverified Commit d19d5b13 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Update to Substrate master (#311)

* Best effort to bring up to date.

* Fix the executor stuff

* Update verisons.

* Finish fixing

* Final fixes and warnings.

* add some docs and bump Wasm versions

* Fix tests

* Fix final test
parent 6b5c3925
Pipeline #42265 passed with stages
in 27 minutes and 26 seconds
This diff is collapsed.
......@@ -9,7 +9,7 @@ edition = "2018"
polkadot-primitives = { path = "../primitives" }
parking_lot = "0.7.1"
log = "0.4.6"
parity-codec = "3.0"
parity-codec = "4.1"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
......
......@@ -26,6 +26,7 @@ use chain_spec::ChainSpec;
use futures::Future;
use tokio::runtime::Runtime;
use service::Service as BareService;
use std::sync::Arc;
use log::info;
pub use service::{
......@@ -35,7 +36,9 @@ pub use service::{
pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::error;
pub use tokio::runtime::TaskExecutor;
/// Abstraction over an executor that lets you spawn tasks in the background.
pub type TaskExecutor = Arc<dyn futures::future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>;
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
......@@ -86,17 +89,16 @@ pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Res
info!("Roles: {:?}", config.roles);
config.custom = worker.configuration();
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
let executor = runtime.executor();
match config.roles {
service::Roles::LIGHT =>
run_until_exit(
runtime,
Factory::new_light(config, executor).map_err(|e| format!("{:?}", e))?,
Factory::new_light(config).map_err(|e| format!("{:?}", e))?,
worker
),
_ => run_until_exit(
runtime,
Factory::new_full(config, executor).map_err(|e| format!("{:?}", e))?,
Factory::new_full(config).map_err(|e| format!("{:?}", e))?,
worker
),
}.map_err(|e| format!("{:?}", e))
......@@ -121,7 +123,7 @@ fn run_until_exit<T, C, W>(
let informant = cli::informant::build(&service);
executor.spawn(exit.until(informant).map(|_| ()));
let _ = runtime.block_on(worker.work(&*service, executor.clone()));
let _ = runtime.block_on(worker.work(&*service, Arc::new(executor)));
exit_send.fire();
// we eagerly drop the service so that the internal exit future is fired,
......
......@@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
futures = "0.1.17"
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
parity-codec = "3.0"
parity-codec = "4.1"
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......
......@@ -7,6 +7,6 @@ edition = "2018"
[dependencies]
primitives = { package = "polkadot-primitives", path = "../primitives" }
reed_solomon = { package = "reed-solomon-erasure", git = "https://github.com/paritytech/reed-solomon-erasure" }
parity-codec = "3.0"
parity-codec = "4.1"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie = { package = "substrate-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......@@ -11,7 +11,7 @@ parking_lot = "0.7.1"
av_store = { package = "polkadot-availability-store", path = "../availability-store" }
polkadot-validation = { path = "../validation" }
polkadot-primitives = { path = "../primitives" }
parity-codec = { version = "3.5.1", features = ["derive"] }
parity-codec = { version = "4.1", features = ["derive"] }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......
......@@ -32,10 +32,11 @@ use polkadot_primitives::parachain::{
Id as ParaId, BlockData, CollatorId, CandidateReceipt, Collation, PoVBlock,
StructuredUnroutedIngress,
};
use substrate_network::{PeerId, RequestId, Context};
use substrate_network::{message, generic_message};
use substrate_network::specialization::NetworkSpecialization as Specialization;
use substrate_network::StatusMessage as GenericFullStatus;
use substrate_network::{
PeerId, RequestId, Context, Event, message, generic_message,
specialization::NetworkSpecialization as Specialization,
StatusMessage as GenericFullStatus
};
use self::validation::{LiveValidationSessions, RecentValidatorIds, InsertedRecentKey};
use self::collator_pool::{CollatorPool, Role, Action};
use self::local_collations::LocalCollations;
......@@ -69,7 +70,7 @@ mod benefit {
type FullStatus = GenericFullStatus<Block>;
/// Specialization of the network service for the polkadot protocol.
pub type NetworkService = substrate_network::NetworkService<Block, PolkadotProtocol>;
pub type NetworkService = substrate_network::NetworkService<Block, PolkadotProtocol, Hash>;
/// Status of a Polkadot node.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
......@@ -593,6 +594,8 @@ impl Specialization<Block> for PolkadotProtocol {
}
}
fn on_event(&mut self, _event: Event) { }
fn on_abort(&mut self) { }
fn maintain_peers(&mut self, ctx: &mut dyn Context<Block>) {
......
......@@ -41,11 +41,13 @@ use sr_primitives::traits::{ApiRef, ProvideRuntimeApi};
use std::collections::HashMap;
use std::sync::Arc;
use futures::{prelude::*, sync::mpsc};
use tokio::runtime::{Runtime, TaskExecutor};
use tokio::runtime::Runtime;
use parity_codec::Encode;
use super::TestContext;
type TaskExecutor = Arc<dyn futures::future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>;
#[derive(Clone, Copy)]
struct NeverExit;
......
......@@ -44,7 +44,6 @@ use std::io;
use std::sync::Arc;
use arrayvec::ArrayVec;
use tokio::runtime::TaskExecutor;
use parking_lot::Mutex;
use log::{debug, warn};
......@@ -63,6 +62,7 @@ pub trait Executor {
}
/// A wrapped futures::future::Executor.
#[derive(Clone)]
pub struct WrappedExecutor<T>(pub T);
impl<T> Executor for WrappedExecutor<T>
......@@ -75,9 +75,11 @@ impl<T> Executor for WrappedExecutor<T>
}
}
impl Executor for TaskExecutor {
impl Executor for Arc<
dyn futures::future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync
> {
fn spawn<F: Future<Item=(),Error=()> + Send + 'static>(&self, f: F) {
TaskExecutor::spawn(self, f)
let _ = FutureExecutor::execute(&**self, Box::new(f));
}
}
......
......@@ -6,7 +6,7 @@ description = "Types and utilities for creating and working with parachains"
edition = "2018"
[dependencies]
codec = { package = "parity-codec", version = "3.5", default-features = false, features = [ "derive" ] }
codec = { package = "parity-codec", version = "4.1", default-features = false, features = [ "derive" ] }
wasmi = { version = "0.4.3", optional = true }
derive_more = { version = "0.14", optional = true }
serde = { version = "1.0", default-features = false, features = [ "derive" ] }
......
......@@ -6,8 +6,7 @@ edition = "2018"
[dependencies]
serde = { version = "1.0", optional = true, features = ["derive"] }
parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
parity-codec = { version = "4.1", default-features = false }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......@@ -23,7 +22,6 @@ pretty_assertions = "0.5.1"
default = ["std"]
std = [
"parity-codec/std",
"parity-codec-derive/std",
"primitives/std",
"substrate-client/std",
"rstd/std",
......
......@@ -12,7 +12,7 @@ serde = { version = "1.0", default-features = false }
serde_derive = { version = "1.0", optional = true }
safe-mix = { version = "1.0", default-features = false}
primitives = { package = "polkadot-primitives", path = "../primitives", default-features = false }
parity-codec = { version = "3.0", default-features = false, features = ["derive"] }
parity-codec = { version = "4.1", default-features = false, features = ["derive"] }
substrate-serializer = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......@@ -23,10 +23,12 @@ inherents = { package = "substrate-inherents", git = "https://github.com/parityt
consensus_aura = { package = "substrate-consensus-aura-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
offchain_primitives = { package = "substrate-offchain-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
aura = { package = "srml-aura", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
authorship = { package = "srml-authorship", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
balances = { package = "srml-balances", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
council = { package = "srml-council", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
democracy = { package = "srml-democracy", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
executive = { package = "srml-executive", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
finality-tracker = { package = "srml-finality-tracker", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
grandpa = { package = "srml-grandpa", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
indices = { package = "srml-indices", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......@@ -60,10 +62,13 @@ std = [
"rstd/std",
"sr-io/std",
"srml-support/std",
"aura/std",
"authorship/std",
"balances/std",
"council/std",
"democracy/std",
"executive/std",
"finality-tracker/std",
"grandpa/std",
"indices/std",
"sr-primitives/std",
......@@ -79,5 +84,4 @@ std = [
"log",
"safe-mix/std",
"consensus_aura/std",
"aura/std",
]
......@@ -197,7 +197,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 required.
use sr_primitives::{
BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::Header
traits::{BlakeTwo256, IdentityLookup}, testing::Header
};
use balances;
use srml_support::{impl_outer_origin, assert_ok, assert_err, assert_noop, parameter_types};
......@@ -222,6 +222,15 @@ mod tests {
type Header = Header;
type Event = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 0;
pub const TransferFee: u64 = 0;
pub const CreationFee: u64 = 0;
pub const TransactionBaseFee: u64 = 0;
pub const TransactionByteFee: u64 = 0;
}
impl balances::Trait for Test {
type Balance = u64;
type OnFreeBalanceZero = ();
......@@ -230,6 +239,11 @@ mod tests {
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
}
parameter_types!{
......@@ -274,7 +288,7 @@ mod tests {
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap().0;
// We use default for brevity, but you can configure as desired if needed.
t.extend(balances::GenesisConfig::<Test>::default().build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
......
......@@ -48,7 +48,9 @@ use council::seats as council_seats;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
use srml_support::{parameter_types, construct_runtime};
use srml_support::{
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency, OnUnbalanced}
};
#[cfg(feature = "std")]
pub use staking::StakerStatus;
......@@ -80,6 +82,16 @@ pub fn native_version() -> NativeVersion {
}
}
const DOTS: Balance = 1_000_000_000_000;
const BUCKS: Balance = DOTS / 100;
const CENTS: Balance = BUCKS / 100;
const MILLICENTS: Balance = CENTS / 1_000;
const SECS_PER_BLOCK: BlockNumber = 10;
const MINUTES: BlockNumber = 60 / SECS_PER_BLOCK;
const HOURS: BlockNumber = MINUTES * 60;
const DAYS: BlockNumber = HOURS * 24;
impl system::Trait for Runtime {
type Origin = Origin;
type Index = Nonce;
......@@ -104,14 +116,46 @@ impl indices::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const ExistentialDeposit: Balance = 1 * BUCKS;
pub const TransferFee: Balance = 1 * CENTS;
pub const CreationFee: Balance = 1 * CENTS;
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
/// Logic for the author to get a portion of fees.
pub struct ToAuthor;
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
impl OnUnbalanced<NegativeImbalance> for ToAuthor {
fn on_unbalanced(amount: NegativeImbalance) {
Balances::resolve_creating(&Authorship::author(), amount);
}
}
/// Splits fees 80/20 between treasury and block author.
pub type DealWithFees = SplitTwoWays<
Balance,
NegativeImbalance,
_4, Treasury, // 4 parts (80%) goes to the treasury.
_1, ToAuthor, // 1 part (20%) goes to the block author.
>;
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = Staking;
type OnNewAccount = Indices;
type Event = Event;
type TransactionPayment = ();
type TransactionPayment = DealWithFees;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
}
impl timestamp::Trait for Runtime {
......@@ -119,6 +163,18 @@ impl timestamp::Trait for Runtime {
type OnTimestampSet = Aura;
}
parameter_types! {
pub const UncleGenerations: u64 = 0;
}
// TODO: substrate#2986 implement this properly
impl authorship::Trait for Runtime {
type FindAuthor = ();
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = ();
}
parameter_types! {
pub const Period: BlockNumber = 10 * MINUTES;
pub const Offset: BlockNumber = 0;
......@@ -174,9 +230,6 @@ impl staking::Trait for Runtime {
type BondingDuration = BondingDuration;
}
const MINUTES: BlockNumber = 6;
const BUCKS: Balance = 1_000_000_000_000;
parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
......@@ -203,6 +256,18 @@ impl democracy::Trait for Runtime {
type CooloffPeriod = CooloffPeriod;
}
parameter_types! {
pub const CandidacyBond: Balance = 10 * BUCKS;
pub const VotingBond: Balance = 1 * BUCKS;
pub const VotingFee: Balance = 2 * BUCKS;
pub const PresentSlashPerVoter: Balance = 1 * CENTS;
pub const CarryCount: u32 = 6;
// one additional vote should go by before an inactive voter can be reaped.
pub const InactiveGracePeriod: council::VoteIndex = 1;
pub const CouncilVotingPeriod: BlockNumber = 2 * DAYS;
pub const DecayRatio: u32 = 0;
}
impl council::Trait for Runtime {
type Event = Event;
type BadPresentation = ();
......@@ -210,6 +275,14 @@ impl council::Trait for Runtime {
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type VotingFee = VotingFee;
type PresentSlashPerVoter = PresentSlashPerVoter;
type CarryCount = CarryCount;
type InactiveGracePeriod = InactiveGracePeriod;
type CouncilVotingPeriod = CouncilVotingPeriod;
type DecayRatio = DecayRatio;
}
impl council::motions::Trait for Runtime {
......@@ -218,19 +291,41 @@ impl council::motions::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 1 * BUCKS;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
}
impl treasury::Trait for Runtime {
type Currency = balances::Module<Self>;
type Currency = Balances;
type ApproveOrigin = council_motions::EnsureMembers<_4, AccountId>;
type RejectOrigin = council_motions::EnsureMembers<_2, AccountId>;
type Event = Event;
type MintedForSpending = ();
type ProposalRejection = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
}
impl grandpa::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const WindowSize: BlockNumber = finality_tracker::DEFAULT_WINDOW_SIZE.into();
pub const ReportLatency: BlockNumber = finality_tracker::DEFAULT_REPORT_LATENCY.into();
}
impl finality_tracker::Trait for Runtime {
type OnFinalizationStalled = Grandpa;
type WindowSize = WindowSize;
type ReportLatency = ReportLatency;
}
impl parachains::Trait for Runtime {
type Origin = Origin;
type Call = Call;
......@@ -263,20 +358,22 @@ construct_runtime!(
NodeBlock = primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system,
System: system::{Module, Call, Storage, Config, Event},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Authorship: authorship::{Module, Call, Storage},
Indices: indices,
Balances: balances,
Session: session::{Module, Call, Storage, Event, Config<T>},
Staking: staking,
Democracy: democracy,
Grandpa: grandpa::{Module, Call, Storage, Config<T>, Event},
CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
Staking: staking::{default, OfflineWorker},
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
Council: council::{Module, Call, Storage, Event<T>},
CouncilMotions: council_motions::{Module, Call, Storage, Event<T>, Origin<T>},
CouncilSeats: council_seats::{Config<T>},
Treasury: treasury,
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
CuratedGrandpa: curated_grandpa::{Module, Call, Config<T>, Storage},
Treasury: treasury::{Module, Call, Storage, Event<T>},
Parachains: parachains::{Module, Call, Storage, Config<T>, Inherent, Origin},
Slots: slots::{Module, Call, Storage, Event<T>},
Sudo: sudo,
......
......@@ -93,7 +93,7 @@ pub trait ParachainRegistrar<AccountId> {
impl<T: Trait> ParachainRegistrar<T::AccountId> for Module<T> {
type ParaId = ParaId;
fn new_id() -> ParaId {
<NextFreeId<T>>::mutate(|n| { let r = *n; *n = ParaId::from(u32::from(*n) + 1); r })
<NextFreeId>::mutate(|n| { let r = *n; *n = ParaId::from(u32::from(*n) + 1); r })
}
fn register_parachain(id: ParaId, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result {
let mut parachains = Self::active_parachains();
......@@ -102,9 +102,9 @@ impl<T: Trait> ParachainRegistrar<T::AccountId> for Module<T> {
Err(idx) => parachains.insert(idx, id),
}
<Code<T>>::insert(id, code);
<Parachains<T>>::put(parachains);
<Heads<T>>::insert(id, initial_head_data);
<Code>::insert(id, code);
<Parachains>::put(parachains);
<Heads>::insert(id, initial_head_data);
// Because there are no ordering guarantees that inherents
// are applied before regular transactions, a parachain candidate could
......@@ -121,8 +121,8 @@ impl<T: Trait> ParachainRegistrar<T::AccountId> for Module<T> {
Err(_) => return Ok(()),
}
<Code<T>>::remove(id);
<Heads<T>>::remove(id);
<Code>::remove(id);
<Heads>::remove(id);
let watermark = <Watermarks<T>>::take(id);
......@@ -137,7 +137,7 @@ impl<T: Trait> ParachainRegistrar<T::AccountId> for Module<T> {
}
}
<Parachains<T>>::put(parachains);
<Parachains>::put(parachains);
Ok(())
}
......@@ -249,12 +249,12 @@ decl_storage! {
let only_ids: Vec<_> = p.iter().map(|&(ref id, _, _)| id).cloned().collect();
<Parachains<T> as generator::StorageValue<_>>::put(&only_ids, storage);
<Parachains as generator::StorageValue<_>>::put(&only_ids, storage);
for (id, code, genesis) in p {
// no ingress -- a chain cannot be routed to until it is live.
<Code<T> as generator::StorageMap<_, _>>::insert(&id, &code, storage);
<Heads<T> as generator::StorageMap<_, _>>::insert(&id, &genesis, storage);
<Code as generator::StorageMap<_, _>>::insert(&id, &code, storage);
<Heads as generator::StorageMap<_, _>>::insert(&id, &genesis, storage);
<Watermarks<T> as generator::StorageMap<_, _>>::insert(&id, &Zero::zero(), storage);
}
});
......@@ -267,7 +267,7 @@ decl_module! {
/// Provide candidate receipts for parachains, in ascending order by id.
fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
ensure_none(origin)?;
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
ensure!(!<DidUpdate>::exists(), "Parachain heads must be updated only once in the block");
let active_parachains = Self::active_parachains();
let parachain_count = active_parachains.len();
......@@ -322,7 +322,7 @@ decl_module! {
);
}
<DidUpdate<T>>::put(true);
<DidUpdate>::put(true);
Ok(())
}
......@@ -385,7 +385,7 @@ impl<T: Trait> Module<T> {
) -> Result {
// Either there are no more messages to add...
if !upward_messages.is_empty() {
let (count, size) = <RelayDispatchQueueSize<T>>::get(id);
let (count, size) = <RelayDispatchQueueSize>::get(id);
ensure!(
// ...or we are appending one message onto an empty queue...
upward_messages.len() + count as usize == 1
......@@ -421,7 +421,7 @@ impl<T: Trait> Module<T> {
for head in heads.iter() {
let id = head.parachain_index();
<Heads<T>>::insert(id, &head.candidate.head_data.0);
<Heads>::insert(id, &head.candidate.head_data.0);
let last_watermark = <Watermarks<T>>::mutate(id, |mark| {
rstd::mem::replace(mark, Some(watermark))
......@@ -452,14 +452,14 @@ impl<T: Trait> Module<T> {
/// Place any new upward messages into our queue for later dispatch.
fn queue_upward_messages(id: ParaId, upward_messages: &[UpwardMessage]) {
if !upward_messages.is_empty() {
<RelayDispatchQueueSize<T>>::mutate(id, |&mut(ref mut count, ref mut len)| {
<RelayDispatchQueueSize>::mutate(id, |&mut(ref mut count, ref mut len)| {
*count += upward_messages.len() as u32;
*len += upward_messages.iter()
.fold(0, |a, x| a + x.data.len()) as u32;
});
// Should never be able to fail assuming our state is uncorrupted, but best not
// to panic, even if it does.
let _ = <RelayDispatchQueue<T>>::append(id, upward_messages);
let _ = <RelayDispatchQueue>::append(id, upward_messages);
}
}
......@@ -480,7 +480,7 @@ impl<T: Trait> Module<T> {
let mut dispatched_count = 0usize;
let mut dispatched_size = 0usize;