Skip to content

Commit eba3f90

Browse files
committed
Trampoline payload construction method
Trampoline routing relies on serializing an inner onion within the hop data. In this commit, we introduce the method to serialize it based on the augmented path data introduced in the previous commit.
1 parent 03762ba commit eba3f90

7 files changed

+677
-111
lines changed

lightning/src/ln/blinded_payment_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
365365
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
366366
let cur_height = nodes[0].best_block_info().1;
367367
let (mut onion_payloads, ..) = onion_utils::build_onion_payloads(
368-
&route.paths[0], amt_msat, &recipient_onion_fields, cur_height, &None, None).unwrap();
368+
&route.paths[0], amt_msat, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
369369
// Remove the receive payload so the blinded forward payload is encoded as a final payload
370370
// (i.e. next_hop_hmac == [0; 32])
371371
onion_payloads.pop();
@@ -935,7 +935,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
935935
let cur_height = nodes[0].best_block_info().1;
936936
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
937937
let (mut onion_payloads, ..) = onion_utils::build_onion_payloads(
938-
&route.paths[0], amt_msat, &recipient_onion_fields, cur_height, &None, None).unwrap();
938+
&route.paths[0], amt_msat, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
939939

940940
let update_add = &mut payment_event_1_2.msgs[0];
941941
onion_payloads.last_mut().map(|p| {

lightning/src/ln/functional_tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ fn test_fee_spike_violation_fails_htlc() {
14281428
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
14291429
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
14301430
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
1431-
3460001, &recipient_onion_fields, cur_height, &None, None).unwrap();
1431+
3460001, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
14321432
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
14331433
let msg = msgs::UpdateAddHTLC {
14341434
channel_id: chan.2,
@@ -1623,7 +1623,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
16231623
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
16241624
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
16251625
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
1626-
700_000, &recipient_onion_fields, cur_height, &None, None).unwrap();
1626+
700_000, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
16271627
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
16281628
let msg = msgs::UpdateAddHTLC {
16291629
channel_id: chan.2,
@@ -1803,7 +1803,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
18031803
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route_2.paths[0], &session_priv).unwrap();
18041804
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
18051805
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
1806-
&route_2.paths[0], recv_value_2, &recipient_onion_fields, cur_height, &None, None).unwrap();
1806+
&route_2.paths[0], recv_value_2, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
18071807
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &our_payment_hash_1).unwrap();
18081808
let msg = msgs::UpdateAddHTLC {
18091809
channel_id: chan.2,
@@ -3856,7 +3856,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() {
38563856
let current_height = nodes[1].node.best_block.read().unwrap().height + 1;
38573857
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
38583858
let (onion_payloads, _amount_msat, cltv_expiry) = onion_utils::build_onion_payloads(
3859-
&route.paths[0], 50_000, &recipient_onion_fields, current_height, &None, None).unwrap();
3859+
&route.paths[0], 50_000, &recipient_onion_fields, current_height, &None, None, None).unwrap();
38603860
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
38613861
let onion_routing_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
38623862

@@ -6852,7 +6852,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
68526852
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::signing_only(), &route.paths[0], &session_priv).unwrap();
68536853
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
68546854
let (onion_payloads, _htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
6855-
&route.paths[0], send_amt, &recipient_onion_fields, cur_height, &None, None).unwrap();
6855+
&route.paths[0], send_amt, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
68566856
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &our_payment_hash).unwrap();
68576857

68586858
let mut msg = msgs::UpdateAddHTLC {
@@ -8607,7 +8607,7 @@ fn test_onion_value_mpp_set_calculation() {
86078607
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
86088608
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
86098609
let (mut onion_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], 100_000,
8610-
&recipient_onion_fields, height + 1, &None, None).unwrap();
8610+
&recipient_onion_fields, height + 1, &None, None, None).unwrap();
86118611
// Edit amt_to_forward to simulate the sender having set
86128612
// the final amount and the routing node taking less fee
86138613
if let msgs::OutboundOnionPayload::Receive {

lightning/src/ln/max_payment_path_len_tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ fn blinded_path_with_custom_tlv() {
281281
let reserved_packet_bytes_without_custom_tlv: usize = onion_utils::build_onion_payloads(
282282
&route.paths[0], MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
283283
&RecipientOnionFields::spontaneous_empty(),
284-
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &None, None
284+
nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, &None,
285+
None, None
285286
)
286287
.unwrap()
287288
.0

lightning/src/ln/msgs.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,6 @@ mod fuzzy_internal_msgs {
18341834
}
18351835

18361836
pub(crate) enum OutboundTrampolinePayload<'a> {
1837-
#[allow(unused)]
18381837
Forward {
18391838
/// The value, in msat, of the payment after this hop's fee is deducted.
18401839
amt_to_forward: u64,
@@ -1854,12 +1853,10 @@ mod fuzzy_internal_msgs {
18541853
/// If applicable, features of the BOLT12 invoice being paid.
18551854
invoice_features: Option<Bolt12InvoiceFeatures>,
18561855
},
1857-
#[allow(unused)]
18581856
BlindedForward {
18591857
encrypted_tlvs: &'a Vec<u8>,
18601858
intro_node_blinding_point: Option<PublicKey>,
18611859
},
1862-
#[allow(unused)]
18631860
BlindedReceive {
18641861
sender_intended_htlc_amt_msat: u64,
18651862
total_msat: u64,

lightning/src/ln/onion_payment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ mod tests {
537537
let path = Path { hops, blinded_tail: None, };
538538
let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap();
539539
let (onion_payloads, ..) = super::onion_utils::build_onion_payloads(
540-
&path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage), None
540+
&path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage), None, None
541541
).unwrap();
542542

543543
assert!(super::onion_utils::construct_onion_packet(

0 commit comments

Comments
 (0)