@@ -193,6 +193,9 @@ struct ClaimableHTLC {
193
193
cltv_expiry : u32 ,
194
194
/// The amount (in msats) of this MPP part
195
195
value : u64 ,
196
+ /// The amount (in msats) that the sender intended to be sent (used for
197
+ /// validating total MPP amount)
198
+ intended_value : u64 ,
196
199
onion_payload : OnionPayload ,
197
200
timer_ticks : u8 ,
198
201
/// The sum total of all MPP parts
@@ -3182,7 +3185,7 @@ where
3182
3185
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3183
3186
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
3184
3187
forward_info : PendingHTLCInfo {
3185
- routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3188
+ routing, incoming_shared_secret, payment_hash, incoming_amt_msat , outgoing_amt_msat, ..
3186
3189
}
3187
3190
} ) => {
3188
3191
let ( cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
@@ -3204,7 +3207,8 @@ where
3204
3207
incoming_packet_shared_secret : incoming_shared_secret,
3205
3208
phantom_shared_secret,
3206
3209
} ,
3207
- value : outgoing_amt_msat,
3210
+ value : incoming_amt_msat. unwrap_or ( outgoing_amt_msat) ,
3211
+ intended_value : outgoing_amt_msat,
3208
3212
timer_ticks : 0 ,
3209
3213
total_msat : if let Some ( data) = & payment_data { data. total_msat } else { outgoing_amt_msat } ,
3210
3214
cltv_expiry,
@@ -3259,9 +3263,9 @@ where
3259
3263
continue
3260
3264
}
3261
3265
}
3262
- let mut total_value = claimable_htlc. value ;
3266
+ let mut total_value = claimable_htlc. intended_value ;
3263
3267
for htlc in htlcs. iter( ) {
3264
- total_value += htlc. value ;
3268
+ total_value += htlc. intended_value ;
3265
3269
match & htlc. onion_payload {
3266
3270
OnionPayload :: Invoice { .. } => {
3267
3271
if htlc. total_msat != $payment_data. total_msat {
@@ -3278,7 +3282,7 @@ where
3278
3282
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the total value {} ran over the maximum possible msats {} (or HTLCs were inconsistent)" ,
3279
3283
log_bytes!( payment_hash. 0 ) , total_value, msgs:: MAX_VALUE_MSAT ) ;
3280
3284
fail_htlc!( claimable_htlc, payment_hash) ;
3281
- } else if total_value - claimable_htlc. value >= $payment_data. total_msat {
3285
+ } else if total_value - claimable_htlc. intended_value >= $payment_data. total_msat {
3282
3286
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3283
3287
log_bytes!( payment_hash. 0 ) ) ;
3284
3288
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3289,7 +3293,7 @@ where
3289
3293
receiver_node_id: Some ( receiver_node_id) ,
3290
3294
payment_hash,
3291
3295
purpose: purpose( ) ,
3292
- amount_msat: total_value ,
3296
+ amount_msat: htlcs . iter ( ) . map ( |htlc| htlc . value ) . sum ( ) ,
3293
3297
via_channel_id: Some ( prev_channel_id) ,
3294
3298
via_user_channel_id: Some ( prev_user_channel_id) ,
3295
3299
} ) ;
@@ -3343,13 +3347,14 @@ where
3343
3347
}
3344
3348
match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3345
3349
hash_map:: Entry :: Vacant ( e) => {
3350
+ let amount_msat = claimable_htlc. value ;
3346
3351
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3347
3352
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3348
3353
let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3349
3354
new_events. push ( events:: Event :: PaymentClaimable {
3350
3355
receiver_node_id : Some ( receiver_node_id) ,
3351
3356
payment_hash,
3352
- amount_msat : outgoing_amt_msat ,
3357
+ amount_msat,
3353
3358
purpose,
3354
3359
via_channel_id : Some ( prev_channel_id) ,
3355
3360
via_user_channel_id : Some ( prev_user_channel_id) ,
@@ -6716,6 +6721,7 @@ impl Writeable for ClaimableHTLC {
6716
6721
( 0 , self . prev_hop, required) ,
6717
6722
( 1 , self . total_msat, required) ,
6718
6723
( 2 , self . value, required) ,
6724
+ ( 3 , self . intended_value, required) ,
6719
6725
( 4 , payment_data, option) ,
6720
6726
( 6 , self . cltv_expiry, required) ,
6721
6727
( 8 , keysend_preimage, option) ,
@@ -6728,6 +6734,7 @@ impl Readable for ClaimableHTLC {
6728
6734
fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6729
6735
let mut prev_hop = crate :: util:: ser:: RequiredWrapper ( None ) ;
6730
6736
let mut value = 0 ;
6737
+ let mut intended_value = None ;
6731
6738
let mut payment_data: Option < msgs:: FinalOnionHopData > = None ;
6732
6739
let mut cltv_expiry = 0 ;
6733
6740
let mut total_msat = None ;
@@ -6736,6 +6743,7 @@ impl Readable for ClaimableHTLC {
6736
6743
( 0 , prev_hop, required) ,
6737
6744
( 1 , total_msat, option) ,
6738
6745
( 2 , value, required) ,
6746
+ ( 3 , intended_value, option) ,
6739
6747
( 4 , payment_data, option) ,
6740
6748
( 6 , cltv_expiry, required) ,
6741
6749
( 8 , keysend_preimage, option)
@@ -6764,6 +6772,7 @@ impl Readable for ClaimableHTLC {
6764
6772
prev_hop : prev_hop. 0 . unwrap ( ) ,
6765
6773
timer_ticks : 0 ,
6766
6774
value,
6775
+ intended_value : intended_value. unwrap_or ( value) ,
6767
6776
total_msat : total_msat. unwrap ( ) ,
6768
6777
onion_payload,
6769
6778
cltv_expiry,
0 commit comments