diff --git a/polkadot/api/src/full.rs b/polkadot/api/src/full.rs index 6b3035e5da..7c39bc3c6c 100644 --- a/polkadot/api/src/full.rs +++ b/polkadot/api/src/full.rs @@ -20,7 +20,7 @@ use client::backend::{Backend, LocalBackend}; use client::block_builder::BlockBuilder as ClientBlockBuilder; use client::{Client, LocalCallExecutor}; use polkadot_executor::Executor as LocalDispatch; -use substrate_executor::{NativeExecutionDispatch, NativeExecutor}; +use substrate_executor::NativeExecutor; use state_machine; use runtime::Address; @@ -28,23 +28,13 @@ use runtime_primitives::traits::AuxLookup; 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(crate) BlockId); - -impl CheckedBlockId for CheckedId { - fn block_id(&self) -> &BlockId { - &self.0 - } -} +use {BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Error, Result}; // set up the necessary scaffolding to execute a set of calls to the runtime. // this creates a new block on top of the given ID and initialises it. macro_rules! with_runtime { ($client: ident, $at: expr, $exec: expr) => {{ - let parent = $at.block_id(); + let parent = $at; let header = Header { parent_hash: $client.block_hash_from_id(&parent)? .ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))?, @@ -83,39 +73,29 @@ impl> BlockBuilder for ClientBlockBuilder> PolkadotApi for Client>, Block> where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { - type CheckedBlockId = CheckedId; 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.into())? != LocalDispatch::native_equivalent() { - bail!("This node is out of date. Block authoring may not work correctly. Bailing.") - } - - Ok(CheckedId(id)) - } - - fn session_keys(&self, at: &CheckedId) -> Result> { + fn session_keys(&self, at: &BlockId) -> Result> { with_runtime!(self, at, ::runtime::Consensus::authorities) } - fn validators(&self, at: &CheckedId) -> Result> { + fn validators(&self, at: &BlockId) -> Result> { with_runtime!(self, at, ::runtime::Session::validators) } - fn random_seed(&self, at: &CheckedId) -> Result { + fn random_seed(&self, at: &BlockId) -> Result { with_runtime!(self, at, ::runtime::System::random_seed) } - fn duty_roster(&self, at: &CheckedId) -> Result { + fn duty_roster(&self, at: &BlockId) -> Result { with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster) } - fn timestamp(&self, at: &CheckedId) -> Result { + fn timestamp(&self, at: &BlockId) -> Result { with_runtime!(self, at, ::runtime::Timestamp::get) } - fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result { + fn evaluate_block(&self, at: &BlockId, block: Block) -> Result { use substrate_executor::error::ErrorKind as ExecErrorKind; use codec::Slicable; use runtime::Block as RuntimeBlock; @@ -136,28 +116,28 @@ impl> PolkadotApi for Client Result { + fn index(&self, at: &BlockId, account: AccountId) -> Result { with_runtime!(self, at, || ::runtime::System::account_nonce(account)) } - fn lookup(&self, at: &Self::CheckedBlockId, address: Address) -> Result> { + fn lookup(&self, at: &BlockId, address: Address) -> Result> { with_runtime!(self, at, || <::runtime::Staking as AuxLookup>::lookup(address).ok()) } - fn active_parachains(&self, at: &CheckedId) -> Result> { + fn active_parachains(&self, at: &BlockId) -> Result> { with_runtime!(self, at, ::runtime::Parachains::active_parachains) } - fn parachain_code(&self, at: &CheckedId, parachain: ParaId) -> Result>> { + fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result>> { with_runtime!(self, at, || ::runtime::Parachains::parachain_code(parachain)) } - fn parachain_head(&self, at: &CheckedId, parachain: ParaId) -> Result>> { + fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result>> { with_runtime!(self, at, || ::runtime::Parachains::parachain_head(parachain)) } - fn build_block(&self, at: &CheckedId, timestamp: Timestamp, new_heads: Vec) -> Result { - let mut block_builder = self.new_block_at(at.block_id())?; + fn build_block(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec) -> Result { + let mut block_builder = self.new_block_at(at)?; for inherent in self.inherent_extrinsics(at, timestamp, new_heads)? { block_builder.push(inherent)?; } @@ -165,7 +145,7 @@ impl> PolkadotApi for Client) -> Result> { + fn inherent_extrinsics(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec) -> Result> { use codec::Slicable; with_runtime!(self, at, || { @@ -231,7 +211,7 @@ mod tests { #[test] fn gets_session_and_validator_keys() { let client = client(); - let id = client.check_id(BlockId::number(0)).unwrap(); + let id = BlockId::number(0); assert_eq!(client.session_keys(&id).unwrap(), session_keys()); assert_eq!(client.validators(&id).unwrap(), validators()); } @@ -240,7 +220,7 @@ mod tests { fn build_block_implicit_succeeds() { let client = client(); - let id = client.check_id(BlockId::number(0)).unwrap(); + let id = BlockId::number(0); let block_builder = client.build_block(&id, 1_000_000, Vec::new()).unwrap(); let block = block_builder.bake().unwrap(); @@ -252,10 +232,10 @@ mod tests { fn build_block_with_inherent_succeeds() { let client = client(); - let id = client.check_id(BlockId::number(0)).unwrap(); + let id = BlockId::number(0); let inherent = client.inherent_extrinsics(&id, 1_000_000, Vec::new()).unwrap(); - let mut block_builder = client.new_block_at(id.block_id()).unwrap(); + let mut block_builder = client.new_block_at(&id).unwrap(); for extrinsic in inherent { block_builder.push(extrinsic).unwrap(); } @@ -266,16 +246,11 @@ mod tests { assert!(block.header.extrinsics_root != Default::default()); } - #[test] - fn fails_to_check_id_for_unknown_block() { - 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 = BlockId::number(0); assert!(client.random_seed(&id).is_ok()); } } diff --git a/polkadot/api/src/lib.rs b/polkadot/api/src/lib.rs index 81e3b02420..27bea18a0d 100644 --- a/polkadot/api/src/lib.rs +++ b/polkadot/api/src/lib.rs @@ -77,12 +77,6 @@ impl From for Error { } } -/// 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. @@ -96,57 +90,49 @@ pub trait BlockBuilder { /// /// 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 block builder for this API type. type BlockBuilder: BlockBuilder; - /// Check whether requests at the given block ID can be served. - /// - /// It should not be possible to instantiate this type without going - /// through this function. - fn check_id(&self, id: BlockId) -> Result; - /// Get session keys at a given block. - fn session_keys(&self, at: &Self::CheckedBlockId) -> Result>; + fn session_keys(&self, at: &BlockId) -> Result>; /// Get validators at a given block. - fn validators(&self, at: &Self::CheckedBlockId) -> Result>; + fn validators(&self, at: &BlockId) -> Result>; /// Get the value of the randomness beacon at a given block. - fn random_seed(&self, at: &Self::CheckedBlockId) -> Result; + fn random_seed(&self, at: &BlockId) -> Result; /// Get the authority duty roster at a block. - fn duty_roster(&self, at: &Self::CheckedBlockId) -> Result; + fn duty_roster(&self, at: &BlockId) -> Result; /// Get the timestamp registered at a block. - fn timestamp(&self, at: &Self::CheckedBlockId) -> Result; + fn timestamp(&self, at: &BlockId) -> Result; /// Get the nonce (né index) of an account at a block. - fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result; + fn index(&self, at: &BlockId, account: AccountId) -> Result; /// Get the account id of an address at a block. - fn lookup(&self, at: &Self::CheckedBlockId, address: Address) -> Result>; + fn lookup(&self, at: &BlockId, address: Address) -> Result>; /// Get the active parachains at a block. - fn active_parachains(&self, at: &Self::CheckedBlockId) -> Result>; + fn active_parachains(&self, at: &BlockId) -> Result>; /// Get the validation code of a parachain at a block. If the parachain is active, this will always return `Some`. - fn parachain_code(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result>>; + fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result>>; /// Get the chain head of a parachain. If the parachain is active, this will always return `Some`. - fn parachain_head(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result>>; + fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result>>; /// Evaluate a block. Returns true if the block is good, false if it is known to be bad, /// and an error if we can't evaluate for some reason. - fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result; + fn evaluate_block(&self, at: &BlockId, block: Block) -> 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; + fn build_block(&self, at: &BlockId, 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>; + fn inherent_extrinsics(&self, at: &BlockId, 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 6a4f1f0322..e20c1a245e 100644 --- a/polkadot/api/src/light.rs +++ b/polkadot/api/src/light.rs @@ -24,8 +24,7 @@ use state_machine; use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic}; use runtime::Address; use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId}; -use full::CheckedId; -use {PolkadotApi, BlockBuilder, RemotePolkadotApi, CheckedBlockId, Result, ErrorKind}; +use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind}; /// Light block builder. TODO: make this work (efficiently) #[derive(Clone, Copy)] @@ -47,65 +46,60 @@ pub struct RemotePolkadotApiWrapper, E: CallExecutor>(p impl, E: CallExecutor> PolkadotApi for RemotePolkadotApiWrapper where ::client::error::Error: From<<>::State as state_machine::backend::Backend>::Error> { - type CheckedBlockId = CheckedId; type BlockBuilder = LightBlockBuilder; - fn check_id(&self, id: BlockId) -> Result { - Ok(CheckedId(id)) - } - - fn session_keys(&self, at: &CheckedId) -> Result> { - self.0.executor().call(at.block_id(), "authorities", &[]) + fn session_keys(&self, at: &BlockId) -> Result> { + self.0.executor().call(at, "authorities", &[]) .and_then(|r| Vec::::decode(&mut &r.return_data[..]) .ok_or("error decoding session keys".into())) .map_err(Into::into) } - fn validators(&self, _at: &CheckedId) -> Result> { + fn validators(&self, _at: &BlockId) -> Result> { Err(ErrorKind::UnknownRuntime.into()) } - fn random_seed(&self, _at: &Self::CheckedBlockId) -> Result { + fn random_seed(&self, _at: &BlockId) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn duty_roster(&self, _at: &CheckedId) -> Result { + fn duty_roster(&self, _at: &BlockId) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn timestamp(&self, _at: &CheckedId) -> Result { + fn timestamp(&self, _at: &BlockId) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn evaluate_block(&self, _at: &CheckedId, _block: Block) -> Result { + fn evaluate_block(&self, _at: &BlockId, _block: Block) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn index(&self, _at: &CheckedId, _account: AccountId) -> Result { + fn index(&self, _at: &BlockId, _account: AccountId) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn lookup(&self, _at: &CheckedId, _address: Address) -> Result> { + fn lookup(&self, _at: &BlockId, _address: Address) -> Result> { Err(ErrorKind::UnknownRuntime.into()) } - fn active_parachains(&self, _at: &Self::CheckedBlockId) -> Result> { + fn active_parachains(&self, _at: &BlockId) -> Result> { Err(ErrorKind::UnknownRuntime.into()) } - fn parachain_code(&self, _at: &Self::CheckedBlockId, _parachain: ParaId) -> Result>> { + fn parachain_code(&self, _at: &BlockId, _parachain: ParaId) -> Result>> { Err(ErrorKind::UnknownRuntime.into()) } - fn parachain_head(&self, _at: &Self::CheckedBlockId, _parachain: ParaId) -> Result>> { + fn parachain_head(&self, _at: &BlockId, _parachain: ParaId) -> Result>> { Err(ErrorKind::UnknownRuntime.into()) } - fn build_block(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result { + fn build_block(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result { Err(ErrorKind::UnknownRuntime.into()) } - fn inherent_extrinsics(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result>> { + fn inherent_extrinsics(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result>> { Err(ErrorKind::UnknownRuntime.into()) } } diff --git a/polkadot/consensus/src/collation.rs b/polkadot/consensus/src/collation.rs index 3738ae9004..f0b1f626c6 100644 --- a/polkadot/consensus/src/collation.rs +++ b/polkadot/consensus/src/collation.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use polkadot_api::PolkadotApi; -use polkadot_primitives::{Hash, AccountId}; +use polkadot_primitives::{Hash, AccountId, BlockId}; use polkadot_primitives::parachain::{Id as ParaId, Chain, BlockData, Extrinsic, CandidateReceipt}; use futures::prelude::*; @@ -57,7 +57,7 @@ pub trait Collators: Clone { pub struct CollationFetch { parachain: Option, relay_parent_hash: Hash, - relay_parent: P::CheckedBlockId, + relay_parent: BlockId, collators: C, live_fetch: Option<::Future>, client: Arc

, @@ -65,7 +65,7 @@ pub struct CollationFetch { impl CollationFetch { /// Create a new collation fetcher for the given chain. - pub fn new(parachain: Chain, relay_parent: P::CheckedBlockId, relay_parent_hash: Hash, collators: C, client: Arc

) -> Self { + pub fn new(parachain: Chain, relay_parent: BlockId, relay_parent_hash: Hash, collators: C, client: Arc

) -> Self { CollationFetch { relay_parent_hash, relay_parent, @@ -145,7 +145,7 @@ error_chain! { } /// Check whether a given collation is valid. Returns `Ok` on success, error otherwise. -pub fn validate_collation(client: &P, relay_parent: &P::CheckedBlockId, collation: &Collation) -> Result<(), Error> { +pub fn validate_collation(client: &P, relay_parent: &BlockId, collation: &Collation) -> Result<(), Error> { use parachain::{self, ValidationParams}; let para_id = collation.receipt.parachain_index; diff --git a/polkadot/consensus/src/lib.rs b/polkadot/consensus/src/lib.rs index 4fb8fc4090..c75d8ac6ee 100644 --- a/polkadot/consensus/src/lib.rs +++ b/polkadot/consensus/src/lib.rs @@ -240,7 +240,6 @@ pub struct ProposerFactory { impl bft::ProposerFactory for ProposerFactory where C: PolkadotApi + Send + Sync, - C::CheckedBlockId: Sync, N: Network, P: Collators, { @@ -254,9 +253,9 @@ impl bft::ProposerFactory for ProposerFactory 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)?; - let random_seed = self.client.random_seed(&checked_id)?; + let id = BlockId::hash(parent_hash); + let duty_roster = self.client.duty_roster(&id)?; + let random_seed = self.client.random_seed(&id)?; let (group_info, local_duty) = make_group_info( duty_roster, @@ -264,7 +263,7 @@ impl bft::ProposerFactory for ProposerFactory sign_with.public().into(), )?; - let active_parachains = self.client.active_parachains(&checked_id)?; + let active_parachains = self.client.active_parachains(&id)?; let n_parachains = active_parachains.len(); let table = Arc::new(SharedTable::new(group_info, sign_with.clone(), parent_hash)); @@ -291,7 +290,7 @@ impl bft::ProposerFactory for ProposerFactory local_duty, local_key: sign_with, parent_hash, - parent_id: checked_id, + parent_id: id, parent_number: parent_header.number, random_seed, router, @@ -315,7 +314,7 @@ pub struct Proposer { local_duty: LocalDuty, local_key: Arc, parent_hash: Hash, - parent_id: C::CheckedBlockId, + parent_id: BlockId, parent_number: BlockNumber, random_seed: Hash, router: R, @@ -326,7 +325,6 @@ pub struct Proposer { impl bft::Proposer for Proposer where C: PolkadotApi + Send + Sync, - C::CheckedBlockId: Sync, R: TableRouter, P: Collators, { @@ -621,7 +619,7 @@ impl ProposalTiming { pub struct CreateProposal { parent_hash: Hash, parent_number: BlockNumber, - parent_id: C::CheckedBlockId, + parent_id: BlockId, client: Arc, transaction_pool: Arc>, collation: CollationFetch, diff --git a/polkadot/consensus/src/service.rs b/polkadot/consensus/src/service.rs index f761c51d01..494e785809 100644 --- a/polkadot/consensus/src/service.rs +++ b/polkadot/consensus/src/service.rs @@ -242,7 +242,6 @@ impl Service { where A: LocalPolkadotApi + Send + Sync + 'static, C: BlockchainEvents + ChainHead + bft::BlockImport + bft::Authorities + Send + Sync + 'static, - A::CheckedBlockId: Sync, { let (signal, exit) = ::exit_future::signal(); let thread = thread::spawn(move || { diff --git a/polkadot/executor/src/lib.rs b/polkadot/executor/src/lib.rs index be44d8afba..82cd5cd478 100644 --- a/polkadot/executor/src/lib.rs +++ b/polkadot/executor/src/lib.rs @@ -20,4 +20,4 @@ extern crate polkadot_runtime; #[macro_use] extern crate substrate_executor; -native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm")); +native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, polkadot_runtime::VERSION, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm")); diff --git a/polkadot/runtime/Cargo.toml b/polkadot/runtime/Cargo.toml index 9ac1f50175..4068595601 100644 --- a/polkadot/runtime/Cargo.toml +++ b/polkadot/runtime/Cargo.toml @@ -26,6 +26,7 @@ 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" } +substrate-runtime-version = { path = "../../substrate/runtime/version" } [dev-dependencies] hex-literal = "0.1.0" @@ -48,6 +49,7 @@ std = [ "substrate-runtime-staking/std", "substrate-runtime-system/std", "substrate-runtime-timestamp/std", + "substrate-runtime-version/std", "serde_derive", "serde/std", "log", diff --git a/polkadot/runtime/src/lib.rs b/polkadot/runtime/src/lib.rs index 6452aadcfd..532de07cd7 100644 --- a/polkadot/runtime/src/lib.rs +++ b/polkadot/runtime/src/lib.rs @@ -56,6 +56,8 @@ 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; +#[macro_use] +extern crate substrate_runtime_version as version; #[cfg(feature = "std")] mod checked_block; @@ -69,6 +71,7 @@ pub use staking::address::Address as RawAddress; use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature}; use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}}; +use version::RuntimeVersion; #[cfg(feature = "std")] pub use runtime_primitives::BuildStorage; @@ -102,6 +105,22 @@ pub type Block = generic::Block; #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] pub struct Concrete; +/// Polkadot runtime version. +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: ver_str!("polkadot"), + impl_name: ver_str!("parity-polkadot"), + authoring_version: 0, + spec_version: 0, + impl_version: 0, +}; + +impl version::Trait for Concrete { + const VERSION: RuntimeVersion = VERSION; +} + +/// Version module for this concrete runtime. +pub type Version = version::Module; + impl HasPublicAux for Concrete { type PublicAux = AccountId; // TODO: Option } @@ -221,6 +240,7 @@ impl_outer_config! { pub mod api { impl_stubs!( + version => |()| super::Version::version(), authorities => |()| super::Consensus::authorities(), initialise_block => |header| super::Executive::initialise_block(&header), apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic), diff --git a/polkadot/runtime/wasm/Cargo.lock b/polkadot/runtime/wasm/Cargo.lock index 82cbbb68e9..b5b23aa1d4 100644 --- a/polkadot/runtime/wasm/Cargo.lock +++ b/polkadot/runtime/wasm/Cargo.lock @@ -485,6 +485,7 @@ dependencies = [ "substrate-runtime-support 0.1.0", "substrate-runtime-system 0.1.0", "substrate-runtime-timestamp 0.1.0", + "substrate-runtime-version 0.1.0", ] [[package]] @@ -972,6 +973,17 @@ dependencies = [ "substrate-runtime-system 0.1.0", ] +[[package]] +name = "substrate-runtime-version" +version = "0.1.0" +dependencies = [ + "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", + "substrate-runtime-support 0.1.0", +] + [[package]] name = "substrate-state-machine" version = "0.1.0" diff --git a/polkadot/runtime/wasm/Cargo.toml b/polkadot/runtime/wasm/Cargo.toml index f5dc280e6f..3a73d89400 100644 --- a/polkadot/runtime/wasm/Cargo.toml +++ b/polkadot/runtime/wasm/Cargo.toml @@ -24,6 +24,7 @@ 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 } +substrate-runtime-version = { path = "../../../substrate/runtime/version", default-features = false } [features] default = [] @@ -44,6 +45,7 @@ std = [ "substrate-runtime-staking/std", "substrate-runtime-system/std", "substrate-runtime-timestamp/std", + "substrate-runtime-version/std", ] [profile.release] diff --git a/polkadot/runtime/wasm/genesis.wasm b/polkadot/runtime/wasm/genesis.wasm index 07c28e8cff..c862998de6 100644 Binary files a/polkadot/runtime/wasm/genesis.wasm and b/polkadot/runtime/wasm/genesis.wasm differ 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 5010850d88..f114ea539b 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 77c56b6c0a..0794dc20ff 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/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index 1fab5d481e..5f344035ce 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -180,7 +180,7 @@ impl txpool::Scoring for Scoring { /// Readiness evaluator for polkadot transactions. pub struct Ready<'a, A: 'a + PolkadotApi> { - at_block: A::CheckedBlockId, + at_block: BlockId, api: &'a A, known_nonces: HashMap, } @@ -188,7 +188,7 @@ pub struct Ready<'a, A: 'a + PolkadotApi> { impl<'a, A: 'a + PolkadotApi> Ready<'a, A> { /// Create a new readiness evaluator at the given block. Requires that /// the ID has already been checked for local corresponding and available state. - fn create(at: A::CheckedBlockId, api: &'a A) -> Self { + fn create(at: BlockId, api: &'a A) -> Self { Ready { at_block: at, api, @@ -244,12 +244,12 @@ impl<'a, A: 'a + PolkadotApi> txpool::Ready for Ready<'a, A } } -pub struct Verifier<'a, A: 'a, B> { +pub struct Verifier<'a, A: 'a> { api: &'a A, - at_block: B, + at_block: BlockId, } -impl<'a, A> Verifier<'a, A, A::CheckedBlockId> where +impl<'a, A> Verifier<'a, A> where A: 'a + PolkadotApi, { const NO_ACCOUNT: &'static str = "Account not found."; @@ -267,7 +267,7 @@ impl<'a, A> Verifier<'a, A, A::CheckedBlockId> where } } -impl<'a, A> txpool::Verifier for Verifier<'a, A, A::CheckedBlockId> where +impl<'a, A> txpool::Verifier for Verifier<'a, A> where A: 'a + PolkadotApi, { type VerifiedTransaction = VerifiedTransaction; @@ -322,7 +322,7 @@ impl TransactionPool where pub fn import_unchecked_extrinsic(&self, block: BlockId, uxt: UncheckedExtrinsic) -> Result> { let verifier = Verifier { api: &*self.api, - at_block: self.api.check_id(block)?, + at_block: block, }; self.inner.submit(verifier, vec![uxt]).map(|mut v| v.swap_remove(0)) } @@ -332,7 +332,7 @@ impl TransactionPool where let to_reverify = self.inner.remove_sender(None); let verifier = Verifier { api: &*self.api, - at_block: self.api.check_id(block)?, + at_block: block, }; self.inner.submit(verifier, to_reverify.into_iter().map(|tx| tx.original.clone()))?; @@ -358,8 +358,7 @@ impl TransactionPool where /// Cull old transactions from the queue. pub fn cull(&self, block: BlockId) -> Result { - let id = self.api.check_id(block)?; - let ready = Ready::create(id, &*self.api); + let ready = Ready::create(block, &*self.api); Ok(self.inner.cull(None, ready)) } @@ -367,8 +366,7 @@ impl TransactionPool where pub fn cull_and_get_pending(&self, block: BlockId, f: F) -> Result where F: FnOnce(txpool::PendingIterator, Scoring, Listener>) -> T, { - let id = self.api.check_id(block)?; - let ready = Ready::create(id, &*self.api); + let ready = Ready::create(block, &*self.api); self.inner.cull(None, ready.clone()); Ok(self.inner.pending(ready, f)) } @@ -413,7 +411,7 @@ mod tests { use super::TransactionPool; use substrate_keyring::Keyring::{self, *}; use codec::Slicable; - use polkadot_api::{PolkadotApi, BlockBuilder, CheckedBlockId, Result}; + use polkadot_api::{PolkadotApi, BlockBuilder, Result}; use primitives::{AccountId, AccountIndex, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic as FutureProofUncheckedExtrinsic}; use runtime::{RawAddress, Call, TimestampCall, BareExtrinsic, Extrinsic, UncheckedExtrinsic}; @@ -426,15 +424,9 @@ mod tests { fn bake(self) -> Result { unimplemented!() } } - #[derive(Clone)] - struct TestCheckedBlockId(pub BlockId); - impl CheckedBlockId for TestCheckedBlockId { - fn block_id(&self) -> &BlockId { &self.0 } - } - - fn number_of(at: &TestCheckedBlockId) -> u32 { - match at.0 { - generic::BlockId::Number(n) => n as u32, + fn number_of(at: &BlockId) -> u32 { + match at { + generic::BlockId::Number(n) => *n as u32, _ => 0, } } @@ -457,26 +449,24 @@ mod tests { } impl PolkadotApi for TestPolkadotApi { - type CheckedBlockId = TestCheckedBlockId; type BlockBuilder = TestBlockBuilder; - fn check_id(&self, id: BlockId) -> Result { Ok(TestCheckedBlockId(id)) } - fn session_keys(&self, _at: &TestCheckedBlockId) -> Result> { unimplemented!() } - fn validators(&self, _at: &TestCheckedBlockId) -> Result> { unimplemented!() } - fn random_seed(&self, _at: &TestCheckedBlockId) -> Result { unimplemented!() } - fn duty_roster(&self, _at: &TestCheckedBlockId) -> Result { unimplemented!() } - fn timestamp(&self, _at: &TestCheckedBlockId) -> Result { unimplemented!() } - fn evaluate_block(&self, _at: &TestCheckedBlockId, _block: Block) -> Result { unimplemented!() } - fn active_parachains(&self, _at: &TestCheckedBlockId) -> Result> { unimplemented!() } - fn parachain_code(&self, _at: &TestCheckedBlockId, _parachain: ParaId) -> Result>> { unimplemented!() } - fn parachain_head(&self, _at: &TestCheckedBlockId, _parachain: ParaId) -> Result>> { unimplemented!() } - fn build_block(&self, _at: &TestCheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result { unimplemented!() } - fn inherent_extrinsics(&self, _at: &TestCheckedBlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result>> { unimplemented!() } + fn session_keys(&self, _at: &BlockId) -> Result> { unimplemented!() } + fn validators(&self, _at: &BlockId) -> Result> { unimplemented!() } + fn random_seed(&self, _at: &BlockId) -> Result { unimplemented!() } + fn duty_roster(&self, _at: &BlockId) -> Result { unimplemented!() } + fn timestamp(&self, _at: &BlockId) -> Result { unimplemented!() } + fn evaluate_block(&self, _at: &BlockId, _block: Block) -> Result { unimplemented!() } + fn active_parachains(&self, _at: &BlockId) -> Result> { unimplemented!() } + fn parachain_code(&self, _at: &BlockId, _parachain: ParaId) -> Result>> { unimplemented!() } + fn parachain_head(&self, _at: &BlockId, _parachain: ParaId) -> Result>> { unimplemented!() } + fn build_block(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result { unimplemented!() } + fn inherent_extrinsics(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec) -> Result>> { unimplemented!() } - fn index(&self, _at: &TestCheckedBlockId, _account: AccountId) -> Result { + fn index(&self, _at: &BlockId, _account: AccountId) -> Result { Ok((_account[0] as u32) + number_of(_at)) } - fn lookup(&self, _at: &TestCheckedBlockId, _address: RawAddress) -> Result> { + fn lookup(&self, _at: &BlockId, _address: RawAddress) -> Result> { match _address { RawAddress::Id(i) => Ok(Some(i)), RawAddress::Index(_) if self.no_lookup.load(atomic::Ordering::SeqCst) => Ok(None),