Skip to content

Commit e3cfe1c

Browse files
refactor: optimize sync progress calculation in StatusDisplay
- Improved the sync progress method by cloning the inner heights handle and copying necessary counters without holding the RwLock, enhancing performance. - Updated the calculation of the last synced filter height to avoid holding the RwLock guard, ensuring better concurrency and responsiveness in the status display.
1 parent 593bd79 commit e3cfe1c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

dash-spv/src/client/status_display.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
7373
/// Get current sync progress.
7474
pub async fn sync_progress(&self) -> Result<SyncProgress> {
7575
let state = self.state.read().await;
76-
let stats = self.stats.read().await;
76+
// Clone the inner heights handle and copy needed counters without awaiting while holding the RwLock
77+
let (filters_received, received_heights) = {
78+
let stats = self.stats.read().await;
79+
(stats.filters_received, std::sync::Arc::clone(&stats.received_filter_heights))
80+
};
7781

78-
// Calculate last synced filter height from received filter heights
82+
// Calculate last synced filter height from received filter heights without holding the RwLock guard
7983
let last_synced_filter_height = {
80-
let heights = stats.received_filter_heights.lock().await;
84+
let heights = received_heights.lock().await;
8185
heights.iter().max().copied()
8286
};
8387

@@ -99,7 +103,7 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
99103
filter_headers_synced: false, // TODO: Implement
100104
masternodes_synced: false, // TODO: Implement
101105
filter_sync_available: false, // TODO: Get from network manager
102-
filters_downloaded: stats.filters_received,
106+
filters_downloaded: filters_received,
103107
last_synced_filter_height,
104108
sync_start: std::time::SystemTime::now(), // TODO: Track properly
105109
last_update: std::time::SystemTime::now(),

0 commit comments

Comments
 (0)