mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +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:
@@ -61,8 +61,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,
|
||||
warp_request_handler, ChainSync,
|
||||
block_request_handler::BlockRequestHandler, service::network::NetworkServiceProvider,
|
||||
state_request_handler::StateRequestHandler, warp_request_handler, ChainSync,
|
||||
};
|
||||
use sc_service::client::Client;
|
||||
use sp_blockchain::{
|
||||
@@ -864,6 +864,8 @@ where
|
||||
let block_announce_validator = config
|
||||
.block_announce_validator
|
||||
.unwrap_or_else(|| Box::new(DefaultBlockAnnounceValidator));
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
NetworkServiceProvider::new();
|
||||
let (chain_sync, chain_sync_service) = ChainSync::new(
|
||||
match network_config.sync_mode {
|
||||
SyncMode::Full => sc_network_common::sync::SyncMode::Full,
|
||||
@@ -878,6 +880,7 @@ where
|
||||
block_announce_validator,
|
||||
network_config.max_parallel_downloads,
|
||||
Some(warp_sync),
|
||||
chain_sync_network_handle,
|
||||
)
|
||||
.unwrap();
|
||||
let block_announce_config = chain_sync.get_block_announce_proto_config(
|
||||
@@ -915,6 +918,11 @@ where
|
||||
|
||||
trace!(target: "test_network", "Peer identifier: {}", network.service().local_peer_id());
|
||||
|
||||
let service = network.service().clone();
|
||||
async_std::task::spawn(async move {
|
||||
chain_sync_network_provider.run(service).await;
|
||||
});
|
||||
|
||||
self.mut_peers(move |peers| {
|
||||
for peer in peers.iter_mut() {
|
||||
peer.network
|
||||
|
||||
Reference in New Issue
Block a user