From: Antoine Riard Date: Tue, 11 Sep 2018 01:37:31 +0000 (+0000) Subject: Implement set_their_delayed_payment_base_key in ChannelMonitor X-Git-Tag: v0.0.12~312^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d84c084df7b7dae62ea6b1a51951fb01391a7ebd;p=rust-lightning Implement set_their_delayed_payment_base_key in ChannelMonitor Needed to build redeemscript on HTLC-Success/HTLC-Timeout tx from remote revoked commitment tx --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 0ed2dde04..4a9271196 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -570,7 +570,7 @@ impl Channel { &PublicKey::from_secret_key(&secp_ctx, &chan_keys.delayed_payment_base_key), &chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script); - channel_monitor.set_their_htlc_base_key(&msg.htlc_basepoint); + channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint); channel_monitor.set_their_to_self_delay(msg.to_self_delay); let mut chan = Channel { @@ -1236,7 +1236,7 @@ impl Channel { // max_accepted_htlcs too small // dust_limit_satoshis too small - self.channel_monitor.set_their_htlc_base_key(&msg.htlc_basepoint); + self.channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint); self.their_dust_limit_satoshis = msg.dust_limit_satoshis; self.their_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000); diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 39146daa9..81efedcbf 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -166,6 +166,7 @@ pub struct ChannelMonitor { key_storage: KeyStorage, delayed_payment_base_key: PublicKey, their_htlc_base_key: Option, + their_delayed_payment_base_key: Option, // first is the idx of the first of the two revocation points their_cur_revocation_points: Option<(u64, PublicKey, Option)>, @@ -207,6 +208,7 @@ impl Clone for ChannelMonitor { key_storage: self.key_storage.clone(), delayed_payment_base_key: self.delayed_payment_base_key.clone(), their_htlc_base_key: self.their_htlc_base_key.clone(), + their_delayed_payment_base_key: self.their_delayed_payment_base_key.clone(), their_cur_revocation_points: self.their_cur_revocation_points.clone(), our_to_self_delay: self.our_to_self_delay, @@ -238,6 +240,7 @@ impl PartialEq for ChannelMonitor { self.key_storage != other.key_storage || self.delayed_payment_base_key != other.delayed_payment_base_key || self.their_htlc_base_key != other.their_htlc_base_key || + self.their_delayed_payment_base_key != other.their_delayed_payment_base_key || self.their_cur_revocation_points != other.their_cur_revocation_points || self.our_to_self_delay != other.our_to_self_delay || self.their_to_self_delay != other.their_to_self_delay || @@ -274,6 +277,7 @@ impl ChannelMonitor { }, delayed_payment_base_key: delayed_payment_base_key.clone(), their_htlc_base_key: None, + their_delayed_payment_base_key: None, their_cur_revocation_points: None, our_to_self_delay: our_to_self_delay, @@ -478,8 +482,10 @@ impl ChannelMonitor { self.funding_txo = Some(funding_info); } - pub(super) fn set_their_htlc_base_key(&mut self, their_htlc_base_key: &PublicKey) { + /// We log these base keys at channel opening to being able to rebuild redeemscript in case of leaked revoked commit tx + pub(super) fn set_their_base_keys(&mut self, their_htlc_base_key: &PublicKey, their_delayed_payment_base_key: &PublicKey) { self.their_htlc_base_key = Some(their_htlc_base_key.clone()); + self.their_delayed_payment_base_key = Some(their_delayed_payment_base_key.clone()); } pub(super) fn set_their_to_self_delay(&mut self, their_to_self_delay: u16) { @@ -531,6 +537,7 @@ impl ChannelMonitor { res.extend_from_slice(&self.delayed_payment_base_key.serialize()); res.extend_from_slice(&self.their_htlc_base_key.as_ref().unwrap().serialize()); + res.extend_from_slice(&self.their_delayed_payment_base_key.as_ref().unwrap().serialize()); match self.their_cur_revocation_points { Some((idx, pubkey, second_option)) => { @@ -705,6 +712,7 @@ impl ChannelMonitor { let delayed_payment_base_key = unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33))); let their_htlc_base_key = Some(unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33)))); + let their_delayed_payment_base_key = Some(unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33)))); let their_cur_revocation_points = { let first_idx = byte_utils::slice_to_be48(read_bytes!(6)); @@ -867,6 +875,7 @@ impl ChannelMonitor { key_storage, delayed_payment_base_key, their_htlc_base_key, + their_delayed_payment_base_key, their_cur_revocation_points, our_to_self_delay,