Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
updating to latest substrate v0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Feb 21, 2019
1 parent 05a7b52 commit 3798772
Show file tree
Hide file tree
Showing 24 changed files with 1,122 additions and 890 deletions.
1,395 changes: 812 additions & 583 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions availability-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ authors = ["Parity Technologies <admin@parity.io>"]
polkadot-primitives = { path = "../primitives" }
parking_lot = "0.4"
log = "0.3"
parity-codec = "2.1"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
parity-codec = "3.0"
parity-codec-derive = "3.0"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="616b40150ded71f57f650067fcbc5c99d7c343e6" }
3 changes: 1 addition & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ log = "0.3"
tokio = "0.1.7"
futures = "0.1.17"
exit-future = "0.1"
substrate-cli = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-cli = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
polkadot-service = { path = "../service" }
structopt = "0.2.13"
53 changes: 21 additions & 32 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern crate tokio;
extern crate substrate_cli as cli;
extern crate polkadot_service as service;
extern crate exit_future;
extern crate structopt;

#[macro_use]
extern crate log;
Expand All @@ -36,15 +35,14 @@ use std::ops::Deref;
use chain_spec::ChainSpec;
use futures::Future;
use tokio::runtime::Runtime;
use structopt::StructOpt;
use service::Service as BareService;

pub use service::{
Components as ServiceComponents, PolkadotService, CustomConfiguration, ServiceFactory, Factory,
ProvideRuntimeApi, CoreApi, ParachainHost,
};

pub use cli::{VersionInfo, IntoExit};
pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::error;

fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Expand Down Expand Up @@ -85,42 +83,33 @@ pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Res
T: Into<std::ffi::OsString> + Clone,
W: Worker,
{
let full_version = polkadot_service::full_version_from_strs(
version.version,
version.commit
);

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");
cli::parse_and_execute::<service::Factory, NoCustom, NoCustom, _, _, _, _, _>(
load_spec, &version, "parity-polkadot", args, worker,
|worker, _custom_args, mut config| {
info!("{}", version.name);
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!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);
config.custom = worker.configuration();
let mut runtime = Runtime::new()?;
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
let executor = runtime.executor();
match config.roles == service::Roles::LIGHT {
true => run_until_exit(runtime, Factory::new_light(config, executor)?, worker)?,
false => run_until_exit(runtime, Factory::new_full(config, executor)?, worker)?,
}
match config.roles {
service::Roles::LIGHT =>
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))
}
}
Ok(())
).map_err(Into::into).map(|_| ())
}

fn run_until_exit<T, C, W>(
Expand Down
4 changes: 2 additions & 2 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ description = "Collator node implementation"

[dependencies]
futures = "0.1.17"
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
parity-codec = "2.1"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
polkadot-runtime = { path = "../runtime", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" }
Expand Down
23 changes: 13 additions & 10 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ tokio = "0.1.7"
error-chain = "0.12"
log = "0.3"
exit-future = "0.1"
parity-codec = "2.1"
parity-codec = "3.0"
polkadot-availability-store = { path = "../availability-store" }
polkadot-parachain = { path = "../parachain" }
polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" }
polkadot-statement-table = { path = "../statement-table" }
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
srml-support = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-inherents = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
srml-aura = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
srml-support = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }

[dev-dependencies]
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "alexander-backports" }
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "v0.10" }
4 changes: 2 additions & 2 deletions consensus/src/attestation_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
{
Expand Down
59 changes: 38 additions & 21 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ extern crate polkadot_runtime;
extern crate polkadot_primitives;

extern crate parity_codec as codec;
extern crate substrate_inherents as inherents;
extern crate substrate_primitives as primitives;
extern crate srml_aura as runtime_aura;
extern crate srml_support as runtime_support;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_client as client;

extern crate exit_future;
extern crate tokio;
extern crate substrate_consensus_common as consensus;
extern crate substrate_consensus_aura as aura;
extern crate substrate_consensus_aura_primitives as aura_primitives;
extern crate substrate_finality_grandpa as grandpa;
extern crate substrate_transaction_pool as transaction_pool;
Expand All @@ -65,6 +68,7 @@ use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use std::time::{self, Duration, Instant};

use aura::SlotDuration;
use client::{BlockchainEvents, ChainHead, BlockBody};
use client::blockchain::HeaderBackend;
use client::block_builder::api::BlockBuilder as BlockBuilderApi;
Expand All @@ -73,7 +77,7 @@ use codec::Encode;
use extrinsic_store::Store as ExtrinsicStore;
use parking_lot::Mutex;
use polkadot_primitives::{
Hash, Block, BlockId, BlockNumber, Header, SessionKey, InherentData
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};
Expand All @@ -82,13 +86,14 @@ 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;

pub use self::collation::{validate_collation, Collators};
pub use self::error::{ErrorKind, Error};
Expand Down Expand Up @@ -256,7 +261,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,
{
Expand Down Expand Up @@ -350,14 +355,15 @@ 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
C: Collators + Send + Sync + 'static,
<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,
Expand All @@ -371,6 +377,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(),
Expand All @@ -394,16 +401,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,
{
Expand Down Expand Up @@ -431,6 +439,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,
})
}
}
Expand Down Expand Up @@ -505,20 +514,21 @@ 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>,
>;

fn propose(&self, consensus_data: AuraConsensusData) -> Self::Create {
fn propose(&self, inherent_data: InherentData, max_duration: Duration) -> 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.

Expand All @@ -528,15 +538,18 @@ 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(
now,
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();
Expand Down Expand Up @@ -564,8 +577,10 @@ 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),
// leave some time for the proposal finalisation
deadline: Instant::now() + max_duration - max_duration / 3,
})
}
}
Expand Down Expand Up @@ -633,25 +648,23 @@ pub struct CreateProposal<C: Send + Sync, TxApi: PoolChainApi> {
table: Arc<SharedTable>,
timing: ProposalTiming,
believed_minimum_timestamp: u64,
consensus_data: AuraConsensusData,
inherent_data: Option<InherentData>,
deadline: Instant,
}

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();

Expand All @@ -672,6 +685,10 @@ impl<C, TxApi> CreateProposal<C, TxApi> where
if pending_size + encoded_size >= MAX_TRANSACTIONS_SIZE {
break
}
if Instant::now() > self.deadline {
debug!("Consensus deadline reached when pushing block transactions, proceeding with proposing.");
break;
}

match block_builder.push(ready.data.clone()) {
Ok(()) => {
Expand Down Expand Up @@ -716,7 +733,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;
Expand Down
Loading

0 comments on commit 3798772

Please sign in to comment.