@@ -3260,6 +3260,112 @@ fn do_test_custom_tlvs(spontaneous: bool) {
3260
3260
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , our_payment_preimage) ;
3261
3261
}
3262
3262
3263
+ #[ test]
3264
+ fn test_custom_tlvs_consistency ( ) {
3265
+ // Test that if we recieve two HTLCs with different custom TLVs we drop the non-matching TLVs
3266
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
3267
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
3268
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
3269
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
3270
+
3271
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 ) ;
3272
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 2 , 100_000 , 0 ) ;
3273
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 3 , 100_000 , 0 ) ;
3274
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 100_000 , 0 ) ;
3275
+
3276
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
3277
+ . with_bolt11_features ( nodes[ 3 ] . node . invoice_features ( ) ) . unwrap ( ) ;
3278
+ let mut route = get_route ! ( nodes[ 0 ] , payment_params, 15_000_000 ) . unwrap ( ) ;
3279
+ assert_eq ! ( route. paths. len( ) , 2 ) ;
3280
+ route. paths . sort_by ( |path_a, _| {
3281
+ // Sort the path so that the path through nodes[1] comes first
3282
+ if path_a. hops [ 0 ] . pubkey == nodes[ 1 ] . node . get_our_node_id ( ) {
3283
+ core:: cmp:: Ordering :: Less } else { core:: cmp:: Ordering :: Greater }
3284
+ } ) ;
3285
+
3286
+ let ( our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash ! ( & nodes[ 3 ] ) ;
3287
+ let payment_id = PaymentId ( [ 42 ; 32 ] ) ;
3288
+ let amt_msat = 15_000_000 ;
3289
+ let custom_tlvs = vec ! [
3290
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3291
+ ( 5482373487 , vec![ 0x42u8 ; 16 ] ) ,
3292
+ ] ;
3293
+ let onion_fields = RecipientOnionFields {
3294
+ payment_secret : Some ( our_payment_secret) ,
3295
+ payment_metadata : None ,
3296
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3297
+ } ;
3298
+ let session_privs = nodes[ 0 ] . node . test_add_new_pending_payment ( our_payment_hash,
3299
+ onion_fields. clone ( ) , payment_id, & route) . unwrap ( ) ;
3300
+ let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 ;
3301
+ nodes[ 0 ] . node . test_send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash,
3302
+ onion_fields. clone ( ) , amt_msat, cur_height, payment_id,
3303
+ & None , session_privs[ 0 ] ) . unwrap ( ) ;
3304
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
3305
+
3306
+ {
3307
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3308
+ assert_eq ! ( events. len( ) , 1 ) ;
3309
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 3 ] ] , amt_msat, our_payment_hash, Some ( our_payment_secret) , events. pop ( ) . unwrap ( ) , false , None ) ;
3310
+ }
3311
+ assert ! ( nodes[ 3 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3312
+
3313
+ let custom_tlvs = vec ! [
3314
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3315
+ ] ;
3316
+ let onion_fields = RecipientOnionFields {
3317
+ payment_secret : Some ( our_payment_secret) ,
3318
+ payment_metadata : None ,
3319
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3320
+ } ;
3321
+ nodes[ 0 ] . node . test_send_payment_along_path ( & route. paths [ 1 ] , & our_payment_hash,
3322
+ onion_fields. clone ( ) , amt_msat, cur_height, payment_id, & None , session_privs[ 1 ] ) . unwrap ( ) ;
3323
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
3324
+
3325
+ {
3326
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3327
+ assert_eq ! ( events. len( ) , 1 ) ;
3328
+ let payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
3329
+
3330
+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3331
+ commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
3332
+
3333
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
3334
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
3335
+
3336
+ let mut events = nodes[ 2 ] . node . get_and_clear_pending_msg_events ( ) ;
3337
+ assert_eq ! ( events. len( ) , 1 ) ;
3338
+ let payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
3339
+
3340
+ nodes[ 3 ] . node . handle_update_add_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3341
+ check_added_monitors ! ( nodes[ 3 ] , 0 ) ;
3342
+ commitment_signed_dance ! ( nodes[ 3 ] , nodes[ 2 ] , payment_event. commitment_msg, true , true ) ;
3343
+ }
3344
+ expect_pending_htlcs_forwardable_ignore ! ( nodes[ 3 ] ) ;
3345
+ nodes[ 3 ] . node . process_pending_htlc_forwards ( ) ;
3346
+
3347
+ let events = nodes[ 3 ] . node . get_and_clear_pending_events ( ) ;
3348
+ assert_eq ! ( events. len( ) , 1 ) ;
3349
+ match events[ 0 ] {
3350
+ Event :: PaymentClaimable { ref purpose, amount_msat, ref onion_fields, .. } => {
3351
+ match & purpose {
3352
+ PaymentPurpose :: InvoicePayment { payment_secret, .. } => {
3353
+ assert_eq ! ( our_payment_secret, * payment_secret) ;
3354
+ assert_eq ! ( Some ( * payment_secret) , onion_fields. as_ref( ) . unwrap( ) . payment_secret) ;
3355
+ } ,
3356
+ PaymentPurpose :: SpontaneousPayment ( payment_preimage) => {
3357
+ assert_eq ! ( our_payment_preimage, * payment_preimage) ;
3358
+ } ,
3359
+ }
3360
+ assert_eq ! ( amount_msat, amt_msat) ;
3361
+ assert_eq ! ( onion_fields. clone( ) . unwrap( ) . custom_tlvs. unwrap( ) , custom_tlvs) ;
3362
+ } ,
3363
+ _ => panic ! ( "Unexpected event" ) ,
3364
+ }
3365
+
3366
+ do_claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , our_payment_preimage) ;
3367
+ expect_payment_sent ( & nodes[ 0 ] , our_payment_preimage, Some ( Some ( 2000 ) ) , true ) ;
3368
+ }
3263
3369
3264
3370
fn do_test_payment_metadata_consistency ( do_reload : bool , do_modify : bool ) {
3265
3371
// Check that a payment metadata received on one HTLC that doesn't match the one received on
0 commit comments