mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Extract syncing protocol from sc-network (#12828)
* Move import queue out of `sc-network` Add supplementary asynchronous API for the import queue which means it can be run as an independent task and communicated with through the `ImportQueueService`. This commit removes removes block and justification imports from `sc-network` and provides `ChainSync` with a handle to import queue so it can import blocks and justifications. Polling of the import queue is moved complete out of `sc-network` and `sc_consensus::Link` is implemented for `ChainSyncInterfaceHandled` so the import queue can still influence the syncing process. * Move stuff to SyncingEngine * Move `ChainSync` instanation to `SyncingEngine` Some of the tests have to be rewritten * Move peer hashmap to `SyncingEngine` * Let `SyncingEngine` to implement `ChainSyncInterface` * Introduce `SyncStatusProvider` * Move `sync_peer_(connected|disconnected)` to `SyncingEngine` * Implement `SyncEventStream` Remove `SyncConnected`/`SyncDisconnected` events from `NetworkEvenStream` and provide those events through `ChainSyncInterface` instead. Modify BEEFY/GRANDPA/transactions protocol and `NetworkGossip` to take `SyncEventStream` object which they listen to for incoming sync peer events. * Introduce `ChainSyncInterface` This interface provides a set of miscellaneous functions that other subsystems can use to query, for example, the syncing status. * Move event stream polling to `SyncingEngine` Subscribe to `NetworkStreamEvent` and poll the incoming notifications and substream events from `SyncingEngine`. The code needs refactoring. * Make `SyncingEngine` into an asynchronous runner This commits removes the last hard dependency of syncing from `sc-network` meaning the protocol now lives completely outside of `sc-network`, ignoring the hardcoded peerset entry which will be addressed in the future. Code needs a lot of refactoring. * Fix warnings * Code refactoring * Use `SyncingService` for BEEFY * Use `SyncingService` for GRANDPA * Remove call delegation from `NetworkService` * Remove `ChainSyncService` * Remove `ChainSync` service tests They were written for the sole purpose of verifying that `NetworWorker` continues to function while the calls are being dispatched to `ChainSync`. * Refactor code * Refactor code * Update client/finality-grandpa/src/communication/tests.rs Co-authored-by: Anton <anton.kalyaev@gmail.com> * Fix warnings * Apply review comments * Fix docs * Fix test * cargo-fmt * Update client/network/sync/src/engine.rs Co-authored-by: Anton <anton.kalyaev@gmail.com> * Update client/network/sync/src/engine.rs Co-authored-by: Anton <anton.kalyaev@gmail.com> * Add missing docs * Refactor code --------- Co-authored-by: Anton <anton.kalyaev@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ use sc_network_common::{
|
||||
service::NetworkStatus,
|
||||
sync::{
|
||||
warp::{WarpSyncPhase, WarpSyncProgress},
|
||||
SyncState,
|
||||
SyncState, SyncStatus,
|
||||
},
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Saturating, Zero};
|
||||
@@ -69,7 +69,12 @@ impl<B: BlockT> InformantDisplay<B> {
|
||||
}
|
||||
|
||||
/// Displays the informant by calling `info!`.
|
||||
pub fn display(&mut self, info: &ClientInfo<B>, net_status: NetworkStatus<B>) {
|
||||
pub fn display(
|
||||
&mut self,
|
||||
info: &ClientInfo<B>,
|
||||
net_status: NetworkStatus,
|
||||
sync_status: SyncStatus<B>,
|
||||
) {
|
||||
let best_number = info.chain.best_number;
|
||||
let best_hash = info.chain.best_hash;
|
||||
let finalized_number = info.chain.finalized_number;
|
||||
@@ -94,7 +99,7 @@ impl<B: BlockT> InformantDisplay<B> {
|
||||
};
|
||||
|
||||
let (level, status, target) =
|
||||
match (net_status.sync_state, net_status.state_sync, net_status.warp_sync) {
|
||||
match (sync_status.state, sync_status.state_sync, sync_status.warp_sync) {
|
||||
(
|
||||
_,
|
||||
_,
|
||||
|
||||
@@ -23,7 +23,7 @@ use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use log::{debug, info, trace};
|
||||
use sc_client_api::{BlockchainEvents, UsageProvider};
|
||||
use sc_network_common::service::NetworkStatusProvider;
|
||||
use sc_network_common::{service::NetworkStatusProvider, sync::SyncStatusProvider};
|
||||
use sp_blockchain::HeaderMetadata;
|
||||
use sp_runtime::traits::{Block as BlockT, Header};
|
||||
use std::{collections::VecDeque, fmt::Display, sync::Arc, time::Duration};
|
||||
@@ -51,9 +51,10 @@ impl Default for OutputFormat {
|
||||
}
|
||||
|
||||
/// Builds the informant and returns a `Future` that drives the informant.
|
||||
pub async fn build<B: BlockT, C, N>(client: Arc<C>, network: N, format: OutputFormat)
|
||||
pub async fn build<B: BlockT, C, N, S>(client: Arc<C>, network: N, syncing: S, format: OutputFormat)
|
||||
where
|
||||
N: NetworkStatusProvider<B>,
|
||||
N: NetworkStatusProvider,
|
||||
S: SyncStatusProvider<B>,
|
||||
C: UsageProvider<B> + HeaderMetadata<B> + BlockchainEvents<B>,
|
||||
<C as HeaderMetadata<B>>::Error: Display,
|
||||
{
|
||||
@@ -63,10 +64,15 @@ where
|
||||
|
||||
let display_notifications = interval(Duration::from_millis(5000))
|
||||
.filter_map(|_| async {
|
||||
let status = network.status().await;
|
||||
status.ok()
|
||||
let net_status = network.status().await;
|
||||
let sync_status = syncing.status().await;
|
||||
|
||||
match (net_status.ok(), sync_status.ok()) {
|
||||
(Some(net), Some(sync)) => Some((net, sync)),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.for_each(move |net_status| {
|
||||
.for_each(move |(net_status, sync_status)| {
|
||||
let info = client_1.usage_info();
|
||||
if let Some(ref usage) = info.usage {
|
||||
trace!(target: "usage", "Usage statistics: {}", usage);
|
||||
@@ -76,7 +82,7 @@ where
|
||||
"Usage statistics not displayed as backend does not provide it",
|
||||
)
|
||||
}
|
||||
display.display(&info, net_status);
|
||||
display.display(&info, net_status, sync_status);
|
||||
future::ready(())
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user