Skip to content

Commit e14011a

Browse files
committed
updated WalletManager::filter_matches to cache matched_wallet_ids
1 parent 0c98598 commit e14011a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

key-wallet-manager/src/wallet_manager/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub struct WalletManager<T: WalletInfoInterface = ManagedWalletInfo> {
9090
network_states: BTreeMap<Network, NetworkState>,
9191
/// Filter match cache (per network) - caches whether a filter matched
9292
/// This is used for SPV operations to avoid rechecking filters
93-
filter_matches: BTreeMap<Network, BTreeMap<BlockHash, bool>>,
93+
filter_matches: BTreeMap<Network, BTreeMap<BlockHash, Vec<[u8; 32]>>>,
9494
}
9595

9696
impl<T: WalletInfoInterface> Default for WalletManager<T>

key-wallet-manager/src/wallet_manager/process_block.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletInterface for WalletM
9090
block_hash: &BlockHash,
9191
network: Network,
9292
) -> Vec<[u8; 32]> {
93+
// Check if we've already evaluated this filter
94+
if let Some(network_cache) = self.filter_matches.get(&network) {
95+
if let Some(matched) = network_cache.get(block_hash) {
96+
return matched.clone();
97+
}
98+
}
99+
93100
let mut matched_wallet_ids = Vec::new();
94101

95102
// Check each wallet individually to track which ones match
@@ -115,9 +122,11 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletInterface for WalletM
115122
}
116123
}
117124

118-
// Cache the result (true if any wallet matched)
119-
let any_match = !matched_wallet_ids.is_empty();
120-
self.filter_matches.entry(network).or_default().insert(*block_hash, any_match);
125+
// Cache the result
126+
self.filter_matches
127+
.entry(network)
128+
.or_default()
129+
.insert(*block_hash, matched_wallet_ids.clone());
121130

122131
matched_wallet_ids
123132
}

0 commit comments

Comments
 (0)