@@ -191,6 +191,9 @@ struct ClaimableHTLC {
191
191
cltv_expiry : u32 ,
192
192
/// The amount (in msats) of this MPP part
193
193
value : u64 ,
194
+ /// The amount (in msats) that the sender intended to be sent in this MPP
195
+ /// part (used for validating total MPP amount)
196
+ sender_intended_value : u64 ,
194
197
onion_payload : OnionPayload ,
195
198
timer_ticks : u8 ,
196
199
/// The sum total of all MPP parts
@@ -2159,7 +2162,7 @@ where
2159
2162
payment_hash,
2160
2163
incoming_shared_secret : shared_secret,
2161
2164
incoming_amt_msat : Some ( amt_msat) ,
2162
- outgoing_amt_msat : amt_msat ,
2165
+ outgoing_amt_msat : hop_data . amt_to_forward ,
2163
2166
outgoing_cltv_value : hop_data. outgoing_cltv_value ,
2164
2167
} )
2165
2168
}
@@ -3232,7 +3235,7 @@ where
3232
3235
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3233
3236
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3234
3237
forward_info : PendingHTLCInfo {
3235
- routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3238
+ routing, incoming_shared_secret, payment_hash, incoming_amt_msat , outgoing_amt_msat, ..
3236
3239
}
3237
3240
} ) => {
3238
3241
let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
@@ -3254,7 +3257,11 @@ where
3254
3257
incoming_packet_shared_secret : incoming_shared_secret,
3255
3258
phantom_shared_secret,
3256
3259
} ,
3257
- value : outgoing_amt_msat,
3260
+ // We differentiate the received value from the sender intended value
3261
+ // if possible so that we don't prematurely mark MPP payments complete
3262
+ // if routing nodes overpay
3263
+ value : incoming_amt_msat. unwrap_or ( outgoing_amt_msat) ,
3264
+ sender_intended_value : outgoing_amt_msat,
3258
3265
timer_ticks : 0 ,
3259
3266
total_msat : if let Some ( data) = & payment_data { data. total_msat } else { outgoing_amt_msat } ,
3260
3267
cltv_expiry,
@@ -3309,9 +3316,9 @@ where
3309
3316
continue
3310
3317
}
3311
3318
}
3312
- let mut total_value = claimable_htlc. value ;
3319
+ let mut total_value = claimable_htlc. sender_intended_value ;
3313
3320
for htlc in htlcs. iter( ) {
3314
- total_value += htlc. value ;
3321
+ total_value += htlc. sender_intended_value ;
3315
3322
match & htlc. onion_payload {
3316
3323
OnionPayload :: Invoice { .. } => {
3317
3324
if htlc. total_msat != $payment_data. total_msat {
@@ -3326,7 +3333,7 @@ where
3326
3333
}
3327
3334
if total_value >= msgs:: MAX_VALUE_MSAT {
3328
3335
fail_htlc!( claimable_htlc, payment_hash) ;
3329
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3336
+ } else if total_value - claimable_htlc. sender_intended_value >= $payment_data. total_msat {
3330
3337
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3331
3338
log_bytes!( payment_hash. 0 ) ) ;
3332
3339
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3337,7 +3344,7 @@ where
3337
3344
receiver_node_id: Some ( receiver_node_id) ,
3338
3345
payment_hash,
3339
3346
purpose: purpose( ) ,
3340
- amount_msat: total_value ,
3347
+ amount_msat: htlcs . iter ( ) . map ( |htlc| htlc . value ) . sum ( ) ,
3341
3348
via_channel_id: Some ( prev_channel_id) ,
3342
3349
via_user_channel_id: Some ( prev_user_channel_id) ,
3343
3350
} ) ;
@@ -3391,13 +3398,14 @@ where
3391
3398
}
3392
3399
match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3393
3400
hash_map:: Entry :: Vacant ( e) => {
3401
+ let amount_msat = claimable_htlc. value ;
3394
3402
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3395
3403
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3396
3404
let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3397
3405
new_events. push ( events:: Event :: PaymentClaimable {
3398
3406
receiver_node_id : Some ( receiver_node_id) ,
3399
3407
payment_hash,
3400
- amount_msat : outgoing_amt_msat ,
3408
+ amount_msat,
3401
3409
purpose,
3402
3410
via_channel_id : Some ( prev_channel_id) ,
3403
3411
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6767,6 +6775,7 @@ impl Writeable for ClaimableHTLC {
6767
6775
( 0 , self . prev_hop, required) ,
6768
6776
( 1 , self . total_msat, required) ,
6769
6777
( 2 , self . value, required) ,
6778
+ ( 3 , self . sender_intended_value, required) ,
6770
6779
( 4 , payment_data, option) ,
6771
6780
( 6 , self . cltv_expiry, required) ,
6772
6781
( 8 , keysend_preimage, option) ,
@@ -6779,6 +6788,7 @@ impl Readable for ClaimableHTLC {
6779
6788
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6780
6789
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6781
6790
let mut value = 0 ;
6791
+ let mut sender_intended_value = None ;
6782
6792
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6783
6793
let mut cltv_expiry = 0 ;
6784
6794
let mut total_msat = None ;
@@ -6787,6 +6797,7 @@ impl Readable for ClaimableHTLC {
6787
6797
( 0 , prev_hop, required) ,
6788
6798
( 1 , total_msat, option) ,
6789
6799
( 2 , value, required) ,
6800
+ ( 3 , sender_intended_value, option) ,
6790
6801
( 4 , payment_data, option) ,
6791
6802
( 6 , cltv_expiry, required) ,
6792
6803
( 8 , keysend_preimage, option)
@@ -6815,6 +6826,7 @@ impl Readable for ClaimableHTLC {
6815
6826
prev_hop : prev_hop. 0 . unwrap ( ) ,
6816
6827
timer_ticks : 0 ,
6817
6828
value,
6829
+ sender_intended_value : sender_intended_value. unwrap_or ( value) ,
6818
6830
total_msat : total_msat. unwrap ( ) ,
6819
6831
onion_payload,
6820
6832
cltv_expiry,
0 commit comments