Skip to content
Open
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
7 changes: 7 additions & 0 deletions dash-spv/src/storage/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub trait FilterStorage: Send + Sync + 'static {

async fn filter_tip_height(&self) -> StorageResult<u32>;

/// Lowest height with a stored filter, or `None` when no filters are stored.
async fn filter_start_height(&self) -> Option<u32>;

/// Drop all filters with `height > target_height`.
///
/// Truncating above the current tip is a no-op, truncating below
Expand Down Expand Up @@ -79,6 +82,10 @@ impl FilterStorage for PersistentFilterStorage {
Ok(self.filters.read().await.tip_height().unwrap_or(0))
}

async fn filter_start_height(&self) -> Option<u32> {
self.filters.read().await.start_height()
}

async fn truncate_above(&mut self, target_height: u32) -> StorageResult<()> {
self.filters.write().await.truncate_above(target_height).await
}
Expand Down
4 changes: 4 additions & 0 deletions dash-spv/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ impl filters::FilterStorage for DiskStorageManager {
self.filters.read().await.filter_tip_height().await
}

async fn filter_start_height(&self) -> Option<u32> {
self.filters.read().await.filter_start_height().await
}

async fn truncate_above(&mut self, target_height: u32) -> StorageResult<()> {
self.filters.write().await.truncate_above(target_height).await
}
Expand Down
22 changes: 22 additions & 0 deletions dash-spv/src/sync/filters/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub(super) struct FiltersBatch {
/// need rescan, attributed per wallet so we can rerun matching only
/// against the wallet that produced each new script.
collected_scripts: HashMap<WalletId, HashSet<ScriptBuf>>,
/// Scripts already forward-rescanned but still awaiting the one combined
/// backward sweep over the committed range (#846). Accumulated across
/// fixpoint rounds so each script crosses the stored history exactly
/// once, instead of the whole history being reloaded per derivation
/// round.
backward_scripts: HashMap<WalletId, HashSet<ScriptBuf>>,
}

impl FiltersBatch {
Expand All @@ -51,6 +57,7 @@ impl FiltersBatch {
rescan_complete: false,
scanned_wallets: BTreeSet::new(),
collected_scripts: HashMap::new(),
backward_scripts: HashMap::new(),
}
}
/// Start height of this batch (inclusive).
Expand Down Expand Up @@ -118,6 +125,21 @@ impl FiltersBatch {
pub(super) fn take_collected_scripts(&mut self) -> HashMap<WalletId, HashSet<ScriptBuf>> {
std::mem::take(&mut self.collected_scripts)
}
/// Queue already forward-rescanned scripts for the deferred backward
/// sweep over the committed range.
pub(super) fn accumulate_backward_scripts(
&mut self,
scripts: HashMap<WalletId, HashSet<ScriptBuf>>,
) {
for (wallet_id, scripts) in scripts {
self.backward_scripts.entry(wallet_id).or_default().extend(scripts);
}
}
/// Take the scripts accumulated for the backward sweep, leaving the map
/// empty.
pub(super) fn take_backward_scripts(&mut self) -> HashMap<WalletId, HashSet<ScriptBuf>> {
std::mem::take(&mut self.backward_scripts)
}
/// Record the set of wallets that were behind for this batch at scan time.
pub(super) fn set_scanned_wallets(&mut self, wallets: BTreeSet<WalletId>) {
self.scanned_wallets = wallets;
Expand Down
Loading
Loading