@@ -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 (used for
195
+ /// validating total MPP amount)
196
+ intended_value : u64 ,
194
197
onion_payload : OnionPayload ,
195
198
timer_ticks : u8 ,
196
199
/// The sum total of all MPP parts
@@ -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,8 @@ where
3254
3257
incoming_packet_shared_secret : incoming_shared_secret,
3255
3258
phantom_shared_secret,
3256
3259
} ,
3257
- value : outgoing_amt_msat,
3260
+ value : incoming_amt_msat. unwrap_or ( outgoing_amt_msat) ,
3261
+ intended_value : outgoing_amt_msat,
3258
3262
timer_ticks : 0 ,
3259
3263
total_msat : if let Some ( data) = & payment_data { data. total_msat } else { outgoing_amt_msat } ,
3260
3264
cltv_expiry,
@@ -3309,9 +3313,9 @@ where
3309
3313
continue
3310
3314
}
3311
3315
}
3312
- let mut total_value = claimable_htlc. value ;
3316
+ let mut total_value = claimable_htlc. intended_value ;
3313
3317
for htlc in htlcs. iter( ) {
3314
- total_value += htlc. value ;
3318
+ total_value += htlc. intended_value ;
3315
3319
match & htlc. onion_payload {
3316
3320
OnionPayload :: Invoice { .. } => {
3317
3321
if htlc. total_msat != $payment_data. total_msat {
@@ -3326,7 +3330,7 @@ where
3326
3330
}
3327
3331
if total_value >= msgs:: MAX_VALUE_MSAT {
3328
3332
fail_htlc!( claimable_htlc, payment_hash) ;
3329
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3333
+ } else if total_value - claimable_htlc. intended_value >= $payment_data. total_msat {
3330
3334
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3331
3335
log_bytes!( payment_hash. 0 ) ) ;
3332
3336
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3337,7 +3341,7 @@ where
3337
3341
receiver_node_id: Some ( receiver_node_id) ,
3338
3342
payment_hash,
3339
3343
purpose: purpose( ) ,
3340
- amount_msat: total_value ,
3344
+ amount_msat: htlcs . iter ( ) . map ( |htlc| htlc . value ) . sum ( ) ,
3341
3345
via_channel_id: Some ( prev_channel_id) ,
3342
3346
via_user_channel_id: Some ( prev_user_channel_id) ,
3343
3347
} ) ;
@@ -3391,13 +3395,14 @@ where
3391
3395
}
3392
3396
match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3393
3397
hash_map:: Entry :: Vacant ( e) => {
3398
+ let amount_msat = claimable_htlc. value ;
3394
3399
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3395
3400
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3396
3401
let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3397
3402
new_events. push ( events:: Event :: PaymentClaimable {
3398
3403
receiver_node_id : Some ( receiver_node_id) ,
3399
3404
payment_hash,
3400
- amount_msat : outgoing_amt_msat ,
3405
+ amount_msat,
3401
3406
purpose,
3402
3407
via_channel_id : Some ( prev_channel_id) ,
3403
3408
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6767,6 +6772,7 @@ impl Writeable for ClaimableHTLC {
6767
6772
( 0 , self . prev_hop, required) ,
6768
6773
( 1 , self . total_msat, required) ,
6769
6774
( 2 , self . value, required) ,
6775
+ ( 3 , self . intended_value, required) ,
6770
6776
( 4 , payment_data, option) ,
6771
6777
( 6 , self . cltv_expiry, required) ,
6772
6778
( 8 , keysend_preimage, option) ,
@@ -6779,6 +6785,7 @@ impl Readable for ClaimableHTLC {
6779
6785
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6780
6786
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6781
6787
let mut value = 0 ;
6788
+ let mut intended_value = None ;
6782
6789
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6783
6790
let mut cltv_expiry = 0 ;
6784
6791
let mut total_msat = None ;
@@ -6787,6 +6794,7 @@ impl Readable for ClaimableHTLC {
6787
6794
( 0 , prev_hop, required) ,
6788
6795
( 1 , total_msat, option) ,
6789
6796
( 2 , value, required) ,
6797
+ ( 3 , intended_value, option) ,
6790
6798
( 4 , payment_data, option) ,
6791
6799
( 6 , cltv_expiry, required) ,
6792
6800
( 8 , keysend_preimage, option)
@@ -6815,6 +6823,7 @@ impl Readable for ClaimableHTLC {
6815
6823
prev_hop : prev_hop. 0 . unwrap ( ) ,
6816
6824
timer_ticks : 0 ,
6817
6825
value,
6826
+ intended_value : intended_value. unwrap_or ( value) ,
6818
6827
total_msat : total_msat. unwrap ( ) ,
6819
6828
onion_payload,
6820
6829
cltv_expiry,
0 commit comments