Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dash-spv/src/sync/filters/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ impl<H: BlockHeaderStorage, FH: FilterHeaderStorage, F: FilterStorage, W: Wallet
}
}

/// Clear all in-flight processing state. Called on peer disconnect when
/// in-flight filter batches and block tracking become invalid.
pub(super) fn clear_in_flight_state(&mut self) {
self.active_batches.clear();
self.blocks_remaining.clear();
self.filters_matched.clear();
self.pending_batches.clear();
self.filter_pipeline = FiltersPipeline::new();
}

async fn load_filters(
&self,
start_height: u32,
Expand Down
8 changes: 8 additions & 0 deletions dash-spv/src/sync/filters/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl<
&[MessageType::CFilter]
}

fn stop_sync(&mut self) {
self.set_state(SyncState::WaitingForConnections);
self.clear_in_flight_state();
}

async fn initialize(&mut self) -> SyncResult<()> {
let wallet = self.wallet.read().await;
let synced_height = wallet.synced_height();
Expand Down Expand Up @@ -80,6 +85,9 @@ impl<
// Already at or beyond stored filters tip - check if fully synced
if stored_filters_tip > 0 && stored_filters_tip == self.progress.current_height() {
self.progress.update_filter_header_tip_height(stored_filters_tip);
// Initialize the pipeline at the current tip. On full disconnect in-flight state gets
// reset, so we need to initialize the pipeline otherwise it would re-queue from height 1.
self.filter_pipeline.init(stored_filters_tip + 1, stored_filters_tip);
// Only emit SyncComplete if we've also reached the chain tip
if self.progress.current_height() >= self.progress.target_height() {
self.set_state(SyncState::Synced);
Expand Down
Loading