X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmonitor.rs;h=d619edcbcd98f7fd8a6c6c1c1e6c7f51a2f37194;hb=be7d3d17ac4c8f45f8ac80e11368c62b423f8318;hp=d3121c131cbce91616719f98e7d296b460209420;hpb=9df0250dbbad7449e3ec8f90532ce9197eb31997;p=rust-lightning diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index d3121c13..d619edcb 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -109,6 +109,12 @@ pub struct HTLCUpdate { /// channel's monitor everywhere (including remote watchtowers) *before* this function returns. If /// an update occurs and a remote watchtower is left with old state, it may broadcast transactions /// which we have revoked, allowing our counterparty to claim all funds in the channel! +/// +/// User needs to notify implementors of ManyChannelMonitor when a new block is connected or +/// disconnected using their `block_connected` and `block_disconnected` methods. However, rather +/// than calling these methods directly, the user should register implementors as listeners to the +/// BlockNotifier and call the BlockNotifier's `block_(dis)connected` methods, which will notify +/// all registered listeners in one go. pub trait ManyChannelMonitor: Send + Sync { /// Adds or updates a monitor for the given `funding_txo`. /// @@ -146,7 +152,8 @@ pub struct SimpleManyChannelMonitor { fee_estimator: Arc } -impl ChainListener for SimpleManyChannelMonitor { +impl<'a, Key : Send + cmp::Eq + hash::Hash> ChainListener for SimpleManyChannelMonitor { + fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[u32]) { let block_hash = header.bitcoin_hash(); let mut new_events: Vec = Vec::with_capacity(0); @@ -223,8 +230,7 @@ impl SimpleManyChannelMonitor logger, fee_estimator: feeest, }); - let weak_res = Arc::downgrade(&res); - res.chain_monitor.register_listener(weak_res); + res } @@ -2138,14 +2144,14 @@ impl ChannelMonitor { }; if funding_txo.is_none() || (prevout.txid == funding_txo.as_ref().unwrap().0.txid && prevout.vout == funding_txo.as_ref().unwrap().0.index as u32) { if (tx.input[0].sequence >> 8*3) as u8 == 0x80 && (tx.lock_time >> 8*3) as u8 == 0x20 { - let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(tx, height, fee_estimator); + let (remote_txn, new_outputs, mut spendable_output) = self.check_spend_remote_transaction(&tx, height, fee_estimator); txn = remote_txn; spendable_outputs.append(&mut spendable_output); if !new_outputs.1.is_empty() { watch_outputs.push(new_outputs); } if txn.is_empty() { - let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(tx, height); + let (local_txn, mut spendable_output, new_outputs) = self.check_spend_local_transaction(&tx, height); spendable_outputs.append(&mut spendable_output); txn = local_txn; if !new_outputs.1.is_empty() { @@ -2154,13 +2160,13 @@ impl ChannelMonitor { } } if !funding_txo.is_none() && txn.is_empty() { - if let Some(spendable_output) = self.check_spend_closing_transaction(tx) { + if let Some(spendable_output) = self.check_spend_closing_transaction(&tx) { spendable_outputs.push(spendable_output); } } } else { if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) { - let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number, height, fee_estimator); + let (tx, spendable_output) = self.check_spend_remote_htlc(&tx, commitment_number, height, fee_estimator); if let Some(tx) = tx { txn.push(tx); } @@ -2177,7 +2183,7 @@ impl ChannelMonitor { // While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs // can also be resolved in a few other ways which can have more than one output. Thus, // we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check. - let mut updated = self.is_resolving_htlc_output(tx, height); + let mut updated = self.is_resolving_htlc_output(&tx, height); if updated.len() > 0 { htlc_updated.append(&mut updated); }