@@ -112,6 +112,8 @@ pub(super) enum PendingHTLCRouting {
112
112
phantom_shared_secret : Option < [ u8 ; 32 ] > ,
113
113
} ,
114
114
ReceiveKeysend {
115
+ /// This was added in 0.0.116 and will break deserialization on downgrades.
116
+ payment_data : Option < msgs:: FinalOnionHopData > ,
115
117
payment_preimage : PaymentPreimage ,
116
118
payment_metadata : Option < Vec < u8 > > ,
117
119
incoming_cltv_expiry : u32 , // Used to track when we should expire pending HTLCs that go unclaimed
@@ -2342,20 +2344,7 @@ where
2342
2344
} ) ;
2343
2345
} ,
2344
2346
msgs:: OnionHopDataFormat :: FinalNode { payment_data, keysend_preimage, payment_metadata } => {
2345
- if payment_data. is_some ( ) && keysend_preimage. is_some ( ) {
2346
- return Err ( ReceiveError {
2347
- err_code : 0x4000 |22 ,
2348
- err_data : Vec :: new ( ) ,
2349
- msg : "We don't support MPP keysend payments" ,
2350
- } ) ;
2351
- } else if let Some ( data) = payment_data {
2352
- PendingHTLCRouting :: Receive {
2353
- payment_data : data,
2354
- payment_metadata,
2355
- incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2356
- phantom_shared_secret,
2357
- }
2358
- } else if let Some ( payment_preimage) = keysend_preimage {
2347
+ if let Some ( payment_preimage) = keysend_preimage {
2359
2348
// We need to check that the sender knows the keysend preimage before processing this
2360
2349
// payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
2361
2350
// could discover the final destination of X, by probing the adjacent nodes on the route
@@ -2369,12 +2358,26 @@ where
2369
2358
msg : "Payment preimage didn't match payment hash" ,
2370
2359
} ) ;
2371
2360
}
2372
-
2361
+ if !self . default_configuration . accept_mpp_keysend && payment_data. is_some ( ) {
2362
+ return Err ( ReceiveError {
2363
+ err_code : 0x4000 |22 ,
2364
+ err_data : Vec :: new ( ) ,
2365
+ msg : "We don't support MPP keysend payments" ,
2366
+ } ) ;
2367
+ }
2373
2368
PendingHTLCRouting :: ReceiveKeysend {
2369
+ payment_data,
2374
2370
payment_preimage,
2375
2371
payment_metadata,
2376
2372
incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2377
2373
}
2374
+ } else if let Some ( data) = payment_data {
2375
+ PendingHTLCRouting :: Receive {
2376
+ payment_data : data,
2377
+ payment_metadata,
2378
+ incoming_cltv_expiry : hop_data. outgoing_cltv_value ,
2379
+ phantom_shared_secret,
2380
+ }
2378
2381
} else {
2379
2382
return Err ( ReceiveError {
2380
2383
err_code : 0x4000 |0x2000 |3 ,
@@ -3490,10 +3493,13 @@ where
3490
3493
( incoming_cltv_expiry, OnionPayload :: Invoice { _legacy_hop_data } ,
3491
3494
Some ( payment_data) , phantom_shared_secret, onion_fields)
3492
3495
} ,
3493
- PendingHTLCRouting :: ReceiveKeysend { payment_preimage, payment_metadata, incoming_cltv_expiry } => {
3494
- let onion_fields = RecipientOnionFields { payment_secret : None , payment_metadata } ;
3496
+ PendingHTLCRouting :: ReceiveKeysend { payment_data, payment_preimage, payment_metadata, incoming_cltv_expiry } => {
3497
+ let onion_fields = RecipientOnionFields {
3498
+ payment_secret : payment_data. as_ref ( ) . map ( |data| data. payment_secret ) ,
3499
+ payment_metadata
3500
+ } ;
3495
3501
( incoming_cltv_expiry, OnionPayload :: Spontaneous ( payment_preimage) ,
3496
- None , None , onion_fields)
3502
+ payment_data , None , onion_fields)
3497
3503
} ,
3498
3504
_ => {
3499
3505
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
@@ -7058,6 +7064,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
7058
7064
( 0 , payment_preimage, required) ,
7059
7065
( 2 , incoming_cltv_expiry, required) ,
7060
7066
( 3 , payment_metadata, option) ,
7067
+ ( 4 , payment_data, option) , // Added in 0.0.116
7061
7068
} ,
7062
7069
; ) ;
7063
7070
@@ -8704,10 +8711,13 @@ mod tests {
8704
8711
8705
8712
#[ test]
8706
8713
fn test_keysend_msg_with_secret_err ( ) {
8707
- // Test that we error as expected if we receive a keysend payment that includes a payment secret.
8714
+ // Test that we error as expected if we receive a keysend payment that includes a payment
8715
+ // secret when we don't support MPP keysend.
8716
+ let mut reject_mpp_keysend_cfg = test_default_channel_config ( ) ;
8717
+ reject_mpp_keysend_cfg. accept_mpp_keysend = false ;
8708
8718
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
8709
8719
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
8710
- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
8720
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( reject_mpp_keysend_cfg ) ] ) ;
8711
8721
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
8712
8722
8713
8723
let payer_pubkey = nodes[ 0 ] . node . get_our_node_id ( ) ;
0 commit comments