From 981015ee676b0ba3115395a458f5350e0492e50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 22 Mar 2022 09:56:38 +0100 Subject: [PATCH 1/4] warp-sync: Return an error when trying to enable it for archive nodes. --- client/service/src/builder.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e9c1691107c71..aece91a8d869d 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -814,19 +814,25 @@ where } }; - let warp_sync_params = warp_sync.map(|provider| { - let protocol_config = if matches!(config.role, Role::Light) { - // Allow outgoing requests but deny incoming requests. - warp_request_handler::generate_request_response_config(protocol_id.clone()) - } else { - // Allow both outgoing and incoming requests. - let (handler, protocol_config) = - WarpSyncRequestHandler::new(protocol_id.clone(), provider.clone()); - spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run()); - protocol_config - }; - (provider, protocol_config) - }); + let warp_sync_params = warp_sync + .map(|provider| { + if config.state_pruning.is_archive() { + return Err("Warp sync doesn't work for archive nodes") + } + + let protocol_config = if matches!(config.role, Role::Light) { + // Allow outgoing requests but deny incoming requests. + warp_request_handler::generate_request_response_config(protocol_id.clone()) + } else { + // Allow both outgoing and incoming requests. + let (handler, protocol_config) = + WarpSyncRequestHandler::new(protocol_id.clone(), provider.clone()); + spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run()); + protocol_config + }; + Ok((provider, protocol_config)) + }) + .transpose()?; let light_client_request_protocol_config = { if matches!(config.role, Role::Light) { From fecfb6af1926288c0138a98d79f721a2602e3f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 22 Mar 2022 11:23:42 +0100 Subject: [PATCH 2/4] Fix checks --- client/network/src/config.rs | 14 +++++++++++++- client/service/src/builder.rs | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/client/network/src/config.rs b/client/network/src/config.rs index a7e4e5cc87668..eedf3fc22b961 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -377,8 +377,8 @@ impl From for ParseErr { } } -#[derive(Clone, Debug, Eq, PartialEq)] /// Sync operation mode. +#[derive(Clone, Debug, Eq, PartialEq)] pub enum SyncMode { /// Full block download and verification. Full, @@ -393,6 +393,18 @@ pub enum SyncMode { Warp, } +impl SyncMode { + /// Returns if `self` is [`Self::Warp`]. + pub fn is_warp(&self) -> bool { + matches!(self, Self::Warp) + } + + /// Returns if `self` is [`Self::Fast`]. + pub fn is_fast(&self) -> bool { + matches!(self, Self::Fast { .. }) + } +} + impl Default for SyncMode { fn default() -> Self { Self::Full diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index aece91a8d869d..8bc3cfa794aff 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -39,7 +39,7 @@ use sc_executor::RuntimeVersionOf; use sc_keystore::LocalKeystore; use sc_network::{ block_request_handler::{self, BlockRequestHandler}, - config::Role, + config::{Role, SyncMode}, light_client_requests::{self, handler::LightClientRequestHandler}, state_request_handler::{self, StateRequestHandler}, warp_request_handler::{self, RequestHandler as WarpSyncRequestHandler, WarpSyncProvider}, @@ -767,6 +767,18 @@ where warp_sync, } = params; + if warp_sync.is_none() && config.network.sync_mode.is_warp() { + return Err("Warp sync enabled, but no warp sync provider configured.".into()) + } + + if config.state_pruning.is_archive() { + match config.network.sync_mode { + SyncMode::Fast { .. } => return Err("Fast sync doesn't work for archive nodes".into()), + SyncMode::Warp => return Err("Warp sync doesn't work for archive nodes".into()), + SyncMode::Full => {}, + }; + } + let transaction_pool_adapter = Arc::new(TransactionPoolAdapter { imports_external_transactions: !matches!(config.role, Role::Light), pool: transaction_pool, @@ -816,10 +828,6 @@ where let warp_sync_params = warp_sync .map(|provider| { - if config.state_pruning.is_archive() { - return Err("Warp sync doesn't work for archive nodes") - } - let protocol_config = if matches!(config.role, Role::Light) { // Allow outgoing requests but deny incoming requests. warp_request_handler::generate_request_response_config(protocol_id.clone()) From 7bfbbf86a0d53cbbb68f23784dfab3671506c396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 22 Mar 2022 11:36:51 +0100 Subject: [PATCH 3/4] Ups --- client/service/src/builder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 8bc3cfa794aff..11507f9a3aa36 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -838,9 +838,8 @@ where spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run()); protocol_config }; - Ok((provider, protocol_config)) - }) - .transpose()?; + (provider, protocol_config) + }); let light_client_request_protocol_config = { if matches!(config.role, Role::Light) { From 1670573c15637d77dddd5d1f9ebb98905d0e7cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 22 Mar 2022 12:46:43 +0100 Subject: [PATCH 4/4] FMT --- client/service/src/builder.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 11507f9a3aa36..f4ff932435755 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -826,20 +826,19 @@ where } }; - let warp_sync_params = warp_sync - .map(|provider| { - let protocol_config = if matches!(config.role, Role::Light) { - // Allow outgoing requests but deny incoming requests. - warp_request_handler::generate_request_response_config(protocol_id.clone()) - } else { - // Allow both outgoing and incoming requests. - let (handler, protocol_config) = - WarpSyncRequestHandler::new(protocol_id.clone(), provider.clone()); - spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run()); - protocol_config - }; - (provider, protocol_config) - }); + let warp_sync_params = warp_sync.map(|provider| { + let protocol_config = if matches!(config.role, Role::Light) { + // Allow outgoing requests but deny incoming requests. + warp_request_handler::generate_request_response_config(protocol_id.clone()) + } else { + // Allow both outgoing and incoming requests. + let (handler, protocol_config) = + WarpSyncRequestHandler::new(protocol_id.clone(), provider.clone()); + spawn_handle.spawn("warp-sync-request-handler", Some("networking"), handler.run()); + protocol_config + }; + (provider, protocol_config) + }); let light_client_request_protocol_config = { if matches!(config.role, Role::Light) {