X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-transaction-sync%2Fsrc%2Fcommon.rs;h=420d7d8a9575f8672ce3111a52d000270c141a4e;hb=c5cd801f8781dd459b01e0221fd499f62922eb34;hp=c635f7385c6ecbd47bb6b4e90f5abb335feca8f5;hpb=1e54dd6a21a645f855c88cc95df85bea68aa23a9;p=rust-lightning diff --git a/lightning-transaction-sync/src/common.rs b/lightning-transaction-sync/src/common.rs index c635f738..420d7d8a 100644 --- a/lightning-transaction-sync/src/common.rs +++ b/lightning-transaction-sync/src/common.rs @@ -1,10 +1,10 @@ -use lightning::chain::{Confirm, WatchedOutput}; -use lightning::chain::channelmonitor::ANTI_REORG_DELAY; -use bitcoin::{Txid, BlockHash, Transaction, OutPoint}; use bitcoin::block::Header; +use bitcoin::{BlockHash, OutPoint, Transaction, Txid}; +use lightning::chain::channelmonitor::ANTI_REORG_DELAY; +use lightning::chain::{Confirm, WatchedOutput}; -use std::collections::{HashSet, HashMap}; - +use std::collections::{HashMap, HashSet}; +use std::ops::Deref; // Represents the current state. pub(crate) struct SyncState { @@ -33,10 +33,11 @@ impl SyncState { pending_sync: false, } } - pub fn sync_unconfirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, - unconfirmed_txs: Vec, - ) { + pub fn sync_unconfirmed_transactions( + &mut self, confirmables: &Vec, unconfirmed_txs: Vec, + ) where + C::Target: Confirm, + { for txid in unconfirmed_txs { for c in confirmables { c.transaction_unconfirmed(&txid); @@ -46,21 +47,24 @@ impl SyncState { // If a previously-confirmed output spend is unconfirmed, re-add the watched output to // the tracking map. - self.outputs_spends_pending_threshold_conf.retain(|(conf_txid, _, prev_outpoint, output)| { - if txid == *conf_txid { - self.watched_outputs.insert(*prev_outpoint, output.clone()); - false - } else { - true - } - }) + self.outputs_spends_pending_threshold_conf.retain( + |(conf_txid, _, prev_outpoint, output)| { + if txid == *conf_txid { + self.watched_outputs.insert(*prev_outpoint, output.clone()); + false + } else { + true + } + }, + ) } } - pub fn sync_confirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, - confirmed_txs: Vec - ) { + pub fn sync_confirmed_transactions( + &mut self, confirmables: &Vec, confirmed_txs: Vec, + ) where + C::Target: Confirm, + { for ctx in confirmed_txs { for c in confirmables { c.transactions_confirmed( @@ -74,20 +78,19 @@ impl SyncState { for input in &ctx.tx.input { if let Some(output) = self.watched_outputs.remove(&input.previous_output) { - self.outputs_spends_pending_threshold_conf.push((ctx.tx.txid(), ctx.block_height, input.previous_output, output)); + let spent = (ctx.tx.txid(), ctx.block_height, input.previous_output, output); + self.outputs_spends_pending_threshold_conf.push(spent); } } } } pub fn prune_output_spends(&mut self, cur_height: u32) { - self.outputs_spends_pending_threshold_conf.retain(|(_, conf_height, _, _)| { - cur_height < conf_height + ANTI_REORG_DELAY - 1 - }); + self.outputs_spends_pending_threshold_conf + .retain(|(_, conf_height, _, _)| cur_height < conf_height + ANTI_REORG_DELAY - 1); } } - // A queue that is to be filled by `Filter` and drained during the next syncing round. pub(crate) struct FilterQueue { // Transactions that were registered via the `Filter` interface and have to be processed. @@ -98,10 +101,7 @@ pub(crate) struct FilterQueue { impl FilterQueue { pub fn new() -> Self { - Self { - transactions: HashSet::new(), - outputs: HashMap::new(), - } + Self { transactions: HashSet::new(), outputs: HashMap::new() } } // Processes the transaction and output queues and adds them to the given [`SyncState`].