]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement set_their_delayed_payment_base_key in ChannelMonitor
authorAntoine Riard <ariard@student.42.fr>
Tue, 11 Sep 2018 01:37:31 +0000 (01:37 +0000)
committerAntoine Riard <ariard@student.42.fr>
Wed, 12 Sep 2018 23:17:20 +0000 (23:17 +0000)
Needed to build redeemscript on HTLC-Success/HTLC-Timeout tx from
remote revoked commitment tx

src/ln/channel.rs
src/ln/channelmonitor.rs

index 0ed2dde04ec9f216141663111ffebf979b743459..4a927119695ad0efa3a557fa22cb6d903da981e9 100644 (file)
@@ -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);
index 39146daa9b2d96e6f93f5251c76e0f77353e72fb..81efedcbffd1408e0f6b8268b8e7b4eed9a5279a 100644 (file)
@@ -166,6 +166,7 @@ pub struct ChannelMonitor {
        key_storage: KeyStorage,
        delayed_payment_base_key: PublicKey,
        their_htlc_base_key: Option<PublicKey>,
+       their_delayed_payment_base_key: Option<PublicKey>,
        // first is the idx of the first of the two revocation points
        their_cur_revocation_points: Option<(u64, PublicKey, Option<PublicKey>)>,
 
@@ -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,