Skip to content

Commit

Permalink
Move Trampoline data to separate enum variant on OutboundOnionPayload.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Mar 14, 2024
1 parent c4fda75 commit ff22217
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 19 additions & 9 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,14 +1698,19 @@ mod fuzzy_internal_msgs {
amt_to_forward: u64,
outgoing_cltv_value: u32,
},
TrampolineEntry {
amt_to_forward: u64,
outgoing_cltv_value: u32,
payment_data: Option<FinalOnionHopData>,
trampoline_packet: crate::onion_message::packet::Packet
},
Receive {
payment_data: Option<FinalOnionHopData>,
payment_metadata: Option<Vec<u8>>,
keysend_preimage: Option<PaymentPreimage>,
custom_tlvs: Vec<(u64, Vec<u8>)>,
sender_intended_htlc_amt_msat: u64,
cltv_expiry_height: u32,
trampoline_packet: Option<crate::onion_message::packet::Packet>
},
BlindedForward {
encrypted_tlvs: Vec<u8>,
Expand Down Expand Up @@ -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
Expand All @@ -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 } => {
Expand Down Expand Up @@ -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 = <Vec<u8>>::from_hex("1002080badf00d010203040404ffffffff").unwrap();
Expand Down Expand Up @@ -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 = <Vec<u8>>::from_hex("3602080badf00d010203040404ffffffff082442424242424242424242424242424242424242424242424242424242424242421badca1f").unwrap();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = <Vec<u8>>::from_hex("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap();
Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ff22217

Please sign in to comment.