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
This commit is contained in:
Gav Wood
2018-09-12 19:36:33 +02:00
committed by Arkadiy Paronyan
parent 17ede5b8a0
commit 84748fccd3
44 changed files with 1491 additions and 2184 deletions
+777 -751
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -39,7 +39,6 @@ members = [
exclude = [ exclude = [
"runtime/wasm", "runtime/wasm",
"test-parachains/adder/wasm", "test-parachains/adder/wasm",
"demo/runtime/wasm",
] ]
[badges] [badges]
+4 -4
View File
@@ -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" }
+25 -83
View File
@@ -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>( impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec> {
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> {
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
} }
} }
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
} }
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
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 {
] ]
} }
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 {
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 {
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();
} }
} }
+4 -5
View File
@@ -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)]
+5 -5
View File
@@ -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 {
} }
/// 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
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> {}
+1 -1
View File
@@ -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" }
+1 -1
View File
@@ -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;
-1
View File
@@ -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
+1 -2
View File
@@ -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"
+2 -2
View File
@@ -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};
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};
+3 -4
View File
@@ -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" }
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" }
+15 -22
View File
@@ -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;
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;
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>
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>
=> 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,
}; };
let uxt: Vec<u8> = Decode::decode(&mut UncheckedExtrinsic::new(extrinsic, signature).encode().as_slice()).expect("Encoded extrinsic is valid"); let uxt: Vec<u8> = Decode::decode(&mut extrinsic.encode().as_slice()).expect("Encoded extrinsic is valid");
self.transaction_pool.submit_one(&BlockId::hash(self.parent_hash), uxt) self.transaction_pool.submit_one(&BlockId::hash(self.parent_hash), polkadot_primitives::UncheckedExtrinsic(uxt))
.expect("locally signed extrinsic is valid; qed"); .expect("locally signed extrinsic is valid; qed");
} }
} }
@@ -663,7 +656,7 @@ impl<C> bft::Proposer<Block> for Proposer<C>
// this is determined by checking if our local validator would have been forced to skip the round. // this is determined by checking if our local validator would have been forced to skip the round.
let consider_online = was_proposed || { let consider_online = was_proposed || {
let forced_delay = self.dynamic_inclusion.acceptable_in(Instant::now(), self.table.includable_count()); let forced_delay = self.dynamic_inclusion.acceptable_in(Instant::now(), self.table.includable_count());
let public = ::ed25519::Public::from_raw(primary_validator.0); let public = ed25519::Public::from_raw(primary_validator.0);
match forced_delay { match forced_delay {
None => info!( None => info!(
"Potential Offline Validator: {} failed to propose during assigned slot: {}", "Potential Offline Validator: {} failed to propose during assigned slot: {}",
+1 -1
View File
@@ -29,7 +29,7 @@ use std::sync::Arc;
use bft::{self, BftService}; use bft::{self, BftService};
use client::{BlockchainEvents, ChainHead, BlockBody}; use client::{BlockchainEvents, ChainHead, BlockBody};
use ed25519; use primitives::ed25519;
use futures::prelude::*; use futures::prelude::*;
use polkadot_api::LocalPolkadotApi; use polkadot_api::LocalPolkadotApi;
use polkadot_primitives::{Block, Header}; use polkadot_primitives::{Block, Header};
+3 -2
View File
@@ -30,6 +30,7 @@ use futures::{future, prelude::*};
use super::{GroupInfo, TableRouter}; use super::{GroupInfo, TableRouter};
use self::includable::IncludabilitySender; use self::includable::IncludabilitySender;
use primitives::ed25519;
mod includable; mod includable;
@@ -39,7 +40,7 @@ pub use table::generic::Statement as GenericStatement;
struct TableContext { struct TableContext {
parent_hash: Hash, parent_hash: Hash,
key: Arc<::ed25519::Pair>, key: Arc<ed25519::Pair>,
groups: HashMap<ParaId, GroupInfo>, groups: HashMap<ParaId, GroupInfo>,
} }
@@ -320,7 +321,7 @@ impl SharedTable {
/// block being built. /// block being built.
pub fn new( pub fn new(
groups: HashMap<ParaId, GroupInfo>, groups: HashMap<ParaId, GroupInfo>,
key: Arc<::ed25519::Pair>, key: Arc<ed25519::Pair>,
parent_hash: Hash, parent_hash: Hash,
extrinsic_store: ExtrinsicStore, extrinsic_store: ExtrinsicStore,
) -> Self { ) -> Self {
+2 -3
View File
@@ -11,11 +11,10 @@ polkadot-availability-store = { path = "../availability-store" }
polkadot-consensus = { path = "../consensus" } polkadot-consensus = { path = "../consensus" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
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-codec-derive = { git = "https://github.com/paritytech/substrate" } parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
substrate-network = { git = "https://github.com/paritytech/substrate" } substrate-network = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
ed25519 = { git = "https://github.com/paritytech/substrate" }
futures = "0.1" futures = "0.1"
tokio = "0.1.7" tokio = "0.1.7"
log = "0.4" log = "0.4"
+1 -1
View File
@@ -19,7 +19,7 @@
//! each time consensus begins on a new chain head. //! each time consensus begins on a new chain head.
use bft; use bft;
use ed25519; use substrate_primitives::ed25519;
use substrate_network::{self as net, generic_message as msg}; use substrate_network::{self as net, generic_message as msg};
use substrate_network::consensus_gossip::ConsensusMessage; use substrate_network::consensus_gossip::ConsensusMessage;
use polkadot_api::{PolkadotApi, LocalPolkadotApi}; use polkadot_api::{PolkadotApi, LocalPolkadotApi};
+2 -3
View File
@@ -21,7 +21,7 @@
//! and more. //! and more.
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_network; extern crate substrate_network;
extern crate substrate_primitives; extern crate substrate_primitives;
@@ -30,7 +30,6 @@ extern crate polkadot_availability_store as av_store;
extern crate polkadot_consensus; extern crate polkadot_consensus;
extern crate polkadot_primitives; extern crate polkadot_primitives;
extern crate ed25519;
extern crate futures; extern crate futures;
extern crate parking_lot; extern crate parking_lot;
extern crate tokio; extern crate tokio;
@@ -39,7 +38,7 @@ extern crate rhododendron;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
mod collator_pool; mod collator_pool;
mod local_collations; mod local_collations;
+3 -3
View File
@@ -5,8 +5,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
description = "Types and utilities for creating and working with parachains" description = "Types and utilities for creating and working with parachains"
[dependencies] [dependencies]
substrate-codec = { git = "https://github.com/paritytech/substrate", default-features = false } parity-codec = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false } parity-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false }
wasmi = { version = "0.4", optional = true } wasmi = { version = "0.4", optional = true }
error-chain = { version = "0.12", optional = true } error-chain = { version = "0.12", optional = true }
@@ -15,4 +15,4 @@ tiny-keccak = "1.4"
[features] [features]
default = ["std"] default = ["std"]
std = ["substrate-codec/std", "wasmi", "error-chain"] std = ["parity-codec/std", "wasmi", "error-chain"]
+3 -3
View File
@@ -43,11 +43,11 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(not(feature = "std"), feature(alloc))]
/// Re-export of substrate-codec. /// Re-export of parity-codec.
pub extern crate substrate_codec as codec; pub extern crate parity_codec as codec;
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
extern crate alloc; extern crate alloc;
+2 -2
View File
@@ -17,8 +17,8 @@
//! Basic parachain that adds a number as part of its state. //! Basic parachain that adds a number as part of its state.
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate polkadot_parachain as parachain; extern crate polkadot_parachain as parachain;
extern crate tiny_keccak; extern crate tiny_keccak;
+7 -7
View File
@@ -6,11 +6,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
serde = { version = "1.0", default_features = false } serde = { version = "1.0", default_features = false }
serde_derive = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true }
substrate-codec = { git = "https://github.com/paritytech/substrate", default_features = false } parity-codec = { git = "https://github.com/paritytech/substrate", default_features = false }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default_features = false } parity-codec-derive = { git = "https://github.com/paritytech/substrate", default_features = false }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default_features = false } substrate-primitives = { git = "https://github.com/paritytech/substrate", default_features = false }
substrate-runtime-std = { git = "https://github.com/paritytech/substrate", default_features = false } sr-std = { git = "https://github.com/paritytech/substrate", default_features = false }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate", default_features = false } sr-primitives = { git = "https://github.com/paritytech/substrate", default_features = false }
[dev-dependencies] [dev-dependencies]
substrate-serializer = { git = "https://github.com/paritytech/substrate" } substrate-serializer = { git = "https://github.com/paritytech/substrate" }
@@ -19,10 +19,10 @@ pretty_assertions = "0.4"
[features] [features]
default = ["std"] default = ["std"]
std = [ std = [
"substrate-codec/std", "parity-codec/std",
"substrate-primitives/std", "substrate-primitives/std",
"substrate-runtime-std/std", "sr-std/std",
"substrate-runtime-primitives/std", "sr-primitives/std",
"serde_derive", "serde_derive",
"serde/std", "serde/std",
] ]
+15 -27
View File
@@ -21,16 +21,16 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(not(feature = "std"), feature(alloc))]
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_primitives as runtime_primitives; extern crate sr_primitives as runtime_primitives;
extern crate substrate_runtime_std as rstd; extern crate sr_std as rstd;
#[cfg(test)] #[cfg(test)]
extern crate substrate_serializer; extern crate substrate_serializer;
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[macro_use] #[macro_use]
@@ -39,27 +39,12 @@ extern crate serde_derive;
#[cfg(feature = "std")] #[cfg(feature = "std")]
extern crate serde; extern crate serde;
#[cfg(feature = "std")]
use primitives::bytes;
use rstd::prelude::*; use rstd::prelude::*;
use runtime_primitives::traits::BlakeTwo256; use runtime_primitives::{generic, traits::BlakeTwo256};
use runtime_primitives::generic;
pub mod parachain; pub mod parachain;
/// Block header type as expected by this runtime. #[cfg(feature = "std")]
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>; use primitives::bytes;
/// Opaque, encoded, unchecked extrinsic.
pub type UncheckedExtrinsic = Vec<u8>;
/// A "future-proof" block type for Polkadot. This will be resilient to upgrades in transaction
/// format, because it doesn't attempt to decode extrinsics.
///
/// Specialized code needs to link to (at least one version of) the runtime directly
/// in order to handle the extrinsics within.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// An index to a block. /// An index to a block.
/// 32-bits will allow for 136 years of blocks assuming 1 block per second. /// 32-bits will allow for 136 years of blocks assuming 1 block per second.
@@ -88,7 +73,7 @@ pub type Index = u32;
/// Alias to 512-bit hash when used in the context of a signature on the relay chain. /// Alias to 512-bit hash when used in the context of a signature on the relay chain.
/// Equipped with logic for possibly "unsigned" messages. /// Equipped with logic for possibly "unsigned" messages.
pub type Signature = runtime_primitives::MaybeUnsigned<runtime_primitives::Ed25519Signature>; pub type Signature = runtime_primitives::Ed25519Signature;
/// A timestamp: seconds since the unix epoch. /// A timestamp: seconds since the unix epoch.
pub type Timestamp = u64; pub type Timestamp = u64;
@@ -102,14 +87,17 @@ pub type Timestamp = u64;
/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow. /// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow.
pub type Balance = u128; pub type Balance = u128;
/// "generic" block ID for the future-proof block type. /// Header type.
// TODO: parameterize blockid only as necessary. pub type Header = generic::Header<BlockNumber, BlakeTwo256, generic::DigestItem<()>>;
/// Block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Block ID.
pub type BlockId = generic::BlockId<Block>; pub type BlockId = generic::BlockId<Block>;
/// A log entry in the block. /// Opaque, encoded, unchecked extrinsic.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)] #[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct Log(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>); pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
/// Inherent data to include in a block. /// Inherent data to include in a block.
#[derive(Encode, Decode)] #[derive(Encode, Decode)]
+34 -32
View File
@@ -10,25 +10,26 @@ serde = { version = "1.0", default_features = false }
serde_derive = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true }
safe-mix = { version = "1.0", default_features = false} safe-mix = { version = "1.0", default_features = false}
polkadot-primitives = { path = "../primitives", default_features = false } polkadot-primitives = { path = "../primitives", default_features = false }
substrate-codec = { git = "https://github.com/paritytech/substrate" } parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate" } parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
substrate-serializer = { git = "https://github.com/paritytech/substrate" } substrate-serializer = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-std = { git = "https://github.com/paritytech/substrate" } sr-std = { 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-support = { git = "https://github.com/paritytech/substrate" } srml-support = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-keyring = { git = "https://github.com/paritytech/substrate" } substrate-keyring = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-balances = { git = "https://github.com/paritytech/substrate" } srml-balances = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-consensus = { git = "https://github.com/paritytech/substrate" } srml-consensus = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-council = { git = "https://github.com/paritytech/substrate" } srml-council = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-democracy = { git = "https://github.com/paritytech/substrate" } srml-democracy = { 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-runtime-session = { git = "https://github.com/paritytech/substrate" } srml-session = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-staking = { git = "https://github.com/paritytech/substrate" } srml-staking = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-system = { git = "https://github.com/paritytech/substrate" } srml-system = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-timestamp = { git = "https://github.com/paritytech/substrate" } srml-timestamp = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-version = { git = "https://github.com/paritytech/substrate" } srml-treasury = { git = "https://github.com/paritytech/substrate" }
sr-version = { git = "https://github.com/paritytech/substrate" }
[dev-dependencies] [dev-dependencies]
hex-literal = "0.1.0" hex-literal = "0.1.0"
@@ -37,23 +38,24 @@ hex-literal = "0.1.0"
default = ["std"] default = ["std"]
std = [ std = [
"polkadot-primitives/std", "polkadot-primitives/std",
"substrate-codec/std", "parity-codec/std",
"substrate-codec-derive/std", "parity-codec-derive/std",
"substrate-primitives/std", "substrate-primitives/std",
"substrate-runtime-std/std", "sr-std/std",
"substrate-runtime-io/std", "sr-io/std",
"substrate-runtime-support/std", "srml-support/std",
"substrate-runtime-balances/std", "srml-balances/std",
"substrate-runtime-consensus/std", "srml-consensus/std",
"substrate-runtime-council/std", "srml-council/std",
"substrate-runtime-democracy/std", "srml-democracy/std",
"substrate-runtime-executive/std", "srml-executive/std",
"substrate-runtime-primitives/std", "sr-primitives/std",
"substrate-runtime-session/std", "srml-session/std",
"substrate-runtime-staking/std", "srml-staking/std",
"substrate-runtime-system/std", "srml-system/std",
"substrate-runtime-timestamp/std", "srml-timestamp/std",
"substrate-runtime-version/std", "srml-treasury/std",
"sr-version/std",
"serde_derive", "serde_derive",
"serde/std", "serde/std",
"log", "log",
+5 -5
View File
@@ -32,7 +32,7 @@ impl CheckedBlock {
/// Create a new checked block. Fails if the block is not structurally valid. /// Create a new checked block. Fails if the block is not structurally valid.
pub fn new(block: Block) -> Result<Self, Block> { pub fn new(block: Block) -> Result<Self, Block> {
let has_timestamp = block.extrinsics.get(TIMESTAMP_SET_POSITION as usize).map_or(false, |xt| { let has_timestamp = block.extrinsics.get(TIMESTAMP_SET_POSITION as usize).map_or(false, |xt| {
!xt.is_signed() && match xt.extrinsic.function { !xt.is_signed() && match xt.function {
Call::Timestamp(TimestampCall::set(_)) => true, Call::Timestamp(TimestampCall::set(_)) => true,
_ => false, _ => false,
} }
@@ -41,7 +41,7 @@ impl CheckedBlock {
if !has_timestamp { return Err(block) } if !has_timestamp { return Err(block) }
let has_heads = block.extrinsics.get(PARACHAINS_SET_POSITION as usize).map_or(false, |xt| { let has_heads = block.extrinsics.get(PARACHAINS_SET_POSITION as usize).map_or(false, |xt| {
!xt.is_signed() && match xt.extrinsic.function { !xt.is_signed() && match xt.function {
Call::Parachains(ParachainsCall::set_heads(_)) => true, Call::Parachains(ParachainsCall::set_heads(_)) => true,
_ => false, _ => false,
} }
@@ -66,7 +66,7 @@ impl CheckedBlock {
/// Extract the timestamp from the block. /// Extract the timestamp from the block.
pub fn timestamp(&self) -> ::primitives::Timestamp { pub fn timestamp(&self) -> ::primitives::Timestamp {
let x = self.inner.extrinsics.get(TIMESTAMP_SET_POSITION as usize).and_then(|xt| match xt.extrinsic.function { let x = self.inner.extrinsics.get(TIMESTAMP_SET_POSITION as usize).and_then(|xt| match xt.function {
Call::Timestamp(TimestampCall::set(x)) => Some(x), Call::Timestamp(TimestampCall::set(x)) => Some(x),
_ => None _ => None
}); });
@@ -79,7 +79,7 @@ impl CheckedBlock {
/// Extract the parachain heads from the block. /// Extract the parachain heads from the block.
pub fn parachain_heads(&self) -> &[CandidateReceipt] { pub fn parachain_heads(&self) -> &[CandidateReceipt] {
let x = self.inner.extrinsics.get(PARACHAINS_SET_POSITION as usize).and_then(|xt| match xt.extrinsic.function { let x = self.inner.extrinsics.get(PARACHAINS_SET_POSITION as usize).and_then(|xt| match xt.function {
Call::Parachains(ParachainsCall::set_heads(ref x)) => Some(&x[..]), Call::Parachains(ParachainsCall::set_heads(ref x)) => Some(&x[..]),
_ => None _ => None
}); });
@@ -92,7 +92,7 @@ impl CheckedBlock {
/// Extract the noted missed proposal validator indices (if any) from the block. /// Extract the noted missed proposal validator indices (if any) from the block.
pub fn noted_offline(&self) -> &[u32] { pub fn noted_offline(&self) -> &[u32] {
self.inner.extrinsics.get(NOTE_OFFLINE_POSITION as usize).and_then(|xt| match xt.extrinsic.function { self.inner.extrinsics.get(NOTE_OFFLINE_POSITION as usize).and_then(|xt| match xt.function {
Call::Consensus(ConsensusCall::note_offline(ref x)) => Some(&x[..]), Call::Consensus(ConsensusCall::note_offline(ref x)) => Some(&x[..]),
_ => None, _ => None,
}).unwrap_or(&[]) }).unwrap_or(&[])
+191 -158
View File
@@ -26,13 +26,13 @@ extern crate serde_derive;
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
extern crate substrate_runtime_io as runtime_io; extern crate sr_io as runtime_io;
#[macro_use] #[macro_use]
extern crate substrate_runtime_support; extern crate srml_support;
#[macro_use] #[macro_use]
extern crate substrate_runtime_primitives as runtime_primitives; extern crate sr_primitives as runtime_primitives;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
@@ -44,23 +44,24 @@ extern crate substrate_serializer;
extern crate substrate_primitives; extern crate substrate_primitives;
#[macro_use] #[macro_use]
extern crate substrate_runtime_std as rstd; extern crate sr_std as rstd;
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate substrate_runtime_balances as balances; extern crate srml_balances as balances;
extern crate substrate_runtime_consensus as consensus; extern crate srml_consensus as consensus;
extern crate substrate_runtime_council as council; extern crate srml_council as council;
extern crate substrate_runtime_democracy as democracy; extern crate srml_democracy as democracy;
extern crate substrate_runtime_executive as executive; extern crate srml_executive as executive;
extern crate substrate_runtime_session as session; extern crate srml_session as session;
extern crate substrate_runtime_staking as staking; extern crate srml_staking as staking;
extern crate substrate_runtime_system as system; extern crate srml_system as system;
extern crate substrate_runtime_timestamp as timestamp; extern crate srml_timestamp as timestamp;
extern crate srml_treasury as treasury;
#[macro_use] #[macro_use]
extern crate substrate_runtime_version as version; extern crate sr_version as version;
#[cfg(feature = "std")] #[cfg(feature = "std")]
mod checked_block; mod checked_block;
@@ -72,9 +73,13 @@ pub use checked_block::CheckedBlock;
pub use utils::{inherent_extrinsics, check_extrinsic}; pub use utils::{inherent_extrinsics, check_extrinsic};
pub use balances::address::Address as RawAddress; pub use balances::address::Address as RawAddress;
use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature}; use rstd::prelude::*;
use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}}; use codec::{Encode, Decode, Input};
use substrate_primitives::u32_trait::{_2, _4};
use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, SessionKey, Signature};
use runtime_primitives::{generic, traits::{Convert, BlakeTwo256, DigestItem}};
use version::RuntimeVersion; use version::RuntimeVersion;
use council::{motions as council_motions, voting as council_voting};
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use runtime_primitives::BuildStorage; pub use runtime_primitives::BuildStorage;
@@ -82,7 +87,6 @@ pub use runtime_primitives::BuildStorage;
pub use consensus::Call as ConsensusCall; pub use consensus::Call as ConsensusCall;
pub use timestamp::Call as TimestampCall; pub use timestamp::Call as TimestampCall;
pub use parachains::Call as ParachainsCall; pub use parachains::Call as ParachainsCall;
pub use primitives::Header;
/// The position of the timestamp set extrinsic. /// The position of the timestamp set extrinsic.
pub const TIMESTAMP_SET_POSITION: u32 = 0; pub const TIMESTAMP_SET_POSITION: u32 = 0;
@@ -91,24 +95,24 @@ pub const PARACHAINS_SET_POSITION: u32 = 1;
/// The position of the note_offline in the block, if it exists. /// The position of the note_offline in the block, if it exists.
pub const NOTE_OFFLINE_POSITION: u32 = 2; pub const NOTE_OFFLINE_POSITION: u32 = 2;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
/// The address format for describing accounts. /// The address format for describing accounts.
pub type Address = balances::Address<Concrete>; pub type Address = balances::Address<Runtime>;
/// Block Id type for this block. /// Block Id type for this block.
pub type BlockId = generic::BlockId<Block>; pub type BlockId = generic::BlockId<Block>;
/// Unchecked extrinsic type as expected by this runtime. /// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call, Signature>; pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call, Signature>;
/// Extrinsic type as expected by this runtime. This is not the type that is signed. /// Extrinsic type that has already been checked.
pub type Extrinsic = generic::Extrinsic<Address, Index, Call>; pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Index, Call>;
/// Extrinsic type that is signed.
pub type BareExtrinsic = generic::Extrinsic<AccountId, Index, Call>;
/// Block type as expected by this runtime. /// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>; pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Concrete runtime type used to parameterize the various modules. /// Runtime runtime type used to parameterize the various modules.
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct Concrete; pub struct Runtime;
/// Polkadot runtime version. /// Polkadot runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion { pub const VERSION: RuntimeVersion = RuntimeVersion {
@@ -119,19 +123,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0, impl_version: 0,
}; };
impl version::Trait for Concrete { impl system::Trait for Runtime {
const VERSION: RuntimeVersion = VERSION; type Origin = Origin;
}
/// Version module for this concrete runtime.
pub type Version = version::Module<Concrete>;
impl HasPublicAux for Concrete {
type PublicAux = AccountId; // TODO: Option<AccountId>
}
impl system::Trait for Concrete {
type PublicAux = <Concrete as HasPublicAux>::PublicAux;
type Index = Index; type Index = Index;
type BlockNumber = BlockNumber; type BlockNumber = BlockNumber;
type Hash = Hash; type Hash = Hash;
@@ -142,9 +135,9 @@ impl system::Trait for Concrete {
type Event = Event; type Event = Event;
} }
/// System module for this concrete runtime. /// System module for this concrete runtime.
pub type System = system::Module<Concrete>; pub type System = system::Module<Runtime>;
impl balances::Trait for Concrete { impl balances::Trait for Runtime {
type Balance = Balance; type Balance = Balance;
type AccountIndex = AccountIndex; type AccountIndex = AccountIndex;
type OnFreeBalanceZero = Staking; type OnFreeBalanceZero = Staking;
@@ -152,22 +145,23 @@ impl balances::Trait for Concrete {
type Event = Event; type Event = Event;
} }
/// Staking module for this concrete runtime. /// Staking module for this concrete runtime.
pub type Balances = balances::Module<Concrete>; pub type Balances = balances::Module<Runtime>;
impl consensus::Trait for Concrete { impl consensus::Trait for Runtime {
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION; const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
type Log = Log;
type SessionKey = SessionKey; type SessionKey = SessionKey;
type OnOfflineValidator = Staking; type OnOfflineValidator = Staking;
} }
/// Consensus module for this concrete runtime. /// Consensus module for this concrete runtime.
pub type Consensus = consensus::Module<Concrete>; pub type Consensus = consensus::Module<Runtime>;
impl timestamp::Trait for Concrete { impl timestamp::Trait for Runtime {
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION; const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
type Moment = u64; type Moment = u64;
} }
/// Timestamp module for this concrete runtime. /// Timestamp module for this concrete runtime.
pub type Timestamp = timestamp::Module<Concrete>; pub type Timestamp = timestamp::Module<Runtime>;
/// Session key conversion. /// Session key conversion.
pub struct SessionKeyConversion; pub struct SessionKeyConversion;
@@ -177,82 +171,111 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {
} }
} }
impl session::Trait for Concrete { impl session::Trait for Runtime {
type ConvertAccountIdToSessionKey = SessionKeyConversion; type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking; type OnSessionChange = Staking;
type Event = Event; type Event = Event;
} }
/// Session module for this concrete runtime. /// Session module for this concrete runtime.
pub type Session = session::Module<Concrete>; pub type Session = session::Module<Runtime>;
impl staking::Trait for Concrete { impl staking::Trait for Runtime {
type OnRewardMinted = Treasury;
type Event = Event; type Event = Event;
} }
/// Staking module for this concrete runtime. /// Staking module for this concrete runtime.
pub type Staking = staking::Module<Concrete>; pub type Staking = staking::Module<Runtime>;
impl democracy::Trait for Concrete { impl democracy::Trait for Runtime {
type Proposal = PrivCall; type Proposal = Call;
type Event = Event;
} }
/// Democracy module for this concrete runtime. /// Democracy module for this concrete runtime.
pub type Democracy = democracy::Module<Concrete>; pub type Democracy = democracy::Module<Runtime>;
impl council::Trait for Concrete {} impl council::Trait for Runtime {
/// Council module for this concrete runtime. type Event = Event;
pub type Council = council::Module<Concrete>;
/// Council voting module for this concrete runtime.
pub type CouncilVoting = council::voting::Module<Concrete>;
impl parachains::Trait for Concrete {
const SET_POSITION: u32 = PARACHAINS_SET_POSITION;
type PublicAux = <Concrete as HasPublicAux>::PublicAux;
} }
pub type Parachains = parachains::Module<Concrete>;
/// Council module for this concrete runtime.
pub type Council = council::Module<Runtime>;
impl council::voting::Trait for Runtime {
type Event = Event;
}
/// Council voting module for this concrete runtime.
pub type CouncilVoting = council::voting::Module<Runtime>;
impl council::motions::Trait for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
}
/// Council motions module for this concrete runtime.
pub type CouncilMotions = council_motions::Module<Runtime>;
impl treasury::Trait for Runtime {
type ApproveOrigin = council_motions::EnsureMembers<_4>;
type RejectOrigin = council_motions::EnsureMembers<_2>;
type Event = Event;
}
/// Treasury module for this concrete runtime.
pub type Treasury = treasury::Module<Runtime>;
impl parachains::Trait for Runtime {
const SET_POSITION: u32 = PARACHAINS_SET_POSITION;
}
pub type Parachains = parachains::Module<Runtime>;
impl_outer_event! { impl_outer_event! {
pub enum Event for Concrete { pub enum Event for Runtime {
balances, session, staking //consensus,
balances,
//timetstamp,
session,
staking,
democracy,
council,
council_voting,
council_motions,
treasury
}
}
impl_outer_log! {
pub enum Log(InternalLog: DigestItem<SessionKey>) for Runtime {
consensus(AuthoritiesChange)
}
}
impl_outer_origin! {
pub enum Origin for Runtime {
council_motions
} }
} }
impl_outer_dispatch! { impl_outer_dispatch! {
/// Call type for polkadot transactions. /// Call type for polkadot transactions.
#[derive(Clone, PartialEq, Eq)] pub enum Call where origin: <Runtime as system::Trait>::Origin {
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] Consensus,
pub enum Call where aux: <Concrete as HasPublicAux>::PublicAux { Balances,
Consensus = 0, Session,
Balances = 1, Staking,
Session = 2, Timestamp,
Staking = 3, Democracy,
Timestamp = 4, Council,
Democracy = 5, CouncilVoting,
Council = 6, CouncilMotions,
CouncilVoting = 7, Parachains,
Parachains = 8, Treasury,
}
/// Internal calls.
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum PrivCall {
Consensus = 0,
Balances = 1,
Session = 2,
Staking = 3,
Democracy = 5,
Council = 6,
CouncilVoting = 7,
Parachains = 8,
} }
} }
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Concrete, Block, Balances, Balances,
(((((((), Parachains), Council), Democracy), Staking), Session), Timestamp)>;
impl_outer_config! { impl_outer_config! {
pub struct GenesisConfig for Concrete { pub struct GenesisConfig for Runtime {
ConsensusConfig => consensus, ConsensusConfig => consensus,
SystemConfig => system, SystemConfig => system,
BalancesConfig => balances, BalancesConfig => balances,
@@ -261,13 +284,58 @@ impl_outer_config! {
DemocracyConfig => democracy, DemocracyConfig => democracy,
CouncilConfig => council, CouncilConfig => council,
TimestampConfig => timestamp, TimestampConfig => timestamp,
TreasuryConfig => treasury,
ParachainsConfig => parachains, ParachainsConfig => parachains,
} }
} }
type AllModules = (
Consensus,
Balances,
Session,
Staking,
Timestamp,
Democracy,
Council,
CouncilVoting,
CouncilMotions,
Parachains,
Treasury,
);
impl_json_metadata!(
for Runtime with modules
system::Module with Storage,
consensus::Module with Storage,
balances::Module with Storage,
timestamp::Module with Storage,
session::Module with Storage,
staking::Module with Storage,
democracy::Module with Storage,
council::Module with Storage,
council_voting::Module with Storage,
council_motions::Module with Storage,
treasury::Module with Storage,
parachains::Module with Storage,
);
impl DigestItem for Log {
type AuthorityId = SessionKey;
fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]> {
match self.0 {
InternalLog::consensus(ref item) => item.as_authorities_change(),
}
}
}
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Balances, Balances, AllModules>;
pub mod api { pub mod api {
impl_stubs!( impl_stubs!(
version => |()| super::Version::version(), version => |()| super::VERSION,
json_metadata => |()| super::Runtime::json_metadata(),
authorities => |()| super::Consensus::authorities(), authorities => |()| super::Consensus::authorities(),
initialise_block => |header| super::Executive::initialise_block(&header), initialise_block => |header| super::Executive::initialise_block(&header),
apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic), apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic),
@@ -276,14 +344,14 @@ pub mod api {
inherent_extrinsics => |(inherent, spec_version)| super::inherent_extrinsics(inherent, spec_version), inherent_extrinsics => |(inherent, spec_version)| super::inherent_extrinsics(inherent, spec_version),
validator_count => |()| super::Session::validator_count(), validator_count => |()| super::Session::validator_count(),
validators => |()| super::Session::validators(), validators => |()| super::Session::validators(),
duty_roster => |()| super::Parachains::calculate_duty_roster(),
active_parachains => |()| super::Parachains::active_parachains(),
parachain_head => |id| super::Parachains::parachain_head(&id),
parachain_code => |id| super::Parachains::parachain_code(&id),
timestamp => |()| super::Timestamp::get(), timestamp => |()| super::Timestamp::get(),
random_seed => |()| super::System::random_seed(), random_seed => |()| super::System::random_seed(),
account_nonce => |account| super::System::account_nonce(&account), account_nonce => |account| super::System::account_nonce(&account),
lookup_address => |address| super::Balances::lookup_address(address) lookup_address => |address| super::Balances::lookup_address(address),
duty_roster => |()| super::Parachains::calculate_duty_roster(),
active_parachains => |()| super::Parachains::active_parachains(),
parachain_head => |id| super::Parachains::parachain_head(&id),
parachain_code => |id| super::Parachains::parachain_code(&id)
); );
} }
@@ -294,7 +362,7 @@ mod tests {
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use substrate_primitives::hexdisplay::HexDisplay; use substrate_primitives::hexdisplay::HexDisplay;
use substrate_serializer as ser; use substrate_serializer as ser;
use runtime_primitives::traits::{Digest as DigestT, Header as HeaderT}; use runtime_primitives::traits::Header as HeaderT;
type Digest = generic::Digest<Log>; type Digest = generic::Digest<Log>;
#[test] #[test]
@@ -304,7 +372,7 @@ mod tests {
number: 67, number: 67,
state_root: 3.into(), state_root: 3.into(),
extrinsics_root: 6.into(), extrinsics_root: 6.into(),
digest: { let mut d = Digest::default(); d.push(Log(vec![1])); d }, digest: Digest::default(),
}; };
assert_eq!(ser::to_string_pretty(&header), r#"{ assert_eq!(ser::to_string_pretty(&header), r#"{
@@ -313,9 +381,7 @@ mod tests {
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000003", "stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000003",
"extrinsicsRoot": "0x0000000000000000000000000000000000000000000000000000000000000006", "extrinsicsRoot": "0x0000000000000000000000000000000000000000000000000000000000000006",
"digest": { "digest": {
"logs": [ "logs": []
"0x01"
]
} }
}"#); }"#);
@@ -328,13 +394,9 @@ mod tests {
let mut block = Block { let mut block = Block {
header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()), header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()),
extrinsics: vec![ extrinsics: vec![
UncheckedExtrinsic::new( UncheckedExtrinsic::new_unsigned(
generic::Extrinsic {
function: Call::Timestamp(timestamp::Call::set(100_000_000)),
signed: Default::default(),
index: Default::default(),
},
Default::default(), Default::default(),
Call::Timestamp(timestamp::Call::set(100_000_000))
) )
], ],
}; };
@@ -344,13 +406,9 @@ mod tests {
assert_eq!(block, decoded); assert_eq!(block, decoded);
block.extrinsics.push(UncheckedExtrinsic::new( block.extrinsics.push(UncheckedExtrinsic::new_unsigned(
generic::Extrinsic { 10101,
function: Call::Staking(staking::Call::stake()), Call::Staking(staking::Call::stake())
signed: Default::default(),
index: 10101,
},
Default::default(),
)); ));
let raw = block.encode(); let raw = block.encode();
@@ -364,24 +422,16 @@ mod tests {
let mut block = Block { let mut block = Block {
header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()), header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()),
extrinsics: vec![ extrinsics: vec![
UncheckedExtrinsic::new( UncheckedExtrinsic::new_unsigned(
generic::Extrinsic {
function: Call::Timestamp(timestamp::Call::set(100_000_000)),
signed: Default::default(),
index: Default::default(),
},
Default::default(), Default::default(),
Call::Timestamp(timestamp::Call::set(100_000_000))
) )
], ],
}; };
block.extrinsics.push(UncheckedExtrinsic::new( block.extrinsics.push(UncheckedExtrinsic::new_unsigned(
generic::Extrinsic { 10101,
function: Call::Staking(staking::Call::stake()), Call::Staking(staking::Call::stake())
signed: Default::default(),
index: 10101,
},
Default::default()
)); ));
let raw = block.encode(); let raw = block.encode();
@@ -394,12 +444,10 @@ mod tests {
#[test] #[test]
fn serialize_unchecked() { fn serialize_unchecked() {
let tx = UncheckedExtrinsic::new( let tx = UncheckedExtrinsic::new_signed(
Extrinsic { 999,
signed: AccountId::from([1; 32]).into(), Call::Timestamp(TimestampCall::set(135135)),
index: 999, AccountId::from([1; 32]).into(),
function: Call::Timestamp(TimestampCall::set(135135)),
},
runtime_primitives::Ed25519Signature(primitives::hash::H512([0; 64])).into() runtime_primitives::Ed25519Signature(primitives::hash::H512([0; 64])).into()
); );
@@ -411,29 +459,14 @@ mod tests {
// 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
let v = Encode::encode(&tx); let v = Encode::encode(&tx);
assert_eq!(&v[..], &hex!["6f000000ff0101010101010101010101010101010101010101010101010101010101010101e70300000400df0f02000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"][..]); assert_eq!(&v[..], &hex!["7000000001ff010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e70300000400df0f020000000000"][..]);
println!("{}", HexDisplay::from(&v)); println!("{}", HexDisplay::from(&v));
assert_eq!(UncheckedExtrinsic::decode(&mut &v[..]).unwrap(), tx); assert_eq!(UncheckedExtrinsic::decode(&mut &v[..]).unwrap(), tx);
} }
#[test]
fn serialize_checked() {
let xt = Extrinsic {
signed: AccountId::from(hex!["0d71d1a9cad6f2ab773435a7dec1bac019994d05d1dd5eb3108211dcf25c9d1e"]).into(),
index: 0,
function: Call::CouncilVoting(council::voting::Call::propose(Box::new(
PrivCall::Consensus(consensus::PrivCall::set_code(
vec![]
))
))),
};
let v = Encode::encode(&xt);
assert_eq!(Extrinsic::decode(&mut &v[..]).unwrap(), xt);
}
#[test] #[test]
fn parachain_calls_are_privcall() { fn parachain_calls_are_privcall() {
let _register = PrivCall::Parachains(parachains::PrivCall::register_parachain(0.into(), vec![1, 2, 3], vec![])); let _register = Call::Parachains(parachains::Call::register_parachain(0.into(), vec![1, 2, 3], vec![]));
let _deregister = PrivCall::Parachains(parachains::PrivCall::deregister_parachain(0.into())); let _deregister = Call::Parachains(parachains::Call::deregister_parachain(0.into()));
} }
} }
+29 -34
View File
@@ -19,12 +19,12 @@
use rstd::prelude::*; use rstd::prelude::*;
use codec::Decode; use codec::Decode;
use runtime_primitives::traits::{Hash, BlakeTwo256, Executable, RefInto, MaybeEmpty}; use runtime_primitives::traits::{Hash, BlakeTwo256, OnFinalise};
use primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt}; use primitives::parachain::{Id, Chain, DutyRoster, CandidateReceipt};
use {system, session}; use {system, session};
use substrate_runtime_support::{StorageValue, StorageMap}; use srml_support::{StorageValue, StorageMap};
use substrate_runtime_support::dispatch::Result; use srml_support::dispatch::Result;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
use rstd::marker::PhantomData; use rstd::marker::PhantomData;
@@ -35,28 +35,21 @@ use runtime_primitives;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
use std::collections::HashMap; use std::collections::HashMap;
use system::{ensure_root, ensure_inherent};
pub trait Trait: system::Trait<Hash = ::primitives::Hash> + session::Trait { pub trait Trait: system::Trait<Hash = ::primitives::Hash> + session::Trait {
/// The position of the set_heads call in the block. /// The position of the set_heads call in the block.
const SET_POSITION: u32; const SET_POSITION: u32;
type PublicAux: RefInto<Self::AccountId> + MaybeEmpty;
} }
decl_module! { decl_module! {
/// Parachains module. /// Parachains module.
pub struct Module<T: Trait>; pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Call type for parachains. /// Provide candidate receipts for parachains, in ascending order by id.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] fn set_heads(origin, heads: Vec<CandidateReceipt>) -> Result;
pub enum Call where aux: <T as Trait>::PublicAux {
// provide candidate receipts for parachains, in ascending order by id.
fn set_heads(aux, heads: Vec<CandidateReceipt>) -> Result = 0;
}
/// Private calls for parachains. fn register_parachain(origin, id: Id, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result;
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] fn deregister_parachain(origin, id: Id) -> Result;
pub enum PrivCall {
fn register_parachain(id: Id, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result = 0;
fn deregister_parachain(id: Id) -> Result = 1;
} }
} }
@@ -126,7 +119,8 @@ impl<T: Trait> Module<T> {
/// Register a parachain with given code. /// Register a parachain with given code.
/// Fails if given ID is already used. /// Fails if given ID is already used.
pub fn register_parachain(id: Id, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result { pub fn register_parachain(origin: T::Origin, id: Id, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result {
ensure_root(origin)?;
let mut parachains = Self::active_parachains(); let mut parachains = Self::active_parachains();
match parachains.binary_search(&id) { match parachains.binary_search(&id) {
Ok(_) => fail!("Parachain already exists"), Ok(_) => fail!("Parachain already exists"),
@@ -141,7 +135,8 @@ impl<T: Trait> Module<T> {
} }
/// Deregister a parachain with given id /// Deregister a parachain with given id
pub fn deregister_parachain(id: Id) -> Result { pub fn deregister_parachain(origin: T::Origin, id: Id) -> Result {
ensure_root(origin)?;
let mut parachains = Self::active_parachains(); let mut parachains = Self::active_parachains();
match parachains.binary_search(&id) { match parachains.binary_search(&id) {
Ok(idx) => { parachains.remove(idx); } Ok(idx) => { parachains.remove(idx); }
@@ -154,8 +149,8 @@ impl<T: Trait> Module<T> {
Ok(()) Ok(())
} }
fn set_heads(aux: &<T as Trait>::PublicAux, heads: Vec<CandidateReceipt>) -> Result { fn set_heads(origin: T::Origin, heads: Vec<CandidateReceipt>) -> Result {
ensure!(aux.is_empty(), "set_heads must not be signed"); ensure_inherent(origin)?;
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block"); ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
ensure!( ensure!(
<system::Module<T>>::extrinsic_index() == Some(T::SET_POSITION), <system::Module<T>>::extrinsic_index() == Some(T::SET_POSITION),
@@ -186,8 +181,8 @@ impl<T: Trait> Module<T> {
} }
} }
impl<T: Trait> Executable for Module<T> { impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
fn execute() { fn on_finalise(_n: T::BlockNumber) {
assert!(<Self as Store>::DidUpdate::take(), "Parachain heads must be updated once in the block"); assert!(<Self as Store>::DidUpdate::take(), "Parachain heads must be updated once in the block");
} }
} }
@@ -246,24 +241,26 @@ impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
mod tests { mod tests {
use super::*; use super::*;
use runtime_io::{TestExternalities, with_externalities}; use runtime_io::{TestExternalities, with_externalities};
use substrate_primitives::{H256, KeccakHasher}; use substrate_primitives::{H256, Blake2Hasher};
use runtime_primitives::BuildStorage; use runtime_primitives::BuildStorage;
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256}; use runtime_primitives::traits::{Identity, BlakeTwo256};
use runtime_primitives::testing::{Digest, Header}; use runtime_primitives::testing::{Digest, Header};
use {consensus, timestamp}; use {consensus, timestamp};
impl_outer_origin! {
pub enum Origin for Test {}
}
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
pub struct Test; pub struct Test;
impl HasPublicAux for Test {
type PublicAux = u64;
}
impl consensus::Trait for Test { impl consensus::Trait for Test {
const NOTE_OFFLINE_POSITION: u32 = 1; const NOTE_OFFLINE_POSITION: u32 = 1;
type SessionKey = u64; type SessionKey = u64;
type OnOfflineValidator = (); type OnOfflineValidator = ();
type Log = u64;
} }
impl system::Trait for Test { impl system::Trait for Test {
type PublicAux = <Self as HasPublicAux>::PublicAux; type Origin = Origin;
type Index = u64; type Index = u64;
type BlockNumber = u64; type BlockNumber = u64;
type Hash = H256; type Hash = H256;
@@ -284,13 +281,11 @@ mod tests {
} }
impl Trait for Test { impl Trait for Test {
const SET_POSITION: u32 = 0; const SET_POSITION: u32 = 0;
type PublicAux = <Self as HasPublicAux>::PublicAux;
} }
type Parachains = Module<Test>; type Parachains = Module<Test>;
fn new_test_ext(parachains: Vec<(Id, Vec<u8>, Vec<u8>)>) -> TestExternalities<KeccakHasher> { fn new_test_ext(parachains: Vec<(Id, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap(); let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
t.extend(consensus::GenesisConfig::<Test>{ t.extend(consensus::GenesisConfig::<Test>{
code: vec![], code: vec![],
@@ -334,12 +329,12 @@ mod tests {
assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3])); assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3]));
assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6])); assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6]));
Parachains::register_parachain(99u32.into(), vec![7,8,9], vec![1, 1, 1]).unwrap(); assert_ok!(Parachains::register_parachain(Origin::ROOT, 99u32.into(), vec![7,8,9], vec![1, 1, 1]));
assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 99u32.into(), 100u32.into()]); assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 99u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&99u32.into()), Some(vec![7,8,9])); assert_eq!(Parachains::parachain_code(&99u32.into()), Some(vec![7,8,9]));
Parachains::deregister_parachain(5u32.into()).unwrap(); assert_ok!(Parachains::deregister_parachain(Origin::ROOT, 5u32.into()));
assert_eq!(Parachains::active_parachains(), vec![99u32.into(), 100u32.into()]); assert_eq!(Parachains::active_parachains(), vec![99u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&5u32.into()), None); assert_eq!(Parachains::parachain_code(&5u32.into()), None);
+4 -11
View File
@@ -17,29 +17,22 @@
//! Utils for block interaction. //! Utils for block interaction.
use rstd::prelude::*; use rstd::prelude::*;
use super::{Call, UncheckedExtrinsic, Extrinsic, Balances}; use super::{Call, UncheckedExtrinsic, Balances};
use runtime_primitives::traits::{Checkable, AuxLookup}; use runtime_primitives::traits::{Checkable, Lookup};
use timestamp::Call as TimestampCall; use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall; use parachains::Call as ParachainsCall;
use consensus::Call as ConsensusCall; use consensus::Call as ConsensusCall;
/// Produces the list of inherent extrinsics. /// Produces the list of inherent extrinsics.
pub fn inherent_extrinsics(data: ::primitives::InherentData, spec_version: u32) -> Vec<UncheckedExtrinsic> { pub fn inherent_extrinsics(data: ::primitives::InherentData, spec_version: u32) -> Vec<UncheckedExtrinsic> {
let make_inherent = |function| UncheckedExtrinsic::new( let make_inherent = |function| UncheckedExtrinsic::new_unsigned(0, function);
Extrinsic {
signed: Default::default(),
function,
index: 0,
},
Default::default(),
);
let mut inherent = vec![ let mut inherent = vec![
make_inherent(Call::Timestamp(TimestampCall::set(data.timestamp))), make_inherent(Call::Timestamp(TimestampCall::set(data.timestamp))),
make_inherent(Call::Parachains(ParachainsCall::set_heads(data.parachain_heads))), make_inherent(Call::Parachains(ParachainsCall::set_heads(data.parachain_heads))),
]; ];
if !data.offline_indices.is_empty() && spec_version == 4 { if !data.offline_indices.is_empty() && spec_version == 5 {
inherent.push(make_inherent( inherent.push(make_inherent(
Call::Consensus(ConsensusCall::note_offline(data.offline_indices)) Call::Consensus(ConsensusCall::note_offline(data.offline_indices))
)); ));
+274 -917
View File
File diff suppressed because it is too large Load Diff
+17 -40
View File
@@ -10,47 +10,24 @@ crate-type = ["cdylib"]
integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" } integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" }
polkadot-primitives = { path = "../../primitives", default-features = false } polkadot-primitives = { path = "../../primitives", default-features = false }
safe-mix = { version = "1.0", default-features = false } safe-mix = { version = "1.0", default-features = false }
substrate-codec = { git = "https://github.com/paritytech/substrate", default-features = false } parity-codec = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false } parity-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false } substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-std = { git = "https://github.com/paritytech/substrate", default-features = false } sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-io = { git = "https://github.com/paritytech/substrate", default-features = false } sr-io = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-support = { git = "https://github.com/paritytech/substrate", default-features = false } srml-support = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-balances = { git = "https://github.com/paritytech/substrate", default-features = false } srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-consensus = { git = "https://github.com/paritytech/substrate", default-features = false } srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-council = { git = "https://github.com/paritytech/substrate", default-features = false } srml-council = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-democracy = { git = "https://github.com/paritytech/substrate", default-features = false } srml-democracy = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate", default-features = false } srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate", default-features = false } sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-session = { git = "https://github.com/paritytech/substrate", default-features = false } srml-session = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-staking = { git = "https://github.com/paritytech/substrate", default-features = false } srml-staking = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-system = { git = "https://github.com/paritytech/substrate", default-features = false } srml-system = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false } srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false }
substrate-runtime-version = { git = "https://github.com/paritytech/substrate", default-features = false } srml-treasury = { git = "https://github.com/paritytech/substrate", default-features = false }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
[features]
default = []
std = [
"polkadot-primitives/std",
"safe-mix/std",
"substrate-codec/std",
"substrate-codec-derive/std",
"substrate-primitives/std",
"substrate-runtime-std/std",
"substrate-runtime-io/std",
"substrate-runtime-support/std",
"substrate-runtime-balances/std",
"substrate-runtime-consensus/std",
"substrate-runtime-council/std",
"substrate-runtime-democracy/std",
"substrate-runtime-executive/std",
"substrate-runtime-primitives/std",
"substrate-runtime-session/std",
"substrate-runtime-staking/std",
"substrate-runtime-system/std",
"substrate-runtime-timestamp/std",
"substrate-runtime-version/std",
]
[profile.release] [profile.release]
panic = "abort" panic = "abort"
+1 -2
View File
@@ -11,7 +11,6 @@ log = "0.3"
slog = "^2" slog = "^2"
tokio = "0.1.7" tokio = "0.1.7"
hex-literal = "0.1" hex-literal = "0.1"
ed25519 = { git = "https://github.com/paritytech/substrate" }
polkadot-availability-store = { path = "../availability-store" } polkadot-availability-store = { path = "../availability-store" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
@@ -20,7 +19,7 @@ polkadot-executor = { path = "../executor" }
polkadot-api = { path = "../api" } polkadot-api = { path = "../api" }
polkadot-transaction-pool = { path = "../transaction-pool" } polkadot-transaction-pool = { path = "../transaction-pool" }
polkadot-network = { path = "../network" } polkadot-network = { path = "../network" }
substrate-runtime-io = { git = "https://github.com/paritytech/substrate" } sr-io = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-network = { git = "https://github.com/paritytech/substrate" } substrate-network = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" } substrate-client = { git = "https://github.com/paritytech/substrate" }
+9 -1
View File
@@ -45,7 +45,15 @@
"/ip4/104.211.48.51/tcp/30333/p2p/QmWCnXrhM1in1qPqVT3rDXQEJHedAzbPDMimdjqy2P9fGn", "/ip4/104.211.48.51/tcp/30333/p2p/QmWCnXrhM1in1qPqVT3rDXQEJHedAzbPDMimdjqy2P9fGn",
"/ip4/104.211.48.247/tcp/30333/p2p/QmY33GW69TnTsdQWjAkxJR1GrWTdeV1PmzzcSmUay4HvAB", "/ip4/104.211.48.247/tcp/30333/p2p/QmY33GW69TnTsdQWjAkxJR1GrWTdeV1PmzzcSmUay4HvAB",
"/ip4/40.114.120.164/tcp/30333/p2p/QmWzYU5X1NpFrprD1YZF5Lcj9aE5WF4QEg5FpvQx5XGWG7", "/ip4/40.114.120.164/tcp/30333/p2p/QmWzYU5X1NpFrprD1YZF5Lcj9aE5WF4QEg5FpvQx5XGWG7",
"/ip4/40.117.153.33/tcp/30333/p2p/QmSz8qCADMmi92QB8dTqMPu56JYQQKZBAHz7y8KXjvqcvW" "/ip4/40.117.153.33/tcp/30333/p2p/QmSz8qCADMmi92QB8dTqMPu56JYQQKZBAHz7y8KXjvqcvW",
"/ip4/177.32.114.36/tcp/30333/p2p/QmPgSfuqyjxHWUtQ1fnpAcAdxMsusDNpTQeJsoM5P5HdGn",
"/ip4/149.28.131.52/tcp/30333/p2p/QmXxUhbiH4MrFnPhs1TcAt349ba7jhedA66VQNAwGkRxr7",
"/ip4/144.217.5.91/tcp/30333/p2p/QmUDCNHn87dwZQDd35XTsyjSTfUmJ2iCST9SZeD5ocMkhw",
"/ip4/140.82.45.229/tcp/30333/p2p/QmYGL2yf8UYtCLGfwtZFiE8An59kv5NzYGyEstChbD2vJZ",
"/ip4/45.77.202.29/tcp/30333/p2p/QmbcPnLqWwWZUVW7sU7ttRJHWGGA4jtqxv8V7swwmAMpJ2",
"/ip4/167.99.191.24/tcp/30333/p2p/QmQWZhtBatdb82kaDSQGGzNSFM4F7jTpLTN2v3KUVyKZf7",
"/ip4/35.236.220.53/tcp/30333/p2p/QmQShZHiGGvwijD86qXMFL3e1KjwwakAzGUAc11DPPApSc",
"/ip4/81.187.58.219/tcp/30333/p2p/QmPLEZvyzwpE9CWM3QsB1oQL23FE386sanJQ1gk87J21bF"
], ],
"telemetryUrl": "wss://telemetry.polkadot.io/submit/" "telemetryUrl": "wss://telemetry.polkadot.io/submit/"
} }
+5 -4
View File
@@ -16,8 +16,7 @@
//! Polkadot chain configurations. //! Polkadot chain configurations.
use ed25519; use primitives::{AuthorityId, ed25519};
use primitives::AuthorityId;
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig, use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig}; SessionConfig, StakingConfig, TimestampConfig, BalancesConfig};
use service::ChainSpec; use service::ChainSpec;
@@ -60,7 +59,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
staking: Some(StakingConfig { staking: Some(StakingConfig {
current_era: 0, current_era: 0,
intentions: initial_authorities.iter().cloned().map(Into::into).collect(), intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
early_era_slash: 10000, offline_slash: 10000,
session_reward: 100, session_reward: 100,
validator_count: 12, validator_count: 12,
sessions_per_era: 12, // 1 hour per era sessions_per_era: 12, // 1 hour per era
@@ -92,6 +91,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
timestamp: Some(TimestampConfig { timestamp: Some(TimestampConfig {
period: 5, // 5 second block time. period: 5, // 5 second block time.
}), }),
treasury: Some(Default::default()),
} }
} }
@@ -142,7 +142,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
validator_count: 2, validator_count: 2,
sessions_per_era: 5, sessions_per_era: 5,
bonding_duration: 2 * 60 * 12, bonding_duration: 2 * 60 * 12,
early_era_slash: 0, offline_slash: 0,
session_reward: 0, session_reward: 0,
offline_slash_grace: 0, offline_slash_grace: 0,
}), }),
@@ -170,6 +170,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
timestamp: Some(TimestampConfig { timestamp: Some(TimestampConfig {
period: 5, // 5 second block time. period: 5, // 5 second block time.
}), }),
treasury: Some(Default::default()),
} }
} }
+3 -4
View File
@@ -18,7 +18,6 @@
//! Polkadot service. Specialized wrapper over substrate service. //! Polkadot service. Specialized wrapper over substrate service.
extern crate ed25519;
extern crate polkadot_availability_store as av_store; extern crate polkadot_availability_store as av_store;
extern crate polkadot_primitives; extern crate polkadot_primitives;
extern crate polkadot_runtime; extern crate polkadot_runtime;
@@ -50,7 +49,7 @@ use client::{Client, BlockchainEvents};
use polkadot_network::{PolkadotProtocol, consensus::ConsensusNetwork}; use polkadot_network::{PolkadotProtocol, consensus::ConsensusNetwork};
use tokio::runtime::TaskExecutor; use tokio::runtime::TaskExecutor;
use service::FactoryFullConfiguration; use service::FactoryFullConfiguration;
use primitives::{KeccakHasher, RlpCodec}; use primitives::{Blake2Hasher, RlpCodec};
pub use service::{Roles, PruningMode, ExtrinsicPoolOptions, pub use service::{Roles, PruningMode, ExtrinsicPoolOptions,
ErrorKind, Error, ComponentBlock, LightComponents, FullComponents}; ErrorKind, Error, ComponentBlock, LightComponents, FullComponents};
@@ -67,9 +66,9 @@ pub trait Components: service::Components {
/// Polkadot API. /// Polkadot API.
type Api: 'static + PolkadotApi + Send + Sync; type Api: 'static + PolkadotApi + Send + Sync;
/// Client backend. /// Client backend.
type Backend: 'static + client::backend::Backend<Block, KeccakHasher, RlpCodec>; type Backend: 'static + client::backend::Backend<Block, Blake2Hasher, RlpCodec>;
/// Client executor. /// Client executor.
type Executor: 'static + client::CallExecutor<Block, KeccakHasher, RlpCodec> + Send + Sync; type Executor: 'static + client::CallExecutor<Block, Blake2Hasher, RlpCodec> + Send + Sync;
} }
impl Components for service::LightComponents<Factory> { impl Components for service::LightComponents<Factory> {
+2 -2
View File
@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
[dependencies] [dependencies]
substrate-codec = { git = "https://github.com/paritytech/substrate" } parity-codec = { git = "https://github.com/paritytech/substrate" }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate" } parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
+2 -2
View File
@@ -14,12 +14,12 @@
//! propose and attest to validity of candidates, and those who can only attest //! propose and attest to validity of candidates, and those who can only attest
//! to availability. //! to availability.
extern crate substrate_codec as codec; extern crate parity_codec as codec;
extern crate substrate_primitives; extern crate substrate_primitives;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
pub mod generic; pub mod generic;
+1 -1
View File
@@ -6,5 +6,5 @@ description = "Test parachain which adds to a number as its state transition"
[dependencies] [dependencies]
polkadot-parachain = { path = "../../parachain/", default-features = false } polkadot-parachain = { path = "../../parachain/", default-features = false }
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false } parity-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false }
tiny-keccak = "1.4" tiny-keccak = "1.4"
@@ -8,7 +8,7 @@ adder = { path = ".." }
polkadot-parachain = { path = "../../../parachain" } polkadot-parachain = { path = "../../../parachain" }
polkadot-collator = { path = "../../../collator" } polkadot-collator = { path = "../../../collator" }
polkadot-primitives = { path = "../../../primitives" } polkadot-primitives = { path = "../../../primitives" }
ed25519 = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
parking_lot = "0.4" parking_lot = "0.4"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
futures = "0.1" futures = "0.1"
@@ -17,10 +17,10 @@
//! Collator for polkadot //! Collator for polkadot
extern crate adder; extern crate adder;
extern crate substrate_primitives;
extern crate polkadot_parachain as parachain; extern crate polkadot_parachain as parachain;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
extern crate polkadot_collator as collator; extern crate polkadot_collator as collator;
extern crate ed25519;
extern crate parking_lot; extern crate parking_lot;
extern crate ctrlc; extern crate ctrlc;
extern crate futures; extern crate futures;
@@ -31,7 +31,7 @@ use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use adder::{HeadData as AdderHead, BlockData as AdderBody}; use adder::{HeadData as AdderHead, BlockData as AdderBody};
use ed25519::Pair; use substrate_primitives::ed25519::Pair;
use parachain::codec::{Encode, Decode}; use parachain::codec::{Encode, Decode};
use primitives::parachain::{HeadData, BlockData, Id as ParaId, Message}; use primitives::parachain::{HeadData, BlockData, Id as ParaId, Message};
use collator::{InvalidHead, ParachainContext, VersionInfo}; use collator::{InvalidHead, ParachainContext, VersionInfo};
+1 -1
View File
@@ -19,7 +19,7 @@
#![no_std] #![no_std]
#[macro_use] #[macro_use]
extern crate substrate_codec_derive; extern crate parity_codec_derive;
extern crate polkadot_parachain as parachain; extern crate polkadot_parachain as parachain;
extern crate tiny_keccak; extern crate tiny_keccak;
+2 -3
View File
@@ -11,9 +11,8 @@ polkadot-api = { path = "../api" }
polkadot-primitives = { path = "../primitives" } polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" } polkadot-runtime = { path = "../runtime" }
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-keyring = { git = "https://github.com/paritytech/substrate" } substrate-keyring = { git = "https://github.com/paritytech/substrate" }
substrate-extrinsic-pool = { git = "https://github.com/paritytech/substrate" } substrate-extrinsic-pool = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" } substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" } sr-primitives = { git = "https://github.com/paritytech/substrate" }
ed25519 = { git = "https://github.com/paritytech/substrate" }
+31 -30
View File
@@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
extern crate ed25519;
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_extrinsic_pool as extrinsic_pool; extern crate substrate_extrinsic_pool as extrinsic_pool;
extern crate substrate_primitives; extern crate substrate_primitives;
extern crate substrate_runtime_primitives; extern crate sr_primitives;
extern crate polkadot_runtime as runtime; extern crate polkadot_runtime as runtime;
extern crate polkadot_primitives as primitives; extern crate polkadot_primitives as primitives;
extern crate polkadot_api; extern crate polkadot_api;
@@ -47,7 +46,7 @@ use extrinsic_pool::{Readiness, scoring::{Change, Choice}, VerifiedFor, Extrinsi
use polkadot_api::PolkadotApi; use polkadot_api::PolkadotApi;
use primitives::{AccountId, BlockId, Block, Hash, Index}; use primitives::{AccountId, BlockId, Block, Hash, Index};
use runtime::{Address, UncheckedExtrinsic}; use runtime::{Address, UncheckedExtrinsic};
use substrate_runtime_primitives::traits::{Bounded, Checkable, Hash as HashT, BlakeTwo256}; use sr_primitives::traits::{Bounded, Checkable, Hash as HashT, BlakeTwo256};
pub use extrinsic_pool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps}; pub use extrinsic_pool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps};
pub use error::{Error, ErrorKind, Result}; pub use error::{Error, ErrorKind, Result};
@@ -182,7 +181,13 @@ impl<A> extrinsic_pool::ChainApi for ChainApi<A> where
Err(Self::NO_ACCOUNT) => None, Err(Self::NO_ACCOUNT) => None,
Err(e) => bail!(e), Err(e) => bail!(e),
}; };
let sender = inner.as_ref().map(|x| x.signed.clone()); let sender = match inner.as_ref() {
Some(cxt) => match cxt.signed {
Some(ref sender) => Some(sender.clone()),
None => bail!(ErrorKind::IsInherent(uxt))
},
None => None,
};
if encoded_size < 1024 { if encoded_size < 1024 {
debug!(target: "transaction-pool", "Transaction verified: {} => {:?}", hash, uxt); debug!(target: "transaction-pool", "Transaction verified: {} => {:?}", hash, uxt);
@@ -191,7 +196,7 @@ impl<A> extrinsic_pool::ChainApi for ChainApi<A> where
} }
Ok(VerifiedTransaction { Ok(VerifiedTransaction {
index: uxt.extrinsic.index, index: uxt.index,
inner, inner,
sender, sender,
hash, hash,
@@ -291,9 +296,9 @@ mod tests {
use polkadot_api::{PolkadotApi, BlockBuilder, Result}; use polkadot_api::{PolkadotApi, BlockBuilder, Result};
use primitives::{AccountId, AccountIndex, Block, BlockId, Hash, Index, SessionKey, use primitives::{AccountId, AccountIndex, Block, BlockId, Hash, Index, SessionKey,
UncheckedExtrinsic as FutureProofUncheckedExtrinsic}; UncheckedExtrinsic as FutureProofUncheckedExtrinsic};
use runtime::{RawAddress, Call, TimestampCall, BareExtrinsic, Extrinsic, UncheckedExtrinsic}; use runtime::{RawAddress, Call, TimestampCall, UncheckedExtrinsic};
use primitives::parachain::{DutyRoster, Id as ParaId}; use primitives::parachain::{DutyRoster, Id as ParaId};
use substrate_runtime_primitives::{MaybeUnsigned, generic}; use sr_primitives::generic;
use extrinsic_pool::Pool; use extrinsic_pool::Pool;
use super::ChainApi; use super::ChainApi;
@@ -340,7 +345,7 @@ mod tests {
fn parachain_code(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() } fn parachain_code(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() }
fn parachain_head(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() } fn parachain_head(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() }
fn build_block(&self, _at: &BlockId, _inherent: ::primitives::InherentData) -> Result<Self::BlockBuilder> { unimplemented!() } fn build_block(&self, _at: &BlockId, _inherent: ::primitives::InherentData) -> Result<Self::BlockBuilder> { unimplemented!() }
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: ::primitives::InherentData) -> Result<Vec<Vec<u8>>> { unimplemented!() } fn inherent_extrinsics(&self, _at: &BlockId, _inherent: ::primitives::InherentData) -> Result<Vec<::primitives::UncheckedExtrinsic>> { unimplemented!() }
fn index(&self, _at: &BlockId, _account: AccountId) -> Result<Index> { fn index(&self, _at: &BlockId, _account: AccountId) -> Result<Index> {
Ok((_account[0] as u32) + number_of(_at)) Ok((_account[0] as u32) + number_of(_at))
@@ -366,28 +371,24 @@ mod tests {
} }
fn uxt(who: Keyring, nonce: Index, use_id: bool) -> FutureProofUncheckedExtrinsic { fn uxt(who: Keyring, nonce: Index, use_id: bool) -> FutureProofUncheckedExtrinsic {
let sxt = BareExtrinsic { let sxt = (nonce, Call::Timestamp(TimestampCall::set(0)));
signed: who.to_raw_public().into(),
index: nonce,
function: Call::Timestamp(TimestampCall::set(0)),
};
let sig = sxt.using_encoded(|e| who.sign(e)); let sig = sxt.using_encoded(|e| who.sign(e));
UncheckedExtrinsic::new(Extrinsic { let signed = who.to_raw_public().into();
signed: if use_id { RawAddress::Id(sxt.signed) } else { RawAddress::Index( let sender = if use_id { RawAddress::Id(signed) } else { RawAddress::Index(
match who { match who {
Alice => 0, Alice => 0,
Bob => 1, Bob => 1,
Charlie => 2, Charlie => 2,
Dave => 3, Dave => 3,
Eve => 4, Eve => 4,
Ferdie => 5, Ferdie => 5,
One => 6, One => 6,
Two => 7, Two => 7,
} }
)}, )};
index: sxt.index, UncheckedExtrinsic::new_signed(sxt.0, sxt.1, sender, sig.into())
function: sxt.function, .using_encoded(|e| FutureProofUncheckedExtrinsic::decode(&mut &e[..]))
}, MaybeUnsigned(sig.into())).using_encoded(|e| FutureProofUncheckedExtrinsic::decode(&mut &e[..])).unwrap() .unwrap()
} }
fn pool(api: &TestPolkadotApi) -> Pool<ChainApi<TestPolkadotApi>> { fn pool(api: &TestPolkadotApi) -> Pool<ChainApi<TestPolkadotApi>> {