@@ -14,11 +14,11 @@ use bitcoin::hashes::sha256::Hash as Sha256;
14
14
use bitcoin:: secp256k1:: { self , Secp256k1 , SecretKey } ;
15
15
16
16
use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
17
- use crate :: events:: { self , PaymentFailureReason } ;
17
+ use crate :: events:: { self , PaymentFailureReason , Event , PaymentPurpose } ;
18
18
use crate :: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
19
19
use crate :: ln:: channelmanager:: { ChannelDetails , EventCompletionAction , HTLCSource , IDEMPOTENCY_TIMEOUT_TICKS , PaymentId } ;
20
20
use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
21
- use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
21
+ use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router , Payee } ;
22
22
use crate :: util:: errors:: APIError ;
23
23
use crate :: util:: logger:: Logger ;
24
24
use crate :: util:: time:: Time ;
@@ -552,7 +552,7 @@ impl OutboundPayments {
552
552
}
553
553
554
554
pub ( super ) fn send_payment < R : Deref , ES : Deref , NS : Deref , IH , SP , L : Deref > (
555
- & self , payment_hash : PaymentHash , recipient_onion : RecipientOnionFields , payment_id : PaymentId ,
555
+ & self , payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > , recipient_onion : RecipientOnionFields , payment_id : PaymentId ,
556
556
retry_strategy : Retry , route_params : RouteParameters , router : & R ,
557
557
first_hops : Vec < ChannelDetails > , compute_inflight_htlcs : IH , entropy_source : & ES ,
558
558
node_signer : & NS , best_block_height : u32 , logger : & L ,
@@ -566,7 +566,7 @@ impl OutboundPayments {
566
566
IH : Fn ( ) -> InFlightHtlcs ,
567
567
SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
568
568
{
569
- self . send_payment_internal ( payment_id, payment_hash, recipient_onion, None , retry_strategy,
569
+ self . send_payment_internal ( payment_id, payment_hash, payment_preimage , recipient_onion, None , retry_strategy,
570
570
route_params, router, first_hops, & compute_inflight_htlcs, entropy_source, node_signer,
571
571
best_block_height, logger, pending_events, & send_payment_along_path)
572
572
}
@@ -605,7 +605,7 @@ impl OutboundPayments {
605
605
let preimage = payment_preimage
606
606
. unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
607
607
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
608
- self . send_payment_internal ( payment_id, payment_hash, recipient_onion, Some ( preimage) ,
608
+ self . send_payment_internal ( payment_id, payment_hash, None , recipient_onion, Some ( preimage) ,
609
609
retry_strategy, route_params, router, first_hops, inflight_htlcs, entropy_source,
610
610
node_signer, best_block_height, logger, pending_events, send_payment_along_path)
611
611
. map ( |( ) | payment_hash)
@@ -706,7 +706,7 @@ impl OutboundPayments {
706
706
/// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
707
707
/// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
708
708
fn send_payment_internal < R : Deref , NS : Deref , ES : Deref , IH , SP , L : Deref > (
709
- & self , payment_id : PaymentId , payment_hash : PaymentHash , recipient_onion : RecipientOnionFields ,
709
+ & self , payment_id : PaymentId , payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > , recipient_onion : RecipientOnionFields ,
710
710
keysend_preimage : Option < PaymentPreimage > , retry_strategy : Retry , route_params : RouteParameters ,
711
711
router : & R , first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES ,
712
712
node_signer : & NS , best_block_height : u32 , logger : & L ,
@@ -728,8 +728,9 @@ impl OutboundPayments {
728
728
}
729
729
}
730
730
731
+ let payer_pubkey = node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) ;
731
732
let route = router. find_route_with_id (
732
- & node_signer . get_node_id ( Recipient :: Node ) . unwrap ( ) , & route_params,
733
+ & payer_pubkey , & route_params,
733
734
Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , inflight_htlcs ( ) ,
734
735
payment_hash, payment_id,
735
736
) . map_err ( |_| {
@@ -747,6 +748,35 @@ impl OutboundPayments {
747
748
RetryableSendFailure :: DuplicatePayment
748
749
} ) ?;
749
750
751
+
752
+ match route_params. payment_params . payee {
753
+ Payee :: Clear { node_id, .. } if node_id == payer_pubkey => {
754
+ let payment_secret = match recipient_onion. payment_secret {
755
+ Some ( secret) => secret,
756
+ None => PaymentSecret ( [ 0 ; 32 ] )
757
+ } ;
758
+ let payment_purpose = PaymentPurpose :: InvoicePayment {
759
+ payment_preimage,
760
+ payment_secret,
761
+ } ;
762
+
763
+ let payment_preimage = payment_preimage
764
+ . unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
765
+ let mut pending_events_lock = pending_events. lock ( ) . unwrap ( ) ;
766
+ pending_events_lock. push_back ( ( Event :: PaymentSent { payment_id : Some ( payment_id) , payment_preimage,
767
+ payment_hash, fee_paid_msat : None } , None ) ) ;
768
+ pending_events_lock. push_back ( ( Event :: PaymentClaimable { receiver_node_id : Some ( payer_pubkey) , payment_hash,
769
+ onion_fields : Some ( recipient_onion) , amount_msat : route_params. final_value_msat , counterparty_skimmed_fee_msat : 0 ,
770
+ purpose : payment_purpose, via_channel_id : None , via_user_channel_id : None , claim_deadline : None } , None ) ) ;
771
+
772
+ let mut pending_outbounds_lock = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
773
+ let payment = pending_outbounds_lock. get_mut ( & payment_id) . unwrap ( ) ;
774
+ payment. mark_fulfilled ( ) ;
775
+ return Ok ( ( ) ) ;
776
+ } ,
777
+ _ => { } ,
778
+ }
779
+
750
780
let res = self . pay_route_internal ( & route, payment_hash, recipient_onion, keysend_preimage, payment_id, None ,
751
781
onion_session_privs, node_signer, best_block_height, & send_payment_along_path) ;
752
782
log_info ! ( logger, "Sending payment with id {} and hash {} returned {:?}" ,
@@ -1586,7 +1616,7 @@ mod tests {
1586
1616
} else { panic ! ( "Unexpected event" ) ; }
1587
1617
} else {
1588
1618
let err = outbound_payments. send_payment (
1589
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1619
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1590
1620
Retry :: Attempts ( 0 ) , expired_route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1591
1621
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1592
1622
if let RetryableSendFailure :: PaymentExpired = err { } else { panic ! ( "Unexpected error" ) ; }
@@ -1631,7 +1661,7 @@ mod tests {
1631
1661
if let Event :: PaymentFailed { .. } = events[ 0 ] . 0 { } else { panic ! ( "Unexpected event" ) ; }
1632
1662
} else {
1633
1663
let err = outbound_payments. send_payment (
1634
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1664
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1635
1665
Retry :: Attempts ( 0 ) , route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1636
1666
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1637
1667
if let RetryableSendFailure :: RouteNotFound = err {
@@ -1679,7 +1709,7 @@ mod tests {
1679
1709
// PaymentPathFailed event.
1680
1710
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
1681
1711
outbound_payments. send_payment (
1682
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1712
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1683
1713
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1684
1714
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1685
1715
|_| Err ( APIError :: ChannelUnavailable { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
@@ -1697,15 +1727,15 @@ mod tests {
1697
1727
1698
1728
// Ensure that a MonitorUpdateInProgress "error" will not result in a PaymentPathFailed event.
1699
1729
outbound_payments. send_payment (
1700
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1730
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1701
1731
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1702
1732
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1703
1733
|_| Err ( APIError :: MonitorUpdateInProgress ) ) . unwrap ( ) ;
1704
1734
assert_eq ! ( pending_events. lock( ) . unwrap( ) . len( ) , 0 ) ;
1705
1735
1706
1736
// Ensure that any other error will result in a PaymentPathFailed event but no blamed scid.
1707
1737
outbound_payments. send_payment (
1708
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 1 ; 32 ] ) ,
1738
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 1 ; 32 ] ) ,
1709
1739
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1710
1740
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1711
1741
|_| Err ( APIError :: APIMisuseError { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
0 commit comments