|
5 | 5 | // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in |
6 | 6 | // accordance with one or both of these licenses. |
7 | 7 |
|
8 | | -use std::collections::HashMap; |
| 8 | +use std::collections::{HashMap, HashSet}; |
9 | 9 | use std::net::SocketAddr; |
10 | 10 | use std::sync::atomic::{AtomicU32, Ordering}; |
11 | 11 | use std::sync::{Arc, Mutex, RwLock}; |
@@ -93,7 +93,7 @@ pub(super) struct CbfChainSource { |
93 | 93 | /// Serializes concurrent filter scans (on-chain and lightning). |
94 | 94 | scan_lock: tokio::sync::Mutex<()>, |
95 | 95 | /// Scripts registered by LDK's Filter trait for lightning channel monitoring. |
96 | | - registered_scripts: Mutex<Vec<ScriptBuf>>, |
| 96 | + registered_scripts: Mutex<HashSet<ScriptBuf>>, |
97 | 97 | /// Deduplicates concurrent on-chain wallet sync requests. |
98 | 98 | onchain_wallet_sync_status: Mutex<WalletSyncStatus>, |
99 | 99 | /// Deduplicates concurrent lightning wallet sync requests. |
@@ -151,7 +151,7 @@ impl CbfChainSource { |
151 | 151 | let matched_block_hashes = Arc::new(Mutex::new(Vec::new())); |
152 | 152 | let sync_completion_tx = Arc::new(Mutex::new(None)); |
153 | 153 | let filter_skip_height = Arc::new(AtomicU32::new(0)); |
154 | | - let registered_scripts = Mutex::new(Vec::new()); |
| 154 | + let registered_scripts = Mutex::new(HashSet::new()); |
155 | 155 | let scan_lock = tokio::sync::Mutex::new(()); |
156 | 156 | let onchain_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed); |
157 | 157 | let lightning_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed); |
@@ -510,12 +510,12 @@ impl CbfChainSource { |
510 | 510 |
|
511 | 511 | /// Register a transaction script for Lightning channel monitoring. |
512 | 512 | pub(crate) fn register_tx(&self, _txid: &Txid, script_pubkey: &Script) { |
513 | | - self.registered_scripts.lock().expect("lock").push(script_pubkey.to_owned()); |
| 513 | + self.registered_scripts.lock().expect("lock").insert(script_pubkey.to_owned()); |
514 | 514 | } |
515 | 515 |
|
516 | 516 | /// Register a watched output script for Lightning channel monitoring. |
517 | 517 | pub(crate) fn register_output(&self, output: WatchedOutput) { |
518 | | - self.registered_scripts.lock().expect("lock").push(output.script_pubkey.clone()); |
| 518 | + self.registered_scripts.lock().expect("lock").insert(output.script_pubkey.clone()); |
519 | 519 | } |
520 | 520 |
|
521 | 521 | /// Run a CBF filter scan: set watched scripts, trigger a rescan, wait for |
@@ -738,7 +738,8 @@ impl CbfChainSource { |
738 | 738 | let requester = self.requester()?; |
739 | 739 | let now = Instant::now(); |
740 | 740 |
|
741 | | - let scripts: Vec<ScriptBuf> = self.registered_scripts.lock().expect("lock").clone(); |
| 741 | + let scripts: Vec<ScriptBuf> = |
| 742 | + self.registered_scripts.lock().expect("lock").iter().cloned().collect(); |
742 | 743 | if scripts.is_empty() { |
743 | 744 | log_debug!(self.logger, "No registered scripts for CBF lightning sync."); |
744 | 745 | } else { |
|
0 commit comments