@@ -3336,9 +3336,13 @@ where
3336
3336
}
3337
3337
3338
3338
macro_rules! check_total_value {
3339
- ( $payment_data: expr, $payment_preimage: expr) => { {
3339
+ ( $payment_data: expr, $payment_preimage: expr, $is_keysend : expr ) => { {
3340
3340
let mut payment_claimable_generated = false ;
3341
- let purpose = || {
3341
+ let purpose = if $is_keysend {
3342
+ events:: PaymentPurpose :: SpontaneousPayment (
3343
+ $payment_preimage. expect( "Should never call check_total_value with $is_keysend as true but no preimage" )
3344
+ )
3345
+ } else {
3342
3346
events:: PaymentPurpose :: InvoicePayment {
3343
3347
payment_preimage: $payment_preimage,
3344
3348
payment_secret: $payment_data. payment_secret,
@@ -3350,8 +3354,8 @@ where
3350
3354
continue
3351
3355
}
3352
3356
let ( _, ref mut htlcs) = claimable_payments. claimable_htlcs. entry( payment_hash)
3353
- . or_insert_with( || ( purpose( ) , Vec :: new( ) ) ) ;
3354
- if htlcs. len( ) == 1 {
3357
+ . or_insert_with( || ( purpose. clone ( ) , Vec :: new( ) ) ) ;
3358
+ if htlcs. len( ) == 1 && !$is_keysend {
3355
3359
if let OnionPayload :: Spontaneous ( _) = htlcs[ 0 ] . onion_payload {
3356
3360
log_trace!( self . logger, "Failing new HTLC with payment_hash {} as we already had an existing keysend HTLC with the same payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3357
3361
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3361,17 +3365,12 @@ where
3361
3365
let mut total_value = claimable_htlc. sender_intended_value;
3362
3366
for htlc in htlcs. iter( ) {
3363
3367
total_value += htlc. sender_intended_value;
3364
- match & htlc. onion_payload {
3365
- OnionPayload :: Invoice { .. } => {
3366
- if htlc. total_msat != $payment_data. total_msat {
3367
- log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3368
- log_bytes!( payment_hash. 0 ) , $payment_data. total_msat, htlc. total_msat) ;
3369
- total_value = msgs:: MAX_VALUE_MSAT ;
3370
- }
3371
- if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
3372
- } ,
3373
- _ => unreachable!( ) ,
3368
+ if htlc. total_msat != $payment_data. total_msat {
3369
+ log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3370
+ log_bytes!( payment_hash. 0 ) , $payment_data. total_msat, htlc. total_msat) ;
3371
+ total_value = msgs:: MAX_VALUE_MSAT ;
3374
3372
}
3373
+ if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
3375
3374
}
3376
3375
// The condition determining whether an MPP is complete must
3377
3376
// match exactly the condition used in `timer_tick_occurred`
@@ -3389,7 +3388,7 @@ where
3389
3388
new_events. push( events:: Event :: PaymentClaimable {
3390
3389
receiver_node_id: Some ( receiver_node_id) ,
3391
3390
payment_hash,
3392
- purpose: purpose ( ) ,
3391
+ purpose,
3393
3392
amount_msat,
3394
3393
via_channel_id: Some ( prev_channel_id) ,
3395
3394
via_user_channel_id: Some ( prev_user_channel_id) ,
@@ -3434,33 +3433,37 @@ where
3434
3433
continue ;
3435
3434
}
3436
3435
}
3437
- check_total_value ! ( payment_data, payment_preimage) ;
3436
+ check_total_value ! ( payment_data, payment_preimage, false ) ;
3438
3437
} ,
3439
3438
OnionPayload :: Spontaneous ( preimage) => {
3440
- let mut claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
3441
- if claimable_payments. pending_claiming_payments . contains_key ( & payment_hash) {
3442
- fail_htlc ! ( claimable_htlc, payment_hash) ;
3443
- continue
3444
- }
3445
- match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3446
- hash_map:: Entry :: Vacant ( e) => {
3447
- let amount_msat = claimable_htlc. value ;
3448
- claimable_htlc. total_value_received = Some ( amount_msat) ;
3449
- let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3450
- e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3451
- let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3452
- new_events. push ( events:: Event :: PaymentClaimable {
3453
- receiver_node_id : Some ( receiver_node_id) ,
3454
- payment_hash,
3455
- amount_msat,
3456
- purpose,
3457
- via_channel_id : Some ( prev_channel_id) ,
3458
- via_user_channel_id : Some ( prev_user_channel_id) ,
3459
- } ) ;
3460
- } ,
3461
- hash_map:: Entry :: Occupied ( _) => {
3462
- log_trace ! ( self . logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3439
+ if let Some ( payment_data) = payment_data {
3440
+ check_total_value ! ( payment_data, Some ( preimage) , true ) ;
3441
+ } else {
3442
+ let mut claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
3443
+ if claimable_payments. pending_claiming_payments . contains_key ( & payment_hash) {
3463
3444
fail_htlc ! ( claimable_htlc, payment_hash) ;
3445
+ continue
3446
+ }
3447
+ match claimable_payments. claimable_htlcs . entry ( payment_hash) {
3448
+ hash_map:: Entry :: Vacant ( e) => {
3449
+ let amount_msat = claimable_htlc. value ;
3450
+ claimable_htlc. total_value_received = Some ( amount_msat) ;
3451
+ let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3452
+ e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3453
+ let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3454
+ new_events. push ( events:: Event :: PaymentClaimable {
3455
+ receiver_node_id : Some ( receiver_node_id) ,
3456
+ payment_hash,
3457
+ amount_msat,
3458
+ purpose,
3459
+ via_channel_id : Some ( prev_channel_id) ,
3460
+ via_user_channel_id : Some ( prev_user_channel_id) ,
3461
+ } ) ;
3462
+ } ,
3463
+ hash_map:: Entry :: Occupied ( _) => {
3464
+ log_trace ! ( self . logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3465
+ fail_htlc ! ( claimable_htlc, payment_hash) ;
3466
+ }
3464
3467
}
3465
3468
}
3466
3469
}
@@ -3481,7 +3484,7 @@ where
3481
3484
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3482
3485
fail_htlc ! ( claimable_htlc, payment_hash) ;
3483
3486
} else {
3484
- let payment_claimable_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage) ;
3487
+ let payment_claimable_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage, false ) ;
3485
3488
if payment_claimable_generated {
3486
3489
inbound_payment. remove_entry ( ) ;
3487
3490
}
@@ -4037,17 +4040,6 @@ where
4037
4040
}
4038
4041
expected_amt_msat = htlc. total_value_received ;
4039
4042
4040
- if let OnionPayload :: Spontaneous ( _) = & htlc. onion_payload {
4041
- // We don't currently support MPP for spontaneous payments, so just check
4042
- // that there's one payment here and move on.
4043
- if sources. len ( ) != 1 {
4044
- log_error ! ( self . logger, "Somehow ended up with an MPP spontaneous payment - this should not be reachable!" ) ;
4045
- debug_assert ! ( false ) ;
4046
- valid_mpp = false ;
4047
- break ;
4048
- }
4049
- }
4050
-
4051
4043
claimable_amt_msat += htlc. value ;
4052
4044
}
4053
4045
mem:: drop ( per_peer_state) ;
0 commit comments