@@ -3548,26 +3548,26 @@ where
3548
3548
}
3549
3549
3550
3550
macro_rules! check_total_value {
3551
- ( $payment_secret: expr, $payment_preimage: expr, $is_keysend : expr ) => { {
3551
+ ( $payment_secret: expr, $payment_preimage: expr) => { {
3552
3552
let mut payment_claimable_generated = false ;
3553
- let purpose = if $is_keysend {
3553
+ let is_keysend = match claimable_htlc. onion_payload {
3554
+ OnionPayload :: Spontaneous ( _) => true ,
3555
+ OnionPayload :: Invoice { .. } => false ,
3556
+ } ;
3557
+ let purpose = if is_keysend {
3554
3558
events:: PaymentPurpose :: SpontaneousPayment (
3555
- $payment_preimage. expect( "Should never call check_total_value with $is_keysend as true but no preimage" )
3559
+ $payment_preimage. expect( "Should never call check_total_value with keysend payment but no preimage" )
3556
3560
)
3557
3561
} else {
3558
3562
events:: PaymentPurpose :: InvoicePayment {
3559
3563
payment_preimage: $payment_preimage,
3560
- payment_secret: $payment_secret. expect( "Should never call check_total_value with $is_keysend as false but no payment secret" ) ,
3564
+ payment_secret: $payment_secret. expect( "Should never call check_total_value with non-keysend payment but no payment secret" ) ,
3561
3565
}
3562
3566
} ;
3563
3567
let mut claimable_payments = self . claimable_payments. lock( ) . unwrap( ) ;
3564
3568
if claimable_payments. pending_claiming_payments. contains_key( & payment_hash) {
3565
3569
fail_htlc!( claimable_htlc, payment_hash) ;
3566
3570
}
3567
- if $is_keysend && $payment_secret. is_none( ) && claimable_payments. claimable_payments. get( & payment_hash) . is_some( ) {
3568
- log_trace!( self . logger, "Failing new keysend HTLC with payment_hash {} for duplicative payment hash" , log_bytes!( payment_hash. 0 ) ) ;
3569
- fail_htlc!( claimable_htlc, payment_hash) ;
3570
- }
3571
3571
let ref mut claimable_payment = claimable_payments. claimable_payments
3572
3572
. entry( payment_hash)
3573
3573
// Note that if we insert here we MUST NOT fail_htlc!()
@@ -3577,6 +3577,11 @@ where
3577
3577
purpose: purpose. clone( ) , htlcs: Vec :: new( ) , onion_fields: None ,
3578
3578
}
3579
3579
} ) ;
3580
+ if purpose != claimable_payment. purpose {
3581
+ let log_keysend = |keysend| if keysend { "keysend" } else { "non-keysend" } ;
3582
+ log_trace!( self . logger, "Failing new {} HTLC with payment_hash {} as we already had an existing {} HTLC with the same payment hash" , log_keysend( is_keysend) , log_bytes!( payment_hash. 0 ) , log_keysend( !is_keysend) ) ;
3583
+ fail_htlc!( claimable_htlc, payment_hash) ;
3584
+ }
3580
3585
if let Some ( earlier_fields) = & mut claimable_payment. onion_fields {
3581
3586
if earlier_fields. check_merge( & mut onion_fields) . is_err( ) {
3582
3587
fail_htlc!( claimable_htlc, payment_hash) ;
@@ -3585,12 +3590,6 @@ where
3585
3590
claimable_payment. onion_fields = Some ( onion_fields) ;
3586
3591
}
3587
3592
let ref mut htlcs = & mut claimable_payment. htlcs;
3588
- if !htlcs. is_empty( ) && !$is_keysend {
3589
- if let OnionPayload :: Spontaneous ( _) = htlcs[ 0 ] . onion_payload {
3590
- 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 ) ) ;
3591
- fail_htlc!( claimable_htlc, payment_hash) ;
3592
- }
3593
- }
3594
3593
let mut total_value = claimable_htlc. sender_intended_value;
3595
3594
let mut earliest_expiry = claimable_htlc. cltv_expiry;
3596
3595
for htlc in htlcs. iter( ) {
@@ -3670,10 +3669,10 @@ where
3670
3669
fail_htlc ! ( claimable_htlc, payment_hash) ;
3671
3670
}
3672
3671
}
3673
- check_total_value ! ( Some ( payment_data. payment_secret) , payment_preimage, false ) ;
3672
+ check_total_value ! ( Some ( payment_data. payment_secret) , payment_preimage) ;
3674
3673
} ,
3675
3674
OnionPayload :: Spontaneous ( preimage) => {
3676
- check_total_value ! ( payment_data. as_ref( ) . map( |d| d. payment_secret) , Some ( preimage) , true ) ;
3675
+ check_total_value ! ( payment_data. as_ref( ) . map( |d| d. payment_secret) , Some ( preimage) ) ;
3677
3676
}
3678
3677
}
3679
3678
} ,
@@ -3691,7 +3690,7 @@ where
3691
3690
log_bytes!( payment_hash. 0 ) , payment_data. total_msat, inbound_payment. get( ) . min_value_msat. unwrap( ) ) ;
3692
3691
fail_htlc ! ( claimable_htlc, payment_hash) ;
3693
3692
} else {
3694
- let payment_claimable_generated = check_total_value ! ( Some ( payment_data. payment_secret) , inbound_payment. get( ) . payment_preimage, false ) ;
3693
+ let payment_claimable_generated = check_total_value ! ( Some ( payment_data. payment_secret) , inbound_payment. get( ) . payment_preimage) ;
3695
3694
if payment_claimable_generated {
3696
3695
inbound_payment. remove_entry ( ) ;
3697
3696
}
0 commit comments