X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fchannelmonitor.rs;h=65b592a879927182bfe970915d62217b94816e18;hb=35bd8c31e88965a21186454470be9c558732b8b4;hp=fe84865017c3407d62fdc22b4545e693fc325cde;hpb=e86e10b87d8e0fe8631558dd61aee4cc77f50bde;p=rust-lightning diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index fe848650..65b592a8 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -243,7 +243,6 @@ enum Storage { Watchtower { revocation_base_key: PublicKey, htlc_base_key: PublicKey, - sigs: HashMap, } } @@ -545,54 +544,29 @@ impl ChannelMonitor { /// After a successful call this ChannelMonitor is up-to-date and is safe to use to monitor the /// chain for new blocks/transactions. pub fn insert_combine(&mut self, mut other: ChannelMonitor) -> Result<(), MonitorUpdateError> { - - 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, ref mut funding_info, .. } => { - - macro_rules! new_storage_local { - ($funding_info: expr) => { - 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: $funding_info, - } - } - } - + match self.key_storage { + Storage::Local { ref funding_info, .. } => { + if funding_info.is_none() { return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); } let our_funding_info = funding_info; - if let Storage::Local { ref mut funding_info, .. } = other.key_storage { - if our_funding_info.is_some() { + if let Storage::Local { ref funding_info, .. } = other.key_storage { + if funding_info.is_none() { return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); } // We should be able to compare the entire funding_txo, but in fuzztarget its trivially // easy to collide the funding_txo hash and have a different scriptPubKey. - if funding_info.is_some() && our_funding_info.is_some() && funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 { - return Err(MonitorUpdateError("Funding transaction outputs are not identical!")); - } else { - new_storage_local!(our_funding_info.take()) - } - } else { - return Err(MonitorUpdateError("Try to combine a Local monitor without funding_info")); + if funding_info.as_ref().unwrap().0 != our_funding_info.as_ref().unwrap().0 { + return Err(MonitorUpdateError("Funding transaction outputs are not identical!")); } } else { return Err(MonitorUpdateError("Try to combine a Local monitor with a Watchtower one !")); } }, Storage::Watchtower { .. } => { - if let Storage::Watchtower { ref revocation_base_key, ref htlc_base_key, ref mut sigs } = other.key_storage { - Storage::Watchtower { - revocation_base_key: *revocation_base_key, - htlc_base_key: *htlc_base_key, - sigs: sigs.drain().collect(), - } + if let Storage::Watchtower { .. } = other.key_storage { + unimplemented!(); } else { return Err(MonitorUpdateError("Try to combine a Watchtower monitor with a Local one !")); } }, - }; + } let other_min_secret = other.get_min_seen_secret(); let our_min_secret = self.get_min_seen_secret(); if our_min_secret > other_min_secret { @@ -639,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 @@ -670,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?"); }, } }