Commit bde1b099 authored by Gav Wood's avatar Gav Wood Committed by Arkadiy Paronyan
Browse files

Bring runtime API up to date with Substrate master (#17)

* Fixups for 646

* Fixes for API

* For for #678

* Fix runtime

* Update and build

* Tests build

* Fix tests
parent c2938ed9
This diff is collapsed.
...@@ -39,7 +39,6 @@ members = [ ...@@ -39,7 +39,6 @@ members = [
exclude = [ exclude = [
"runtime/wasm", "runtime/wasm",
"test-parachains/adder/wasm", "test-parachains/adder/wasm",
"demo/runtime/wasm",
] ]
[badges] [badges]
......
...@@ -9,10 +9,10 @@ log = "0.3" ...@@ -9,10 +9,10 @@ log = "0.3"
polkadot-executor = { path = "../executor" } polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
substrate-codec = { git = "https://github.com/paritytech/substrate" } parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-io = { git = "https://github.com/paritytech/substrate" } sr-io = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate" } srml-executive = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" } sr-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" } substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-executor = { git = "https://github.com/paritytech/substrate" } substrate-executor = { git = "https://github.com/paritytech/substrate" }
......
...@@ -18,70 +18,22 @@ ...@@ -18,70 +18,22 @@
use client::backend::LocalBackend; use client::backend::LocalBackend;
use client::block_builder::BlockBuilder as ClientBlockBuilder; use client::block_builder::BlockBuilder as ClientBlockBuilder;
use client::{self, Client, LocalCallExecutor, CallExecutor}; use client::{Client, LocalCallExecutor};
use codec::{Encode, Decode};
use polkadot_executor::Executor as LocalDispatch; use polkadot_executor::Executor as LocalDispatch;
use substrate_executor::NativeExecutor; use substrate_executor::NativeExecutor;
use state_machine::ExecutionManager;
//use runtime::{Block, Header, Address, BlockId};
use runtime::Address; use runtime::Address;
use primitives::{ use primitives::{
AccountId, Block, Header, BlockId, Hash, Index, InherentData, Block, BlockId,
AccountId, Hash, Index, InherentData,
SessionKey, Timestamp, UncheckedExtrinsic, SessionKey, Timestamp, UncheckedExtrinsic,
}; };
use primitives::parachain::{DutyRoster, Id as ParaId}; use primitives::parachain::{DutyRoster, Id as ParaId};
use substrate_primitives::{KeccakHasher, RlpCodec}; use substrate_primitives::{Blake2Hasher, RlpCodec};
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, Error, ErrorKind, Result}; use {BlockBuilder, PolkadotApi, LocalPolkadotApi, 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)))?)
})
}
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<()> { fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
self.push(extrinsic).map_err(Into::into) self.push(extrinsic).map_err(Into::into)
} }
...@@ -92,32 +44,31 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> BlockBuilder for ClientBloc ...@@ -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> { impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block> {
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, KeccakHasher, RlpCodec>; type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec>;
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> { fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
Ok(self.authorities_at(at)?) Ok(self.authorities_at(at)?)
} }
fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>> { 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> { 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> { 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> { 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> { fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool> {
let encoded = block.encode(); let res: Result<()> = self.call_api_at(at, "execute_block", &block).map_err(From::from);
let res: Result<()> = call(self, at, "execute_block", &encoded);
match res { match res {
Ok(_) => Ok(true), Ok(_) => Ok(true),
Err(err) => match err.kind() { Err(err) => match err.kind() {
...@@ -128,31 +79,23 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L ...@@ -128,31 +79,23 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L
} }
fn index(&self, at: &BlockId, account: AccountId) -> Result<Index> { fn index(&self, at: &BlockId, account: AccountId) -> Result<Index> {
account.using_encoded(|encoded| { Ok(self.call_api_at(at, "account_nonce", &account)?)
call(self, at, "account_nonce", encoded)
})
} }
fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>> { fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>> {
address.using_encoded(|encoded| { Ok(self.call_api_at(at, "lookup_address", &address)?)
call(self, at, "lookup_address", encoded)
})
} }
fn active_parachains(&self, at: &BlockId) -> Result<Vec<ParaId>> { 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>>> { fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
parachain.using_encoded(|encoded| { Ok(self.call_api_at(at, "parachain_code", &parachain)?)
call(self, at, "parachain_code", encoded)
})
} }
fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> { fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
parachain.using_encoded(|encoded| { Ok(self.call_api_at(at, "parachain_head", &parachain)?)
call(self, at, "parachain_head", encoded)
})
} }
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder> { fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder> {
...@@ -166,13 +109,11 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L ...@@ -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>> { fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>> {
let runtime_version = self.runtime_version_at(at)?; let runtime_version = self.runtime_version_at(at)?;
(inherent_data, runtime_version.spec_version).using_encoded(|encoded| { Ok(self.call_api_at(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version))?)
call(self, at, "inherent_extrinsics", encoded)
})
} }
} }
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)] #[cfg(test)]
...@@ -198,7 +139,7 @@ mod tests { ...@@ -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 { let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig { consensus: Some(ConsensusConfig {
code: LocalDispatch::native_equivalent().to_vec(), code: LocalDispatch::native_equivalent().to_vec(),
...@@ -215,9 +156,10 @@ mod tests { ...@@ -215,9 +156,10 @@ mod tests {
parachains: Some(Default::default()), parachains: Some(Default::default()),
staking: Some(Default::default()), staking: Some(Default::default()),
timestamp: 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] #[test]
...@@ -273,6 +215,6 @@ mod tests { ...@@ -273,6 +215,6 @@ mod tests {
let client = client(); let client = client();
let id = BlockId::number(0); let id = BlockId::number(0);
assert!(client.random_seed(&id).is_ok()); client.random_seed(&id).unwrap();
} }
} }
...@@ -20,19 +20,18 @@ ...@@ -20,19 +20,18 @@
extern crate polkadot_executor; extern crate polkadot_executor;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
extern crate polkadot_runtime as runtime; extern crate polkadot_runtime as runtime;
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate substrate_runtime_io as runtime_io; extern crate sr_io as runtime_io;
extern crate substrate_client as client; extern crate substrate_client as client;
extern crate substrate_executor as substrate_executor; extern crate substrate_executor as substrate_executor;
extern crate substrate_runtime_executive; extern crate srml_executive;
extern crate substrate_primitives; 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; extern crate substrate_state_machine as state_machine;
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
#[macro_use]
extern crate log; extern crate log;
#[cfg(test)] #[cfg(test)]
......
...@@ -27,7 +27,7 @@ use primitives::{ ...@@ -27,7 +27,7 @@ use primitives::{
use runtime::Address; use runtime::Address;
use primitives::parachain::{DutyRoster, Id as ParaId}; use primitives::parachain::{DutyRoster, Id as ParaId};
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind}; use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind};
use substrate_primitives::{KeccakHasher, RlpCodec}; use substrate_primitives::{Blake2Hasher, RlpCodec};
/// Light block builder. TODO: make this work (efficiently) /// Light block builder. TODO: make this work (efficiently)
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
...@@ -44,9 +44,9 @@ impl BlockBuilder for LightBlockBuilder { ...@@ -44,9 +44,9 @@ impl BlockBuilder for LightBlockBuilder {
} }
/// Remote polkadot API implementation. /// 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; type BlockBuilder = LightBlockBuilder;
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> { fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
...@@ -100,9 +100,9 @@ impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHas ...@@ -100,9 +100,9 @@ impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHas
Err(ErrorKind::UnknownRuntime.into()) 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()) 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> {}
...@@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"] ...@@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
parking_lot = "0.4" parking_lot = "0.4"
log = "0.3" 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" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
kvdb = { git = "https://github.com/paritytech/parity-common.git" } kvdb = { git = "https://github.com/paritytech/parity-common.git" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common.git" } kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common.git" }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
extern crate polkadot_primitives; extern crate polkadot_primitives;
extern crate parking_lot; extern crate parking_lot;
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate substrate_primitives; extern crate substrate_primitives;
extern crate kvdb; extern crate kvdb;
extern crate kvdb_rocksdb; extern crate kvdb_rocksdb;
......
...@@ -24,6 +24,5 @@ case $TARGET in ...@@ -24,6 +24,5 @@ case $TARGET in
# Install prerequisites and build all wasm projects # Install prerequisites and build all wasm projects
./scripts/init.sh ./scripts/init.sh
./scripts/build.sh ./scripts/build.sh
./scripts/build-demos.sh
;; ;;
esac esac
...@@ -7,12 +7,11 @@ description = "Collator node implementation" ...@@ -7,12 +7,11 @@ description = "Collator node implementation"
[dependencies] [dependencies]
futures = "0.1.17" futures = "0.1.17"
substrate-client = { git = "https://github.com/paritytech/substrate" } 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" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
polkadot-runtime = { path = "../runtime", version = "0.1" } polkadot-runtime = { path = "../runtime", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" } polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" } polkadot-cli = { path = "../cli" }
log = "0.4" log = "0.4"
ed25519 = { git = "https://github.com/paritytech/substrate" }
tokio = "0.1.7" tokio = "0.1.7"
...@@ -46,9 +46,8 @@ ...@@ -46,9 +46,8 @@
extern crate futures; extern crate futures;
extern crate substrate_client as client; 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 substrate_primitives as primitives;
extern crate ed25519;
extern crate tokio; extern crate tokio;
extern crate polkadot_api; extern crate polkadot_api;
...@@ -67,6 +66,7 @@ use std::time::{Duration, Instant}; ...@@ -67,6 +66,7 @@ use std::time::{Duration, Instant};
use futures::{future, stream, Stream, Future, IntoFuture}; use futures::{future, stream, Stream, Future, IntoFuture};
use client::BlockchainEvents; use client::BlockchainEvents;
use polkadot_api::PolkadotApi; use polkadot_api::PolkadotApi;
use primitives::ed25519;
use polkadot_primitives::{AccountId, BlockId, SessionKey}; use polkadot_primitives::{AccountId, BlockId, SessionKey};
use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId}; use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId};
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration}; use polkadot_cli::{ServiceComponents, Service, CustomConfiguration};
......
...@@ -7,7 +7,6 @@ authors = ["Parity Technologies <admin@parity.io>"] ...@@ -7,7 +7,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
futures = "0.1.17" futures = "0.1.17"
parking_lot = "0.4" parking_lot = "0.4"
tokio = "0.1.7" tokio = "0.1.7"
ed25519 = { git = "https://github.com/paritytech/substrate" }
error-chain = "0.12" error-chain = "0.12"
log = "0.3" log = "0.3"
exit-future = "0.1" exit-future = "0.1"
...@@ -20,11 +19,11 @@ polkadot-runtime = { path = "../runtime" } ...@@ -20,11 +19,11 @@ polkadot-runtime = { path = "../runtime" }
polkadot-statement-table = { path = "../statement-table" } polkadot-statement-table = { path = "../statement-table" }
polkadot-transaction-pool = { path = "../transaction-pool" } polkadot-transaction-pool = { path = "../transaction-pool" }
substrate-bft = { git = "https://github.com/paritytech/substrate" } 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-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-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] [dev-dependencies]
substrate-keyring = { git = "https://github.com/paritytech/substrate" } substrate-keyring = { git = "https://github.com/paritytech/substrate" }
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
//! //!
//! Groups themselves may be compromised by malicious authorities. //! Groups themselves may be compromised by malicious authorities.
extern crate ed25519;
extern crate parking_lot; extern crate parking_lot;
extern crate polkadot_api; extern crate polkadot_api;
extern crate polkadot_availability_store as extrinsic_store; extern crate polkadot_availability_store as extrinsic_store;
...@@ -40,10 +39,10 @@ extern crate polkadot_runtime; ...@@ -40,10 +39,10 @@ extern crate polkadot_runtime;
extern crate polkadot_primitives; extern crate polkadot_primitives;
extern crate substrate_bft as bft; extern crate substrate_bft as bft;
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate substrate_primitives as primitives; extern crate substrate_primitives as primitives;
extern crate substrate_runtime_support as runtime_support; extern crate srml_support as runtime_support;
extern crate substrate_runtime_primitives as runtime_primitives; extern crate sr_primitives as runtime_primitives;
extern crate substrate_client as client; extern crate substrate_client as client;
extern crate exit_future; extern crate exit_future;
...@@ -71,7 +70,7 @@ use extrinsic_store::Store as ExtrinsicStore; ...@@ -71,7 +70,7 @@ use extrinsic_store::Store as ExtrinsicStore;
use polkadot_api::PolkadotApi; use polkadot_api::PolkadotApi;
use polkadot_primitives::{AccountId, Hash, Block, BlockId, BlockNumber, Header, Timestamp, SessionKey}; use polkadot_primitives::{AccountId, Hash, Block, BlockId, BlockNumber, Header, Timestamp, SessionKey};
use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt, CandidateSignature}; use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt, CandidateSignature};
use primitives::AuthorityId; use primitives::{AuthorityId, ed25519};
use transaction_pool::TransactionPool; use transaction_pool::TransactionPool;
use tokio::runtime::TaskExecutor; use tokio::runtime::TaskExecutor;
use tokio::timer::{Delay, Interval}; use tokio::timer::{Delay, Interval};
...@@ -593,8 +592,7 @@ impl<C> bft::Proposer<Block> for Proposer<C> ...@@ -593,8 +592,7 @@ impl<C> bft::Proposer<Block> for Proposer<C>
fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior<Hash>)>) { fn import_misbehavior(&self, misbehavior: Vec<(AuthorityId, bft::Misbehavior<Hash>)>) {
use rhododendron::Misbehavior as GenericMisbehavior; use rhododendron::Misbehavior as GenericMisbehavior;
use runtime_primitives::bft::{MisbehaviorKind, MisbehaviorReport}; use runtime_primitives::bft::{MisbehaviorKind, MisbehaviorReport};
use runtime_primitives::MaybeUnsigned; use polkadot_runtime::{Call, UncheckedExtrinsic, ConsensusCall, RawAddress};
use polkadot_runtime::{Call, Extrinsic, BareExtrinsic, UncheckedExtrinsic, ConsensusCall};
let local_id = self.local_key.public().0.into(); let local_id = self.local_key.public().0.into();
let mut next_index = { let mut next_index = {
...@@ -632,23 +630,18 @@ impl<C> bft::Proposer<Block> for Proposer<C> ...@@ -632,23 +630,18 @@ impl<C> bft::Proposer<Block> for Proposer<C>
=> MisbehaviorKind::BftDoubleCommit(round as u32, (h1, s1.signature), (h2, s2.signature)), => MisbehaviorKind::BftDoubleCommit(round as u32, (h1, s1.signature), (h2, s2.signature)),
} }
}; };
let extrinsic = BareExtrinsic { let payload = (next_index, Call::Consensus(ConsensusCall::report_misbehavior(report)));
signed: local_id, let signature = self.local_key.sign(&payload.encode()).into();
index: next_index,
function: Call::Consensus(ConsensusCall::report_misbehavior(report)),
};
next_index += 1; next_index += 1;
let signature = MaybeUnsigned(self.local_key.sign(&extrinsic.encode()).into()); let local_id = self.local_key.public().0.into();
let extrinsic = UncheckedExtrinsic {
let extrinsic = Extrinsic { signature: Some((RawAddress::Id(local_id), signature)),
signed: extrinsic.signed.into(), index: payload.0,
index: extrinsic.index, function: payload.1,
function: extrinsic.function,
}; };