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
16 changes: 11 additions & 5 deletions dash-spv/src/sync/filters/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::sync::Arc;

use dashcore::bip158::BlockFilter;
use dashcore::bip158::{BlockFilter, FilterQuery};
use dashcore::ScriptBuf;

use super::batch::FiltersBatch;
Expand Down Expand Up @@ -783,6 +783,14 @@ impl<H: BlockHeaderStorage, FH: FilterHeaderStorage, F: FilterStorage, W: Wallet
wallet_states.iter().flat_map(|(_, _, scripts)| scripts.iter().cloned()).collect();
let min_synced = wallet_states.iter().map(|(_, synced, _)| *synced).min().unwrap_or(0);

// Pre-group each wallet's scripts by length once; reused across every matched filter.
let wallet_queries: Vec<(WalletId, u32, FilterQuery)> = wallet_states
.iter()
.map(|(id, synced, scripts)| {
(*id, *synced, scripts.iter().map(|s| s.as_bytes()).collect())
})
.collect();

let block_to_wallets = {
let Some(batch) = self.active_batches.get(&batch_start) else {
return Ok(events);
Expand All @@ -802,13 +810,11 @@ impl<H: BlockHeaderStorage, FH: FilterHeaderStorage, F: FilterStorage, W: Wallet
);
continue;
};
for (wallet_id, wallet_synced, scripts) in &wallet_states {
for (wallet_id, wallet_synced, query) in &wallet_queries {
if key.height() <= *wallet_synced {
continue;
}
let matched = match filter
.match_any(key.hash(), scripts.iter().map(|s| s.as_bytes()))
{
let matched = match filter.match_any(key.hash(), query) {
Ok(matched) => matched,
Err(e) => {
tracing::warn!(
Expand Down
4 changes: 2 additions & 2 deletions dash/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ impl ShortId {
pub fn with_siphash_keys<T: AsRef<[u8]>>(txid: &T, siphash_keys: (u64, u64)) -> ShortId {
// 2. Running SipHash-2-4 with the input being the transaction ID and the keys (k0/k1)
// set to the first two little-endian 64-bit integers from the above hash, respectively.
let hash = siphash24::Hash::hash_with_keys(siphash_keys.0, siphash_keys.1, txid.as_ref());
let hash = siphash24::siphash(siphash_keys.0, siphash_keys.1, txid.as_ref());

// 3. Dropping the 2 most significant bytes from the SipHash output to make it 6 bytes.
let mut id = ShortId([0; 6]);
id.0.copy_from_slice(&hash[0..6]);
id.0.copy_from_slice(&hash.to_le_bytes()[0..6]);
id
}
}
Expand Down
Loading
Loading