Skip to content

Commit d84c084

Browse files
author
Antoine Riard
committed
Implement set_their_delayed_payment_base_key in ChannelMonitor
Needed to build redeemscript on HTLC-Success/HTLC-Timeout tx from remote revoked commitment tx
1 parent 648a31b commit d84c084

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl Channel {
570570
&PublicKey::from_secret_key(&secp_ctx, &chan_keys.delayed_payment_base_key),
571571
&chan_keys.htlc_base_key,
572572
BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
573-
channel_monitor.set_their_htlc_base_key(&msg.htlc_basepoint);
573+
channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
574574
channel_monitor.set_their_to_self_delay(msg.to_self_delay);
575575

576576
let mut chan = Channel {
@@ -1236,7 +1236,7 @@ impl Channel {
12361236
// max_accepted_htlcs too small
12371237
// dust_limit_satoshis too small
12381238

1239-
self.channel_monitor.set_their_htlc_base_key(&msg.htlc_basepoint);
1239+
self.channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
12401240

12411241
self.their_dust_limit_satoshis = msg.dust_limit_satoshis;
12421242
self.their_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000);

src/ln/channelmonitor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub struct ChannelMonitor {
166166
key_storage: KeyStorage,
167167
delayed_payment_base_key: PublicKey,
168168
their_htlc_base_key: Option<PublicKey>,
169+
their_delayed_payment_base_key: Option<PublicKey>,
169170
// first is the idx of the first of the two revocation points
170171
their_cur_revocation_points: Option<(u64, PublicKey, Option<PublicKey>)>,
171172

@@ -207,6 +208,7 @@ impl Clone for ChannelMonitor {
207208
key_storage: self.key_storage.clone(),
208209
delayed_payment_base_key: self.delayed_payment_base_key.clone(),
209210
their_htlc_base_key: self.their_htlc_base_key.clone(),
211+
their_delayed_payment_base_key: self.their_delayed_payment_base_key.clone(),
210212
their_cur_revocation_points: self.their_cur_revocation_points.clone(),
211213

212214
our_to_self_delay: self.our_to_self_delay,
@@ -238,6 +240,7 @@ impl PartialEq for ChannelMonitor {
238240
self.key_storage != other.key_storage ||
239241
self.delayed_payment_base_key != other.delayed_payment_base_key ||
240242
self.their_htlc_base_key != other.their_htlc_base_key ||
243+
self.their_delayed_payment_base_key != other.their_delayed_payment_base_key ||
241244
self.their_cur_revocation_points != other.their_cur_revocation_points ||
242245
self.our_to_self_delay != other.our_to_self_delay ||
243246
self.their_to_self_delay != other.their_to_self_delay ||
@@ -274,6 +277,7 @@ impl ChannelMonitor {
274277
},
275278
delayed_payment_base_key: delayed_payment_base_key.clone(),
276279
their_htlc_base_key: None,
280+
their_delayed_payment_base_key: None,
277281
their_cur_revocation_points: None,
278282

279283
our_to_self_delay: our_to_self_delay,
@@ -478,8 +482,10 @@ impl ChannelMonitor {
478482
self.funding_txo = Some(funding_info);
479483
}
480484

481-
pub(super) fn set_their_htlc_base_key(&mut self, their_htlc_base_key: &PublicKey) {
485+
/// We log these base keys at channel opening to being able to rebuild redeemscript in case of leaked revoked commit tx
486+
pub(super) fn set_their_base_keys(&mut self, their_htlc_base_key: &PublicKey, their_delayed_payment_base_key: &PublicKey) {
482487
self.their_htlc_base_key = Some(their_htlc_base_key.clone());
488+
self.their_delayed_payment_base_key = Some(their_delayed_payment_base_key.clone());
483489
}
484490

485491
pub(super) fn set_their_to_self_delay(&mut self, their_to_self_delay: u16) {
@@ -531,6 +537,7 @@ impl ChannelMonitor {
531537

532538
res.extend_from_slice(&self.delayed_payment_base_key.serialize());
533539
res.extend_from_slice(&self.their_htlc_base_key.as_ref().unwrap().serialize());
540+
res.extend_from_slice(&self.their_delayed_payment_base_key.as_ref().unwrap().serialize());
534541

535542
match self.their_cur_revocation_points {
536543
Some((idx, pubkey, second_option)) => {
@@ -705,6 +712,7 @@ impl ChannelMonitor {
705712

706713
let delayed_payment_base_key = unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33)));
707714
let their_htlc_base_key = Some(unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33))));
715+
let their_delayed_payment_base_key = Some(unwrap_obj!(PublicKey::from_slice(&secp_ctx, read_bytes!(33))));
708716

709717
let their_cur_revocation_points = {
710718
let first_idx = byte_utils::slice_to_be48(read_bytes!(6));
@@ -867,6 +875,7 @@ impl ChannelMonitor {
867875
key_storage,
868876
delayed_payment_base_key,
869877
their_htlc_base_key,
878+
their_delayed_payment_base_key,
870879
their_cur_revocation_points,
871880

872881
our_to_self_delay,

0 commit comments

Comments
 (0)