Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing strategy refactoring (part 3) #5737

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0515f8f
Use `SyncingAction` everywhere instead of custom enums in different s…
nazar-pc Sep 6, 2024
743161c
Make strategy key opaque instead of having a hardcoded list of variants
nazar-pc Sep 6, 2024
e393d30
Rename `SyncingConfig` to `PolkadotSyncingStrategyConfig`
nazar-pc Sep 6, 2024
6b5acc4
Move `PolkadotSyncingStrategy` into its own module
nazar-pc Sep 6, 2024
a312e09
Replace `SyncingAction::SendWarpProofRequest` and `SyncingStrategy::o…
nazar-pc Sep 6, 2024
72908d3
Replace state sync request/response handling with generic one
nazar-pc Sep 6, 2024
c727dc1
Replace `SyncingAction::SendGenericRequest` with more generic `Syncin…
nazar-pc Sep 6, 2024
6bf9b7f
Move block downloader instantiation outside the network instantiation
nazar-pc Sep 10, 2024
76b2dcf
Move `ChainSync::on_block_response` implementation out of the trait i…
nazar-pc Sep 10, 2024
a1a0863
Pass protocol name down to generic response handler
nazar-pc Sep 10, 2024
d2ab786
Replace `SyncingAction::SendBlockRequest` and `SyncingStrategy::on_bl…
nazar-pc Sep 10, 2024
0ae9dc0
Improve import queue API, removing the need for `Box<dyn Link<B>>` if…
nazar-pc Sep 11, 2024
a26bbfa
Remove syncing engine construction from `build_network` and expose `b…
nazar-pc Sep 11, 2024
53b34d0
Add prdoc
nazar-pc Sep 17, 2024
0ac0ddf
Rename `build_network` to `build_network_advanced` and restore `build…
nazar-pc Sep 20, 2024
8388a81
Make `build_network_advanced` arguments lower-level and not require `…
nazar-pc Sep 20, 2024
243af75
Merge remote-tracking branch 'upstream/master' into syncing-strategy-…
nazar-pc Sep 20, 2024
63dbf0f
Fix toml formatting
nazar-pc Sep 20, 2024
7f4ce2c
Change name of generics for consistency
nazar-pc Oct 22, 2024
87be088
Remove redundant comment (present in places that set `remove_obsolete…
nazar-pc Oct 22, 2024
27ee43c
Merge remote-tracking branch 'upstream/master' into syncing-strategy-…
nazar-pc Oct 22, 2024
dfa87f4
Merge remote-tracking branch 'upstream/master' into syncing-strategy-…
nazar-pc Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

47 changes: 23 additions & 24 deletions cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
Expand Down
49 changes: 24 additions & 25 deletions polkadot/node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Block>;
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
})?;
Expand Down
46 changes: 21 additions & 25 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -510,29 +511,24 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::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 {
Expand All @@ -542,8 +538,8 @@ 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,
block_announce_validator_builder: None,
syncing_strategy,
sync_service,
block_announce_config,
network_service_provider,
metrics,
})?;
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/network/sync/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ where
network_metrics: NotificationMetrics,
net_config: &FullNetworkConfiguration<B, <B as BlockT>::Hash, N>,
protocol_id: ProtocolId,
fork_id: &Option<String>,
fork_id: Option<&str>,
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
syncing_strategy: Box<dyn SyncingStrategy<B>>,
network_service: service::network::NetworkServiceHandle,
Expand Down Expand Up @@ -1039,7 +1039,7 @@ where
/// Get config for the block announcement protocol
fn get_block_announce_proto_config<N: NetworkBackend<B, <B as BlockT>::Hash>>(
protocol_id: ProtocolId,
fork_id: &Option<String>,
fork_id: Option<&str>,
roles: Roles,
best_number: NumberFor<B>,
best_hash: B::Hash,
Expand All @@ -1050,7 +1050,7 @@ where
) -> (N::NotificationProtocolConfig, Box<dyn NotificationService>) {
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),
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/test/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading