mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 06:08:00 +00:00
Runtime version (#256)
* Runtime version * Updated genesis.wasm * Minor fixes * Fresh runtime * Default version for pre Poc-2; Fixed authorship interface check * Fixed authoring check
This commit is contained in:
committed by
Gav Wood
parent
c7067fa03a
commit
5e4ef36e40
+22
-47
@@ -20,7 +20,7 @@ use client::backend::{Backend, LocalBackend};
|
||||
use client::block_builder::BlockBuilder as ClientBlockBuilder;
|
||||
use client::{Client, LocalCallExecutor};
|
||||
use polkadot_executor::Executor as LocalDispatch;
|
||||
use substrate_executor::{NativeExecutionDispatch, NativeExecutor};
|
||||
use substrate_executor::NativeExecutor;
|
||||
use state_machine;
|
||||
|
||||
use runtime::Address;
|
||||
@@ -28,23 +28,13 @@ use runtime_primitives::traits::AuxLookup;
|
||||
use primitives::{AccountId, Block, Header, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic};
|
||||
use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId};
|
||||
|
||||
use {CheckedBlockId, BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Error, Result};
|
||||
|
||||
/// A checked block ID used for the substrate-client implementation of CheckedBlockId;
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct CheckedId(pub(crate) BlockId);
|
||||
|
||||
impl CheckedBlockId for CheckedId {
|
||||
fn block_id(&self) -> &BlockId {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
use {BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Error, Result};
|
||||
|
||||
// set up the necessary scaffolding to execute a set of calls to the runtime.
|
||||
// this creates a new block on top of the given ID and initialises it.
|
||||
macro_rules! with_runtime {
|
||||
($client: ident, $at: expr, $exec: expr) => {{
|
||||
let parent = $at.block_id();
|
||||
let parent = $at;
|
||||
let header = Header {
|
||||
parent_hash: $client.block_hash_from_id(&parent)?
|
||||
.ok_or_else(|| ErrorKind::UnknownBlock(format!("{:?}", parent)))?,
|
||||
@@ -83,39 +73,29 @@ impl<B: LocalBackend<Block>> BlockBuilder for ClientBlockBuilder<B, LocalCallExe
|
||||
impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
|
||||
where ::client::error::Error: From<<<B as Backend<Block>>::State as state_machine::backend::Backend>::Error>
|
||||
{
|
||||
type CheckedBlockId = CheckedId;
|
||||
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>;
|
||||
|
||||
fn check_id(&self, id: BlockId) -> Result<CheckedId> {
|
||||
// bail if the code is not the same as the natively linked.
|
||||
if self.code_at(&id.into())? != LocalDispatch::native_equivalent() {
|
||||
bail!("This node is out of date. Block authoring may not work correctly. Bailing.")
|
||||
}
|
||||
|
||||
Ok(CheckedId(id))
|
||||
}
|
||||
|
||||
fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> {
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
|
||||
with_runtime!(self, at, ::runtime::Consensus::authorities)
|
||||
}
|
||||
|
||||
fn validators(&self, at: &CheckedId) -> Result<Vec<AccountId>> {
|
||||
fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>> {
|
||||
with_runtime!(self, at, ::runtime::Session::validators)
|
||||
}
|
||||
|
||||
fn random_seed(&self, at: &CheckedId) -> Result<Hash> {
|
||||
fn random_seed(&self, at: &BlockId) -> Result<Hash> {
|
||||
with_runtime!(self, at, ::runtime::System::random_seed)
|
||||
}
|
||||
|
||||
fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> {
|
||||
fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster> {
|
||||
with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster)
|
||||
}
|
||||
|
||||
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
|
||||
fn timestamp(&self, at: &BlockId) -> Result<Timestamp> {
|
||||
with_runtime!(self, at, ::runtime::Timestamp::get)
|
||||
}
|
||||
|
||||
fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<bool> {
|
||||
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool> {
|
||||
use substrate_executor::error::ErrorKind as ExecErrorKind;
|
||||
use codec::Slicable;
|
||||
use runtime::Block as RuntimeBlock;
|
||||
@@ -136,28 +116,28 @@ impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, Nati
|
||||
}
|
||||
}
|
||||
|
||||
fn index(&self, at: &CheckedId, account: AccountId) -> Result<Index> {
|
||||
fn index(&self, at: &BlockId, account: AccountId) -> Result<Index> {
|
||||
with_runtime!(self, at, || ::runtime::System::account_nonce(account))
|
||||
}
|
||||
|
||||
fn lookup(&self, at: &Self::CheckedBlockId, address: Address) -> Result<Option<AccountId>> {
|
||||
fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>> {
|
||||
with_runtime!(self, at, || <::runtime::Staking as AuxLookup>::lookup(address).ok())
|
||||
}
|
||||
|
||||
fn active_parachains(&self, at: &CheckedId) -> Result<Vec<ParaId>> {
|
||||
fn active_parachains(&self, at: &BlockId) -> Result<Vec<ParaId>> {
|
||||
with_runtime!(self, at, ::runtime::Parachains::active_parachains)
|
||||
}
|
||||
|
||||
fn parachain_code(&self, at: &CheckedId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
with_runtime!(self, at, || ::runtime::Parachains::parachain_code(parachain))
|
||||
}
|
||||
|
||||
fn parachain_head(&self, at: &CheckedId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
with_runtime!(self, at, || ::runtime::Parachains::parachain_head(parachain))
|
||||
}
|
||||
|
||||
fn build_block(&self, at: &CheckedId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
|
||||
let mut block_builder = self.new_block_at(at.block_id())?;
|
||||
fn build_block(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
|
||||
let mut block_builder = self.new_block_at(at)?;
|
||||
for inherent in self.inherent_extrinsics(at, timestamp, new_heads)? {
|
||||
block_builder.push(inherent)?;
|
||||
}
|
||||
@@ -165,7 +145,7 @@ impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, Nati
|
||||
Ok(block_builder)
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>> {
|
||||
fn inherent_extrinsics(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>> {
|
||||
use codec::Slicable;
|
||||
|
||||
with_runtime!(self, at, || {
|
||||
@@ -231,7 +211,7 @@ mod tests {
|
||||
#[test]
|
||||
fn gets_session_and_validator_keys() {
|
||||
let client = client();
|
||||
let id = client.check_id(BlockId::number(0)).unwrap();
|
||||
let id = BlockId::number(0);
|
||||
assert_eq!(client.session_keys(&id).unwrap(), session_keys());
|
||||
assert_eq!(client.validators(&id).unwrap(), validators());
|
||||
}
|
||||
@@ -240,7 +220,7 @@ mod tests {
|
||||
fn build_block_implicit_succeeds() {
|
||||
let client = client();
|
||||
|
||||
let id = client.check_id(BlockId::number(0)).unwrap();
|
||||
let id = BlockId::number(0);
|
||||
let block_builder = client.build_block(&id, 1_000_000, Vec::new()).unwrap();
|
||||
let block = block_builder.bake().unwrap();
|
||||
|
||||
@@ -252,10 +232,10 @@ mod tests {
|
||||
fn build_block_with_inherent_succeeds() {
|
||||
let client = client();
|
||||
|
||||
let id = client.check_id(BlockId::number(0)).unwrap();
|
||||
let id = BlockId::number(0);
|
||||
let inherent = client.inherent_extrinsics(&id, 1_000_000, Vec::new()).unwrap();
|
||||
|
||||
let mut block_builder = client.new_block_at(id.block_id()).unwrap();
|
||||
let mut block_builder = client.new_block_at(&id).unwrap();
|
||||
for extrinsic in inherent {
|
||||
block_builder.push(extrinsic).unwrap();
|
||||
}
|
||||
@@ -266,16 +246,11 @@ mod tests {
|
||||
assert!(block.header.extrinsics_root != Default::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_check_id_for_unknown_block() {
|
||||
assert!(client().check_id(BlockId::number(100)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_random_seed_with_genesis() {
|
||||
let client = client();
|
||||
|
||||
let id = client.check_id(BlockId::number(0)).unwrap();
|
||||
let id = BlockId::number(0);
|
||||
assert!(client.random_seed(&id).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
+13
-27
@@ -77,12 +77,6 @@ impl From<client::error::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// A checked block identifier.
|
||||
pub trait CheckedBlockId: Clone + 'static {
|
||||
/// Yield the underlying block ID.
|
||||
fn block_id(&self) -> &BlockId;
|
||||
}
|
||||
|
||||
/// Build new blocks.
|
||||
pub trait BlockBuilder {
|
||||
/// Push an extrinsic onto the block. Fails if the extrinsic is invalid.
|
||||
@@ -96,57 +90,49 @@ pub trait BlockBuilder {
|
||||
///
|
||||
/// All calls should fail when the exact runtime is unknown.
|
||||
pub trait PolkadotApi {
|
||||
/// A checked block ID. Used to avoid redundancy of code check.
|
||||
type CheckedBlockId: CheckedBlockId;
|
||||
/// The block builder for this API type.
|
||||
type BlockBuilder: BlockBuilder;
|
||||
|
||||
/// Check whether requests at the given block ID can be served.
|
||||
///
|
||||
/// It should not be possible to instantiate this type without going
|
||||
/// through this function.
|
||||
fn check_id(&self, id: BlockId) -> Result<Self::CheckedBlockId>;
|
||||
|
||||
/// Get session keys at a given block.
|
||||
fn session_keys(&self, at: &Self::CheckedBlockId) -> Result<Vec<SessionKey>>;
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>>;
|
||||
|
||||
/// Get validators at a given block.
|
||||
fn validators(&self, at: &Self::CheckedBlockId) -> Result<Vec<AccountId>>;
|
||||
fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>>;
|
||||
|
||||
/// Get the value of the randomness beacon at a given block.
|
||||
fn random_seed(&self, at: &Self::CheckedBlockId) -> Result<Hash>;
|
||||
fn random_seed(&self, at: &BlockId) -> Result<Hash>;
|
||||
|
||||
/// Get the authority duty roster at a block.
|
||||
fn duty_roster(&self, at: &Self::CheckedBlockId) -> Result<DutyRoster>;
|
||||
fn duty_roster(&self, at: &BlockId) -> Result<DutyRoster>;
|
||||
|
||||
/// Get the timestamp registered at a block.
|
||||
fn timestamp(&self, at: &Self::CheckedBlockId) -> Result<Timestamp>;
|
||||
fn timestamp(&self, at: &BlockId) -> Result<Timestamp>;
|
||||
|
||||
/// Get the nonce (né index) of an account at a block.
|
||||
fn index(&self, at: &Self::CheckedBlockId, account: AccountId) -> Result<Index>;
|
||||
fn index(&self, at: &BlockId, account: AccountId) -> Result<Index>;
|
||||
|
||||
/// Get the account id of an address at a block.
|
||||
fn lookup(&self, at: &Self::CheckedBlockId, address: Address) -> Result<Option<AccountId>>;
|
||||
fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>>;
|
||||
|
||||
/// Get the active parachains at a block.
|
||||
fn active_parachains(&self, at: &Self::CheckedBlockId) -> Result<Vec<ParaId>>;
|
||||
fn active_parachains(&self, at: &BlockId) -> Result<Vec<ParaId>>;
|
||||
|
||||
/// Get the validation code of a parachain at a block. If the parachain is active, this will always return `Some`.
|
||||
fn parachain_code(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;
|
||||
fn parachain_code(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;
|
||||
|
||||
/// Get the chain head of a parachain. If the parachain is active, this will always return `Some`.
|
||||
fn parachain_head(&self, at: &Self::CheckedBlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;
|
||||
fn parachain_head(&self, at: &BlockId, parachain: ParaId) -> Result<Option<Vec<u8>>>;
|
||||
|
||||
/// Evaluate a block. Returns true if the block is good, false if it is known to be bad,
|
||||
/// and an error if we can't evaluate for some reason.
|
||||
fn evaluate_block(&self, at: &Self::CheckedBlockId, block: Block) -> Result<bool>;
|
||||
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool>;
|
||||
|
||||
/// Build a block on top of the given, with inherent extrinsics pre-pushed.
|
||||
fn build_block(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder>;
|
||||
fn build_block(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder>;
|
||||
|
||||
/// Attempt to produce the (encoded) inherent extrinsics for a block being built upon the given.
|
||||
/// This may vary by runtime and will fail if a runtime doesn't follow the same API.
|
||||
fn inherent_extrinsics(&self, at: &Self::CheckedBlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>>;
|
||||
fn inherent_extrinsics(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>>;
|
||||
}
|
||||
|
||||
/// Mark for all Polkadot API implementations, that are making use of state data, stored locally.
|
||||
|
||||
+15
-21
@@ -24,8 +24,7 @@ use state_machine;
|
||||
use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic};
|
||||
use runtime::Address;
|
||||
use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId};
|
||||
use full::CheckedId;
|
||||
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, CheckedBlockId, Result, ErrorKind};
|
||||
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind};
|
||||
|
||||
/// Light block builder. TODO: make this work (efficiently)
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -47,65 +46,60 @@ pub struct RemotePolkadotApiWrapper<B: Backend<Block>, E: CallExecutor<Block>>(p
|
||||
impl<B: Backend<Block>, E: CallExecutor<Block>> PolkadotApi for RemotePolkadotApiWrapper<B, E>
|
||||
where ::client::error::Error: From<<<B as Backend<Block>>::State as state_machine::backend::Backend>::Error>
|
||||
{
|
||||
type CheckedBlockId = CheckedId;
|
||||
type BlockBuilder = LightBlockBuilder;
|
||||
|
||||
fn check_id(&self, id: BlockId) -> Result<CheckedId> {
|
||||
Ok(CheckedId(id))
|
||||
}
|
||||
|
||||
fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> {
|
||||
self.0.executor().call(at.block_id(), "authorities", &[])
|
||||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>> {
|
||||
self.0.executor().call(at, "authorities", &[])
|
||||
.and_then(|r| Vec::<SessionKey>::decode(&mut &r.return_data[..])
|
||||
.ok_or("error decoding session keys".into()))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
fn validators(&self, _at: &CheckedId) -> Result<Vec<AccountId>> {
|
||||
fn validators(&self, _at: &BlockId) -> Result<Vec<AccountId>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn random_seed(&self, _at: &Self::CheckedBlockId) -> Result<Hash> {
|
||||
fn random_seed(&self, _at: &BlockId) -> Result<Hash> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn duty_roster(&self, _at: &CheckedId) -> Result<DutyRoster> {
|
||||
fn duty_roster(&self, _at: &BlockId) -> Result<DutyRoster> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn timestamp(&self, _at: &CheckedId) -> Result<Timestamp> {
|
||||
fn timestamp(&self, _at: &BlockId) -> Result<Timestamp> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn evaluate_block(&self, _at: &CheckedId, _block: Block) -> Result<bool> {
|
||||
fn evaluate_block(&self, _at: &BlockId, _block: Block) -> Result<bool> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn index(&self, _at: &CheckedId, _account: AccountId) -> Result<Index> {
|
||||
fn index(&self, _at: &BlockId, _account: AccountId) -> Result<Index> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn lookup(&self, _at: &CheckedId, _address: Address) -> Result<Option<AccountId>> {
|
||||
fn lookup(&self, _at: &BlockId, _address: Address) -> Result<Option<AccountId>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn active_parachains(&self, _at: &Self::CheckedBlockId) -> Result<Vec<ParaId>> {
|
||||
fn active_parachains(&self, _at: &BlockId) -> Result<Vec<ParaId>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn parachain_code(&self, _at: &Self::CheckedBlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
fn parachain_code(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn parachain_head(&self, _at: &Self::CheckedBlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
fn parachain_head(&self, _at: &BlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn build_block(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
|
||||
fn build_block(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(&self, _at: &Self::CheckedBlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Vec<Vec<u8>>> {
|
||||
fn inherent_extrinsics(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Vec<Vec<u8>>> {
|
||||
Err(ErrorKind::UnknownRuntime.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use polkadot_api::PolkadotApi;
|
||||
use polkadot_primitives::{Hash, AccountId};
|
||||
use polkadot_primitives::{Hash, AccountId, BlockId};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, Chain, BlockData, Extrinsic, CandidateReceipt};
|
||||
|
||||
use futures::prelude::*;
|
||||
@@ -57,7 +57,7 @@ pub trait Collators: Clone {
|
||||
pub struct CollationFetch<C: Collators, P: PolkadotApi> {
|
||||
parachain: Option<ParaId>,
|
||||
relay_parent_hash: Hash,
|
||||
relay_parent: P::CheckedBlockId,
|
||||
relay_parent: BlockId,
|
||||
collators: C,
|
||||
live_fetch: Option<<C::Collation as IntoFuture>::Future>,
|
||||
client: Arc<P>,
|
||||
@@ -65,7 +65,7 @@ pub struct CollationFetch<C: Collators, P: PolkadotApi> {
|
||||
|
||||
impl<C: Collators, P: PolkadotApi> CollationFetch<C, P> {
|
||||
/// Create a new collation fetcher for the given chain.
|
||||
pub fn new(parachain: Chain, relay_parent: P::CheckedBlockId, relay_parent_hash: Hash, collators: C, client: Arc<P>) -> Self {
|
||||
pub fn new(parachain: Chain, relay_parent: BlockId, relay_parent_hash: Hash, collators: C, client: Arc<P>) -> Self {
|
||||
CollationFetch {
|
||||
relay_parent_hash,
|
||||
relay_parent,
|
||||
@@ -145,7 +145,7 @@ error_chain! {
|
||||
}
|
||||
|
||||
/// Check whether a given collation is valid. Returns `Ok` on success, error otherwise.
|
||||
pub fn validate_collation<P: PolkadotApi>(client: &P, relay_parent: &P::CheckedBlockId, collation: &Collation) -> Result<(), Error> {
|
||||
pub fn validate_collation<P: PolkadotApi>(client: &P, relay_parent: &BlockId, collation: &Collation) -> Result<(), Error> {
|
||||
use parachain::{self, ValidationParams};
|
||||
|
||||
let para_id = collation.receipt.parachain_index;
|
||||
|
||||
@@ -240,7 +240,6 @@ pub struct ProposerFactory<C, N, P> {
|
||||
impl<C, N, P> bft::ProposerFactory<Block> for ProposerFactory<C, N, P>
|
||||
where
|
||||
C: PolkadotApi + Send + Sync,
|
||||
C::CheckedBlockId: Sync,
|
||||
N: Network,
|
||||
P: Collators,
|
||||
{
|
||||
@@ -254,9 +253,9 @@ impl<C, N, P> bft::ProposerFactory<Block> for ProposerFactory<C, N, P>
|
||||
|
||||
let parent_hash = parent_header.blake2_256().into();
|
||||
|
||||
let checked_id = self.client.check_id(BlockId::hash(parent_hash))?;
|
||||
let duty_roster = self.client.duty_roster(&checked_id)?;
|
||||
let random_seed = self.client.random_seed(&checked_id)?;
|
||||
let id = BlockId::hash(parent_hash);
|
||||
let duty_roster = self.client.duty_roster(&id)?;
|
||||
let random_seed = self.client.random_seed(&id)?;
|
||||
|
||||
let (group_info, local_duty) = make_group_info(
|
||||
duty_roster,
|
||||
@@ -264,7 +263,7 @@ impl<C, N, P> bft::ProposerFactory<Block> for ProposerFactory<C, N, P>
|
||||
sign_with.public().into(),
|
||||
)?;
|
||||
|
||||
let active_parachains = self.client.active_parachains(&checked_id)?;
|
||||
let active_parachains = self.client.active_parachains(&id)?;
|
||||
|
||||
let n_parachains = active_parachains.len();
|
||||
let table = Arc::new(SharedTable::new(group_info, sign_with.clone(), parent_hash));
|
||||
@@ -291,7 +290,7 @@ impl<C, N, P> bft::ProposerFactory<Block> for ProposerFactory<C, N, P>
|
||||
local_duty,
|
||||
local_key: sign_with,
|
||||
parent_hash,
|
||||
parent_id: checked_id,
|
||||
parent_id: id,
|
||||
parent_number: parent_header.number,
|
||||
random_seed,
|
||||
router,
|
||||
@@ -315,7 +314,7 @@ pub struct Proposer<C: PolkadotApi, R, P> {
|
||||
local_duty: LocalDuty,
|
||||
local_key: Arc<ed25519::Pair>,
|
||||
parent_hash: Hash,
|
||||
parent_id: C::CheckedBlockId,
|
||||
parent_id: BlockId,
|
||||
parent_number: BlockNumber,
|
||||
random_seed: Hash,
|
||||
router: R,
|
||||
@@ -326,7 +325,6 @@ pub struct Proposer<C: PolkadotApi, R, P> {
|
||||
impl<C, R, P> bft::Proposer<Block> for Proposer<C, R, P>
|
||||
where
|
||||
C: PolkadotApi + Send + Sync,
|
||||
C::CheckedBlockId: Sync,
|
||||
R: TableRouter,
|
||||
P: Collators,
|
||||
{
|
||||
@@ -621,7 +619,7 @@ impl ProposalTiming {
|
||||
pub struct CreateProposal<C: PolkadotApi, R, P: Collators> {
|
||||
parent_hash: Hash,
|
||||
parent_number: BlockNumber,
|
||||
parent_id: C::CheckedBlockId,
|
||||
parent_id: BlockId,
|
||||
client: Arc<C>,
|
||||
transaction_pool: Arc<TransactionPool<C>>,
|
||||
collation: CollationFetch<P, C>,
|
||||
|
||||
@@ -242,7 +242,6 @@ impl Service {
|
||||
where
|
||||
A: LocalPolkadotApi + Send + Sync + 'static,
|
||||
C: BlockchainEvents<Block> + ChainHead<Block> + bft::BlockImport<Block> + bft::Authorities<Block> + Send + Sync + 'static,
|
||||
A::CheckedBlockId: Sync,
|
||||
{
|
||||
let (signal, exit) = ::exit_future::signal();
|
||||
let thread = thread::spawn(move || {
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
extern crate polkadot_runtime;
|
||||
#[macro_use] extern crate substrate_executor;
|
||||
|
||||
native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm"));
|
||||
native_executor_instance!(pub Executor, polkadot_runtime::api::dispatch, polkadot_runtime::VERSION, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm"));
|
||||
|
||||
@@ -26,6 +26,7 @@ substrate-runtime-session = { path = "../../substrate/runtime/session" }
|
||||
substrate-runtime-staking = { path = "../../substrate/runtime/staking" }
|
||||
substrate-runtime-system = { path = "../../substrate/runtime/system" }
|
||||
substrate-runtime-timestamp = { path = "../../substrate/runtime/timestamp" }
|
||||
substrate-runtime-version = { path = "../../substrate/runtime/version" }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
@@ -48,6 +49,7 @@ std = [
|
||||
"substrate-runtime-staking/std",
|
||||
"substrate-runtime-system/std",
|
||||
"substrate-runtime-timestamp/std",
|
||||
"substrate-runtime-version/std",
|
||||
"serde_derive",
|
||||
"serde/std",
|
||||
"log",
|
||||
|
||||
@@ -56,6 +56,8 @@ extern crate substrate_runtime_session as session;
|
||||
extern crate substrate_runtime_staking as staking;
|
||||
extern crate substrate_runtime_system as system;
|
||||
extern crate substrate_runtime_timestamp as timestamp;
|
||||
#[macro_use]
|
||||
extern crate substrate_runtime_version as version;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod checked_block;
|
||||
@@ -69,6 +71,7 @@ pub use staking::address::Address as RawAddress;
|
||||
|
||||
use primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Log, SessionKey, Signature};
|
||||
use runtime_primitives::{generic, traits::{HasPublicAux, BlakeTwo256, Convert}};
|
||||
use version::RuntimeVersion;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use runtime_primitives::BuildStorage;
|
||||
@@ -102,6 +105,22 @@ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
pub struct Concrete;
|
||||
|
||||
/// Polkadot runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: ver_str!("polkadot"),
|
||||
impl_name: ver_str!("parity-polkadot"),
|
||||
authoring_version: 0,
|
||||
spec_version: 0,
|
||||
impl_version: 0,
|
||||
};
|
||||
|
||||
impl version::Trait for Concrete {
|
||||
const VERSION: RuntimeVersion = VERSION;
|
||||
}
|
||||
|
||||
/// Version module for this concrete runtime.
|
||||
pub type Version = version::Module<Concrete>;
|
||||
|
||||
impl HasPublicAux for Concrete {
|
||||
type PublicAux = AccountId; // TODO: Option<AccountId>
|
||||
}
|
||||
@@ -221,6 +240,7 @@ impl_outer_config! {
|
||||
|
||||
pub mod api {
|
||||
impl_stubs!(
|
||||
version => |()| super::Version::version(),
|
||||
authorities => |()| super::Consensus::authorities(),
|
||||
initialise_block => |header| super::Executive::initialise_block(&header),
|
||||
apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic),
|
||||
|
||||
Generated
+12
@@ -485,6 +485,7 @@ dependencies = [
|
||||
"substrate-runtime-support 0.1.0",
|
||||
"substrate-runtime-system 0.1.0",
|
||||
"substrate-runtime-timestamp 0.1.0",
|
||||
"substrate-runtime-version 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -972,6 +973,17 @@ dependencies = [
|
||||
"substrate-runtime-system 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-version"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-state-machine"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -24,6 +24,7 @@ substrate-runtime-session = { path = "../../../substrate/runtime/session", defau
|
||||
substrate-runtime-staking = { path = "../../../substrate/runtime/staking", default-features = false }
|
||||
substrate-runtime-system = { path = "../../../substrate/runtime/system", default-features = false }
|
||||
substrate-runtime-timestamp = { path = "../../../substrate/runtime/timestamp", default-features = false }
|
||||
substrate-runtime-version = { path = "../../../substrate/runtime/version", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
@@ -44,6 +45,7 @@ std = [
|
||||
"substrate-runtime-staking/std",
|
||||
"substrate-runtime-system/std",
|
||||
"substrate-runtime-timestamp/std",
|
||||
"substrate-runtime-version/std",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -180,7 +180,7 @@ impl txpool::Scoring<VerifiedTransaction> for Scoring {
|
||||
|
||||
/// Readiness evaluator for polkadot transactions.
|
||||
pub struct Ready<'a, A: 'a + PolkadotApi> {
|
||||
at_block: A::CheckedBlockId,
|
||||
at_block: BlockId,
|
||||
api: &'a A,
|
||||
known_nonces: HashMap<AccountId, ::primitives::Index>,
|
||||
}
|
||||
@@ -188,7 +188,7 @@ pub struct Ready<'a, A: 'a + PolkadotApi> {
|
||||
impl<'a, A: 'a + PolkadotApi> Ready<'a, A> {
|
||||
/// Create a new readiness evaluator at the given block. Requires that
|
||||
/// the ID has already been checked for local corresponding and available state.
|
||||
fn create(at: A::CheckedBlockId, api: &'a A) -> Self {
|
||||
fn create(at: BlockId, api: &'a A) -> Self {
|
||||
Ready {
|
||||
at_block: at,
|
||||
api,
|
||||
@@ -244,12 +244,12 @@ impl<'a, A: 'a + PolkadotApi> txpool::Ready<VerifiedTransaction> for Ready<'a, A
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Verifier<'a, A: 'a, B> {
|
||||
pub struct Verifier<'a, A: 'a> {
|
||||
api: &'a A,
|
||||
at_block: B,
|
||||
at_block: BlockId,
|
||||
}
|
||||
|
||||
impl<'a, A> Verifier<'a, A, A::CheckedBlockId> where
|
||||
impl<'a, A> Verifier<'a, A> where
|
||||
A: 'a + PolkadotApi,
|
||||
{
|
||||
const NO_ACCOUNT: &'static str = "Account not found.";
|
||||
@@ -267,7 +267,7 @@ impl<'a, A> Verifier<'a, A, A::CheckedBlockId> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A> txpool::Verifier<UncheckedExtrinsic> for Verifier<'a, A, A::CheckedBlockId> where
|
||||
impl<'a, A> txpool::Verifier<UncheckedExtrinsic> for Verifier<'a, A> where
|
||||
A: 'a + PolkadotApi,
|
||||
{
|
||||
type VerifiedTransaction = VerifiedTransaction;
|
||||
@@ -322,7 +322,7 @@ impl<A> TransactionPool<A> where
|
||||
pub fn import_unchecked_extrinsic(&self, block: BlockId, uxt: UncheckedExtrinsic) -> Result<Arc<VerifiedTransaction>> {
|
||||
let verifier = Verifier {
|
||||
api: &*self.api,
|
||||
at_block: self.api.check_id(block)?,
|
||||
at_block: block,
|
||||
};
|
||||
self.inner.submit(verifier, vec![uxt]).map(|mut v| v.swap_remove(0))
|
||||
}
|
||||
@@ -332,7 +332,7 @@ impl<A> TransactionPool<A> where
|
||||
let to_reverify = self.inner.remove_sender(None);
|
||||
let verifier = Verifier {
|
||||
api: &*self.api,
|
||||
at_block: self.api.check_id(block)?,
|
||||
at_block: block,
|
||||
};
|
||||
|
||||
self.inner.submit(verifier, to_reverify.into_iter().map(|tx| tx.original.clone()))?;
|
||||
@@ -358,8 +358,7 @@ impl<A> TransactionPool<A> where
|
||||
|
||||
/// Cull old transactions from the queue.
|
||||
pub fn cull(&self, block: BlockId) -> Result<usize> {
|
||||
let id = self.api.check_id(block)?;
|
||||
let ready = Ready::create(id, &*self.api);
|
||||
let ready = Ready::create(block, &*self.api);
|
||||
Ok(self.inner.cull(None, ready))
|
||||
}
|
||||
|
||||
@@ -367,8 +366,7 @@ impl<A> TransactionPool<A> where
|
||||
pub fn cull_and_get_pending<F, T>(&self, block: BlockId, f: F) -> Result<T> where
|
||||
F: FnOnce(txpool::PendingIterator<VerifiedTransaction, Ready<A>, Scoring, Listener<Hash>>) -> T,
|
||||
{
|
||||
let id = self.api.check_id(block)?;
|
||||
let ready = Ready::create(id, &*self.api);
|
||||
let ready = Ready::create(block, &*self.api);
|
||||
self.inner.cull(None, ready.clone());
|
||||
Ok(self.inner.pending(ready, f))
|
||||
}
|
||||
@@ -413,7 +411,7 @@ mod tests {
|
||||
use super::TransactionPool;
|
||||
use substrate_keyring::Keyring::{self, *};
|
||||
use codec::Slicable;
|
||||
use polkadot_api::{PolkadotApi, BlockBuilder, CheckedBlockId, Result};
|
||||
use polkadot_api::{PolkadotApi, BlockBuilder, Result};
|
||||
use primitives::{AccountId, AccountIndex, Block, BlockId, Hash, Index, SessionKey, Timestamp,
|
||||
UncheckedExtrinsic as FutureProofUncheckedExtrinsic};
|
||||
use runtime::{RawAddress, Call, TimestampCall, BareExtrinsic, Extrinsic, UncheckedExtrinsic};
|
||||
@@ -426,15 +424,9 @@ mod tests {
|
||||
fn bake(self) -> Result<Block> { unimplemented!() }
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TestCheckedBlockId(pub BlockId);
|
||||
impl CheckedBlockId for TestCheckedBlockId {
|
||||
fn block_id(&self) -> &BlockId { &self.0 }
|
||||
}
|
||||
|
||||
fn number_of(at: &TestCheckedBlockId) -> u32 {
|
||||
match at.0 {
|
||||
generic::BlockId::Number(n) => n as u32,
|
||||
fn number_of(at: &BlockId) -> u32 {
|
||||
match at {
|
||||
generic::BlockId::Number(n) => *n as u32,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
@@ -457,26 +449,24 @@ mod tests {
|
||||
}
|
||||
|
||||
impl PolkadotApi for TestPolkadotApi {
|
||||
type CheckedBlockId = TestCheckedBlockId;
|
||||
type BlockBuilder = TestBlockBuilder;
|
||||
|
||||
fn check_id(&self, id: BlockId) -> Result<TestCheckedBlockId> { Ok(TestCheckedBlockId(id)) }
|
||||
fn session_keys(&self, _at: &TestCheckedBlockId) -> Result<Vec<SessionKey>> { unimplemented!() }
|
||||
fn validators(&self, _at: &TestCheckedBlockId) -> Result<Vec<AccountId>> { unimplemented!() }
|
||||
fn random_seed(&self, _at: &TestCheckedBlockId) -> Result<Hash> { unimplemented!() }
|
||||
fn duty_roster(&self, _at: &TestCheckedBlockId) -> Result<DutyRoster> { unimplemented!() }
|
||||
fn timestamp(&self, _at: &TestCheckedBlockId) -> Result<u64> { unimplemented!() }
|
||||
fn evaluate_block(&self, _at: &TestCheckedBlockId, _block: Block) -> Result<bool> { unimplemented!() }
|
||||
fn active_parachains(&self, _at: &TestCheckedBlockId) -> Result<Vec<ParaId>> { unimplemented!() }
|
||||
fn parachain_code(&self, _at: &TestCheckedBlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() }
|
||||
fn parachain_head(&self, _at: &TestCheckedBlockId, _parachain: ParaId) -> Result<Option<Vec<u8>>> { unimplemented!() }
|
||||
fn build_block(&self, _at: &TestCheckedBlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> { unimplemented!() }
|
||||
fn inherent_extrinsics(&self, _at: &TestCheckedBlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Vec<Vec<u8>>> { unimplemented!() }
|
||||
fn session_keys(&self, _at: &BlockId) -> Result<Vec<SessionKey>> { unimplemented!() }
|
||||
fn validators(&self, _at: &BlockId) -> Result<Vec<AccountId>> { unimplemented!() }
|
||||
fn random_seed(&self, _at: &BlockId) -> Result<Hash> { unimplemented!() }
|
||||
fn duty_roster(&self, _at: &BlockId) -> Result<DutyRoster> { unimplemented!() }
|
||||
fn timestamp(&self, _at: &BlockId) -> Result<u64> { unimplemented!() }
|
||||
fn evaluate_block(&self, _at: &BlockId, _block: Block) -> Result<bool> { unimplemented!() }
|
||||
fn active_parachains(&self, _at: &BlockId) -> Result<Vec<ParaId>> { 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 build_block(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> { unimplemented!() }
|
||||
fn inherent_extrinsics(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Vec<Vec<u8>>> { unimplemented!() }
|
||||
|
||||
fn index(&self, _at: &TestCheckedBlockId, _account: AccountId) -> Result<Index> {
|
||||
fn index(&self, _at: &BlockId, _account: AccountId) -> Result<Index> {
|
||||
Ok((_account[0] as u32) + number_of(_at))
|
||||
}
|
||||
fn lookup(&self, _at: &TestCheckedBlockId, _address: RawAddress<AccountId, AccountIndex>) -> Result<Option<AccountId>> {
|
||||
fn lookup(&self, _at: &BlockId, _address: RawAddress<AccountId, AccountIndex>) -> Result<Option<AccountId>> {
|
||||
match _address {
|
||||
RawAddress::Id(i) => Ok(Some(i)),
|
||||
RawAddress::Index(_) if self.no_lookup.load(atomic::Ordering::SeqCst) => Ok(None),
|
||||
|
||||
Reference in New Issue
Block a user