diff --git a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs index a46bba6938..67c36b79a5 100644 --- a/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs +++ b/crates/subspace-malicious-operator/src/bin/subspace-malicious-operator.rs @@ -215,6 +215,7 @@ fn main() -> Result<(), Error> { let partial_components = subspace_service::new_partial::( &consensus_chain_config, + false, &pot_external_entropy, ) .map_err(|error| { diff --git a/crates/subspace-node/src/commands/run.rs b/crates/subspace-node/src/commands/run.rs index 23d6d6b542..5559d79fc0 100644 --- a/crates/subspace-node/src/commands/run.rs +++ b/crates/subspace-node/src/commands/run.rs @@ -17,7 +17,6 @@ use domain_runtime_primitives::opaque::Block as DomainBlock; use futures::FutureExt; use sc_cli::Signals; use sc_consensus_slots::SlotProportion; -use sc_network::config::SyncMode; use sc_service::{BlocksPruning, PruningMode}; use sc_storage_monitor::StorageMonitorService; use sc_transaction_pool_api::OffchainTransactionPoolFactory; @@ -149,6 +148,10 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> { let partial_components = match subspace_service::new_partial::( &subspace_configuration, + match subspace_configuration.sync { + ChainSyncMode::Full => false, + ChainSyncMode::Snap => true, + }, &pot_external_entropy, ) { Ok(partial_components) => partial_components, @@ -164,15 +167,9 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> { consensus_state_pruning = PruningMode::ArchiveCanonical; subspace_configuration.base.state_pruning = Some(PruningMode::ArchiveCanonical); - // TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407 - if subspace_configuration.base.network.sync_mode.light_state() { - // In case of archival pruning mode sync mode needs to be set to full or - // else Substrate network will fail to initialize - subspace_configuration.base.network.sync_mode = SyncMode::Full; - } - subspace_service::new_partial::( &subspace_configuration, + false, &pot_external_entropy, ) .map_err(|error| { diff --git a/crates/subspace-node/src/main.rs b/crates/subspace-node/src/main.rs index e15dbea048..8f6d72cd12 100644 --- a/crates/subspace-node/src/main.rs +++ b/crates/subspace-node/src/main.rs @@ -148,6 +148,7 @@ fn main() -> Result<(), Error> { .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; Ok(( @@ -166,6 +167,7 @@ fn main() -> Result<(), Error> { .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; Ok(( @@ -185,6 +187,7 @@ fn main() -> Result<(), Error> { .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; Ok(( @@ -205,6 +208,7 @@ fn main() -> Result<(), Error> { .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; Ok(( @@ -227,6 +231,7 @@ fn main() -> Result<(), Error> { .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; Ok(( @@ -263,6 +268,7 @@ fn main() -> Result<(), Error> { let PartialComponents { client, .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; @@ -279,6 +285,7 @@ fn main() -> Result<(), Error> { client, backend, .. } = subspace_service::new_partial::( &config, + false, &derive_pot_external_entropy(&config, None)?, )?; let db = backend.expose_db(); diff --git a/crates/subspace-service/src/config.rs b/crates/subspace-service/src/config.rs index b98aaf5e25..5b325a9c84 100644 --- a/crates/subspace-service/src/config.rs +++ b/crates/subspace-service/src/config.rs @@ -154,14 +154,7 @@ impl From for Configuration { max_parallel_downloads: 5, // Substrate's default max_blocks_per_request: 64, - sync_mode: match configuration.network.sync_mode { - ChainSyncMode::Full => SyncMode::Full, - // TODO: revisit SyncMode change after https://github.com/paritytech/polkadot-sdk/issues/4407 - ChainSyncMode::Snap => SyncMode::LightState { - skip_proofs: false, - storage_chain_mode: false, - }, - }, + sync_mode: SyncMode::Full, pause_sync: Arc::new(AtomicBool::new(false)), // Substrate's default enable_dht_random_walk: true, diff --git a/crates/subspace-service/src/lib.rs b/crates/subspace-service/src/lib.rs index 14ec425d9d..09f6a15577 100644 --- a/crates/subspace-service/src/lib.rs +++ b/crates/subspace-service/src/lib.rs @@ -52,6 +52,7 @@ use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi; use parking_lot::Mutex; use prometheus_client::registry::Registry; use sc_basic_authorship::ProposerFactory; +use sc_chain_spec::GenesisBlockBuilder; use sc_client_api::execution_extensions::ExtensionsFactory; use sc_client_api::{ AuxStore, Backend, BlockBackend, BlockchainEvents, ExecutorProvider, HeaderBackend, @@ -459,9 +460,12 @@ type PartialComponents = sc_service::PartialComponents< >; /// Creates `PartialComponents` for Subspace client. -#[allow(clippy::type_complexity)] pub fn new_partial( + // TODO: Stop using `Configuration` once + // https://github.com/paritytech/polkadot-sdk/pull/5364 is in our fork config: &Configuration, + // TODO: Replace with check for `ChainSyncMode` once we get rid of ^ `Configuration` + snap_sync: bool, pot_external_entropy: &[u8], ) -> Result, ServiceError> where @@ -495,11 +499,23 @@ where let executor = sc_service::new_wasm_executor(config); let domains_executor = sc_service::new_wasm_executor(config); + let backend = sc_service::new_db_backend(config.db_config())?; + + let genesis_block_builder = GenesisBlockBuilder::new( + config.chain_spec.as_storage_builder(), + !snap_sync, + backend.clone(), + executor.clone(), + )?; + let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts_with_genesis_builder::( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor.clone(), + backend, + genesis_block_builder, + false, )?; let kzg = tokio::task::block_in_place(|| Kzg::new(embedded_kzg_settings())); diff --git a/crates/subspace-service/src/sync_from_dsn/snap_sync.rs b/crates/subspace-service/src/sync_from_dsn/snap_sync.rs index 7cc324b7d6..9130d1d18b 100644 --- a/crates/subspace-service/src/sync_from_dsn/snap_sync.rs +++ b/crates/subspace-service/src/sync_from_dsn/snap_sync.rs @@ -10,9 +10,7 @@ use sc_consensus::{ }; use sc_consensus_subspace::archiver::{decode_block, SegmentHeadersStore}; use sc_network::{NetworkRequest, PeerId}; -use sc_network_sync::service::syncing_service::SyncRestartArgs; use sc_network_sync::SyncingService; -use sc_service::config::SyncMode; use sc_service::{ClientExt, Error}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; @@ -90,15 +88,6 @@ pub(crate) async fn snap_sync( } else { debug!("Snap sync can only work with genesis state, skipping"); } - - // Switch back to full sync mode - let info = client.info(); - sync_service - .restart(SyncRestartArgs { - sync_mode: SyncMode::Full, - new_best_block: Some(info.best_number), - }) - .await; } // Get blocks from the last segment or from the segment containing the target block.