mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
Make NetworkService callable for ChainSync (#12542)
Introduce a middleware called `NetworkServiceProvider` which the `ChainSync` can use to communicate with `NetworkService`. `ChainSync` is given a `NetworkServiceHandle` which it uses to call `NetworkServiceProvider` which then dispatches the calls to `NetworkService` on behalf of `ChainSync`. This change will allow `ChainSync` to disconnect and report peers and in the future it'll be possible to send requests and notifications through the `NetworkServiceProvider`. `NetworkServiceProvider` is needed only until the `ChainSync` object has been removed from `Protocol`. After that, a normal `NetworkService` handle can be passed onto `ChainSync` and these changes can be deprecated. Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -46,7 +46,8 @@ use sc_network_common::{
|
||||
};
|
||||
use sc_network_light::light_client_requests::handler::LightClientRequestHandler;
|
||||
use sc_network_sync::{
|
||||
block_request_handler::BlockRequestHandler, state_request_handler::StateRequestHandler,
|
||||
block_request_handler::BlockRequestHandler, service::network::NetworkServiceProvider,
|
||||
state_request_handler::StateRequestHandler,
|
||||
warp_request_handler::RequestHandler as WarpSyncRequestHandler, ChainSync,
|
||||
};
|
||||
use sc_rpc::{
|
||||
@@ -844,6 +845,7 @@ where
|
||||
protocol_config
|
||||
};
|
||||
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) = NetworkServiceProvider::new();
|
||||
let (chain_sync, chain_sync_service) = ChainSync::new(
|
||||
match config.network.sync_mode {
|
||||
SyncMode::Full => sc_network_common::sync::SyncMode::Full,
|
||||
@@ -855,7 +857,9 @@ where
|
||||
block_announce_validator,
|
||||
config.network.max_parallel_downloads,
|
||||
warp_sync_provider,
|
||||
chain_sync_network_handle,
|
||||
)?;
|
||||
|
||||
let block_announce_config = chain_sync.get_block_announce_proto_config(
|
||||
protocol_id.clone(),
|
||||
&config.chain_spec.fork_id().map(ToOwned::to_owned),
|
||||
@@ -926,7 +930,13 @@ where
|
||||
Arc::new(TransactionPoolAdapter { pool: transaction_pool, client: client.clone() }),
|
||||
config.prometheus_config.as_ref().map(|config| &config.registry),
|
||||
)?;
|
||||
|
||||
spawn_handle.spawn("network-transactions-handler", Some("networking"), tx_handler.run());
|
||||
spawn_handle.spawn(
|
||||
"chain-sync-network-service-provider",
|
||||
Some("networking"),
|
||||
chain_sync_network_provider.run(network.clone()),
|
||||
);
|
||||
|
||||
let (system_rpc_tx, system_rpc_rx) = tracing_unbounded("mpsc_system_rpc");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user