@@ -394,15 +394,17 @@ pub(super) fn build_onion_payloads(
394
394
395
395
/// returns the hop data, as well as the first-hop value_msat and CLTV value we should send.
396
396
pub ( super ) fn build_trampoline_payloads (
397
- path : & [ TrampolineHop ] , total_msat : u64 , mut recipient_onion : RecipientOnionFields ,
397
+ path : & Path , total_msat : u64 , mut recipient_onion : RecipientOnionFields ,
398
398
starting_htlc_offset : u32 , keysend_preimage : & Option < PaymentPreimage > ,
399
399
) -> Result < ( Vec < msgs:: OutboundOnionPayload > , u64 , u32 ) , APIError > {
400
400
let mut cur_value_msat = 0u64 ;
401
401
let mut cur_cltv = starting_htlc_offset;
402
- let mut res: Vec < msgs:: OutboundOnionPayload > = Vec :: with_capacity ( path. len ( ) ) ;
403
402
let mut last_node_id = None ;
403
+ let mut res: Vec < msgs:: OutboundOnionPayload > = Vec :: with_capacity (
404
+ path. trampoline_hops . len ( ) + path. blinded_tail . as_ref ( ) . map_or ( 0 , |t| t. hops . len ( ) ) ,
405
+ ) ;
404
406
405
- for ( idx, hop) in path. iter ( ) . rev ( ) . enumerate ( ) {
407
+ for ( idx, hop) in path. trampoline_hops . iter ( ) . rev ( ) . enumerate ( ) {
406
408
// First hop gets special values so that it can check, on receipt, that everything is
407
409
// exactly as it should be (and the next hop isn't trying to probe to find out if we're
408
410
// the intended recipient).
@@ -413,25 +415,54 @@ pub(super) fn build_trampoline_payloads(
413
415
cur_cltv
414
416
} ;
415
417
if idx == 0 {
416
- res. push ( msgs:: OutboundOnionPayload :: Receive {
417
- payment_data : if let Some ( secret) = recipient_onion. payment_secret . take ( ) {
418
- Some ( msgs:: FinalOnionHopData { payment_secret : secret, total_msat } )
419
- } else {
420
- None
421
- } ,
422
- payment_metadata : recipient_onion. payment_metadata . take ( ) ,
423
- keysend_preimage : * keysend_preimage,
424
- custom_tlvs : recipient_onion. custom_tlvs . clone ( ) ,
425
- sender_intended_htlc_amt_msat : value_msat,
426
- cltv_expiry_height : cltv,
427
- } ) ;
418
+ if let Some ( BlindedTail {
419
+ blinding_point,
420
+ hops,
421
+ final_value_msat,
422
+ excess_final_cltv_expiry_delta,
423
+ ..
424
+ } ) = & path. blinded_tail
425
+ {
426
+ let mut blinding_point = Some ( * blinding_point) ;
427
+ for ( i, blinded_hop) in hops. iter ( ) . enumerate ( ) {
428
+ if i == hops. len ( ) - 1 {
429
+ cur_value_msat += final_value_msat;
430
+ res. push ( msgs:: OutboundOnionPayload :: BlindedReceive {
431
+ sender_intended_htlc_amt_msat : * final_value_msat,
432
+ total_msat,
433
+ cltv_expiry_height : cur_cltv + excess_final_cltv_expiry_delta,
434
+ encrypted_tlvs : blinded_hop. encrypted_payload . clone ( ) ,
435
+ intro_node_blinding_point : blinding_point. take ( ) ,
436
+ } ) ;
437
+ } else {
438
+ res. push ( msgs:: OutboundOnionPayload :: BlindedForward {
439
+ encrypted_tlvs : blinded_hop. encrypted_payload . clone ( ) ,
440
+ intro_node_blinding_point : blinding_point. take ( ) ,
441
+ } ) ;
442
+ }
443
+ }
444
+ } else {
445
+ res. push ( msgs:: OutboundOnionPayload :: Receive {
446
+ payment_data : if let Some ( secret) = recipient_onion. payment_secret . take ( ) {
447
+ Some ( msgs:: FinalOnionHopData { payment_secret : secret, total_msat } )
448
+ } else {
449
+ None
450
+ } ,
451
+ payment_metadata : recipient_onion. payment_metadata . take ( ) ,
452
+ keysend_preimage : * keysend_preimage,
453
+ custom_tlvs : recipient_onion. custom_tlvs . clone ( ) ,
454
+ sender_intended_htlc_amt_msat : value_msat,
455
+ cltv_expiry_height : cltv,
456
+ } ) ;
457
+ }
428
458
} else {
429
459
res. insert (
430
460
0 ,
431
461
msgs:: OutboundOnionPayload :: TrampolineForward {
432
462
amt_to_forward : value_msat,
433
463
outgoing_cltv_value : cltv,
434
- outgoing_node_id : last_node_id. unwrap ( ) ,
464
+ outgoing_node_id : last_node_id
465
+ . expect ( "outgoing node id cannot be None after last hop" ) ,
435
466
} ,
436
467
) ;
437
468
}
0 commit comments