Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Fix checks
  • Loading branch information
bkchr committed Mar 22, 2022
commit fecfb6af1926288c0138a98d79f721a2602e3f5a
14 changes: 13 additions & 1 deletion client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ impl From<multiaddr::Error> for ParseErr {
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
/// Sync operation mode.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SyncMode {
/// Full block download and verification.
Full,
Expand All @@ -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
Expand Down
18 changes: 13 additions & 5 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down