@@ -3493,7 +3493,7 @@ where
3493
3493
panic ! ( "short_channel_id == 0 should imply any pending_forward entries are of type Receive" ) ;
3494
3494
}
3495
3495
} ;
3496
- let mut claimable_htlc = ClaimableHTLC {
3496
+ let claimable_htlc = ClaimableHTLC {
3497
3497
prev_hop : HTLCPreviousHopData {
3498
3498
short_channel_id : prev_short_channel_id,
3499
3499
outpoint : prev_funding_outpoint,
@@ -3543,7 +3543,7 @@ where
3543
3543
}
3544
3544
3545
3545
macro_rules! check_total_value {
3546
- ( $payment_data : expr, $payment_preimage: expr, $is_keysend: expr) => { {
3546
+ ( $payment_secret : expr, $payment_preimage: expr , $total_msat : expr, $is_keysend: expr) => { {
3547
3547
let mut payment_claimable_generated = false ;
3548
3548
let purpose = if $is_keysend {
3549
3549
events:: PaymentPurpose :: SpontaneousPayment (
@@ -3552,13 +3552,17 @@ where
3552
3552
} else {
3553
3553
events:: PaymentPurpose :: InvoicePayment {
3554
3554
payment_preimage: $payment_preimage,
3555
- payment_secret: $payment_data . payment_secret,
3555
+ payment_secret: $payment_secret. unwrap ( ) ,
3556
3556
}
3557
3557
} ;
3558
3558
let mut claimable_payments = self . claimable_payments. lock( ) . unwrap( ) ;
3559
3559
if claimable_payments. pending_claiming_payments. contains_key( & payment_hash) {
3560
3560
fail_htlc!( claimable_htlc, payment_hash) ;
3561
3561
}
3562
+ if $is_keysend && $payment_secret. is_none( ) && claimable_payments. claimable_payments. get( & payment_hash) . is_some( ) {
3563
+ log_trace!( self . logger, "Failing new keysend HTLC with payment_hash {} for duplicative payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3564
+ fail_htlc!( claimable_htlc, payment_hash) ;
3565
+ }
3562
3566
let ref mut claimable_payment = claimable_payments. claimable_payments
3563
3567
. entry( payment_hash)
3564
3568
// Note that if we insert here we MUST NOT fail_htlc!()
@@ -3587,9 +3591,9 @@ where
3587
3591
for htlc in htlcs. iter( ) {
3588
3592
total_value += htlc. sender_intended_value;
3589
3593
earliest_expiry = cmp:: min( earliest_expiry, htlc. cltv_expiry) ;
3590
- if htlc. total_msat != $payment_data . total_msat {
3594
+ if htlc. total_msat != $total_msat {
3591
3595
log_trace!( self . logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})" ,
3592
- log_bytes!( payment_hash. 0 ) , $payment_data . total_msat, htlc. total_msat) ;
3596
+ log_bytes!( payment_hash. 0 ) , $total_msat, htlc. total_msat) ;
3593
3597
total_value = msgs:: MAX_VALUE_MSAT ;
3594
3598
}
3595
3599
if total_value >= msgs:: MAX_VALUE_MSAT { break ; }
@@ -3598,11 +3602,11 @@ where
3598
3602
// match exactly the condition used in `timer_tick_occurred`
3599
3603
if total_value >= msgs:: MAX_VALUE_MSAT {
3600
3604
fail_htlc!( claimable_htlc, payment_hash) ;
3601
- } else if total_value - claimable_htlc. sender_intended_value >= $payment_data . total_msat {
3605
+ } else if total_value - claimable_htlc. sender_intended_value >= $total_msat {
3602
3606
log_trace!( self . logger, "Failing HTLC with payment_hash {} as payment is already claimable" ,
3603
3607
log_bytes!( payment_hash. 0 ) ) ;
3604
3608
fail_htlc!( claimable_htlc, payment_hash) ;
3605
- } else if total_value >= $payment_data . total_msat {
3609
+ } else if total_value >= $total_msat {
3606
3610
#[ allow( unused_assignments) ] {
3607
3611
committed_to_claimable = true ;
3608
3612
}
@@ -3661,45 +3665,10 @@ where
3661
3665
fail_htlc ! ( claimable_htlc, payment_hash) ;
3662
3666
}
3663
3667
}
3664
- check_total_value ! ( payment_data, payment_preimage, false ) ;
3668
+ check_total_value ! ( Some ( payment_data. payment_secret ) , payment_preimage, payment_data . total_msat , false ) ;
3665
3669
} ,
3666
3670
OnionPayload :: Spontaneous ( preimage) => {
3667
- if let Some ( payment_data) = payment_data {
3668
- check_total_value ! ( payment_data, Some ( preimage) , true ) ;
3669
- } else {
3670
- let mut claimable_payments = self . claimable_payments . lock ( ) . unwrap ( ) ;
3671
- if claimable_payments. pending_claiming_payments . contains_key ( & payment_hash) {
3672
- fail_htlc ! ( claimable_htlc, payment_hash) ;
3673
- }
3674
- match claimable_payments. claimable_payments . entry ( payment_hash) {
3675
- hash_map:: Entry :: Vacant ( e) => {
3676
- let amount_msat = claimable_htlc. value ;
3677
- claimable_htlc. total_value_received = Some ( amount_msat) ;
3678
- let claim_deadline = Some ( claimable_htlc. cltv_expiry - HTLC_FAIL_BACK_BUFFER ) ;
3679
- let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3680
- e. insert ( ClaimablePayment {
3681
- purpose : purpose. clone ( ) ,
3682
- onion_fields : Some ( onion_fields. clone ( ) ) ,
3683
- htlcs : vec ! [ claimable_htlc] ,
3684
- } ) ;
3685
- let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3686
- new_events. push_back ( ( events:: Event :: PaymentClaimable {
3687
- receiver_node_id : Some ( receiver_node_id) ,
3688
- payment_hash,
3689
- amount_msat,
3690
- purpose,
3691
- via_channel_id : Some ( prev_channel_id) ,
3692
- via_user_channel_id : Some ( prev_user_channel_id) ,
3693
- claim_deadline,
3694
- onion_fields : Some ( onion_fields) ,
3695
- } , None ) ) ;
3696
- } ,
3697
- hash_map:: Entry :: Occupied ( _) => {
3698
- log_trace ! ( self . logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3699
- fail_htlc ! ( claimable_htlc, payment_hash) ;
3700
- }
3701
- }
3702
- }
3671
+ check_total_value ! ( payment_data. as_ref( ) . map( |d| d. payment_secret) , Some ( preimage) , payment_data. as_ref( ) . map_or( claimable_htlc. value, |d| d. total_msat) , true ) ;
3703
3672
}
3704
3673
}
3705
3674
} ,
@@ -3717,7 +3686,7 @@ where
3717
3686
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3718
3687
fail_htlc ! ( claimable_htlc, payment_hash) ;
3719
3688
} else {
3720
- let payment_claimable_generated = check_total_value ! ( payment_data, inbound_payment. get( ) . payment_preimage, false ) ;
3689
+ let payment_claimable_generated = check_total_value ! ( Some ( payment_data. payment_secret ) , inbound_payment. get( ) . payment_preimage, payment_data . total_msat , false ) ;
3721
3690
if payment_claimable_generated {
3722
3691
inbound_payment. remove_entry ( ) ;
3723
3692
}
0 commit comments