mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
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:
committed by
Robert Habermeier
parent
ac2b9168ac
commit
6d778c99d2
+65
-13
@@ -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 _))
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user