@@ -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 {
@@ -3328,7 +3332,7 @@ where
3328
3332
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over the maximum possible msats {} (or HTLCs were inconsistent)" ,
3329
3333
log_bytes!( payment_hash. 0 ) , total_value, msgs:: MAX_VALUE_MSAT ) ;
3330
3334
fail_htlc!( claimable_htlc, payment_hash) ;
3331
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3335
+ } else if total_value - claimable_htlc. intended_value >= $payment_data. total_msat {
3332
3336
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3333
3337
log_bytes!( payment_hash. 0 ) ) ;
3334
3338
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3339,7 +3343,7 @@ where
3339
3343
receiver_node_id: Some ( receiver_node_id) ,
3340
3344
payment_hash,
3341
3345
purpose: purpose( ) ,
3342
- amount_msat: total_value ,
3346
+ amount_msat: htlcs . iter ( ) . map ( |htlc| htlc . value ) . sum ( ) ,
3343
3347
via_channel_id: Some ( prev_channel_id) ,
3344
3348
via_user_channel_id: Some ( prev_user_channel_id) ,
3345
3349
} ) ;
@@ -3393,13 +3397,14 @@ where
3393
3397
}
3394
3398
match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3395
3399
hash_map:: Entry :: Vacant ( e) => {
3400
+ let amount_msat = claimable_htlc. value ;
3396
3401
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3397
3402
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3398
3403
let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3399
3404
new_events. push ( events:: Event :: PaymentClaimable {
3400
3405
receiver_node_id : Some ( receiver_node_id) ,
3401
3406
payment_hash,
3402
- amount_msat : outgoing_amt_msat ,
3407
+ amount_msat,
3403
3408
purpose,
3404
3409
via_channel_id : Some ( prev_channel_id) ,
3405
3410
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6769,6 +6774,7 @@ impl Writeable for ClaimableHTLC {
6769
6774
( 0 , self . prev_hop, required) ,
6770
6775
( 1 , self . total_msat, required) ,
6771
6776
( 2 , self . value, required) ,
6777
+ ( 3 , self . intended_value, required) ,
6772
6778
( 4 , payment_data, option) ,
6773
6779
( 6 , self . cltv_expiry, required) ,
6774
6780
( 8 , keysend_preimage, option) ,
@@ -6781,6 +6787,7 @@ impl Readable for ClaimableHTLC {
6781
6787
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6782
6788
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6783
6789
let mut value = 0 ;
6790
+ let mut intended_value = None ;
6784
6791
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6785
6792
let mut cltv_expiry = 0 ;
6786
6793
let mut total_msat = None ;
@@ -6789,6 +6796,7 @@ impl Readable for ClaimableHTLC {
6789
6796
( 0 , prev_hop, required) ,
6790
6797
( 1 , total_msat, option) ,
6791
6798
( 2 , value, required) ,
6799
+ ( 3 , intended_value, option) ,
6792
6800
( 4 , payment_data, option) ,
6793
6801
( 6 , cltv_expiry, required) ,
6794
6802
( 8 , keysend_preimage, option)
@@ -6817,6 +6825,7 @@ impl Readable for ClaimableHTLC {
6817
6825
prev_hop : prev_hop. 0 . unwrap ( ) ,
6818
6826
timer_ticks : 0 ,
6819
6827
value,
6828
+ intended_value : intended_value. unwrap_or ( value) ,
6820
6829
total_msat : total_msat. unwrap ( ) ,
6821
6830
onion_payload,
6822
6831
cltv_expiry,
0 commit comments