@@ -18,7 +18,7 @@ use crate::routing::gossip::NetworkUpdate;
1818use crate :: routing:: router:: { BlindedTail , Path , RouteHop , RouteParameters , TrampolineHop } ;
1919use crate :: sign:: NodeSigner ;
2020use crate :: types:: features:: { ChannelFeatures , NodeFeatures } ;
21- use crate :: types:: payment:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
21+ use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
2222use crate :: util:: errors:: { self , APIError } ;
2323use crate :: util:: logger:: Logger ;
2424use crate :: util:: ser:: { LengthCalculatingWriter , Readable , ReadableArgs , Writeable , Writer } ;
@@ -1478,7 +1478,6 @@ pub fn create_payment_onion<T: secp256k1::Signing>(
14781478 prng_seed,
14791479 None ,
14801480 None ,
1481- None ,
14821481 )
14831482}
14841483
@@ -1488,8 +1487,8 @@ pub(crate) fn create_payment_onion_internal<T: secp256k1::Signing>(
14881487 secp_ctx : & Secp256k1 < T > , path : & Path , session_priv : & SecretKey , total_msat : u64 ,
14891488 recipient_onion : & RecipientOnionFields , cur_block_height : u32 , payment_hash : & PaymentHash ,
14901489 keysend_preimage : & Option < PaymentPreimage > , invoice_request : Option < & InvoiceRequest > ,
1491- prng_seed : [ u8 ; 32 ] , secondary_payment_secret : Option < PaymentSecret > ,
1492- secondary_session_priv : Option < SecretKey > , secondary_prng_seed : Option < [ u8 ; 32 ] > ,
1490+ prng_seed : [ u8 ; 32 ] , secondary_session_priv : Option < SecretKey > ,
1491+ secondary_prng_seed : Option < [ u8 ; 32 ] > ,
14931492) -> Result < ( msgs:: OnionPacket , u64 , u32 ) , APIError > {
14941493 let mut outer_total_msat = total_msat;
14951494 let mut outer_starting_htlc_offset = cur_block_height;
@@ -1526,54 +1525,23 @@ pub(crate) fn create_payment_onion_internal<T: secp256k1::Signing>(
15261525 } ) ?;
15271526
15281527 trampoline_packet_option = Some ( trampoline_packet) ;
1528+
1529+ outer_session_priv_override = Some ( secondary_session_priv. unwrap_or_else ( || {
1530+ let session_priv_hash = Sha256 :: hash ( & session_priv. secret_bytes ( ) ) . to_byte_array ( ) ;
1531+ SecretKey :: from_slice ( & session_priv_hash[ ..] ) . expect ( "You broke SHA-256!" )
1532+ } ) ) ;
15291533 }
15301534
1531- let ( mut onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads (
1535+ let ( onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads (
15321536 & path,
15331537 outer_total_msat,
15341538 recipient_onion,
15351539 outer_starting_htlc_offset,
15361540 keysend_preimage,
15371541 invoice_request,
1542+ trampoline_packet_option,
15381543 ) ?;
15391544
1540- if !path. trampoline_hops . is_empty ( ) {
1541- let last_payload = onion_payloads. pop ( ) . ok_or ( APIError :: InvalidRoute {
1542- err : "Non-Trampoline path needs at least one hop" . to_owned ( ) ,
1543- } ) ?;
1544-
1545- match last_payload {
1546- OutboundOnionPayload :: Receive { payment_data, .. } => {
1547- let fee_delta = path. hops . last ( ) . map_or ( 0 , |h| h. fee_msat ) ;
1548- let cltv_delta = path. hops . last ( ) . map_or ( 0 , |h| h. cltv_expiry_delta ) ;
1549- let multipath_trampoline_data = payment_data. map ( |d| {
1550- let trampoline_payment_secret = secondary_payment_secret. unwrap_or_else ( || {
1551- PaymentSecret ( Sha256 :: hash ( & d. payment_secret . 0 ) . to_byte_array ( ) )
1552- } ) ;
1553- let total_msat = fee_delta;
1554- FinalOnionHopData { payment_secret : trampoline_payment_secret, total_msat }
1555- } ) ;
1556- onion_payloads. push ( OutboundOnionPayload :: TrampolineEntrypoint {
1557- amt_to_forward : fee_delta,
1558- outgoing_cltv_value : outer_starting_htlc_offset + cltv_delta,
1559- multipath_trampoline_data,
1560- trampoline_packet : trampoline_packet_option. unwrap ( ) ,
1561- } ) ;
1562- } ,
1563- _ => {
1564- return Err ( APIError :: InvalidRoute {
1565- err : "Last non-Trampoline hop must be of type OutboundOnionPayload::Receive"
1566- . to_owned ( ) ,
1567- } ) ;
1568- } ,
1569- } ;
1570-
1571- outer_session_priv_override = Some ( secondary_session_priv. unwrap_or_else ( || {
1572- let session_priv_hash = Sha256 :: hash ( & session_priv. secret_bytes ( ) ) . to_byte_array ( ) ;
1573- SecretKey :: from_slice ( & session_priv_hash[ ..] ) . expect ( "You broke SHA-256!" )
1574- } ) ) ;
1575- }
1576-
15771545 let outer_session_priv = outer_session_priv_override. as_ref ( ) . unwrap_or ( session_priv) ;
15781546 let onion_keys = construct_onion_keys ( & secp_ctx, & path, outer_session_priv) . map_err ( |_| {
15791547 APIError :: InvalidRoute { err : "Pubkey along hop was maliciously selected" . to_owned ( ) }
0 commit comments