@@ -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 total value received for a payment (sum of all MPP parts if the payment is a MPP).
@@ -2162,7 +2165,7 @@ where
2162
2165
payment_hash,
2163
2166
incoming_shared_secret : shared_secret,
2164
2167
incoming_amt_msat : Some ( amt_msat) ,
2165
- outgoing_amt_msat : amt_msat ,
2168
+ outgoing_amt_msat : hop_data . amt_to_forward ,
2166
2169
outgoing_cltv_value : hop_data. outgoing_cltv_value ,
2167
2170
} )
2168
2171
}
@@ -3235,7 +3238,7 @@ where
3235
3238
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3236
3239
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3237
3240
forward_info : PendingHTLCInfo {
3238
- routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3241
+ routing, incoming_shared_secret, payment_hash, incoming_amt_msat , outgoing_amt_msat, ..
3239
3242
}
3240
3243
} ) => {
3241
3244
let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
@@ -3257,7 +3260,11 @@ where
3257
3260
incoming_packet_shared_secret : incoming_shared_secret,
3258
3261
phantom_shared_secret,
3259
3262
} ,
3260
- value : outgoing_amt_msat,
3263
+ // We differentiate the received value from the sender intended value
3264
+ // if possible so that we don't prematurely mark MPP payments complete
3265
+ // if routing nodes overpay
3266
+ value : incoming_amt_msat. unwrap_or ( outgoing_amt_msat) ,
3267
+ sender_intended_value : outgoing_amt_msat,
3261
3268
timer_ticks : 0 ,
3262
3269
total_value_received : None ,
3263
3270
total_msat : if let Some ( data) = & payment_data { data. total_msat } else { outgoing_amt_msat } ,
@@ -3313,9 +3320,9 @@ where
3313
3320
continue
3314
3321
}
3315
3322
}
3316
- let mut total_value = claimable_htlc. value ;
3323
+ let mut total_value = claimable_htlc. sender_intended_value ;
3317
3324
for htlc in htlcs. iter( ) {
3318
- total_value += htlc. value ;
3325
+ total_value += htlc. sender_intended_value ;
3319
3326
match & htlc. onion_payload {
3320
3327
OnionPayload :: Invoice { .. } => {
3321
3328
if htlc. total_msat != $payment_data. total_msat {
@@ -3330,7 +3337,7 @@ where
3330
3337
}
3331
3338
if total_value >= msgs:: MAX_VALUE_MSAT {
3332
3339
fail_htlc!( claimable_htlc, payment_hash) ;
3333
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3340
+ } else if total_value - claimable_htlc. sender_intended_value >= $payment_data. total_msat {
3334
3341
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3335
3342
log_bytes!( payment_hash. 0 ) ) ;
3336
3343
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3405,7 +3412,7 @@ where
3405
3412
new_events. push ( events:: Event :: PaymentClaimable {
3406
3413
receiver_node_id : Some ( receiver_node_id) ,
3407
3414
payment_hash,
3408
- amount_msat : outgoing_amt_msat ,
3415
+ amount_msat,
3409
3416
purpose,
3410
3417
via_channel_id : Some ( prev_channel_id) ,
3411
3418
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6784,6 +6791,7 @@ impl Writeable for ClaimableHTLC {
6784
6791
( 0 , self . prev_hop, required) ,
6785
6792
( 1 , self . total_msat, required) ,
6786
6793
( 2 , self . value, required) ,
6794
+ ( 3 , self . sender_intended_value, required) ,
6787
6795
( 4 , payment_data, option) ,
6788
6796
( 5 , self . total_value_received, option) ,
6789
6797
( 6 , self . cltv_expiry, required) ,
@@ -6797,6 +6805,7 @@ impl Readable for ClaimableHTLC {
6797
6805
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6798
6806
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6799
6807
let mut value = 0 ;
6808
+ let mut sender_intended_value = None ;
6800
6809
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6801
6810
let mut cltv_expiry = 0 ;
6802
6811
let mut total_value_received = None ;
@@ -6806,6 +6815,7 @@ impl Readable for ClaimableHTLC {
6806
6815
( 0 , prev_hop, required) ,
6807
6816
( 1 , total_msat, option) ,
6808
6817
( 2 , value, required) ,
6818
+ ( 3 , sender_intended_value, option) ,
6809
6819
( 4 , payment_data, option) ,
6810
6820
( 5 , total_value_received, option) ,
6811
6821
( 6 , cltv_expiry, required) ,
@@ -6835,6 +6845,7 @@ impl Readable for ClaimableHTLC {
6835
6845
prev_hop : prev_hop. 0 . unwrap ( ) ,
6836
6846
timer_ticks : 0 ,
6837
6847
value,
6848
+ sender_intended_value : sender_intended_value. unwrap_or ( value) ,
6838
6849
total_value_received,
6839
6850
total_msat : total_msat. unwrap ( ) ,
6840
6851
onion_payload,
0 commit comments