Move bitswap to its own crate (#12242)

* Introduce `sc-network-bitswap`

Move the bitswap protocol out of `sc-network` to its own crate.

* Improve test coverage

* Remove mention of bitswap from `sc-network`

* Fix documentation

* Fix clippy and remove the void dependency

* Remove unneeded trait bound and bump prost to 0.11
This commit is contained in:
Aaro Altonen
2022-09-13 11:02:31 +03:00
committed by GitHub
parent b74e584e02
commit b494167d16
17 changed files with 708 additions and 494 deletions
+15 -2
View File
@@ -37,7 +37,8 @@ use sc_client_db::{Backend, DatabaseSettings};
use sc_consensus::import_queue::ImportQueue;
use sc_executor::RuntimeVersionOf;
use sc_keystore::LocalKeystore;
use sc_network::{bitswap::Bitswap, config::SyncMode, NetworkService};
use sc_network::{config::SyncMode, NetworkService};
use sc_network_bitswap::BitswapRequestHandler;
use sc_network_common::{
service::{NetworkStateInfo, NetworkStatusProvider, NetworkTransaction},
sync::warp::WarpSyncProvider,
@@ -746,6 +747,8 @@ where
warp_sync,
} = params;
let mut request_response_protocol_configs = Vec::new();
if warp_sync.is_none() && config.network.sync_mode.is_warp() {
return Err("Warp sync enabled, but no warp sync provider configured.".into())
}
@@ -835,6 +838,13 @@ where
config.network.max_parallel_downloads,
warp_sync_provider,
)?;
request_response_protocol_configs.push(config.network.ipfs_server.then(|| {
let (handler, protocol_config) = BitswapRequestHandler::new(client.clone());
spawn_handle.spawn("bitswap-request-handler", Some("networking"), handler.run());
protocol_config
}));
let network_params = sc_network::config::Params {
role: config.role.clone(),
executor: {
@@ -856,12 +866,15 @@ where
fork_id: config.chain_spec.fork_id().map(ToOwned::to_owned),
import_queue: Box::new(import_queue),
chain_sync: Box::new(chain_sync),
bitswap: config.network.ipfs_server.then(|| Bitswap::from_client(client.clone())),
metrics_registry: config.prometheus_config.as_ref().map(|config| config.registry.clone()),
block_request_protocol_config,
state_request_protocol_config,
warp_sync_protocol_config,
light_client_request_protocol_config,
request_response_protocol_configs: request_response_protocol_configs
.into_iter()
.flatten()
.collect::<Vec<_>>(),
};
let has_bootnodes = !network_params.network_config.boot_nodes.is_empty();