@@ -3075,6 +3075,112 @@ fn do_test_custom_tlvs(spontaneous: bool) {
3075
3075
claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , our_payment_preimage) ;
3076
3076
}
3077
3077
3078
+ #[ test]
3079
+ fn test_custom_tlvs_consistency ( ) {
3080
+ // Test that if we recieve two HTLCs with different custom TLVs we drop the non-matching TLVs
3081
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
3082
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
3083
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
3084
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
3085
+
3086
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100_000 , 0 ) ;
3087
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 2 , 100_000 , 0 ) ;
3088
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 3 , 100_000 , 0 ) ;
3089
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 100_000 , 0 ) ;
3090
+
3091
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 3 ] . node . get_our_node_id ( ) , TEST_FINAL_CLTV )
3092
+ . with_bolt11_features ( nodes[ 3 ] . node . invoice_features ( ) ) . unwrap ( ) ;
3093
+ let mut route = get_route ! ( nodes[ 0 ] , payment_params, 15_000_000 ) . unwrap ( ) ;
3094
+ assert_eq ! ( route. paths. len( ) , 2 ) ;
3095
+ route. paths . sort_by ( |path_a, _| {
3096
+ // Sort the path so that the path through nodes[1] comes first
3097
+ if path_a. hops [ 0 ] . pubkey == nodes[ 1 ] . node . get_our_node_id ( ) {
3098
+ core:: cmp:: Ordering :: Less } else { core:: cmp:: Ordering :: Greater }
3099
+ } ) ;
3100
+
3101
+ let ( our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash ! ( & nodes[ 3 ] ) ;
3102
+ let payment_id = PaymentId ( [ 42 ; 32 ] ) ;
3103
+ let amt_msat = 15_000_000 ;
3104
+ let custom_tlvs = vec ! [
3105
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3106
+ ( 5482373487 , vec![ 0x42u8 ; 16 ] ) ,
3107
+ ] ;
3108
+ let onion_fields = RecipientOnionFields {
3109
+ payment_secret : Some ( our_payment_secret) ,
3110
+ payment_metadata : None ,
3111
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3112
+ } ;
3113
+ let session_privs = nodes[ 0 ] . node . test_add_new_pending_payment ( our_payment_hash,
3114
+ onion_fields. clone ( ) , payment_id, & route) . unwrap ( ) ;
3115
+ let cur_height = nodes[ 0 ] . best_block_info ( ) . 1 ;
3116
+ nodes[ 0 ] . node . test_send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash,
3117
+ onion_fields. clone ( ) , amt_msat, cur_height, payment_id,
3118
+ & None , session_privs[ 0 ] ) . unwrap ( ) ;
3119
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
3120
+
3121
+ {
3122
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3123
+ assert_eq ! ( events. len( ) , 1 ) ;
3124
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 3 ] ] , amt_msat, our_payment_hash, Some ( our_payment_secret) , events. pop ( ) . unwrap ( ) , false , None ) ;
3125
+ }
3126
+ assert ! ( nodes[ 3 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
3127
+
3128
+ let custom_tlvs = vec ! [
3129
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3130
+ ] ;
3131
+ let onion_fields = RecipientOnionFields {
3132
+ payment_secret : Some ( our_payment_secret) ,
3133
+ payment_metadata : None ,
3134
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3135
+ } ;
3136
+ nodes[ 0 ] . node . test_send_payment_along_path ( & route. paths [ 1 ] , & our_payment_hash,
3137
+ onion_fields. clone ( ) , amt_msat, cur_height, payment_id, & None , session_privs[ 1 ] ) . unwrap ( ) ;
3138
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
3139
+
3140
+ {
3141
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3142
+ assert_eq ! ( events. len( ) , 1 ) ;
3143
+ let payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
3144
+
3145
+ nodes[ 2 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3146
+ commitment_signed_dance ! ( nodes[ 2 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
3147
+
3148
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
3149
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
3150
+
3151
+ let mut events = nodes[ 2 ] . node . get_and_clear_pending_msg_events ( ) ;
3152
+ assert_eq ! ( events. len( ) , 1 ) ;
3153
+ let payment_event = SendEvent :: from_event ( events. pop ( ) . unwrap ( ) ) ;
3154
+
3155
+ nodes[ 3 ] . node . handle_update_add_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3156
+ check_added_monitors ! ( nodes[ 3 ] , 0 ) ;
3157
+ commitment_signed_dance ! ( nodes[ 3 ] , nodes[ 2 ] , payment_event. commitment_msg, true , true ) ;
3158
+ }
3159
+ expect_pending_htlcs_forwardable_ignore ! ( nodes[ 3 ] ) ;
3160
+ nodes[ 3 ] . node . process_pending_htlc_forwards ( ) ;
3161
+
3162
+ let events = nodes[ 3 ] . node . get_and_clear_pending_events ( ) ;
3163
+ assert_eq ! ( events. len( ) , 1 ) ;
3164
+ match events[ 0 ] {
3165
+ Event :: PaymentClaimable { ref purpose, amount_msat, ref onion_fields, .. } => {
3166
+ match & purpose {
3167
+ PaymentPurpose :: InvoicePayment { payment_secret, .. } => {
3168
+ assert_eq ! ( our_payment_secret, * payment_secret) ;
3169
+ assert_eq ! ( Some ( * payment_secret) , onion_fields. as_ref( ) . unwrap( ) . payment_secret) ;
3170
+ } ,
3171
+ PaymentPurpose :: SpontaneousPayment ( payment_preimage) => {
3172
+ assert_eq ! ( our_payment_preimage, * payment_preimage) ;
3173
+ } ,
3174
+ }
3175
+ assert_eq ! ( amount_msat, amt_msat) ;
3176
+ assert_eq ! ( onion_fields. clone( ) . unwrap( ) . custom_tlvs. unwrap( ) , custom_tlvs) ;
3177
+ } ,
3178
+ _ => panic ! ( "Unexpected event" ) ,
3179
+ }
3180
+
3181
+ do_claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , our_payment_preimage) ;
3182
+ expect_payment_sent ( & nodes[ 0 ] , our_payment_preimage, Some ( Some ( 2000 ) ) , true ) ;
3183
+ }
3078
3184
3079
3185
fn do_test_payment_metadata_consistency ( do_reload : bool , do_modify : bool ) {
3080
3186
// Check that a payment metadata received on one HTLC that doesn't match the one received on
0 commit comments