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:
Bastian Köcher
2019-01-27 15:21:25 +01:00
committed by Gav Wood
parent 1514ee9192
commit 2b0dbd2d77
19 changed files with 2273 additions and 984 deletions
@@ -33,7 +33,7 @@ use client::blockchain::HeaderBackend;
use client::runtime_api::Core;
use primitives::ed25519;
use futures::prelude::*;
use polkadot_primitives::{Block, BlockId, InherentData};
use polkadot_primitives::{Block, BlockId};
use polkadot_primitives::parachain::ParachainHost;
use extrinsic_store::Store as ExtrinsicStore;
use runtime_primitives::traits::ProvideRuntimeApi;
@@ -122,7 +122,7 @@ pub(crate) fn start<C, N, P>(
<C::Collation as IntoFuture>::Future: Send + 'static,
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
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::TableRouter: Send + 'static,
{
+42 -31
View File
@@ -38,7 +38,6 @@ extern crate polkadot_primitives;
extern crate parity_codec as codec;
extern crate substrate_primitives as primitives;
extern crate srml_support as runtime_support;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_client as client;
extern crate substrate_trie as trie;
@@ -46,9 +45,11 @@ extern crate substrate_trie as trie;
extern crate exit_future;
extern crate tokio;
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_transaction_pool as transaction_pool;
extern crate substrate_inherents as inherents;
extern crate srml_aura as runtime_aura;
#[macro_use]
extern crate error_chain;
@@ -73,27 +74,35 @@ use client::runtime_api::Core;
use codec::Encode;
use extrinsic_store::Store as ExtrinsicStore;
use parking_lot::Mutex;
use polkadot_primitives::{
Hash, Block, BlockId, BlockNumber, Header, SessionKey, InherentData
use polkadot_primitives::{Hash, Block, BlockId, BlockNumber, Header, SessionKey};
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 runtime_primitives::traits::ProvideRuntimeApi;
use tokio::runtime::TaskExecutor;
use tokio::timer::{Delay, Interval};
use transaction_pool::txpool::{Pool, ChainApi as PoolChainApi};
use aura_primitives::AuraConsensusData;
use attestation_service::ServiceHandle;
use futures::prelude::*;
use futures::future::{self, Either};
use collation::CollationFetch;
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::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 dynamic_inclusion;
@@ -231,7 +240,7 @@ impl<C, N, P> ParachainConsensus<C, N, P> where
C: Collators + Send + 'static,
N: Network,
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,
N::TableRouter: Send + 'static,
{
@@ -325,6 +334,7 @@ pub struct ProposerFactory<C, N, P, TxApi: PoolChainApi> {
transaction_pool: Arc<Pool<TxApi>>,
key: Arc<ed25519::Pair>,
_service_handle: ServiceHandle,
aura_slot_duration: SlotDuration,
}
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,
P: BlockchainEvents<Block> + ChainHead<Block> + BlockBody<Block>,
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::TableRouter: Send + 'static,
TxApi: PoolChainApi,
@@ -346,6 +356,7 @@ impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
thread_pool: TaskExecutor,
key: Arc<ed25519::Pair>,
extrinsic_store: ExtrinsicStore,
aura_slot_duration: SlotDuration,
) -> Self {
let parachain_consensus = Arc::new(ParachainConsensus {
client: client.clone(),
@@ -369,16 +380,17 @@ impl<C, N, P, TxApi> ProposerFactory<C, N, P, TxApi> where
transaction_pool,
key,
_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,
N: Network,
TxApi: PoolChainApi<Block=Block>,
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,
N::TableRouter: Send + 'static,
{
@@ -406,6 +418,7 @@ impl<C, N, P, TxApi> consensus::Environment<Block, AuraConsensusData> for Propos
parent_id,
parent_number: parent_header.number,
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,
tracker: Arc<AttestationTracker>,
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>,
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
C::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
C::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
{
type Error = Error;
type Create = Either<
CreateProposal<C, TxApi>,
future::FutureResult<Block, Error>,
>;
type Create = Either<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 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(
self.tracker.table.num_parachains(),
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(
@@ -514,7 +525,10 @@ impl<C, TxApi> consensus::Proposer<Block, AuraConsensusData> for Proposer<C, TxA
initial_included,
).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.
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(),
table: self.tracker.table.clone(),
believed_minimum_timestamp: believed_timestamp,
consensus_data,
timing,
inherent_data: Some(inherent_data),
})
}
}
@@ -611,25 +625,22 @@ pub struct CreateProposal<C: Send + Sync, TxApi: PoolChainApi> {
table: Arc<SharedTable>,
timing: ProposalTiming,
believed_minimum_timestamp: u64,
consensus_data: AuraConsensusData,
inherent_data: Option<InherentData>,
}
impl<C, TxApi> CreateProposal<C, TxApi> where
TxApi: PoolChainApi<Block=Block>,
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 runtime_primitives::traits::{Hash as HashT, BlakeTwo256};
const MAX_TRANSACTIONS: usize = 40;
let inherent_data = InherentData {
timestamp: self.believed_minimum_timestamp,
parachains: candidates,
aura_expected_slot: self.consensus_data.slot,
};
let mut inherent_data = self.inherent_data.take().expect("CreateProposal is not polled after finishing; qed");
inherent_data.put_data(polkadot_runtime::PARACHAIN_INHERENT_IDENTIFIER, &candidates).map_err(ErrorKind::InherentError)?;
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
TxApi: PoolChainApi<Block=Block>,
C: ProvideRuntimeApi + HeaderBackend<Block> + Send + Sync,
C::Api: ParachainHost<Block> + BlockBuilderApi<Block, InherentData>,
C::Api: ParachainHost<Block> + BlockBuilderApi<Block>,
{
type Item = Block;
type Error = Error;