mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
Updates substrate to latest master (#107)
* Updates substrate to latest master * Use slot_duration and not slot * Update to latest substrate master again to have latest CLI * Rename iherent indentifier * Update after master merge
This commit is contained in:
Generated
+697
-617
File diff suppressed because it is too large
Load Diff
@@ -11,4 +11,3 @@ futures = "0.1.17"
|
|||||||
exit-future = "0.1"
|
exit-future = "0.1"
|
||||||
substrate-cli = { git = "https://github.com/paritytech/substrate" }
|
substrate-cli = { git = "https://github.com/paritytech/substrate" }
|
||||||
polkadot-service = { path = "../service" }
|
polkadot-service = { path = "../service" }
|
||||||
structopt = "0.2.13"
|
|
||||||
|
|||||||
+21
-31
@@ -25,7 +25,6 @@ extern crate tokio;
|
|||||||
extern crate substrate_cli as cli;
|
extern crate substrate_cli as cli;
|
||||||
extern crate polkadot_service as service;
|
extern crate polkadot_service as service;
|
||||||
extern crate exit_future;
|
extern crate exit_future;
|
||||||
extern crate structopt;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
@@ -36,8 +35,8 @@ use std::ops::Deref;
|
|||||||
use chain_spec::ChainSpec;
|
use chain_spec::ChainSpec;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use structopt::StructOpt;
|
|
||||||
use service::Service as BareService;
|
use service::Service as BareService;
|
||||||
|
use cli::NoCustom;
|
||||||
|
|
||||||
pub use service::{
|
pub use service::{
|
||||||
Components as ServiceComponents, PolkadotService, CustomConfiguration, ServiceFactory, Factory,
|
Components as ServiceComponents, PolkadotService, CustomConfiguration, ServiceFactory, Factory,
|
||||||
@@ -85,42 +84,33 @@ pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Res
|
|||||||
T: Into<std::ffi::OsString> + Clone,
|
T: Into<std::ffi::OsString> + Clone,
|
||||||
W: Worker,
|
W: Worker,
|
||||||
{
|
{
|
||||||
let full_version = polkadot_service::full_version_from_strs(
|
cli::parse_and_execute::<service::Factory, NoCustom, NoCustom, _, _, _, _, _>(
|
||||||
version.version,
|
load_spec, &version, "parity-polkadot", args, worker,
|
||||||
version.commit
|
|worker, _custom_args, mut config| {
|
||||||
);
|
info!("{}", version.name);
|
||||||
|
|
||||||
let matches = match cli::CoreParams::clap()
|
|
||||||
.name(version.executable_name)
|
|
||||||
.author(version.author)
|
|
||||||
.about(version.description)
|
|
||||||
.version(&(full_version + "\n")[..])
|
|
||||||
.get_matches_from_safe(args) {
|
|
||||||
Ok(m) => m,
|
|
||||||
Err(e) => e.exit(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let (spec, mut config) = cli::parse_matches::<service::Factory, _>(load_spec, &version, "parity-polkadot", &matches)?;
|
|
||||||
|
|
||||||
match cli::execute_default::<service::Factory, _>(spec, worker, &matches, &config)? {
|
|
||||||
cli::Action::ExecutedInternally => (),
|
|
||||||
cli::Action::RunService(worker) => {
|
|
||||||
info!("Parity ·:· Polkadot");
|
|
||||||
info!(" version {}", config.full_version());
|
info!(" version {}", config.full_version());
|
||||||
info!(" by Parity Technologies, 2017, 2018");
|
info!(" by {}, 2017-2019", version.author);
|
||||||
info!("Chain specification: {}", config.chain_spec.name());
|
info!("Chain specification: {}", config.chain_spec.name());
|
||||||
info!("Node name: {}", config.name);
|
info!("Node name: {}", config.name);
|
||||||
info!("Roles: {:?}", config.roles);
|
info!("Roles: {:?}", config.roles);
|
||||||
config.custom = worker.configuration();
|
config.custom = worker.configuration();
|
||||||
let mut runtime = Runtime::new()?;
|
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
|
||||||
let executor = runtime.executor();
|
let executor = runtime.executor();
|
||||||
match config.roles == service::Roles::LIGHT {
|
match config.roles {
|
||||||
true => run_until_exit(runtime, Factory::new_light(config, executor)?, worker)?,
|
service::Roles::LIGHT =>
|
||||||
false => run_until_exit(runtime, Factory::new_full(config, executor)?, worker)?,
|
run_until_exit(
|
||||||
}
|
runtime,
|
||||||
|
Factory::new_light(config, executor).map_err(|e| format!("{:?}", e))?,
|
||||||
|
worker
|
||||||
|
),
|
||||||
|
_ => run_until_exit(
|
||||||
|
runtime,
|
||||||
|
Factory::new_full(config, executor).map_err(|e| format!("{:?}", e))?,
|
||||||
|
worker
|
||||||
|
),
|
||||||
|
}.map_err(|e| format!("{:?}", e))
|
||||||
}
|
}
|
||||||
}
|
).map_err(Into::into).map(|_| ())
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_until_exit<T, C, W>(
|
fn run_until_exit<T, C, W>(
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ polkadot-parachain = { path = "../parachain" }
|
|||||||
polkadot-primitives = { path = "../primitives" }
|
polkadot-primitives = { path = "../primitives" }
|
||||||
polkadot-runtime = { path = "../runtime" }
|
polkadot-runtime = { path = "../runtime" }
|
||||||
polkadot-statement-table = { path = "../statement-table" }
|
polkadot-statement-table = { path = "../statement-table" }
|
||||||
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate" }
|
substrate-consensus-aura = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate" }
|
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-consensus-common = { git = "https://github.com/paritytech/substrate" }
|
substrate-consensus-common = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||||
|
substrate-inherents = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate" }
|
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate" }
|
||||||
srml-support = { git = "https://github.com/paritytech/substrate" }
|
srml-aura = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-trie = { git = "https://github.com/paritytech/substrate" }
|
substrate-trie = { git = "https://github.com/paritytech/substrate" }
|
||||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use client::blockchain::HeaderBackend;
|
|||||||
use client::runtime_api::Core;
|
use client::runtime_api::Core;
|
||||||
use primitives::ed25519;
|
use primitives::ed25519;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use polkadot_primitives::{Block, BlockId, InherentData};
|
use polkadot_primitives::{Block, BlockId};
|
||||||
use polkadot_primitives::parachain::ParachainHost;
|
use polkadot_primitives::parachain::ParachainHost;
|
||||||
use extrinsic_store::Store as ExtrinsicStore;
|
use extrinsic_store::Store as ExtrinsicStore;
|
||||||
use runtime_primitives::traits::ProvideRuntimeApi;
|
use runtime_primitives::traits::ProvideRuntimeApi;
|
||||||
@@ -122,7 +122,7 @@ pub(crate) fn start<C, N, P>(
|
|||||||
<C::Collation as IntoFuture>::Future: Send + 'static,
|
<C::Collation as IntoFuture>::Future: Send + 'static,
|
||||||
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
|
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
|
||||||
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
||||||
P::Api: ParachainHost<Block> + Core<Block> + BlockBuilder<Block, InherentData>,
|
P::Api: ParachainHost<Block> + Core<Block> + BlockBuilder<Block>,
|
||||||
N: Network + Send + Sync + 'static,
|
N: Network + Send + Sync + 'static,
|
||||||
N::TableRouter: Send + 'static,
|
N::TableRouter: Send + 'static,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ extern crate polkadot_primitives;
|
|||||||
|
|
||||||
extern crate parity_codec as codec;
|
extern crate parity_codec as codec;
|
||||||
extern crate substrate_primitives as primitives;
|
extern crate substrate_primitives as primitives;
|
||||||
extern crate srml_support as runtime_support;
|
|
||||||
extern crate sr_primitives as runtime_primitives;
|
extern crate sr_primitives as runtime_primitives;
|
||||||
extern crate substrate_client as client;
|
extern crate substrate_client as client;
|
||||||
extern crate substrate_trie as trie;
|
extern crate substrate_trie as trie;
|
||||||
@@ -46,9 +45,11 @@ extern crate substrate_trie as trie;
|
|||||||
extern crate exit_future;
|
extern crate exit_future;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
extern crate substrate_consensus_common as consensus;
|
extern crate substrate_consensus_common as consensus;
|
||||||
extern crate substrate_consensus_aura_primitives as aura_primitives;
|
extern crate substrate_consensus_aura as aura;
|
||||||
extern crate substrate_finality_grandpa as grandpa;
|
extern crate substrate_finality_grandpa as grandpa;
|
||||||
extern crate substrate_transaction_pool as transaction_pool;
|
extern crate substrate_transaction_pool as transaction_pool;
|
||||||
|
extern crate substrate_inherents as inherents;
|
||||||
|
extern crate srml_aura as runtime_aura;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
@@ -73,27 +74,35 @@ use client::runtime_api::Core;
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use extrinsic_store::Store as ExtrinsicStore;
|
use extrinsic_store::Store as ExtrinsicStore;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use polkadot_primitives::{
|
use polkadot_primitives::{Hash, Block, BlockId, BlockNumber, Header, SessionKey};
|
||||||
Hash, Block, BlockId, BlockNumber, Header, SessionKey, InherentData
|
use polkadot_primitives::parachain::{
|
||||||
|
Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt,
|
||||||
|
CandidateSignature
|
||||||
|
};
|
||||||
|
use polkadot_primitives::parachain::{
|
||||||
|
AttestedCandidate, ParachainHost, Statement as PrimitiveStatement
|
||||||
};
|
};
|
||||||
use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt, CandidateSignature};
|
|
||||||
use polkadot_primitives::parachain::{AttestedCandidate, ParachainHost, Statement as PrimitiveStatement};
|
|
||||||
use primitives::{Ed25519AuthorityId as AuthorityId, ed25519};
|
use primitives::{Ed25519AuthorityId as AuthorityId, ed25519};
|
||||||
use runtime_primitives::traits::ProvideRuntimeApi;
|
use runtime_primitives::traits::ProvideRuntimeApi;
|
||||||
use tokio::runtime::TaskExecutor;
|
use tokio::runtime::TaskExecutor;
|
||||||
use tokio::timer::{Delay, Interval};
|
use tokio::timer::{Delay, Interval};
|
||||||
use transaction_pool::txpool::{Pool, ChainApi as PoolChainApi};
|
use transaction_pool::txpool::{Pool, ChainApi as PoolChainApi};
|
||||||
use aura_primitives::AuraConsensusData;
|
|
||||||
|
|
||||||
use attestation_service::ServiceHandle;
|
use attestation_service::ServiceHandle;
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use futures::future::{self, Either};
|
use futures::future::{self, Either};
|
||||||
use collation::CollationFetch;
|
use collation::CollationFetch;
|
||||||
use dynamic_inclusion::DynamicInclusion;
|
use dynamic_inclusion::DynamicInclusion;
|
||||||
|
use inherents::InherentData;
|
||||||
|
use runtime_aura::timestamp::TimestampInherentData;
|
||||||
|
use aura::SlotDuration;
|
||||||
|
|
||||||
pub use self::collation::{validate_collation, egress_trie_root, Collators};
|
pub use self::collation::{validate_collation, egress_trie_root, Collators};
|
||||||
pub use self::error::{ErrorKind, Error};
|
pub use self::error::{ErrorKind, Error};
|
||||||
pub use self::shared_table::{SharedTable, ParachainWork, PrimedParachainWork, Validated, Statement, SignedStatement, GenericStatement};
|
pub use self::shared_table::{
|
||||||
|
SharedTable, ParachainWork, PrimedParachainWork, Validated, Statement, SignedStatement,
|
||||||
|
GenericStatement
|
||||||
|
};
|
||||||
|
|
||||||
mod attestation_service;
|
mod attestation_service;
|
||||||
mod dynamic_inclusion;
|
mod dynamic_inclusion;
|
||||||
@@ -231,7 +240,7 @@ impl<C, N, P> ParachainConsensus<C, N, P> where
|
|||||||
C: Collators + Send + 'static,
|
C: Collators + Send + 'static,
|
||||||
N: Network,
|
N: Network,
|
||||||
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
||||||
P::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
|
P::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
|
||||||
<C::Collation as IntoFuture>::Future: Send + 'static,
|
<C::Collation as IntoFuture>::Future: Send + 'static,
|
||||||
N::TableRouter: Send + 'static,
|
N::TableRouter: Send + 'static,
|
||||||
{
|
{
|
||||||
@@ -325,6 +334,7 @@ pub struct ProposerFactory<C, N, P, TxApi: PoolChainApi> {
|
|||||||
transaction_pool: Arc<Pool<TxApi>>,
|
transaction_pool: Arc<Pool<TxApi>>,
|
||||||
key: Arc<ed25519::Pair>,
|
key: Arc<ed25519::Pair>,
|
||||||
_service_handle: ServiceHandle,
|
_service_handle: ServiceHandle,
|
||||||
|
aura_slot_duration: SlotDuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
|
impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
|
||||||
@@ -332,7 +342,7 @@ impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
|
|||||||
<C::Collation as IntoFuture>::Future: Send + 'static,
|
<C::Collation as IntoFuture>::Future: Send + 'static,
|
||||||
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
|
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
|
||||||
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
||||||
P::Api: ParachainHost<Block> + Core<Block> + BlockBuilderApi<Block, InherentData>,
|
P::Api: ParachainHost<Block> + Core<Block> + BlockBuilderApi<Block>,
|
||||||
N: Network + Send + Sync + 'static,
|
N: Network + Send + Sync + 'static,
|
||||||
N::TableRouter: Send + 'static,
|
N::TableRouter: Send + 'static,
|
||||||
TxApi: PoolChainApi,
|
TxApi: PoolChainApi,
|
||||||
@@ -346,6 +356,7 @@ impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
|
|||||||
thread_pool: TaskExecutor,
|
thread_pool: TaskExecutor,
|
||||||
key: Arc<ed25519::Pair>,
|
key: Arc<ed25519::Pair>,
|
||||||
extrinsic_store: ExtrinsicStore,
|
extrinsic_store: ExtrinsicStore,
|
||||||
|
aura_slot_duration: SlotDuration,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let parachain_consensus = Arc::new(ParachainConsensus {
|
let parachain_consensus = Arc::new(ParachainConsensus {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
@@ -369,16 +380,17 @@ impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
|
|||||||
transaction_pool,
|
transaction_pool,
|
||||||
key,
|
key,
|
||||||
_service_handle: service_handle,
|
_service_handle: service_handle,
|
||||||
|
aura_slot_duration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, N, P, TxApi> consensus::Environment<Block, AuraConsensusData> for ProposerFactory<C, N, P, TxApi> where
|
impl<C, N, P, TxApi> consensus::Environment<Block> for ProposerFactory<C, N, P, TxApi> where
|
||||||
C: Collators + Send + 'static,
|
C: Collators + Send + 'static,
|
||||||
N: Network,
|
N: Network,
|
||||||
TxApi: PoolChainApi<Block=Block>,
|
TxApi: PoolChainApi<Block=Block>,
|
||||||
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
P: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync + 'static,
|
||||||
P::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
|
P::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
|
||||||
<C::Collation as IntoFuture>::Future: Send + 'static,
|
<C::Collation as IntoFuture>::Future: Send + 'static,
|
||||||
N::TableRouter: Send + 'static,
|
N::TableRouter: Send + 'static,
|
||||||
{
|
{
|
||||||
@@ -406,6 +418,7 @@ impl<C, N, P, TxApi> consensus::Environment<Block, AuraConsensusData> for Propos
|
|||||||
parent_id,
|
parent_id,
|
||||||
parent_number: parent_header.number,
|
parent_number: parent_header.number,
|
||||||
transaction_pool: self.transaction_pool.clone(),
|
transaction_pool: self.transaction_pool.clone(),
|
||||||
|
slot_duration: self.aura_slot_duration,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,20 +496,18 @@ pub struct Proposer<C: Send + Sync, TxApi: PoolChainApi> where
|
|||||||
parent_number: BlockNumber,
|
parent_number: BlockNumber,
|
||||||
tracker: Arc<AttestationTracker>,
|
tracker: Arc<AttestationTracker>,
|
||||||
transaction_pool: Arc<Pool<TxApi>>,
|
transaction_pool: Arc<Pool<TxApi>>,
|
||||||
|
slot_duration: SlotDuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, TxApi> consensus::Proposer<Block, AuraConsensusData> for Proposer<C, TxApi> where
|
impl<C, TxApi> consensus::Proposer<Block> for Proposer<C, TxApi> where
|
||||||
TxApi: PoolChainApi<Block=Block>,
|
TxApi: PoolChainApi<Block=Block>,
|
||||||
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
||||||
C::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
|
C::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Create = Either<
|
type Create = Either<CreateProposal<C, TxApi>, future::FutureResult<Block, Error>>;
|
||||||
CreateProposal<C, TxApi>,
|
|
||||||
future::FutureResult<Block, Error>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
fn propose(&self, consensus_data: AuraConsensusData) -> Self::Create {
|
fn propose(&self, inherent_data: InherentData) -> Self::Create {
|
||||||
const ATTEMPT_PROPOSE_EVERY: Duration = Duration::from_millis(100);
|
const ATTEMPT_PROPOSE_EVERY: Duration = Duration::from_millis(100);
|
||||||
const SLOT_DURATION_DENOMINATOR: u64 = 3; // wait up to 1/3 of the slot for candidates.
|
const SLOT_DURATION_DENOMINATOR: u64 = 3; // wait up to 1/3 of the slot for candidates.
|
||||||
|
|
||||||
@@ -506,7 +517,7 @@ impl<C, TxApi> consensus::Proposer<Block, AuraConsensusData> for Proposer<C, TxA
|
|||||||
let dynamic_inclusion = DynamicInclusion::new(
|
let dynamic_inclusion = DynamicInclusion::new(
|
||||||
self.tracker.table.num_parachains(),
|
self.tracker.table.num_parachains(),
|
||||||
self.tracker.started,
|
self.tracker.started,
|
||||||
Duration::from_secs(consensus_data.slot_duration / SLOT_DURATION_DENOMINATOR),
|
Duration::from_secs(self.slot_duration.get() / SLOT_DURATION_DENOMINATOR),
|
||||||
);
|
);
|
||||||
|
|
||||||
let enough_candidates = dynamic_inclusion.acceptable_in(
|
let enough_candidates = dynamic_inclusion.acceptable_in(
|
||||||
@@ -514,7 +525,10 @@ impl<C, TxApi> consensus::Proposer<Block, AuraConsensusData> for Proposer<C, TxA
|
|||||||
initial_included,
|
initial_included,
|
||||||
).unwrap_or_else(|| now + Duration::from_millis(1));
|
).unwrap_or_else(|| now + Duration::from_millis(1));
|
||||||
|
|
||||||
let believed_timestamp = consensus_data.timestamp;
|
let believed_timestamp = match inherent_data.timestamp_inherent_data() {
|
||||||
|
Ok(timestamp) => timestamp,
|
||||||
|
Err(e) => return Either::B(future::err(ErrorKind::InherentError(e).into())),
|
||||||
|
};
|
||||||
|
|
||||||
// set up delay until next allowed timestamp.
|
// set up delay until next allowed timestamp.
|
||||||
let current_timestamp = current_timestamp();
|
let current_timestamp = current_timestamp();
|
||||||
@@ -542,8 +556,8 @@ impl<C, TxApi> consensus::Proposer<Block, AuraConsensusData> for Proposer<C, TxA
|
|||||||
transaction_pool: self.transaction_pool.clone(),
|
transaction_pool: self.transaction_pool.clone(),
|
||||||
table: self.tracker.table.clone(),
|
table: self.tracker.table.clone(),
|
||||||
believed_minimum_timestamp: believed_timestamp,
|
believed_minimum_timestamp: believed_timestamp,
|
||||||
consensus_data,
|
|
||||||
timing,
|
timing,
|
||||||
|
inherent_data: Some(inherent_data),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,25 +625,22 @@ pub struct CreateProposal<C: Send + Sync, TxApi: PoolChainApi> {
|
|||||||
table: Arc<SharedTable>,
|
table: Arc<SharedTable>,
|
||||||
timing: ProposalTiming,
|
timing: ProposalTiming,
|
||||||
believed_minimum_timestamp: u64,
|
believed_minimum_timestamp: u64,
|
||||||
consensus_data: AuraConsensusData,
|
inherent_data: Option<InherentData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, TxApi> CreateProposal<C, TxApi> where
|
impl<C, TxApi> CreateProposal<C, TxApi> where
|
||||||
TxApi: PoolChainApi<Block=Block>,
|
TxApi: PoolChainApi<Block=Block>,
|
||||||
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
||||||
C::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
|
C::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
|
||||||
{
|
{
|
||||||
fn propose_with(&self, candidates: Vec<AttestedCandidate>) -> Result<Block, Error> {
|
fn propose_with(&mut self, candidates: Vec<AttestedCandidate>) -> Result<Block, Error> {
|
||||||
use client::block_builder::BlockBuilder;
|
use client::block_builder::BlockBuilder;
|
||||||
use runtime_primitives::traits::{Hash as HashT, BlakeTwo256};
|
use runtime_primitives::traits::{Hash as HashT, BlakeTwo256};
|
||||||
|
|
||||||
const MAX_TRANSACTIONS: usize = 40;
|
const MAX_TRANSACTIONS: usize = 40;
|
||||||
|
|
||||||
let inherent_data = InherentData {
|
let mut inherent_data = self.inherent_data.take().expect("CreateProposal is not polled after finishing; qed");
|
||||||
timestamp: self.believed_minimum_timestamp,
|
inherent_data.put_data(polkadot_runtime::PARACHAIN_INHERENT_IDENTIFIER, &candidates).map_err(ErrorKind::InherentError)?;
|
||||||
parachains: candidates,
|
|
||||||
aura_expected_slot: self.consensus_data.slot,
|
|
||||||
};
|
|
||||||
|
|
||||||
let runtime_api = self.client.runtime_api();
|
let runtime_api = self.client.runtime_api();
|
||||||
|
|
||||||
@@ -694,7 +705,7 @@ impl<C, TxApi> CreateProposal<C, TxApi> where
|
|||||||
impl<C, TxApi> Future for CreateProposal<C, TxApi> where
|
impl<C, TxApi> Future for CreateProposal<C, TxApi> where
|
||||||
TxApi: PoolChainApi<Block=Block>,
|
TxApi: PoolChainApi<Block=Block>,
|
||||||
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
|
||||||
C::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
|
C::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
|
||||||
{
|
{
|
||||||
type Item = Block;
|
type Item = Block;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|||||||
@@ -106,14 +106,3 @@ pub type BlockId = generic::BlockId<Block>;
|
|||||||
pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
||||||
|
|
||||||
impl Extrinsic for UncheckedExtrinsic {}
|
impl Extrinsic for UncheckedExtrinsic {}
|
||||||
|
|
||||||
/// Inherent data to include in a block.
|
|
||||||
#[derive(Encode, Decode)]
|
|
||||||
pub struct InherentData {
|
|
||||||
/// Current timestamp.
|
|
||||||
pub timestamp: u64,
|
|
||||||
/// Parachain heads update. This contains fully-attested candidates.
|
|
||||||
pub parachains: Vec<::parachain::AttestedCandidate>,
|
|
||||||
/// Expected slot for aura authorship.
|
|
||||||
pub aura_expected_slot: u64,
|
|
||||||
}
|
|
||||||
|
|||||||
+28
-25
@@ -11,32 +11,33 @@ serde = { version = "1.0", default-features = false }
|
|||||||
serde_derive = { version = "1.0", optional = true }
|
serde_derive = { version = "1.0", optional = true }
|
||||||
safe-mix = { version = "1.0", default-features = false}
|
safe-mix = { version = "1.0", default-features = false}
|
||||||
polkadot-primitives = { path = "../primitives", default-features = false }
|
polkadot-primitives = { path = "../primitives", default-features = false }
|
||||||
parity-codec = "2.1"
|
parity-codec = { version = "2.2", default-features = false }
|
||||||
parity-codec-derive = "2.1"
|
parity-codec-derive = { version = "2.2", default-features = false }
|
||||||
substrate-serializer = { git = "https://github.com/paritytech/substrate" }
|
substrate-serializer = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
sr-std = { git = "https://github.com/paritytech/substrate" }
|
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
sr-io = { git = "https://github.com/paritytech/substrate" }
|
sr-io = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-support = { git = "https://github.com/paritytech/substrate" }
|
srml-support = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
|
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
substrate-client = { git = "https://github.com/paritytech/substrate" }
|
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
|
substrate-inherents = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-aura = { git = "https://github.com/paritytech/substrate" }
|
srml-aura = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-balances = { git = "https://github.com/paritytech/substrate" }
|
srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-consensus = { git = "https://github.com/paritytech/substrate" }
|
srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-council = { git = "https://github.com/paritytech/substrate" }
|
srml-council = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-democracy = { git = "https://github.com/paritytech/substrate" }
|
srml-democracy = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-executive = { git = "https://github.com/paritytech/substrate" }
|
srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-grandpa = { git = "https://github.com/paritytech/substrate" }
|
srml-grandpa = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-indices = { git = "https://github.com/paritytech/substrate" }
|
srml-indices = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
sr-primitives = { git = "https://github.com/paritytech/substrate" }
|
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-session = { git = "https://github.com/paritytech/substrate" }
|
srml-session = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-staking = { git = "https://github.com/paritytech/substrate" }
|
srml-staking = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-sudo = { git = "https://github.com/paritytech/substrate" }
|
srml-sudo = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-system = { git = "https://github.com/paritytech/substrate" }
|
srml-system = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-timestamp = { git = "https://github.com/paritytech/substrate" }
|
srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-treasury = { git = "https://github.com/paritytech/substrate" }
|
srml-treasury = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
srml-upgrade-key = { git = "https://github.com/paritytech/substrate" }
|
srml-upgrade-key = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
sr-version = { git = "https://github.com/paritytech/substrate" }
|
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
|
||||||
libsecp256k1 = "0.2.1"
|
libsecp256k1 = "0.2.1"
|
||||||
tiny-keccak = "1.4.2"
|
tiny-keccak = "1.4.2"
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ std = [
|
|||||||
"parity-codec/std",
|
"parity-codec/std",
|
||||||
"parity-codec-derive/std",
|
"parity-codec-derive/std",
|
||||||
"substrate-primitives/std",
|
"substrate-primitives/std",
|
||||||
|
"substrate-client/std",
|
||||||
|
"substrate-inherents/std",
|
||||||
"sr-std/std",
|
"sr-std/std",
|
||||||
"sr-io/std",
|
"sr-io/std",
|
||||||
"srml-support/std",
|
"srml-support/std",
|
||||||
|
|||||||
+12
-58
@@ -36,10 +36,10 @@ extern crate parity_codec as codec;
|
|||||||
|
|
||||||
extern crate substrate_consensus_aura_primitives as consensus_aura;
|
extern crate substrate_consensus_aura_primitives as consensus_aura;
|
||||||
extern crate substrate_primitives;
|
extern crate substrate_primitives;
|
||||||
|
extern crate substrate_inherents as inherents;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate substrate_client as client;
|
extern crate substrate_client as client;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate sr_std as rstd;
|
extern crate sr_std as rstd;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate sr_io;
|
extern crate sr_io;
|
||||||
@@ -80,12 +80,11 @@ use primitives::{
|
|||||||
parachain,
|
parachain,
|
||||||
};
|
};
|
||||||
use client::{
|
use client::{
|
||||||
block_builder::api as block_builder_api,
|
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
|
||||||
runtime_api as client_api,
|
runtime_api as client_api,
|
||||||
};
|
};
|
||||||
use consensus_aura::api as aura_api;
|
|
||||||
use sr_primitives::{
|
use sr_primitives::{
|
||||||
ApplyResult, CheckInherentError, generic, transaction_validity::TransactionValidity,
|
ApplyResult, generic, transaction_validity::TransactionValidity,
|
||||||
traits::{Convert, BlakeTwo256, Block as BlockT, DigestFor, StaticLookup}
|
traits::{Convert, BlakeTwo256, Block as BlockT, DigestFor, StaticLookup}
|
||||||
};
|
};
|
||||||
use version::RuntimeVersion;
|
use version::RuntimeVersion;
|
||||||
@@ -102,15 +101,11 @@ pub use sr_primitives::BuildStorage;
|
|||||||
pub use consensus::Call as ConsensusCall;
|
pub use consensus::Call as ConsensusCall;
|
||||||
pub use timestamp::Call as TimestampCall;
|
pub use timestamp::Call as TimestampCall;
|
||||||
pub use balances::Call as BalancesCall;
|
pub use balances::Call as BalancesCall;
|
||||||
pub use parachains::Call as ParachainsCall;
|
pub use parachains::{Call as ParachainsCall, INHERENT_IDENTIFIER as PARACHAIN_INHERENT_IDENTIFIER};
|
||||||
pub use sr_primitives::{Permill, Perbill};
|
pub use sr_primitives::{Permill, Perbill};
|
||||||
pub use timestamp::BlockPeriod;
|
pub use timestamp::BlockPeriod;
|
||||||
pub use srml_support::{StorageValue, RuntimeMetadata};
|
pub use srml_support::{StorageValue, RuntimeMetadata};
|
||||||
|
|
||||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
|
||||||
const PARACHAINS_SET_POSITION: u32 = 1;
|
|
||||||
const NOTE_OFFLINE_POSITION: u32 = 2; // this should be reintroduced
|
|
||||||
|
|
||||||
/// Runtime version.
|
/// Runtime version.
|
||||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||||
spec_name: create_runtime_str!("polkadot"),
|
spec_name: create_runtime_str!("polkadot"),
|
||||||
@@ -164,7 +159,6 @@ impl balances::Trait for Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl consensus::Trait for Runtime {
|
impl consensus::Trait for Runtime {
|
||||||
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
|
|
||||||
type Log = Log;
|
type Log = Log;
|
||||||
type SessionKey = SessionKey;
|
type SessionKey = SessionKey;
|
||||||
|
|
||||||
@@ -174,7 +168,6 @@ impl consensus::Trait for Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl timestamp::Trait for Runtime {
|
impl timestamp::Trait for Runtime {
|
||||||
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
|
|
||||||
type Moment = u64;
|
type Moment = u64;
|
||||||
type OnTimestampSet = Aura;
|
type OnTimestampSet = Aura;
|
||||||
}
|
}
|
||||||
@@ -229,9 +222,7 @@ impl grandpa::Trait for Runtime {
|
|||||||
type Event = Event;
|
type Event = Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl parachains::Trait for Runtime {
|
impl parachains::Trait for Runtime {}
|
||||||
const SET_POSITION: u32 = PARACHAINS_SET_POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl upgrade_key::Trait for Runtime {
|
impl upgrade_key::Trait for Runtime {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
@@ -250,7 +241,7 @@ construct_runtime!(
|
|||||||
pub enum Runtime with Log(InternalLog: DigestItem<Hash, SessionKey>) where
|
pub enum Runtime with Log(InternalLog: DigestItem<Hash, SessionKey>) where
|
||||||
Block = Block,
|
Block = Block,
|
||||||
NodeBlock = primitives::Block,
|
NodeBlock = primitives::Block,
|
||||||
InherentData = primitives::InherentData
|
UncheckedExtrinsic = UncheckedExtrinsic
|
||||||
{
|
{
|
||||||
System: system::{default, Log(ChangesTrieRoot)},
|
System: system::{default, Log(ChangesTrieRoot)},
|
||||||
Aura: aura::{Module},
|
Aura: aura::{Module},
|
||||||
@@ -317,7 +308,7 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl block_builder_api::BlockBuilder<Block, primitives::InherentData> for Runtime {
|
impl block_builder_api::BlockBuilder<Block> for Runtime {
|
||||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {
|
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {
|
||||||
Executive::apply_extrinsic(extrinsic)
|
Executive::apply_extrinsic(extrinsic)
|
||||||
}
|
}
|
||||||
@@ -326,48 +317,12 @@ impl_runtime_apis! {
|
|||||||
Executive::finalise_block()
|
Executive::finalise_block()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inherent_extrinsics(data: primitives::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
fn inherent_extrinsics(data: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||||
use sr_primitives::traits::ProvideInherent;
|
data.create_extrinsics()
|
||||||
|
|
||||||
let mut inherent = Vec::new();
|
|
||||||
|
|
||||||
inherent.extend(
|
|
||||||
Timestamp::create_inherent_extrinsics(data.timestamp)
|
|
||||||
.into_iter()
|
|
||||||
.map(|v| (v.0, UncheckedExtrinsic::new_unsigned(Call::Timestamp(v.1))))
|
|
||||||
);
|
|
||||||
|
|
||||||
inherent.extend(
|
|
||||||
Parachains::create_inherent_extrinsics(data.parachains)
|
|
||||||
.into_iter()
|
|
||||||
.map(|v| (v.0, UncheckedExtrinsic::new_unsigned(Call::Parachains(v.1))))
|
|
||||||
);
|
|
||||||
|
|
||||||
inherent.as_mut_slice().sort_unstable_by_key(|v| v.0);
|
|
||||||
inherent.into_iter().map(|v| v.1).collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_inherents(block: Block, data: primitives::InherentData) -> Result<(), CheckInherentError> {
|
fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {
|
||||||
let expected_slot = data.aura_expected_slot;
|
data.check_extrinsics(&block)
|
||||||
|
|
||||||
// draw timestamp out from extrinsics.
|
|
||||||
let set_timestamp = block.extrinsics()
|
|
||||||
.get(TIMESTAMP_SET_POSITION as usize)
|
|
||||||
.and_then(|xt: &UncheckedExtrinsic| match xt.function {
|
|
||||||
Call::Timestamp(TimestampCall::set(ref t)) => Some(t.clone()),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.ok_or_else(|| CheckInherentError::Other("No valid timestamp in block.".into()))?;
|
|
||||||
|
|
||||||
// take the "worse" result of normal verification and the timestamp vs. seal
|
|
||||||
// check.
|
|
||||||
CheckInherentError::combine_results(
|
|
||||||
Runtime::check_inherents(block, data),
|
|
||||||
|| {
|
|
||||||
Aura::verify_inherent(set_timestamp.into(), expected_slot)
|
|
||||||
.map_err(|s| CheckInherentError::Other(s.into()))
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_seed() -> <Block as BlockT>::Hash {
|
fn random_seed() -> <Block as BlockT>::Hash {
|
||||||
@@ -419,10 +374,9 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl aura_api::AuraApi<Block> for Runtime {
|
impl consensus_aura::AuraApi<Block> for Runtime {
|
||||||
fn slot_duration() -> u64 {
|
fn slot_duration() -> u64 {
|
||||||
Aura::slot_duration()
|
Aura::slot_duration()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,16 +20,15 @@ use rstd::prelude::*;
|
|||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
|
|
||||||
use bitvec::BigEndian;
|
use bitvec::BigEndian;
|
||||||
use sr_primitives::CheckInherentError;
|
use sr_primitives::traits::{Hash as HashT, BlakeTwo256};
|
||||||
use sr_primitives::traits::{
|
|
||||||
Extrinsic, Block as BlockT, Hash as HashT, BlakeTwo256, ProvideInherent,
|
|
||||||
};
|
|
||||||
use primitives::parachain::{Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement};
|
use primitives::parachain::{Id as ParaId, Chain, DutyRoster, AttestedCandidate, Statement};
|
||||||
use {system, session};
|
use {system, session};
|
||||||
|
|
||||||
use srml_support::{StorageValue, StorageMap};
|
use srml_support::{StorageValue, StorageMap};
|
||||||
use srml_support::dispatch::Result;
|
use srml_support::dispatch::Result;
|
||||||
|
|
||||||
|
use inherents::{ProvideInherent, InherentData, RuntimeString, MakeFatalError, InherentIdentifier};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
use sr_primitives::{self, ChildrenStorageMap};
|
use sr_primitives::{self, ChildrenStorageMap};
|
||||||
|
|
||||||
@@ -38,10 +37,7 @@ use rstd::marker::PhantomData;
|
|||||||
|
|
||||||
use system::ensure_inherent;
|
use system::ensure_inherent;
|
||||||
|
|
||||||
pub trait Trait: session::Trait {
|
pub trait Trait: session::Trait {}
|
||||||
/// The position of the set_heads call in the block.
|
|
||||||
const SET_POSITION: u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
decl_storage! {
|
decl_storage! {
|
||||||
trait Store for Module<T: Trait> as Parachains {
|
trait Store for Module<T: Trait> as Parachains {
|
||||||
@@ -87,11 +83,6 @@ decl_module! {
|
|||||||
fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
|
fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
|
||||||
ensure_inherent(origin)?;
|
ensure_inherent(origin)?;
|
||||||
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
|
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
|
||||||
ensure!(
|
|
||||||
<system::Module<T>>::extrinsic_index() == Some(T::SET_POSITION),
|
|
||||||
"Parachain heads update extrinsic must be at position {} in the block"
|
|
||||||
// , T::SET_POSITION
|
|
||||||
);
|
|
||||||
|
|
||||||
let active_parachains = Self::active_parachains();
|
let active_parachains = Self::active_parachains();
|
||||||
|
|
||||||
@@ -378,34 +369,21 @@ impl<T: Trait> Module<T> {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"newheads";
|
||||||
|
|
||||||
|
pub type InherentType = Vec<AttestedCandidate>;
|
||||||
|
|
||||||
impl<T: Trait> ProvideInherent for Module<T> {
|
impl<T: Trait> ProvideInherent for Module<T> {
|
||||||
type Inherent = Vec<AttestedCandidate>;
|
|
||||||
type Call = Call<T>;
|
type Call = Call<T>;
|
||||||
|
type Error = MakeFatalError<RuntimeString>;
|
||||||
|
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
|
||||||
|
|
||||||
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)> {
|
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||||
vec![(T::SET_POSITION, Call::set_heads(data))]
|
let data = data.get_data::<InherentType>(&INHERENT_IDENTIFIER)
|
||||||
}
|
.expect("Parachain heads could not be decoded.")
|
||||||
|
.expect("No parachain heads found in inherent data.");
|
||||||
|
|
||||||
fn check_inherent<Block: BlockT, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
|
Some(Call::set_heads(data))
|
||||||
block: &Block, _data: Self::Inherent, extract_function: &F
|
|
||||||
) -> ::rstd::result::Result<(), CheckInherentError> {
|
|
||||||
let has_heads = block
|
|
||||||
.extrinsics()
|
|
||||||
.get(T::SET_POSITION as usize)
|
|
||||||
.map_or(false, |xt| {
|
|
||||||
xt.is_signed() == Some(false) && match extract_function(&xt) {
|
|
||||||
Some(Call::set_heads(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if !has_heads {
|
|
||||||
return Err(CheckInherentError::Other(
|
|
||||||
"No valid parachains inherent in block".into()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +405,6 @@ mod tests {
|
|||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub struct Test;
|
pub struct Test;
|
||||||
impl consensus::Trait for Test {
|
impl consensus::Trait for Test {
|
||||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
|
||||||
type SessionKey = SessionKey;
|
type SessionKey = SessionKey;
|
||||||
type InherentOfflineReport = ();
|
type InherentOfflineReport = ();
|
||||||
type Log = ::Log;
|
type Log = ::Log;
|
||||||
@@ -451,13 +428,10 @@ mod tests {
|
|||||||
type Event = ();
|
type Event = ();
|
||||||
}
|
}
|
||||||
impl timestamp::Trait for Test {
|
impl timestamp::Trait for Test {
|
||||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
|
||||||
type Moment = u64;
|
type Moment = u64;
|
||||||
type OnTimestampSet = ();
|
type OnTimestampSet = ();
|
||||||
}
|
}
|
||||||
impl Trait for Test {
|
impl Trait for Test {}
|
||||||
const SET_POSITION: u32 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Parachains = Module<Test>;
|
type Parachains = Module<Test>;
|
||||||
|
|
||||||
|
|||||||
Generated
+1378
-107
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,20 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "polkadot-runtime"
|
name = "polkadot-runtime-wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
name = "polkadot_runtime"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitvec = { version = "0.8", default-features = false, features = ["alloc"] }
|
polkadot-runtime = { path = "..", default-features = false }
|
||||||
integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git", branch = "master" }
|
|
||||||
polkadot-primitives = { path = "../../primitives", default-features = false }
|
[features]
|
||||||
safe-mix = { version = "1.0", default-features = false }
|
default = []
|
||||||
parity-codec = { version = "2.1", default-features = false }
|
std = [
|
||||||
parity-codec-derive = { version = "2.1", default-features = false }
|
"polkadot-runtime/std",
|
||||||
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
]
|
||||||
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false }
|
|
||||||
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
|
|
||||||
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-aura = { 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 }
|
|
||||||
srml-grandpa = { git = "https://github.com/paritytech/substrate", default-features = false }
|
|
||||||
srml-indices = { 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-sudo = { 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 }
|
|
||||||
srml-upgrade-key = { git = "https://github.com/paritytech/substrate", default-features = false }
|
|
||||||
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
|
|
||||||
libsecp256k1 = "0.2.1"
|
|
||||||
tiny-keccak = "1.4.2"
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cargo +nightly build --target=wasm32-unknown-unknown --release
|
if cargo --version | grep -q "nightly"; then
|
||||||
|
CARGO_CMD="cargo"
|
||||||
|
else
|
||||||
|
CARGO_CMD="cargo +nightly"
|
||||||
|
fi
|
||||||
|
$CARGO_CMD build --target=wasm32-unknown-unknown --release
|
||||||
for i in polkadot_runtime
|
for i in polkadot_runtime
|
||||||
do
|
do
|
||||||
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
|
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../src
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Polkadot.
|
||||||
|
|
||||||
|
// Substrate is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Substrate is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! The Polkadot runtime reexported for WebAssembly compile.
|
||||||
|
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
extern crate polkadot_runtime;
|
||||||
|
pub use polkadot_runtime::*;
|
||||||
BIN
Binary file not shown.
Binary file not shown.
@@ -25,4 +25,5 @@ substrate-consensus-aura = { git = "https://github.com/paritytech/substrate" }
|
|||||||
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate" }
|
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-service = { git = "https://github.com/paritytech/substrate" }
|
substrate-service = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-telemetry = { git = "https://github.com/paritytech/substrate" }
|
substrate-telemetry = { git = "https://github.com/paritytech/substrate" }
|
||||||
|
substrate-inherents = { git = "https://github.com/paritytech/substrate" }
|
||||||
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate" }
|
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate" }
|
||||||
|
|||||||
+36
-23
@@ -33,6 +33,7 @@ extern crate substrate_consensus_aura as aura;
|
|||||||
extern crate substrate_finality_grandpa as grandpa;
|
extern crate substrate_finality_grandpa as grandpa;
|
||||||
extern crate substrate_transaction_pool as transaction_pool;
|
extern crate substrate_transaction_pool as transaction_pool;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
extern crate substrate_inherents as inherents;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
@@ -43,13 +44,14 @@ pub mod chain_spec;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use polkadot_primitives::{parachain, AccountId, Block, InherentData};
|
use polkadot_primitives::{parachain, AccountId, Block};
|
||||||
use polkadot_runtime::{GenesisConfig, RuntimeApi};
|
use polkadot_runtime::{GenesisConfig, RuntimeApi};
|
||||||
use primitives::ed25519;
|
use primitives::ed25519;
|
||||||
use tokio::runtime::TaskExecutor;
|
use tokio::runtime::TaskExecutor;
|
||||||
use service::{FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor};
|
use service::{FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor};
|
||||||
use transaction_pool::txpool::{Pool as TransactionPool};
|
use transaction_pool::txpool::{Pool as TransactionPool};
|
||||||
use aura::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra, InherentProducingFn};
|
use aura::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
|
||||||
|
use inherents::InherentDataProviders;
|
||||||
|
|
||||||
pub use service::{
|
pub use service::{
|
||||||
Roles, PruningMode, TransactionPoolOptions, ComponentClient,
|
Roles, PruningMode, TransactionPoolOptions, ComponentClient,
|
||||||
@@ -68,7 +70,6 @@ pub use chain_spec::ChainSpec;
|
|||||||
pub type Configuration = FactoryFullConfiguration<Factory>;
|
pub type Configuration = FactoryFullConfiguration<Factory>;
|
||||||
|
|
||||||
/// Polkadot-specific configuration.
|
/// Polkadot-specific configuration.
|
||||||
#[derive(Default)]
|
|
||||||
pub struct CustomConfiguration {
|
pub struct CustomConfiguration {
|
||||||
/// Set to `Some` with a collator `AccountId` and desired parachain
|
/// Set to `Some` with a collator `AccountId` and desired parachain
|
||||||
/// if the network protocol should be started in collator mode.
|
/// if the network protocol should be started in collator mode.
|
||||||
@@ -81,6 +82,18 @@ pub struct CustomConfiguration {
|
|||||||
Arc<grandpa::BlockImportForService<Factory>>,
|
Arc<grandpa::BlockImportForService<Factory>>,
|
||||||
grandpa::LinkHalfForService<Factory>
|
grandpa::LinkHalfForService<Factory>
|
||||||
)>,
|
)>,
|
||||||
|
|
||||||
|
inherent_data_providers: InherentDataProviders,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CustomConfiguration {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
collating_for: None,
|
||||||
|
grandpa_import_setup: None,
|
||||||
|
inherent_data_providers: InherentDataProviders::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chain API type for the transaction pool.
|
/// Chain API type for the transaction pool.
|
||||||
@@ -139,14 +152,6 @@ impl PolkadotService for Service<LightComponents<Factory>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inherent_data_import_queue(timestamp: u64, slot: u64) -> InherentData {
|
|
||||||
InherentData {
|
|
||||||
parachains: Vec::new(),
|
|
||||||
timestamp,
|
|
||||||
aura_expected_slot: slot,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
construct_service_factory! {
|
construct_service_factory! {
|
||||||
struct Factory {
|
struct Factory {
|
||||||
Block = Block,
|
Block = Block,
|
||||||
@@ -220,6 +225,7 @@ construct_service_factory! {
|
|||||||
executor.clone(),
|
executor.clone(),
|
||||||
key.clone(),
|
key.clone(),
|
||||||
extrinsic_store,
|
extrinsic_store,
|
||||||
|
SlotDuration::get_or_compute(&*client)?,
|
||||||
);
|
);
|
||||||
|
|
||||||
info!("Using authority key {}", key.public());
|
info!("Using authority key {}", key.public());
|
||||||
@@ -231,7 +237,8 @@ construct_service_factory! {
|
|||||||
Arc::new(proposer_factory),
|
Arc::new(proposer_factory),
|
||||||
service.network(),
|
service.network(),
|
||||||
service.on_exit(),
|
service.on_exit(),
|
||||||
);
|
service.config.custom.inherent_data_providers.clone(),
|
||||||
|
)?;
|
||||||
|
|
||||||
executor.spawn(task);
|
executor.spawn(task);
|
||||||
Ok(service)
|
Ok(service)
|
||||||
@@ -240,39 +247,45 @@ construct_service_factory! {
|
|||||||
{ |config, executor| <LightComponents<Factory>>::new(config, executor) },
|
{ |config, executor| <LightComponents<Factory>>::new(config, executor) },
|
||||||
FullImportQueue = AuraImportQueue<
|
FullImportQueue = AuraImportQueue<
|
||||||
Self::Block,
|
Self::Block,
|
||||||
grandpa::BlockImportForService<Self>,
|
FullClient<Self>,
|
||||||
NothingExtra,
|
NothingExtra,
|
||||||
InherentProducingFn<InherentData>,
|
|
||||||
>
|
>
|
||||||
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
|
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
|
||||||
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
||||||
|
|
||||||
let (block_import, link_half) = grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>>(client.clone(), client)?;
|
let (block_import, link_half) =
|
||||||
|
grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>>(
|
||||||
|
client.clone(), client.clone(),
|
||||||
|
)?;
|
||||||
let block_import = Arc::new(block_import);
|
let block_import = Arc::new(block_import);
|
||||||
|
let justification_import = block_import.clone();
|
||||||
|
|
||||||
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
|
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
|
||||||
Ok(import_queue(
|
import_queue(
|
||||||
slot_duration,
|
slot_duration,
|
||||||
block_import,
|
block_import,
|
||||||
|
Some(justification_import),
|
||||||
|
client,
|
||||||
NothingExtra,
|
NothingExtra,
|
||||||
inherent_data_import_queue as _,
|
config.custom.inherent_data_providers.clone(),
|
||||||
))
|
).map_err(Into::into)
|
||||||
}},
|
}},
|
||||||
LightImportQueue = AuraImportQueue<
|
LightImportQueue = AuraImportQueue<
|
||||||
Self::Block,
|
Self::Block,
|
||||||
LightClient<Self>,
|
LightClient<Self>,
|
||||||
NothingExtra,
|
NothingExtra,
|
||||||
InherentProducingFn<InherentData>,
|
|
||||||
>
|
>
|
||||||
{ |config, client: Arc<LightClient<Self>>| {
|
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<LightClient<Self>>| {
|
||||||
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
||||||
|
|
||||||
Ok(import_queue(
|
import_queue(
|
||||||
slot_duration,
|
slot_duration,
|
||||||
|
client.clone(),
|
||||||
|
None,
|
||||||
client,
|
client,
|
||||||
NothingExtra,
|
NothingExtra,
|
||||||
inherent_data_import_queue as _,
|
config.custom.inherent_data_providers.clone(),
|
||||||
))
|
).map_err(Into::into)
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user