mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
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:
committed by
Arkadiy Paronyan
parent
17ede5b8a0
commit
84748fccd3
Generated
+777
-751
File diff suppressed because it is too large
Load Diff
@@ -39,7 +39,6 @@ members = [
|
||||
exclude = [
|
||||
"runtime/wasm",
|
||||
"test-parachains/adder/wasm",
|
||||
"demo/runtime/wasm",
|
||||
]
|
||||
|
||||
[badges]
|
||||
|
||||
@@ -9,10 +9,10 @@ log = "0.3"
|
||||
polkadot-executor = { path = "../executor" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-io = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-io = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-executive = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-executor = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
+25
-83
@@ -18,70 +18,22 @@
|
||||
|
||||
use client::backend::LocalBackend;
|
||||
use client::block_builder::BlockBuilder as ClientBlockBuilder;
|
||||
use client::{self, Client, LocalCallExecutor, CallExecutor};
|
||||
use codec::{Encode, Decode};
|
||||
use client::{Client, LocalCallExecutor};
|
||||
use polkadot_executor::Executor as LocalDispatch;
|
||||
use substrate_executor::NativeExecutor;
|
||||
use state_machine::ExecutionManager;
|
||||
|
||||
//use runtime::{Block, Header, Address, BlockId};
|
||||
use runtime::Address;
|
||||
use primitives::{
|
||||
AccountId, Block, Header, BlockId, Hash, Index, InherentData,
|
||||
Block, BlockId,
|
||||
AccountId, Hash, Index, InherentData,
|
||||
SessionKey, Timestamp, UncheckedExtrinsic,
|
||||
};
|
||||
use primitives::parachain::{DutyRoster, Id as ParaId};
|
||||
use substrate_primitives::{KeccakHasher, RlpCodec};
|
||||
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, Error, ErrorKind, Result};
|
||||
use substrate_primitives::{Blake2Hasher, RlpCodec};
|
||||
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Result};
|
||||
|
||||
fn call<B, R>(
|
||||
client: &Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>,
|
||||
at: &BlockId,
|
||||
function: &'static str,
|
||||
input: &[u8])
|
||||
-> Result<R>
|
||||
where
|
||||
R: Decode,
|
||||
B: LocalBackend<Block, KeccakHasher, RlpCodec>,
|
||||
{
|
||||
let parent = at;
|
||||
let header = Header {
|
||||
parent_hash: client.block_hash_from_id(&parent)?
|
||||
.ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))?,
|
||||
number: client.block_number_from_id(&parent)?
|
||||
.ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))? + 1,
|
||||
state_root: Default::default(),
|
||||
extrinsics_root: Default::default(),
|
||||
digest: Default::default(),
|
||||
};
|
||||
client.state_at(&parent).map_err(Error::from).and_then(|state| {
|
||||
let mut overlay = Default::default();
|
||||
let execution_manager = || ExecutionManager::Both(|wasm_result, native_result| {
|
||||
warn!("Consensus error between wasm and native runtime execution at block {:?}", at);
|
||||
warn!(" Function {:?}", function);
|
||||
warn!(" Native result {:?}", native_result);
|
||||
warn!(" Wasm result {:?}", wasm_result);
|
||||
wasm_result
|
||||
});
|
||||
client.executor().call_at_state(
|
||||
&state,
|
||||
&mut overlay,
|
||||
"initialise_block",
|
||||
&header.encode(),
|
||||
execution_manager()
|
||||
)?;
|
||||
let (r, _) = client.executor().call_at_state(
|
||||
&state,
|
||||
&mut overlay,
|
||||
function,
|
||||
input,
|
||||
execution_manager()
|
||||
)?;
|
||||
Ok(R::decode(&mut &r[..])
|
||||
.ok_or_else(|| client::error::Error::from(client::error::ErrorKind::CallResultDecode(function)))?)
|
||||
})
|
||||
}
|
||||
|
||||
impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, KeccakHasher, RlpCodec> {
|
||||
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec> {
|
||||
fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
|
||||
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> {
|
||||
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, KeccakHasher, RlpCodec>;
|
||||
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block> {
|
||||
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec>;
|
||||
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
|
||||
Ok(self.authorities_at(at)?)
|
||||
}
|
||||
|
||||
fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>> {
|
||||
call(self, at, "validators", &[])
|
||||
Ok(self.call_api_at(at, "validators", &())?)
|
||||
}
|
||||
|
||||
fn random_seed(&self, at: &BlockId) -> Result<Hash> {
|
||||
call(self, at, "random_seed", &[])
|
||||
Ok(self.call_api_at(at, "random_seed", &())?)
|
||||
}
|
||||
|
||||
fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster> {
|
||||
call(self, at, "duty_roster", &[])
|
||||
Ok(self.call_api_at(at, "duty_roster", &())?)
|
||||
}
|
||||
|
||||
fn timestamp(&self, at: &BlockId) -> Result<Timestamp> {
|
||||
call(self, at, "timestamp", &[])
|
||||
Ok(self.call_api_at(at, "timestamp", &())?)
|
||||
}
|
||||
|
||||
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool> {
|
||||
let encoded = block.encode();
|
||||
let res: Result<()> = call(self, at, "execute_block", &encoded);
|
||||
let res: Result<()> = self.call_api_at(at, "execute_block", &block).map_err(From::from);
|
||||
match res {
|
||||
Ok(_) => Ok(true),
|
||||
Err(err) => match err.kind() {
|
||||
@@ -128,31 +79,23 @@ impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> PolkadotApi for Client<B, L
|
||||
}
|
||||
|
||||
fn index(&self, at: &BlockId, account: AccountId) -> Result<Index> {
|
||||
account.using_encoded(|encoded| {
|
||||
call(self, at, "account_nonce", encoded)
|
||||
})
|
||||
Ok(self.call_api_at(at, "account_nonce", &account)?)
|
||||
}
|
||||
|
||||
fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>> {
|
||||
address.using_encoded(|encoded| {
|
||||
call(self, at, "lookup_address", encoded)
|
||||
})
|
||||
Ok(self.call_api_at(at, "lookup_address", &address)?)
|
||||
}
|
||||
|
||||
fn active_parachains(&self, at: &BlockId) -> Result<Vec<ParaId>> {
|
||||
call(self, at, "active_parachains", &[])
|
||||
Ok(self.call_api_at(at, "active_parachains", &())?)
|
||||
}
|
||||
|
||||
fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
parachain.using_encoded(|encoded| {
|
||||
call(self, at, "parachain_code", encoded)
|
||||
})
|
||||
Ok(self.call_api_at(at, "parachain_code", ¶chain)?)
|
||||
}
|
||||
|
||||
fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
parachain.using_encoded(|encoded| {
|
||||
call(self, at, "parachain_head", encoded)
|
||||
})
|
||||
Ok(self.call_api_at(at, "parachain_head", ¶chain)?)
|
||||
}
|
||||
|
||||
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>> {
|
||||
let runtime_version = self.runtime_version_at(at)?;
|
||||
(inherent_data, runtime_version.spec_version).using_encoded(|encoded| {
|
||||
call(self, at, "inherent_extrinsics", encoded)
|
||||
})
|
||||
Ok(self.call_api_at(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version))?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: LocalBackend<Block, KeccakHasher, RlpCodec>> LocalPolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
|
||||
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> LocalPolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
|
||||
{}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -198,7 +139,7 @@ mod tests {
|
||||
]
|
||||
}
|
||||
|
||||
fn client() -> Client<InMemory<Block, KeccakHasher, RlpCodec>, LocalCallExecutor<InMemory<Block, KeccakHasher, RlpCodec>, NativeExecutor<LocalDispatch>>, Block> {
|
||||
fn client() -> Client<InMemory<Block, Blake2Hasher, RlpCodec>, LocalCallExecutor<InMemory<Block, Blake2Hasher, RlpCodec>, NativeExecutor<LocalDispatch>>, Block> {
|
||||
let genesis_config = GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: LocalDispatch::native_equivalent().to_vec(),
|
||||
@@ -215,9 +156,10 @@ mod tests {
|
||||
parachains: Some(Default::default()),
|
||||
staking: Some(Default::default()),
|
||||
timestamp: Some(Default::default()),
|
||||
treasury: Some(Default::default()),
|
||||
};
|
||||
|
||||
::client::new_in_mem(LocalDispatch::with_heap_pages(8), genesis_config).unwrap()
|
||||
::client::new_in_mem(LocalDispatch::new(), genesis_config).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -273,6 +215,6 @@ mod tests {
|
||||
let client = client();
|
||||
|
||||
let id = BlockId::number(0);
|
||||
assert!(client.random_seed(&id).is_ok());
|
||||
client.random_seed(&id).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +20,18 @@
|
||||
extern crate polkadot_executor;
|
||||
extern crate polkadot_primitives as primitives;
|
||||
extern crate polkadot_runtime as runtime;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate sr_io as runtime_io;
|
||||
extern crate substrate_client as client;
|
||||
extern crate substrate_executor as substrate_executor;
|
||||
extern crate substrate_runtime_executive;
|
||||
extern crate srml_executive;
|
||||
extern crate substrate_primitives;
|
||||
extern crate substrate_runtime_primitives as runtime_primitives;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
extern crate substrate_state_machine as state_machine;
|
||||
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -27,7 +27,7 @@ use primitives::{
|
||||
use runtime::Address;
|
||||
use primitives::parachain::{DutyRoster, Id as ParaId};
|
||||
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind};
|
||||
use substrate_primitives::{KeccakHasher, RlpCodec};
|
||||
use substrate_primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
/// Light block builder. TODO: make this work (efficiently)
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -44,9 +44,9 @@ impl BlockBuilder for LightBlockBuilder {
|
||||
}
|
||||
|
||||
/// Remote polkadot API implementation.
|
||||
pub struct RemotePolkadotApiWrapper<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>>(pub Arc<Client<B, E, Block>>);
|
||||
pub struct RemotePolkadotApiWrapper<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>>(pub Arc<Client<B, E, Block>>);
|
||||
|
||||
impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>> PolkadotApi for RemotePolkadotApiWrapper<B, E> {
|
||||
impl<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> PolkadotApi for RemotePolkadotApiWrapper<B, E> {
|
||||
type BlockBuilder = LightBlockBuilder;
|
||||
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
|
||||
@@ -100,9 +100,9 @@ impl<B: Backend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHas
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<Vec<u8>>> {
|
||||
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<UncheckedExtrinsic>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: RemoteBackend<Block, KeccakHasher, RlpCodec>, E: CallExecutor<Block, KeccakHasher, RlpCodec>> RemotePolkadotApi for RemotePolkadotApiWrapper<B, E> {}
|
||||
impl<B: RemoteBackend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> RemotePolkadotApi for RemotePolkadotApiWrapper<B, E> {}
|
||||
|
||||
@@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
parking_lot = "0.4"
|
||||
log = "0.3"
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
kvdb = { git = "https://github.com/paritytech/parity-common.git" }
|
||||
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common.git" }
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
extern crate polkadot_primitives;
|
||||
extern crate parking_lot;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_primitives;
|
||||
extern crate kvdb;
|
||||
extern crate kvdb_rocksdb;
|
||||
|
||||
@@ -24,6 +24,5 @@ case $TARGET in
|
||||
# Install prerequisites and build all wasm projects
|
||||
./scripts/init.sh
|
||||
./scripts/build.sh
|
||||
./scripts/build-demos.sh
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -7,12 +7,11 @@ description = "Collator node implementation"
|
||||
[dependencies]
|
||||
futures = "0.1.17"
|
||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
polkadot-api = { path = "../api" }
|
||||
polkadot-runtime = { path = "../runtime", version = "0.1" }
|
||||
polkadot-primitives = { path = "../primitives", version = "0.1" }
|
||||
polkadot-cli = { path = "../cli" }
|
||||
log = "0.4"
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
tokio = "0.1.7"
|
||||
|
||||
@@ -46,9 +46,8 @@
|
||||
|
||||
extern crate futures;
|
||||
extern crate substrate_client as client;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_primitives as primitives;
|
||||
extern crate ed25519;
|
||||
extern crate tokio;
|
||||
|
||||
extern crate polkadot_api;
|
||||
@@ -67,6 +66,7 @@ use std::time::{Duration, Instant};
|
||||
use futures::{future, stream, Stream, Future, IntoFuture};
|
||||
use client::BlockchainEvents;
|
||||
use polkadot_api::PolkadotApi;
|
||||
use primitives::ed25519;
|
||||
use polkadot_primitives::{AccountId, BlockId, SessionKey};
|
||||
use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId};
|
||||
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration};
|
||||
|
||||
@@ -7,7 +7,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
futures = "0.1.17"
|
||||
parking_lot = "0.4"
|
||||
tokio = "0.1.7"
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
error-chain = "0.12"
|
||||
log = "0.3"
|
||||
exit-future = "0.1"
|
||||
@@ -20,11 +19,11 @@ polkadot-runtime = { path = "../runtime" }
|
||||
polkadot-statement-table = { path = "../statement-table" }
|
||||
polkadot-transaction-pool = { path = "../transaction-pool" }
|
||||
substrate-bft = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-support = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-support = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-keyring = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
//!
|
||||
//! Groups themselves may be compromised by malicious authorities.
|
||||
|
||||
extern crate ed25519;
|
||||
extern crate parking_lot;
|
||||
extern crate polkadot_api;
|
||||
extern crate polkadot_availability_store as extrinsic_store;
|
||||
@@ -40,10 +39,10 @@ extern crate polkadot_runtime;
|
||||
extern crate polkadot_primitives;
|
||||
|
||||
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_runtime_support as runtime_support;
|
||||
extern crate substrate_runtime_primitives as runtime_primitives;
|
||||
extern crate srml_support as runtime_support;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
extern crate substrate_client as client;
|
||||
|
||||
extern crate exit_future;
|
||||
@@ -71,7 +70,7 @@ use extrinsic_store::Store as ExtrinsicStore;
|
||||
use polkadot_api::PolkadotApi;
|
||||
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 primitives::AuthorityId;
|
||||
use primitives::{AuthorityId, ed25519};
|
||||
use transaction_pool::TransactionPool;
|
||||
use tokio::runtime::TaskExecutor;
|
||||
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>)>) {
|
||||
use rhododendron::Misbehavior as GenericMisbehavior;
|
||||
use runtime_primitives::bft::{MisbehaviorKind, MisbehaviorReport};
|
||||
use runtime_primitives::MaybeUnsigned;
|
||||
use polkadot_runtime::{Call, Extrinsic, BareExtrinsic, UncheckedExtrinsic, ConsensusCall};
|
||||
use polkadot_runtime::{Call, UncheckedExtrinsic, ConsensusCall, RawAddress};
|
||||
|
||||
let local_id = self.local_key.public().0.into();
|
||||
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)),
|
||||
}
|
||||
};
|
||||
let extrinsic = BareExtrinsic {
|
||||
signed: local_id,
|
||||
index: next_index,
|
||||
function: Call::Consensus(ConsensusCall::report_misbehavior(report)),
|
||||
};
|
||||
|
||||
let payload = (next_index, Call::Consensus(ConsensusCall::report_misbehavior(report)));
|
||||
let signature = self.local_key.sign(&payload.encode()).into();
|
||||
next_index += 1;
|
||||
|
||||
let signature = MaybeUnsigned(self.local_key.sign(&extrinsic.encode()).into());
|
||||
|
||||
let extrinsic = Extrinsic {
|
||||
signed: extrinsic.signed.into(),
|
||||
index: extrinsic.index,
|
||||
function: extrinsic.function,
|
||||
let local_id = self.local_key.public().0.into();
|
||||
let extrinsic = UncheckedExtrinsic {
|
||||
signature: Some((RawAddress::Id(local_id), signature)),
|
||||
index: payload.0,
|
||||
function: payload.1,
|
||||
};
|
||||
let uxt: Vec<u8> = Decode::decode(&mut UncheckedExtrinsic::new(extrinsic, signature).encode().as_slice()).expect("Encoded extrinsic is valid");
|
||||
self.transaction_pool.submit_one(&BlockId::hash(self.parent_hash), uxt)
|
||||
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), polkadot_primitives::UncheckedExtrinsic(uxt))
|
||||
.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.
|
||||
let consider_online = was_proposed || {
|
||||
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 {
|
||||
None => info!(
|
||||
"Potential Offline Validator: {} failed to propose during assigned slot: {}",
|
||||
|
||||
@@ -29,7 +29,7 @@ use std::sync::Arc;
|
||||
|
||||
use bft::{self, BftService};
|
||||
use client::{BlockchainEvents, ChainHead, BlockBody};
|
||||
use ed25519;
|
||||
use primitives::ed25519;
|
||||
use futures::prelude::*;
|
||||
use polkadot_api::LocalPolkadotApi;
|
||||
use polkadot_primitives::{Block, Header};
|
||||
|
||||
@@ -30,6 +30,7 @@ use futures::{future, prelude::*};
|
||||
|
||||
use super::{GroupInfo, TableRouter};
|
||||
use self::includable::IncludabilitySender;
|
||||
use primitives::ed25519;
|
||||
|
||||
mod includable;
|
||||
|
||||
@@ -39,7 +40,7 @@ pub use table::generic::Statement as GenericStatement;
|
||||
|
||||
struct TableContext {
|
||||
parent_hash: Hash,
|
||||
key: Arc<::ed25519::Pair>,
|
||||
key: Arc<ed25519::Pair>,
|
||||
groups: HashMap<ParaId, GroupInfo>,
|
||||
}
|
||||
|
||||
@@ -320,7 +321,7 @@ impl SharedTable {
|
||||
/// block being built.
|
||||
pub fn new(
|
||||
groups: HashMap<ParaId, GroupInfo>,
|
||||
key: Arc<::ed25519::Pair>,
|
||||
key: Arc<ed25519::Pair>,
|
||||
parent_hash: Hash,
|
||||
extrinsic_store: ExtrinsicStore,
|
||||
) -> Self {
|
||||
|
||||
@@ -11,11 +11,10 @@ polkadot-availability-store = { path = "../availability-store" }
|
||||
polkadot-consensus = { path = "../consensus" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
substrate-bft = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-network = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
futures = "0.1"
|
||||
tokio = "0.1.7"
|
||||
log = "0.4"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//! each time consensus begins on a new chain head.
|
||||
|
||||
use bft;
|
||||
use ed25519;
|
||||
use substrate_primitives::ed25519;
|
||||
use substrate_network::{self as net, generic_message as msg};
|
||||
use substrate_network::consensus_gossip::ConsensusMessage;
|
||||
use polkadot_api::{PolkadotApi, LocalPolkadotApi};
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
//! and more.
|
||||
|
||||
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_primitives;
|
||||
|
||||
@@ -30,7 +30,6 @@ extern crate polkadot_availability_store as av_store;
|
||||
extern crate polkadot_consensus;
|
||||
extern crate polkadot_primitives;
|
||||
|
||||
extern crate ed25519;
|
||||
extern crate futures;
|
||||
extern crate parking_lot;
|
||||
extern crate tokio;
|
||||
@@ -39,7 +38,7 @@ extern crate rhododendron;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
mod collator_pool;
|
||||
mod local_collations;
|
||||
|
||||
@@ -5,8 +5,8 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "Types and utilities for creating and working with parachains"
|
||||
|
||||
[dependencies]
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
parity-codec = { 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 }
|
||||
error-chain = { version = "0.12", optional = true }
|
||||
|
||||
@@ -15,4 +15,4 @@ tiny-keccak = "1.4"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["substrate-codec/std", "wasmi", "error-chain"]
|
||||
std = ["parity-codec/std", "wasmi", "error-chain"]
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||
|
||||
/// Re-export of substrate-codec.
|
||||
pub extern crate substrate_codec as codec;
|
||||
/// Re-export of parity-codec.
|
||||
pub extern crate parity_codec as codec;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
extern crate alloc;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
//! Basic parachain that adds a number as part of its state.
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate parity_codec_derive;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate polkadot_parachain as parachain;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0", default_features = false }
|
||||
serde_derive = { version = "1.0", optional = true }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
parity-codec = { 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-runtime-std = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
sr-std = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate", default_features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
substrate-serializer = { git = "https://github.com/paritytech/substrate" }
|
||||
@@ -19,10 +19,10 @@ pretty_assertions = "0.4"
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"substrate-codec/std",
|
||||
"parity-codec/std",
|
||||
"substrate-primitives/std",
|
||||
"substrate-runtime-std/std",
|
||||
"substrate-runtime-primitives/std",
|
||||
"sr-std/std",
|
||||
"sr-primitives/std",
|
||||
"serde_derive",
|
||||
"serde/std",
|
||||
]
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![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_runtime_primitives as runtime_primitives;
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
extern crate sr_std as rstd;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate substrate_serializer;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
@@ -39,27 +39,12 @@ extern crate serde_derive;
|
||||
#[cfg(feature = "std")]
|
||||
extern crate serde;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use primitives::bytes;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use runtime_primitives::traits::BlakeTwo256;
|
||||
use runtime_primitives::generic;
|
||||
|
||||
use runtime_primitives::{generic, traits::BlakeTwo256};
|
||||
pub mod parachain;
|
||||
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
|
||||
|
||||
/// 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>;
|
||||
#[cfg(feature = "std")]
|
||||
use primitives::bytes;
|
||||
|
||||
/// An index to a block.
|
||||
/// 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.
|
||||
/// 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.
|
||||
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.
|
||||
pub type Balance = u128;
|
||||
|
||||
/// "generic" block ID for the future-proof block type.
|
||||
// TODO: parameterize blockid only as necessary.
|
||||
/// Header type.
|
||||
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>;
|
||||
|
||||
/// A log entry in the block.
|
||||
/// Opaque, encoded, unchecked extrinsic.
|
||||
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
|
||||
#[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.
|
||||
#[derive(Encode, Decode)]
|
||||
|
||||
+34
-32
@@ -10,25 +10,26 @@ serde = { version = "1.0", default_features = false }
|
||||
serde_derive = { version = "1.0", optional = true }
|
||||
safe-mix = { version = "1.0", default_features = false}
|
||||
polkadot-primitives = { path = "../primitives", default_features = false }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-serializer = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-std = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-io = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-support = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-std = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-io = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-support = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-keyring = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-balances = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-consensus = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-council = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-democracy = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-session = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-staking = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-system = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-timestamp = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-version = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-balances = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-consensus = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-council = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-democracy = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-executive = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-session = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-staking = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-system = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-timestamp = { git = "https://github.com/paritytech/substrate" }
|
||||
srml-treasury = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-version = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
@@ -37,23 +38,24 @@ hex-literal = "0.1.0"
|
||||
default = ["std"]
|
||||
std = [
|
||||
"polkadot-primitives/std",
|
||||
"substrate-codec/std",
|
||||
"substrate-codec-derive/std",
|
||||
"parity-codec/std",
|
||||
"parity-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",
|
||||
"sr-std/std",
|
||||
"sr-io/std",
|
||||
"srml-support/std",
|
||||
"srml-balances/std",
|
||||
"srml-consensus/std",
|
||||
"srml-council/std",
|
||||
"srml-democracy/std",
|
||||
"srml-executive/std",
|
||||
"sr-primitives/std",
|
||||
"srml-session/std",
|
||||
"srml-staking/std",
|
||||
"srml-system/std",
|
||||
"srml-timestamp/std",
|
||||
"srml-treasury/std",
|
||||
"sr-version/std",
|
||||
"serde_derive",
|
||||
"serde/std",
|
||||
"log",
|
||||
|
||||
@@ -32,7 +32,7 @@ impl CheckedBlock {
|
||||
/// Create a new checked block. Fails if the block is not structurally valid.
|
||||
pub fn new(block: Block) -> Result<Self, Block> {
|
||||
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,
|
||||
_ => false,
|
||||
}
|
||||
@@ -41,7 +41,7 @@ impl CheckedBlock {
|
||||
if !has_timestamp { return Err(block) }
|
||||
|
||||
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,
|
||||
_ => false,
|
||||
}
|
||||
@@ -66,7 +66,7 @@ impl CheckedBlock {
|
||||
|
||||
/// Extract the timestamp from the block.
|
||||
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),
|
||||
_ => None
|
||||
});
|
||||
@@ -79,7 +79,7 @@ impl CheckedBlock {
|
||||
|
||||
/// Extract the parachain heads from the block.
|
||||
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[..]),
|
||||
_ => None
|
||||
});
|
||||
@@ -92,7 +92,7 @@ impl CheckedBlock {
|
||||
|
||||
/// Extract the noted missed proposal validator indices (if any) from the block.
|
||||
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[..]),
|
||||
_ => None,
|
||||
}).unwrap_or(&[])
|
||||
|
||||
+191
-158
@@ -26,13 +26,13 @@ extern crate serde_derive;
|
||||
extern crate serde;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_io as runtime_io;
|
||||
extern crate sr_io as runtime_io;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_support;
|
||||
extern crate srml_support;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_primitives as runtime_primitives;
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
@@ -44,23 +44,24 @@ extern crate substrate_serializer;
|
||||
extern crate substrate_primitives;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_std as rstd;
|
||||
extern crate sr_std as rstd;
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
extern crate polkadot_primitives as primitives;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_runtime_balances as balances;
|
||||
extern crate substrate_runtime_consensus as consensus;
|
||||
extern crate substrate_runtime_council as council;
|
||||
extern crate substrate_runtime_democracy as democracy;
|
||||
extern crate substrate_runtime_executive as executive;
|
||||
extern crate substrate_runtime_session as session;
|
||||
extern crate substrate_runtime_staking as staking;
|
||||
extern crate substrate_runtime_system as system;
|
||||
extern crate substrate_runtime_timestamp as timestamp;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate srml_balances as balances;
|
||||
extern crate srml_consensus as consensus;
|
||||
extern crate srml_council as council;
|
||||
extern crate srml_democracy as democracy;
|
||||
extern crate srml_executive as executive;
|
||||
extern crate srml_session as session;
|
||||
extern crate srml_staking as staking;
|
||||
extern crate srml_system as system;
|
||||
extern crate srml_timestamp as timestamp;
|
||||
extern crate srml_treasury as treasury;
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_version as version;
|
||||
extern crate sr_version as version;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod checked_block;
|
||||
@@ -72,9 +73,13 @@ pub use checked_block::CheckedBlock;
|
||||
pub use utils::{inherent_extrinsics, check_extrinsic};
|
||||
pub use balances::address::Address as RawAddress;
|
||||
|
||||
use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature};
|
||||
use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}};
|
||||
use rstd::prelude::*;
|
||||
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 council::{motions as council_motions, voting as council_voting};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use runtime_primitives::BuildStorage;
|
||||
@@ -82,7 +87,6 @@ pub use runtime_primitives::BuildStorage;
|
||||
pub use consensus::Call as ConsensusCall;
|
||||
pub use timestamp::Call as TimestampCall;
|
||||
pub use parachains::Call as ParachainsCall;
|
||||
pub use primitives::Header;
|
||||
|
||||
/// The position of the timestamp set extrinsic.
|
||||
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.
|
||||
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.
|
||||
pub type Address = balances::Address<Concrete>;
|
||||
pub type Address = balances::Address<Runtime>;
|
||||
/// Block Id type for this block.
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call, Signature>;
|
||||
/// Extrinsic type as expected by this runtime. This is not the type that is signed.
|
||||
pub type Extrinsic = generic::Extrinsic<Address, Index, Call>;
|
||||
/// Extrinsic type that is signed.
|
||||
pub type BareExtrinsic = generic::Extrinsic<AccountId, Index, Call>;
|
||||
/// Extrinsic type that has already been checked.
|
||||
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Index, Call>;
|
||||
/// Block type as expected by this runtime.
|
||||
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.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub struct Concrete;
|
||||
pub struct Runtime;
|
||||
|
||||
/// Polkadot runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
@@ -119,19 +123,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
};
|
||||
|
||||
impl version::Trait for Concrete {
|
||||
const VERSION: RuntimeVersion = VERSION;
|
||||
}
|
||||
|
||||
/// 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;
|
||||
impl system::Trait for Runtime {
|
||||
type Origin = Origin;
|
||||
type Index = Index;
|
||||
type BlockNumber = BlockNumber;
|
||||
type Hash = Hash;
|
||||
@@ -142,9 +135,9 @@ impl system::Trait for Concrete {
|
||||
type Event = Event;
|
||||
}
|
||||
/// 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 AccountIndex = AccountIndex;
|
||||
type OnFreeBalanceZero = Staking;
|
||||
@@ -152,22 +145,23 @@ impl balances::Trait for Concrete {
|
||||
type Event = Event;
|
||||
}
|
||||
/// 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;
|
||||
type Log = Log;
|
||||
type SessionKey = SessionKey;
|
||||
type OnOfflineValidator = Staking;
|
||||
}
|
||||
/// 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;
|
||||
type Moment = u64;
|
||||
}
|
||||
/// Timestamp module for this concrete runtime.
|
||||
pub type Timestamp = timestamp::Module<Concrete>;
|
||||
pub type Timestamp = timestamp::Module<Runtime>;
|
||||
|
||||
/// Session key conversion.
|
||||
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 OnSessionChange = Staking;
|
||||
type Event = Event;
|
||||
}
|
||||
/// 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;
|
||||
}
|
||||
/// Staking module for this concrete runtime.
|
||||
pub type Staking = staking::Module<Concrete>;
|
||||
pub type Staking = staking::Module<Runtime>;
|
||||
|
||||
impl democracy::Trait for Concrete {
|
||||
type Proposal = PrivCall;
|
||||
impl democracy::Trait for Runtime {
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
}
|
||||
/// Democracy module for this concrete runtime.
|
||||
pub type Democracy = democracy::Module<Concrete>;
|
||||
pub type Democracy = democracy::Module<Runtime>;
|
||||
|
||||
impl council::Trait for Concrete {}
|
||||
/// Council module for this concrete runtime.
|
||||
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;
|
||||
impl council::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
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! {
|
||||
pub enum Event for Concrete {
|
||||
balances, session, staking
|
||||
pub enum Event for Runtime {
|
||||
//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! {
|
||||
/// Call type for polkadot transactions.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub enum Call where aux: <Concrete as HasPublicAux>::PublicAux {
|
||||
Consensus = 0,
|
||||
Balances = 1,
|
||||
Session = 2,
|
||||
Staking = 3,
|
||||
Timestamp = 4,
|
||||
Democracy = 5,
|
||||
Council = 6,
|
||||
CouncilVoting = 7,
|
||||
Parachains = 8,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
pub enum Call where origin: <Runtime as system::Trait>::Origin {
|
||||
Consensus,
|
||||
Balances,
|
||||
Session,
|
||||
Staking,
|
||||
Timestamp,
|
||||
Democracy,
|
||||
Council,
|
||||
CouncilVoting,
|
||||
CouncilMotions,
|
||||
Parachains,
|
||||
Treasury,
|
||||
}
|
||||
}
|
||||
|
||||
/// 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! {
|
||||
pub struct GenesisConfig for Concrete {
|
||||
pub struct GenesisConfig for Runtime {
|
||||
ConsensusConfig => consensus,
|
||||
SystemConfig => system,
|
||||
BalancesConfig => balances,
|
||||
@@ -261,13 +284,58 @@ impl_outer_config! {
|
||||
DemocracyConfig => democracy,
|
||||
CouncilConfig => council,
|
||||
TimestampConfig => timestamp,
|
||||
TreasuryConfig => treasury,
|
||||
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 {
|
||||
impl_stubs!(
|
||||
version => |()| super::Version::version(),
|
||||
version => |()| super::VERSION,
|
||||
json_metadata => |()| super::Runtime::json_metadata(),
|
||||
authorities => |()| super::Consensus::authorities(),
|
||||
initialise_block => |header| super::Executive::initialise_block(&header),
|
||||
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),
|
||||
validator_count => |()| super::Session::validator_count(),
|
||||
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(),
|
||||
random_seed => |()| super::System::random_seed(),
|
||||
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 substrate_primitives::hexdisplay::HexDisplay;
|
||||
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>;
|
||||
|
||||
#[test]
|
||||
@@ -304,7 +372,7 @@ mod tests {
|
||||
number: 67,
|
||||
state_root: 3.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#"{
|
||||
@@ -313,9 +381,7 @@ mod tests {
|
||||
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000003",
|
||||
"extrinsicsRoot": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
||||
"digest": {
|
||||
"logs": [
|
||||
"0x01"
|
||||
]
|
||||
"logs": []
|
||||
}
|
||||
}"#);
|
||||
|
||||
@@ -328,13 +394,9 @@ mod tests {
|
||||
let mut block = Block {
|
||||
header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()),
|
||||
extrinsics: vec![
|
||||
UncheckedExtrinsic::new(
|
||||
generic::Extrinsic {
|
||||
function: Call::Timestamp(timestamp::Call::set(100_000_000)),
|
||||
signed: Default::default(),
|
||||
index: Default::default(),
|
||||
},
|
||||
UncheckedExtrinsic::new_unsigned(
|
||||
Default::default(),
|
||||
Call::Timestamp(timestamp::Call::set(100_000_000))
|
||||
)
|
||||
],
|
||||
};
|
||||
@@ -344,13 +406,9 @@ mod tests {
|
||||
|
||||
assert_eq!(block, decoded);
|
||||
|
||||
block.extrinsics.push(UncheckedExtrinsic::new(
|
||||
generic::Extrinsic {
|
||||
function: Call::Staking(staking::Call::stake()),
|
||||
signed: Default::default(),
|
||||
index: 10101,
|
||||
},
|
||||
Default::default(),
|
||||
block.extrinsics.push(UncheckedExtrinsic::new_unsigned(
|
||||
10101,
|
||||
Call::Staking(staking::Call::stake())
|
||||
));
|
||||
|
||||
let raw = block.encode();
|
||||
@@ -364,24 +422,16 @@ mod tests {
|
||||
let mut block = Block {
|
||||
header: Header::new(1, Default::default(), Default::default(), Default::default(), Default::default()),
|
||||
extrinsics: vec![
|
||||
UncheckedExtrinsic::new(
|
||||
generic::Extrinsic {
|
||||
function: Call::Timestamp(timestamp::Call::set(100_000_000)),
|
||||
signed: Default::default(),
|
||||
index: Default::default(),
|
||||
},
|
||||
UncheckedExtrinsic::new_unsigned(
|
||||
Default::default(),
|
||||
Call::Timestamp(timestamp::Call::set(100_000_000))
|
||||
)
|
||||
],
|
||||
};
|
||||
|
||||
block.extrinsics.push(UncheckedExtrinsic::new(
|
||||
generic::Extrinsic {
|
||||
function: Call::Staking(staking::Call::stake()),
|
||||
signed: Default::default(),
|
||||
index: 10101,
|
||||
},
|
||||
Default::default()
|
||||
block.extrinsics.push(UncheckedExtrinsic::new_unsigned(
|
||||
10101,
|
||||
Call::Staking(staking::Call::stake())
|
||||
));
|
||||
|
||||
let raw = block.encode();
|
||||
@@ -394,12 +444,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn serialize_unchecked() {
|
||||
let tx = UncheckedExtrinsic::new(
|
||||
Extrinsic {
|
||||
signed: AccountId::from([1; 32]).into(),
|
||||
index: 999,
|
||||
function: Call::Timestamp(TimestampCall::set(135135)),
|
||||
},
|
||||
let tx = UncheckedExtrinsic::new_signed(
|
||||
999,
|
||||
Call::Timestamp(TimestampCall::set(135135)),
|
||||
AccountId::from([1; 32]).into(),
|
||||
runtime_primitives::Ed25519Signature(primitives::hash::H512([0; 64])).into()
|
||||
);
|
||||
|
||||
@@ -411,29 +459,14 @@ mod tests {
|
||||
// 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
|
||||
let v = Encode::encode(&tx);
|
||||
assert_eq!(&v[..], &hex!["6f000000ff0101010101010101010101010101010101010101010101010101010101010101e70300000400df0f02000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"][..]);
|
||||
assert_eq!(&v[..], &hex!["7000000001ff010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e70300000400df0f020000000000"][..]);
|
||||
println!("{}", HexDisplay::from(&v));
|
||||
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]
|
||||
fn parachain_calls_are_privcall() {
|
||||
let _register = PrivCall::Parachains(parachains::PrivCall::register_parachain(0.into(), vec![1, 2, 3], vec![]));
|
||||
let _deregister = PrivCall::Parachains(parachains::PrivCall::deregister_parachain(0.into()));
|
||||
let _register = Call::Parachains(parachains::Call::register_parachain(0.into(), vec![1, 2, 3], vec![]));
|
||||
let _deregister = Call::Parachains(parachains::Call::deregister_parachain(0.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
use rstd::prelude::*;
|
||||
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 {system, session};
|
||||
|
||||
use substrate_runtime_support::{StorageValue, StorageMap};
|
||||
use substrate_runtime_support::dispatch::Result;
|
||||
use srml_support::{StorageValue, StorageMap};
|
||||
use srml_support::dispatch::Result;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use rstd::marker::PhantomData;
|
||||
@@ -35,28 +35,21 @@ use runtime_primitives;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use system::{ensure_root, ensure_inherent};
|
||||
|
||||
pub trait Trait: system::Trait<Hash = ::primitives::Hash> + session::Trait {
|
||||
/// The position of the set_heads call in the block.
|
||||
const SET_POSITION: u32;
|
||||
|
||||
type PublicAux: RefInto<Self::AccountId> + MaybeEmpty;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
/// Parachains module.
|
||||
pub struct Module<T: Trait>;
|
||||
/// Call type for parachains.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
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;
|
||||
}
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// Provide candidate receipts for parachains, in ascending order by id.
|
||||
fn set_heads(origin, heads: Vec<CandidateReceipt>) -> Result;
|
||||
|
||||
/// Private calls for parachains.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
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;
|
||||
fn register_parachain(origin, id: Id, code: Vec<u8>, initial_head_data: Vec<u8>) -> Result;
|
||||
fn deregister_parachain(origin, id: Id) -> Result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +119,8 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
/// Register a parachain with given code.
|
||||
/// 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();
|
||||
match parachains.binary_search(&id) {
|
||||
Ok(_) => fail!("Parachain already exists"),
|
||||
@@ -141,7 +135,8 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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();
|
||||
match parachains.binary_search(&id) {
|
||||
Ok(idx) => { parachains.remove(idx); }
|
||||
@@ -154,8 +149,8 @@ impl<T: Trait> Module<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_heads(aux: &<T as Trait>::PublicAux, heads: Vec<CandidateReceipt>) -> Result {
|
||||
ensure!(aux.is_empty(), "set_heads must not be signed");
|
||||
fn set_heads(origin: T::Origin, heads: Vec<CandidateReceipt>) -> Result {
|
||||
ensure_inherent(origin)?;
|
||||
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
|
||||
ensure!(
|
||||
<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> {
|
||||
fn execute() {
|
||||
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
|
||||
fn on_finalise(_n: T::BlockNumber) {
|
||||
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 {
|
||||
use super::*;
|
||||
use runtime_io::{TestExternalities, with_externalities};
|
||||
use substrate_primitives::{H256, KeccakHasher};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256};
|
||||
use runtime_primitives::traits::{Identity, BlakeTwo256};
|
||||
use runtime_primitives::testing::{Digest, Header};
|
||||
use {consensus, timestamp};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
impl HasPublicAux for Test {
|
||||
type PublicAux = u64;
|
||||
}
|
||||
impl consensus::Trait for Test {
|
||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
||||
type SessionKey = u64;
|
||||
type OnOfflineValidator = ();
|
||||
type Log = u64;
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type PublicAux = <Self as HasPublicAux>::PublicAux;
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
@@ -284,13 +281,11 @@ mod tests {
|
||||
}
|
||||
impl Trait for Test {
|
||||
const SET_POSITION: u32 = 0;
|
||||
|
||||
type PublicAux = <Self as HasPublicAux>::PublicAux;
|
||||
}
|
||||
|
||||
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();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
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(&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::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::parachain_code(&5u32.into()), None);
|
||||
|
||||
@@ -17,29 +17,22 @@
|
||||
//! Utils for block interaction.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use super::{Call, UncheckedExtrinsic, Extrinsic, Balances};
|
||||
use runtime_primitives::traits::{Checkable, AuxLookup};
|
||||
use super::{Call, UncheckedExtrinsic, Balances};
|
||||
use runtime_primitives::traits::{Checkable, Lookup};
|
||||
use timestamp::Call as TimestampCall;
|
||||
use parachains::Call as ParachainsCall;
|
||||
use consensus::Call as ConsensusCall;
|
||||
|
||||
/// Produces the list of inherent extrinsics.
|
||||
pub fn inherent_extrinsics(data: ::primitives::InherentData, spec_version: u32) -> Vec<UncheckedExtrinsic> {
|
||||
let make_inherent = |function| UncheckedExtrinsic::new(
|
||||
Extrinsic {
|
||||
signed: Default::default(),
|
||||
function,
|
||||
index: 0,
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
let make_inherent = |function| UncheckedExtrinsic::new_unsigned(0, function);
|
||||
|
||||
let mut inherent = vec![
|
||||
make_inherent(Call::Timestamp(TimestampCall::set(data.timestamp))),
|
||||
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(
|
||||
Call::Consensus(ConsensusCall::note_offline(data.offline_indices))
|
||||
));
|
||||
|
||||
Generated
+274
-917
File diff suppressed because it is too large
Load Diff
@@ -10,47 +10,24 @@ crate-type = ["cdylib"]
|
||||
integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" }
|
||||
polkadot-primitives = { path = "../../primitives", default-features = false }
|
||||
safe-mix = { version = "1.0", default-features = false }
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
parity-codec = { 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-runtime-std = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-io = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-support = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-balances = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-consensus = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-council = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-democracy = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-executive = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-session = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-staking = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-system = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
substrate-runtime-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",
|
||||
]
|
||||
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
sr-io = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-support = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-council = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-democracy = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-session = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-staking = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-system = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||
srml-timestamp = { 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 }
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,6 @@ log = "0.3"
|
||||
slog = "^2"
|
||||
tokio = "0.1.7"
|
||||
hex-literal = "0.1"
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
polkadot-availability-store = { path = "../availability-store" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
@@ -20,7 +19,7 @@ polkadot-executor = { path = "../executor" }
|
||||
polkadot-api = { path = "../api" }
|
||||
polkadot-transaction-pool = { path = "../transaction-pool" }
|
||||
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-network = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
@@ -45,7 +45,15 @@
|
||||
"/ip4/104.211.48.51/tcp/30333/p2p/QmWCnXrhM1in1qPqVT3rDXQEJHedAzbPDMimdjqy2P9fGn",
|
||||
"/ip4/104.211.48.247/tcp/30333/p2p/QmY33GW69TnTsdQWjAkxJR1GrWTdeV1PmzzcSmUay4HvAB",
|
||||
"/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/"
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
//! Polkadot chain configurations.
|
||||
|
||||
use ed25519;
|
||||
use primitives::AuthorityId;
|
||||
use primitives::{AuthorityId, ed25519};
|
||||
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig};
|
||||
use service::ChainSpec;
|
||||
@@ -60,7 +59,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
staking: Some(StakingConfig {
|
||||
current_era: 0,
|
||||
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
early_era_slash: 10000,
|
||||
offline_slash: 10000,
|
||||
session_reward: 100,
|
||||
validator_count: 12,
|
||||
sessions_per_era: 12, // 1 hour per era
|
||||
@@ -92,6 +91,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
timestamp: Some(TimestampConfig {
|
||||
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,
|
||||
sessions_per_era: 5,
|
||||
bonding_duration: 2 * 60 * 12,
|
||||
early_era_slash: 0,
|
||||
offline_slash: 0,
|
||||
session_reward: 0,
|
||||
offline_slash_grace: 0,
|
||||
}),
|
||||
@@ -170,6 +170,7 @@ fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
treasury: Some(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
//! Polkadot service. Specialized wrapper over substrate service.
|
||||
|
||||
extern crate ed25519;
|
||||
extern crate polkadot_availability_store as av_store;
|
||||
extern crate polkadot_primitives;
|
||||
extern crate polkadot_runtime;
|
||||
@@ -50,7 +49,7 @@ use client::{Client, BlockchainEvents};
|
||||
use polkadot_network::{PolkadotProtocol, consensus::ConsensusNetwork};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use service::FactoryFullConfiguration;
|
||||
use primitives::{KeccakHasher, RlpCodec};
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
|
||||
pub use service::{Roles, PruningMode, ExtrinsicPoolOptions,
|
||||
ErrorKind, Error, ComponentBlock, LightComponents, FullComponents};
|
||||
@@ -67,9 +66,9 @@ pub trait Components: service::Components {
|
||||
/// Polkadot API.
|
||||
type Api: 'static + PolkadotApi + Send + Sync;
|
||||
/// Client backend.
|
||||
type Backend: 'static + client::backend::Backend<Block, KeccakHasher, RlpCodec>;
|
||||
type Backend: 'static + client::backend::Backend<Block, Blake2Hasher, RlpCodec>;
|
||||
/// 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> {
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
substrate-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec = { git = "https://github.com/paritytech/substrate" }
|
||||
parity-codec-derive = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
//! propose and attest to validity of candidates, and those who can only attest
|
||||
//! to availability.
|
||||
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_primitives;
|
||||
extern crate polkadot_primitives as primitives;
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
pub mod generic;
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ description = "Test parachain which adds to a number as its state transition"
|
||||
|
||||
[dependencies]
|
||||
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"
|
||||
|
||||
@@ -8,7 +8,7 @@ adder = { path = ".." }
|
||||
polkadot-parachain = { path = "../../../parachain" }
|
||||
polkadot-collator = { path = "../../../collator" }
|
||||
polkadot-primitives = { path = "../../../primitives" }
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
parking_lot = "0.4"
|
||||
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
|
||||
futures = "0.1"
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
//! Collator for polkadot
|
||||
|
||||
extern crate adder;
|
||||
extern crate substrate_primitives;
|
||||
extern crate polkadot_parachain as parachain;
|
||||
extern crate polkadot_primitives as primitives;
|
||||
extern crate polkadot_collator as collator;
|
||||
extern crate ed25519;
|
||||
extern crate parking_lot;
|
||||
extern crate ctrlc;
|
||||
extern crate futures;
|
||||
@@ -31,7 +31,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use adder::{HeadData as AdderHead, BlockData as AdderBody};
|
||||
use ed25519::Pair;
|
||||
use substrate_primitives::ed25519::Pair;
|
||||
use parachain::codec::{Encode, Decode};
|
||||
use primitives::parachain::{HeadData, BlockData, Id as ParaId, Message};
|
||||
use collator::{InvalidHead, ParachainContext, VersionInfo};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
extern crate substrate_codec_derive;
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
extern crate polkadot_parachain as parachain;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
@@ -11,9 +11,8 @@ polkadot-api = { path = "../api" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
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-extrinsic-pool = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
substrate-runtime-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
ed25519 = { git = "https://github.com/paritytech/substrate" }
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate ed25519;
|
||||
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_primitives;
|
||||
extern crate substrate_runtime_primitives;
|
||||
extern crate sr_primitives;
|
||||
extern crate polkadot_runtime as runtime;
|
||||
extern crate polkadot_primitives as primitives;
|
||||
extern crate polkadot_api;
|
||||
@@ -47,7 +46,7 @@ use extrinsic_pool::{Readiness, scoring::{Change, Choice}, VerifiedFor, Extrinsi
|
||||
use polkadot_api::PolkadotApi;
|
||||
use primitives::{AccountId, BlockId, Block, Hash, Index};
|
||||
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 error::{Error, ErrorKind, Result};
|
||||
@@ -182,7 +181,13 @@ impl<A> extrinsic_pool::ChainApi for ChainApi<A> where
|
||||
Err(Self::NO_ACCOUNT) => None,
|
||||
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 {
|
||||
debug!(target: "transaction-pool", "Transaction verified: {} => {:?}", hash, uxt);
|
||||
@@ -191,7 +196,7 @@ impl<A> extrinsic_pool::ChainApi for ChainApi<A> where
|
||||
}
|
||||
|
||||
Ok(VerifiedTransaction {
|
||||
index: uxt.extrinsic.index,
|
||||
index: uxt.index,
|
||||
inner,
|
||||
sender,
|
||||
hash,
|
||||
@@ -291,9 +296,9 @@ mod tests {
|
||||
use polkadot_api::{PolkadotApi, BlockBuilder, Result};
|
||||
use primitives::{AccountId, AccountIndex, Block, BlockId, Hash, Index, SessionKey,
|
||||
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 substrate_runtime_primitives::{MaybeUnsigned, generic};
|
||||
use sr_primitives::generic;
|
||||
use extrinsic_pool::Pool;
|
||||
use super::ChainApi;
|
||||
|
||||
@@ -340,7 +345,7 @@ mod tests {
|
||||
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 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> {
|
||||
Ok((_account[0] as u32) + number_of(_at))
|
||||
@@ -366,28 +371,24 @@ mod tests {
|
||||
}
|
||||
|
||||
fn uxt(who: Keyring, nonce: Index, use_id: bool) -> FutureProofUncheckedExtrinsic {
|
||||
let sxt = BareExtrinsic {
|
||||
signed: who.to_raw_public().into(),
|
||||
index: nonce,
|
||||
function: Call::Timestamp(TimestampCall::set(0)),
|
||||
};
|
||||
let sxt = (nonce, Call::Timestamp(TimestampCall::set(0)));
|
||||
let sig = sxt.using_encoded(|e| who.sign(e));
|
||||
UncheckedExtrinsic::new(Extrinsic {
|
||||
signed: if use_id { RawAddress::Id(sxt.signed) } else { RawAddress::Index(
|
||||
match who {
|
||||
Alice => 0,
|
||||
Bob => 1,
|
||||
Charlie => 2,
|
||||
Dave => 3,
|
||||
Eve => 4,
|
||||
Ferdie => 5,
|
||||
One => 6,
|
||||
Two => 7,
|
||||
}
|
||||
)},
|
||||
index: sxt.index,
|
||||
function: sxt.function,
|
||||
}, MaybeUnsigned(sig.into())).using_encoded(|e| FutureProofUncheckedExtrinsic::decode(&mut &e[..])).unwrap()
|
||||
let signed = who.to_raw_public().into();
|
||||
let sender = if use_id { RawAddress::Id(signed) } else { RawAddress::Index(
|
||||
match who {
|
||||
Alice => 0,
|
||||
Bob => 1,
|
||||
Charlie => 2,
|
||||
Dave => 3,
|
||||
Eve => 4,
|
||||
Ferdie => 5,
|
||||
One => 6,
|
||||
Two => 7,
|
||||
}
|
||||
)};
|
||||
UncheckedExtrinsic::new_signed(sxt.0, sxt.1, sender, sig.into())
|
||||
.using_encoded(|e| FutureProofUncheckedExtrinsic::decode(&mut &e[..]))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn pool(api: &TestPolkadotApi) -> Pool<ChainApi<TestPolkadotApi>> {
|
||||
|
||||
Reference in New Issue
Block a user