From c89514c37c8c2632cb32f1fb00764f9d7f2ce7f8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 18 Apr 2020 21:33:54 -0400 Subject: [PATCH] De-Option<> some fields in ChannelMonitor which are set at init After we moved the ChannelMonitor creation later during Channel init, we never went back and cleaned up ChannelMonitor to remove a number of now-useless Option<>s, so we do that now. --- lightning/src/ln/channelmanager.rs | 4 +- lightning/src/ln/channelmonitor.rs | 120 ++++++++-------------- lightning/src/ln/functional_test_utils.rs | 4 +- lightning/src/ln/functional_tests.rs | 14 +-- lightning/src/util/macro_logger.rs | 7 +- 5 files changed, 57 insertions(+), 92 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index f9ccc18a..62ac9866 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1432,7 +1432,7 @@ impl ChannelMan }; // Because we have exclusive ownership of the channel here we can release the channel_state // lock before add_monitor - if let Err(e) = self.monitor.add_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) { + if let Err(e) = self.monitor.add_monitor(chan_monitor.get_funding_txo(), chan_monitor) { match e { ChannelMonitorUpdateErr::PermanentFailure => { match handle_error!(self, Err(MsgHandleErrInternal::from_finish_shutdown("ChannelMonitor storage failure", *temporary_channel_id, chan.force_shutdown(true), None)), chan.get_their_node_id()) { @@ -2275,7 +2275,7 @@ impl ChannelMan }; // Because we have exclusive ownership of the channel here we can release the channel_state // lock before add_monitor - if let Err(e) = self.monitor.add_monitor(monitor_update.get_funding_txo().unwrap(), monitor_update) { + if let Err(e) = self.monitor.add_monitor(monitor_update.get_funding_txo(), monitor_update) { match e { ChannelMonitorUpdateErr::PermanentFailure => { // Note that we reply with the new channel_id in error messages if we gave up on the diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index e88dd333..7a6bac9c 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -290,16 +290,9 @@ impl return Err(MonitorUpdateError("Channel monitor for given key is already present")), hash_map::Entry::Vacant(e) => e, }; - match monitor.funding_info { - None => { - return Err(MonitorUpdateError("Try to update a useless monitor without funding_txo !")); - }, - Some((ref outpoint, ref script)) => { - log_trace!(self, "Got new Channel Monitor for channel {}", log_bytes!(outpoint.to_channel_id()[..])); - self.chain_monitor.install_watch_tx(&outpoint.txid, script); - self.chain_monitor.install_watch_outpoint((outpoint.txid, outpoint.index as u32), script); - }, - } + log_trace!(self, "Got new Channel Monitor for channel {}", log_bytes!(monitor.funding_info.0.to_channel_id()[..])); + self.chain_monitor.install_watch_tx(&monitor.funding_info.0.txid, &monitor.funding_info.1); + self.chain_monitor.install_watch_outpoint((monitor.funding_info.0.txid, monitor.funding_info.0.index as u32), &monitor.funding_info.1); for (txid, outputs) in monitor.get_outputs_to_watch().iter() { for (idx, script) in outputs.iter().enumerate() { self.chain_monitor.install_watch_outpoint((*txid, idx as u32), script); @@ -721,19 +714,19 @@ pub struct ChannelMonitor { shutdown_script: Script, keys: ChanSigner, - funding_info: Option<(OutPoint, Script)>, + funding_info: (OutPoint, Script), current_remote_commitment_txid: Option, prev_remote_commitment_txid: Option, - their_htlc_base_key: Option, - their_delayed_payment_base_key: Option, - funding_redeemscript: Option