mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Attempt to relieve pressure on mpsc_network_worker (#13725)
* Attempt to relieve pressure on `mpsc_network_worker` `SyncingEngine` interacting with `NetworkWorker` can put a lot of strain on the channel if the number of inbound connections is high. This is because `SyncingEngine` is notified of each inbound substream which it then can either accept or reject and this causes a lot of message exchange on the already busy channel. Use a direct channel pair between `Protocol` and `SyncingEngine` to exchange notification events. It is a temporary change to alleviate the problems caused by syncing being an independent protocol and the fix will be removed once `NotificationService` is implemented. * Apply review comments * fixes * trigger ci * Fix tests Verify that both peers have a connection now that the validation goes through `SyncingEngine`. Depending on how the tasks are scheduled, one of them might not have the peer registered in `SyncingEngine` at which point the test won't make any progress because block announcement received from an unknown peer is discarded. Move polling of `ChainSync` at the end of the function so that if a block announcement causes a block request to be sent, that can be sent in the same call to `SyncingEngine::poll()`. --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -55,8 +55,8 @@ use sc_network::{
|
||||
},
|
||||
request_responses::ProtocolConfig as RequestResponseConfig,
|
||||
types::ProtocolName,
|
||||
Multiaddr, NetworkBlock, NetworkEventStream, NetworkService, NetworkStateInfo,
|
||||
NetworkSyncForkRequest, NetworkWorker,
|
||||
Multiaddr, NetworkBlock, NetworkService, NetworkStateInfo, NetworkSyncForkRequest,
|
||||
NetworkWorker,
|
||||
};
|
||||
use sc_network_common::{
|
||||
role::Roles,
|
||||
@@ -896,6 +896,7 @@ where
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
NetworkServiceProvider::new();
|
||||
|
||||
let (tx, rx) = sc_utils::mpsc::tracing_unbounded("mpsc_syncing_engine_protocol", 100_000);
|
||||
let (engine, sync_service, block_announce_config) =
|
||||
sc_network_sync::engine::SyncingEngine::new(
|
||||
Roles::from(if config.is_authority { &Role::Authority } else { &Role::Full }),
|
||||
@@ -911,6 +912,7 @@ where
|
||||
block_request_protocol_config.name.clone(),
|
||||
state_request_protocol_config.name.clone(),
|
||||
Some(warp_protocol_config.name.clone()),
|
||||
rx,
|
||||
)
|
||||
.unwrap();
|
||||
let sync_service_import_queue = Box::new(sync_service.clone());
|
||||
@@ -918,7 +920,7 @@ where
|
||||
|
||||
let genesis_hash =
|
||||
client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
|
||||
let network = NetworkWorker::new::<Block>(sc_network::config::Params {
|
||||
let network = NetworkWorker::new(sc_network::config::Params {
|
||||
role: if config.is_authority { Role::Authority } else { Role::Full },
|
||||
executor: Box::new(|f| {
|
||||
tokio::spawn(f);
|
||||
@@ -929,6 +931,7 @@ where
|
||||
fork_id,
|
||||
metrics_registry: None,
|
||||
block_announce_config,
|
||||
tx,
|
||||
request_response_protocol_configs: [
|
||||
block_request_protocol_config,
|
||||
state_request_protocol_config,
|
||||
@@ -950,9 +953,8 @@ where
|
||||
import_queue.run(sync_service_import_queue).await;
|
||||
});
|
||||
|
||||
let service = network.service().clone();
|
||||
tokio::spawn(async move {
|
||||
engine.run(service.event_stream("syncing")).await;
|
||||
engine.run().await;
|
||||
});
|
||||
|
||||
self.mut_peers(move |peers| {
|
||||
|
||||
@@ -177,6 +177,7 @@ impl TestNetworkBuilder {
|
||||
|
||||
let (chain_sync_network_provider, chain_sync_network_handle) =
|
||||
self.chain_sync_network.unwrap_or(NetworkServiceProvider::new());
|
||||
let (tx, rx) = sc_utils::mpsc::tracing_unbounded("mpsc_syncing_engine_protocol", 100_000);
|
||||
|
||||
let (engine, chain_sync_service, block_announce_config) = SyncingEngine::new(
|
||||
Roles::from(&config::Role::Full),
|
||||
@@ -192,6 +193,7 @@ impl TestNetworkBuilder {
|
||||
block_request_protocol_config.name.clone(),
|
||||
state_request_protocol_config.name.clone(),
|
||||
None,
|
||||
rx,
|
||||
)
|
||||
.unwrap();
|
||||
let mut link = self.link.unwrap_or(Box::new(chain_sync_service.clone()));
|
||||
@@ -217,6 +219,7 @@ impl TestNetworkBuilder {
|
||||
light_client_request_protocol_config,
|
||||
]
|
||||
.to_vec(),
|
||||
tx,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -234,8 +237,7 @@ impl TestNetworkBuilder {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(250)).await;
|
||||
}
|
||||
});
|
||||
let stream = worker.service().event_stream("syncing");
|
||||
tokio::spawn(engine.run(stream));
|
||||
tokio::spawn(engine.run());
|
||||
|
||||
TestNetwork::new(worker)
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ async fn can_sync_small_non_best_forks() {
|
||||
// poll until the two nodes connect, otherwise announcing the block will not work
|
||||
futures::future::poll_fn::<(), _>(|cx| {
|
||||
net.poll(cx);
|
||||
if net.peer(0).num_peers() == 0 {
|
||||
if net.peer(0).num_peers() == 0 || net.peer(1).num_peers() == 0 {
|
||||
Poll::Pending
|
||||
} else {
|
||||
Poll::Ready(())
|
||||
|
||||
Reference in New Issue
Block a user