diff --git a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs index b0093f4b81..e6a88bc1e5 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs @@ -145,22 +145,31 @@ struct HeaderSynchronisation<'a, 'b, B> { impl HeaderSynchronisation<'_, '_, B> { pub async fn synchronize(&mut self) -> Result<(), HeaderSyncError> { let tip_header = async_db::fetch_tip_header(self.db()).await?; + let tip_header_height = tip_header.height; + if tip_header_height >= self.sync_height { + debug!( + target: LOG_TARGET, + "The current tip height ({}) is greater than the requested sync height ({}). Headers already synced.", + tip_header_height, + self.sync_height + ); + return Ok(()); + } debug!( target: LOG_TARGET, "Syncing from height {} to sync height {}.", tip_header.height, self.sync_height ); trace!(target: LOG_TARGET, "Synchronizing headers"); - self.synchronize_headers(&tip_header).await?; + self.synchronize_headers(tip_header_height).await?; Ok(()) } - async fn synchronize_headers(&mut self, tip_header: &BlockHeader) -> Result<(), HeaderSyncError> { - let tip_height = tip_header.height; + async fn synchronize_headers(&mut self, tip_header_height: u64) -> Result<(), HeaderSyncError> { let config = self.shared.config.block_sync_config; - let chunks = VecChunkIter::new(tip_height + 1, self.sync_height + 1, config.header_request_size); + let chunks = VecChunkIter::new(tip_header_height + 1, self.sync_height + 1, config.header_request_size); for block_nums in chunks { let num_sync_peers = self.sync_peers.len(); for attempt in 1..=num_sync_peers { diff --git a/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync/state_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync/state_sync.rs index 955fbf8bfe..c7d517c02d 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync/state_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync/state_sync.rs @@ -392,6 +392,12 @@ impl HorizonStateSynchronization<'_, '_, '_, B> config.max_sync_request_retry_attempts, ) .await?; + + if local_num_utxo_nodes >= remote_num_utxo_nodes { + debug!(target: LOG_TARGET, "UTXOs and range proofs are already synchronized."); + return Ok(()); + } + debug!( target: LOG_TARGET, "Synchronizing {} UTXO MMR nodes from {} to {}",