diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 61890f0510..eadfdd27c4 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -1005,6 +1005,7 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "native-runtime 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "polkadot-primitives 0.1.0", "substrate-codec 0.1.0", "substrate-executor 0.1.0", "substrate-primitives 0.1.0", @@ -1035,6 +1036,7 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-client 0.1.0", + "polkadot-primitives 0.1.0", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/client/Cargo.toml b/substrate/client/Cargo.toml index 1239525530..b5ee065dbb 100644 --- a/substrate/client/Cargo.toml +++ b/substrate/client/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Parity Technologies "] error-chain = "0.11" log = "0.3" parking_lot = "0.4" +polkadot-primitives = { path = "../polkadot-primitives", version = "0.1" } substrate-primitives = { path = "../primitives", version = "0.1" } substrate-state-machine = { path = "../state-machine", version = "0.1" } substrate-serializer = { path = "../serializer" } diff --git a/substrate/client/src/backend.rs b/substrate/client/src/backend.rs index 2af11f3254..563dd03699 100644 --- a/substrate/client/src/backend.rs +++ b/substrate/client/src/backend.rs @@ -18,7 +18,7 @@ use state_machine; use error; -use primitives::relay::block; +use primitives::block; use blockchain::{self, BlockId}; /// Block insertion transction. Keeps hold if the inseted block state and data. @@ -50,4 +50,3 @@ pub trait Backend { /// Returns state backend for specified block. fn state_at(&self, block: BlockId) -> error::Result; } - diff --git a/substrate/client/src/blockchain.rs b/substrate/client/src/blockchain.rs index 0b5e715731..6eb9061eb7 100644 --- a/substrate/client/src/blockchain.rs +++ b/substrate/client/src/blockchain.rs @@ -17,7 +17,7 @@ //! Polkadot blockchain trait use std::fmt::{Display, Formatter, Error as FmtError}; -use primitives::relay::block; +use primitives::block; use error::Result; /// Block indentification. @@ -83,4 +83,3 @@ pub enum BlockStatus { /// Not in the queue or the blockchain. Unknown, } - diff --git a/substrate/client/src/genesis.rs b/substrate/client/src/genesis.rs index 6815f6b2b5..5a48f947dd 100644 --- a/substrate/client/src/genesis.rs +++ b/substrate/client/src/genesis.rs @@ -17,7 +17,7 @@ //! Tool for creating the genesis block. use std::collections::HashMap; -use primitives::relay::{Block, Header}; +use primitives::{Block, Header}; use triehash::trie_root; /// Create a genesis block, given the initial storage. @@ -46,7 +46,7 @@ mod tests { use state_machine::OverlayedChanges; use state_machine::backend::InMemory; use substrate_executor::executor; - use primitives::relay::{AccountId, Hash, BlockNumber, Header, Digest, UncheckedTransaction, + use polkadot_primitives::{AccountId, Hash, BlockNumber, Header, Digest, UncheckedTransaction, Transaction, Function}; use ed25519::Pair; diff --git a/substrate/client/src/in_mem.rs b/substrate/client/src/in_mem.rs index c1f9d113a4..34475886c4 100644 --- a/substrate/client/src/in_mem.rs +++ b/substrate/client/src/in_mem.rs @@ -23,7 +23,7 @@ use error; use backend; use primitives; use ser; -use primitives::relay::block::{self, HeaderHash}; +use primitives::block::{self, HeaderHash}; use blockchain::{self, BlockId, BlockStatus}; fn header_hash(header: &block::Header) -> block::HeaderHash { @@ -201,4 +201,3 @@ impl backend::Backend for Backend { } } } - diff --git a/substrate/client/src/lib.rs b/substrate/client/src/lib.rs index edf4d22c3e..f0d1fd1a63 100644 --- a/substrate/client/src/lib.rs +++ b/substrate/client/src/lib.rs @@ -18,6 +18,7 @@ #![warn(missing_docs)] +extern crate polkadot_primitives; extern crate substrate_primitives as primitives; extern crate substrate_state_machine as state_machine; extern crate substrate_serializer as ser; @@ -47,8 +48,8 @@ pub use genesis::construct_genesis_block; pub use blockchain::Info as ChainInfo; pub use blockchain::BlockId; -use primitives::relay::block; -use primitives::contract::{StorageKey, StorageData}; +use primitives::block; +use primitives::storage::{StorageKey, StorageData}; use blockchain::Backend as BlockchainBackend; use backend::BlockImportOperation; diff --git a/substrate/codec/src/joiner.rs b/substrate/codec/src/joiner.rs index ac85331012..7df97e5705 100644 --- a/substrate/codec/src/joiner.rs +++ b/substrate/codec/src/joiner.rs @@ -16,7 +16,7 @@ //! Trait -use std::iter::Extend; +use rstd::iter::Extend; use super::slicable::Slicable; /// Trait to allow itself to be serialised into a value which can be extended diff --git a/substrate/codec/src/keyedvec.rs b/substrate/codec/src/keyedvec.rs index 535a616e14..aac1df0f17 100644 --- a/substrate/codec/src/keyedvec.rs +++ b/substrate/codec/src/keyedvec.rs @@ -17,8 +17,8 @@ //! Serialiser and prepender. use slicable::Slicable; -use std::iter::Extend; -use std::vec::Vec; +use rstd::iter::Extend; +use rstd::vec::Vec; /// Trait to allow itselg to be serialised and prepended by a given slice. pub trait KeyedVec { diff --git a/substrate/codec/src/lib.rs b/substrate/codec/src/lib.rs index 805c786bc4..0a672161e9 100644 --- a/substrate/codec/src/lib.rs +++ b/substrate/codec/src/lib.rs @@ -20,6 +20,8 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] +extern crate substrate_runtime_std as rstd; + mod endiansensitive; mod slicable; mod joiner; @@ -29,12 +31,3 @@ pub use self::endiansensitive::EndianSensitive; pub use self::slicable::{Slicable, NonTrivialSlicable}; pub use self::joiner::Joiner; pub use self::keyedvec::KeyedVec; - -// TODO: move these into runtime-std and `extern crate runtime_std as std;` -#[cfg(not(feature = "std"))] -mod std { - extern crate alloc; - - pub use core::*; - pub use self::alloc::vec; -} diff --git a/substrate/codec/src/slicable.rs b/substrate/codec/src/slicable.rs index 6baa2ebaad..653bbb7b16 100644 --- a/substrate/codec/src/slicable.rs +++ b/substrate/codec/src/slicable.rs @@ -16,8 +16,8 @@ //! Serialisation. -use std::{mem, slice}; -use std::vec::Vec; +use rstd::{mem, slice}; +use rstd::vec::Vec; use super::joiner::Joiner; use super::endiansensitive::EndianSensitive; @@ -44,7 +44,7 @@ impl Slicable for T { let size = mem::size_of::(); assert!(size > 0, "EndianSensitive can never be implemented for a zero-sized type."); if value.len() >= size { - let x: T = unsafe { ::std::ptr::read(value.as_ptr() as *const T) }; + let x: T = unsafe { ::rstd::ptr::read(value.as_ptr() as *const T) }; *value = &value[size..]; Some(x.from_le()) } else { @@ -115,7 +115,7 @@ impl Slicable for Vec { } fn to_vec(&self) -> Vec { - use std::iter::Extend; + use rstd::iter::Extend; let len = self.len(); assert!(len <= u32::max_value() as usize, "Attempted to serialize vec with too many elements."); diff --git a/substrate/collator/src/lib.rs b/substrate/collator/src/lib.rs index da16e7520e..dfc617717f 100644 --- a/substrate/collator/src/lib.rs +++ b/substrate/collator/src/lib.rs @@ -60,7 +60,7 @@ pub trait ParachainContext { fn produce_candidate>( &self, ingress: I, - ) -> (parachain::BlockData, primitives::relay::Signature); + ) -> (parachain::BlockData, ::Signature); } /// Relay chain context needed to collate. diff --git a/substrate/executor/src/native_executor.rs b/substrate/executor/src/native_executor.rs index a89b436402..37a3a18999 100644 --- a/substrate/executor/src/native_executor.rs +++ b/substrate/executor/src/native_executor.rs @@ -63,7 +63,7 @@ mod tests { use native_runtime::runtime::staking::balance; use state_machine::TestExternalities; use primitives::twox_128; - use primitives::relay::{Hash, Header, BlockNumber, Block, Digest, Transaction, + use polkadot_primitives::{Hash, Header, BlockNumber, Block, Digest, Transaction, UncheckedTransaction, Function, AccountId}; use ed25519::Pair; diff --git a/substrate/executor/src/wasm_executor.rs b/substrate/executor/src/wasm_executor.rs index 76f9d851ff..e46991c2c3 100644 --- a/substrate/executor/src/wasm_executor.rs +++ b/substrate/executor/src/wasm_executor.rs @@ -293,7 +293,7 @@ mod tests { use native_runtime::runtime::staking::balance; use state_machine::TestExternalities; use primitives::twox_128; - use primitives::relay::{Header, Transaction, UncheckedTransaction, Function, AccountId}; + use polkadot_primitives::{Header, Transaction, UncheckedTransaction, Function, AccountId}; use runtime_io; use ed25519::Pair; diff --git a/substrate/network/Cargo.toml b/substrate/network/Cargo.toml index 6591ebf919..e1e8310d33 100644 --- a/substrate/network/Cargo.toml +++ b/substrate/network/Cargo.toml @@ -11,6 +11,7 @@ authors = ["Parity Technologies "] ethcore-network = { git = "https://github.com/paritytech/parity.git" } ethcore-io = { git = "https://github.com/paritytech/parity.git" } substrate-primitives = { path = "../primitives" } +polkadot-primitives = { path = "../polkadot-primitives" } polkadot-client = { path = "../client" } substrate-state-machine = { path = "../state-machine" } substrate-serializer = { path = "../serializer" } diff --git a/substrate/network/src/blocks.rs b/substrate/network/src/blocks.rs index e79aff2c65..5b9ca9f6a5 100644 --- a/substrate/network/src/blocks.rs +++ b/substrate/network/src/blocks.rs @@ -20,7 +20,7 @@ use std::ops::Range; use std::collections::{HashMap, BTreeMap}; use std::collections::hash_map::Entry; use network::PeerId; -use primitives::relay::BlockNumber; +use primitives::block::Number as BlockNumber; use message; const MAX_PARALLEL_DOWNLOADS: u32 = 1; @@ -190,7 +190,7 @@ impl BlockCollection { mod test { use super::{BlockCollection, BlockData}; use message; - use primitives::relay::{HeaderHash}; + use primitives::HeaderHash; fn is_empty(bc: &BlockCollection) -> bool { bc.blocks.is_empty() && @@ -260,4 +260,3 @@ mod test { assert_eq!(drained[40..], blocks[121..150].iter().map(|b| BlockData { block: b.clone(), origin: 1 }).collect::>()[..]); } } - diff --git a/substrate/network/src/chain.rs b/substrate/network/src/chain.rs index cd6ebb8563..9390b727ec 100644 --- a/substrate/network/src/chain.rs +++ b/substrate/network/src/chain.rs @@ -19,7 +19,7 @@ use client::{self, Client as PolkadotClient, ImportResult, ClientInfo, BlockStatus}; use client::error::Error; use state_machine; -use primitives::relay::block; +use primitives::block; pub trait Client : Send + Sync { /// Given a hash return a header @@ -55,5 +55,3 @@ impl Client for PolkadotClient where (self as &Client).block_hash(block_number) } } - - diff --git a/substrate/network/src/lib.rs b/substrate/network/src/lib.rs index f1bd64d63f..6feabb0b46 100644 --- a/substrate/network/src/lib.rs +++ b/substrate/network/src/lib.rs @@ -28,11 +28,14 @@ extern crate parking_lot; extern crate smallvec; extern crate ipnetwork; extern crate substrate_primitives as primitives; -extern crate polkadot_client as client; extern crate substrate_state_machine as state_machine; extern crate substrate_serializer as ser; extern crate serde; extern crate serde_json; +// TODO: remove these two; split off dependent logic into polkadot-network and rename this crate +// to substrate-network. +extern crate polkadot_primitives as polkadot_primitives; +extern crate polkadot_client as client; #[macro_use] extern crate serde_derive; #[macro_use] extern crate log; #[macro_use] extern crate bitflags; @@ -56,7 +59,6 @@ pub use protocol::{ProtocolStatus}; pub use network::{NonReservedPeerMode, ConnectionFilter, ConnectionDirection, NetworkConfiguration}; // TODO: move it elsewhere -fn header_hash(header: &primitives::relay::Header) -> primitives::relay::HeaderHash { +fn header_hash(header: &primitives::Header) -> primitives::block::HeaderHash { primitives::hashing::blake2_256(&ser::to_vec(header)).into() } - diff --git a/substrate/network/src/message.rs b/substrate/network/src/message.rs index e3dce5b0f2..feefb56595 100644 --- a/substrate/network/src/message.rs +++ b/substrate/network/src/message.rs @@ -17,9 +17,10 @@ //! Network packet message types. These get serialized and put into the lower level protocol payload. use std::borrow::Borrow; -use primitives::parachain::Id as ParachainId; -use primitives::relay::{AccountId, BlockNumber, HeaderHash, Header, Body}; +use primitives::AuthorityId; +use primitives::block::{Number as BlockNumber, HeaderHash, Header, Body}; use service::Role as RoleFlags; +use polkadot_primitives::parachain::Id as ParachainId; pub type RequestId = u64; type Bytes = Vec; @@ -149,7 +150,7 @@ pub struct Status { /// Signatue of `best_hash` made with validator address. Required for the validator role. pub validator_signature: Option, /// Validator address. Required for the validator role. - pub validator_id: Option, + pub validator_id: Option, /// Parachain id. Required for the collator role. pub parachain_id: Option, } diff --git a/substrate/network/src/protocol.rs b/substrate/network/src/protocol.rs index 3d5d14dbdd..bd9dd614fe 100644 --- a/substrate/network/src/protocol.rs +++ b/substrate/network/src/protocol.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use parking_lot::RwLock; use serde_json; use std::time; -use primitives::relay::{HeaderHash, TransactionHash, BlockNumber, Header}; +use primitives::block::{HeaderHash, TransactionHash, Number as BlockNumber, Header}; use network::{PeerId, NodeId}; use message::{self, Message}; @@ -342,6 +342,3 @@ impl Protocol { &*self.chain } } - - - diff --git a/substrate/network/src/service.rs b/substrate/network/src/service.rs index 565f7f5249..e3832249db 100644 --- a/substrate/network/src/service.rs +++ b/substrate/network/src/service.rs @@ -19,7 +19,7 @@ use std::collections::{BTreeMap}; use std::io; use network::{NetworkProtocolHandler, NetworkService, NetworkContext, HostInfo, PeerId, ProtocolId, NetworkConfiguration , NonReservedPeerMode, ErrorKind}; -use primitives::relay::{TransactionHash, Header}; +use primitives::block::{TransactionHash, Header}; use core_io::{TimerToken}; use io::NetSyncIo; use protocol::{Protocol, ProtocolStatus, PeerInfo as ProtocolPeerInfo, TransactionStats}; diff --git a/substrate/network/src/sync.rs b/substrate/network/src/sync.rs index 6bed7ec6a2..e7d2847b83 100644 --- a/substrate/network/src/sync.rs +++ b/substrate/network/src/sync.rs @@ -19,7 +19,7 @@ use io::SyncIo; use protocol::Protocol; use network::PeerId; use client::{ImportResult, BlockStatus, ClientInfo}; -use primitives::relay::{HeaderHash, BlockNumber, Header}; +use primitives::block::{HeaderHash, Number as BlockNumber, Header}; use blocks::{self, BlockCollection}; use message::{self, Message}; use super::header_hash; @@ -366,7 +366,3 @@ impl ChainSync { protocol.send_message(io, peer_id, Message::BlockRequest(request)); } } - - - - diff --git a/substrate/polkadot-primitives/src/block.rs b/substrate/polkadot-primitives/src/block.rs index 2cfa7578e1..a5d76bf930 100644 --- a/substrate/polkadot-primitives/src/block.rs +++ b/substrate/polkadot-primitives/src/block.rs @@ -21,7 +21,6 @@ use primitives::bytes; use primitives::H256; use rstd::vec::Vec; use codec::Slicable; -use parachain; use transaction::UncheckedTransaction; /// Used to refer to a block number. @@ -161,24 +160,12 @@ impl Slicable for Header { } } -/// A relay chain block body. -/// -/// Included candidates should be sorted by parachain ID, and without duplicate -/// IDs. -#[derive(PartialEq, Eq, Clone)] -#[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 Body { - /// Parachain proposal blocks. - pub candidates: Vec, -} - #[cfg(test)] mod tests { use super::*; use codec::Slicable; use substrate_serializer as ser; + use parachain; #[test] fn test_header_serialization() { diff --git a/substrate/primitives/src/block.rs b/substrate/primitives/src/block.rs index 057c3c9a56..4ac11f9c46 100644 --- a/substrate/primitives/src/block.rs +++ b/substrate/primitives/src/block.rs @@ -83,6 +83,9 @@ impl Slicable for Digest { } } +/// The body of a block is just a bunch of transactions. +pub type Body = Vec; + /// A Substrate relay chain block. #[derive(PartialEq, Eq, Clone)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] @@ -90,7 +93,7 @@ pub struct Block { /// The block header. pub header: Header, /// All relay-chain transactions. - pub transactions: Vec, + pub transactions: Body, } impl Slicable for Block { diff --git a/substrate/rpc/src/chain/mod.rs b/substrate/rpc/src/chain/mod.rs index b69c2af8a0..519bdefb4a 100644 --- a/substrate/rpc/src/chain/mod.rs +++ b/substrate/rpc/src/chain/mod.rs @@ -16,7 +16,7 @@ //! Polkadot blockchain API. -use primitives::relay::block; +use primitives::block; use client; use state_machine; diff --git a/substrate/rpc/src/state/mod.rs b/substrate/rpc/src/state/mod.rs index dd5ba7d7cb..b21b859435 100644 --- a/substrate/rpc/src/state/mod.rs +++ b/substrate/rpc/src/state/mod.rs @@ -22,8 +22,8 @@ mod error; mod tests; use client::{self, Client}; -use primitives::relay::block; -use primitives::contract::{StorageKey, StorageData}; +use primitives::block; +use primitives::storage::{StorageKey, StorageData}; use state_machine; use self::error::Result; diff --git a/substrate/runtime-std/with_std.rs b/substrate/runtime-std/with_std.rs index 1d5b779a03..01212679fc 100644 --- a/substrate/runtime-std/with_std.rs +++ b/substrate/runtime-std/with_std.rs @@ -21,3 +21,5 @@ pub use std::boxed; pub use std::slice; pub use std::mem; pub use std::ops; +pub use std::iter; +pub use std::ptr; diff --git a/substrate/runtime-std/without_std.rs b/substrate/runtime-std/without_std.rs index 203ee02e82..ea0f278d37 100644 --- a/substrate/runtime-std/without_std.rs +++ b/substrate/runtime-std/without_std.rs @@ -24,3 +24,5 @@ pub use core::mem; pub use core::slice; pub use core::cell; pub use core::ops; +pub use core::iter; +pub use core::ptr; diff --git a/substrate/wasm-runtime/polkadot/src/runtime/governance.rs b/substrate/wasm-runtime/polkadot/src/runtime/governance.rs index 53c4369ffd..4b62d11a95 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/governance.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/governance.rs @@ -148,7 +148,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; use support::{one, two, with_env}; - use primitives::relay::{AccountId, InternalFunction}; + use polkadot_primitives::{AccountId, Proposal}; use runtime::{staking, session}; fn new_test_ext() -> TestExternalities { diff --git a/substrate/wasm-runtime/polkadot/src/runtime/session.rs b/substrate/wasm-runtime/polkadot/src/runtime/session.rs index 302919ac2a..2e3f81b645 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/session.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/session.rs @@ -140,7 +140,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; use support::{one, two, with_env}; - use primitives::relay::AccountId; + use polkadot_primitives::AccountId; use runtime::{consensus, session}; fn simple_setup() -> TestExternalities { diff --git a/substrate/wasm-runtime/polkadot/src/runtime/staking.rs b/substrate/wasm-runtime/polkadot/src/runtime/staking.rs index 356d778733..d6d4065dc9 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/staking.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/staking.rs @@ -216,7 +216,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{KeyedVec, Joiner}; use support::{one, two, with_env}; - use primitives::relay::AccountId; + use polkadot_primitives::AccountId; use runtime::{staking, session}; #[test] diff --git a/substrate/wasm-runtime/polkadot/src/runtime/system.rs b/substrate/wasm-runtime/polkadot/src/runtime/system.rs index aa66c47152..269a9bc31e 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/system.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/system.rs @@ -221,7 +221,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, TestExternalities}; use codec::{Joiner, KeyedVec, Slicable}; use support::{StaticHexInto, HexDisplay, one, two}; - use primitives::relay::{Header, Digest, UncheckedTransaction, Transaction, Function}; + use polkadot_primitives::{Header, Digest, UncheckedTransaction, Transaction, Function}; use runtime::staking; #[test] diff --git a/substrate/wasm-runtime/polkadot/src/support/storage.rs b/substrate/wasm-runtime/polkadot/src/support/storage.rs index e46d48cf1a..3332b7b4cd 100644 --- a/substrate/wasm-runtime/polkadot/src/support/storage.rs +++ b/substrate/wasm-runtime/polkadot/src/support/storage.rs @@ -338,7 +338,7 @@ mod tests { #[test] fn proposals_can_be_stored() { - use primitives::relay::{Proposal, InternalFunction}; + use polkadot_primitives::{Proposal, InternalFunction}; let mut t = TestExternalities { storage: HashMap::new(), }; with_externalities(&mut t, || { let x = Proposal {