diff --git a/Cargo.lock b/Cargo.lock
index d374fa071f6e..258d786f380a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,34 +10,6 @@ dependencies = [
"regex",
]
-[[package]]
-name = "adder"
-version = "0.7.29-pre1"
-dependencies = [
- "dlmalloc",
- "parity-scale-codec",
- "polkadot-parachain",
- "sp-io",
- "substrate-wasm-builder-runner 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "tiny-keccak 1.5.0",
-]
-
-[[package]]
-name = "adder-collator"
-version = "0.1.0"
-dependencies = [
- "adder",
- "futures 0.3.4",
- "parity-scale-codec",
- "parking_lot 0.10.0",
- "polkadot-collator",
- "polkadot-parachain",
- "polkadot-primitives",
- "sc-client",
- "sc-client-api",
- "sp-core",
-]
-
[[package]]
name = "adler32"
version = "1.0.4"
@@ -1767,13 +1739,6 @@ dependencies = [
"tokio-util",
]
-[[package]]
-name = "halt"
-version = "0.7.29-pre1"
-dependencies = [
- "substrate-wasm-builder-runner 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
[[package]]
name = "hash-db"
version = "0.15.2"
@@ -4257,9 +4222,7 @@ dependencies = [
name = "polkadot-parachain"
version = "0.7.29-pre1"
dependencies = [
- "adder",
"derive_more 0.99.3",
- "halt",
"log 0.4.8",
"parity-scale-codec",
"parking_lot 0.10.0",
@@ -4272,7 +4235,6 @@ dependencies = [
"sp-runtime-interface",
"sp-std",
"sp-wasm-interface",
- "tiny-keccak 1.5.0",
]
[[package]]
@@ -4280,7 +4242,6 @@ name = "polkadot-primitives"
version = "0.7.29-pre1"
dependencies = [
"bitvec",
- "pallet-babe",
"parity-scale-codec",
"polkadot-parachain",
"pretty_assertions",
@@ -7412,6 +7373,65 @@ dependencies = [
"winapi-util",
]
+[[package]]
+name = "test-parachain-adder"
+version = "0.7.29-pre1"
+dependencies = [
+ "dlmalloc",
+ "parity-scale-codec",
+ "polkadot-parachain",
+ "sp-io",
+ "substrate-wasm-builder-runner 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tiny-keccak 1.5.0",
+]
+
+[[package]]
+name = "test-parachain-adder-collator"
+version = "0.1.0"
+dependencies = [
+ "futures 0.3.4",
+ "parity-scale-codec",
+ "parking_lot 0.10.0",
+ "polkadot-collator",
+ "polkadot-parachain",
+ "polkadot-primitives",
+ "sc-client",
+ "sc-client-api",
+ "sp-core",
+ "test-parachain-adder",
+]
+
+[[package]]
+name = "test-parachain-code-upgrader"
+version = "0.7.22"
+dependencies = [
+ "dlmalloc",
+ "parity-scale-codec",
+ "polkadot-parachain",
+ "sp-io",
+ "substrate-wasm-builder-runner 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tiny-keccak 1.5.0",
+]
+
+[[package]]
+name = "test-parachain-halt"
+version = "0.7.29-pre1"
+dependencies = [
+ "substrate-wasm-builder-runner 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "test-parachains"
+version = "0.7.22"
+dependencies = [
+ "parity-scale-codec",
+ "polkadot-parachain",
+ "test-parachain-adder",
+ "test-parachain-code-upgrader",
+ "test-parachain-halt",
+ "tiny-keccak 1.5.0",
+]
+
[[package]]
name = "textwrap"
version = "0.11.0"
diff --git a/Cargo.toml b/Cargo.toml
index a83c19a0e649..2fe3d06ba2d3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -41,13 +41,15 @@ members = [
"service",
"validation",
- "test-parachains/adder",
- "test-parachains/adder/collator",
+ "parachain/test-parachains",
+ "parachain/test-parachains/adder",
+ "parachain/test-parachains/adder/collator",
+ "parachain/test-parachains/code-upgrader",
]
exclude = [
"runtime/polkadot/wasm",
"runtime/kusama/wasm",
- "test-parachains/adder/wasm",
+ "parachain/test-parachains/adder/wasm",
]
[badges]
diff --git a/collator/src/lib.rs b/collator/src/lib.rs
index 68d88137f0e3..9a5908f5cbb7 100644
--- a/collator/src/lib.rs
+++ b/collator/src/lib.rs
@@ -59,7 +59,7 @@ use polkadot_primitives::{
BlockId, Hash, Block,
parachain::{
self, BlockData, DutyRoster, HeadData, Id as ParaId,
- PoVBlock, ValidatorId, CollatorPair, LocalValidationData
+ PoVBlock, ValidatorId, CollatorPair, LocalValidationData, GlobalValidationSchedule,
}
};
use polkadot_cli::{
@@ -154,7 +154,8 @@ pub trait ParachainContext: Clone {
fn produce_candidate(
&mut self,
relay_parent: Hash,
- status: LocalValidationData,
+ global_validation: GlobalValidationSchedule,
+ local_validation: LocalValidationData,
) -> Self::ProduceCandidate;
}
@@ -162,6 +163,7 @@ pub trait ParachainContext: Clone {
pub async fn collate
(
relay_parent: Hash,
local_id: ParaId,
+ global_validation: GlobalValidationSchedule,
local_validation_data: LocalValidationData,
mut para_context: P,
key: Arc,
@@ -173,6 +175,7 @@ pub async fn collate(
{
let (block_data, head_data) = para_context.produce_candidate(
relay_parent,
+ global_validation,
local_validation_data,
).map_err(Error::Collator).await?;
@@ -281,6 +284,7 @@ fn build_collator_service(
let work = future::lazy(move |_| {
let api = client.runtime_api();
+ let global_validation = try_fr!(api.global_validation_schedule(&id));
let local_validation = match try_fr!(api.local_validation_data(&id, para_id)) {
Some(local_validation) => local_validation,
None => return future::Either::Left(future::ok(())),
@@ -297,6 +301,7 @@ fn build_collator_service(
let collation_work = collate(
relay_parent,
para_id,
+ global_validation,
local_validation,
parachain_context,
key,
@@ -427,6 +432,7 @@ mod tests {
fn produce_candidate(
&mut self,
_relay_parent: Hash,
+ _global: GlobalValidationSchedule,
_local_validation: LocalValidationData,
) -> Self::ProduceCandidate {
// send messages right back.
diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml
index e8d34d080b77..8cdebc52f1aa 100644
--- a/parachain/Cargo.toml
+++ b/parachain/Cargo.toml
@@ -6,13 +6,18 @@ description = "Types and utilities for creating and working with parachains"
edition = "2018"
[dependencies]
-codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = [ "derive" ] }
-derive_more = { version = "0.99.2", optional = true }
-serde = { version = "1.0.102", default-features = false, features = [ "derive" ], optional = true }
+# note: special care is taken to avoid inclusion of `sp-io` externals when compiling
+# this crate for WASM. This is critical to avoid forcing all parachain WASM into implementing
+# various unnecessary Substrate-specific endpoints.
+codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = [ "derive" ] }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
-sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
+
+# all optional crates.
+derive_more = { version = "0.99.2", optional = true }
+serde = { version = "1.0.102", default-features = false, features = [ "derive" ], optional = true }
+sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true, default-features = false }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
@@ -22,14 +27,9 @@ log = { version = "0.4.8", optional = true }
[target.'cfg(not(target_os = "unknown"))'.dependencies]
shared_memory = { version = "0.10.0", optional = true }
-[dev-dependencies]
-tiny-keccak = "1.5.0"
-adder = { path = "../test-parachains/adder" }
-halt = { path = "../test-parachains/halt" }
-
[features]
default = ["std"]
-wasm-api = []
+wasm-api = ["sp-runtime-interface"]
std = [
"codec/std",
"derive_more",
@@ -39,6 +39,7 @@ std = [
"sp-core/std",
"parking_lot",
"log",
+ "sp-runtime-interface",
"sp-runtime-interface/std",
"sp-externalities",
"sc-executor",
diff --git a/parachain/src/lib.rs b/parachain/src/lib.rs
index 2aeb59a34092..67a5a6839245 100644
--- a/parachain/src/lib.rs
+++ b/parachain/src/lib.rs
@@ -45,182 +45,9 @@
#[cfg(feature = "std")]
pub mod wasm_executor;
+pub mod primitives;
mod wasm_api;
-use sp_std::vec::Vec;
-
-use codec::{Encode, Decode, CompactAs};
-use sp_core::{RuntimeDebug, TypeId};
-
#[cfg(all(not(feature = "std"), feature = "wasm-api"))]
pub use wasm_api::*;
-
-/// Validation parameters for evaluating the parachain validity function.
-// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
-#[derive(PartialEq, Eq, Decode)]
-#[cfg_attr(feature = "std", derive(Debug, Encode))]
-pub struct ValidationParams {
- /// The collation body.
- pub block_data: Vec,
- /// Previous head-data.
- pub parent_head: Vec,
-}
-
-/// The result of parachain validation.
-// TODO: egress and balance uploads (https://github.com/paritytech/polkadot/issues/220)
-#[derive(PartialEq, Eq, Encode)]
-#[cfg_attr(feature = "std", derive(Debug, Decode))]
-pub struct ValidationResult {
- /// New head data that should be included in the relay chain state.
- pub head_data: Vec,
-}
-
-/// Unique identifier of a parachain.
-#[derive(
- Clone, CompactAs, Copy, Decode, Default, Encode, Eq,
- Hash, Ord, PartialEq, PartialOrd, RuntimeDebug,
-)]
-#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, derive_more::Display))]
-pub struct Id(u32);
-
-impl TypeId for Id {
- const TYPE_ID: [u8; 4] = *b"para";
-}
-
-/// Type for determining the active set of parachains.
-pub trait ActiveThreads {
- /// Return the current ordered set of `Id`s of active parathreads.
- fn active_threads() -> Vec;
-}
-
-impl From for u32 {
- fn from(x: Id) -> Self { x.0 }
-}
-
-impl From for Id {
- fn from(x: u32) -> Self { Id(x) }
-}
-
-const USER_INDEX_START: u32 = 1000;
-
-/// The ID of the first user (non-system) parachain.
-pub const LOWEST_USER_ID: Id = Id(USER_INDEX_START);
-
-impl Id {
- /// Create an `Id`.
- pub const fn new(id: u32) -> Self {
- Self(id)
- }
-
- /// Returns `true` if this parachain runs with system-level privileges.
- pub fn is_system(&self) -> bool { self.0 < USER_INDEX_START }
-}
-
-impl sp_std::ops::Add for Id {
- type Output = Self;
-
- fn add(self, other: u32) -> Self {
- Self(self.0 + other)
- }
-}
-
-// TODO: Remove all of this, move sp-runtime::AccountIdConversion to own crate and and use that.
-// #360
-struct TrailingZeroInput<'a>(&'a [u8]);
-impl<'a> codec::Input for TrailingZeroInput<'a> {
- fn remaining_len(&mut self) -> Result