diff --git a/Cargo.lock b/Cargo.lock index 9abdac013ccd6..3d079c8fdfd03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20926,6 +20926,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-blockchain", + "sp-consensus", "sp-consensus-aura", "sp-consensus-grandpa", "sp-core 28.0.0", diff --git a/cumulus/client/service/src/lib.rs b/cumulus/client/service/src/lib.rs index 84b8136b7c739..864f791cbd84e 100644 --- a/cumulus/client/service/src/lib.rs +++ b/cumulus/client/service/src/lib.rs @@ -41,7 +41,7 @@ use sc_network::{config::SyncMode, service::traits::NetworkService, NetworkBacke use sc_network_sync::{service::network::NetworkServiceProvider, SyncingService}; use sc_network_transactions::TransactionsHandlerController; use sc_service::{ - build_default_block_downloader, build_polkadot_syncing_strategy, Configuration, NetworkStarter, + build_default_syncing_engine, Configuration, DefaultSyncingEngineConfig, NetworkStarter, SpawnTaskHandle, TaskManager, WarpSyncConfig, }; use sc_telemetry::{log, TelemetryWorkerHandle}; @@ -499,28 +499,27 @@ where parachain_config.prometheus_config.as_ref().map(|config| &config.registry), ); - let protocol_id = parachain_config.protocol_id(); let network_service_provider = NetworkServiceProvider::new(); - let block_downloader = build_default_block_downloader( - &protocol_id, - parachain_config.chain_spec.fork_id(), - &mut net_config, - network_service_provider.handle(), - client.clone(), - parachain_config.network.default_peers_set.in_peers as usize + - parachain_config.network.default_peers_set.out_peers as usize, - &spawn_handle, - ); - let syncing_strategy = build_polkadot_syncing_strategy( - protocol_id, - parachain_config.chain_spec.fork_id(), - &mut net_config, - warp_sync_config, - block_downloader, - client.clone(), - &spawn_handle, - parachain_config.prometheus_config.as_ref().map(|config| &config.registry), - )?; + 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, @@ -529,8 +528,8 @@ where transaction_pool, spawn_handle, import_queue, - block_announce_validator_builder: Some(Box::new(move |_| block_announce_validator)), - syncing_strategy, + sync_service, + block_announce_config, network_service_provider, metrics, }) diff --git a/polkadot/node/service/src/lib.rs b/polkadot/node/service/src/lib.rs index b8c216067fb64..fec09865f5437 100644 --- a/polkadot/node/service/src/lib.rs +++ b/polkadot/node/service/src/lib.rs @@ -84,7 +84,9 @@ 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_block_downloader, build_polkadot_syncing_strategy, RpcHandlers, SpawnTaskHandle}; +use sc_service::{ + build_default_syncing_engine, DefaultSyncingEngineConfig, RpcHandlers, SpawnTaskHandle, +}; use sc_telemetry::TelemetryWorker; #[cfg(feature = "full-node")] use sc_telemetry::{Telemetry, TelemetryWorkerHandle}; @@ -118,6 +120,8 @@ 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; @@ -1029,29 +1033,24 @@ pub fn new_full< }) }; - let protocol_id = config.protocol_id(); - let spawn_handle = task_manager.spawn_handle(); let network_service_provider = NetworkServiceProvider::new(); - let block_downloader = build_default_block_downloader( - &protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - network_service_provider.handle(), - client.clone(), - config.network.default_peers_set.in_peers as usize + - config.network.default_peers_set.out_peers as usize, - &spawn_handle, - ); - let syncing_strategy = build_polkadot_syncing_strategy( - protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - Some(WarpSyncConfig::WithProvider(warp_sync)), - block_downloader, - client.clone(), - &spawn_handle, - config.prometheus_config.as_ref().map(|config| &config.registry), - )?; + 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 { @@ -1061,8 +1060,8 @@ pub fn new_full< transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue, - block_announce_validator_builder: None, - syncing_strategy, + sync_service, + block_announce_config, network_service_provider, metrics, })?; diff --git a/substrate/bin/node/cli/src/service.rs b/substrate/bin/node/cli/src/service.rs index 0723e729a3097..5dfd9a6da789c 100644 --- a/substrate/bin/node/cli/src/service.rs +++ b/substrate/bin/node/cli/src/service.rs @@ -34,7 +34,8 @@ use kitchensink_runtime::RuntimeApi; use node_primitives::Block; use polkadot_sdk::{ sc_network_sync::service::network::NetworkServiceProvider, - sc_service::{build_default_block_downloader, build_polkadot_syncing_strategy}, + 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}; @@ -510,29 +511,24 @@ pub fn new_full_base::Hash>>( Vec::default(), )); - let protocol_id = config.protocol_id(); - let spawn_handle = task_manager.spawn_handle(); let network_service_provider = NetworkServiceProvider::new(); - let block_downloader = build_default_block_downloader( - &protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - network_service_provider.handle(), - client.clone(), - config.network.default_peers_set.in_peers as usize + - config.network.default_peers_set.out_peers as usize, - &spawn_handle, - ); - let syncing_strategy = build_polkadot_syncing_strategy( - protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - Some(WarpSyncConfig::WithProvider(warp_sync)), - block_downloader, - client.clone(), - &spawn_handle, - config.prometheus_config.as_ref().map(|config| &config.registry), - )?; + 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 { @@ -542,8 +538,8 @@ pub fn new_full_base::Hash>>( transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue, - block_announce_validator_builder: None, - syncing_strategy, + sync_service, + block_announce_config, network_service_provider, metrics, })?; diff --git a/substrate/client/network/sync/src/engine.rs b/substrate/client/network/sync/src/engine.rs index 49fc664281ea4..7401ede7a4427 100644 --- a/substrate/client/network/sync/src/engine.rs +++ b/substrate/client/network/sync/src/engine.rs @@ -279,7 +279,7 @@ where network_metrics: NotificationMetrics, net_config: &FullNetworkConfiguration::Hash, N>, protocol_id: ProtocolId, - fork_id: &Option, + fork_id: Option<&str>, block_announce_validator: Box + Send>, syncing_strategy: Box>, network_service: service::network::NetworkServiceHandle, @@ -1039,7 +1039,7 @@ where /// Get config for the block announcement protocol fn get_block_announce_proto_config::Hash>>( protocol_id: ProtocolId, - fork_id: &Option, + fork_id: Option<&str>, roles: Roles, best_number: NumberFor, best_hash: B::Hash, @@ -1050,7 +1050,7 @@ where ) -> (N::NotificationProtocolConfig, Box) { let block_announces_protocol = { let genesis_hash = genesis_hash.as_ref(); - if let Some(ref fork_id) = fork_id { + if let Some(fork_id) = fork_id { format!( "/{}/{}/block-announces/1", array_bytes::bytes2hex("", genesis_hash), diff --git a/substrate/client/network/test/src/lib.rs b/substrate/client/network/test/src/lib.rs index 074cf99c9ea66..346f209ec7adb 100644 --- a/substrate/client/network/test/src/lib.rs +++ b/substrate/client/network/test/src/lib.rs @@ -936,7 +936,7 @@ pub trait TestNetFactory: Default + Sized + Send { metrics, &full_net_config, protocol_id.clone(), - &fork_id, + fork_id.as_deref(), block_announce_validator, syncing_strategy, chain_sync_network_handle, diff --git a/substrate/client/network/test/src/service.rs b/substrate/client/network/test/src/service.rs index c160f67bff7b7..688b569c32228 100644 --- a/substrate/client/network/test/src/service.rs +++ b/substrate/client/network/test/src/service.rs @@ -224,7 +224,7 @@ impl TestNetworkBuilder { NotificationMetrics::new(None), &full_net_config, protocol_id.clone(), - &None, + None, Box::new(sp_consensus::block_validation::DefaultBlockAnnounceValidator), syncing_strategy, chain_sync_network_handle, diff --git a/substrate/client/service/src/builder.rs b/substrate/client/service/src/builder.rs index 517282eed5fbc..96a8b9fbdeaa8 100644 --- a/substrate/client/service/src/builder.rs +++ b/substrate/client/service/src/builder.rs @@ -35,7 +35,7 @@ use sc_client_api::{ BlockBackend, BlockchainEvents, ExecutorProvider, ForkBlocks, StorageProvider, UsageProvider, }; use sc_client_db::{Backend, BlocksPruning, DatabaseSettings, PruningMode}; -use sc_consensus::import_queue::ImportQueue; +use sc_consensus::import_queue::{ImportQueue, ImportQueueService}; use sc_executor::{ sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY, @@ -50,7 +50,7 @@ use sc_network::{ }, NetworkBackend, NetworkStateInfo, }; -use sc_network_common::role::Roles; +use sc_network_common::role::{Role, Roles}; use sc_network_light::light_client_requests::handler::LightClientRequestHandler; use sc_network_sync::{ block_relay_protocol::{BlockDownloader, BlockRelayParams}, @@ -84,9 +84,7 @@ use sc_transaction_pool_api::{MaintainedTransactionPool, TransactionPool}; use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender}; use sp_api::{CallApiAt, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; -use sp_consensus::block_validation::{ - BlockAnnounceValidator, Chain, DefaultBlockAnnounceValidator, -}; +use sp_consensus::block_validation::{BlockAnnounceValidator, Chain}; use sp_core::traits::{CodeExecutor, SpawnNamed}; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, BlockIdTo, NumberFor, Zero}; @@ -801,12 +799,10 @@ where pub spawn_handle: SpawnTaskHandle, /// An import queue. pub import_queue: IQ, - /// A block announce validator builder. - pub block_announce_validator_builder: Option< - Box) -> Box + Send> + Send>, - >, - /// Syncing strategy to use in syncing engine. - pub syncing_strategy: Box>, + /// Syncing service to communicate with syncing engine. + pub sync_service: SyncingService, + /// Block announce config. + pub block_announce_config: Net::NotificationProtocolConfig, /// Network service provider to drive with network internally. pub network_service_provider: NetworkServiceProvider, /// Metrics. @@ -848,8 +844,8 @@ where transaction_pool, spawn_handle, import_queue, - block_announce_validator_builder, - syncing_strategy, + sync_service, + block_announce_config, network_service_provider, metrics, } = params; @@ -857,12 +853,6 @@ where let protocol_id = config.protocol_id(); let genesis_hash = client.info().genesis_hash; - let block_announce_validator = if let Some(f) = block_announce_validator_builder { - f(client.clone()) - } else { - Box::new(DefaultBlockAnnounceValidator) - }; - let light_client_request_protocol_config = { // Allow both outgoing and incoming requests. let (handler, protocol_config) = LightClientRequestHandler::new::( @@ -884,37 +874,21 @@ where config }); - // create transactions protocol and add it to the list of supported protocols of - let peer_store_handle = net_config.peer_store_handle(); + // Create transactions protocol and add it to the list of supported protocols of let (transactions_handler_proto, transactions_config) = sc_network_transactions::TransactionsHandlerPrototype::new::<_, Block, Net>( protocol_id.clone(), genesis_hash, config.chain_spec.fork_id(), metrics.clone(), - Arc::clone(&peer_store_handle), + net_config.peer_store_handle(), ); net_config.add_notification_protocol(transactions_config); // Start task for `PeerStore` let peer_store = net_config.take_peer_store(); - let peer_store_handle = peer_store.handle(); spawn_handle.spawn("peer-store", Some("networking"), peer_store.run()); - let (engine, sync_service, block_announce_config) = SyncingEngine::new( - Roles::from(&config.role), - client.clone(), - config.prometheus_config.as_ref().map(|config| config.registry.clone()).as_ref(), - metrics.clone(), - &net_config, - protocol_id.clone(), - &config.chain_spec.fork_id().map(ToOwned::to_owned), - block_announce_validator, - syncing_strategy, - network_service_provider.handle(), - import_queue.service(), - Arc::clone(&peer_store_handle), - )?; let sync_service = Arc::new(sync_service); let network_params = sc_network::config::Params::::Hash, Net> { @@ -961,7 +935,6 @@ where async move { import_queue.run(sync_service.as_ref()).await } }); - spawn_handle.spawn_blocking("syncing", None, engine.run()); let (system_rpc_tx, system_rpc_rx) = tracing_unbounded("mpsc_system_rpc", 10_000); spawn_handle.spawn( @@ -1029,6 +1002,112 @@ where )) } +/// Configuration for [`build_default_syncing_engine`]. +pub struct DefaultSyncingEngineConfig<'a, Block, Client, Net> +where + Block: BlockT, + Net: NetworkBackend::Hash>, +{ + /// Role of the local node. + pub role: Role, + /// Protocol name prefix. + pub protocol_id: ProtocolId, + /// Fork ID. + pub fork_id: Option<&'a str>, + /// Full network configuration. + pub net_config: &'a mut FullNetworkConfiguration::Hash, Net>, + /// Validator for incoming block announcements. + pub block_announce_validator: Box + Send>, + /// Handle to communicate with `NetworkService`. + pub network_service_handle: NetworkServiceHandle, + /// Warp sync configuration (when used). + pub warp_sync_config: Option>, + /// A shared client returned by `new_full_parts`. + pub client: Arc, + /// Blocks import queue API. + pub import_queue_service: Box>, + /// Expected max total number of peer connections (in + out). + pub num_peers_hint: usize, + /// A handle for spawning tasks. + pub spawn_handle: &'a SpawnTaskHandle, + /// Prometheus metrics registry. + pub metrics_registry: Option<&'a Registry>, + /// Metrics. + pub metrics: NotificationMetrics, +} + +/// Build default syncing engine using [`build_default_block_downloader`] and +/// [`build_polkadot_syncing_strategy`] internally. +pub fn build_default_syncing_engine( + config: DefaultSyncingEngineConfig, +) -> Result<(SyncingService, Net::NotificationProtocolConfig), Error> +where + Block: BlockT, + Client: HeaderBackend + + BlockBackend + + HeaderMetadata + + ProofProvider + + Send + + Sync + + 'static, + Net: NetworkBackend::Hash>, +{ + let DefaultSyncingEngineConfig { + role, + protocol_id, + fork_id, + net_config, + block_announce_validator, + network_service_handle, + warp_sync_config, + client, + import_queue_service, + num_peers_hint, + spawn_handle, + metrics_registry, + metrics, + } = config; + + let block_downloader = build_default_block_downloader( + &protocol_id, + fork_id, + net_config, + network_service_handle.clone(), + client.clone(), + num_peers_hint, + spawn_handle, + ); + let syncing_strategy = build_polkadot_syncing_strategy( + protocol_id.clone(), + fork_id, + net_config, + warp_sync_config, + block_downloader, + client.clone(), + spawn_handle, + metrics_registry, + )?; + + let (syncing_engine, sync_service, block_announce_config) = SyncingEngine::new( + Roles::from(&role), + client, + metrics_registry, + metrics, + &net_config, + protocol_id, + fork_id, + block_announce_validator, + syncing_strategy, + network_service_handle, + import_queue_service, + net_config.peer_store_handle(), + )?; + + spawn_handle.spawn_blocking("syncing", None, syncing_engine.run()); + + Ok((sync_service, block_announce_config)) +} + /// Build default block downloader pub fn build_default_block_downloader( protocol_id: &ProtocolId, diff --git a/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index 13fd9b180efde..4df0aa9618935 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -59,12 +59,13 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; pub use self::{ builder::{ - build_default_block_downloader, build_network, build_polkadot_syncing_strategy, - gen_rpc_module, init_telemetry, new_client, new_db_backend, new_full_client, - new_full_parts, new_full_parts_record_import, new_full_parts_with_genesis_builder, - new_wasm_executor, propagate_transaction_notifications, spawn_tasks, BuildNetworkParams, - KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, TFullCallExecutor, - TFullClient, + build_default_block_downloader, build_default_syncing_engine, build_network, + build_polkadot_syncing_strategy, gen_rpc_module, init_telemetry, new_client, + new_db_backend, new_full_client, new_full_parts, new_full_parts_record_import, + new_full_parts_with_genesis_builder, new_wasm_executor, + propagate_transaction_notifications, spawn_tasks, BuildNetworkParams, + DefaultSyncingEngineConfig, KeystoreContainer, NetworkStarter, SpawnTasksParams, + TFullBackend, TFullCallExecutor, TFullClient, }, client::{ClientConfig, LocalCallExecutor}, error::Error, diff --git a/templates/minimal/node/src/service.rs b/templates/minimal/node/src/service.rs index 1c5e7225caee8..11da193018cad 100644 --- a/templates/minimal/node/src/service.rs +++ b/templates/minimal/node/src/service.rs @@ -23,11 +23,12 @@ use polkadot_sdk::{ sc_executor::WasmExecutor, sc_network_sync::service::network::NetworkServiceProvider, sc_service::{ - build_default_block_downloader, build_polkadot_syncing_strategy, - error::Error as ServiceError, Configuration, TaskManager, + build_default_syncing_engine, error::Error as ServiceError, Configuration, + DefaultSyncingEngineConfig, ImportQueue, TaskManager, }, sc_telemetry::{Telemetry, TelemetryWorker}, sc_transaction_pool_api::OffchainTransactionPoolFactory, + sp_consensus::block_validation::DefaultBlockAnnounceValidator, sp_runtime::traits::Block as BlockT, *, }; @@ -135,29 +136,24 @@ pub fn new_full::Ha config.prometheus_config.as_ref().map(|cfg| &cfg.registry), ); - let protocol_id = config.protocol_id(); - let spawn_handle = task_manager.spawn_handle(); let network_service_provider = NetworkServiceProvider::new(); - let block_downloader = build_default_block_downloader( - &protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - network_service_provider.handle(), - client.clone(), - config.network.default_peers_set.in_peers as usize + - config.network.default_peers_set.out_peers as usize, - &spawn_handle, - ); - let syncing_strategy = build_polkadot_syncing_strategy( - protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - None, - block_downloader, - client.clone(), - &spawn_handle, - config.prometheus_config.as_ref().map(|config| &config.registry), - )?; + 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: None, + 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 { @@ -166,9 +162,9 @@ pub fn new_full::Ha transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue, + sync_service, + block_announce_config, net_config, - block_announce_validator_builder: None, - syncing_strategy, network_service_provider, metrics, })?; diff --git a/templates/solochain/node/Cargo.toml b/templates/solochain/node/Cargo.toml index 076cce2d5bf4f..1b3d281225143 100644 --- a/templates/solochain/node/Cargo.toml +++ b/templates/solochain/node/Cargo.toml @@ -31,10 +31,11 @@ sc-telemetry = { workspace = true, default-features = true } sc-transaction-pool = { workspace = true, default-features = true } sc-transaction-pool-api = { workspace = true, default-features = true } sc-offchain = { workspace = true, default-features = true } +sc-consensus = { workspace = true, default-features = true } sc-consensus-aura = { workspace = true, default-features = true } sp-consensus-aura = { workspace = true, default-features = true } -sc-consensus = { workspace = true, default-features = true } sc-consensus-grandpa = { workspace = true, default-features = true } +sp-consensus = { workspace = true, default-features = true } sp-consensus-grandpa = { workspace = true, default-features = true } sc-client-api = { workspace = true, default-features = true } sc-basic-authorship = { workspace = true, default-features = true } @@ -68,21 +69,21 @@ substrate-build-script-utils = { workspace = true, default-features = true } [features] default = ["std"] std = [ - "solochain-template-runtime/std", + "solochain-template-runtime/std", ] # Dependencies that are only required if runtime benchmarking should be build. runtime-benchmarks = [ - "frame-benchmarking-cli/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sc-service/runtime-benchmarks", - "solochain-template-runtime/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sc-service/runtime-benchmarks", + "solochain-template-runtime/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] # Enable features that allow the runtime to be tried and debugged. Name might be subject to change # in the near future. try-runtime = [ - "frame-system/try-runtime", - "pallet-transaction-payment/try-runtime", - "solochain-template-runtime/try-runtime", - "sp-runtime/try-runtime", + "frame-system/try-runtime", + "pallet-transaction-payment/try-runtime", + "solochain-template-runtime/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/templates/solochain/node/src/service.rs b/templates/solochain/node/src/service.rs index 7c7ddcee7c9f2..01bd13c34cc7f 100644 --- a/templates/solochain/node/src/service.rs +++ b/templates/solochain/node/src/service.rs @@ -2,16 +2,18 @@ use futures::FutureExt; use sc_client_api::{Backend, BlockBackend}; +use sc_consensus::ImportQueue; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; use sc_consensus_grandpa::SharedVoterState; use sc_network_sync::service::network::NetworkServiceProvider; use sc_service::{ - build_default_block_downloader, build_polkadot_syncing_strategy, error::Error as ServiceError, - Configuration, TaskManager, WarpSyncConfig, + build_default_syncing_engine, error::Error as ServiceError, Configuration, + DefaultSyncingEngineConfig, TaskManager, WarpSyncConfig, }; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use solochain_template_runtime::{self, apis::RuntimeApi, opaque::Block}; +use sp_consensus::block_validation::DefaultBlockAnnounceValidator; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use std::{sync::Arc, time::Duration}; @@ -170,29 +172,24 @@ pub fn new_full< Vec::default(), )); - let protocol_id = config.protocol_id(); - let spawn_handle = task_manager.spawn_handle(); let network_service_provider = NetworkServiceProvider::new(); - let block_downloader = build_default_block_downloader( - &protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - network_service_provider.handle(), - client.clone(), - config.network.default_peers_set.in_peers as usize + - config.network.default_peers_set.out_peers as usize, - &spawn_handle, - ); - let syncing_strategy = build_polkadot_syncing_strategy( - protocol_id, - config.chain_spec.fork_id(), - &mut net_config, - Some(WarpSyncConfig::WithProvider(warp_sync)), - block_downloader, - client.clone(), - &spawn_handle, - config.prometheus_config.as_ref().map(|config| &config.registry), - )?; + 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 { @@ -202,8 +199,8 @@ pub fn new_full< transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), import_queue, - block_announce_validator_builder: None, - syncing_strategy, + sync_service, + block_announce_config, network_service_provider, metrics, })?;