Skip to content

Commit

Permalink
Bring runtime API up to date with Substrate master (paritytech#17)
Browse files Browse the repository at this point in the history
* Fixups for 646

* Fixes for API

* For for paritytech#678

* Fix runtime

* Update and build

* Tests build

* Fix tests
  • Loading branch information
gavofyork authored and arkpar committed Sep 12, 2018
1 parent c2938ed commit bde1b09
Show file tree
Hide file tree
Showing 44 changed files with 1,443 additions and 2,136 deletions.
1,564 changes: 795 additions & 769 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ members = [
exclude = [
"runtime/wasm",
"test-parachains/adder/wasm",
"demo/runtime/wasm",
]

[badges]
Expand Down
8 changes: 4 additions & 4 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ log = "0.3"
polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" }
substrate-codec = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-io = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
parity-codec = { git = "https://github.com/paritytech/substrate" }
sr-io = { git = "https://github.com/paritytech/substrate" }
srml-executive = { git = "https://github.com/paritytech/substrate" }
sr-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-executor = { git = "https://github.com/paritytech/substrate" }
Expand Down
108 changes: 25 additions & 83 deletions api/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,22 @@
use client::backend::LocalBackend;
use client::block_builder::BlockBuilder as ClientBlockBuilder;
use client::{self, Client, LocalCallExecutor, CallExecutor};
use codec::{Encode, Decode};
use client::{Client, LocalCallExecutor};
use polkadot_executor::Executor as LocalDispatch;
use substrate_executor::NativeExecutor;
use state_machine::ExecutionManager;

//use runtime::{Block, Header, Address, BlockId};
use runtime::Address;
use primitives::{
AccountId, Block, Header, BlockId, Hash, Index, InherentData,
Block, BlockId,
AccountId, Hash, Index, InherentData,
SessionKey, Timestamp, UncheckedExtrinsic,
};
use primitives::parachain::{DutyRoster, Id as ParaId};
use substrate_primitives::{KeccakHasher, RlpCodec};
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, Error, ErrorKind, Result};

fn call<B, R>(
client: &Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>,
at: &BlockId,
function: &'static str,
input: &[u8])
-> Result<R>
where
R: Decode,
B: LocalBackend<Block, KeccakHasher, RlpCodec>,
{
let parent = at;
let header = Header {
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| {
let mut overlay = Default::default();
let execution_manager = || ExecutionManager::Both(|wasm_result, native_result| {
warn!("Consensus error between wasm and native runtime execution at block {:?}", at);
warn!(" Function {:?}", function);
warn!(" Native result {:?}", native_result);
warn!(" Wasm result {:?}", wasm_result);
wasm_result
});
client.executor().call_at_state(
&state,
&mut overlay,
"initialise_block",
&header.encode(),
execution_manager()
)?;
let (r, _) = client.executor().call_at_state(
&state,
&mut overlay,
function,
input,
execution_manager()
)?;
Ok(R::decode(&mut &r[..])
.ok_or_else(|| client::error::Error::from(client::error::ErrorKind::CallResultDecode(function)))?)
})
}
use substrate_primitives::{Blake2Hasher, RlpCodec};
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Result};

impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, KeccakHasher, RlpCodec> {
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec> {
fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
self.push(extrinsic).map_err(Into::into)
}
Expand All @@ -92,32 +44,31 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> BlockBuilder for ClientBloc
}
}

impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block> {
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, KeccakHasher, RlpCodec>;
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block> {
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec>;

fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
Ok(self.authorities_at(at)?)
}

fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>> {
call(self, at, "validators", &[])
Ok(self.call_api_at(at, "validators", &())?)
}

fn random_seed(&self, at: &BlockId) -> Result<Hash> {
call(self, at, "random_seed", &[])
Ok(self.call_api_at(at, "random_seed", &())?)
}

fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster> {
call(self, at, "duty_roster", &[])
Ok(self.call_api_at(at, "duty_roster", &())?)
}

fn timestamp(&self, at: &BlockId) -> Result<Timestamp> {
call(self, at, "timestamp", &[])
Ok(self.call_api_at(at, "timestamp", &())?)
}

fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool> {
let encoded = block.encode();
let res: Result<()> = call(self, at, "execute_block", &encoded);
let res: Result<()> = self.call_api_at(at, "execute_block", &block).map_err(From::from);
match res {
Ok(_) => Ok(true),
Err(err) => match err.kind() {
Expand All @@ -128,31 +79,23 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L
}

fn index(&self, at: &BlockId, account: AccountId) -> Result<Index> {
account.using_encoded(|encoded| {
call(self, at, "account_nonce", encoded)
})
Ok(self.call_api_at(at, "account_nonce", &account)?)
}

fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>> {
address.using_encoded(|encoded| {
call(self, at, "lookup_address", encoded)
})
Ok(self.call_api_at(at, "lookup_address", &address)?)
}

fn active_parachains(&self, at: &BlockId) -> Result<Vec<ParaId>> {
call(self, at, "active_parachains", &[])
Ok(self.call_api_at(at, "active_parachains", &())?)
}

fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
parachain.using_encoded(|encoded| {
call(self, at, "parachain_code", encoded)
})
Ok(self.call_api_at(at, "parachain_code", &parachain)?)
}

fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
parachain.using_encoded(|encoded| {
call(self, at, "parachain_head", encoded)
})
Ok(self.call_api_at(at, "parachain_head", &parachain)?)
}

fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder> {
Expand All @@ -166,13 +109,11 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L

fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>> {
let runtime_version = self.runtime_version_at(at)?;
(inherent_data, runtime_version.spec_version).using_encoded(|encoded| {
call(self, at, "inherent_extrinsics", encoded)
})
Ok(self.call_api_at(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version))?)
}
}

impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> LocalPolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> LocalPolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
{}

#[cfg(test)]
Expand All @@ -198,7 +139,7 @@ mod tests {
]
}

fn client() -> Client<InMemory<Block, KeccakHasher, RlpCodec>, LocalCallExecutor<InMemory<Block, KeccakHasher, RlpCodec>, NativeExecutor<LocalDispatch>>, Block> {
fn client() -> Client<InMemory<Block, Blake2Hasher, RlpCodec>, LocalCallExecutor<InMemory<Block, Blake2Hasher, RlpCodec>, NativeExecutor<LocalDispatch>>, Block> {
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: LocalDispatch::native_equivalent().to_vec(),
Expand All @@ -215,9 +156,10 @@ mod tests {
parachains: Some(Default::default()),
staking: Some(Default::default()),
timestamp: Some(Default::default()),
treasury: Some(Default::default()),
};

::client::new_in_mem(LocalDispatch::with_heap_pages(8), genesis_config).unwrap()
::client::new_in_mem(LocalDispatch::new(), genesis_config).unwrap()
}

#[test]
Expand Down Expand Up @@ -273,6 +215,6 @@ mod tests {
let client = client();

let id = BlockId::number(0);
assert!(client.random_seed(&id).is_ok());
client.random_seed(&id).unwrap();
}
}
9 changes: 4 additions & 5 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
extern crate polkadot_executor;
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 parity_codec as codec;
extern crate sr_io as runtime_io;
extern crate substrate_client as client;
extern crate substrate_executor as substrate_executor;
extern crate substrate_runtime_executive;
extern crate srml_executive;
extern crate substrate_primitives;
extern crate substrate_runtime_primitives as runtime_primitives;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_state_machine as state_machine;

#[macro_use]
extern crate error_chain;

#[macro_use]
extern crate log;

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions api/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use primitives::{
use runtime::Address;
use primitives::parachain::{DutyRoster, Id as ParaId};
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind};
use substrate_primitives::{KeccakHasher, RlpCodec};
use substrate_primitives::{Blake2Hasher, RlpCodec};

/// Light block builder. TODO: make this work (efficiently)
#[derive(Clone, Copy)]
Expand All @@ -44,9 +44,9 @@ impl BlockBuilder for LightBlockBuilder {
}

/// Remote polkadot API implementation.
pub struct RemotePolkadotApiWrapper<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>>(pub Arc<Client<B, E, Block>>);
pub struct RemotePolkadotApiWrapper<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>>(pub Arc<Client<B, E, Block>>);

impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>> PolkadotApi for RemotePolkadotApiWrapper<B, E> {
impl<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> PolkadotApi for RemotePolkadotApiWrapper<B, E> {
type BlockBuilder = LightBlockBuilder;

fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
Expand Down Expand Up @@ -100,9 +100,9 @@ impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHas
Err(ErrorKind::UnknownRuntime.into())
}

fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<Vec<u8>>> {
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<UncheckedExtrinsic>> {
Err(ErrorKind::UnknownRuntime.into())
}
}

impl<B: RemoteBackend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>> RemotePolkadotApi for RemotePolkadotApiWrapper<B, E> {}
impl<B: RemoteBackend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> RemotePolkadotApi for RemotePolkadotApiWrapper<B, E> {}
2 changes: 1 addition & 1 deletion availability-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = ["Parity Technologies <[email protected]>"]
polkadot-primitives = { path = "../primitives" }
parking_lot = "0.4"
log = "0.3"
substrate-codec = { git = "https://github.com/paritytech/substrate" }
parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
kvdb = { git = "https://github.com/paritytech/parity-common.git" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common.git" }
Expand Down
2 changes: 1 addition & 1 deletion availability-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extern crate polkadot_primitives;
extern crate parking_lot;
extern crate substrate_codec as codec;
extern crate parity_codec as codec;
extern crate substrate_primitives;
extern crate kvdb;
extern crate kvdb_rocksdb;
Expand Down
1 change: 0 additions & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ case $TARGET in
# Install prerequisites and build all wasm projects
./scripts/init.sh
./scripts/build.sh
./scripts/build-demos.sh
;;
esac
3 changes: 1 addition & 2 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ description = "Collator node implementation"
[dependencies]
futures = "0.1.17"
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-codec = { git = "https://github.com/paritytech/substrate" }
parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
polkadot-api = { path = "../api" }
polkadot-runtime = { path = "../runtime", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" }
log = "0.4"
ed25519 = { git = "https://github.com/paritytech/substrate" }
tokio = "0.1.7"
4 changes: 2 additions & 2 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
extern crate futures;
extern crate substrate_client as client;
extern crate substrate_codec as codec;
extern crate parity_codec as codec;
extern crate substrate_primitives as primitives;
extern crate ed25519;
extern crate tokio;

extern crate polkadot_api;
Expand All @@ -67,6 +66,7 @@ use std::time::{Duration, Instant};
use futures::{future, stream, Stream, Future, IntoFuture};
use client::BlockchainEvents;
use polkadot_api::PolkadotApi;
use primitives::ed25519;
use polkadot_primitives::{AccountId, BlockId, SessionKey};
use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId};
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration};
Expand Down
7 changes: 3 additions & 4 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ authors = ["Parity Technologies <[email protected]>"]
futures = "0.1.17"
parking_lot = "0.4"
tokio = "0.1.7"
ed25519 = { git = "https://github.com/paritytech/substrate" }
error-chain = "0.12"
log = "0.3"
exit-future = "0.1"
Expand All @@ -20,11 +19,11 @@ polkadot-runtime = { path = "../runtime" }
polkadot-statement-table = { path = "../statement-table" }
polkadot-transaction-pool = { path = "../transaction-pool" }
substrate-bft = { git = "https://github.com/paritytech/substrate" }
substrate-codec = { git = "https://github.com/paritytech/substrate" }
parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-support = { git = "https://github.com/paritytech/substrate" }
srml-support = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
sr-primitives = { git = "https://github.com/paritytech/substrate" }

[dev-dependencies]
substrate-keyring = { git = "https://github.com/paritytech/substrate" }
Loading

0 comments on commit bde1b09

Please sign in to comment.