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
This commit is contained in:
thiolliere
2019-05-15 20:35:27 +02:00
committed by Robert Habermeier
parent ac2b9168ac
commit 6d778c99d2
25 changed files with 1005 additions and 943 deletions
+12 -11
View File
@@ -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" }
+65 -13
View File
@@ -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 _))
}},
}
}