Skip to content

Commit e24799d

Browse files
authored
refactor: Rename HeaderSyncManagerWithReorg -> HeaderSyncManager (#221)
1 parent 8520482 commit e24799d

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

dash-spv/src/sync/headers_with_reorg.rs renamed to dash-spv/src/sync/headers.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//! Header synchronization with reorganization support
2-
//!
3-
//! This module extends the basic header sync with fork detection and reorg handling.
1+
//! Header synchronization with fork detection and reorganization handling.
42
53
use dashcore::{
64
block::{Header as BlockHeader, Version},
@@ -45,8 +43,8 @@ impl Default for ReorgConfig {
4543
}
4644
}
4745

48-
/// Manages header synchronization with reorg support
49-
pub struct HeaderSyncManagerWithReorg<S: StorageManager, N: NetworkManager> {
46+
/// Manages header synchronization with fork detection and reorganization support
47+
pub struct HeaderSyncManager<S: StorageManager, N: NetworkManager> {
5048
_phantom_s: std::marker::PhantomData<S>,
5149
_phantom_n: std::marker::PhantomData<N>,
5250
config: ClientConfig,
@@ -67,9 +65,9 @@ pub struct HeaderSyncManagerWithReorg<S: StorageManager, N: NetworkManager> {
6765
}
6866

6967
impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync + 'static>
70-
HeaderSyncManagerWithReorg<S, N>
68+
HeaderSyncManager<S, N>
7169
{
72-
/// Create a new header sync manager with reorg support
70+
/// Create a new header sync manager
7371
pub fn new(
7472
config: &ClientConfig,
7573
reorg_config: ReorgConfig,
@@ -229,14 +227,14 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
229227
Ok(loaded_count)
230228
}
231229

232-
/// Handle a Headers message with fork detection and reorg support
230+
/// Handle a Headers message
233231
pub async fn handle_headers_message(
234232
&mut self,
235233
headers: Vec<BlockHeader>,
236234
storage: &mut S,
237235
network: &mut N,
238236
) -> SyncResult<bool> {
239-
tracing::info!("🔍 Handle headers message with {} headers (reorg-aware)", headers.len());
237+
tracing::info!("🔍 Handle headers message with {} headers", headers.len());
240238

241239
// Step 1: Handle Empty Batch
242240
if headers.is_empty() {
@@ -656,7 +654,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
656654
return Err(SyncError::SyncInProgress);
657655
}
658656

659-
tracing::info!("Preparing header synchronization with reorg support");
657+
tracing::info!("Preparing header synchronization");
660658
tracing::info!(
661659
"Chain state before prepare_sync: sync_base_height={}, synced_from_checkpoint={}, headers_count={}",
662660
self.get_sync_base_height(),
@@ -804,7 +802,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
804802
self.syncing_headers = true;
805803
self.last_sync_progress = std::time::Instant::now();
806804
tracing::info!(
807-
"✅ Prepared header sync state with reorg support, ready to request headers from {:?}",
805+
"✅ Prepared header sync state, ready to request headers from {:?}",
808806
base_hash
809807
);
810808

@@ -813,7 +811,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
813811

814812
/// Start synchronizing headers (initialize the sync state).
815813
pub async fn start_sync(&mut self, network: &mut N, storage: &mut S) -> SyncResult<bool> {
816-
tracing::info!("Starting header synchronization with reorg support");
814+
tracing::info!("Starting header synchronization");
817815

818816
// Prepare sync state (this will check if sync is already in progress)
819817
let base_hash = self.prepare_sync(storage).await?;

dash-spv/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
pub mod embedded_data;
77
pub mod filters;
8+
pub mod headers;
89
pub mod headers2_state;
9-
pub mod headers_with_reorg;
1010
pub mod masternodes;
1111
pub mod sequential;
1212
pub use filters::FilterSyncManager;
13-
pub use headers_with_reorg::{HeaderSyncManagerWithReorg, ReorgConfig};
13+
pub use headers::{HeaderSyncManager, ReorgConfig};
1414
pub use masternodes::MasternodeSyncManager;

dash-spv/src/sync/sequential/lifecycle.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::client::ClientConfig;
88
use crate::error::{SyncError, SyncResult};
99
use crate::network::NetworkManager;
1010
use crate::storage::StorageManager;
11-
use crate::sync::{
12-
FilterSyncManager, HeaderSyncManagerWithReorg, MasternodeSyncManager, ReorgConfig,
13-
};
11+
use crate::sync::{FilterSyncManager, HeaderSyncManager, MasternodeSyncManager, ReorgConfig};
1412
use crate::types::{SharedFilterHeights, SpvStats};
1513
use key_wallet_manager::{wallet_interface::WalletInterface, Network as WalletNetwork};
1614
use std::sync::Arc;
@@ -40,10 +38,9 @@ impl<
4038
Ok(Self {
4139
current_phase: SyncPhase::Idle,
4240
transition_manager: TransitionManager::new(config),
43-
header_sync: HeaderSyncManagerWithReorg::new(config, reorg_config, chain_state)
44-
.map_err(|e| {
45-
SyncError::InvalidState(format!("Failed to create header sync manager: {}", e))
46-
})?,
41+
header_sync: HeaderSyncManager::new(config, reorg_config, chain_state).map_err(
42+
|e| SyncError::InvalidState(format!("Failed to create header sync manager: {}", e)),
43+
)?,
4744
filter_sync: FilterSyncManager::new(config, received_filter_heights),
4845
masternode_sync: MasternodeSyncManager::new(config),
4946
config: config.clone(),

dash-spv/src/sync/sequential/manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::client::ClientConfig;
66
use crate::error::SyncResult;
77
use crate::network::NetworkManager;
88
use crate::storage::StorageManager;
9-
use crate::sync::{FilterSyncManager, HeaderSyncManagerWithReorg, MasternodeSyncManager};
9+
use crate::sync::{FilterSyncManager, HeaderSyncManager, MasternodeSyncManager};
1010
use crate::types::SyncProgress;
1111
use key_wallet_manager::wallet_interface::WalletInterface;
1212

@@ -47,7 +47,7 @@ pub(super) const CHAINLOCK_VALIDATION_MASTERNODE_OFFSET: u32 = 8;
4747
/// - Optimize across trait boundaries
4848
///
4949
/// ### 3. **Delegation Pattern** 🔗
50-
/// The sync manager delegates to specialized sub-managers (`HeaderSyncManagerWithReorg`,
50+
/// The sync manager delegates to specialized sub-managers (`HeaderSyncManager`,
5151
/// `FilterSyncManager`, `MasternodeSyncManager`), each also generic over `S` and `N`.
5252
/// This maintains type consistency throughout the sync pipeline.
5353
///
@@ -68,7 +68,7 @@ pub struct SequentialSyncManager<S: StorageManager, N: NetworkManager, W: Wallet
6868
pub(super) transition_manager: TransitionManager,
6969

7070
/// Existing sync managers (wrapped and controlled)
71-
pub(super) header_sync: HeaderSyncManagerWithReorg<S, N>,
71+
pub(super) header_sync: HeaderSyncManager<S, N>,
7272
pub(super) filter_sync: FilterSyncManager<S, N>,
7373
pub(super) masternode_sync: MasternodeSyncManager<S, N>,
7474

0 commit comments

Comments
 (0)