Commit ee0076f7 authored by thiolliere's avatar thiolliere Committed by asynchronous rob
Browse files

update substrate (#259)

* WIP

* merging select_chain

* WIP

* update to point to gui-polkadot-master

* Fix collator

* update gui-polkadot-master and fix

* fix unwraps

* better returning an error
parent d36f8521
This diff is collapsed.
......@@ -9,7 +9,7 @@ polkadot-primitives = { path = "../primitives" }
parking_lot = "0.7.1"
log = "0.4.6"
parity-codec = "3.0"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
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" }
......@@ -9,5 +9,5 @@ log = "0.4.6"
tokio = "0.1.7"
futures = "0.1.17"
exit-future = "0.1"
substrate-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-cli = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
polkadot-service = { path = "../service" }
......@@ -6,10 +6,11 @@ description = "Collator node implementation"
[dependencies]
futures = "0.1.17"
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
parity-codec = "3.0"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-consensus-authorities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-consensus-authorities = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-consensus-common= { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
polkadot-runtime = { path = "../runtime", version = "0.1" }
polkadot-primitives = { path = "../primitives", version = "0.1" }
polkadot-cli = { path = "../cli" }
......@@ -19,4 +20,4 @@ log = "0.4"
tokio = "0.1.7"
[dev-dependencies]
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
......@@ -49,6 +49,7 @@ extern crate substrate_client as client;
extern crate parity_codec as codec;
extern crate substrate_primitives as primitives;
extern crate substrate_consensus_authorities as consensus_authorities;
extern crate substrate_consensus_common as consensus_common;
extern crate tokio;
extern crate polkadot_cli;
......@@ -82,6 +83,7 @@ use polkadot_network::validation::{ValidationNetwork, SessionParams};
use polkadot_network::NetworkService;
use tokio::timer::Timeout;
use consensus_authorities::AuthoritiesApi;
use consensus_common::SelectChain;
pub use polkadot_cli::VersionInfo;
pub use polkadot_network::validation::Incoming;
......@@ -256,18 +258,24 @@ impl<P, E> Worker for CollationNode<P, E> where
let client = service.client();
let network = service.network();
let known_oracle = client.clone();
let select_chain = if let Some(select_chain) = service.select_chain() {
select_chain
} else {
info!("The node cannot work because it can't select chain.");
return Box::new(future::err(()));
};
let message_validator = polkadot_network::gossip::register_validator(
&*network,
move |block_hash: &Hash| {
use client::{BlockStatus, ChainHead};
use client::BlockStatus;
use polkadot_network::gossip::Known;
match known_oracle.block_status(&BlockId::hash(*block_hash)) {
Err(_) | Ok(BlockStatus::Unknown) | Ok(BlockStatus::Queued) => None,
Ok(BlockStatus::KnownBad) => Some(Known::Bad),
Ok(BlockStatus::InChainWithState) | Ok(BlockStatus::InChainPruned) =>
match known_oracle.leaves() {
match select_chain.leaves() {
Err(_) => None,
Ok(leaves) => if leaves.contains(block_hash) {
Some(Known::Leaf)
......
......@@ -8,5 +8,5 @@ edition = "2018"
polkadot-primitives = { path = "../primitives" }
reed-solomon-erasure = { git = "https://github.com/paritytech/reed-solomon-erasure" }
parity-codec = "3.0"
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
......@@ -5,6 +5,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
description = "Polkadot node implementation in Rust."
[dependencies]
substrate-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-executor = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
polkadot-runtime = { path = "../runtime" }
......@@ -12,9 +12,9 @@ polkadot-validation = { path = "../validation" }
polkadot-primitives = { path = "../primitives" }
parity-codec = "3.0"
parity-codec-derive = "3.0"
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
futures = "0.1"
tokio = "0.1.7"
log = "0.4"
......@@ -22,5 +22,5 @@ slice-group-by = "0.2.2"
exit-future = "0.1.4"
[dev-dependencies]
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
......@@ -27,10 +27,11 @@ use polkadot_primitives::parachain::{
ConsolidatedIngressRoots,
};
use substrate_primitives::crypto::UncheckedInto;
use sr_primitives::traits::Block as BlockT;
use codec::Encode;
use substrate_network::{
PeerId, PeerInfo, ClientHandle, Context, config::Roles,
message::{BlockRequest, generic::ConsensusMessage},
message::{BlockRequest, generic::{ConsensusMessage, FinalityProofRequest}},
specialization::NetworkSpecialization, generic_message::Message as GenericMessage
};
......@@ -47,10 +48,6 @@ struct TestContext {
}
impl Context<Block> for TestContext {
fn client(&self) -> &ClientHandle<Block> {
unimplemented!()
}
fn report_peer(&mut self, peer: PeerId, reputation: i32) {
let reputation = self.reputations.get(&peer).map_or(reputation, |v| v + reputation);
self.reputations.insert(peer.clone(), reputation);
......@@ -62,14 +59,6 @@ impl Context<Block> for TestContext {
}
}
fn peer_info(&self, _peer: &PeerId) -> Option<PeerInfo<Block>> {
unimplemented!()
}
fn send_block_request(&mut self, _who: PeerId, _request: BlockRequest<Block>) {
unimplemented!()
}
fn send_consensus(&mut self, _who: PeerId, _consensus: ConsensusMessage) {
unimplemented!()
}
......
......@@ -360,12 +360,12 @@ impl Knowledge {
// generated by valid execution.
match *statement {
GenericStatement::Candidate(ref c) => {
let mut entry = self.candidates.entry(c.hash()).or_insert_with(Default::default);
let entry = self.candidates.entry(c.hash()).or_insert_with(Default::default);
entry.knows_block_data.push(from.clone());
entry.knows_extrinsic.push(from);
}
GenericStatement::Valid(ref hash) => {
let mut entry = self.candidates.entry(*hash).or_insert_with(Default::default);
let entry = self.candidates.entry(*hash).or_insert_with(Default::default);
entry.knows_block_data.push(from.clone());
entry.knows_extrinsic.push(from);
}
......
......@@ -8,15 +8,15 @@ serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
polkadot-parachain = { path = "../parachain", default-features = false }
[dev-dependencies]
substrate-serializer = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-serializer = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
pretty_assertions = "0.5.1"
[features]
......
......@@ -13,39 +13,39 @@ safe-mix = { version = "1.0", default-features = false}
polkadot-primitives = { path = "../primitives", default-features = false }
parity-codec = { version = "3.0", default-features = false }
parity-codec-derive = { version = "3.0", default-features = false }
substrate-serializer = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-offchain-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-council = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-democracy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-grandpa = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-indices = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-consensus-authorities = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
substrate-serializer = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-offchain-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-council = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-democracy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-grandpa = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-indices = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
srml-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
sr-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
substrate-consensus-authorities = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "gui-polkadot-master" }
[dev-dependencies]
hex-literal = "0.1.0"
libsecp256k1 = "0.2.1"
tiny-keccak = "1.4.2"
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-keyring = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
trie-db = "0.12"
[features]
......
......@@ -302,7 +302,7 @@ pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Balances, AllModules>;
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Balances, Runtime, AllModules>;
impl_runtime_apis! {
impl client_api::Core<Block> for Runtime {
......
......@@ -36,7 +36,7 @@ use sr_primitives::{StorageOverlay, ChildrenStorageOverlay};
#[cfg(any(feature = "std", test))]
use rstd::marker::PhantomData;
use system::ensure_inherent;
use system::ensure_none;
pub trait Trait: session::Trait {}
......@@ -88,7 +88,7 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
/// Provide candidate receipts for parachains, in ascending order by id.
fn set_heads(origin, heads: Vec<AttestedCandidate>) -> Result {
ensure_inherent(origin)?;
ensure_none(origin)?;
ensure!(!<DidUpdate<T>>::exists(), "Parachain heads must be updated only once in the block");
let active_parachains = Self::active_parachains();
......@@ -710,7 +710,7 @@ mod tests {
};
assert!(Parachains::dispatch(Call::set_heads(vec![candidate]), Origin::INHERENT).is_err());
assert!(Parachains::dispatch(Call::set_heads(vec![candidate]), Origin::NONE).is_err());
})
}
......@@ -755,12 +755,12 @@ mod tests {
assert!(Parachains::dispatch(
Call::set_heads(vec![candidate_b.clone(), candidate_a.clone()]),
Origin::INHERENT,
Origin::NONE,
).is_err());
assert!(Parachains::dispatch(
Call::set_heads(vec![candidate_a.clone(), candidate_b.clone()]),
Origin::INHERENT,
Origin::NONE,
).is_ok());
});
}
......@@ -794,7 +794,7 @@ mod tests {
assert!(Parachains::dispatch(
Call::set_heads(vec![double_validity]),
Origin::INHERENT,
Origin::NONE,
).is_err());
});
}
......@@ -846,7 +846,7 @@ mod tests {
assert!(Parachains::dispatch(
Call::set_heads(vec![candidate_a, candidate_b]),
Origin::INHERENT,
Origin::NONE,
).is_ok());
assert_eq!(
......@@ -885,7 +885,7 @@ mod tests {
let result = Parachains::dispatch(
Call::set_heads(vec![candidate.clone()]),
Origin::INHERENT,
Origin::NONE,
);
assert_eq!(Err("Routing to non-existent parachain"), result);
......@@ -909,7 +909,7 @@ mod tests {
let result = Parachains::dispatch(
Call::set_heads(vec![candidate.clone()]),
Origin::INHERENT,
Origin::NONE,
);
assert_eq!(Err("Parachain routing to self"), result);
......@@ -933,7 +933,7 @@ mod tests {
let result = Parachains::dispatch(
Call::set_heads(vec![candidate.clone()]),
Origin::INHERENT,
Origin::NONE,
);
assert_eq!(Err("Egress routes out of order by ID"), result);
......@@ -957,7 +957,7 @@ mod tests {
let result = Parachains::dispatch(
Call::set_heads(vec![candidate.clone()]),
Origin::INHERENT,
Origin::NONE,
);
assert_eq!(Err("Empty trie root included"), result);
......
This diff is collapsed.
......@@ -17,14 +17,15 @@ polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" }
polkadot-executor = { path = "../executor" }
polkadot-network = { path = "../network" }
sr-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sr-io = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-primitives = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-client = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-consensus-common = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-inherents = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-service = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-telemetry = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
substrate-keystore = { git = "https://github.com/paritytech/substrate", branch = "gui-polkadot-master" }
......@@ -28,6 +28,7 @@ extern crate substrate_client as client;
#[macro_use]
extern crate substrate_service as service;
extern crate substrate_consensus_aura as aura;
extern crate substrate_consensus_common as consensus_common;
extern crate substrate_finality_grandpa as grandpa;
extern crate substrate_transaction_pool as transaction_pool;
extern crate substrate_telemetry as telemetry;
......@@ -41,6 +42,8 @@ extern crate hex_literal;
pub mod chain_spec;
use client::LongestChain;
use consensus_common::SelectChain;
use std::sync::Arc;
use std::time::Duration;
use polkadot_primitives::{parachain, Block, Hash, BlockId};
......@@ -111,6 +114,8 @@ pub trait PolkadotService {
/// Get a handle to the client.
fn client(&self) -> Arc<client::Client<Self::Backend, Self::Executor, Block, RuntimeApi>>;
fn select_chain(&self) -> Option<client::LongestChain<Self::Backend, Block>>;
/// Get a handle to the network.
fn network(&self) -> Arc<NetworkService>;
......@@ -125,6 +130,11 @@ impl PolkadotService for Service<FullComponents<Factory>> {
fn client(&self) -> Arc<client::Client<Self::Backend, Self::Executor, Block, RuntimeApi>> {
Service::client(self)
}
fn select_chain(&self) -> Option<client::LongestChain<Self::Backend, Block>> {
Service::select_chain(self)
}
fn network(&self) -> Arc<NetworkService> {
Service::network(self)
}
......@@ -142,6 +152,10 @@ impl PolkadotService for Service<LightComponents<Factory>> {
Service::client(self)
}
fn select_chain(&self) -> Option<client::LongestChain<Self::Backend, Block>> {
None
}
fn network(&self) -> Arc<NetworkService> {
Service::network(self)
}
......@@ -249,22 +263,31 @@ construct_service_factory! {
let client = service.client();
let known_oracle = client.clone();
let select_chain = if let Some(select_chain) = service.select_chain() {
select_chain
} else {
info!("The node cannot start as an authority because it can't select chain.");
return Ok(service);
};
let gossip_validator_select_chain = select_chain.clone();
let gossip_validator = network_gossip::register_validator(
&*service.network(),
move |block_hash: &Hash| {
use client::{BlockStatus, ChainHead};
use client::BlockStatus;
match known_oracle.block_status(&BlockId::hash(*block_hash)) {
Err(_) | Ok(BlockStatus::Unknown) | Ok(BlockStatus::Queued) => None,
Ok(BlockStatus::KnownBad) => Some(Known::Bad),
Ok(BlockStatus::InChainWithState) | Ok(BlockStatus::InChainPruned) => match known_oracle.leaves() {
Err(_) => None,
Ok(leaves) => if leaves.contains(block_hash) {
Some(Known::Leaf)
} else {
Some(Known::Old)
},
Ok(BlockStatus::InChainWithState) | Ok(BlockStatus::InChainPruned) => {
match gossip_validator_select_chain.leaves() {
Err(_) => None,
Ok(leaves) => if leaves.contains(block_hash) {
Some(Known::Leaf)
} else {
Some(Known::Old)
},
}
}
}
},
......@@ -280,6 +303,7 @@ construct_service_factory! {
);
let proposer_factory = ::consensus::ProposerFactory::new(
client.clone(),
select_chain.clone(),
validation_network.clone(),
validation_network,
service.transaction_pool(),
......@@ -294,6 +318,7 @@ construct_service_factory! {
SlotDuration::get_or_compute(&*client)?,
key,
client.clone(),
select_chain,
block_import,
Arc::new(proposer_factory),
service.network(),
......@@ -310,10 +335,13 @@ construct_service_factory! {
FullImportQueue = AuraImportQueue<
Self::Block,
>
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>, select_chain: Self::SelectChain| {
let slot_duration = SlotDuration::get_or_compute(&*client)?;
let (block_import, link_half) = grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>>(client.clone(), client.clone())?;
let (block_import, link_half) =
grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>, _>(
client.clone(), client.clone(), select_chain
)?;
let block_import = Arc::new(block_import);
let justification_import = block_import.clone();
......@@ -322,6 +350,8 @@ construct_service_factory! {
slot_duration,
block_import,
Some(justification_import),
None,
None,
client,
NothingExtra,
config.custom.inherent_data_providers.clone(),
......@@ -331,16 +361,38 @@ construct_service_factory! {
Self::Block,
>
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<LightClient<Self>>| {
let slot_duration = SlotDuration::get_or_compute(&*client)?;
let fetch_checker = client.backend().blockchain().fetcher()
.upgrade()
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, LightClient<Self>>(
client.clone(), Arc::new(fetch_checker), client.clone()
)?;
let block_import = Arc::new(block_import);
let finality_proof_import = block_import.clone();
let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder();
import_queue::<_, _, _, ed25519::Pair>(
slot_duration,
client.clone(),
SlotDuration::get_or_compute(&*client)?,
block_import,
None,
Some(finality_proof_import),
Some(finality_proof_request_builder),
client,
NothingExtra,
config.custom.inherent_data_providers.clone(),
).map_err(Into::into)
}},
SelectChain = LongestChain<FullBackend<Self>, Self::Block>
{ |config: &FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
Ok(LongestChain::new(
client.backend().clone(),
client.import_lock()
))
}
},
FinalityProofProvider = { |client: Arc<FullClient<Self>>| {
Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _))
}},
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment