diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock
index 41c7da9793..73d1cb5fa6 100644
--- a/polkadot/Cargo.lock
+++ b/polkadot/Cargo.lock
@@ -2273,6 +2273,8 @@ dependencies = [
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -2283,6 +2285,7 @@ version = "0.1.0"
dependencies = [
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "polkadot-parachain 0.1.0",
"pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/polkadot/consensus/src/collation.rs b/polkadot/consensus/src/collation.rs
index af1918e389..13b64784a3 100644
--- a/polkadot/consensus/src/collation.rs
+++ b/polkadot/consensus/src/collation.rs
@@ -305,8 +305,7 @@ pub fn validate_collation
(
parent_head: chain_head,
block_data: collation.block_data.0.clone(),
ingress: incoming.iter()
- .flat_map(|&(para_id, ref messages)| {
- let source: u32 = para_id.into();
+ .flat_map(|&(source, ref messages)| {
messages.iter().map(move |msg| IncomingMessage {
source,
data: msg.0.clone(),
@@ -391,7 +390,7 @@ mod tests {
outgoing: Vec::new(),
};
- assert!(ext.post_message(MessageRef { target: 1, data: &[] }).is_ok());
- assert!(ext.post_message(MessageRef { target: 5, data: &[] }).is_err());
+ assert!(ext.post_message(MessageRef { target: 1.into(), data: &[] }).is_ok());
+ assert!(ext.post_message(MessageRef { target: 5.into(), data: &[] }).is_err());
}
}
diff --git a/polkadot/parachain/Cargo.toml b/polkadot/parachain/Cargo.toml
index aba3c106be..c60634d03b 100644
--- a/polkadot/parachain/Cargo.toml
+++ b/polkadot/parachain/Cargo.toml
@@ -9,6 +9,8 @@ parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
wasmi = { version = "0.4.3", optional = true }
error-chain = { version = "0.12", optional = true }
+serde = { version = "1.0", default-features = false }
+serde_derive = { version = "1.0", optional = true }
[dev-dependencies]
tiny-keccak = "1.4"
@@ -16,4 +18,4 @@ tiny-keccak = "1.4"
[features]
default = ["std"]
wasm-api = []
-std = ["parity-codec/std", "wasmi", "error-chain"]
+std = ["parity-codec/std", "wasmi", "error-chain", "serde_derive", "serde/std"]
diff --git a/polkadot/parachain/src/lib.rs b/polkadot/parachain/src/lib.rs
index 434b560c75..fe2c388ca9 100644
--- a/polkadot/parachain/src/lib.rs
+++ b/polkadot/parachain/src/lib.rs
@@ -62,6 +62,13 @@ extern crate wasmi;
#[macro_use]
extern crate error_chain;
+#[cfg(feature = "std")]
+extern crate serde;
+
+#[cfg(feature = "std")]
+#[macro_use]
+extern crate serde_derive;
+
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
@@ -93,12 +100,32 @@ pub struct ValidationResult {
pub head_data: Vec,
}
+/// Unique identifier of a parachain.
+#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+pub struct Id(u32);
+
+impl From for u32 {
+ fn from(x: Id) -> Self { x.0 }
+}
+
+impl From for Id {
+ fn from(x: u32) -> Self { Id(x) }
+}
+
+impl Id {
+ /// Convert this Id into its inner representation.
+ pub fn into_inner(self) -> u32 {
+ self.0
+ }
+}
+
/// An incoming message.
#[derive(PartialEq, Eq, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Encode))]
pub struct IncomingMessage {
/// The source parachain.
- pub source: u32,
+ pub source: Id,
/// The data of the message.
pub data: Vec,
}
@@ -106,8 +133,7 @@ pub struct IncomingMessage {
/// A reference to a message.
pub struct MessageRef<'a> {
/// The target parachain.
- pub target: u32,
+ pub target: Id,
/// Underlying data of the message.
pub data: &'a [u8],
}
-
diff --git a/polkadot/parachain/src/wasm_api.rs b/polkadot/parachain/src/wasm_api.rs
index 8cda5c3da6..0f11259b7b 100644
--- a/polkadot/parachain/src/wasm_api.rs
+++ b/polkadot/parachain/src/wasm_api.rs
@@ -59,5 +59,5 @@ pub fn post_message(message: MessageRef) {
let data_ptr = message.data.as_ptr();
let data_len = message.data.len();
- unsafe { ll::ext_post_message(message.target, data_ptr, data_len as u32) }
+ unsafe { ll::ext_post_message(message.target.into_inner(), data_ptr, data_len as u32) }
}
diff --git a/polkadot/parachain/src/wasm_executor.rs b/polkadot/parachain/src/wasm_executor.rs
index 402fd936e5..cde5df04d5 100644
--- a/polkadot/parachain/src/wasm_executor.rs
+++ b/polkadot/parachain/src/wasm_executor.rs
@@ -162,7 +162,7 @@ impl<'a, E: 'a + Externalities> ValidationExternals<'a, E> {
Err(Trap::new(wasmi::TrapKind::MemoryAccessOutOfBounds))
} else {
let res = self.externalities.post_message(MessageRef {
- target,
+ target: target.into(),
data: &mem[data_ptr..][..data_len],
});
diff --git a/polkadot/parachain/tests/adder.rs b/polkadot/parachain/tests/adder.rs
index c03cc98579..ac36f5c96d 100644
--- a/polkadot/parachain/tests/adder.rs
+++ b/polkadot/parachain/tests/adder.rs
@@ -185,9 +185,9 @@ fn processes_messages() {
parent_head: parent_head.encode(),
block_data: block_data.encode(),
ingress: vec![
- IncomingMessage { source: 1, data: (AddMessage { amount: 256 }).encode() },
- IncomingMessage { source: 2, data: bad_message_data },
- IncomingMessage { source: 3, data: (AddMessage { amount: 256 }).encode() },
+ IncomingMessage { source: 1.into(), data: (AddMessage { amount: 256 }).encode() },
+ IncomingMessage { source: 2.into(), data: bad_message_data },
+ IncomingMessage { source: 3.into(), data: (AddMessage { amount: 256 }).encode() },
],
},
&mut DummyExt,
diff --git a/polkadot/parachain/tests/res/adder.wasm b/polkadot/parachain/tests/res/adder.wasm
index 387e336777..d7fc5ecf5e 100644
Binary files a/polkadot/parachain/tests/res/adder.wasm and b/polkadot/parachain/tests/res/adder.wasm differ
diff --git a/polkadot/primitives/Cargo.toml b/polkadot/primitives/Cargo.toml
index 144a911308..1f35359d6f 100644
--- a/polkadot/primitives/Cargo.toml
+++ b/polkadot/primitives/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Parity Technologies "]
[dependencies]
-serde = { version = "1.0", default-features = false }
+serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
@@ -13,6 +13,7 @@ substrate-client = { git = "https://github.com/paritytech/substrate", default-fe
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
+polkadot-parachain = { path = "../parachain", default-features = false }
[dev-dependencies]
substrate-serializer = { git = "https://github.com/paritytech/substrate" }
@@ -29,5 +30,6 @@ std = [
"sr-version/std",
"sr-primitives/std",
"serde_derive",
- "serde/std",
+ "serde",
+ "polkadot-parachain/std",
]
diff --git a/polkadot/primitives/src/lib.rs b/polkadot/primitives/src/lib.rs
index 5df7d0de89..3978567868 100644
--- a/polkadot/primitives/src/lib.rs
+++ b/polkadot/primitives/src/lib.rs
@@ -26,6 +26,7 @@ extern crate substrate_primitives as primitives;
extern crate sr_primitives as runtime_primitives;
extern crate sr_std as rstd;
extern crate sr_version;
+extern crate polkadot_parachain;
#[cfg(test)]
extern crate substrate_serializer;
diff --git a/polkadot/primitives/src/parachain.rs b/polkadot/primitives/src/parachain.rs
index d5a3b77a64..84d6b3a26a 100644
--- a/polkadot/primitives/src/parachain.rs
+++ b/polkadot/primitives/src/parachain.rs
@@ -25,29 +25,11 @@ use {AccountId};
#[cfg(feature = "std")]
use primitives::bytes;
+pub use polkadot_parachain::Id;
+
/// Signature on candidate's block data by a collator.
pub type CandidateSignature = ::runtime_primitives::Ed25519Signature;
-/// Unique identifier of a parachain.
-#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Encode, Decode)]
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
-pub struct Id(u32);
-
-impl From for u32 {
- fn from(x: Id) -> Self { x.0 }
-}
-
-impl From for Id {
- fn from(x: u32) -> Self { Id(x) }
-}
-
-impl Id {
- /// Convert this Id into its inner representation.
- pub fn into_inner(self) -> u32 {
- self.0
- }
-}
-
/// Identifier for a chain, either one of a number of parachains or the relay chain.
#[derive(Copy, Clone, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
diff --git a/polkadot/runtime/wasm/Cargo.lock b/polkadot/runtime/wasm/Cargo.lock
index 1c6622bde5..d7c686f418 100644
--- a/polkadot/runtime/wasm/Cargo.lock
+++ b/polkadot/runtime/wasm/Cargo.lock
@@ -806,12 +806,25 @@ name = "pkg-config"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "polkadot-parachain"
+version = "0.1.0"
+dependencies = [
+ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "polkadot-primitives"
version = "0.1.0"
dependencies = [
"parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "polkadot-parachain 0.1.0",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)",
diff --git a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm
index 264f40f644..4b771e04a1 100644
Binary files a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm and b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm differ
diff --git a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm
index 9b01386249..53a43eb475 100755
Binary files a/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm and b/polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm differ