Skip to content

Commit 245a330

Browse files
authored
chore: remove legacy sync code (#414)
* remove legacy sync module * remove related code
1 parent 2bd764f commit 245a330

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+31
-13374
lines changed

dash-spv-ffi/FFI_API.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ Release a wallet manager obtained from `dash_spv_ffi_client_get_wallet_manager`.
999999
- `FFINetwork` - Network type (Dash, Testnet, Regtest, Devnet)
10001000
- `FFIValidationMode` - Validation mode (None, Basic, Full)
10011001
- `FFIMempoolStrategy` - Mempool strategy (FetchAll, BloomFilter, Selective)
1002-
- `FFISyncStage` - Synchronization stage
10031002
10041003
## Memory Management
10051004

dash-spv-ffi/scripts/generate_ffi_docs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ def generate_markdown(functions: List[FFIFunction]) -> str:
279279
md.append("- `FFINetwork` - Network type (Dash, Testnet, Regtest, Devnet)")
280280
md.append("- `FFIValidationMode` - Validation mode (None, Basic, Full)")
281281
md.append("- `FFIMempoolStrategy` - Mempool strategy (FetchAll, BloomFilter, Selective)")
282-
md.append("- `FFISyncStage` - Synchronization stage")
283282
md.append("")
284283

285284
# Memory Management

dash-spv-ffi/src/client.rs

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use dash_spv::Hash;
1313
use futures::future::{AbortHandle, Abortable};
1414
use std::sync::{Arc, Mutex};
1515
use std::thread::JoinHandle;
16-
use std::time::Duration;
1716
use tokio::runtime::Handle;
1817
use tokio::runtime::Runtime;
1918
use tokio::sync::{broadcast, watch};
@@ -355,70 +354,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_stop(client: *mut FFIDashSpvClient)
355354
}
356355
}
357356

358-
pub fn client_test_sync(client: &FFIDashSpvClient) -> i32 {
359-
let result = client.runtime.block_on(async {
360-
let spv_client = {
361-
let mut guard = client.inner.lock().unwrap();
362-
match guard.take() {
363-
Some(client) => client,
364-
None => {
365-
return Err(dash_spv::SpvError::Config("Client not initialized".to_string()))
366-
}
367-
}
368-
};
369-
tracing::info!("Starting test sync...");
370-
371-
// Get initial height
372-
let progress = spv_client.sync_progress();
373-
let start_height = match progress.headers() {
374-
Ok(progress) => progress.current_height(),
375-
Err(e) => {
376-
tracing::error!("Failed to get initial height: {}", e);
377-
return Err(e.into());
378-
}
379-
};
380-
tracing::info!("Initial height: {}", start_height);
381-
382-
// Wait a bit for headers to download
383-
tokio::time::sleep(Duration::from_secs(10)).await;
384-
385-
// Check if headers increased
386-
let progress = spv_client.sync_progress();
387-
let end_height = match progress.headers() {
388-
Ok(progress) => progress.current_height(),
389-
Err(e) => {
390-
tracing::error!("Failed to get final height: {}", e);
391-
let mut guard = client.inner.lock().unwrap();
392-
*guard = Some(spv_client);
393-
return Err(e.into());
394-
}
395-
};
396-
tracing::info!("Final height: {}", end_height);
397-
398-
let result = if end_height > start_height {
399-
tracing::info!("✅ Sync working! Downloaded {} headers", end_height - start_height);
400-
Ok(())
401-
} else {
402-
let msg = "No headers downloaded".to_string();
403-
tracing::error!("❌ {}", msg);
404-
Err(dash_spv::SpvError::Sync(dash_spv::SyncError::Network(msg)))
405-
};
406-
407-
// put client back
408-
let mut guard = client.inner.lock().unwrap();
409-
*guard = Some(spv_client);
410-
result
411-
});
412-
413-
match result {
414-
Ok(_) => FFIErrorCode::Success as i32,
415-
Err(e) => {
416-
set_last_error(&e.to_string());
417-
FFIErrorCode::from(e) as i32
418-
}
419-
}
420-
}
421-
422357
/// Start the SPV client and begin syncing in the background.
423358
///
424359
/// This is the streamlined entry point that combines `start()` and continuous monitoring

dash-spv-ffi/src/types.rs

Lines changed: 1 addition & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use dash_spv::sync::{
33
BlockHeadersProgress, BlocksProgress, ChainLockProgress, FilterHeadersProgress,
44
FiltersProgress, InstantSendProgress, MasternodesProgress, SyncProgress, SyncState,
55
};
6-
use dash_spv::types::{DetailedSyncProgress, MempoolRemovalReason, SyncStage};
7-
use dash_spv::SyncProgress as LegacySyncProgress;
6+
use dash_spv::types::MempoolRemovalReason;
87
use std::ffi::{CStr, CString};
98
use std::os::raw::c_char;
109

@@ -46,75 +45,6 @@ impl FFIString {
4645
}
4746
}
4847

49-
#[repr(C)]
50-
pub struct FFILegacySyncProgress {
51-
pub header_height: u32,
52-
pub filter_header_height: u32,
53-
pub masternode_height: u32,
54-
pub peer_count: u32,
55-
pub filter_sync_available: bool,
56-
pub filters_downloaded: u32,
57-
pub last_synced_filter_height: u32,
58-
}
59-
60-
impl From<LegacySyncProgress> for FFILegacySyncProgress {
61-
fn from(progress: LegacySyncProgress) -> Self {
62-
FFILegacySyncProgress {
63-
header_height: progress.header_height,
64-
filter_header_height: progress.filter_header_height,
65-
masternode_height: progress.masternode_height,
66-
peer_count: progress.peer_count,
67-
filter_sync_available: progress.filter_sync_available,
68-
filters_downloaded: progress.filters_downloaded as u32,
69-
last_synced_filter_height: progress.last_synced_filter_height.unwrap_or(0),
70-
}
71-
}
72-
}
73-
74-
#[repr(C)]
75-
#[derive(Debug, Clone, Copy)]
76-
pub enum FFISyncStage {
77-
Connecting = 0,
78-
QueryingHeight = 1,
79-
Downloading = 2,
80-
Validating = 3,
81-
Storing = 4,
82-
DownloadingFilterHeaders = 5,
83-
DownloadingFilters = 6,
84-
DownloadingBlocks = 7,
85-
Complete = 8,
86-
Failed = 9,
87-
}
88-
89-
impl From<SyncStage> for FFISyncStage {
90-
fn from(stage: SyncStage) -> Self {
91-
match stage {
92-
SyncStage::Connecting => FFISyncStage::Connecting,
93-
SyncStage::QueryingPeerHeight => FFISyncStage::QueryingHeight,
94-
SyncStage::DownloadingHeaders {
95-
..
96-
} => FFISyncStage::Downloading,
97-
SyncStage::ValidatingHeaders {
98-
..
99-
} => FFISyncStage::Validating,
100-
SyncStage::StoringHeaders {
101-
..
102-
} => FFISyncStage::Storing,
103-
SyncStage::DownloadingFilterHeaders {
104-
..
105-
} => FFISyncStage::DownloadingFilterHeaders,
106-
SyncStage::DownloadingFilters {
107-
..
108-
} => FFISyncStage::DownloadingFilters,
109-
SyncStage::DownloadingBlocks {
110-
..
111-
} => FFISyncStage::DownloadingBlocks,
112-
SyncStage::Complete => FFISyncStage::Complete,
113-
SyncStage::Failed(_) => FFISyncStage::Failed,
114-
}
115-
}
116-
}
117-
11848
/// SyncState exposed by the FFI as FFISyncState.
11949
#[repr(C)]
12050
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
@@ -404,74 +334,6 @@ impl From<SyncProgress> for FFISyncProgress {
404334
}
405335
}
406336

407-
#[repr(C)]
408-
pub struct FFIDetailedSyncProgress {
409-
pub total_height: u32,
410-
pub percentage: f64,
411-
pub headers_per_second: f64,
412-
pub estimated_seconds_remaining: i64, // -1 if unknown
413-
pub stage: FFISyncStage,
414-
pub stage_message: FFIString,
415-
pub overview: FFILegacySyncProgress,
416-
pub total_headers: u64,
417-
pub sync_start_timestamp: i64,
418-
}
419-
420-
impl From<DetailedSyncProgress> for FFIDetailedSyncProgress {
421-
fn from(progress: DetailedSyncProgress) -> Self {
422-
use std::time::UNIX_EPOCH;
423-
424-
let stage_message = match &progress.sync_stage {
425-
SyncStage::Connecting => "Connecting to peers".to_string(),
426-
SyncStage::QueryingPeerHeight => "Querying blockchain height".to_string(),
427-
SyncStage::DownloadingHeaders {
428-
start,
429-
end,
430-
} => format!("Downloading headers {} to {}", start, end),
431-
SyncStage::ValidatingHeaders {
432-
batch_size,
433-
} => format!("Validating {} headers", batch_size),
434-
SyncStage::StoringHeaders {
435-
batch_size,
436-
} => format!("Storing {} headers", batch_size),
437-
SyncStage::DownloadingFilterHeaders {
438-
current,
439-
target,
440-
} => format!("Downloading filter headers {} / {}", current, target),
441-
SyncStage::DownloadingFilters {
442-
completed,
443-
total,
444-
} => format!("Downloading filters {} / {}", completed, total),
445-
SyncStage::DownloadingBlocks {
446-
pending,
447-
} => format!("Downloading blocks ({} pending)", pending),
448-
SyncStage::Complete => "Synchronization complete".to_string(),
449-
SyncStage::Failed(err) => err.clone(),
450-
};
451-
452-
let overview = FFILegacySyncProgress::from(progress.sync_progress.clone());
453-
454-
FFIDetailedSyncProgress {
455-
total_height: progress.peer_best_height,
456-
percentage: progress.percentage,
457-
headers_per_second: progress.headers_per_second,
458-
estimated_seconds_remaining: progress
459-
.estimated_time_remaining
460-
.map(|d| d.as_secs() as i64)
461-
.unwrap_or(-1),
462-
stage: progress.sync_stage.into(),
463-
stage_message: FFIString::new(&stage_message),
464-
overview,
465-
total_headers: progress.total_headers_processed,
466-
sync_start_timestamp: progress
467-
.sync_start_time
468-
.duration_since(UNIX_EPOCH)
469-
.unwrap_or(std::time::Duration::from_secs(0))
470-
.as_secs() as i64,
471-
}
472-
}
473-
}
474-
475337
/// # Safety
476338
/// - `s.ptr` must be a pointer previously returned by `FFIString::new` or compatible.
477339
/// - It must not be used after this call.

dash-spv-ffi/tests/test_client.rs

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod tests {
44
use key_wallet_ffi::FFINetwork;
55
use serial_test::serial;
66
use std::ffi::CString;
7-
use std::os::raw::c_void;
87
use std::sync::{Arc, Mutex};
98
use tempfile::TempDir;
109

@@ -14,25 +13,6 @@ mod tests {
1413
last_progress: Arc<Mutex<f64>>,
1514
}
1615

17-
extern "C" fn _test_progress_callback(
18-
progress: f64,
19-
_message: *const std::os::raw::c_char,
20-
user_data: *mut c_void,
21-
) {
22-
let data = unsafe { &*(user_data as *const _TestCallbackData) };
23-
*data.progress_called.lock().unwrap() = true;
24-
*data.last_progress.lock().unwrap() = progress;
25-
}
26-
27-
extern "C" fn _test_completion_callback(
28-
_success: bool,
29-
_error: *const std::os::raw::c_char,
30-
user_data: *mut c_void,
31-
) {
32-
let data = unsafe { &*(user_data as *const _TestCallbackData) };
33-
*data.completion_called.lock().unwrap() = true;
34-
}
35-
3616
fn create_test_config() -> (*mut FFIClientConfig, TempDir) {
3717
let temp_dir = TempDir::new().unwrap();
3818
let config = dash_spv_ffi_config_new(FFINetwork::Regtest);
@@ -98,91 +78,4 @@ mod tests {
9878
assert!(progress.is_null());
9979
}
10080
}
101-
102-
#[test]
103-
#[serial]
104-
fn test_sync_progress() {
105-
unsafe {
106-
let (config, _temp_dir) = create_test_config();
107-
let client = dash_spv_ffi_client_new(config);
108-
109-
let progress = dash_spv_ffi_client_get_sync_progress(client);
110-
if !progress.is_null() {
111-
let _progress_ref = &*progress;
112-
// header_height and filter_header_height are u32, always >= 0
113-
dash_spv_ffi_sync_progress_destroy(progress);
114-
}
115-
116-
dash_spv_ffi_client_destroy(client);
117-
dash_spv_ffi_config_destroy(config);
118-
}
119-
}
120-
121-
#[test]
122-
#[serial]
123-
fn test_client_stats() {
124-
unsafe {
125-
let (config, _temp_dir) = create_test_config();
126-
let client = dash_spv_ffi_client_new(config);
127-
128-
dash_spv_ffi_client_destroy(client);
129-
dash_spv_ffi_config_destroy(config);
130-
}
131-
}
132-
133-
#[test]
134-
#[serial]
135-
#[ignore]
136-
fn test_sync_diagnostic() {
137-
unsafe {
138-
// Allow running this test only when explicitly enabled
139-
if std::env::var("RUST_DASH_FFI_RUN_NETWORK_TESTS").unwrap_or_default() != "1" {
140-
println!(
141-
"Skipping test_sync_diagnostic (set RUST_DASH_FFI_RUN_NETWORK_TESTS=1 to run)"
142-
);
143-
return;
144-
}
145-
146-
// Create testnet config for the diagnostic test
147-
let config = dash_spv_ffi_config_testnet();
148-
let temp_dir = TempDir::new().unwrap();
149-
let path = CString::new(temp_dir.path().to_str().unwrap()).unwrap();
150-
dash_spv_ffi_config_set_data_dir(config, path.as_ptr());
151-
152-
// Create client
153-
let client = dash_spv_ffi_client_new(config);
154-
assert!(!client.is_null(), "Failed to create client");
155-
156-
// Start the client
157-
let start_result = dash_spv_ffi_client_start(client);
158-
if start_result != FFIErrorCode::Success as i32 {
159-
println!("Warning: Failed to start client, error code: {}", start_result);
160-
let error = dash_spv_ffi_get_last_error();
161-
if !error.is_null() {
162-
let error_str = std::ffi::CStr::from_ptr(error);
163-
println!("Error message: {:?}", error_str);
164-
}
165-
}
166-
167-
// Run the diagnostic sync test
168-
println!("Running sync diagnostic test...");
169-
let test_result = client_test_sync(&*client);
170-
171-
if test_result == FFIErrorCode::Success as i32 {
172-
println!("✅ Sync test passed!");
173-
} else {
174-
println!("❌ Sync test failed with error code: {}", test_result);
175-
let error = dash_spv_ffi_get_last_error();
176-
if !error.is_null() {
177-
let error_str = std::ffi::CStr::from_ptr(error);
178-
println!("Error message: {:?}", error_str);
179-
}
180-
}
181-
182-
// Stop and cleanup
183-
let _stop_result = dash_spv_ffi_client_stop(client);
184-
dash_spv_ffi_client_destroy(client);
185-
dash_spv_ffi_config_destroy(config);
186-
}
187-
}
18881
}

0 commit comments

Comments
 (0)