Unverified Commit 90d5dbe5 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Downward & Upward messages (#1266)

* Downward messages, the front-end.

* Move types around to make them accessible from Parachains

* Fix compilation

* Fix branch

* Make it compile for Cumulus

* Update the branch names

* Add default generic parameter

* Implement `Partialeq`

* Move upward messages into the `ValidationResult`

* Support disabling of the runtime api

* Update branch

* Adds support for handling downward messages

* Implement sending XCMP messages as up/downward messages

* service: update to latest ServiceBuilder changes

* Make it compile

* Initial commit

Forked at: b2c9c149


Parent branch: origin/master

* Update substrate branch to cecton-update-polkadot-substrate

* Update substrate & polkadot to cumulus-branch

* Reset branch

* Update primitives/src/parachain.rs
Co-authored-by: asynchronous rob's avatarRobert Habermeier <rphmeier@gmail.com>

* Update runtime/common/src/parachains.rs
Co-authored-by: asynchronous rob's avatarRobert Habermeier <rphmeier@gmail.com>

* Update runtime/common/src/parachains.rs
Co-authored-by: asynchronous rob's avatarRobert Habermeier <rphmeier@gmail.com>

* Minor fixes

* Fix wasm build
Co-authored-by: default avatarGav Wood <gavin@parity.io>
Co-authored-by: André Silva's avatarAndré Silva <andre.beat@gmail.com>
Co-authored-by: default avatarCecile Tonglet <cecile.tonglet@cecton.com>
Co-authored-by: asynchronous rob's avatarRobert Habermeier <rphmeier@gmail.com>
parent c6b29c7b
Pipeline #99049 passed with stages
in 22 minutes and 4 seconds
...@@ -4319,6 +4319,16 @@ dependencies = [ ...@@ -4319,6 +4319,16 @@ dependencies = [
"tokio 0.2.21", "tokio 0.2.21",
] ]
[[package]]
name = "polkadot-core-primitives"
version = "0.7.30"
dependencies = [
"parity-scale-codec",
"sp-core",
"sp-runtime",
"sp-std",
]
[[package]] [[package]]
name = "polkadot-erasure-coding" name = "polkadot-erasure-coding"
version = "0.8.13" version = "0.8.13"
...@@ -4446,13 +4456,13 @@ dependencies = [ ...@@ -4446,13 +4456,13 @@ dependencies = [
"log 0.4.8", "log 0.4.8",
"parity-scale-codec", "parity-scale-codec",
"parking_lot 0.10.2", "parking_lot 0.10.2",
"polkadot-core-primitives",
"sc-executor", "sc-executor",
"serde", "serde",
"shared_memory", "shared_memory",
"sp-core", "sp-core",
"sp-externalities", "sp-externalities",
"sp-io", "sp-io",
"sp-runtime-interface",
"sp-std", "sp-std",
"sp-wasm-interface", "sp-wasm-interface",
] ]
...@@ -4464,6 +4474,7 @@ dependencies = [ ...@@ -4464,6 +4474,7 @@ dependencies = [
"bitvec", "bitvec",
"frame-system", "frame-system",
"parity-scale-codec", "parity-scale-codec",
"polkadot-core-primitives",
"polkadot-parachain", "polkadot-parachain",
"pretty_assertions", "pretty_assertions",
"serde", "serde",
...@@ -8043,6 +8054,7 @@ dependencies = [ ...@@ -8043,6 +8054,7 @@ dependencies = [
"parity-scale-codec", "parity-scale-codec",
"polkadot-parachain", "polkadot-parachain",
"sp-io", "sp-io",
"sp-std",
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.5.0", "tiny-keccak 1.5.0",
] ]
...@@ -8070,6 +8082,7 @@ dependencies = [ ...@@ -8070,6 +8082,7 @@ dependencies = [
"parity-scale-codec", "parity-scale-codec",
"polkadot-parachain", "polkadot-parachain",
"sp-io", "sp-io",
"sp-std",
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.5.0", "tiny-keccak 1.5.0",
] ]
......
...@@ -26,6 +26,7 @@ members = [ ...@@ -26,6 +26,7 @@ members = [
"availability-store", "availability-store",
"cli", "cli",
"collator", "collator",
"core-primitives",
"erasure-coding", "erasure-coding",
"network", "network",
"network/test", "network/test",
......
...@@ -33,7 +33,7 @@ use polkadot_primitives::{ ...@@ -33,7 +33,7 @@ use polkadot_primitives::{
}, },
}; };
use sp_runtime::traits::HashFor; use sp_runtime::traits::HashFor;
use sp_blockchain::{Result as ClientResult}; use sp_blockchain::Result as ClientResult;
use client::{ use client::{
BlockchainEvents, BlockBackend, BlockchainEvents, BlockBackend,
}; };
...@@ -58,7 +58,7 @@ use worker::{ ...@@ -58,7 +58,7 @@ use worker::{
Worker, WorkerHandle, IncludedParachainBlocks, WorkerMsg, MakeAvailable, Chunks Worker, WorkerHandle, IncludedParachainBlocks, WorkerMsg, MakeAvailable, Chunks
}; };
use store::{Store as InnerStore}; use store::Store as InnerStore;
const LOG_TARGET: &str = "availability"; const LOG_TARGET: &str = "availability";
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
use kvdb_rocksdb::{Database, DatabaseConfig}; use kvdb_rocksdb::{Database, DatabaseConfig};
use kvdb::{KeyValueDB, DBTransaction}; use kvdb::{KeyValueDB, DBTransaction};
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use polkadot_erasure_coding::{self as erasure}; use polkadot_erasure_coding as erasure;
use polkadot_primitives::{ use polkadot_primitives::{
Hash, Hash,
parachain::{ parachain::{
......
...@@ -56,7 +56,7 @@ use sc_client_api::{StateBackend, BlockchainEvents}; ...@@ -56,7 +56,7 @@ use sc_client_api::{StateBackend, BlockchainEvents};
use sp_blockchain::HeaderBackend; use sp_blockchain::HeaderBackend;
use sp_core::Pair; use sp_core::Pair;
use polkadot_primitives::{ use polkadot_primitives::{
BlockId, Hash, Block, BlockId, Hash, Block, DownwardMessage,
parachain::{ parachain::{
self, BlockData, DutyRoster, HeadData, Id as ParaId, self, BlockData, DutyRoster, HeadData, Id as ParaId,
PoVBlock, ValidatorId, CollatorPair, LocalValidationData, GlobalValidationSchedule, PoVBlock, ValidatorId, CollatorPair, LocalValidationData, GlobalValidationSchedule,
...@@ -150,6 +150,7 @@ pub trait ParachainContext: Clone { ...@@ -150,6 +150,7 @@ pub trait ParachainContext: Clone {
relay_parent: Hash, relay_parent: Hash,
global_validation: GlobalValidationSchedule, global_validation: GlobalValidationSchedule,
local_validation: LocalValidationData, local_validation: LocalValidationData,
downward_messages: Vec<DownwardMessage>,
) -> Self::ProduceCandidate; ) -> Self::ProduceCandidate;
} }
...@@ -159,6 +160,7 @@ pub async fn collate<P>( ...@@ -159,6 +160,7 @@ pub async fn collate<P>(
local_id: ParaId, local_id: ParaId,
global_validation: GlobalValidationSchedule, global_validation: GlobalValidationSchedule,
local_validation_data: LocalValidationData, local_validation_data: LocalValidationData,
downward_messages: Vec<DownwardMessage>,
mut para_context: P, mut para_context: P,
key: Arc<CollatorPair>, key: Arc<CollatorPair>,
) -> Option<parachain::Collation> ) -> Option<parachain::Collation>
...@@ -170,6 +172,7 @@ pub async fn collate<P>( ...@@ -170,6 +172,7 @@ pub async fn collate<P>(
relay_parent, relay_parent,
global_validation, global_validation,
local_validation_data, local_validation_data,
downward_messages,
).await?; ).await?;
let pov_block = PoVBlock { let pov_block = PoVBlock {
...@@ -317,6 +320,7 @@ fn build_collator_service<P, C, R, Extrinsic>( ...@@ -317,6 +320,7 @@ fn build_collator_service<P, C, R, Extrinsic>(
Some(local_validation) => local_validation, Some(local_validation) => local_validation,
None => return future::Either::Left(future::ok(())), None => return future::Either::Left(future::ok(())),
}; };
let downward_messages = try_fr!(api.downward_messages(&id, para_id));
let validators = try_fr!(api.validators(&id)); let validators = try_fr!(api.validators(&id));
...@@ -331,6 +335,7 @@ fn build_collator_service<P, C, R, Extrinsic>( ...@@ -331,6 +335,7 @@ fn build_collator_service<P, C, R, Extrinsic>(
para_id, para_id,
global_validation, global_validation,
local_validation, local_validation,
downward_messages,
parachain_context, parachain_context,
key, key,
).map(move |collation| { ).map(move |collation| {
...@@ -470,6 +475,7 @@ mod tests { ...@@ -470,6 +475,7 @@ mod tests {
_relay_parent: Hash, _relay_parent: Hash,
_global: GlobalValidationSchedule, _global: GlobalValidationSchedule,
_local_validation: LocalValidationData, _local_validation: LocalValidationData,
_: Vec<DownwardMessage>,
) -> Self::ProduceCandidate { ) -> Self::ProduceCandidate {
// send messages right back. // send messages right back.
future::ready(Some(( future::ready(Some((
......
[package]
name = "polkadot-core-primitives"
version = "0.7.30"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = [ "derive" ] }
[features]
default = [ "std" ]
std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"codec/std",
]
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
#![cfg_attr(not(feature = "std"), no_std)]
//! Core Polkadot types.
//!
//! These core Polkadot types are used by the relay chain and the Parachains.
use sp_runtime::{generic, MultiSignature, traits::{Verify, BlakeTwo256, IdentifyAccount}};
/// The block number type used by Polkadot.
/// 32-bits will allow for 136 years of blocks assuming 1 block per second.
pub type BlockNumber = u32;
/// An instant or duration in time.
pub type Moment = u64;
/// Alias to type for a signature for a transaction on the relay chain. This allows one of several
/// kinds of underlying crypto to be used, so isn't a fixed size when encoded.
pub type Signature = MultiSignature;
/// Alias to the public key used for this chain, actually a `MultiSigner`. Like the signature, this
/// also isn't a fixed size when encoded, as different cryptos have different size public keys.
pub type AccountPublic = <Signature as Verify>::Signer;
/// Alias to the opaque account ID type for this chain, actually a `AccountId32`. This is always
/// 32 bytes.
pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
/// The type for looking up accounts. We don't expect more than 4 billion of them.
pub type AccountIndex = u32;
/// Identifier for a chain. 32-bit should be plenty.
pub type ChainId = u32;
/// A hash of some data used by the relay chain.
pub type Hash = sp_core::H256;
/// Index of a transaction in the relay chain. 32-bit should be plenty.
pub type Nonce = u32;
/// The balance of an account.
/// 128-bits (or 38 significant decimal figures) will allow for 10m currency (10^7) at a resolution
/// to all for one second's worth of an annualised 50% reward be paid to a unit holder (10^11 unit
/// denomination), or 10^18 total atomic units, to grow at 50%/year for 51 years (10^9 multiplier)
/// for an eventual total of 10^27 units (27 significant decimal figures).
/// We round denomination to 10^12 (12 sdf), and leave the other redundancy at the upper end so
/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow.
pub type Balance = u128;
/// Header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Block ID.
pub type BlockId = generic::BlockId<Block>;
/// Opaque, encoded, unchecked extrinsic.
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
/// The information that goes alongside a transfer_into_parachain operation. Entirely opaque, it
/// will generally be used for identifying the reason for the transfer. Typically it will hold the
/// destination account to which the transfer should be credited. If still more information is
/// needed, then this should be a hash with the pre-image presented via an off-chain mechanism on
/// the parachain.
pub type Remark = [u8; 32];
/// These are special "control" messages that can be passed from the Relaychain to a parachain.
/// They should be handled by all parachains.
#[derive(codec::Encode, codec::Decode, Clone, sp_runtime::RuntimeDebug, PartialEq)]
pub enum DownwardMessage<AccountId = crate::AccountId> {
/// Some funds were transferred into the parachain's account. The hash is the identifier that
/// was given with the transfer.
TransferInto(AccountId, Balance, Remark),
/// An opaque blob of data. The relay chain must somehow know how to form this so that the
/// destination parachain does something sensible.
///
/// NOTE: Be very careful not to allow users to place arbitrary size information in here.
Opaque(sp_std::vec::Vec<u8>),
/// XCMP message for the Parachain.
XCMPMessage(sp_std::vec::Vec<u8>),
}
...@@ -185,6 +185,9 @@ sp_api::mock_impl_runtime_apis! { ...@@ -185,6 +185,9 @@ sp_api::mock_impl_runtime_apis! {
parent_hash: Default::default(), parent_hash: Default::default(),
} }
} }
fn downward_messages(_: ParaId) -> Vec<polkadot_primitives::DownwardMessage> {
Vec::new()
}
} }
} }
......
...@@ -13,11 +13,11 @@ codec = { package = "parity-scale-codec", version = "1.1.0", default-features = ...@@ -13,11 +13,11 @@ codec = { package = "parity-scale-codec", version = "1.1.0", default-features =
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } 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-core = { 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 } sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
polkadot-core-primitives = { path = "../core-primitives", default-features = false }
# all optional crates. # all optional crates.
derive_more = { version = "0.99.2", optional = true } derive_more = { version = "0.99.2", optional = true }
serde = { version = "1.0.102", default-features = false, features = [ "derive" ], 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 } sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-executor = { 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 } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
...@@ -29,7 +29,7 @@ shared_memory = { version = "0.10.0", optional = true } ...@@ -29,7 +29,7 @@ shared_memory = { version = "0.10.0", optional = true }
[features] [features]
default = ["std"] default = ["std"]
wasm-api = ["sp-runtime-interface"] wasm-api = []
std = [ std = [
"codec/std", "codec/std",
"derive_more", "derive_more",
...@@ -39,8 +39,8 @@ std = [ ...@@ -39,8 +39,8 @@ std = [
"sp-core/std", "sp-core/std",
"parking_lot", "parking_lot",
"log", "log",
"sp-runtime-interface/std",
"sp-externalities", "sp-externalities",
"sc-executor", "sc-executor",
"sp-io", "sp-io",
"polkadot-core-primitives/std",
] ]
...@@ -28,9 +28,8 @@ use serde::{Serialize, Deserialize}; ...@@ -28,9 +28,8 @@ use serde::{Serialize, Deserialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use sp_core::bytes; use sp_core::bytes;
/// The block number of the relay chain. /// Block number type used by the relay chain.
/// 32-bits will allow for 136 years of blocks assuming 1 block per second. pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber;
pub type RelayChainBlockNumber = u32;
/// Parachain head data included in the chain. /// Parachain head data included in the chain.
#[derive(PartialEq, Eq, Clone, PartialOrd, Ord, Encode, Decode, RuntimeDebug)] #[derive(PartialEq, Eq, Clone, PartialOrd, Ord, Encode, Decode, RuntimeDebug)]
...@@ -186,10 +185,6 @@ impl sp_std::convert::TryFrom<u8> for ParachainDispatchOrigin { ...@@ -186,10 +185,6 @@ impl sp_std::convert::TryFrom<u8> for ParachainDispatchOrigin {
/// A message from a parachain to its Relay Chain. /// A message from a parachain to its Relay Chain.
#[derive(Clone, PartialEq, Eq, Encode, Decode)] #[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(
any(feature = "std", feature = "wasm-api"),
derive(sp_runtime_interface::pass_by::PassByCodec,
))]
#[cfg_attr(feature = "std", derive(Debug))] #[cfg_attr(feature = "std", derive(Debug))]
pub struct UpwardMessage { pub struct UpwardMessage {
/// The origin for the message to be sent from. /// The origin for the message to be sent from.
...@@ -212,13 +207,13 @@ pub struct ValidationParams { ...@@ -212,13 +207,13 @@ pub struct ValidationParams {
/// The maximum head-data size permitted, in bytes. /// The maximum head-data size permitted, in bytes.
pub max_head_data_size: u32, pub max_head_data_size: u32,
/// The current relay-chain block number. /// The current relay-chain block number.
pub relay_chain_height: RelayChainBlockNumber, pub relay_chain_height: polkadot_core_primitives::BlockNumber,
/// Whether a code upgrade is allowed or not, and at which height the upgrade /// Whether a code upgrade is allowed or not, and at which height the upgrade
/// would be applied after, if so. The parachain logic should apply any upgrade /// would be applied after, if so. The parachain logic should apply any upgrade
/// issued in this block after the first block /// issued in this block after the first block
/// with `relay_chain_height` at least this value, if `Some`. if `None`, issue /// with `relay_chain_height` at least this value, if `Some`. if `None`, issue
/// no upgrade. /// no upgrade.
pub code_upgrade_allowed: Option<RelayChainBlockNumber>, pub code_upgrade_allowed: Option<polkadot_core_primitives::BlockNumber>,
} }
/// The result of parachain validation. /// The result of parachain validation.
...@@ -230,4 +225,10 @@ pub struct ValidationResult { ...@@ -230,4 +225,10 @@ pub struct ValidationResult {
pub head_data: HeadData, pub head_data: HeadData,
/// An update to the validation code that should be scheduled in the relay chain. /// An update to the validation code that should be scheduled in the relay chain.
pub new_validation_code: Option<ValidationCode>, pub new_validation_code: Option<ValidationCode>,
/// Upward messages send by the Parachain.
pub upward_messages: Vec<UpwardMessage>,
/// Number of downward messages that were processed by the Parachain.
///
/// It is expected that the Parachain processes them from first to last.
pub processed_downward_messages: u32,
} }
...@@ -16,29 +16,6 @@ ...@@ -16,29 +16,6 @@
//! Utilities for writing parachain WASM. //! Utilities for writing parachain WASM.
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
use crate::primitives::UpwardMessage;
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
use sp_runtime_interface::runtime_interface;
#[cfg(feature = "std")]
use sp_externalities::ExternalitiesExt;
/// The parachain api for posting messages.
// Either activate on `std` to get access to the `HostFunctions` or when `wasm-api` is given and on
// `no_std`.
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "wasm-api")))]
#[runtime_interface]
pub trait Parachain {
/// Post a message to this parachain's relay chain.
#[allow(dead_code)]
fn post_upward_message(&mut self, msg: UpwardMessage) {
self.extension::<crate::wasm_executor::ParachainExt>()
.expect("No `ParachainExt` associated with the current context.")
.post_upward_message(msg)
.expect("Failed to post upward message")
}
}
/// Load the validation params from memory when implementing a Rust parachain. /// Load the validation params from memory when implementing a Rust parachain.
/// ///
/// Offset and length must have been provided by the validation /// Offset and length must have been provided by the validation
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
//! a WASM VM for re-execution of a parachain candidate. //! a WASM VM for re-execution of a parachain candidate.
use std::any::{TypeId, Any}; use std::any::{TypeId, Any};
use crate::primitives::{ValidationParams, ValidationResult, UpwardMessage}; use crate::primitives::{ValidationParams, ValidationResult};
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use sp_core::storage::ChildInfo; use sp_core::storage::ChildInfo;
use sp_core::traits::CallInWasm; use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _;
use sp_externalities::Extensions; use sp_externalities::Extensions;
use sp_wasm_interface::HostFunctions as _;
#[cfg(not(any(target_os = "android", target_os = "unknown")))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC}; pub use validation_host::{run_worker, ValidationPool, EXECUTION_TIMEOUT_SEC};
...@@ -37,18 +37,6 @@ mod validation_host; ...@@ -37,18 +37,6 @@ mod validation_host;
const MAX_RUNTIME_MEM: usize = 1024 * 1024 * 1024; // 1 GiB const MAX_RUNTIME_MEM: usize = 1024 * 1024 * 1024; // 1 GiB
const MAX_CODE_MEM: usize = 16 * 1024 * 1024; // 16 MiB const MAX_CODE_MEM: usize = 16 * 1024 * 1024; // 16 MiB
sp_externalities::decl_extension! {
/// The extension that is registered at the `Externalities` when validating a parachain state
/// transition.
pub(crate) struct ParachainExt(Box<dyn Externalities>);
}
impl ParachainExt {
pub fn new<T: Externalities + 'static>(ext: T) -> Self {
Self(Box::new(ext))
}
}
/// A stub validation-pool defined when compiling for Android or WASM. /// A stub validation-pool defined when compiling for Android or WASM.
#[cfg(any(target_os = "android", target_os = "unknown"))] #[cfg(any(target_os = "android", target_os = "unknown"))]
#[derive(Clone)] #[derive(Clone)]
...@@ -124,32 +112,25 @@ impl std::error::Error for Error { ...@@ -124,32 +112,25 @@ impl std::error::Error for Error {
} }
} }
/// Externalities for parachain validation.
pub trait Externalities: Send {
/// Called when a message is to be posted to the parachain's relay chain.
fn post_upward_message(&mut self, message: UpwardMessage) -> Result<(), String>;
}
/// Validate a candidate under the given validation code. /// Validate a candidate under the given validation code.
/// ///
/// This will fail if the validation code is not a proper parachain validation module. /// This will fail if the validation code is not a proper parachain validation module.
pub fn validate_candidate<E: Externalities + 'static>( pub fn validate_candidate(
validation_code: &[u8], validation_code: &[u8],
params: ValidationParams, params: ValidationParams,
ext: E,
options: ExecutionMode<'_>, options: ExecutionMode<'_>,
) -> Result<ValidationResult, Error> { ) -> Result<ValidationResult, Error> {
match options { match options {
ExecutionMode::Local => { ExecutionMode::Local => {
validate_candidate_internal(validation_code, &params.encode(), ext) validate_candidate_internal(validation_code, &params.encode())
}, },
#[cfg(not(any(target_os = "android", target_os = "unknown")))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
ExecutionMode::Remote(pool) => { ExecutionMode::Remote(pool) => {
pool.validate_candidate(validation_code, params, ext, false) pool.validate_candidate(validation_code, params, false)
}, },
#[cfg(not(any(target_os = "android", target_os = "unknown")))] #[cfg(not(any(target_os = "android", target_os = "unknown")))]
ExecutionMode::RemoteTest(pool) => { ExecutionMode::RemoteTest(pool) => {
pool.validate_candidate(validation_code, params, ext, true) pool.validate_candidate(validation_code, params, true)
}, },
#[cfg(any(target_os = "android", target_os = "unknown"))] #[cfg(any(target_os = "android", target_os = "unknown"))]