From 35bd8c31e88965a21186454470be9c558732b8b4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 2 Dec 2018 14:11:13 -0500 Subject: [PATCH] Simplify ChannelMonitor Storage updates a bit --- src/ln/channelmonitor.rs | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 38886d2a..65b592a8 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -613,24 +613,15 @@ impl ChannelMonitor { /// provides slightly better privacy. /// It's the responsibility of the caller to register outpoint and script with passing the former /// value as key to add_update_monitor. - pub(super) fn set_funding_info(&mut self, funding_info: (OutPoint, Script)) { - self.key_storage = match self.key_storage { - Storage::Local { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref prev_latest_per_commitment_point, ref latest_per_commitment_point, .. } => { - Storage::Local { - revocation_base_key: *revocation_base_key, - htlc_base_key: *htlc_base_key, - delayed_payment_base_key: *delayed_payment_base_key, - payment_base_key: *payment_base_key, - shutdown_pubkey: *shutdown_pubkey, - prev_latest_per_commitment_point: *prev_latest_per_commitment_point, - latest_per_commitment_point: *latest_per_commitment_point, - funding_info: Some(funding_info.clone()), - } + pub(super) fn set_funding_info(&mut self, new_funding_info: (OutPoint, Script)) { + match self.key_storage { + Storage::Local { ref mut funding_info, .. } => { + *funding_info = Some(new_funding_info); }, Storage::Watchtower { .. } => { - unimplemented!(); + panic!("Channel somehow ended up with its internal ChannelMonitor being in Watchtower mode?"); } - }; + } } /// We log these base keys at channel opening to being able to rebuild redeemscript in case of leaked revoked commit tx @@ -644,21 +635,12 @@ impl ChannelMonitor { } pub(super) fn unset_funding_info(&mut self) { - self.key_storage = match self.key_storage { - Storage::Local { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref prev_latest_per_commitment_point, ref latest_per_commitment_point, .. } => { - Storage::Local { - revocation_base_key: *revocation_base_key, - htlc_base_key: *htlc_base_key, - delayed_payment_base_key: *delayed_payment_base_key, - payment_base_key: *payment_base_key, - shutdown_pubkey: *shutdown_pubkey, - prev_latest_per_commitment_point: *prev_latest_per_commitment_point, - latest_per_commitment_point: *latest_per_commitment_point, - funding_info: None, - } + match self.key_storage { + Storage::Local { ref mut funding_info, .. } => { + *funding_info = None; }, Storage::Watchtower { .. } => { - unimplemented!(); + panic!("Channel somehow ended up with its internal ChannelMonitor being in Watchtower mode?"); }, } } -- 2.30.2