From ff22217e8f6dac11fe3405e1fa158513ee2b45b0 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Wed, 13 Mar 2024 19:45:43 -0700 Subject: [PATCH] Move Trampoline data to separate enum variant on OutboundOnionPayload. --- lightning/src/ln/msgs.rs | 28 +++++++++++++++++++--------- lightning/src/ln/onion_utils.rs | 1 - 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index fb0f8e80602..1f3bb06bcb7 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1698,6 +1698,12 @@ mod fuzzy_internal_msgs { amt_to_forward: u64, outgoing_cltv_value: u32, }, + TrampolineEntry { + amt_to_forward: u64, + outgoing_cltv_value: u32, + payment_data: Option, + trampoline_packet: crate::onion_message::packet::Packet + }, Receive { payment_data: Option, payment_metadata: Option>, @@ -1705,7 +1711,6 @@ mod fuzzy_internal_msgs { custom_tlvs: Vec<(u64, Vec)>, sender_intended_htlc_amt_msat: u64, cltv_expiry_height: u32, - trampoline_packet: Option }, BlindedForward { encrypted_tlvs: Vec, @@ -2479,9 +2484,20 @@ impl Writeable for OutboundOnionPayload { (6, short_channel_id, required) }); }, + Self::TrampolineEntry { + amt_to_forward, outgoing_cltv_value, ref payment_data, + ref trampoline_packet + } => { + _encode_varint_length_prefixed_tlv!(w, { + (2, HighZeroBytesDroppedBigSize(*amt_to_forward), required), + (4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required), + (8, payment_data, option), + (20, trampoline_packet, required) + }); + }, Self::Receive { ref payment_data, ref payment_metadata, ref keysend_preimage, sender_intended_htlc_amt_msat, - cltv_expiry_height, ref trampoline_packet, ref custom_tlvs, + cltv_expiry_height, ref custom_tlvs, } => { // We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`] // to reject any reserved types in the experimental range if new ones are ever @@ -2495,8 +2511,7 @@ impl Writeable for OutboundOnionPayload { (2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required), (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required), (8, payment_data, option), - (16, payment_metadata.as_ref().map(|m| WithoutLength(m)), option), - (20, trampoline_packet, option) + (16, payment_metadata.as_ref().map(|m| WithoutLength(m)), option) }, custom_tlvs.iter()); }, Self::BlindedForward { encrypted_tlvs, intro_node_blinding_point } => { @@ -4223,7 +4238,6 @@ mod tests { sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], - trampoline_packet: None }; let encoded_value = outbound_msg.encode(); let target_value = >::from_hex("1002080badf00d010203040404ffffffff").unwrap(); @@ -4252,7 +4266,6 @@ mod tests { sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], - trampoline_packet: None }; let encoded_value = outbound_msg.encode(); let target_value = >::from_hex("3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f").unwrap(); @@ -4292,7 +4305,6 @@ mod tests { custom_tlvs: bad_type_range_tlvs, sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, - trampoline_packet: None }; let encoded_value = msg.encode(); let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet); @@ -4325,7 +4337,6 @@ mod tests { custom_tlvs: expected_custom_tlvs.clone(), sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, - trampoline_packet: None }; let encoded_value = msg.encode(); let target_value = >::from_hex("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap(); @@ -4371,7 +4382,6 @@ mod tests { custom_tlvs: Vec::new(), sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, - trampoline_packet: Some(trampoline_packet), }; let encoded_payload = msg.encode(); diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 383d3c7e848..c705c4afda8 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -233,7 +233,6 @@ pub(super) fn build_onion_payloads( custom_tlvs: recipient_onion.custom_tlvs.clone(), sender_intended_htlc_amt_msat: value_msat, cltv_expiry_height: cltv, - trampoline_packet: None, }); } } else {