From 3dcea8e6f1da9c5c4fdd03dfc21aad509ae19aba Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Fri, 19 Jul 2024 22:36:52 +0300 Subject: [PATCH] Clear block gap proactively after DSN sync as well --- crates/subspace-service/src/sync_from_dsn.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/subspace-service/src/sync_from_dsn.rs b/crates/subspace-service/src/sync_from_dsn.rs index 8b3de1f6d7..33d81346da 100644 --- a/crates/subspace-service/src/sync_from_dsn.rs +++ b/crates/subspace-service/src/sync_from_dsn.rs @@ -13,6 +13,7 @@ use sc_client_api::{AuxStore, BlockBackend, BlockchainEvents}; use sc_consensus::import_queue::ImportQueueService; use sc_consensus_subspace::archiver::SegmentHeadersStore; use sc_network::service::traits::NetworkService; +use sc_service::ClientExt; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_consensus_subspace::{FarmerPublicKey, SubspaceApi}; @@ -84,7 +85,7 @@ enum NotificationReason { /// Create node observer that will track node state and send notifications to worker to start sync /// from DSN. #[allow(clippy::too_many_arguments)] -pub(super) fn create_observer_and_worker( +pub(super) fn create_observer_and_worker( segment_headers_store: SegmentHeadersStore, network_service: Arc, node: Node, @@ -99,11 +100,13 @@ pub(super) fn create_observer_and_worker( ) where Block: BlockT, + Backend: sc_client_api::Backend, AS: AuxStore + Send + Sync + 'static, Client: HeaderBackend + BlockBackend + BlockchainEvents + ProvideRuntimeApi + + ClientExt + Send + Sync + 'static, @@ -247,7 +250,7 @@ async fn create_substrate_network_observer( } #[allow(clippy::too_many_arguments)] -async fn create_worker( +async fn create_worker( segment_headers_store: SegmentHeadersStore, node: &Node, client: &Client, @@ -259,10 +262,12 @@ async fn create_worker( ) -> Result<(), sc_service::Error> where Block: BlockT, + Backend: sc_client_api::Backend, AS: AuxStore + Send + Sync + 'static, Client: HeaderBackend + BlockBackend + ProvideRuntimeApi + + ClientExt + Send + Sync + 'static, @@ -329,6 +334,11 @@ where } } + // Clear the block gap that arises from first block import with a much higher number than + // previously (resulting in a gap) + // TODO: This is a hack and better solution is needed: https://github.com/paritytech/polkadot-sdk/issues/4407 + client.clear_block_gap()?; + debug!("Finished DSN sync"); pause_sync.store(false, Ordering::Release);