mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 02:21:14 +00:00
Light GRANDPA import handler (#1669)
* GrandpaLightBlockImport * extract authorities in AuraVerifier * post-merge fix * restore authorities cache * license * new finality proof draft * generalized PendingJustifications * finality proof messages * fixed compilation * pass verifier to import_finality_proof * do not fetch remote proof from light import directly * FinalityProofProvider * fixed authorities cache test * restored finality proof tests * finality_proof docs * use DB backend in test client * justification_is_fetched_by_light_client_when_consensus_data_changes * restore justification_is_fetched_by_light_client_when_consensus_data_changes * some more tests * added authorities-related TODO * removed unneeded clear_finality_proof_requests field * truncated some long lines * more granular light import tests * only provide finality proof if it is generated by the requested set * post-merge fix * finality_proof_is_none_if_first_justification_is_generated_by_unknown_set * make light+grandpa test rely on finality proofs (instead of simple justifications) * empty_finality_proof_is_returned_to_light_client_when_authority_set_is_different * missing trait method impl * fixed proof-of-finality docs * one more doc fix * fix docs * initialize authorities cache (post-merge fix) * fixed cache initialization (post-merge fix) * post-fix merge: fix light + GRANDPA tests (bad way) * proper fix of empty_finality_proof_is_returned_to_light_client_when_authority_set_is_different * fixed easy grumbles * import finality proofs in BlockImportWorker thread * allow import of finality proofs for non-requested blocks * limit number of fragments in finality proof * GRANDPA post-merge fix * BABE: pos-merge fix
This commit is contained in:
committed by
Gavin Wood
parent
258f0835e4
commit
22586113ea
@@ -24,7 +24,7 @@ use client_db;
|
||||
use client::{self, Client, runtime_api};
|
||||
use crate::{error, Service, maybe_start_server};
|
||||
use consensus_common::{import_queue::ImportQueue, SelectChain};
|
||||
use network::{self, OnDemand};
|
||||
use network::{self, OnDemand, FinalityProofProvider};
|
||||
use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use transaction_pool::txpool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
||||
use runtime_primitives::{
|
||||
@@ -72,7 +72,7 @@ pub type LightExecutor<F> = client::light::call_executor::RemoteOrLocalCallExecu
|
||||
client_db::light::LightStorage<<F as ServiceFactory>::Block>,
|
||||
network::OnDemand<<F as ServiceFactory>::Block>
|
||||
>,
|
||||
network::OnDemand<<F as ServiceFactory>::Block>
|
||||
network::OnDemand<<F as ServiceFactory>::Block>,
|
||||
>,
|
||||
client::LocalCallExecutor<
|
||||
client::light::backend::Backend<
|
||||
@@ -322,6 +322,11 @@ pub trait ServiceFactory: 'static + Sized {
|
||||
fn build_network_protocol(config: &FactoryFullConfiguration<Self>)
|
||||
-> Result<Self::NetworkProtocol, error::Error>;
|
||||
|
||||
/// Build finality proof provider for serving network requests on full node.
|
||||
fn build_finality_proof_provider(
|
||||
client: Arc<FullClient<Self>>
|
||||
) -> Result<Option<Arc<FinalityProofProvider<Self::Block>>>, error::Error>;
|
||||
|
||||
/// Build the Fork Choice algorithm for full client
|
||||
fn build_select_chain(
|
||||
config: &mut FactoryFullConfiguration<Self>,
|
||||
@@ -413,12 +418,16 @@ pub trait Components: Sized + 'static {
|
||||
select_chain: Self::SelectChain,
|
||||
) -> Result<Self::ImportQueue, error::Error>;
|
||||
|
||||
/// Finality proof provider for serving network requests.
|
||||
fn build_finality_proof_provider(
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<Option<Arc<FinalityProofProvider<<Self::Factory as ServiceFactory>::Block>>>, error::Error>;
|
||||
|
||||
/// Build fork choice selector
|
||||
fn build_select_chain(
|
||||
config: &mut FactoryFullConfiguration<Self::Factory>,
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<Self::SelectChain, error::Error>;
|
||||
|
||||
}
|
||||
|
||||
/// A struct that implement `Components` for the full client.
|
||||
@@ -508,7 +517,12 @@ impl<Factory: ServiceFactory> Components for FullComponents<Factory> {
|
||||
) -> Result<Self::SelectChain, error::Error> {
|
||||
Self::Factory::build_select_chain(config, client)
|
||||
}
|
||||
|
||||
|
||||
fn build_finality_proof_provider(
|
||||
client: Arc<ComponentClient<Self>>
|
||||
) -> Result<Option<Arc<FinalityProofProvider<<Self::Factory as ServiceFactory>::Block>>>, error::Error> {
|
||||
Factory::build_finality_proof_provider(client)
|
||||
}
|
||||
}
|
||||
|
||||
/// A struct that implement `Components` for the light client.
|
||||
@@ -587,14 +601,17 @@ impl<Factory: ServiceFactory> Components for LightComponents<Factory> {
|
||||
Factory::build_light_import_queue(config, client)
|
||||
}
|
||||
|
||||
/// Build fork choice selector
|
||||
fn build_finality_proof_provider(
|
||||
_client: Arc<ComponentClient<Self>>
|
||||
) -> Result<Option<Arc<FinalityProofProvider<<Self::Factory as ServiceFactory>::Block>>>, error::Error> {
|
||||
Ok(None)
|
||||
}
|
||||
fn build_select_chain(
|
||||
_config: &mut FactoryFullConfiguration<Self::Factory>,
|
||||
_client: Arc<ComponentClient<Self>>
|
||||
) -> Result<Self::SelectChain, error::Error> {
|
||||
Err("Fork choice doesn't happen on light clients.".into())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -65,7 +65,7 @@ use components::{StartRPC, MaintainTransactionPool, OffchainWorker};
|
||||
#[doc(hidden)]
|
||||
pub use std::{ops::Deref, result::Result, sync::Arc};
|
||||
#[doc(hidden)]
|
||||
pub use network::OnDemand;
|
||||
pub use network::{FinalityProofProvider, OnDemand};
|
||||
#[doc(hidden)]
|
||||
pub use tokio::runtime::TaskExecutor;
|
||||
|
||||
@@ -156,8 +156,9 @@ impl<Components: components::Components> Service<Components> {
|
||||
let import_queue = Box::new(Components::build_import_queue(
|
||||
&mut config,
|
||||
client.clone(),
|
||||
select_chain.clone()
|
||||
select_chain.clone(),
|
||||
)?);
|
||||
let finality_proof_provider = Components::build_finality_proof_provider(client.clone())?;
|
||||
let best_header = select_chain.best_chain()?;
|
||||
|
||||
let version = config.full_version();
|
||||
@@ -178,6 +179,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
config: network::config::ProtocolConfig { roles: config.roles },
|
||||
network_config: config.network.clone(),
|
||||
chain: client.clone(),
|
||||
finality_proof_provider,
|
||||
on_demand: on_demand.as_ref().map(|d| d.clone() as _),
|
||||
transaction_pool: transaction_pool_adapter.clone() as _,
|
||||
specialization: network_protocol,
|
||||
@@ -593,6 +595,7 @@ macro_rules! construct_service_factory {
|
||||
{ $( $light_import_queue_init:tt )* },
|
||||
SelectChain = $select_chain:ty
|
||||
{ $( $select_chain_init:tt )* },
|
||||
FinalityProofProvider = { $( $finality_proof_provider_init:tt )* },
|
||||
}
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
@@ -658,6 +661,12 @@ macro_rules! construct_service_factory {
|
||||
( $( $light_import_queue_init )* ) (config, client)
|
||||
}
|
||||
|
||||
fn build_finality_proof_provider(
|
||||
client: Arc<$crate::FullClient<Self>>
|
||||
) -> Result<Option<Arc<$crate::FinalityProofProvider<Self::Block>>>, $crate::Error> {
|
||||
( $( $finality_proof_provider_init )* ) (client)
|
||||
}
|
||||
|
||||
fn new_light(
|
||||
config: $crate::FactoryFullConfiguration<Self>,
|
||||
executor: $crate::TaskExecutor
|
||||
|
||||
Reference in New Issue
Block a user