Skip to content

Commit f3256e3

Browse files
more fixes
1 parent 8e4b37d commit f3256e3

File tree

9 files changed

+47
-20
lines changed

9 files changed

+47
-20
lines changed

dash-spv-ffi/dash_spv_ffi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ typedef enum FFISyncStage {
3030
Storing = 4,
3131
DownloadingFilterHeaders = 5,
3232
DownloadingFilters = 6,
33-
Complete = 7,
34-
Failed = 8,
33+
DownloadingBlocks = 7,
34+
Complete = 8,
35+
Failed = 9,
3536
} FFISyncStage;
3637

3738
typedef enum DashSpvValidationMode {

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ typedef enum FFISyncStage {
3030
Storing = 4,
3131
DownloadingFilterHeaders = 5,
3232
DownloadingFilters = 6,
33-
Complete = 7,
34-
Failed = 8,
33+
DownloadingBlocks = 7,
34+
Complete = 8,
35+
Failed = 9,
3536
} FFISyncStage;
3637

3738
typedef enum DashSpvValidationMode {

dash-spv-ffi/src/bin/ffi_cli.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::{CStr, CString};
22
use std::os::raw::{c_char, c_void};
33
use std::ptr;
4+
use std::sync::atomic::{AtomicBool, Ordering};
45
use std::thread;
56
use std::time::Duration;
67

@@ -16,6 +17,8 @@ enum NetworkOpt {
1617
Regtest,
1718
}
1819

20+
static SYNC_COMPLETED: AtomicBool = AtomicBool::new(false);
21+
1922
fn ffi_string_to_rust(s: *const c_char) -> String {
2023
if s.is_null() {
2124
return String::new();
@@ -44,6 +47,7 @@ extern "C" fn on_completion(success: bool, msg: *const c_char, _ud: *mut c_void)
4447
let m = ffi_string_to_rust(msg);
4548
if success {
4649
println!("Completed: {}", m);
50+
SYNC_COMPLETED.store(true, Ordering::SeqCst);
4751
} else {
4852
eprintln!("Failed: {}", m);
4953
}
@@ -188,6 +192,9 @@ fn main() {
188192
std::process::exit(1);
189193
}
190194

195+
// Ensure completion flag is reset before starting sync
196+
SYNC_COMPLETED.store(false, Ordering::SeqCst);
197+
191198
// Run sync on this thread; detailed progress will print via callback
192199
let rc = dash_spv_ffi_client_sync_to_tip_with_progress(
193200
client,
@@ -206,11 +213,14 @@ fn main() {
206213
let prog_ptr = dash_spv_ffi_client_get_sync_progress(client);
207214
if !prog_ptr.is_null() {
208215
let prog = &*prog_ptr;
209-
let headers_done = prog.header_height >= prog.filter_header_height;
210-
let filters_complete = prog.filter_header_height >= prog.header_height
211-
|| !prog.filter_sync_available
212-
|| disable_filter_sync;
213-
if headers_done && filters_complete {
216+
let headers_done = SYNC_COMPLETED.load(Ordering::SeqCst);
217+
let filters_complete = if disable_filter_sync || !prog.filter_sync_available {
218+
false
219+
} else {
220+
prog.filter_header_height >= prog.header_height
221+
&& prog.last_synced_filter_height >= prog.filter_header_height
222+
};
223+
if headers_done && (filters_complete || disable_filter_sync) {
214224
dash_spv_ffi_sync_progress_destroy(prog_ptr);
215225
break;
216226
}

dash-spv-ffi/src/types.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ pub enum FFISyncStage {
6767
Storing = 4,
6868
DownloadingFilterHeaders = 5,
6969
DownloadingFilters = 6,
70-
Complete = 7,
71-
Failed = 8,
70+
DownloadingBlocks = 7,
71+
Complete = 8,
72+
Failed = 9,
7273
}
7374

7475
impl From<SyncStage> for FFISyncStage {
@@ -91,6 +92,9 @@ impl From<SyncStage> for FFISyncStage {
9192
SyncStage::DownloadingFilters {
9293
..
9394
} => FFISyncStage::DownloadingFilters,
95+
SyncStage::DownloadingBlocks {
96+
..
97+
} => FFISyncStage::DownloadingBlocks,
9498
SyncStage::Complete => FFISyncStage::Complete,
9599
SyncStage::Failed(_) => FFISyncStage::Failed,
96100
}
@@ -135,6 +139,9 @@ impl From<DetailedSyncProgress> for FFIDetailedSyncProgress {
135139
completed,
136140
total,
137141
} => format!("Downloading filters {} / {}", completed, total),
142+
SyncStage::DownloadingBlocks {
143+
pending,
144+
} => format!("Downloading blocks ({} pending)", pending),
138145
SyncStage::Complete => "Synchronization complete".to_string(),
139146
SyncStage::Failed(err) => err.clone(),
140147
};

dash-spv/src/client/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ impl<
195195
SyncPhase::DownloadingBlocks {
196196
pending_blocks,
197197
..
198-
} => SyncStage::StoringHeaders {
199-
batch_size: pending_blocks.len(),
198+
} => SyncStage::DownloadingBlocks {
199+
pending: pending_blocks.len(),
200200
},
201201
SyncPhase::FullySynced {
202202
..

dash-spv/src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ pub enum SyncStage {
116116
completed: u32,
117117
total: u32,
118118
},
119+
DownloadingBlocks {
120+
pending: usize,
121+
},
119122
Complete,
120123
Failed(String),
121124
}

swift-dash-core-sdk/Sources/DashSPVFFI/include/dash_spv_ffi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ typedef enum FFISyncStage {
3030
Storing = 4,
3131
DownloadingFilterHeaders = 5,
3232
DownloadingFilters = 6,
33-
Complete = 7,
34-
Failed = 8,
33+
DownloadingBlocks = 7,
34+
Complete = 8,
35+
Failed = 9,
3536
} FFISyncStage;
3637

3738
typedef enum DashSpvValidationMode {

swift-dash-core-sdk/Sources/SwiftDashCoreSDK/Core/SPVClient.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public enum SyncStage: Equatable, Sendable {
109109
case downloading
110110
case downloadingFilterHeaders
111111
case downloadingFilters
112+
case downloadingBlocks
112113
case validating
113114
case storing
114115
case complete
@@ -131,9 +132,11 @@ public enum SyncStage: Equatable, Sendable {
131132
self = .downloadingFilterHeaders
132133
case 6: // Downloading filters
133134
self = .downloadingFilters
134-
case 7: // Complete
135+
case 7: // Downloading blocks
136+
self = .downloadingBlocks
137+
case 8: // Complete
135138
self = .complete
136-
case 8: // Failed
139+
case 9: // Failed
137140
self = .failed
138141
default:
139142
self = .failed
@@ -152,6 +155,8 @@ public enum SyncStage: Equatable, Sendable {
152155
return "Downloading filter headers"
153156
case .downloadingFilters:
154157
return "Downloading filters"
158+
case .downloadingBlocks:
159+
return "Downloading blocks"
155160
case .validating:
156161
return "Validating headers"
157162
case .storing:
@@ -184,6 +189,8 @@ public enum SyncStage: Equatable, Sendable {
184189
return "🧾"
185190
case .downloadingFilters:
186191
return "🪄"
192+
case .downloadingBlocks:
193+
return "📦"
187194
case .validating:
188195
return ""
189196
case .storing:

swift-dash-core-sdk/Sources/SwiftDashCoreSDK/Models/SyncProgress.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public struct SyncProgress: Sendable, Equatable {
2828
filterHeaderHeight: UInt32 = 0,
2929
masternodeHeight: UInt32 = 0,
3030
peerCount: UInt32 = 0,
31-
headersSynced: Bool = false,
32-
filterHeadersSynced: Bool = false,
33-
masternodesSynced: Bool = false,
3431
filtersDownloaded: UInt32 = 0,
3532
lastSyncedFilterHeight: UInt32 = 0
3633
) {

0 commit comments

Comments
 (0)