Skip to content

Commit 84a9552

Browse files
authored
chore: Drop persistent sync state (#279)
* removed version from PersistentSyncState * removed persist and recovery logic of teh ChainState * dropped dead code in sync_state * removed logic to store sync state * sync_state.rs deleted * ffi docs udpated
1 parent 3254ac4 commit 84a9552

File tree

9 files changed

+3
-1247
lines changed

9 files changed

+3
-1247
lines changed

dash-spv-ffi/FFI_API.md

Lines changed: 2 additions & 19 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**: 71
7+
**Total Functions**: 70
88

99
## Table of Contents
1010

@@ -68,12 +68,11 @@ Functions: 27
6868

6969
### Synchronization
7070

71-
Functions: 8
71+
Functions: 7
7272

7373
| Function | Description | Module |
7474
|----------|-------------|--------|
7575
| `dash_spv_ffi_client_cancel_sync` | Cancels the sync operation | client |
76-
| `dash_spv_ffi_client_clear_sync_state` | Clear only the persisted sync-state snapshot | client |
7776
| `dash_spv_ffi_client_get_sync_progress` | Get the current sync progress snapshot | client |
7877
| `dash_spv_ffi_client_is_filter_sync_available` | Check if compact filter sync is currently available | client |
7978
| `dash_spv_ffi_client_sync_to_tip` | Sync the SPV client to the chain tip | client |
@@ -664,22 +663,6 @@ The client pointer must be valid and non-null.
664663
665664
---
666665
667-
#### `dash_spv_ffi_client_clear_sync_state`
668-
669-
```c
670-
dash_spv_ffi_client_clear_sync_state(client: *mut FFIDashSpvClient,) -> i32
671-
```
672-
673-
**Description:**
674-
Clear only the persisted sync-state snapshot. # Safety - `client` must be a valid, non-null pointer.
675-
676-
**Safety:**
677-
- `client` must be a valid, non-null pointer.
678-
679-
**Module:** `client`
680-
681-
---
682-
683666
#### `dash_spv_ffi_client_get_sync_progress`
684667
685668
```c

dash-spv-ffi/include/dash_spv_ffi.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,6 @@ int32_t dash_spv_ffi_client_sync_to_tip_with_progress(struct FFIDashSpvClient *c
457457
*/
458458
int32_t dash_spv_ffi_client_clear_storage(struct FFIDashSpvClient *client) ;
459459

460-
/**
461-
* Clear only the persisted sync-state snapshot.
462-
*
463-
* # Safety
464-
* - `client` must be a valid, non-null pointer.
465-
*/
466-
int32_t dash_spv_ffi_client_clear_sync_state(struct FFIDashSpvClient *client) ;
467-
468460
/**
469461
* Check if compact filter sync is currently available.
470462
*

dash-spv-ffi/src/client.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,45 +1222,6 @@ pub unsafe extern "C" fn dash_spv_ffi_client_clear_storage(client: *mut FFIDashS
12221222
}
12231223
}
12241224

1225-
/// Clear only the persisted sync-state snapshot.
1226-
///
1227-
/// # Safety
1228-
/// - `client` must be a valid, non-null pointer.
1229-
#[no_mangle]
1230-
pub unsafe extern "C" fn dash_spv_ffi_client_clear_sync_state(
1231-
client: *mut FFIDashSpvClient,
1232-
) -> i32 {
1233-
null_check!(client);
1234-
1235-
let client = &(*client);
1236-
let inner = client.inner.clone();
1237-
1238-
let result = client.runtime.block_on(async {
1239-
let mut spv_client = {
1240-
let mut guard = inner.lock().unwrap();
1241-
match guard.take() {
1242-
Some(c) => c,
1243-
None => {
1244-
return Err(dash_spv::SpvError::Config("Client not initialized".to_string()))
1245-
}
1246-
}
1247-
};
1248-
1249-
let res = spv_client.clear_sync_state().await;
1250-
let mut guard = inner.lock().unwrap();
1251-
*guard = Some(spv_client);
1252-
res
1253-
});
1254-
1255-
match result {
1256-
Ok(_) => FFIErrorCode::Success as i32,
1257-
Err(e) => {
1258-
set_last_error(&e.to_string());
1259-
FFIErrorCode::from(e) as i32
1260-
}
1261-
}
1262-
}
1263-
12641225
/// Check if compact filter sync is currently available.
12651226
///
12661227
/// # Safety

dash-spv/src/client/core.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ pub struct DashSpvClient<W: WalletInterface, N: NetworkManager, S: StorageManage
144144
pub(super) event_rx: Option<mpsc::UnboundedReceiver<SpvEvent>>,
145145
pub(super) mempool_state: Arc<RwLock<MempoolState>>,
146146
pub(super) mempool_filter: Option<Arc<MempoolFilter>>,
147-
pub(super) last_sync_state_save: Arc<RwLock<u64>>,
148147
}
149148

150149
impl<
@@ -272,12 +271,6 @@ impl<
272271
Ok(())
273272
}
274273

275-
/// Clear only the persisted sync state snapshot (keep headers/filters).
276-
pub async fn clear_sync_state(&mut self) -> Result<()> {
277-
let mut storage = self.storage.lock().await;
278-
storage.clear_sync_state().await.map_err(SpvError::Storage)
279-
}
280-
281274
/// Clear all stored filter headers and compact filters while keeping other data intact.
282275
pub async fn clear_filters(&mut self) -> Result<()> {
283276
{

dash-spv/src/client/lifecycle.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ impl<
9595
event_rx: Some(event_rx),
9696
mempool_state,
9797
mempool_filter: None,
98-
last_sync_state_save: Arc::new(RwLock::new(0)),
9998
})
10099
}
101100

@@ -163,29 +162,6 @@ impl<
163162
tracing::info!("📊 Sequential sync mode: filter processing handled internally");
164163
}
165164

166-
// Try to restore sync state from persistent storage
167-
if self.config.enable_persistence {
168-
match self.restore_sync_state().await {
169-
Ok(restored) => {
170-
if restored {
171-
tracing::info!(
172-
"✅ Successfully restored sync state from persistent storage"
173-
);
174-
} else {
175-
tracing::info!("No previous sync state found, starting fresh sync");
176-
}
177-
}
178-
Err(e) => {
179-
tracing::error!("Failed to restore sync state: {}", e);
180-
tracing::warn!("Starting fresh sync due to state restoration failure");
181-
// Clear any corrupted state
182-
if let Err(clear_err) = self.storage.lock().await.clear_sync_state().await {
183-
tracing::error!("Failed to clear corrupted sync state: {}", clear_err);
184-
}
185-
}
186-
}
187-
}
188-
189165
// Initialize genesis block if not already present
190166
self.initialize_genesis_block().await?;
191167

@@ -262,14 +238,6 @@ impl<
262238
}
263239
}
264240

265-
// Save sync state before shutting down
266-
if let Err(e) = self.save_sync_state().await {
267-
tracing::error!("Failed to save sync state during shutdown: {}", e);
268-
// Continue with shutdown even if state save fails
269-
} else {
270-
tracing::info!("Sync state saved successfully during shutdown");
271-
}
272-
273241
// Disconnect from network
274242
self.network.disconnect().await?;
275243

0 commit comments

Comments
 (0)