@@ -119,7 +119,10 @@ pub(super) struct PendingHTLCInfo {
119
119
pub ( super ) routing : PendingHTLCRouting ,
120
120
pub ( super ) incoming_shared_secret : [ u8 ; 32 ] ,
121
121
payment_hash : PaymentHash ,
122
+ /// Amount received
122
123
pub ( super ) incoming_amt_msat : Option < u64 > , // Added in 0.0.113
124
+ /// Sender intended amount to forward or receive (actual amount received
125
+ /// may overshoot this in either case)
123
126
pub ( super ) outgoing_amt_msat : u64 ,
124
127
pub ( super ) outgoing_cltv_value : u32 ,
125
128
}
@@ -191,6 +194,9 @@ struct ClaimableHTLC {
191
194
cltv_expiry : u32 ,
192
195
/// The amount (in msats) of this MPP part
193
196
value : u64 ,
197
+ /// The amount (in msats) that the sender intended to be sent in this MPP
198
+ /// part (used for validating total MPP amount)
199
+ sender_intended_value : u64 ,
194
200
onion_payload : OnionPayload ,
195
201
timer_ticks : u8 ,
196
202
/// The total value received for a payment (sum of all MPP parts if the payment is a MPP).
@@ -2162,7 +2168,7 @@ where
2162
2168
payment_hash,
2163
2169
incoming_shared_secret : shared_secret,
2164
2170
incoming_amt_msat : Some ( amt_msat) ,
2165
- outgoing_amt_msat : amt_msat ,
2171
+ outgoing_amt_msat : hop_data . amt_to_forward ,
2166
2172
outgoing_cltv_value : hop_data. outgoing_cltv_value ,
2167
2173
} )
2168
2174
}
@@ -3235,7 +3241,7 @@ where
3235
3241
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3236
3242
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3237
3243
forward_info : PendingHTLCInfo {
3238
- routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3244
+ routing, incoming_shared_secret, payment_hash, incoming_amt_msat , outgoing_amt_msat, ..
3239
3245
}
3240
3246
} ) => {
3241
3247
let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
@@ -3257,7 +3263,11 @@ where
3257
3263
incoming_packet_shared_secret : incoming_shared_secret,
3258
3264
phantom_shared_secret,
3259
3265
} ,
3260
- value : outgoing_amt_msat,
3266
+ // We differentiate the received value from the sender intended value
3267
+ // if possible so that we don't prematurely mark MPP payments complete
3268
+ // if routing nodes overpay
3269
+ value : incoming_amt_msat. unwrap_or ( outgoing_amt_msat) ,
3270
+ sender_intended_value : outgoing_amt_msat,
3261
3271
timer_ticks : 0 ,
3262
3272
total_value_received : None ,
3263
3273
total_msat : if let Some ( data) = & payment_data { data. total_msat } else { outgoing_amt_msat } ,
@@ -3313,9 +3323,9 @@ where
3313
3323
continue
3314
3324
}
3315
3325
}
3316
- let mut total_value = claimable_htlc. value ;
3326
+ let mut total_value = claimable_htlc. sender_intended_value ;
3317
3327
for htlc in htlcs. iter( ) {
3318
- total_value += htlc. value ;
3328
+ total_value += htlc. sender_intended_value ;
3319
3329
match & htlc. onion_payload {
3320
3330
OnionPayload :: Invoice { .. } => {
3321
3331
if htlc. total_msat != $payment_data. total_msat {
@@ -3330,7 +3340,7 @@ where
3330
3340
}
3331
3341
if total_value >= msgs:: MAX_VALUE_MSAT {
3332
3342
fail_htlc!( claimable_htlc, payment_hash) ;
3333
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3343
+ } else if total_value - claimable_htlc. sender_intended_value >= $payment_data. total_msat {
3334
3344
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3335
3345
log_bytes!( payment_hash. 0 ) ) ;
3336
3346
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3405,7 +3415,7 @@ where
3405
3415
new_events. push ( events:: Event :: PaymentClaimable {
3406
3416
receiver_node_id : Some ( receiver_node_id) ,
3407
3417
payment_hash,
3408
- amount_msat : outgoing_amt_msat ,
3418
+ amount_msat,
3409
3419
purpose,
3410
3420
via_channel_id : Some ( prev_channel_id) ,
3411
3421
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6784,6 +6794,7 @@ impl Writeable for ClaimableHTLC {
6784
6794
( 0 , self . prev_hop, required) ,
6785
6795
( 1 , self . total_msat, required) ,
6786
6796
( 2 , self . value, required) ,
6797
+ ( 3 , self . sender_intended_value, required) ,
6787
6798
( 4 , payment_data, option) ,
6788
6799
( 5 , self . total_value_received, option) ,
6789
6800
( 6 , self . cltv_expiry, required) ,
@@ -6797,6 +6808,7 @@ impl Readable for ClaimableHTLC {
6797
6808
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6798
6809
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6799
6810
let mut value = 0 ;
6811
+ let mut sender_intended_value = None ;
6800
6812
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6801
6813
let mut cltv_expiry = 0 ;
6802
6814
let mut total_value_received = None ;
@@ -6806,6 +6818,7 @@ impl Readable for ClaimableHTLC {
6806
6818
( 0 , prev_hop, required) ,
6807
6819
( 1 , total_msat, option) ,
6808
6820
( 2 , value, required) ,
6821
+ ( 3 , sender_intended_value, option) ,
6809
6822
( 4 , payment_data, option) ,
6810
6823
( 5 , total_value_received, option) ,
6811
6824
( 6 , cltv_expiry, required) ,
@@ -6835,6 +6848,7 @@ impl Readable for ClaimableHTLC {
6835
6848
prev_hop : prev_hop. 0 . unwrap ( ) ,
6836
6849
timer_ticks : 0 ,
6837
6850
value,
6851
+ sender_intended_value : sender_intended_value. unwrap_or ( value) ,
6838
6852
total_value_received,
6839
6853
total_msat : total_msat. unwrap ( ) ,
6840
6854
onion_payload,
0 commit comments