@@ -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 } ;
21
21
use crate :: ln:: features:: InvoiceFeatures ;
@@ -3011,6 +3011,71 @@ fn claim_from_closed_chan() {
3011
3011
do_claim_from_closed_chan ( false ) ;
3012
3012
}
3013
3013
3014
+ #[ test]
3015
+ fn test_custom_tlvs ( ) {
3016
+ do_test_custom_tlvs ( true ) ;
3017
+ do_test_custom_tlvs ( false ) ;
3018
+ }
3019
+
3020
+ fn do_test_custom_tlvs ( spontaneous : bool ) {
3021
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3022
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
3023
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None ; 2 ] ) ;
3024
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3025
+
3026
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
3027
+
3028
+ let amt_msat = 100_000 ;
3029
+ let ( mut route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , & nodes[ 1 ] , amt_msat) ;
3030
+ let payment_id = PaymentId ( our_payment_hash. 0 ) ;
3031
+ let custom_tlvs = vec ! [
3032
+ ( 5482373483 , vec![ 1 , 2 , 3 , 4 ] ) ,
3033
+ ( 5482373487 , vec![ 0x42u8 ; 16 ] ) ,
3034
+ ] ;
3035
+ let onion_fields = RecipientOnionFields {
3036
+ payment_secret : if spontaneous { None } else { Some ( our_payment_secret) } ,
3037
+ payment_metadata : None ,
3038
+ custom_tlvs : Some ( custom_tlvs. clone ( ) )
3039
+ } ;
3040
+ if spontaneous {
3041
+ nodes[ 0 ] . node . send_spontaneous_payment ( & route, Some ( our_payment_preimage) , onion_fields, payment_id) . unwrap ( ) ;
3042
+ } else {
3043
+ nodes[ 0 ] . node . send_payment_with_route ( & route, our_payment_hash, onion_fields, payment_id) . unwrap ( ) ;
3044
+ }
3045
+ check_added_monitors ( & nodes[ 0 ] , 1 ) ;
3046
+
3047
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
3048
+ let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
3049
+ let mut payment_event = SendEvent :: from_event ( ev) ;
3050
+
3051
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
3052
+ check_added_monitors ! ( & nodes[ 1 ] , 0 ) ;
3053
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
3054
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
3055
+
3056
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3057
+ assert_eq ! ( events. len( ) , 1 ) ;
3058
+ match events[ 0 ] {
3059
+ Event :: PaymentClaimable { ref purpose, amount_msat, ref onion_fields, .. } => {
3060
+ match & purpose {
3061
+ PaymentPurpose :: InvoicePayment { payment_secret, .. } => {
3062
+ assert_eq ! ( our_payment_secret, * payment_secret) ;
3063
+ assert_eq ! ( Some ( * payment_secret) , onion_fields. as_ref( ) . unwrap( ) . payment_secret) ;
3064
+ } ,
3065
+ PaymentPurpose :: SpontaneousPayment ( payment_preimage) => {
3066
+ assert_eq ! ( our_payment_preimage, * payment_preimage) ;
3067
+ } ,
3068
+ }
3069
+ assert_eq ! ( amount_msat, amt_msat) ;
3070
+ assert_eq ! ( onion_fields. clone( ) . unwrap( ) . custom_tlvs. unwrap( ) , custom_tlvs) ;
3071
+ } ,
3072
+ _ => panic ! ( "Unexpected event" ) ,
3073
+ }
3074
+
3075
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , our_payment_preimage) ;
3076
+ }
3077
+
3078
+
3014
3079
fn do_test_payment_metadata_consistency ( do_reload : bool , do_modify : bool ) {
3015
3080
// Check that a payment metadata received on one HTLC that doesn't match the one received on
3016
3081
// another results in the HTLC being rejected.
0 commit comments