Skip to content

Commit b19bd7d

Browse files
committed
refactor: drop DashSpvClient.sync_to_tip
It's basically doing nothing except logging some things.
1 parent 9f1a9b4 commit b19bd7d

19 files changed

Lines changed: 14 additions & 347 deletions

dash-spv-ffi/FFI_API.md

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document provides a comprehensive reference for all FFI (Foreign Function I
44

55
**Auto-generated**: This documentation is automatically generated from the source code. Do not edit manually.
66

7-
**Total Functions**: 68
7+
**Total Functions**: 67
88

99
## Table of Contents
1010

@@ -66,14 +66,13 @@ Functions: 25
6666

6767
### Synchronization
6868

69-
Functions: 7
69+
Functions: 6
7070

7171
| Function | Description | Module |
7272
|----------|-------------|--------|
7373
| `dash_spv_ffi_client_cancel_sync` | Cancels the sync operation | client |
7474
| `dash_spv_ffi_client_get_sync_progress` | Get the current sync progress snapshot | client |
7575
| `dash_spv_ffi_client_is_filter_sync_available` | Check if compact filter sync is currently available | client |
76-
| `dash_spv_ffi_client_sync_to_tip` | Sync the SPV client to the chain tip | client |
7776
| `dash_spv_ffi_client_sync_to_tip_with_progress` | Sync the SPV client to the chain tip with detailed progress updates | client |
7877
| `dash_spv_ffi_client_test_sync` | Performs a test synchronization of the SPV client # Parameters - `client`:... | client |
7978
| `dash_spv_ffi_sync_progress_destroy` | Destroy a `FFISyncProgress` object returned by this crate | client |
@@ -661,22 +660,6 @@ Check if compact filter sync is currently available. # Safety - `client` must b
661660
662661
---
663662
664-
#### `dash_spv_ffi_client_sync_to_tip`
665-
666-
```c
667-
dash_spv_ffi_client_sync_to_tip(client: *mut FFIDashSpvClient, completion_callback: Option<extern "C" fn(bool, *const c_char, *mut c_void)>, user_data: *mut c_void,) -> i32
668-
```
669-
670-
**Description:**
671-
Sync the SPV client to the chain tip. # Safety This function is unsafe because: - `client` must be a valid pointer to an initialized `FFIDashSpvClient` - `user_data` must satisfy thread safety requirements: - If non-null, it must point to data that is safe to access from multiple threads - The caller must ensure proper synchronization if the data is mutable - The data must remain valid for the entire duration of the sync operation - `completion_callback` must be thread-safe and can be called from any thread # Parameters - `client`: Pointer to the SPV client - `completion_callback`: Optional callback invoked on completion - `user_data`: Optional user data pointer passed to callbacks # Returns 0 on success, error code on failure
672-
673-
**Safety:**
674-
This function is unsafe because: - `client` must be a valid pointer to an initialized `FFIDashSpvClient` - `user_data` must satisfy thread safety requirements: - If non-null, it must point to data that is safe to access from multiple threads - The caller must ensure proper synchronization if the data is mutable - The data must remain valid for the entire duration of the sync operation - `completion_callback` must be thread-safe and can be called from any thread
675-
676-
**Module:** `client`
677-
678-
---
679-
680663
#### `dash_spv_ffi_client_sync_to_tip_with_progress`
681664
682665
```c
@@ -1258,9 +1241,6 @@ if (result != 0) {
12581241
// Handle error
12591242
}
12601243
1261-
// Sync to chain tip
1262-
dash_spv_ffi_client_sync_to_tip(client, NULL, NULL);
1263-
12641244
// Get wallet manager (shares ownership with the client)
12651245
FFIWalletManager* wallet_manager = dash_spv_ffi_client_get_wallet_manager(client);
12661246

dash-spv-ffi/FFI_DOCS_README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,6 @@ When adding new FFI functions:
7373
4. Run `make update-docs` to regenerate documentation
7474
5. Commit both the code changes and updated `FFI_API.md`
7575

76-
## Example FFI Function
77-
78-
```rust
79-
/// Sync the SPV client to the chain tip
80-
///
81-
/// # Safety
82-
///
83-
/// - `client` must be a valid pointer to an FFIDashSpvClient
84-
/// - `on_progress` callback may be invoked from any thread
85-
/// - `on_completion` will be called exactly once
86-
#[no_mangle]
87-
pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip(
88-
client: *mut FFIDashSpvClient,
89-
on_progress: Option<SyncProgressCallback>,
90-
on_completion: Option<CompletionCallback>,
91-
) -> i32 {
92-
// Implementation
93-
}
94-
```
95-
9676
## CI/CD Integration
9777

9878
The documentation verification is integrated into the CI pipeline:

dash-spv-ffi/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ dash_spv_ffi_config_destroy(config);
9090
- `dash_spv_ffi_client_new(config)` - Create new client
9191
- `dash_spv_ffi_client_start(client)` - Start the client
9292
- `dash_spv_ffi_client_stop(client)` - Stop the client
93-
- `dash_spv_ffi_client_sync_to_tip(client, callbacks)` - Sync to chain tip
9493
- `dash_spv_ffi_client_get_sync_progress(client)` - Get sync progress
9594
- `dash_spv_ffi_client_get_stats(client)` - Get client statistics
9695
- `dash_spv_ffi_client_destroy(client)` - Free client memory

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -322,35 +322,6 @@ int32_t dash_spv_ffi_client_update_config(struct FFIDashSpvClient *client,
322322
*/
323323
int32_t dash_spv_ffi_client_stop(struct FFIDashSpvClient *client) ;
324324

325-
/**
326-
* Sync the SPV client to the chain tip.
327-
*
328-
* # Safety
329-
*
330-
* This function is unsafe because:
331-
* - `client` must be a valid pointer to an initialized `FFIDashSpvClient`
332-
* - `user_data` must satisfy thread safety requirements:
333-
* - If non-null, it must point to data that is safe to access from multiple threads
334-
* - The caller must ensure proper synchronization if the data is mutable
335-
* - The data must remain valid for the entire duration of the sync operation
336-
* - `completion_callback` must be thread-safe and can be called from any thread
337-
*
338-
* # Parameters
339-
*
340-
* - `client`: Pointer to the SPV client
341-
* - `completion_callback`: Optional callback invoked on completion
342-
* - `user_data`: Optional user data pointer passed to callbacks
343-
*
344-
* # Returns
345-
*
346-
* 0 on success, error code on failure
347-
*/
348-
349-
int32_t dash_spv_ffi_client_sync_to_tip(struct FFIDashSpvClient *client,
350-
void (*completion_callback)(bool, const char*, void*),
351-
void *user_data)
352-
;
353-
354325
/**
355326
* Performs a test synchronization of the SPV client
356327
*

dash-spv-ffi/scripts/generate_ffi_docs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ def generate_markdown(functions: List[FFIFunction]) -> str:
317317
md.append(" // Handle error")
318318
md.append("}")
319319
md.append("")
320-
md.append("// Sync to chain tip")
321-
md.append("dash_spv_ffi_client_sync_to_tip(client, NULL, NULL);")
322-
md.append("")
323320
md.append("// Get wallet manager (shares ownership with the client)")
324321
md.append("FFIWalletManager* wallet_manager = dash_spv_ffi_client_get_wallet_manager(client);")
325322
md.append("")

dash-spv-ffi/src/client.rs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ enum CallbackInfo {
4444
completion_callback: Option<extern "C" fn(bool, *const c_char, *mut c_void)>,
4545
user_data: *mut c_void,
4646
},
47-
/// Simple progress callbacks (used by sync_to_tip)
48-
Simple {
49-
completion_callback: Option<extern "C" fn(bool, *const c_char, *mut c_void)>,
50-
user_data: *mut c_void,
51-
},
5247
}
5348

5449
/// # Safety
@@ -541,115 +536,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_stop(client: *mut FFIDashSpvClient)
541536
}
542537
}
543538

544-
/// Sync the SPV client to the chain tip.
545-
///
546-
/// # Safety
547-
///
548-
/// This function is unsafe because:
549-
/// - `client` must be a valid pointer to an initialized `FFIDashSpvClient`
550-
/// - `user_data` must satisfy thread safety requirements:
551-
/// - If non-null, it must point to data that is safe to access from multiple threads
552-
/// - The caller must ensure proper synchronization if the data is mutable
553-
/// - The data must remain valid for the entire duration of the sync operation
554-
/// - `completion_callback` must be thread-safe and can be called from any thread
555-
///
556-
/// # Parameters
557-
///
558-
/// - `client`: Pointer to the SPV client
559-
/// - `completion_callback`: Optional callback invoked on completion
560-
/// - `user_data`: Optional user data pointer passed to callbacks
561-
///
562-
/// # Returns
563-
///
564-
/// 0 on success, error code on failure
565-
#[no_mangle]
566-
pub unsafe extern "C" fn dash_spv_ffi_client_sync_to_tip(
567-
client: *mut FFIDashSpvClient,
568-
completion_callback: Option<extern "C" fn(bool, *const c_char, *mut c_void)>,
569-
user_data: *mut c_void,
570-
) -> i32 {
571-
null_check!(client);
572-
573-
let client = &(*client);
574-
let inner = client.inner.clone();
575-
let runtime = client.runtime.clone();
576-
577-
// Register callbacks in the global registry for safe lifetime management
578-
let callback_info = CallbackInfo::Simple {
579-
completion_callback,
580-
user_data,
581-
};
582-
let callback_id = CALLBACK_REGISTRY.lock().unwrap().register(callback_info);
583-
584-
// Execute sync in the runtime
585-
let result = runtime.block_on(async {
586-
let mut spv_client = {
587-
let mut guard = inner.lock().unwrap();
588-
match guard.take() {
589-
Some(client) => client,
590-
None => {
591-
return Err(dash_spv::SpvError::Storage(dash_spv::StorageError::NotFound(
592-
"Client not initialized".to_string(),
593-
)))
594-
}
595-
}
596-
};
597-
match spv_client.sync_to_tip().await {
598-
Ok(_sync_result) => {
599-
// sync_to_tip returns a SyncResult, not a stream
600-
// Progress callbacks removed as sync_to_tip doesn't provide real progress updates
601-
602-
// Report completion and unregister callbacks
603-
let mut registry = CALLBACK_REGISTRY.lock().unwrap();
604-
if let Some(CallbackInfo::Simple {
605-
completion_callback: Some(callback),
606-
user_data,
607-
}) = registry.unregister(callback_id)
608-
{
609-
let msg = CString::new("Sync completed successfully").unwrap_or_else(|_| {
610-
CString::new("Sync completed").expect("hardcoded string is safe")
611-
});
612-
callback(true, msg.as_ptr(), user_data);
613-
}
614-
615-
// Put client back
616-
let mut guard = inner.lock().unwrap();
617-
*guard = Some(spv_client);
618-
619-
Ok(())
620-
}
621-
Err(e) => {
622-
// Report error and unregister callbacks
623-
let mut registry = CALLBACK_REGISTRY.lock().unwrap();
624-
if let Some(CallbackInfo::Simple {
625-
completion_callback: Some(callback),
626-
user_data,
627-
}) = registry.unregister(callback_id)
628-
{
629-
let msg = match CString::new(format!("Sync failed: {}", e)) {
630-
Ok(s) => s,
631-
Err(_) => CString::new("Sync failed").expect("hardcoded string is safe"),
632-
};
633-
callback(false, msg.as_ptr(), user_data);
634-
}
635-
636-
// Put client back
637-
let mut guard = inner.lock().unwrap();
638-
*guard = Some(spv_client);
639-
Err(e)
640-
}
641-
}
642-
});
643-
644-
match result {
645-
Ok(()) => FFIErrorCode::Success as i32,
646-
Err(e) => {
647-
set_last_error(&e.to_string());
648-
FFIErrorCode::from(e) as i32
649-
}
650-
}
651-
}
652-
653539
/// Performs a test synchronization of the SPV client
654540
///
655541
/// # Parameters
@@ -668,7 +554,7 @@ pub unsafe extern "C" fn dash_spv_ffi_client_test_sync(client: *mut FFIDashSpvCl
668554

669555
let client = &(*client);
670556
let result = client.runtime.block_on(async {
671-
let mut spv_client = {
557+
let spv_client = {
672558
let mut guard = client.inner.lock().unwrap();
673559
match guard.take() {
674560
Some(client) => client,
@@ -689,18 +575,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_test_sync(client: *mut FFIDashSpvCl
689575
};
690576
tracing::info!("Initial height: {}", start_height);
691577

692-
// Start sync
693-
match spv_client.sync_to_tip().await {
694-
Ok(_) => tracing::info!("Sync started successfully"),
695-
Err(e) => {
696-
tracing::error!("Failed to start sync: {}", e);
697-
// put back before returning
698-
let mut guard = client.inner.lock().unwrap();
699-
*guard = Some(spv_client);
700-
return Err(e);
701-
}
702-
}
703-
704578
// Wait a bit for headers to download
705579
tokio::time::sleep(Duration::from_secs(10)).await;
706580

dash-spv-ffi/tests/c_tests/test_advanced.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,9 @@ void test_callbacks_with_operations() {
299299
FFIDashSpvClient* client = dash_spv_ffi_client_new(config);
300300
TEST_ASSERT(client != NULL);
301301

302-
CallbackData callback_data = {0};
303-
304-
FFICallbacks callbacks = {0};
305-
callbacks.on_progress = real_progress_callback;
306-
callbacks.on_completion = real_completion_callback;
307-
callbacks.on_data = NULL;
308-
callbacks.user_data = &callback_data;
309-
310-
// Start sync operation
311-
int32_t result = dash_spv_ffi_client_sync_to_tip(client, callbacks);
312-
313302
// Wait a bit for callbacks
314303
usleep(100000); // 100ms
315304

316-
// Callbacks might or might not be called depending on network
317-
printf("Progress callbacks: %d, Completion: %d\n",
318-
callback_data.progress_count,
319-
callback_data.completion_called);
320-
321305
dash_spv_ffi_client_destroy(client);
322306
dash_spv_ffi_config_destroy(config);
323307

dash-spv-ffi/tests/integration/test_full_workflow.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ mod tests {
100100
// Start the client
101101
let result = dash_spv_ffi_client_start(ctx.client);
102102

103-
// Start syncing
104-
let sync_result = dash_spv_ffi_client_sync_to_tip(ctx.client, callbacks);
105-
106103
// Wait for sync to complete or timeout
107104
let start = Instant::now();
108105
let timeout = Duration::from_secs(10);
@@ -391,11 +388,7 @@ mod tests {
391388
// 1. Start without peers
392389
let result = dash_spv_ffi_client_start(ctx.client);
393390

394-
// 2. Try to sync without being started (if not started above)
395-
let callbacks = FFICallbacks::default();
396-
let sync_result = dash_spv_ffi_client_sync_to_tip(ctx.client, callbacks);
397-
398-
// 3. Add invalid address
391+
// 2. Add invalid address
399392
let invalid_addr = CString::new("invalid_address").unwrap();
400393
let watch_result = dash_spv_ffi_client_watch_address(ctx.client, invalid_addr.as_ptr());
401394
assert_eq!(watch_result, FFIErrorCode::InvalidArgument as i32);
@@ -516,17 +509,6 @@ mod tests {
516509
// Start with network issues
517510
let start_result = dash_spv_ffi_client_start(ctx.client);
518511

519-
// Try to sync with poor connectivity
520-
let sync_start = Instant::now();
521-
let callbacks = FFICallbacks {
522-
on_progress: None,
523-
on_completion: None,
524-
on_data: None,
525-
user_data: std::ptr::null_mut(),
526-
};
527-
528-
dash_spv_ffi_client_sync_to_tip(ctx.client, callbacks);
529-
530512
// Should handle timeouts gracefully
531513
thread::sleep(Duration::from_secs(3));
532514

dash-spv-ffi/tests/test_event_callbacks.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ fn test_event_callbacks_setup() {
186186

187187
println!("Client started, waiting for events...");
188188

189-
// Try to sync for a short time to see if we get any events
190-
println!("Starting sync to trigger events...");
191-
let sync_result = dash_spv_ffi_client_test_sync(client);
192-
if sync_result != 0 {
193-
println!("Warning: Test sync failed");
194-
}
195-
196189
// Wait a bit for events to be processed
197190
thread::sleep(Duration::from_secs(5));
198191

0 commit comments

Comments
 (0)