@@ -13,7 +13,8 @@ use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, schnorr};
1313use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
1414use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
1515use crate :: blinded_path;
16- use crate :: blinded_path:: payment:: { BlindedPaymentPath , Bolt12RefundContext , PaymentForwardNode , ForwardTlvs , PaymentConstraints , PaymentContext , PaymentRelay , UnauthenticatedReceiveTlvs } ;
16+ use crate :: blinded_path:: payment:: { BlindedPaymentPath , Bolt12RefundContext , ForwardTlvs , PaymentConstraints , PaymentContext , PaymentForwardNode , PaymentRelay , UnauthenticatedReceiveTlvs , PAYMENT_PADDING_ROUND_OFF } ;
17+ use crate :: blinded_path:: utils:: is_padded;
1718use crate :: events:: { Event , HTLCDestination , PaymentFailureReason } ;
1819use crate :: ln:: types:: ChannelId ;
1920use crate :: types:: payment:: { PaymentHash , PaymentSecret } ;
@@ -367,7 +368,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
367368 let mut route_params = get_blinded_route_parameters ( amt_msat, payment_secret, 1 , 1_0000_0000 ,
368369 nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) ,
369370 & [ & chan_upd_1_2, & chan_upd_2_3] , & chanmon_cfgs[ 3 ] . keys_manager ) ;
370- route_params. payment_params . max_path_length = 17 ;
371+ route_params. payment_params . max_path_length = 16 ;
371372
372373 let route = get_route ( & nodes[ 0 ] , & route_params) . unwrap ( ) ;
373374 node_cfgs[ 0 ] . router . expect_find_route ( route_params. clone ( ) , Ok ( route. clone ( ) ) ) ;
@@ -892,6 +893,8 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
892893 nodes. iter ( ) . skip ( 1 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_upd_1_2] ,
893894 & chanmon_cfgs[ 2 ] . keys_manager ) ;
894895
896+ route_params. payment_params . max_path_length = 17 ;
897+
895898 let route = if check == ReceiveCheckFail :: ProcessPendingHTLCsCheck {
896899 let mut route = get_route ( & nodes[ 0 ] , & route_params) . unwrap ( ) ;
897900 // Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards.
@@ -1446,6 +1449,42 @@ fn fails_receive_tlvs_authentication() {
14461449 ) ;
14471450}
14481451
1452+ #[ test]
1453+ fn blinded_payment_path_padding ( ) {
1454+ // Make sure that for a blinded payment path, all encrypted payloads are padded to equal lengths.
1455+ let chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
1456+ let node_cfgs = create_node_cfgs ( 5 , & chanmon_cfgs) ;
1457+ let node_chanmgrs = create_node_chanmgrs ( 5 , & node_cfgs, & [ None , None , None , None , None ] ) ;
1458+ let mut nodes = create_network ( 5 , & node_cfgs, & node_chanmgrs) ;
1459+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 ) ;
1460+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 1_000_000 , 0 ) ;
1461+ let chan_upd_2_3 = create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 1_000_000 , 0 ) . 0 . contents ;
1462+ let chan_upd_3_4 = create_announced_chan_between_nodes_with_value ( & nodes, 3 , 4 , 1_000_000 , 0 ) . 0 . contents ;
1463+
1464+ // Get all our nodes onto the same height so payments don't fail for CLTV violations.
1465+ connect_blocks ( & nodes[ 0 ] , nodes[ 4 ] . best_block_info ( ) . 1 - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
1466+ connect_blocks ( & nodes[ 1 ] , nodes[ 4 ] . best_block_info ( ) . 1 - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
1467+ connect_blocks ( & nodes[ 2 ] , nodes[ 4 ] . best_block_info ( ) . 1 - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
1468+ assert_eq ! ( nodes[ 4 ] . best_block_info( ) . 1 , nodes[ 3 ] . best_block_info( ) . 1 ) ;
1469+
1470+ let amt_msat = 5000 ;
1471+ let ( payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 4 ] , Some ( amt_msat) , None ) ;
1472+
1473+ let blinded_path = blinded_payment_path ( payment_secret, 1 , 1_0000_0000 ,
1474+ nodes. iter ( ) . skip ( 2 ) . map ( |n| n. node . get_our_node_id ( ) ) . collect ( ) , & [ & chan_upd_2_3, & chan_upd_3_4] ,
1475+ & chanmon_cfgs[ 4 ] . keys_manager
1476+ ) ;
1477+
1478+ assert ! ( is_padded( & blinded_path. blinded_hops( ) , PAYMENT_PADDING_ROUND_OFF ) ) ;
1479+
1480+ let route_params = RouteParameters :: from_payment_params_and_value ( PaymentParameters :: blinded ( vec ! [ blinded_path] ) , amt_msat) ;
1481+
1482+ nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
1483+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
1484+ pass_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] ] , amt_msat, payment_hash, payment_secret) ;
1485+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] ] , payment_preimage) ;
1486+ }
1487+
14491488fn secret_from_hex ( hex : & str ) -> SecretKey {
14501489 SecretKey :: from_slice ( & <Vec < u8 > >:: from_hex ( hex) . unwrap ( ) ) . unwrap ( )
14511490}
0 commit comments