@@ -936,26 +936,23 @@ pub(crate) fn decode_next_payment_hop<NS: Deref>(
936
936
}
937
937
938
938
/// Build a payment onion, returning the first hop msat and cltv values as well.
939
- pub fn create_payment_onion < T > (
940
- secp_ctx : & Secp256k1 < T > , path : & Path , session_priv : & SecretKey , total_msat : u64 ,
941
- recipient_onion : RecipientOnionFields , best_block_height : u32 , payment_hash : PaymentHash ,
942
- keysend_preimage : Option < PaymentPreimage > , prng_seed : [ u8 ; 32 ]
943
- ) -> Result < ( u64 , u32 , msgs:: OnionPacket ) , ( ) >
944
- where
945
- T : secp256k1 :: Signing
946
- {
947
- let onion_keys = construct_onion_keys ( & secp_ctx , & path , & session_priv ) . map_err ( |_| ( ) ) ?;
939
+ pub fn create_payment_onion < T : secp256k1 :: Signing > (
940
+ secp_ctx : & Secp256k1 < T > , path : & Path , session_priv : & SecretKey , total_msat : u64 ,
941
+ recipient_onion : RecipientOnionFields , best_block_height : u32 , payment_hash : & PaymentHash ,
942
+ keysend_preimage : & Option < PaymentPreimage > , prng_seed : [ u8 ; 32 ]
943
+ ) -> Result < ( msgs:: OnionPacket , u64 , u32 ) , APIError > {
944
+ let onion_keys = construct_onion_keys ( & secp_ctx , & path , & session_priv )
945
+ . map_err ( |_| APIError :: InvalidRoute {
946
+ err : "Pubkey along hop was maliciously selected" . to_owned ( )
947
+ } ) ?;
948
948
let ( onion_payloads, htlc_msat, htlc_cltv) = build_onion_payloads (
949
- & path,
950
- total_msat,
951
- recipient_onion,
952
- best_block_height + 1 ,
953
- & keysend_preimage,
954
- ) . map_err ( |_| ( ) ) ?;
955
- let onion_packet = construct_onion_packet (
956
- onion_payloads, onion_keys, prng_seed, & payment_hash
949
+ & path, total_msat, recipient_onion, best_block_height, keysend_preimage
957
950
) ?;
958
- Ok ( ( htlc_msat, htlc_cltv, onion_packet) )
951
+ let onion_packet = construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash)
952
+ . map_err ( |_| APIError :: InvalidRoute {
953
+ err : "Route size too large considering onion data" . to_owned ( )
954
+ } ) ?;
955
+ Ok ( ( onion_packet, htlc_msat, htlc_cltv) )
959
956
}
960
957
961
958
pub ( crate ) fn decode_next_untagged_hop < T , R : ReadableArgs < T > , N : NextPacketBytes > ( shared_secret : [ u8 ; 32 ] , hop_data : & [ u8 ] , hmac_bytes : [ u8 ; 32 ] , read_args : T ) -> Result < ( R , Option < ( [ u8 ; 32 ] , N ) > ) , OnionDecodeErr > {
0 commit comments