diff --git a/polkadot/api/src/full.rs b/polkadot/api/src/full.rs index 68c79819e5..101f59f5a7 100644 --- a/polkadot/api/src/full.rs +++ b/polkadot/api/src/full.rs @@ -17,20 +17,20 @@ //! Strongly typed API for full Polkadot client. use client::backend::{Backend, LocalBackend}; -use client::{self, Client, LocalCallExecutor}; +use client::block_builder::BlockBuilder as ClientBlockBuilder; +use client::{Client, LocalCallExecutor}; use polkadot_executor::Executor as LocalDispatch; use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; -use state_machine::{self, OverlayedChanges}; +use state_machine; -use primitives::{AccountId, BlockId, Hash, Index, SessionKey, Timestamp}; -use primitives::parachain::{DutyRoster, CandidateReceipt, Id as ParaId}; -use runtime::{self, Block, Header, UncheckedExtrinsic, Extrinsic, Call, TimestampCall, ParachainsCall}; +use primitives::{AccountId, Block, Header, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic}; +use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId}; use {CheckedBlockId, BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Error, Result}; /// A checked block ID used for the substrate-client implementation of CheckedBlockId; #[derive(Debug, Clone, Copy)] -pub struct CheckedId(pub BlockId); +pub struct CheckedId(pub(crate) BlockId); impl CheckedBlockId for CheckedId { fn block_id(&self) -> &BlockId { @@ -44,14 +44,16 @@ macro_rules! with_runtime { ($client: ident, $at: expr, $exec: expr) => {{ let parent = $at.block_id(); let header = Header { - parent_hash: $client.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?, - number: $client.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1, + parent_hash: $client.block_hash_from_id(&parent)? + .ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))?, + number: $client.block_number_from_id(&parent)? + .ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))? + 1, state_root: Default::default(), extrinsics_root: Default::default(), digest: Default::default(), }; - $client.state_at(parent).map_err(Error::from).and_then(|state| { + $client.state_at(&parent).map_err(Error::from).and_then(|state| { let mut changes = Default::default(); let mut ext = state_machine::Ext::new(&mut changes, &state); @@ -63,105 +65,28 @@ macro_rules! with_runtime { }} } -/// A polkadot block builder. -#[derive(Debug, Clone)] -pub struct ClientBlockBuilder { - parent: BlockId, - changes: OverlayedChanges, - state: S, - header: Header, - timestamp: Timestamp, - extrinsics: Vec, -} - -impl ClientBlockBuilder - where S::Error: Into -{ - // initialises a block, ready to allow extrinsics to be applied. - fn initialise_block(&mut self) -> Result<()> { - let result = { - let mut ext = state_machine::Ext::new(&mut self.changes, &self.state); - let h = self.header.clone(); - - ::substrate_executor::with_native_environment( - &mut ext, - || runtime::Executive::initialise_block(&h), - ).map_err(Into::into) - }; - - match result { - Ok(_) => { - self.changes.commit_prospective(); - Ok(()) - } - Err(e) => { - self.changes.discard_prospective(); - Err(e) - } - } - } - - // executes a extrinsic, inherent or otherwise, without appending to the list. - fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> { - let result = { - let mut ext = state_machine::Ext::new(&mut self.changes, &self.state); - - ::substrate_executor::with_native_environment( - &mut ext, - move || runtime::Executive::apply_extrinsic(extrinsic), - ).map_err(Into::into) - }; - - match result { - Ok(_) => { - self.changes.commit_prospective(); - Ok(()) - } - Err(e) => { - self.changes.discard_prospective(); - Err(e) - } - } - } -} - -impl BlockBuilder for ClientBlockBuilder - where S::Error: Into +impl> BlockBuilder for ClientBlockBuilder>, Block> + where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> { - // Check that this is not an "inherent" extrinsic. - if extrinsic.signature == Default::default() { - bail!(ErrorKind::PushedInherentTransaction(extrinsic)); - } else { - self.apply_extrinsic(extrinsic.clone())?; - self.extrinsics.push(extrinsic); - Ok(()) - } + self.push(extrinsic).map_err(Into::into) } - fn bake(mut self) -> Block { - let mut ext = state_machine::Ext::new(&mut self.changes, &self.state); - - let final_header = ::substrate_executor::with_native_environment( - &mut ext, - move || runtime::Executive::finalise_block() - ).expect("all inherent extrinsics pushed; all other extrinsics executed correctly; qed"); - Block { - header: final_header, - extrinsics: self.extrinsics, - } + /// Bake the block with provided extrinsics. + fn bake(self) -> Result { + ClientBlockBuilder::bake(self).map_err(Into::into) } } -impl PolkadotApi for Client>> - where ::client::error::Error: From<<::State as state_machine::backend::Backend>::Error> +impl> PolkadotApi for Client>, Block> + where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { type CheckedBlockId = CheckedId; - type BlockBuilder = ClientBlockBuilder; + type BlockBuilder = ClientBlockBuilder>, Block>; fn check_id(&self, id: BlockId) -> Result { // bail if the code is not the same as the natively linked. - if self.code_at(&id)? != LocalDispatch::native_equivalent() { + if self.code_at(&id.into())? != LocalDispatch::native_equivalent() { bail!("This node is out of date. Block authoring may not work correctly. Bailing.") } @@ -190,8 +115,16 @@ impl PolkadotApi for Client Result { use substrate_executor::error::ErrorKind as ExecErrorKind; + use codec::Slicable; + use runtime::Block as RuntimeBlock; - let res = with_runtime!(self, at, || ::runtime::Executive::execute_block(block)); + let encoded = block.encode(); + let runtime_block = match RuntimeBlock::decode(&mut &encoded[..]) { + Some(x) => x, + None => return Ok(false), + }; + + let res = with_runtime!(self, at, || ::runtime::Executive::execute_block(runtime_block)); match res { Ok(()) => Ok(true), Err(err) => match err.kind() { @@ -217,85 +150,65 @@ impl PolkadotApi for Client) -> Result { - let parent = parent.block_id(); - let header = Header { - parent_hash: self.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?, - number: self.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1, - state_root: Default::default(), - extrinsics_root: Default::default(), - digest: Default::default(), - }; - - let extrinsics = vec![ - UncheckedExtrinsic { - extrinsic: Extrinsic { - signed: Default::default(), - index: Default::default(), - function: Call::Timestamp(TimestampCall::set(timestamp)), - }, - signature: Default::default(), - }, - UncheckedExtrinsic { - extrinsic: Extrinsic { - signed: Default::default(), - index: Default::default(), - function: Call::Parachains(ParachainsCall::set_heads(parachains)), - }, - signature: Default::default(), - } - ]; - - let mut builder = ClientBlockBuilder { - parent: *parent, - changes: OverlayedChanges::default(), - state: self.state_at(parent)?, - header, - timestamp, - extrinsics: extrinsics.clone(), - }; - - builder.initialise_block()?; - - for inherent in extrinsics { - builder.apply_extrinsic(inherent)?; + fn build_block(&self, at: &CheckedId, timestamp: Timestamp, new_heads: Vec) -> Result { + let mut block_builder = self.new_block_at(at.block_id())?; + for inherent in self.inherent_extrinsics(at, timestamp, new_heads)? { + block_builder.push(inherent)?; } - Ok(builder) + Ok(block_builder) + } + + fn inherent_extrinsics(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec) -> Result> { + use codec::Slicable; + + with_runtime!(self, at, || { + let extrinsics = ::runtime::inherent_extrinsics(timestamp, new_heads); + extrinsics.into_iter() + .map(|x| x.encode()) // get encoded representation + .map(|x| Slicable::decode(&mut &x[..])) // get byte-vec equivalent to extrinsic + .map(|x| x.expect("UncheckedExtrinsic has encoded representation equivalent to Vec; qed")) + .collect() + }) } } -impl LocalPolkadotApi for Client>> - where ::client::error::Error: From<<::State as state_machine::backend::Backend>::Error> +impl> LocalPolkadotApi for Client>, Block> + where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> {} #[cfg(test)] mod tests { use super::*; use keyring::Keyring; - use codec::Slicable; use client::{self, LocalCallExecutor}; use client::in_mem::Backend as InMemory; use substrate_executor::NativeExecutionDispatch; - use substrate_primitives::{self, Header}; use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildExternalities}; fn validators() -> Vec { + vec![ + Keyring::One.to_raw_public().into(), + Keyring::Two.to_raw_public().into(), + ] + } + + fn session_keys() -> Vec { vec![ Keyring::One.to_raw_public(), Keyring::Two.to_raw_public(), ] } - fn client() -> Client>> { + fn client() -> Client, LocalCallExecutor, NativeExecutor>, Block> { struct GenesisBuilder; - impl client::GenesisBuilder for GenesisBuilder { + impl client::GenesisBuilder for GenesisBuilder { fn build(self) -> (Header, Vec<(Vec, Vec)>) { let genesis_config = GenesisConfig { consensus: Some(ConsensusConfig { code: LocalDispatch::native_equivalent().to_vec(), - authorities: validators(), + authorities: session_keys(), }), system: None, session: Some(SessionConfig { @@ -309,8 +222,8 @@ mod tests { }; let storage = genesis_config.build_externalities(); - let block = ::client::genesis::construct_genesis_block(&storage); - (substrate_primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect()) + let block = ::client::genesis::construct_genesis_block::(&storage); + (block.header, storage.into_iter().collect()) } } @@ -320,18 +233,36 @@ mod tests { #[test] fn gets_session_and_validator_keys() { let client = client(); - let id = client.check_id(BlockId::Number(0)).unwrap(); - assert_eq!(client.session_keys(&id).unwrap(), validators()); + let id = client.check_id(BlockId::number(0)).unwrap(); + assert_eq!(client.session_keys(&id).unwrap(), session_keys()); assert_eq!(client.validators(&id).unwrap(), validators()); } #[test] - fn build_block() { + fn build_block_implicit_succeeds() { let client = client(); - let id = client.check_id(BlockId::Number(0)).unwrap(); + let id = client.check_id(BlockId::number(0)).unwrap(); let block_builder = client.build_block(&id, 1_000_000, Vec::new()).unwrap(); - let block = block_builder.bake(); + let block = block_builder.bake().unwrap(); + + assert_eq!(block.header.number, 1); + assert!(block.header.extrinsics_root != Default::default()); + } + + #[test] + fn build_block_with_inherent_succeeds() { + let client = client(); + + let id = client.check_id(BlockId::number(0)).unwrap(); + let inherent = client.inherent_extrinsics(&id, 1_000_000, Vec::new()).unwrap(); + + let mut block_builder = client.new_block_at(id.block_id()).unwrap(); + for extrinsic in inherent { + block_builder.push(extrinsic).unwrap(); + } + + let block = block_builder.bake().unwrap(); assert_eq!(block.header.number, 1); assert!(block.header.extrinsics_root != Default::default()); @@ -339,14 +270,14 @@ mod tests { #[test] fn fails_to_check_id_for_unknown_block() { - assert!(client().check_id(BlockId::Number(100)).is_err()); + assert!(client().check_id(BlockId::number(100)).is_err()); } #[test] fn gets_random_seed_with_genesis() { let client = client(); - let id = client.check_id(BlockId::Number(0)).unwrap(); + let id = client.check_id(BlockId::number(0)).unwrap(); assert!(client.random_seed(&id).is_ok()); } } diff --git a/polkadot/api/src/lib.rs b/polkadot/api/src/lib.rs index bef92d4d9f..c92f568f7b 100644 --- a/polkadot/api/src/lib.rs +++ b/polkadot/api/src/lib.rs @@ -18,8 +18,8 @@ //! runtime. extern crate polkadot_executor; -extern crate polkadot_runtime as runtime; extern crate polkadot_primitives as primitives; +extern crate polkadot_runtime as runtime; extern crate substrate_codec as codec; extern crate substrate_runtime_io as runtime_io; extern crate substrate_client as client; @@ -37,9 +37,8 @@ extern crate substrate_keyring as keyring; pub mod full; pub mod light; -use primitives::{AccountId, BlockId, Hash, Index, SessionKey, Timestamp}; -use primitives::parachain::{DutyRoster, CandidateReceipt, Id as ParaId}; -use runtime::{Block, UncheckedExtrinsic}; +use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic}; +use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId}; error_chain! { errors { @@ -49,19 +48,9 @@ error_chain! { display("Unknown runtime code") } /// Unknown block ID. - UnknownBlock(b: BlockId) { + UnknownBlock(b: String) { description("Unknown block") - display("Unknown block") - } - /// Attempted to push an inherent extrinsic manually. - PushedInherentTransaction(xt: UncheckedExtrinsic) { - description("Attempted to push an inherent extrinsic to a block."), - display("Pushed inherent extrinsic to a block: {:?}", xt), - } - /// Badly-formed extrinsic. - BadlyFormedTransaction(xt: UncheckedExtrinsic) { - description("Attempted to push a badly-formed extrinsic to a block."), - display("Pushed badly-formed extrinsic to a block: {:?}", xt), + display("Unknown block {}", b) } /// Some other error. // TODO: allow to be specified as associated type of PolkadotApi @@ -85,28 +74,28 @@ impl From for Error { } } -/// A builder for blocks. -pub trait BlockBuilder: Sized { - /// Push a non-inherent extrinsic. - fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()>; - - /// Finalise the block. - fn bake(self) -> Block; -} - /// A checked block identifier. pub trait CheckedBlockId: Clone + 'static { /// Yield the underlying block ID. fn block_id(&self) -> &BlockId; } +/// Build new blocks. +pub trait BlockBuilder { + /// Push an extrinsic onto the block. Fails if the extrinsic is invalid. + fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()>; + + /// Bake the block with provided extrinsics. + fn bake(self) -> Result; +} + /// Trait encapsulating the Polkadot API. /// /// All calls should fail when the exact runtime is unknown. pub trait PolkadotApi { /// A checked block ID. Used to avoid redundancy of code check. type CheckedBlockId: CheckedBlockId; - /// The type used to build blocks. + /// The block builder for this API type. type BlockBuilder: BlockBuilder; /// Check whether requests at the given block ID can be served. @@ -146,8 +135,12 @@ pub trait PolkadotApi { /// and an error if we can't evaluate for some reason. fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result; - /// Create a block builder on top of the parent block. - fn build_block(&self, parent: &Self::CheckedBlockId, timestamp: Timestamp, parachains: Vec) -> Result; + /// Build a block on top of the given, with inherent extrinsics pre-pushed. + fn build_block(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec) -> Result; + + /// Attempt to produce the (encoded) inherent extrinsics for a block being built upon the given. + /// This may vary by runtime and will fail if a runtime doesn't follow the same API. + fn inherent_extrinsics(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec) -> Result>; } /// Mark for all Polkadot API implementations, that are making use of state data, stored locally. diff --git a/polkadot/api/src/light.rs b/polkadot/api/src/light.rs index 6038a8ec1f..560c186699 100644 --- a/polkadot/api/src/light.rs +++ b/polkadot/api/src/light.rs @@ -21,20 +21,30 @@ use client::backend::{Backend, RemoteBackend}; use client::{Client, CallExecutor}; use codec::Slicable; use state_machine; -use primitives::{AccountId, BlockId, Hash, Index, SessionKey, Timestamp}; -use primitives::parachain::{DutyRoster, CandidateReceipt, Id as ParaId}; -use runtime::{Block, UncheckedExtrinsic}; +use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic}; +use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId}; use full::CheckedId; -use {PolkadotApi, RemotePolkadotApi, BlockBuilder, CheckedBlockId, Result, ErrorKind}; +use {PolkadotApi, BlockBuilder, RemotePolkadotApi, CheckedBlockId, Result, ErrorKind}; -/// Remote polkadot API implementation. -pub struct RemotePolkadotApiWrapper(pub Arc>); - -/// Block builder for light client. +/// Light block builder. TODO: make this work (efficiently) +#[derive(Clone, Copy)] pub struct LightBlockBuilder; -impl PolkadotApi for RemotePolkadotApiWrapper - where ::client::error::Error: From<<::State as state_machine::backend::Backend>::Error> +impl BlockBuilder for LightBlockBuilder { + fn push_extrinsic(&mut self, _xt: UncheckedExtrinsic) -> Result<()> { + Err(ErrorKind::UnknownRuntime.into()) + } + + fn bake(self) -> Result { + Err(ErrorKind::UnknownRuntime.into()) + } +} + +/// Remote polkadot API implementation. +pub struct RemotePolkadotApiWrapper, E: CallExecutor>(pub Arc>); + +impl, E: CallExecutor> PolkadotApi for RemotePolkadotApiWrapper + where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { type CheckedBlockId = CheckedId; type BlockBuilder = LightBlockBuilder; @@ -86,21 +96,15 @@ impl PolkadotApi for RemotePolkadotApiWrapper Err(ErrorKind::UnknownRuntime.into()) } - fn build_block(&self, _parent: &CheckedId, _timestamp: Timestamp, _parachains: Vec) -> Result { + fn build_block(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result { + Err(ErrorKind::UnknownRuntime.into()) + } + + fn inherent_extrinsics(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result>> { Err(ErrorKind::UnknownRuntime.into()) } } -impl RemotePolkadotApi for RemotePolkadotApiWrapper - where ::client::error::Error: From<<::State as state_machine::backend::Backend>::Error> +impl, E: CallExecutor> RemotePolkadotApi for RemotePolkadotApiWrapper + where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> {} - -impl BlockBuilder for LightBlockBuilder { - fn push_extrinsic(&mut self, _extrinsic: UncheckedExtrinsic) -> Result<()> { - Err(ErrorKind::UnknownRuntime.into()) - } - - fn bake(self) -> Block { - unimplemented!() - } -} diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index f80b3b1d9f..8cc19b0f66 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -24,16 +24,10 @@ ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } fdlimit = "0.1" parking_lot = "0.4" substrate-client = { path = "../../substrate/client" } -substrate-network = { path = "../../substrate/network" } -substrate-codec = { path = "../../substrate/codec" } -substrate-runtime-support = { path = "../../substrate/runtime-support" } substrate-state-machine = { path = "../../substrate/state-machine" } -substrate-executor = { path = "../../substrate/executor" } -substrate-primitives = { path = "../../substrate/primitives" } substrate-rpc = { path = "../../substrate/rpc" } substrate-rpc-servers = { path = "../../substrate/rpc-servers" } +substrate-network = { path = "../../substrate/network" } polkadot-primitives = { path = "../primitives" } -polkadot-executor = { path = "../executor" } -polkadot-runtime = { path = "../runtime" } polkadot-service = { path = "../service" } polkadot-transaction-pool = { path = "../transaction-pool" } diff --git a/polkadot/cli/src/informant.rs b/polkadot/cli/src/informant.rs index 54affa839e..c5bbe0c2a2 100644 --- a/polkadot/cli/src/informant.rs +++ b/polkadot/cli/src/informant.rs @@ -21,8 +21,7 @@ use futures::stream::Stream; use service::Service; use tokio_core::reactor; use network::{SyncState, SyncProvider}; -use runtime_support::Hashable; -use primitives::block::HeaderHash; +use polkadot_primitives::Block; use state_machine; use client::{self, BlockchainEvents}; @@ -31,9 +30,9 @@ const TIMER_INTERVAL_MS: u64 = 5000; /// Spawn informant on the event loop pub fn start(service: &Service, handle: reactor::Handle) where - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, - client::error::Error: From<<::State as state_machine::backend::Backend>::Error> + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, + client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { let interval = reactor::Interval::new_at(Instant::now(), Duration::from_millis(TIMER_INTERVAL_MS), &handle) .expect("Error creating informant timer"); @@ -45,7 +44,7 @@ pub fn start(service: &Service, handle: reactor::Handle) let sync_status = network.status(); if let Ok(best_block) = client.best_block_header() { - let hash: HeaderHash = best_block.blake2_256().into(); + let hash = best_block.hash(); let status = match (sync_status.sync.state, sync_status.sync.best_seen_block) { (SyncState::Idle, _) => "Idle".into(), (SyncState::Downloading, None) => "Syncing".into(), diff --git a/polkadot/cli/src/lib.rs b/polkadot/cli/src/lib.rs index f734b154cd..0d56f0d11e 100644 --- a/polkadot/cli/src/lib.rs +++ b/polkadot/cli/src/lib.rs @@ -32,17 +32,12 @@ extern crate ed25519; extern crate triehash; extern crate parking_lot; -extern crate substrate_codec as codec; extern crate substrate_state_machine as state_machine; extern crate substrate_client as client; -extern crate substrate_primitives as primitives; extern crate substrate_network as network; extern crate substrate_rpc; extern crate substrate_rpc_servers as rpc; -extern crate substrate_runtime_support as runtime_support; extern crate polkadot_primitives; -extern crate polkadot_executor; -extern crate polkadot_runtime; extern crate polkadot_service as service; extern crate polkadot_transaction_pool as txpool; @@ -61,6 +56,7 @@ mod informant; use std::io; use std::net::SocketAddr; use std::path::{Path, PathBuf}; +use polkadot_primitives::Block; use futures::sync::mpsc; use futures::{Sink, Future, Stream}; @@ -188,9 +184,9 @@ pub fn run(args: I) -> error::Result<()> where fn run_until_exit(mut core: reactor::Core, service: service::Service, matches: &clap::ArgMatches, config: service::Configuration) -> error::Result<()> where - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, - client::error::Error: From<<::State as state_machine::backend::Backend>::Error> + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, + client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { let exit = { // can't use signal directly here because CtrlC takes only `Fn`. @@ -210,7 +206,7 @@ fn run_until_exit(mut core: reactor::Core, service: service::Service let handler = || { let chain = rpc::apis::chain::Chain::new(service.client(), core.remote()); - rpc::rpc_handler( + rpc::rpc_handler::( service.client(), chain, service.transaction_pool(), diff --git a/polkadot/collator/Cargo.toml b/polkadot/collator/Cargo.toml index 42fc14c666..161121eefa 100644 --- a/polkadot/collator/Cargo.toml +++ b/polkadot/collator/Cargo.toml @@ -8,5 +8,6 @@ description = "Abstract collation logic" futures = "0.1.17" substrate-codec = { path = "../../substrate/codec", version = "0.1" } substrate-primitives = { path = "../../substrate/primitives", version = "0.1" } -polkadot-primitives = { path = "../primitives", version = "0.1" } +polkadot-runtime = { path = "../runtime", version = "0.1" } polkadot-parachain = { path = "../parachain", version = "0.1" } +polkadot-primitives = { path = "../primitives", version = "0.1" } diff --git a/polkadot/collator/src/lib.rs b/polkadot/collator/src/lib.rs index 967a8e6de6..55eca734d2 100644 --- a/polkadot/collator/src/lib.rs +++ b/polkadot/collator/src/lib.rs @@ -47,12 +47,13 @@ extern crate futures; extern crate substrate_codec as codec; extern crate substrate_primitives as primitives; +extern crate polkadot_runtime; extern crate polkadot_primitives; use std::collections::{BTreeSet, BTreeMap}; use futures::{stream, Stream, Future, IntoFuture}; -use polkadot_primitives::parachain::{self, ConsolidatedIngress, Message, Id as ParaId}; +use polkadot_primitives::parachain::{self, CandidateSignature, ConsolidatedIngress, Message, Id as ParaId}; /// Parachain context needed for collation. /// @@ -62,7 +63,7 @@ pub trait ParachainContext { fn produce_candidate>( &self, ingress: I, - ) -> (parachain::BlockData, polkadot_primitives::AccountId, polkadot_primitives::Signature); + ) -> (parachain::BlockData, polkadot_primitives::AccountId, CandidateSignature); } /// Relay chain context needed to collate. diff --git a/polkadot/consensus/Cargo.toml b/polkadot/consensus/Cargo.toml index 5be758a91b..9941a21b33 100644 --- a/polkadot/consensus/Cargo.toml +++ b/polkadot/consensus/Cargo.toml @@ -25,3 +25,4 @@ substrate-runtime-support = { path = "../../substrate/runtime-support" } substrate-network = { path = "../../substrate/network" } substrate-keyring = { path = "../../substrate/keyring" } substrate-client = { path = "../../substrate/client" } +substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" } diff --git a/polkadot/consensus/src/error.rs b/polkadot/consensus/src/error.rs index ebc998ab69..acafa88f5e 100644 --- a/polkadot/consensus/src/error.rs +++ b/polkadot/consensus/src/error.rs @@ -16,7 +16,7 @@ //! Errors that can occur during the consensus process. -use polkadot_primitives::AccountId; +use primitives::AuthorityId; error_chain! { links { @@ -29,7 +29,7 @@ error_chain! { description("Duty Roster had invalid length"), display("Invalid duty roster length: expected {}, got {}", expected, got), } - NotValidator(id: AccountId) { + NotValidator(id: AuthorityId) { description("Local account ID not a validator at this block."), display("Local account ID ({:?}) not a validator at this block.", id), } diff --git a/polkadot/consensus/src/evaluation.rs b/polkadot/consensus/src/evaluation.rs index b5ef81d244..c7c4fe2c25 100644 --- a/polkadot/consensus/src/evaluation.rs +++ b/polkadot/consensus/src/evaluation.rs @@ -19,11 +19,9 @@ use super::MAX_TRANSACTIONS_SIZE; use codec::Slicable; -use polkadot_runtime::Block as PolkadotGenericBlock; -use polkadot_primitives::Timestamp; +use polkadot_runtime::{Block as PolkadotGenericBlock, CheckedBlock}; +use polkadot_primitives::{Block, Hash, BlockNumber, Timestamp}; use polkadot_primitives::parachain::Id as ParaId; -use primitives::block::{Block as SubstrateBlock, HeaderHash, Number as BlockNumber}; -use transaction_pool::PolkadotBlock; error_chain! { links { @@ -51,7 +49,7 @@ error_chain! { description("Proposal included unregistered parachain."), display("Proposal included unregistered parachain {:?}", id), } - WrongParentHash(expected: HeaderHash, got: HeaderHash) { + WrongParentHash(expected: Hash, got: Hash) { description("Proposal had wrong parent hash."), display("Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got), } @@ -72,17 +70,17 @@ error_chain! { /// Attempt to evaluate a substrate block as a polkadot block, returning error /// upon any initial validity checks failing. pub fn evaluate_initial( - proposal: &SubstrateBlock, + proposal: &Block, now: Timestamp, - parent_hash: &HeaderHash, + parent_hash: &Hash, parent_number: BlockNumber, active_parachains: &[ParaId], -) -> Result { +) -> Result { const MAX_TIMESTAMP_DRIFT: Timestamp = 60; let encoded = Slicable::encode(proposal); let proposal = PolkadotGenericBlock::decode(&mut &encoded[..]) - .and_then(|b| PolkadotBlock::from(b).ok()) + .and_then(|b| CheckedBlock::new(b).ok()) .ok_or_else(|| ErrorKind::ProposalNotForPolkadot)?; let transactions_size = proposal.extrinsics.iter().fold(0, |a, tx| { diff --git a/polkadot/consensus/src/lib.rs b/polkadot/consensus/src/lib.rs index def896548e..2e23b256b2 100644 --- a/polkadot/consensus/src/lib.rs +++ b/polkadot/consensus/src/lib.rs @@ -35,14 +35,15 @@ extern crate polkadot_api; extern crate polkadot_collator as collator; extern crate polkadot_statement_table as table; extern crate polkadot_parachain as parachain; -extern crate polkadot_primitives; extern crate polkadot_transaction_pool as transaction_pool; extern crate polkadot_runtime; +extern crate polkadot_primitives; extern crate substrate_bft as bft; extern crate substrate_codec as codec; extern crate substrate_primitives as primitives; extern crate substrate_runtime_support as runtime_support; +extern crate substrate_runtime_primitives as runtime_primitives; extern crate substrate_network; extern crate exit_future; @@ -68,10 +69,9 @@ use std::time::{Duration, Instant}; use codec::Slicable; use table::generic::Statement as GenericStatement; use runtime_support::Hashable; -use polkadot_api::{PolkadotApi, BlockBuilder}; -use polkadot_primitives::{Hash, Timestamp}; -use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic, CandidateReceipt}; -use primitives::block::{Block as SubstrateBlock, Header as SubstrateHeader, HeaderHash, Id as BlockId, Number as BlockNumber}; +use polkadot_api::PolkadotApi; +use polkadot_primitives::{Hash, Block, BlockId, BlockNumber, Header, Timestamp}; +use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt}; use primitives::AuthorityId; use transaction_pool::{Ready, TransactionPool}; use tokio_core::reactor::{Handle, Timeout, Interval}; @@ -105,10 +105,10 @@ pub trait TableRouter: Clone { /// Future that resolves when candidate data is fetched. type FetchCandidate: IntoFuture; /// Future that resolves when extrinsic candidate data is fetched. - type FetchExtrinsic: IntoFuture; + type FetchExtrinsic: IntoFuture; /// Note local candidate data, making it available on the network to other validators. - fn local_candidate_data(&self, hash: Hash, block_data: BlockData, extrinsic: Extrinsic); + fn local_candidate_data(&self, hash: Hash, block_data: BlockData, extrinsic: ParachainExtrinsic); /// Fetch block data for a specific candidate. fn fetch_block_data(&self, candidate: &CandidateReceipt) -> Self::FetchCandidate; @@ -236,7 +236,7 @@ pub struct ProposerFactory { pub parachain_empty_duration: Duration, } -impl bft::ProposerFactory for ProposerFactory +impl bft::ProposerFactory for ProposerFactory where C: PolkadotApi, N: Network, @@ -245,14 +245,14 @@ impl bft::ProposerFactory for ProposerFactory type Proposer = Proposer; type Error = Error; - fn init(&self, parent_header: &SubstrateHeader, authorities: &[AuthorityId], sign_with: Arc) -> Result { + fn init(&self, parent_header: &Header, authorities: &[AuthorityId], sign_with: Arc) -> Result { use std::time::Duration; const DELAY_UNTIL: Duration = Duration::from_millis(5000); let parent_hash = parent_header.blake2_256().into(); - let checked_id = self.client.check_id(BlockId::Hash(parent_hash))?; + let checked_id = self.client.check_id(BlockId::hash(parent_hash))?; let duty_roster = self.client.duty_roster(&checked_id)?; let random_seed = self.client.random_seed(&checked_id)?; @@ -312,7 +312,7 @@ pub struct Proposer { handle: Handle, local_duty: LocalDuty, local_key: Arc, - parent_hash: HeaderHash, + parent_hash: Hash, parent_id: C::CheckedBlockId, parent_number: BlockNumber, random_seed: Hash, @@ -321,7 +321,7 @@ pub struct Proposer { transaction_pool: Arc, } -impl bft::Proposer for Proposer +impl bft::Proposer for Proposer where C: PolkadotApi, R: TableRouter, @@ -330,7 +330,7 @@ impl bft::Proposer for Proposer type Error = Error; type Create = future::Either< CreateProposal, - future::FutureResult, + future::FutureResult, >; type Evaluate = Box>; @@ -385,7 +385,7 @@ impl bft::Proposer for Proposer }) } - fn evaluate(&self, proposal: &SubstrateBlock) -> Self::Evaluate { + fn evaluate(&self, unchecked_proposal: &Block) -> Self::Evaluate { debug!(target: "bft", "evaluating block on top of parent ({}, {:?})", self.parent_number, self.parent_hash); let active_parachains = match self.client.active_parachains(&self.parent_id) { @@ -397,7 +397,7 @@ impl bft::Proposer for Proposer // do initial serialization and structural integrity checks. let maybe_proposal = evaluation::evaluate_initial( - proposal, + unchecked_proposal, current_timestamp, &self.parent_hash, self.parent_number, @@ -461,7 +461,10 @@ impl bft::Proposer for Proposer // evaluate whether the block is actually valid. // TODO: is it better to delay this until the delays are finished? - let evaluated = self.client.evaluate_block(&self.parent_id, proposal.into()).map_err(Into::into); + let evaluated = self.client + .evaluate_block(&self.parent_id, unchecked_proposal.clone()) + .map_err(Into::into); + let future = future::result(evaluated).and_then(move |good| { let end_result = future::ok(good); if good { @@ -489,13 +492,13 @@ impl bft::Proposer for Proposer proposer } - fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior)>) { + fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior)>) { use bft::generic::Misbehavior as GenericMisbehavior; - use primitives::bft::{MisbehaviorKind, MisbehaviorReport}; + use runtime_primitives::bft::{MisbehaviorKind, MisbehaviorReport}; + use runtime_primitives::MaybeUnsigned; use polkadot_runtime::{Call, Extrinsic, UncheckedExtrinsic, ConsensusCall}; - - let local_id = self.local_key.public().0; + let local_id = self.local_key.public().0.into(); let mut next_index = { let readiness_evaluator = Ready::create(self.parent_id.clone(), &*self.client); let cur_index = self.transaction_pool.cull_and_get_pending(readiness_evaluator, |pending| pending @@ -536,10 +539,11 @@ impl bft::Proposer for Proposer next_index += 1; - let signature = self.local_key.sign(&extrinsic.encode()).into(); + let signature = MaybeUnsigned(self.local_key.sign(&extrinsic.encode()).into()); let uxt = UncheckedExtrinsic { extrinsic, signature }; - self.transaction_pool.import_unchecked_extrinsic(uxt).expect("locally signed extrinsic is valid; qed"); + self.transaction_pool.import_unchecked_extrinsic(uxt) + .expect("locally signed extrinsic is valid; qed"); } } } @@ -603,7 +607,7 @@ impl ProposalTiming { /// Future which resolves upon the creation of a proposal. pub struct CreateProposal { - parent_hash: HeaderHash, + parent_hash: Hash, parent_number: BlockNumber, parent_id: C::CheckedBlockId, client: Arc, @@ -620,14 +624,13 @@ impl CreateProposal R: TableRouter, P: Collators, { - fn propose_with(&self, candidates: Vec) -> Result { + fn propose_with(&self, candidates: Vec) -> Result { + use polkadot_api::BlockBuilder; + use runtime_primitives::traits::{Hashing, BlakeTwo256}; + // TODO: handle case when current timestamp behind that in state. let timestamp = current_timestamp(); - let mut block_builder = self.client.build_block( - &self.parent_id, - timestamp, - candidates, - )?; + let mut block_builder = self.client.build_block(&self.parent_id, timestamp, candidates)?; { let readiness_evaluator = Ready::create(self.parent_id.clone(), &*self.client); @@ -643,7 +646,7 @@ impl CreateProposal if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break } - match block_builder.push_extrinsic(pending.as_transaction().clone()) { + match block_builder.push_extrinsic(pending.primitive_extrinsic()) { Ok(()) => { pending_size += pending.encoded_size(); } @@ -658,14 +661,14 @@ impl CreateProposal self.transaction_pool.remove(&unqueue_invalid, false); } - let polkadot_block = block_builder.bake(); + let polkadot_block = block_builder.bake()?; info!("Proposing block [number: {}; hash: {}; parent_hash: {}; extrinsics: [{}]]", polkadot_block.header.number, - Hash::from(polkadot_block.header.blake2_256()), + Hash::from(polkadot_block.header.hash()), polkadot_block.header.parent_hash, polkadot_block.extrinsics.iter() - .map(|xt| format!("{}", Hash::from(xt.blake2_256()))) + .map(|xt| format!("{}", BlakeTwo256::hash_of(xt))) .collect::>() .join(", ") ); @@ -693,10 +696,10 @@ impl Future for CreateProposal R: TableRouter, P: Collators, { - type Item = SubstrateBlock; + type Item = Block; type Error = Error; - fn poll(&mut self) -> Poll { + fn poll(&mut self) -> Poll { // 1. poll local collation future. match self.collation.poll() { Ok(Async::Ready((collation, extrinsic))) => { diff --git a/polkadot/consensus/src/service.rs b/polkadot/consensus/src/service.rs index dedab92135..f1ee7f49fe 100644 --- a/polkadot/consensus/src/service.rs +++ b/polkadot/consensus/src/service.rs @@ -29,10 +29,9 @@ use ed25519; use futures::prelude::*; use futures::{future, Canceled}; use polkadot_api::LocalPolkadotApi; -use polkadot_primitives::AccountId; +use polkadot_primitives::{BlockId, Block, Header, Hash, AccountId}; use polkadot_primitives::parachain::{Id as ParaId, BlockData, Extrinsic, CandidateReceipt}; -use primitives::{Hash, AuthorityId}; -use primitives::block::{Id as BlockId, HeaderHash, Header}; +use primitives::AuthorityId; use runtime_support::Hashable; use substrate_network as net; use tokio_core::reactor; @@ -45,19 +44,19 @@ const TIMER_DELAY_MS: u64 = 5000; const TIMER_INTERVAL_MS: u64 = 500; struct BftSink { - network: Arc, - parent_hash: HeaderHash, + network: Arc>, + parent_hash: Hash, _e: ::std::marker::PhantomData, } struct Messages { - network_stream: net::BftMessageStream, + network_stream: net::BftMessageStream, local_id: AuthorityId, authorities: Vec, } impl Stream for Messages { - type Item = bft::Communication; + type Item = bft::Communication; type Error = bft::Error; fn poll(&mut self) -> Poll, Self::Error> { @@ -81,10 +80,10 @@ impl Stream for Messages { } } -fn process_message(msg: net::LocalizedBftMessage, local_id: &AuthorityId, authorities: &[AuthorityId]) -> Result, bft::Error> { +fn process_message(msg: net::LocalizedBftMessage, local_id: &AuthorityId, authorities: &[AuthorityId]) -> Result>, bft::Error> { Ok(Some(match msg.message { - net::BftMessage::Consensus(c) => bft::generic::Communication::Consensus(match c { - net::SignedConsensusMessage::Propose(proposal) => bft::generic::LocalizedMessage::Propose({ + net::generic_message::BftMessage::Consensus(c) => bft::generic::Communication::Consensus(match c { + net::generic_message::SignedConsensusMessage::Propose(proposal) => bft::generic::LocalizedMessage::Propose({ if &proposal.sender == local_id { return Ok(None) } let proposal = bft::generic::LocalizedProposal { round_number: proposal.round_number as usize, @@ -105,7 +104,7 @@ fn process_message(msg: net::LocalizedBftMessage, local_id: &AuthorityId, author trace!(target: "bft", "importing proposal message for round {} from {}", proposal.round_number, Hash::from(proposal.sender)); proposal }), - net::SignedConsensusMessage::Vote(vote) => bft::generic::LocalizedMessage::Vote({ + net::generic_message::SignedConsensusMessage::Vote(vote) => bft::generic::LocalizedMessage::Vote({ if &vote.sender == local_id { return Ok(None) } let vote = bft::generic::LocalizedVote { sender: vote.sender, @@ -114,21 +113,21 @@ fn process_message(msg: net::LocalizedBftMessage, local_id: &AuthorityId, author signer: ed25519::Public(vote.sender), }, vote: match vote.vote { - net::ConsensusVote::Prepare(r, h) => bft::generic::Vote::Prepare(r as usize, h), - net::ConsensusVote::Commit(r, h) => bft::generic::Vote::Commit(r as usize, h), - net::ConsensusVote::AdvanceRound(r) => bft::generic::Vote::AdvanceRound(r as usize), + net::generic_message::ConsensusVote::Prepare(r, h) => bft::generic::Vote::Prepare(r as usize, h), + net::generic_message::ConsensusVote::Commit(r, h) => bft::generic::Vote::Commit(r as usize, h), + net::generic_message::ConsensusVote::AdvanceRound(r) => bft::generic::Vote::AdvanceRound(r as usize), } }; - bft::check_vote(authorities, &msg.parent_hash, &vote)?; + bft::check_vote::(authorities, &msg.parent_hash, &vote)?; trace!(target: "bft", "importing vote {:?} from {}", vote.vote, Hash::from(vote.sender)); vote }), }), - net::BftMessage::Auxiliary(a) => { - let justification = bft::UncheckedJustification::from(a); + net::generic_message::BftMessage::Auxiliary(a) => { + let justification = bft::UncheckedJustification::::from(a); // TODO: get proper error - let justification: Result<_, bft::Error> = bft::check_prepare_justification(authorities, msg.parent_hash, justification) + let justification: Result<_, bft::Error> = bft::check_prepare_justification::(authorities, msg.parent_hash, justification) .map_err(|_| bft::ErrorKind::InvalidJustification.into()); bft::generic::Communication::Auxiliary(justification?) }, @@ -136,15 +135,15 @@ fn process_message(msg: net::LocalizedBftMessage, local_id: &AuthorityId, author } impl Sink for BftSink { - type SinkItem = bft::Communication; + type SinkItem = bft::Communication; // TODO: replace this with the ! type when that's stabilized type SinkError = E; - fn start_send(&mut self, message: bft::Communication) -> ::futures::StartSend { - let network_message = net::LocalizedBftMessage { + fn start_send(&mut self, message: bft::Communication) -> ::futures::StartSend, E> { + let network_message = net::generic_message::LocalizedBftMessage { message: match message { - bft::generic::Communication::Consensus(c) => net::BftMessage::Consensus(match c { - bft::generic::LocalizedMessage::Propose(proposal) => net::SignedConsensusMessage::Propose(net::SignedConsensusProposal { + bft::generic::Communication::Consensus(c) => net::generic_message::BftMessage::Consensus(match c { + bft::generic::LocalizedMessage::Propose(proposal) => net::generic_message::SignedConsensusMessage::Propose(net::generic_message::SignedConsensusProposal { round_number: proposal.round_number as u32, proposal: proposal.proposal, digest: proposal.digest, @@ -152,17 +151,17 @@ impl Sink for BftSink { digest_signature: proposal.digest_signature.signature, full_signature: proposal.full_signature.signature, }), - bft::generic::LocalizedMessage::Vote(vote) => net::SignedConsensusMessage::Vote(net::SignedConsensusVote { + bft::generic::LocalizedMessage::Vote(vote) => net::generic_message::SignedConsensusMessage::Vote(net::generic_message::SignedConsensusVote { sender: vote.sender, signature: vote.signature.signature, vote: match vote.vote { - bft::generic::Vote::Prepare(r, h) => net::ConsensusVote::Prepare(r as u32, h), - bft::generic::Vote::Commit(r, h) => net::ConsensusVote::Commit(r as u32, h), - bft::generic::Vote::AdvanceRound(r) => net::ConsensusVote::AdvanceRound(r as u32), + bft::generic::Vote::Prepare(r, h) => net::generic_message::ConsensusVote::Prepare(r as u32, h), + bft::generic::Vote::Commit(r, h) => net::generic_message::ConsensusVote::Commit(r as u32, h), + bft::generic::Vote::AdvanceRound(r) => net::generic_message::ConsensusVote::AdvanceRound(r as u32), } }), }), - bft::generic::Communication::Auxiliary(justification) => net::BftMessage::Auxiliary(justification.uncheck().into()), + bft::generic::Communication::Auxiliary(justification) => net::generic_message::BftMessage::Auxiliary(justification.uncheck().into()), }, parent_hash: self.parent_hash, }; @@ -175,7 +174,7 @@ impl Sink for BftSink { } } -struct Network(Arc); +struct Network(Arc>); impl super::Network for Network { type TableRouter = Router; @@ -189,20 +188,20 @@ impl super::Network for Network { fn start_bft( header: &Header, handle: reactor::Handle, - client: &bft::Authorities, - network: Arc, - bft_service: &BftService, + client: &bft::Authorities, + network: Arc>, + bft_service: &BftService, ) where - F: bft::ProposerFactory + 'static, - C: bft::BlockImport + bft::Authorities + 'static, - ::Error: ::std::fmt::Debug, - ::Error: ::std::fmt::Display + Into, + F: bft::ProposerFactory + 'static, + C: bft::BlockImport + bft::Authorities + 'static, + >::Error: ::std::fmt::Debug, + >::Error: ::std::fmt::Display + Into, { - let parent_hash = header.blake2_256().into(); + let parent_hash = header.hash(); if bft_service.live_agreement().map_or(false, |h| h == parent_hash) { return; } - let authorities = match client.authorities(&BlockId::Hash(parent_hash)) { + let authorities = match client.authorities(&BlockId::hash(parent_hash)) { Ok(authorities) => authorities, Err(e) => { debug!("Error reading authorities: {:?}", e); @@ -235,14 +234,14 @@ impl Service { pub fn new( client: Arc, api: Arc, - network: Arc, + network: Arc>, transaction_pool: Arc, parachain_empty_duration: Duration, key: ed25519::Pair, ) -> Service where A: LocalPolkadotApi + Send + Sync + 'static, - C: BlockchainEvents + ChainHead + bft::BlockImport + bft::Authorities + Send + Sync + 'static, + C: BlockchainEvents + ChainHead + bft::BlockImport + bft::Authorities + Send + Sync + 'static, { let (signal, exit) = ::exit_future::signal(); let thread = thread::spawn(move || { @@ -346,36 +345,25 @@ impl ::collation::Collators for NoCollators { fn note_bad_collator(&self, _collator: AccountId) { } } -type FetchCandidateAdapter = future::Map) -> BlockData>; - #[derive(Clone)] struct Router { - network: Arc, -} - -impl Router { - fn fetch_candidate_adapter(data: Vec) -> BlockData { - BlockData(data) - } + network: Arc>, } impl TableRouter for Router { type Error = Canceled; - type FetchCandidate = FetchCandidateAdapter; + type FetchCandidate = future::Empty; type FetchExtrinsic = future::FutureResult; - fn local_candidate_data(&self, hash: Hash, block_data: BlockData, _extrinsic: Extrinsic) { - let data = block_data.0; - self.network.set_local_candidate(Some((hash, data))) + fn local_candidate_data(&self, _hash: Hash, _block_data: BlockData, _extrinsic: Extrinsic) { + // TODO } - fn fetch_block_data(&self, candidate: &CandidateReceipt) -> Self::FetchCandidate { - let hash = candidate.hash(); - self.network.fetch_candidate(&hash).map(Self::fetch_candidate_adapter) + fn fetch_block_data(&self, _candidate: &CandidateReceipt) -> Self::FetchCandidate { + future::empty() } fn fetch_extrinsic_data(&self, _candidate: &CandidateReceipt) -> Self::FetchExtrinsic { future::ok(Extrinsic) } } - diff --git a/polkadot/consensus/src/shared_table/mod.rs b/polkadot/consensus/src/shared_table/mod.rs index 23e936eefe..120fbb7fec 100644 --- a/polkadot/consensus/src/shared_table/mod.rs +++ b/polkadot/consensus/src/shared_table/mod.rs @@ -486,7 +486,7 @@ mod tests { let candidate = CandidateReceipt { parachain_index: para_id, - collator: [1; 32], + collator: [1; 32].into(), head_data: ::polkadot_primitives::parachain::HeadData(vec![1, 2, 3, 4]), balance_uploads: Vec::new(), egress_queue_roots: Vec::new(), @@ -536,7 +536,7 @@ mod tests { let candidate = CandidateReceipt { parachain_index: para_id, - collator: [1; 32], + collator: [1; 32].into(), head_data: ::polkadot_primitives::parachain::HeadData(vec![1, 2, 3, 4]), balance_uploads: Vec::new(), egress_queue_roots: Vec::new(), diff --git a/polkadot/executor/Cargo.toml b/polkadot/executor/Cargo.toml index cca94287b0..e7cfc5b772 100644 --- a/polkadot/executor/Cargo.toml +++ b/polkadot/executor/Cargo.toml @@ -5,17 +5,5 @@ authors = ["Parity Technologies "] description = "Polkadot node implementation in Rust." [dependencies] -hex-literal = "0.1" -triehash = { version = "0.1" } -ed25519 = { path = "../../substrate/ed25519" } -substrate-codec = { path = "../../substrate/codec" } -substrate-runtime-io = { path = "../../substrate/runtime-io" } -substrate-runtime-support = { path = "../../substrate/runtime-support" } -substrate-state-machine = { path = "../../substrate/state-machine" } substrate-executor = { path = "../../substrate/executor" } -substrate-primitives = { path = "../../substrate/primitives" } -polkadot-primitives = { path = "../primitives" } polkadot-runtime = { path = "../runtime" } - -[dev-dependencies] -substrate-keyring = { path = "../../substrate/keyring" } diff --git a/polkadot/executor/src/lib.rs b/polkadot/executor/src/lib.rs index e5e096418b..be44d8afba 100644 --- a/polkadot/executor/src/lib.rs +++ b/polkadot/executor/src/lib.rs @@ -19,12 +19,5 @@ extern crate polkadot_runtime; #[macro_use] extern crate substrate_executor; -extern crate substrate_codec as codec; -extern crate substrate_state_machine as state_machine; -extern crate substrate_runtime_io as runtime_io; -extern crate substrate_primitives as primitives; -extern crate polkadot_primitives as polkadot_primitives; -extern crate ed25519; -extern crate triehash; native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm")); diff --git a/polkadot/primitives/src/lib.rs b/polkadot/primitives/src/lib.rs index a140e6ccee..4deded2969 100644 --- a/polkadot/primitives/src/lib.rs +++ b/polkadot/primitives/src/lib.rs @@ -21,12 +21,6 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] -#[cfg(feature = "std")] -#[macro_use] -extern crate serde_derive; -#[cfg(feature = "std")] -extern crate serde; - extern crate substrate_runtime_std as rstd; extern crate substrate_primitives as primitives; extern crate substrate_runtime_primitives as runtime_primitives; @@ -35,27 +29,43 @@ extern crate substrate_serializer; extern crate substrate_codec as codec; +#[cfg(feature = "std")] +#[macro_use] +extern crate serde_derive; + +#[cfg(feature = "std")] +extern crate serde; + +#[cfg(feature = "std")] +use primitives::bytes; + +use rstd::prelude::*; +use runtime_primitives::traits::BlakeTwo256; +use runtime_primitives::generic; +use codec::{Input, Slicable}; + pub mod parachain; -/// Virtual account ID that represents the idea of a dispatch/statement being signed by everybody -/// (who matters). Essentially this means that a majority of validators have decided it is -/// "correct". -pub const EVERYBODY: AccountId = [255u8; 32]; +/// Block header type as expected by this runtime. +pub type Header = generic::Header; -/// Something that identifies a block. -pub use primitives::block::Id as BlockId; +/// Opaque, encoded, unchecked extrinsic. +pub type UncheckedExtrinsic = Vec; -/// The type of digest item. -pub use primitives::block::Log as Log; +/// A "future-proof" block type for Polkadot. This will be resilient to upgrades in transaction +/// format, because it doesn't attempt to decode extrinsics. +/// +/// Specialized code needs to link to (at least one version of) the runtime directly +/// in order to handle the extrinsics within. +pub type Block = generic::Block; /// An index to a block. /// 32-bits will allow for 136 years of blocks assuming 1 block per second. /// TODO: switch to u32 pub type BlockNumber = u64; -/// Alias to Ed25519 pubkey that identifies an account on the relay chain. This will almost -/// certainly continue to be the same as the substrate's `AuthorityId`. -pub type AccountId = primitives::AuthorityId; +/// Alias to Ed25519 pubkey that identifies an account on the relay chain. +pub type AccountId = primitives::hash::H256; /// The Ed25519 pub key of an session that belongs to an authority of the relay chain. This is /// exactly equivalent to what the substrate calls an "authority". @@ -64,14 +74,15 @@ pub type SessionKey = primitives::AuthorityId; /// Indentifier for a chain. 32-bit should be plenty. pub type ChainId = u32; -/// Index of a transaction in the relay chain. 32-bit should be plenty. -pub type Index = u32; - /// A hash of some data used by the relay chain. pub type Hash = primitives::H256; +/// Index of a transaction in the relay chain. 32-bit should be plenty. +pub type Index = u32; + /// Alias to 512-bit hash when used in the context of a signature on the relay chain. -pub type Signature = runtime_primitives::Ed25519Signature; +/// Equipped with logic for possibly "unsigned" messages. +pub type Signature = runtime_primitives::MaybeUnsigned; /// A timestamp: seconds since the unix epoch. pub type Timestamp = u64; @@ -84,3 +95,22 @@ pub type Timestamp = u64; /// 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; + +/// "generic" block ID for the future-proof block type. +// TODO: parameterize blockid only as necessary. +pub type BlockId = generic::BlockId; + +/// A log entry in the block. +#[derive(PartialEq, Eq, Clone, Default)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] +pub struct Log(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); + +impl Slicable for Log { + fn decode(input: &mut I) -> Option { + Vec::::decode(input).map(Log) + } + + fn using_encoded R>(&self, f: F) -> R { + self.0.using_encoded(f) + } +} diff --git a/polkadot/primitives/src/parachain.rs b/polkadot/primitives/src/parachain.rs index 3a87b1faa2..9f803810e4 100644 --- a/polkadot/primitives/src/parachain.rs +++ b/polkadot/primitives/src/parachain.rs @@ -14,19 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Parachain data types. +//! Polkadot parachain types. + +use codec::{Slicable, Input}; +use rstd::prelude::*; +use rstd::cmp::Ordering; +use super::Hash; #[cfg(feature = "std")] use primitives::bytes; -use primitives; -use codec::{Input, Slicable}; -use rstd::cmp::{PartialOrd, Ord, Ordering}; -use rstd::vec::Vec; -use ::Hash; + +/// 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)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct Id(u32); impl From for u32 { @@ -67,7 +70,6 @@ pub enum Chain { impl Slicable for Chain { fn decode(input: &mut I) -> Option { let disc = input.read_byte()?; - match disc { 0 => Some(Chain::Relay), 1 => Some(Chain::Parachain(Slicable::decode(input)?)), @@ -84,7 +86,6 @@ impl Slicable for Chain { id.using_encoded(|s| v.extend(s)); } } - v } @@ -128,7 +129,7 @@ impl Slicable for DutyRoster { /// Extrinsic data for a parachain. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "std", serde(deny_unknown_fields))] pub struct Extrinsic; @@ -137,14 +138,14 @@ pub struct Extrinsic; /// /// https://github.com/w3f/polkadot-spec/blob/master/spec.md#candidate-para-chain-block #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "std", serde(deny_unknown_fields))] pub struct Candidate { /// The ID of the parachain this is a proposal for. pub parachain_index: Id, /// Collator's signature - pub collator_signature: ::Signature, + pub collator_signature: CandidateSignature, /// Unprocessed ingress queue. /// /// Ordered by parachain ID and block number. @@ -155,20 +156,20 @@ pub struct Candidate { /// Candidate receipt type. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Debug, Serialize))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[cfg_attr(feature = "std", serde(deny_unknown_fields))] pub struct CandidateReceipt { /// The ID of the parachain this is a candidate for. pub parachain_index: Id, /// The collator's relay-chain account ID - pub collator: ::AccountId, + pub collator: super::AccountId, /// The head-data pub head_data: HeadData, /// Balance uploads to the relay chain. - pub balance_uploads: Vec<(::AccountId, u64)>, + pub balance_uploads: Vec<(super::AccountId, u64)>, /// Egress queue roots. - pub egress_queue_roots: Vec<(Id, primitives::H256)>, + pub egress_queue_roots: Vec<(Id, Hash)>, /// Fees paid from the chain to the relay chain validators pub fees: u64, } @@ -203,8 +204,8 @@ impl CandidateReceipt { /// Get the blake2_256 hash #[cfg(feature = "std")] pub fn hash(&self) -> Hash { - let encoded = self.encode(); - primitives::hashing::blake2_256(&encoded).into() + use runtime_primitives::traits::{BlakeTwo256, Hashing}; + BlakeTwo256::hash_of(self) } } @@ -224,7 +225,7 @@ impl Ord for CandidateReceipt { /// Parachain ingress queue message. #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct Message(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); /// Consolidated ingress queue data. @@ -232,34 +233,34 @@ pub struct Message(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec /// This is just an ordered vector of other parachains' egress queues, /// obtained according to the routing rules. #[derive(Default, PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct ConsolidatedIngress(pub Vec<(Id, Vec)>); /// Parachain block data. /// /// contains everything required to validate para-block, may contain block and witness data #[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct BlockData(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); /// Parachain header raw bytes wrapper type. #[derive(PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct Header(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); /// Parachain head data included in the chain. #[derive(PartialEq, Eq, Clone, PartialOrd, Ord)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct HeadData(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); /// Parachain validation code. #[derive(PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct ValidationCode(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); /// Activitiy bit field #[derive(PartialEq, Eq, Clone, Default)] -#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct Activity(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); impl Slicable for Activity { @@ -339,41 +340,3 @@ impl Slicable for Statement { } } } - -#[cfg(test)] -mod tests { - use super::*; - use substrate_serializer as ser; - - #[test] - fn test_candidate() { - assert_eq!(ser::to_string_pretty(&Candidate { - parachain_index: 5.into(), - collator_signature: primitives::hash::H512::from(10).into(), - unprocessed_ingress: ConsolidatedIngress(vec![ - (Id(1), vec![Message(vec![2])]), - (Id(2), vec![Message(vec![2]), Message(vec![3])]), - ]), - block: BlockData(vec![1, 2, 3]), - }), r#"{ - "parachainIndex": 5, - "collatorSignature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a", - "unprocessedIngress": [ - [ - 1, - [ - "0x02" - ] - ], - [ - 2, - [ - "0x02", - "0x03" - ] - ] - ], - "block": "0x010203" -}"#); - } -} diff --git a/polkadot/runtime/Cargo.toml b/polkadot/runtime/Cargo.toml index 95044242fe..9ac1f50175 100644 --- a/polkadot/runtime/Cargo.toml +++ b/polkadot/runtime/Cargo.toml @@ -9,6 +9,7 @@ log = { version = "0.3", optional = true } serde = { version = "1.0", default_features = false } serde_derive = { version = "1.0", optional = true } safe-mix = { path = "../../safe-mix", default_features = false} +polkadot-primitives = { path = "../primitives", default_features = false } substrate-codec = { path = "../../substrate/codec" } substrate-serializer = { path = "../../substrate/serializer" } substrate-runtime-std = { path = "../../substrate/runtime-std" } @@ -25,7 +26,6 @@ substrate-runtime-session = { path = "../../substrate/runtime/session" } substrate-runtime-staking = { path = "../../substrate/runtime/staking" } substrate-runtime-system = { path = "../../substrate/runtime/system" } substrate-runtime-timestamp = { path = "../../substrate/runtime/timestamp" } -polkadot-primitives = { path = "../primitives" } [dev-dependencies] hex-literal = "0.1.0" @@ -33,6 +33,7 @@ hex-literal = "0.1.0" [features] default = ["std"] std = [ + "polkadot-primitives/std", "substrate-codec/std", "substrate-primitives/std", "substrate-runtime-std/std", @@ -47,7 +48,6 @@ std = [ "substrate-runtime-staking/std", "substrate-runtime-system/std", "substrate-runtime-timestamp/std", - "polkadot-primitives/std", "serde_derive", "serde/std", "log", diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 9b86eb91cb..16d080cb9e 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -18,11 +18,18 @@ #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "std")] +#[macro_use] +extern crate serde_derive; + +#[cfg(feature = "std")] +extern crate serde; + #[macro_use] extern crate substrate_runtime_io as runtime_io; #[macro_use] -extern crate substrate_runtime_support as runtime_support; +extern crate substrate_runtime_support; #[macro_use] extern crate substrate_runtime_primitives as runtime_primitives; @@ -37,7 +44,10 @@ extern crate substrate_serializer; #[cfg_attr(feature = "std", macro_use)] extern crate substrate_primitives; +#[macro_use] extern crate substrate_runtime_std as rstd; + +extern crate polkadot_primitives as primitives; extern crate substrate_codec as codec; extern crate substrate_runtime_consensus as consensus; extern crate substrate_runtime_council as council; @@ -47,14 +57,13 @@ extern crate substrate_runtime_session as session; extern crate substrate_runtime_staking as staking; extern crate substrate_runtime_system as system; extern crate substrate_runtime_timestamp as timestamp; -extern crate polkadot_primitives; mod parachains; -use runtime_io::BlakeTwo256; -use polkadot_primitives::{AccountId, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature}; -use runtime_primitives::generic; -use runtime_primitives::traits::{Identity, HasPublicAux}; +use rstd::prelude::*; +use primitives::{AccountId, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature}; +use primitives::parachain::CandidateReceipt; +use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}}; #[cfg(feature = "std")] pub use runtime_primitives::BuildExternalities; @@ -62,13 +71,113 @@ pub use runtime_primitives::BuildExternalities; pub use consensus::Call as ConsensusCall; pub use timestamp::Call as TimestampCall; pub use parachains::Call as ParachainsCall; - +pub use primitives::Header; /// The position of the timestamp set extrinsic. pub const TIMESTAMP_SET_POSITION: u32 = 0; /// The position of the parachains set extrinsic. pub const PARACHAINS_SET_POSITION: u32 = 1; +/// Block Id type for this block. +pub type BlockId = generic::BlockId; +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; +/// Extrinsic type as expected by this runtime. +pub type Extrinsic = generic::Extrinsic; + +/// Block type as expected by this runtime. +pub type Block = generic::Block; + +/// Provides a type-safe wrapper around a structurally valid block. +#[cfg(feature = "std")] +pub struct CheckedBlock { + inner: Block, + file_line: Option<(&'static str, u32)>, +} + +#[cfg(feature = "std")] +impl CheckedBlock { + /// Create a new checked block. Fails if the block is not structurally valid. + pub fn new(block: Block) -> Result { + let has_timestamp = block.extrinsics.get(TIMESTAMP_SET_POSITION as usize).map_or(false, |xt| { + !xt.is_signed() && match xt.extrinsic.function { + Call::Timestamp(TimestampCall::set(_)) => true, + _ => false, + } + }); + + if !has_timestamp { return Err(block) } + + let has_heads = block.extrinsics.get(PARACHAINS_SET_POSITION as usize).map_or(false, |xt| { + !xt.is_signed() && match xt.extrinsic.function { + Call::Parachains(ParachainsCall::set_heads(_)) => true, + _ => false, + } + }); + + if !has_heads { return Err(block) } + Ok(CheckedBlock { + inner: block, + file_line: None, + }) + } + + // Creates a new checked block, asserting that it is valid. + #[doc(hidden)] + pub fn new_unchecked(block: Block, file: &'static str, line: u32) -> Self { + CheckedBlock { + inner: block, + file_line: Some((file, line)), + } + } + + /// Extract the timestamp from the block. + pub fn timestamp(&self) -> ::primitives::Timestamp { + let x = self.inner.extrinsics.get(TIMESTAMP_SET_POSITION as usize).and_then(|xt| match xt.extrinsic.function { + Call::Timestamp(TimestampCall::set(x)) => Some(x), + _ => None + }); + + match x { + Some(x) => x, + None => panic!("Invalid polkadot block asserted at {:?}", self.file_line), + } + } + + /// Extract the parachain heads from the block. + pub fn parachain_heads(&self) -> &[CandidateReceipt] { + let x = self.inner.extrinsics.get(PARACHAINS_SET_POSITION as usize).and_then(|xt| match xt.extrinsic.function { + Call::Parachains(ParachainsCall::set_heads(ref x)) => Some(&x[..]), + _ => None + }); + + match x { + Some(x) => x, + None => panic!("Invalid polkadot block asserted at {:?}", self.file_line), + } + } + + /// Convert into inner block. + pub fn into_inner(self) -> Block { self.inner } +} + +#[cfg(feature = "std")] +impl ::std::ops::Deref for CheckedBlock { + type Target = Block; + + fn deref(&self) -> &Block { &self.inner } +} + +/// Assert that a block is structurally valid. May lead to panic in the future +/// in case it isn't. +#[cfg(feature = "std")] +#[macro_export] +macro_rules! assert_polkadot_block { + ($block: expr) => { + $crate::CheckedBlock::new_unchecked($block, file!(), line!()) + } +} + /// Concrete runtime type used to parameterize the various modules. pub struct Concrete; @@ -83,7 +192,7 @@ impl system::Trait for Concrete { type Hashing = BlakeTwo256; type Digest = generic::Digest; type AccountId = AccountId; - type Header = generic::Header; + type Header = Header; } /// System module for this concrete runtime. pub type System = system::Module; @@ -102,8 +211,16 @@ impl timestamp::Trait for Concrete { /// Timestamp module for this concrete runtime. pub type Timestamp = timestamp::Module; +/// Session key conversion. +pub struct SessionKeyConversion; +impl Convert for SessionKeyConversion { + fn convert(a: AccountId) -> SessionKey { + a.0 + } +} + impl session::Trait for Concrete { - type ConvertAccountIdToSessionKey = Identity; + type ConvertAccountIdToSessionKey = SessionKeyConversion; } /// Session module for this concrete runtime. pub type Session = session::Module; @@ -135,6 +252,9 @@ impl parachains::Trait for Concrete { pub type Parachains = parachains::Module; impl_outer_dispatch! { + /// Call type for polkadot transactions. + #[derive(Clone, PartialEq, Eq)] + #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] pub enum Call where aux: ::PublicAux { Consensus = 0, Session = 1, @@ -146,6 +266,9 @@ impl_outer_dispatch! { Parachains = 8, } + /// Internal calls. + #[derive(Clone, PartialEq, Eq)] + #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] pub enum PrivCall { Consensus = 0, Session = 1, @@ -156,14 +279,6 @@ impl_outer_dispatch! { } } -/// Block header type as expected by this runtime. -pub type Header = generic::Header; -/// Block type as expected by this runtime. -pub type Block = generic::Block; -/// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; -/// Extrinsic type as expected by this runtime. -pub type Extrinsic = generic::Extrinsic; /// Executive: handles dispatch to the various modules. pub type Executive = executive::Executive; @@ -180,6 +295,35 @@ impl_outer_config! { } } +/// Produces the list of inherent extrinsics. +pub fn inherent_extrinsics(timestamp: ::primitives::Timestamp, parachain_heads: Vec) -> Vec { + vec![ + UncheckedExtrinsic { + extrinsic: Extrinsic { + signed: Default::default(), + function: Call::Timestamp(TimestampCall::set(timestamp)), + index: 0, + }, + signature: Default::default(), + }, + UncheckedExtrinsic { + extrinsic: Extrinsic { + signed: Default::default(), + function: Call::Parachains(ParachainsCall::set_heads(parachain_heads)), + index: 0, + }, + signature: Default::default(), + }, + ] +} + +/// Checks an unchecked extrinsic for validity. +pub fn check_extrinsic(xt: UncheckedExtrinsic) -> bool { + use runtime_primitives::traits::Checkable; + + xt.check().is_ok() +} + pub mod api { impl_stubs!( authorities => |()| super::Consensus::authorities(), @@ -187,6 +331,7 @@ pub mod api { apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic), execute_block => |block| super::Executive::execute_block(block), finalise_block => |()| super::Executive::finalise_block(), + inherent_extrinsics => |(timestamp, heads)| super::inherent_extrinsics(timestamp, heads), validator_count => |()| super::Session::validator_count(), validators => |()| super::Session::validators() ); @@ -290,9 +435,9 @@ mod tests { }); let raw = block.encode(); - let decoded_substrate = primitives::block::Block::decode(&mut &raw[..]).unwrap(); - let encoded_substrate = decoded_substrate.encode(); - let decoded = Block::decode(&mut &encoded_substrate[..]).unwrap(); + let decoded_primitive = ::primitives::Block::decode(&mut &raw[..]).unwrap(); + let encoded_primitive = decoded_primitive.encode(); + let decoded = Block::decode(&mut &encoded_primitive[..]).unwrap(); assert_eq!(block, decoded); } @@ -301,11 +446,11 @@ mod tests { fn serialize_unchecked() { let tx = UncheckedExtrinsic { extrinsic: Extrinsic { - signed: [1; 32], + signed: [1; 32].into(), index: 999, function: Call::Timestamp(TimestampCall::set(135135)), }, - signature: primitives::hash::H512([0; 64]).into(), + signature: runtime_primitives::Ed25519Signature(primitives::hash::H512([0; 64])).into(), }; // 71000000 // 0101010101010101010101010101010101010101010101010101010101010101 @@ -322,7 +467,7 @@ mod tests { #[test] fn serialize_checked() { let xt = Extrinsic { - signed: hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"], + signed: hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"].into(), index: 0, function: Call::CouncilVoting(council::voting::Call::propose(Box::new( PrivCall::Consensus(consensus::PrivCall::set_code( diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs index 50da4306cb..5bd62afcf2 100644 --- a/polkadot/runtime/src/parachains.rs +++ b/polkadot/runtime/src/parachains.rs @@ -16,17 +16,16 @@ //! Main parachains logic. For now this is just the determination of which validators do what. -use polkadot_primitives; +use primitives; use rstd::prelude::*; use codec::{Slicable, Joiner}; -use runtime_support::Hashable; use runtime_primitives::traits::{Executable, RefInto, MaybeEmpty}; -use polkadot_primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt}; +use primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt}; use {system, session}; -use runtime_support::{StorageValue, StorageMap}; -use runtime_support::dispatch::Result; +use substrate_runtime_support::{Hashable, StorageValue, StorageMap}; +use substrate_runtime_support::dispatch::Result; #[cfg(any(feature = "std", test))] use rstd::marker::PhantomData; @@ -34,7 +33,7 @@ use rstd::marker::PhantomData; #[cfg(any(feature = "std", test))] use {runtime_io, runtime_primitives}; -pub trait Trait: system::Trait + session::Trait { +pub trait Trait: system::Trait + session::Trait { /// The position of the set_heads call in the block. const SET_POSITION: u32; @@ -42,7 +41,11 @@ pub trait Trait: system::Trait + session::Trai } decl_module! { + /// Parachains module. pub struct Module; + + /// Call type for parachains. + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum Call where aux: ::PublicAux { // provide candidate receipts for parachains, in ascending order by id. fn set_heads(aux, heads: Vec) -> Result = 0; @@ -227,7 +230,7 @@ mod tests { use runtime_io::with_externalities; use substrate_primitives::H256; use runtime_primitives::BuildExternalities; - use runtime_primitives::traits::{HasPublicAux, Identity}; + use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256}; use runtime_primitives::testing::{Digest, Header}; use consensus; @@ -243,7 +246,7 @@ mod tests { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Hashing = runtime_io::BlakeTwo256; + type Hashing = BlakeTwo256; type Digest = Digest; type AccountId = u64; type Header = Header; diff --git a/polkadot/runtime/wasm/Cargo.lock b/polkadot/runtime/wasm/Cargo.lock index 9d8f465e4a..40e3acb37a 100644 --- a/polkadot/runtime/wasm/Cargo.lock +++ b/polkadot/runtime/wasm/Cargo.lock @@ -11,19 +11,9 @@ name = "base58" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bigint" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bitflags" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -37,33 +27,55 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.2.1" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.4" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "coco" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "constant_time_eq" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crossbeam-deque" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crunchy" version = "0.1.6" @@ -75,20 +87,15 @@ version = "0.1.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "either" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "elastic-array" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -99,15 +106,37 @@ name = "environmental" version = "0.1.0" [[package]] -name = "ethcore-bigint" +name = "ethbloom" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ethereum-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ethereum-types-serialize" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bigint 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "plain_hasher 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -119,12 +148,23 @@ dependencies = [ "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fixed-hash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -148,16 +188,16 @@ dependencies = [ [[package]] name = "hex-literal" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hex-literal-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hex-literal-impl" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -170,12 +210,12 @@ source = "git+https://github.com/paritytech/integer-sqrt-rs.git#886e9cb983c46498 [[package]] name = "keccak-hash" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -185,12 +225,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.36" +version = "0.2.41" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -206,9 +246,14 @@ name = "log" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "memory_units" version = "0.3.0" @@ -229,7 +274,7 @@ name = "num_cpus" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -245,9 +290,9 @@ name = "parity-wasm" version = "0.27.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -255,43 +300,35 @@ name = "parity-wasm" version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parking_lot" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parking_lot_core" -version = "0.2.10" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "plain_hasher" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "polkadot-primitives" version = "0.1.0" dependencies = [ - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-primitives 0.1.0", @@ -334,12 +371,20 @@ name = "proc-macro-hack-impl" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pwasm-alloc" version = "0.1.0" dependencies = [ "pwasm-libc 0.1.0", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -351,15 +396,18 @@ name = "pwasm-utils" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" -version = "0.3.15" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "rand" @@ -367,7 +415,7 @@ version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -377,7 +425,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -386,19 +434,19 @@ name = "rayon" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -408,20 +456,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rlp" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -437,17 +484,17 @@ source = "git+https://github.com/rphmeier/rustc-hex.git#ee2ec40b9062ac7769ccb9dc [[package]] name = "rustc_version" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "safe-mix" version = "0.1.0" dependencies = [ - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -457,7 +504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "semver" -version = "0.6.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -470,31 +517,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.27" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.27" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive_internals" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "smallvec" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -511,8 +549,8 @@ name = "substrate-keyring" version = "0.1.0" dependencies = [ "ed25519 0.1.0", - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -520,25 +558,26 @@ name = "substrate-primitives" version = "0.1.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", "rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-runtime-std 0.1.0", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", - "wasmi 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-runtime-consensus" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", @@ -563,10 +602,11 @@ dependencies = [ name = "substrate-runtime-council" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "safe-mix 0.1.0", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", @@ -585,9 +625,10 @@ dependencies = [ name = "substrate-runtime-democracy" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 0.1.0", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-consensus 0.1.0", @@ -604,8 +645,8 @@ dependencies = [ name = "substrate-runtime-executive" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-primitives 0.1.0", @@ -620,12 +661,12 @@ version = "0.1.0" dependencies = [ "ed25519 0.1.0", "environmental 0.1.0", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-std 0.1.0", "substrate-state-machine 0.1.0", - "triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -634,8 +675,8 @@ version = "0.1.0" dependencies = [ "integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)", "num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", @@ -647,21 +688,22 @@ dependencies = [ name = "substrate-runtime-sandbox" version = "0.1.0" dependencies = [ - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-std 0.1.0", - "wasmi 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-runtime-session" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 0.1.0", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", @@ -677,9 +719,10 @@ dependencies = [ name = "substrate-runtime-staking" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 0.1.0", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-keyring 0.1.0", "substrate-primitives 0.1.0", @@ -700,7 +743,7 @@ version = "0.1.0" dependencies = [ "pwasm-alloc 0.1.0", "pwasm-libc 0.1.0", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -708,9 +751,9 @@ name = "substrate-runtime-support" version = "0.1.0" dependencies = [ "ed25519 0.1.0", - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", @@ -721,9 +764,9 @@ dependencies = [ name = "substrate-runtime-system" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 0.1.0", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", @@ -736,8 +779,9 @@ dependencies = [ name = "substrate-runtime-timestamp" version = "0.1.0" dependencies = [ - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", @@ -751,43 +795,39 @@ dependencies = [ name = "substrate-state-machine" version = "0.1.0" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 0.1.0", - "triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "syn" -version = "0.11.11" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synom" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tiny-keccak" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "triehash" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -803,14 +843,25 @@ name = "uint" version = "0.1.2" source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "uint" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-xid" -version = "0.0.4" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -820,10 +871,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasmi" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.27.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -850,32 +901,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" -"checksum bigint 4.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5442186ef6560f30f1ee4b9c1e4c87a35a6879d3644550cc248ec2b955eb5fcd" -"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" +"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" -"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" -"checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" +"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d" +"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" -"checksum elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258ff6a9a94f648d0379dbd79110e057edbb53eb85cc237e33eadf8e5a30df85" -"checksum ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb5af77e74a8f70e9c3337e069c37bc82178ef1b459c02091f73c4ad5281eb5" +"checksum elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88d4851b005ef16de812ea9acdb7bece2f0a40dd86c07b85631d7dafa54537bb" +"checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" +"checksum ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c48729b8aea8aedb12cf4cb2e5cef439fdfe2dda4a89e47eeebd15778ef53b6" +"checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" "checksum fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" +"checksum fixed-hash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18d6fd718fb4396e7a9c93ac59ba7143501467ca7a143c145b5555a571d5576" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" -"checksum hex-literal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd546ef520ab3745f1aae5f2cdc6de9e6498e94d1ab138b9eb3ddfbf335847fb" -"checksum hex-literal-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2ea76da4c7f1a54d01d54985566d3fdd960b2bbd7b970da024821c883c2d9631" +"checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95" +"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" "checksum integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)" = "" -"checksum keccak-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f300c1f149cd9ca5214eed24f6e713a597517420fb8b15499824aa916259ec1" +"checksum keccak-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b7f51f30d7986536accaec4a6a288008dfb3dbffe8a2863a65292bc395a3ae7" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" +"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" +"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" +"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775393e285254d2f5004596d69bb8bc1149754570dcc08cf30cabeba67955e28" @@ -883,39 +938,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum parity-wasm 0.27.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bd4dc02a80a0315b109e48992c46942c79bcdb8fac416dd575d330ed9ced6cbd" "checksum parity-wasm 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41083957b80abb8a01fac4d2773d5f92653aed8f0b740c8d3da1da62c7857abe" -"checksum parking_lot 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd9d732f2de194336fb02fe11f9eed13d9e76f13f4315b4d88a14ca411750cd" -"checksum parking_lot_core 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "9f35048d735bb93dd115a0030498785971aab3234d311fbe273d020084d26bd8" -"checksum plain_hasher 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83ae80873992f511142c07d0ec6c44de5636628fdb7e204abd655932ea79d995" +"checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" +"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" "checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" +"checksum proc-macro2 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1fa93823f53cfd0f5ac117b189aed6cfdfb2cfc0a9d82e956dd7927595ed7d46" "checksum pwasm-utils 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3a822d2a1624b10c46572c231c149575bcc261c37d84fd3f1a2f5ae1f65515" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" +"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8" -"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" +"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" "checksum ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6f7d28b30a72c01b458428e0ae988d4149c20d902346902be881e3edc4bb325c" -"checksum rlp 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "babe6fce20c0ca9b1582998734c4569082d0ad08e43772a1c6c40aef4f106ef9" +"checksum rlp 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "89db7f8dfdd5eb7ab3ac3ece7a07fd273a680b4b224cb231181280e8996f9f0b" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" "checksum rustc-hex 2.0.0 (git+https://github.com/rphmeier/rustc-hex.git)" = "" -"checksum rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9743a7670d88d5d52950408ecdb7c71d8986251ab604d4689dd2ca25c9bca69" +"checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526" -"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0" -"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5" -"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9" +"checksum serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)" = "fba5be06346c5200249c8c8ca4ccba4a09e8747c71c16e420bd359a0db4d8f91" +"checksum serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)" = "79e4620ba6fbe051fc7506fab6f84205823564d55da18d55b695160fb3479cd8" +"checksum smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03dab98ab5ded3a8b43b2c80751194608d0b2aa0f1d46cf95d1c35e192844aa7" "checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e9241752647ca572f12c9b520a5d360d9099360c527770647e694001646a1d0" -"checksum triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9291c7f0fae44858b5e087dd462afb382354120003778f1695b44aab98c7abd7" +"checksum syn 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6dfd71b2be5a58ee30a6f8ea355ba8290d397131c00dfa55c3d34e6e13db5101" +"checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" +"checksum triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2033893a813c70e7d8a739ca6c36dc0a7a2c913ec718d7cbf84a3837bbe3c7ce" "checksum twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "475352206e7a290c5fccc27624a163e8d0d115f7bb60ca18a64fc9ce056d7435" "checksum uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" +"checksum uint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "38051a96565903d81c9a9210ce11076b2218f3b352926baa1f5f6abbdfce8273" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" -"checksum wasmi 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26b20dbeb7caee04597a5d2c93e2b3e64872c6ea2af732d7ad49dbec44067c35" +"checksum wasmi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d19da510b59247935ad5f598357b3cc739912666d75d3d28318026478d95bbdb" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/polkadot/runtime/wasm/Cargo.toml b/polkadot/runtime/wasm/Cargo.toml index a75bd649ad..f5dc280e6f 100644 --- a/polkadot/runtime/wasm/Cargo.toml +++ b/polkadot/runtime/wasm/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["cdylib"] [dependencies] integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" } +polkadot-primitives = { path = "../../primitives", default-features = false } safe-mix = { path = "../../../safe-mix", default-features = false } substrate-codec = { path = "../../../substrate/codec", default-features = false } substrate-primitives = { path = "../../../substrate/primitives", default-features = false } @@ -23,11 +24,11 @@ substrate-runtime-session = { path = "../../../substrate/runtime/session", defau substrate-runtime-staking = { path = "../../../substrate/runtime/staking", default-features = false } substrate-runtime-system = { path = "../../../substrate/runtime/system", default-features = false } substrate-runtime-timestamp = { path = "../../../substrate/runtime/timestamp", default-features = false } -polkadot-primitives = { path = "../../primitives", default-features = false } [features] default = [] std = [ + "polkadot-primitives/std", "safe-mix/std", "substrate-codec/std", "substrate-primitives/std", @@ -43,7 +44,6 @@ std = [ "substrate-runtime-staking/std", "substrate-runtime-system/std", "substrate-runtime-timestamp/std", - "polkadot-primitives/std", ] [profile.release] 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 7ca1577099..9ea43b2f9a 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 1a254a365d..dc22849a14 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 diff --git a/polkadot/service/src/lib.rs b/polkadot/service/src/lib.rs index 13dae55c4e..1e86d52112 100644 --- a/polkadot/service/src/lib.rs +++ b/polkadot/service/src/lib.rs @@ -19,6 +19,7 @@ extern crate futures; extern crate ed25519; +extern crate exit_future; extern crate parking_lot; extern crate tokio_timer; extern crate polkadot_primitives; @@ -28,17 +29,16 @@ extern crate polkadot_api; extern crate polkadot_consensus as consensus; extern crate polkadot_transaction_pool as transaction_pool; extern crate polkadot_keystore as keystore; -extern crate substrate_client as client; extern crate substrate_runtime_io as runtime_io; extern crate substrate_primitives as primitives; extern crate substrate_network as network; extern crate substrate_codec as codec; -extern crate substrate_client_db as client_db; extern crate substrate_executor; extern crate substrate_state_machine as state_machine; -extern crate exit_future; extern crate tokio_core; +extern crate substrate_client as client; +extern crate substrate_client_db as client_db; #[macro_use] extern crate error_chain; @@ -56,13 +56,13 @@ use std::thread; use futures::prelude::*; use tokio_core::reactor::Core; use codec::Slicable; -use primitives::block::{Id as BlockId, ExtrinsicHash, HeaderHash, Header}; -use primitives::{AuthorityId}; +use primitives::AuthorityId; use transaction_pool::TransactionPool; use substrate_executor::NativeExecutor; use polkadot_executor::Executor as LocalDispatch; use keystore::Store as Keystore; use polkadot_api::PolkadotApi; +use polkadot_primitives::{Block, BlockId, Hash, Header}; use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig, SessionConfig, StakingConfig, BuildExternalities}; use client::backend::Backend; @@ -78,8 +78,8 @@ type CodeExecutor = NativeExecutor; /// Polkadot service. pub struct Service { thread: Option>, - client: Arc>, - network: Arc, + client: Arc>, + network: Arc>, transaction_pool: Arc, signal: Option, _consensus: Option, @@ -87,18 +87,18 @@ pub struct Service { struct TransactionPoolAdapter where A: Send + Sync, E: Send + Sync { pool: Arc, - client: Arc>, + client: Arc>, api: Arc, } -impl network::TransactionPool for TransactionPoolAdapter +impl network::TransactionPool for TransactionPoolAdapter where - B: Backend + Send + Sync, - E: client::CallExecutor + Send + Sync, - client::error::Error: From<<::State as state_machine::backend::Backend>::Error>, + B: Backend + Send + Sync, + E: client::CallExecutor + Send + Sync, + client::error::Error: From<<>::State as state_machine::backend::Backend>::Error>, A: PolkadotApi + Send + Sync, { - fn transactions(&self) -> Vec<(ExtrinsicHash, Vec)> { + fn transactions(&self) -> Vec<(Hash, Vec)> { let best_block = match self.client.info() { Ok(info) => info.chain.best_hash, Err(e) => { @@ -107,21 +107,25 @@ impl network::TransactionPool for TransactionPoolAdapter } }; - let id = self.api.check_id(BlockId::Hash(best_block)).expect("Best block is always valid; qed."); + let id = match self.api.check_id(BlockId::hash(best_block)) { + Ok(id) => id, + Err(_) => return Vec::new(), + }; + let ready = transaction_pool::Ready::create(id, &*self.api); self.pool.cull_and_get_pending(ready, |pending| pending .map(|t| { - let hash = ::primitives::Hash::from(&t.hash()[..]); - let tx = codec::Slicable::encode(t.as_transaction()); - (hash, tx) + let hash = t.hash().clone(); + (hash, t.primitive_extrinsic()) }) .collect() ) } - fn import(&self, transaction: &[u8]) -> Option { - if let Some(uxt) = codec::Slicable::decode(&mut &transaction[..]) { + fn import(&self, transaction: &Vec) -> Option { + let encoded = transaction.encode(); + if let Some(uxt) = codec::Slicable::decode(&mut &encoded[..]) { match self.pool.import_unchecked_extrinsic(uxt) { Ok(xt) => Some(*xt.hash()), Err(e) => match *e.kind() { @@ -138,7 +142,7 @@ impl network::TransactionPool for TransactionPoolAdapter } } - fn on_broadcasted(&self, propagations: HashMap>) { + fn on_broadcasted(&self, propagations: HashMap>) { self.pool.on_broadcasted(propagations) } } @@ -165,12 +169,12 @@ fn poc_2_testnet_config() -> ChainConfig { }), system: None, session: Some(SessionConfig { - validators: initial_authorities.clone(), + validators: initial_authorities.iter().cloned().map(Into::into).collect(), session_length: 720, // that's 1 hour per session. }), staking: Some(StakingConfig { current_era: 0, - intentions: initial_authorities.clone(), + intentions: initial_authorities.iter().cloned().map(Into::into).collect(), transaction_base_fee: 100, transaction_byte_fee: 1, balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(), @@ -210,12 +214,12 @@ fn poc_2_testnet_config() -> ChainConfig { fn testnet_config(initial_authorities: Vec) -> ChainConfig { let endowed_accounts = vec![ - ed25519::Pair::from_seed(b"Alice ").public().into(), - ed25519::Pair::from_seed(b"Bob ").public().into(), - ed25519::Pair::from_seed(b"Charlie ").public().into(), - ed25519::Pair::from_seed(b"Dave ").public().into(), - ed25519::Pair::from_seed(b"Eve ").public().into(), - ed25519::Pair::from_seed(b"Ferdie ").public().into(), + ed25519::Pair::from_seed(b"Alice ").public().0.into(), + ed25519::Pair::from_seed(b"Bob ").public().0.into(), + ed25519::Pair::from_seed(b"Charlie ").public().0.into(), + ed25519::Pair::from_seed(b"Dave ").public().0.into(), + ed25519::Pair::from_seed(b"Eve ").public().0.into(), + ed25519::Pair::from_seed(b"Ferdie ").public().0.into(), ]; let genesis_config = GenesisConfig { consensus: Some(ConsensusConfig { @@ -224,12 +228,12 @@ fn testnet_config(initial_authorities: Vec) -> ChainConfig { }), system: None, session: Some(SessionConfig { - validators: initial_authorities.clone(), + validators: initial_authorities.iter().cloned().map(Into::into).collect(), session_length: 10, }), staking: Some(StakingConfig { current_era: 0, - intentions: initial_authorities.clone(), + intentions: initial_authorities.iter().cloned().map(Into::into).collect(), transaction_base_fee: 1, transaction_byte_fee: 0, balances: endowed_accounts.iter().map(|&k|(k, (1u128 << 60))).collect(), @@ -243,7 +247,7 @@ fn testnet_config(initial_authorities: Vec) -> ChainConfig { minimum_deposit: 10, }), council: Some(CouncilConfig { - active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|b| a == b).is_none()).map(|a| (a.clone(), 1000000)).collect(), + active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|&b| &a.0 == b).is_none()).map(|a| (a.clone(), 1000000)).collect(), candidacy_bond: 10, voter_bond: 2, present_slash_per_voter: 1, @@ -280,16 +284,23 @@ struct GenesisBuilder { config: GenesisConfig, } -impl client::GenesisBuilder for GenesisBuilder { +impl client::GenesisBuilder for GenesisBuilder { fn build(self) -> (Header, Vec<(Vec, Vec)>) { let storage = self.config.build_externalities(); - let block = genesis::construct_genesis_block(&storage); - (primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect()) + let block = genesis::construct_genesis_block::(&storage); + (block.header, storage.into_iter().collect()) } } /// Creates light client and register protocol with the network service -pub fn new_light(config: Configuration) -> Result>>, error::Error> { +pub fn new_light(config: Configuration) + -> Result< + Service< + client::light::Backend, + client::RemoteCallExecutor, network::OnDemand>> + >, + error::Error, + > { Service::new(move |_, executor, genesis_builder: GenesisBuilder| { let client_backend = client::light::new_light_backend(); let fetch_checker = Arc::new(client::light::new_fetch_checker(client_backend.clone(), executor)); @@ -303,7 +314,7 @@ pub fn new_light(config: Configuration) -> Result Result>, error::Error> { +pub fn new_full(config: Configuration) -> Result, client::LocalCallExecutor, CodeExecutor>>, error::Error> { let is_validator = (config.roles & Role::VALIDATOR) == Role::VALIDATOR; Service::new(|db_settings, executor, genesis_builder: GenesisBuilder| Ok((Arc::new(client_db::new_client(db_settings, executor, genesis_builder)?), None)), @@ -330,9 +341,9 @@ pub fn new_full(config: Configuration) -> Result Service where - B: Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, - client::error::Error: From<<::State as state_machine::backend::Backend>::Error> + B: Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, + client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { /// Creates and register protocol with the network service fn new(client_creator: F, api_creator: G, consensus_creator: C, mut config: Configuration) -> Result @@ -341,13 +352,13 @@ impl Service client_db::DatabaseSettings, CodeExecutor, GenesisBuilder, - ) -> Result<(Arc>, Option>>), error::Error>, + ) -> Result<(Arc>, Option>>>), error::Error>, G: Fn( - Arc>, + Arc>, ) -> Arc, C: Fn( - Arc>, - Arc, + Arc>, + Arc>, Arc, &Keystore ) -> Result, error::Error>, @@ -405,7 +416,6 @@ impl Service on_demand: on_demand.clone().map(|d| d as Arc), transaction_pool: transaction_pool_adapter, }; - let network = network::Service::new(network_params)?; let barrier = ::std::sync::Arc::new(Barrier::new(2)); on_demand.map(|on_demand| on_demand.set_service_link(Arc::downgrade(&network))); @@ -468,12 +478,12 @@ impl Service } /// Get shared client instance. - pub fn client(&self) -> Arc> { + pub fn client(&self) -> Arc> { self.client.clone() } /// Get shared network instance. - pub fn network(&self) -> Arc { + pub fn network(&self) -> Arc> { self.network.clone() } @@ -484,11 +494,11 @@ impl Service } /// Produce a task which prunes any finalized transactions from the pool. -pub fn prune_imported(api: &A, pool: &TransactionPool, hash: HeaderHash) +pub fn prune_imported(api: &A, pool: &TransactionPool, hash: Hash) where A: PolkadotApi, { - match api.check_id(BlockId::Hash(hash)) { + match api.check_id(BlockId::hash(hash)) { Ok(id) => { let ready = transaction_pool::Ready::create(id, api); pool.cull(None, ready); diff --git a/polkadot/statement-table/src/lib.rs b/polkadot/statement-table/src/lib.rs index e3abf95686..86b95b0d90 100644 --- a/polkadot/statement-table/src/lib.rs +++ b/polkadot/statement-table/src/lib.rs @@ -21,8 +21,8 @@ pub mod generic; pub use generic::Table; -use primitives::parachain::{Id, CandidateReceipt}; -use primitives::{SessionKey, Hash, Signature}; +use primitives::parachain::{Id, CandidateReceipt, CandidateSignature as Signature}; +use primitives::{SessionKey, Hash}; /// Statements about candidates on the network. pub type Statement = generic::Statement; diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index 015777a863..2c2224b5d3 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -40,106 +40,23 @@ use std::{ use codec::Slicable; use extrinsic_pool::{Pool, txpool::{self, Readiness, scoring::{Change, Choice}}}; +use extrinsic_pool::api::ExtrinsicPool; use polkadot_api::PolkadotApi; -use primitives::parachain::CandidateReceipt; -use primitives::{AccountId, Timestamp, Hash}; -use runtime::{Block, UncheckedExtrinsic, TimestampCall, ParachainsCall, Call}; -use substrate_primitives::block::{Extrinsic, ExtrinsicHash}; -use substrate_primitives::hexdisplay::HexDisplay; -use substrate_runtime_primitives::traits::{Bounded, Checkable}; +use primitives::{AccountId, Hash, UncheckedExtrinsic as FutureProofUncheckedExtrinsic}; +use runtime::UncheckedExtrinsic; +use substrate_runtime_primitives::traits::{Bounded, Checkable, BlakeTwo256, Hashing}; pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps}; pub use error::{Error, ErrorKind, Result}; -/// Useful functions for working with Polkadot blocks. -pub struct PolkadotBlock { - block: Block, - location: Option<(&'static str, usize)>, -} - -impl PolkadotBlock { - /// Create a new block, checking high-level well-formedness. - pub fn from(unchecked: Block) -> ::std::result::Result { - if unchecked.extrinsics.len() < 2 { - return Err(unchecked); - } - if unchecked.extrinsics[0].is_signed() { - return Err(unchecked); - } - if unchecked.extrinsics[1].is_signed() { - return Err(unchecked); - } - - match unchecked.extrinsics[0].extrinsic.function { - Call::Timestamp(TimestampCall::set(_)) => {}, - _ => return Err(unchecked), - } - - match unchecked.extrinsics[1].extrinsic.function { - Call::Parachains(ParachainsCall::set_heads(_)) => {}, - _ => return Err(unchecked), - } - - // any further checks... - Ok(PolkadotBlock { block: unchecked, location: None }) - } - - /// Create a new block, skipping any high-level well-formedness checks. WARNING: This could - /// result in internal functions panicking if the block is, in fact, not well-formed. - pub fn force_from(known_good: Block, file: &'static str, line: usize) -> Self { - PolkadotBlock { block: known_good, location: Some((file, line)) } - } - - /// Retrieve the timestamp of a Polkadot block. - pub fn timestamp(&self) -> Timestamp { - if let Call::Timestamp(TimestampCall::set(t)) = self.block.extrinsics[0].extrinsic.function { - t - } else { - if let Some((file, line)) = self.location { - panic!("Invalid block used in `PolkadotBlock::force_from` at {}:{}", file, line); - } else { - panic!("Invalid block made it through the PolkadotBlock verification!?"); - } - } - } - - /// Retrieve the parachain candidates proposed for this block. - pub fn parachain_heads(&self) -> &[CandidateReceipt] { - if let Call::Parachains(ParachainsCall::set_heads(ref t)) = self.block.extrinsics[1].extrinsic.function { - &t[..] - } else { - if let Some((file, line)) = self.location { - panic!("Invalid block used in `PolkadotBlock::force_from` at {}:{}", file, line); - } else { - panic!("Invalid block made it through the PolkadotBlock verification!?"); - } - } - } -} - -#[macro_export] -macro_rules! assert_polkadot_block { - ($known_good:expr) => ( PolkadotBlock::force_from(known_good, file!(), line!()) ) -} - -impl ::std::ops::Deref for PolkadotBlock { - type Target = Block; - fn deref(&self) -> &Block { - &self.block - } -} - -impl From for Block { - fn from(pd: PolkadotBlock) -> Self { - pd.block - } -} +/// Type alias for convenience. +pub type CheckedExtrinsic = ::Checked; /// A verified transaction which should be includable and non-inherent. #[derive(Debug, Clone)] pub struct VerifiedTransaction { - inner: ::Checked, - hash: ExtrinsicHash, + inner: CheckedExtrinsic, + hash: Hash, encoded_size: usize, } @@ -150,10 +67,10 @@ impl VerifiedTransaction { bail!(ErrorKind::IsInherent(xt)) } - let message = codec::Slicable::encode(&xt); + let message = Slicable::encode(&xt); match xt.check() { Ok(xt) => { - let hash = substrate_primitives::hashing::blake2_256(&message); + let hash = BlakeTwo256::hash(&message); Ok(VerifiedTransaction { inner: xt, hash: hash.into(), @@ -169,8 +86,14 @@ impl VerifiedTransaction { self.as_ref().as_unchecked() } + /// Convert to primitive unchecked extrinsic. + pub fn primitive_extrinsic(&self) -> ::primitives::UncheckedExtrinsic { + Slicable::decode(&mut self.as_transaction().encode().as_slice()) + .expect("UncheckedExtrinsic shares repr with Vec; qed") + } + /// Consume the verified transaciton, yielding the unchecked counterpart. - pub fn into_inner(self) -> ::Checked { + pub fn into_inner(self) -> CheckedExtrinsic { self.inner } @@ -190,8 +113,8 @@ impl VerifiedTransaction { } } -impl AsRef< ::Checked > for VerifiedTransaction { - fn as_ref(&self) -> &::Checked { +impl AsRef for VerifiedTransaction { + fn as_ref(&self) -> &CheckedExtrinsic { &self.inner } } @@ -303,15 +226,12 @@ impl<'a, T: 'a + PolkadotApi> txpool::Ready for Ready<'a, T pub struct Verifier; -impl txpool::Verifier for Verifier { +impl txpool::Verifier for Verifier { type VerifiedTransaction = VerifiedTransaction; type Error = Error; - fn verify_transaction(&self, xt: Extrinsic) -> Result { - info!("Extrinsic submitted: {}", HexDisplay::from(&xt.0)); - let uxt = xt.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s)) - .ok_or_else(|| ErrorKind::InvalidExtrinsicFormat)?; - info!("Correctly formatted: {:?}", uxt); + fn verify_transaction(&self, uxt: UncheckedExtrinsic) -> Result { + info!("Extrinsic Submitted: {:?}", uxt); VerifiedTransaction::create(uxt) } } @@ -320,7 +240,7 @@ impl txpool::Verifier for Verifier { /// /// Wraps a `extrinsic_pool::Pool`. pub struct TransactionPool { - inner: Pool, + inner: Pool, } impl TransactionPool { @@ -337,14 +257,25 @@ impl TransactionPool { } impl Deref for TransactionPool { - type Target = Pool; + type Target = Pool; fn deref(&self) -> &Self::Target { &self.inner } } -#[cfg(test)] -mod tests { -} +impl ExtrinsicPool for TransactionPool { + type Error = Error; + fn submit(&self, xts: Vec) -> Result> { + // TODO: more general transaction pool, which can handle more kinds of vec-encoded transactions, + // even when runtime is out of date. + xts.into_iter() + .map(|xt| xt.encode()) + .map(|encoded| UncheckedExtrinsic::decode(&mut &encoded[..])) + .map(|maybe_decoded| maybe_decoded.ok_or_else(|| ErrorKind::InvalidExtrinsicFormat.into())) + .map(|x| x.and_then(|x| self.import_unchecked_extrinsic(x))) + .map(|x| x.map(|x| x.hash().clone())) + .collect() + } +}