@@ -15,7 +15,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Listen, Watch};
15
15
use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , HTLC_FAIL_BACK_BUFFER , LATENCY_GRACE_PERIOD_BLOCKS } ;
16
16
use crate :: sign:: EntropySource ;
17
17
use crate :: chain:: transaction:: OutPoint ;
18
- use crate :: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PathFailure , PaymentFailureReason } ;
18
+ use crate :: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PathFailure , PaymentFailureReason , PaymentPurpose } ;
19
19
use crate :: ln:: channel:: EXPIRE_PREV_CONFIG_TICKS ;
20
20
use crate :: ln:: channelmanager:: { BREAKDOWN_TIMEOUT , ChannelManager , MPP_TIMEOUT_TICKS , MIN_CLTV_EXPIRY_DELTA , PaymentId , PaymentSendFailure , IDEMPOTENCY_TIMEOUT_TICKS , RecentPaymentDetails , RecipientOnionFields , HTLCForwardInfo , PendingHTLCRouting , PendingAddHTLCInfo } ;
21
21
use crate :: ln:: features:: InvoiceFeatures ;
@@ -3196,6 +3196,71 @@ fn claim_from_closed_chan() {
3196
3196
do_claim_from_closed_chan ( false ) ;
3197
3197
}
3198
3198
3199
+ #[ test]
3200
+ fn test_custom_tlvs ( ) {
3201
+ do_test_custom_tlvs ( true ) ;
3202
+ do_test_custom_tlvs ( false ) ;
3203
+ }
3204
+
3205
+ fn do_test_custom_tlvs ( spontaneous : bool ) {
3206
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3207
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3208
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None ; 2 ] ) ;
3209
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3210
+
3211
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
3212
+
3213
+ let amt_msat = 100_000 ;
3214
+ let ( mut route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , & nodes[ 1 ] , amt_msat) ;
3215
+ let payment_id = PaymentId ( our_payment_hash. 0 ) ;
3216
+ let custom_tlvs = vec ! [
3217
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3218
+ ( 5482373487 , vec![ 0x42u8 ; 16 ] ) ,
3219
+ ] ;
3220
+ let onion_fields = RecipientOnionFields {
3221
+ payment_secret : if spontaneous { None } else { Some ( our_payment_secret) } ,
3222
+ payment_metadata : None ,
3223
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3224
+ } ;
3225
+ if spontaneous {
3226
+ nodes[ 0 ] . node . send_spontaneous_payment ( & route, Some ( our_payment_preimage) , onion_fields, payment_id) . unwrap ( ) ;
3227
+ } else {
3228
+ nodes[ 0 ] . node . send_payment_with_route ( & route, our_payment_hash, onion_fields, payment_id) . unwrap ( ) ;
3229
+ }
3230
+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
3231
+
3232
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3233
+ let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
3234
+ let mut payment_event = SendEvent :: from_event ( ev) ;
3235
+
3236
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3237
+ check_added_monitors ! ( & nodes[ 1 ] , 0 ) ;
3238
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
3239
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3240
+
3241
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3242
+ assert_eq ! ( events. len( ) , 1 ) ;
3243
+ match events[ 0 ] {
3244
+ Event :: PaymentClaimable { ref purpose, amount_msat, ref onion_fields, .. } => {
3245
+ match & purpose {
3246
+ PaymentPurpose :: InvoicePayment { payment_secret, .. } => {
3247
+ assert_eq ! ( our_payment_secret, * payment_secret) ;
3248
+ assert_eq ! ( Some ( * payment_secret) , onion_fields. as_ref( ) . unwrap( ) . payment_secret) ;
3249
+ } ,
3250
+ PaymentPurpose :: SpontaneousPayment ( payment_preimage) => {
3251
+ assert_eq ! ( our_payment_preimage, * payment_preimage) ;
3252
+ } ,
3253
+ }
3254
+ assert_eq ! ( amount_msat, amt_msat) ;
3255
+ assert_eq ! ( onion_fields. clone( ) . unwrap( ) . custom_tlvs( ) . clone( ) . unwrap( ) , custom_tlvs) ;
3256
+ } ,
3257
+ _ => panic ! ( "Unexpected event" ) ,
3258
+ }
3259
+
3260
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , our_payment_preimage) ;
3261
+ }
3262
+
3263
+
3199
3264
fn do_test_payment_metadata_consistency ( do_reload : bool , do_modify : bool ) {
3200
3265
// Check that a payment metadata received on one HTLC that doesn't match the one received on
3201
3266
// another results in the HTLC being rejected.
0 commit comments