X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchannelmonitor.rs;h=3adf3e0e70528d64985005d217730a4fd44a456e;hb=a162840ffd228f201ad281f715ef63c459eda14c;hp=feff3978603bb3d535c8c4c8c6e2f89a02c005a9;hpb=45a558b17013531f95f40f1211647ae677e84a23;p=rust-lightning diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index feff3978..3adf3e0e 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1214,23 +1214,17 @@ impl ChannelMonitor { /// /// (C-not exported) because we have no HashMap bindings pub fn get_outputs_to_watch(&self) -> &HashMap> { - &self.outputs_to_watch - } - - /// Gets the sets of all outpoints which this ChannelMonitor expects to hear about spends of. - /// Generally useful when deserializing as during normal operation the return values of - /// block_connected are sufficient to ensure all relevant outpoints are being monitored (note - /// that the get_funding_txo outpoint and transaction must also be monitored for!). - /// - /// (C-not exported) as there is no practical way to track lifetimes of returned values. - pub fn get_monitored_outpoints(&self) -> Vec<(Txid, u32, &Script)> { - let mut res = Vec::with_capacity(self.counterparty_commitment_txn_on_chain.len() * 2); - for (ref txid, &(_, ref outputs)) in self.counterparty_commitment_txn_on_chain.iter() { - for (idx, output) in outputs.iter().enumerate() { - res.push(((*txid).clone(), idx as u32, output)); + // If we've detected a counterparty commitment tx on chain, we must include it in the set + // of outputs to watch for spends of, otherwise we're likely to lose user funds. Because + // its trivial to do, double-check that here. + for (txid, &(_, ref outputs)) in self.counterparty_commitment_txn_on_chain.iter() { + let watched_outputs = self.outputs_to_watch.get(txid).expect("Counterparty commitment txn which have been broadcast should have outputs registered"); + assert_eq!(watched_outputs.len(), outputs.len()); + for (watched, output) in watched_outputs.iter().zip(outputs.iter()) { + assert_eq!(watched, output); } } - res + &self.outputs_to_watch } /// Get the list of HTLCs who's status has been updated on chain. This should be called by