diff --git a/network/src/legacy/router.rs b/network/src/legacy/router.rs
index 4a969a4870e6..d4feaca2dff8 100644
--- a/network/src/legacy/router.rs
+++ b/network/src/legacy/router.rs
@@ -32,6 +32,7 @@ use polkadot_primitives::parachain::{
CandidateReceipt, ParachainHost, ValidatorIndex, Collation, PoVBlock, ErasureChunk,
};
use sp_api::ProvideRuntimeApi;
+use sp_blockchain::HeaderBackend;
use futures::prelude::*;
use futures::{task::SpawnExt, future::ready};
@@ -133,6 +134,7 @@ impl
Clone for Router
{
}
impl + Send + Sync + 'static, T> Router where
+ P: HeaderBackend,
P::Api: ParachainHost,
T: Clone + Executor + Send + 'static,
{
diff --git a/network/src/legacy/validation.rs b/network/src/legacy/validation.rs
index c64f21428d41..0901b016df90 100644
--- a/network/src/legacy/validation.rs
+++ b/network/src/legacy/validation.rs
@@ -29,6 +29,7 @@ use polkadot_primitives::parachain::{
ValidatorId, PoVBlock,
};
use sp_api::ProvideRuntimeApi;
+use sp_blockchain::HeaderBackend;
use futures::prelude::*;
use futures::task::SpawnExt;
@@ -167,7 +168,7 @@ impl ValidationNetwork
{
/// A long-lived network which can create parachain statement routing processes on demand.
impl
ParachainNetwork for ValidationNetwork
where
- P: ProvideRuntimeApi + Send + Sync + 'static,
+ P: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static,
P::Api: ParachainHost,
T: Clone + Executor + Send + Sync + 'static,
{
diff --git a/network/src/protocol.rs b/network/src/protocol.rs
index acdee6830771..9fdb73f30cef 100644
--- a/network/src/protocol.rs
+++ b/network/src/protocol.rs
@@ -40,6 +40,7 @@ use polkadot_validation::{
};
use sc_network::{config::Roles, Event, PeerId};
use sp_api::ProvideRuntimeApi;
+use sp_blockchain::HeaderBackend;
use std::collections::HashMap;
use std::pin::Pin;
@@ -110,7 +111,7 @@ pub fn start(
executor: SP,
) -> Result where
C: ChainContext + 'static,
- Api: ProvideRuntimeApi + Send + Sync + 'static,
+ Api: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static,
Api::Api: ParachainHost,
SP: Spawn + Clone + Send + 'static,
{
@@ -566,7 +567,7 @@ async fn worker_loop(
mut receiver: mpsc::Receiver,
executor: Sp,
) where
- Api: ProvideRuntimeApi + Send + Sync + 'static,
+ Api: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static,
Api::Api: ParachainHost,
Sp: Spawn + Clone + Send + 'static,
{
@@ -690,7 +691,7 @@ async fn statement_import_loop(
mut exit: exit_future::Exit,
executor: impl Spawn,
) where
- Api: ProvideRuntimeApi + Send + Sync + 'static,
+ Api: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static,
Api::Api: ParachainHost,
{
let topic = crate::legacy::router::attestation_topic(relay_parent);
diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml
index 85948c302244..a0104dc6f803 100644
--- a/parachain/Cargo.toml
+++ b/parachain/Cargo.toml
@@ -18,6 +18,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-bra
lazy_static = { version = "1.4.0", optional = true }
parking_lot = { version = "0.10.0", optional = true }
log = { version = "0.4.8", optional = true }
+polkadot-primitives = { path = "../primitives", default-features = false }
[target.'cfg(not(target_os = "unknown"))'.dependencies]
shared_memory = { version = "0.10.0", optional = true }
@@ -44,4 +45,5 @@ std = [
"sp-externalities",
"sc-executor",
"sp-io",
+ "polkadot-primitives/std",
]
diff --git a/parachain/src/lib.rs b/parachain/src/lib.rs
index d1324140d78f..215e60c290bd 100644
--- a/parachain/src/lib.rs
+++ b/parachain/src/lib.rs
@@ -50,12 +50,20 @@ mod wasm_api;
use rstd::vec::Vec;
-use codec::{Encode, Decode, CompactAs};
-use sp_core::{RuntimeDebug, TypeId};
+use codec::{Encode, Decode};
#[cfg(all(not(feature = "std"), feature = "wasm-api"))]
pub use wasm_api::*;
+pub use polkadot_primitives::{BlockNumber, parachain::{
+ AccountIdConversion,
+ Id,
+ IncomingMessage,
+ LOWEST_USER_ID,
+ ParachainDispatchOrigin,
+ UpwardMessage,
+}};
+
/// Validation parameters for evaluating the parachain validity function.
// TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220)
#[derive(PartialEq, Eq, Decode)]
@@ -65,6 +73,8 @@ pub struct ValidationParams {
pub block_data: Vec,
/// Previous head-data.
pub parent_head: Vec,
+ /// Number of the current relay chain block.
+ pub current_relay_block: BlockNumber,
}
/// The result of parachain validation.
@@ -75,152 +85,3 @@ 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 rstd::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