Skip to content

Commit

Permalink
Rename build_network to build_network_advanced and restore `build…
Browse files Browse the repository at this point in the history
…_network` API before paritytech#5666
  • Loading branch information
nazar-pc committed Sep 20, 2024
1 parent 53b34d0 commit 0ac0ddf
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 176 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 6 additions & 31 deletions cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ use sc_consensus::{
BlockImport,
};
use sc_network::{config::SyncMode, service::traits::NetworkService, NetworkBackend};
use sc_network_sync::{service::network::NetworkServiceProvider, SyncingService};
use sc_network_sync::SyncingService;
use sc_network_transactions::TransactionsHandlerController;
use sc_service::{
build_default_syncing_engine, Configuration, DefaultSyncingEngineConfig, NetworkStarter,
SpawnTaskHandle, TaskManager, WarpSyncConfig,
};
use sc_service::{Configuration, NetworkStarter, SpawnTaskHandle, TaskManager, WarpSyncConfig};
use sc_telemetry::{log, TelemetryWorkerHandle};
use sc_utils::mpsc::TracingUnboundedSender;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -428,7 +425,7 @@ pub struct BuildNetworkParams<
pub async fn build_network<'a, Block, Client, RCInterface, IQ, Network>(
BuildNetworkParams {
parachain_config,
mut net_config,
net_config,
client,
transaction_pool,
para_id,
Expand Down Expand Up @@ -499,38 +496,16 @@ where
parachain_config.prometheus_config.as_ref().map(|config| &config.registry),
);

let network_service_provider = NetworkServiceProvider::new();
let (sync_service, block_announce_config) =
build_default_syncing_engine(DefaultSyncingEngineConfig {
role: parachain_config.role,
protocol_id: parachain_config.protocol_id(),
fork_id: None,
net_config: &mut net_config,
block_announce_validator,
network_service_handle: network_service_provider.handle(),
warp_sync_config,
client: client.clone(),
import_queue_service: import_queue.service(),
num_peers_hint: parachain_config.network.default_peers_set.in_peers as usize +
parachain_config.network.default_peers_set.out_peers as usize,
spawn_handle: &spawn_handle,
metrics_registry: parachain_config
.prometheus_config
.as_ref()
.map(|config| &config.registry),
metrics: metrics.clone(),
})?;

sc_service::build_network(sc_service::BuildNetworkParams {
config: parachain_config,
net_config,
client,
transaction_pool,
spawn_handle,
import_queue,
sync_service,
block_announce_config,
network_service_provider,
block_announce_validator_builder: Some(Box::new(move |_| block_announce_validator)),
warp_sync_config,
block_relay: None,
metrics,
})
}
Expand Down
32 changes: 4 additions & 28 deletions polkadot/node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc, time::Duration};
use prometheus_endpoint::Registry;
#[cfg(feature = "full-node")]
use sc_service::KeystoreContainer;
use sc_service::{
build_default_syncing_engine, DefaultSyncingEngineConfig, RpcHandlers, SpawnTaskHandle,
};
use sc_service::{RpcHandlers, SpawnTaskHandle};
use sc_telemetry::TelemetryWorker;
#[cfg(feature = "full-node")]
use sc_telemetry::{Telemetry, TelemetryWorkerHandle};
Expand All @@ -100,7 +98,6 @@ pub use sc_client_api::{Backend, CallExecutor};
pub use sc_consensus::{BlockImport, LongestChain};
pub use sc_executor::NativeExecutionDispatch;
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
use sc_network_sync::service::network::NetworkServiceProvider;
pub use sc_service::{
config::{DatabaseSource, PrometheusConfig},
ChainSpec, Configuration, Error as SubstrateServiceError, PruningMode, Role, TFullBackend,
Expand All @@ -120,8 +117,6 @@ pub use {rococo_runtime, rococo_runtime_constants};
pub use {westend_runtime, westend_runtime_constants};

pub use fake_runtime_api::{GetLastTimestamp, RuntimeApi};
use sc_consensus::ImportQueue;
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;

#[cfg(feature = "full-node")]
pub type FullBackend = sc_service::TFullBackend<Block>;
Expand Down Expand Up @@ -1033,25 +1028,6 @@ pub fn new_full<
})
};

let network_service_provider = NetworkServiceProvider::new();
let (sync_service, block_announce_config) =
build_default_syncing_engine(DefaultSyncingEngineConfig {
role: config.role,
protocol_id: config.protocol_id(),
fork_id: None,
net_config: &mut net_config,
block_announce_validator: Box::new(DefaultBlockAnnounceValidator),
network_service_handle: network_service_provider.handle(),
warp_sync_config: Some(WarpSyncConfig::WithProvider(warp_sync)),
client: client.clone(),
import_queue_service: import_queue.service(),
num_peers_hint: config.network.default_peers_set.in_peers as usize +
config.network.default_peers_set.out_peers as usize,
spawn_handle: &task_manager.spawn_handle(),
metrics_registry: config.prometheus_config.as_ref().map(|config| &config.registry),
metrics: metrics.clone(),
})?;

let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
Expand All @@ -1060,9 +1036,9 @@ pub fn new_full<
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
sync_service,
block_announce_config,
network_service_provider,
block_announce_validator_builder: None,
warp_sync_config: Some(WarpSyncConfig::WithProvider(warp_sync)),
block_relay: None,
metrics,
})?;

Expand Down
12 changes: 7 additions & 5 deletions prdoc/pr_5737.prdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ title: Make syncing service an argument of `build_network`
doc:
- audience: Node Dev
description: |
`build_network` no longer creates syncing engine internally, it now takes a handle to syncing service is an
argument instead. In most cases typical syncing engine with polkadot syncing strategy and default block downloader
can be created with newly introduced `sc_service::build_default_syncing_engine()` function, but lower-level
`build_default_block_downloader` also exists for those needing more customization.
`build_network` is accompanied with lower-level `build_network_advanced` with simpler API that does not create
syncing engine internally, but instead takes a handle to syncing service as an argument. In most cases typical
syncing engine with polkadot syncing strategy and default block downloader can be created with newly introduced
`sc_service::build_default_syncing_engine()` function, but lower-level `build_default_block_downloader` also
exists for those needing more customization.

These changes allow developers higher than ever control over syncing implementation.
These changes allow developers higher than ever control over syncing implementation, but `build_network` is still
available for easier high-level usage.

crates:
- name: cumulus-client-service
Expand Down
30 changes: 3 additions & 27 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ use frame_system_rpc_runtime_api::AccountNonceApi;
use futures::prelude::*;
use kitchensink_runtime::RuntimeApi;
use node_primitives::Block;
use polkadot_sdk::{
sc_network_sync::service::network::NetworkServiceProvider,
sc_service::{build_default_syncing_engine, DefaultSyncingEngineConfig, ImportQueue},
sp_consensus::block_validation::DefaultBlockAnnounceValidator,
};
use sc_client_api::{Backend, BlockBackend};
use sc_consensus_babe::{self, SlotProportion};
use sc_network::{
Expand Down Expand Up @@ -511,25 +506,6 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
Vec::default(),
));

let network_service_provider = NetworkServiceProvider::new();
let (sync_service, block_announce_config) =
build_default_syncing_engine(DefaultSyncingEngineConfig {
role: config.role,
protocol_id: config.protocol_id(),
fork_id: None,
net_config: &mut net_config,
block_announce_validator: Box::new(DefaultBlockAnnounceValidator),
network_service_handle: network_service_provider.handle(),
warp_sync_config: Some(WarpSyncConfig::WithProvider(warp_sync)),
client: client.clone(),
import_queue_service: import_queue.service(),
num_peers_hint: config.network.default_peers_set.in_peers as usize +
config.network.default_peers_set.out_peers as usize,
spawn_handle: &task_manager.spawn_handle(),
metrics_registry: config.prometheus_config.as_ref().map(|config| &config.registry),
metrics: metrics.clone(),
})?;

let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
Expand All @@ -538,9 +514,9 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
sync_service,
block_announce_config,
network_service_provider,
block_announce_validator_builder: None,
warp_sync_config: Some(WarpSyncConfig::WithProvider(warp_sync)),
block_relay: None,
metrics,
})?;

Expand Down
Loading

0 comments on commit 0ac0ddf

Please sign in to comment.