diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index 8fa34c3a02..c7c10f9e5d 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -12,7 +12,7 @@ log = "0.3" hex-literal = "0.1" triehash = "0.1" ed25519 = { path = "../../substrate/ed25519" } -app_dirs = "1.2" +app_dirs = "1.2.1" substrate-client = { path = "../../substrate/client" } substrate-codec = { path = "../../substrate/codec" } substrate-runtime-io = { path = "../../substrate/runtime-io" } diff --git a/polkadot/consensus/Cargo.toml b/polkadot/consensus/Cargo.toml index df49b2a1cf..103ae1a913 100644 --- a/polkadot/consensus/Cargo.toml +++ b/polkadot/consensus/Cargo.toml @@ -18,8 +18,8 @@ polkadot-transaction-pool = { path = "../transaction-pool" } substrate-bft = { path = "../../substrate/bft" } substrate-codec = { path = "../../substrate/codec" } substrate-primitives = { path = "../../substrate/primitives" } +substrate-runtime-support = { path = "../../substrate/runtime-support" } substrate-network = { path = "../../substrate/network" } - tokio-core = "0.1.12" substrate-keyring = { path = "../../substrate/keyring" } substrate-client = { path = "../../substrate/client" } diff --git a/polkadot/consensus/src/lib.rs b/polkadot/consensus/src/lib.rs index 8ee93bafa8..ba1e05b05e 100644 --- a/polkadot/consensus/src/lib.rs +++ b/polkadot/consensus/src/lib.rs @@ -41,6 +41,7 @@ extern crate polkadot_transaction_pool as transaction_pool; 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_network; extern crate tokio_core; @@ -58,6 +59,7 @@ use std::sync::Arc; use codec::Slicable; use table::{Table, Context as TableContextTrait}; use table::generic::Statement as GenericStatement; +use runtime_support::Hashable; use polkadot_api::{PolkadotApi, BlockBuilder}; use polkadot_primitives::{Hash, Timestamp}; use polkadot_primitives::block::Block as PolkadotBlock; @@ -480,7 +482,7 @@ impl bft::ProposerFactory for ProposerFactory type Error = Error; fn init(&self, parent_header: &SubstrateHeader, authorities: &[AuthorityId], sign_with: Arc) -> Result { - let parent_hash = parent_header.hash(); + let parent_hash = parent_header.blake2_256().into(); let checked_id = self.client.check_id(BlockId::Hash(parent_hash))?; let duty_roster = self.client.duty_roster(&checked_id)?; diff --git a/polkadot/consensus/src/service.rs b/polkadot/consensus/src/service.rs index 6ef1aa8389..db8c4ee7a5 100644 --- a/polkadot/consensus/src/service.rs +++ b/polkadot/consensus/src/service.rs @@ -26,6 +26,7 @@ use parking_lot::Mutex; use substrate_network as net; use tokio_core::reactor; use client::BlockchainEvents; +use runtime_support::Hashable; use primitives::{Hash, AuthorityId}; use primitives::block::{Id as BlockId, HeaderHash, Header}; use polkadot_primitives::parachain::{BlockData, Extrinsic, CandidateReceipt}; @@ -154,7 +155,7 @@ impl Service { }; let bft_service = BftService::new(client.clone(), key, factory); let build_bft = |header: &Header| -> Result<_, Error> { - let hash = header.hash(); + let hash = header.blake2_256().into(); let authorities = client.authorities(&BlockId::Hash(hash))?; let input = network.bft_messages() .filter_map(move |message| { diff --git a/polkadot/primitives/src/block.rs b/polkadot/primitives/src/block.rs index b2d90a19c0..e74dd19f4c 100644 --- a/polkadot/primitives/src/block.rs +++ b/polkadot/primitives/src/block.rs @@ -49,7 +49,7 @@ impl Slicable for Log { } } -impl ::codec::NonTrivialSlicable for Log { } + /// The digest of a block, useful for light-clients. #[derive(Clone, Default, PartialEq, Eq)] diff --git a/polkadot/primitives/src/parachain.rs b/polkadot/primitives/src/parachain.rs index 34a8b34733..e94ba03d28 100644 --- a/polkadot/primitives/src/parachain.rs +++ b/polkadot/primitives/src/parachain.rs @@ -19,7 +19,7 @@ #[cfg(feature = "std")] use primitives::bytes; use primitives; -use codec::{Input, Slicable, NonTrivialSlicable}; +use codec::{Input, Slicable}; use rstd::cmp::{PartialOrd, Ord, Ordering}; use rstd::vec::Vec; use ::Hash; @@ -59,7 +59,7 @@ pub enum Chain { impl Slicable for Chain { fn decode(input: &mut I) -> Option { - let disc = try_opt!(u8::decode(input)); + let disc = input.read_byte()?; match disc { 0 => Some(Chain::Relay), @@ -71,9 +71,9 @@ impl Slicable for Chain { fn encode(&self) -> Vec { let mut v = Vec::new(); match *self { - Chain::Relay => { 0u8.using_encoded(|s| v.extend(s)); } + Chain::Relay => { v.push(0); } Chain::Parachain(id) => { - 1u8.using_encoded(|s| v.extend(s)); + v.push(1u8); id.using_encoded(|s| v.extend(s)); } } @@ -86,7 +86,7 @@ impl Slicable for Chain { } } -impl NonTrivialSlicable for Chain { } + /// The duty roster specifying what jobs each validator must do. #[derive(Clone, PartialEq)] @@ -317,7 +317,7 @@ impl Slicable for Statement { } fn decode(value: &mut I) -> Option { - match u8::decode(value) { + match value.read_byte() { Some(x) if x == StatementKind::Candidate as u8 => { Slicable::decode(value).map(Statement::Candidate) } diff --git a/polkadot/primitives/src/transaction.rs b/polkadot/primitives/src/transaction.rs index f13cf223a9..f3637034b4 100644 --- a/polkadot/primitives/src/transaction.rs +++ b/polkadot/primitives/src/transaction.rs @@ -94,7 +94,7 @@ pub enum Proposal { impl Slicable for Proposal { fn decode(input: &mut I) -> Option { - let id = try_opt!(u8::decode(input).and_then(InternalFunctionId::from_u8)); + let id = InternalFunctionId::from_u8(input.read_byte()?)?; let function = match id { InternalFunctionId::SystemSetCode => Proposal::SystemSetCode(try_opt!(Slicable::decode(input))), @@ -119,33 +119,33 @@ impl Slicable for Proposal { let mut v = Vec::new(); match *self { Proposal::SystemSetCode(ref data) => { - (InternalFunctionId::SystemSetCode as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::SystemSetCode as u8); data.using_encoded(|s| v.extend(s)); } Proposal::SessionSetLength(ref data) => { - (InternalFunctionId::SessionSetLength as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::SessionSetLength as u8); data.using_encoded(|s| v.extend(s)); } Proposal::SessionForceNewSession => { - (InternalFunctionId::SessionForceNewSession as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::SessionForceNewSession as u8); } Proposal::StakingSetSessionsPerEra(ref data) => { - (InternalFunctionId::StakingSetSessionsPerEra as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::StakingSetSessionsPerEra as u8); data.using_encoded(|s| v.extend(s)); } Proposal::StakingSetBondingDuration(ref data) => { - (InternalFunctionId::StakingSetBondingDuration as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::StakingSetBondingDuration as u8); data.using_encoded(|s| v.extend(s)); } Proposal::StakingSetValidatorCount(ref data) => { - (InternalFunctionId::StakingSetValidatorCount as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::StakingSetValidatorCount as u8); data.using_encoded(|s| v.extend(s)); } Proposal::StakingForceNewEra => { - (InternalFunctionId::StakingForceNewEra as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::StakingForceNewEra as u8); } Proposal::GovernanceSetApprovalPpmRequired(ref data) => { - (InternalFunctionId::GovernanceSetApprovalPpmRequired as u8).using_encoded(|s| v.extend(s)); + v.push(InternalFunctionId::GovernanceSetApprovalPpmRequired as u8); data.using_encoded(|s| v.extend(s)); } } @@ -267,7 +267,7 @@ impl Function { impl Slicable for Function { fn decode(input: &mut I) -> Option { - let id = try_opt!(u8::decode(input).and_then(FunctionId::from_u8)); + let id = FunctionId::from_u8(input.read_byte()?)?; Some(match id { FunctionId::TimestampSet => Function::Inherent(InherentFunction::TimestampSet(try_opt!(Slicable::decode(input)))), @@ -293,34 +293,34 @@ impl Slicable for Function { let mut v = Vec::new(); match *self { Function::Inherent(InherentFunction::TimestampSet(ref data)) => { - (FunctionId::TimestampSet as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::TimestampSet as u8); data.using_encoded(|s| v.extend(s)); } Function::SessionSetKey(ref data) => { - (FunctionId::SessionSetKey as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::SessionSetKey as u8); data.using_encoded(|s| v.extend(s)); } Function::StakingStake => { - (FunctionId::StakingStake as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::StakingStake as u8); } Function::StakingUnstake => { - (FunctionId::StakingUnstake as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::StakingUnstake as u8); } Function::ReportMisbehavior(ref report) => { - (FunctionId::StakingReportMisbehavior as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::StakingReportMisbehavior as u8); report.using_encoded(|s| v.extend(s)); } Function::StakingTransfer(ref to, ref amount) => { - (FunctionId::StakingTransfer as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::StakingTransfer as u8); to.using_encoded(|s| v.extend(s)); amount.using_encoded(|s| v.extend(s)); } Function::GovernancePropose(ref data) => { - (FunctionId::GovernancePropose as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::GovernancePropose as u8); data.using_encoded(|s| v.extend(s)); } Function::GovernanceApprove(ref data) => { - (FunctionId::GovernanceApprove as u8).using_encoded(|s| v.extend(s)); + v.push(FunctionId::GovernanceApprove as u8); data.using_encoded(|s| v.extend(s)); } } @@ -365,7 +365,7 @@ impl Slicable for Transaction { } } -impl ::codec::NonTrivialSlicable for Transaction {} + /// A transactions right from the external world. Unchecked. #[derive(Eq, Clone)] @@ -441,7 +441,7 @@ impl Slicable for UncheckedTransaction { } } -impl ::codec::NonTrivialSlicable for UncheckedTransaction {} + impl PartialEq for UncheckedTransaction { fn eq(&self, other: &Self) -> bool { diff --git a/polkadot/runtime/wasm/Cargo.lock b/polkadot/runtime/wasm/Cargo.lock index d2bf5b3e78..7c2e7ef05b 100644 --- a/polkadot/runtime/wasm/Cargo.lock +++ b/polkadot/runtime/wasm/Cargo.lock @@ -654,8 +654,9 @@ name = "substrate-runtime-support" version = "0.1.0" dependencies = [ "ed25519 0.1.0", - "environmental 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)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", "substrate-runtime-io 0.1.0", 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 a752fb6e21..14e9b61cdb 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 old mode 100755 new mode 100644 index 2dd5cac823..daf9b04682 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