Skip to content

Commit a3e1bad

Browse files
Add RevokeAndACK::release_htlc_message_paths
As part of supporting sending payments as an often-offline sender, the sender needs to send held_htlc_available onion messages where the reply path terminates at their always-online channel counterparty that is holding the HTLC until the recipient comes online. That way when the recipient sends release_held_htlc, the sender's counterparty will receive that message. To accomplish this, the sender's always-online counterparty includes said reply path in the revoke_and_ack message corresponding to the held HTLC. Here we add support for this field, though we don't set it yet. We also had to tweak the ser macros for this because impl_writeable_msg had never had to write a Vec in a message TLV field before.
1 parent 1dd3988 commit a3e1bad

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8998,6 +8998,7 @@ where
89988998
next_per_commitment_point: self.holder_commitment_point.next_point(),
89998999
#[cfg(taproot)]
90009000
next_local_nonce: None,
9001+
release_htlc_message_paths: Vec::new(),
90019002
});
90029003
}
90039004
}

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6548,6 +6548,7 @@ pub fn test_counterparty_raa_skip_no_crash() {
65486548
next_per_commitment_point,
65496549
#[cfg(taproot)]
65506550
next_local_nonce: None,
6551+
release_htlc_message_paths: Vec::new(),
65516552
};
65526553
nodes[1].node.handle_revoke_and_ack(node_a_id, &raa);
65536554
assert_eq!(

lightning/src/ln/htlc_reserve_unit_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
936936
next_per_commitment_point: next_local_point,
937937
#[cfg(taproot)]
938938
next_local_nonce: None,
939+
release_htlc_message_paths: Vec::new(),
939940
};
940941
nodes[1].node.handle_revoke_and_ack(node_a_id, &raa_msg);
941942
expect_and_process_pending_htlcs(&nodes[1], false);
@@ -2381,6 +2382,7 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
23812382
next_per_commitment_point: next_local_point,
23822383
#[cfg(taproot)]
23832384
next_local_nonce: None,
2385+
release_htlc_message_paths: Vec::new(),
23842386
};
23852387
nodes[1].node.handle_revoke_and_ack(node_a_id, &raa_msg);
23862388

lightning/src/ln/msgs.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bitcoin::secp256k1::ecdsa::Signature;
3131
use bitcoin::secp256k1::PublicKey;
3232
use bitcoin::{secp256k1, Transaction, Witness};
3333

34+
use crate::blinded_path::message::BlindedMessagePath;
3435
use crate::blinded_path::payment::{
3536
BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs, UnauthenticatedReceiveTlvs,
3637
};
@@ -888,6 +889,13 @@ pub struct RevokeAndACK {
888889
#[cfg(taproot)]
889890
/// Musig nonce the recipient should use in their next commitment signature message
890891
pub next_local_nonce: Option<musig2::types::PublicNonce>,
892+
/// A list of `(htlc_id, blinded_path)`. The receiver of this message will use the blinded paths
893+
/// as reply paths to [`HeldHtlcAvailable`] onion messages that they send to the often-offline
894+
/// receiver of this HTLC. The `htlc_id` is used by the receiver of this message to identify which
895+
/// held HTLC a given blinded path corresponds to.
896+
///
897+
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
898+
pub release_htlc_message_paths: Vec<(u64, BlindedMessagePath)>,
891899
}
892900

893901
/// An [`update_fee`] message to be sent to or received from a peer
@@ -3260,15 +3268,18 @@ impl_writeable_msg!(RevokeAndACK, {
32603268
channel_id,
32613269
per_commitment_secret,
32623270
next_per_commitment_point
3263-
}, {});
3271+
}, {
3272+
(75537, release_htlc_message_paths, optional_vec)
3273+
});
32643274

32653275
#[cfg(taproot)]
32663276
impl_writeable_msg!(RevokeAndACK, {
32673277
channel_id,
32683278
per_commitment_secret,
32693279
next_per_commitment_point
32703280
}, {
3271-
(4, next_local_nonce, option)
3281+
(4, next_local_nonce, option),
3282+
(75537, release_htlc_message_paths, optional_vec)
32723283
});
32733284

32743285
impl_writeable_msg!(Shutdown, {
@@ -5976,6 +5987,7 @@ mod tests {
59765987
next_per_commitment_point: pubkey_1,
59775988
#[cfg(taproot)]
59785989
next_local_nonce: None,
5990+
release_htlc_message_paths: Vec::new(),
59795991
};
59805992
let encoded_value = raa.encode();
59815993
let target_value = <Vec<u8>>::from_hex("02020202020202020202020202020202020202020202020202020202020202020101010101010101010101010101010101010101010101010101010101010101031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap();

lightning/src/util/ser_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ macro_rules! impl_writeable_msg {
700700
impl $crate::util::ser::Writeable for $st {
701701
fn write<W: $crate::util::ser::Writer>(&self, w: &mut W) -> Result<(), $crate::io::Error> {
702702
$( self.$field.write(w)?; )*
703-
$crate::encode_tlv_stream!(w, {$(($type, self.$tlvfield.as_ref(), $fieldty)),*});
703+
$crate::encode_tlv_stream!(w, {$(($type, &self.$tlvfield, $fieldty)),*});
704704
Ok(())
705705
}
706706
}
@@ -713,7 +713,7 @@ macro_rules! impl_writeable_msg {
713713
$crate::decode_tlv_stream!(r, {$(($type, $tlvfield, $fieldty)),*});
714714
Ok(Self {
715715
$($field,)*
716-
$($tlvfield),*
716+
$($tlvfield: $crate::_init_tlv_based_struct_field!($tlvfield, $fieldty)),*
717717
})
718718
}
719719
}

0 commit comments

Comments
 (0)