@@ -14,12 +14,12 @@ 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 , PaymentId } ;
20
20
use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
21
21
use crate :: offers:: invoice:: Bolt12Invoice ;
22
- use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
22
+ use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router , Payee } ;
23
23
use crate :: util:: errors:: APIError ;
24
24
use crate :: util:: logger:: Logger ;
25
25
use crate :: util:: time:: Time ;
@@ -628,7 +628,7 @@ impl OutboundPayments {
628
628
}
629
629
630
630
pub ( super ) fn send_payment < R : Deref , ES : Deref , NS : Deref , IH , SP , L : Deref > (
631
- & self , payment_hash : PaymentHash , recipient_onion : RecipientOnionFields , payment_id : PaymentId ,
631
+ & self , payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > , recipient_onion : RecipientOnionFields , payment_id : PaymentId ,
632
632
retry_strategy : Retry , route_params : RouteParameters , router : & R ,
633
633
first_hops : Vec < ChannelDetails > , compute_inflight_htlcs : IH , entropy_source : & ES ,
634
634
node_signer : & NS , best_block_height : u32 , logger : & L ,
@@ -642,7 +642,7 @@ impl OutboundPayments {
642
642
IH : Fn ( ) -> InFlightHtlcs ,
643
643
SP : Fn ( SendAlongPathArgs ) -> Result < ( ) , APIError > ,
644
644
{
645
- self . send_payment_internal ( payment_id, payment_hash, recipient_onion, None , retry_strategy,
645
+ self . send_payment_internal ( payment_id, payment_hash, payment_preimage , recipient_onion, None , retry_strategy,
646
646
route_params, router, first_hops, & compute_inflight_htlcs, entropy_source, node_signer,
647
647
best_block_height, logger, pending_events, & send_payment_along_path)
648
648
}
@@ -681,7 +681,7 @@ impl OutboundPayments {
681
681
let preimage = payment_preimage
682
682
. unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
683
683
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
684
- self . send_payment_internal ( payment_id, payment_hash, recipient_onion, Some ( preimage) ,
684
+ self . send_payment_internal ( payment_id, payment_hash, None , recipient_onion, Some ( preimage) ,
685
685
retry_strategy, route_params, router, first_hops, inflight_htlcs, entropy_source,
686
686
node_signer, best_block_height, logger, pending_events, send_payment_along_path)
687
687
. map ( |( ) | payment_hash)
@@ -827,7 +827,7 @@ impl OutboundPayments {
827
827
/// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
828
828
/// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
829
829
fn send_payment_internal < R : Deref , NS : Deref , ES : Deref , IH , SP , L : Deref > (
830
- & self , payment_id : PaymentId , payment_hash : PaymentHash , recipient_onion : RecipientOnionFields ,
830
+ & self , payment_id : PaymentId , payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > , recipient_onion : RecipientOnionFields ,
831
831
keysend_preimage : Option < PaymentPreimage > , retry_strategy : Retry , route_params : RouteParameters ,
832
832
router : & R , first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES ,
833
833
node_signer : & NS , best_block_height : u32 , logger : & L ,
@@ -849,8 +849,9 @@ impl OutboundPayments {
849
849
}
850
850
}
851
851
852
+ let payer_pubkey = node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) ;
852
853
let route = router. find_route_with_id (
853
- & node_signer . get_node_id ( Recipient :: Node ) . unwrap ( ) , & route_params,
854
+ & payer_pubkey , & route_params,
854
855
Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , inflight_htlcs ( ) ,
855
856
payment_hash, payment_id,
856
857
) . map_err ( |_| {
@@ -868,6 +869,36 @@ impl OutboundPayments {
868
869
RetryableSendFailure :: DuplicatePayment
869
870
} ) ?;
870
871
872
+ match route_params. payment_params . payee {
873
+ Payee :: Clear { node_id, .. } if node_id == payer_pubkey => {
874
+ let payment_secret = match recipient_onion. payment_secret {
875
+ Some ( secret) => secret,
876
+ None => PaymentSecret ( [ 0 ; 32 ] )
877
+ } ;
878
+ let payment_purpose = PaymentPurpose :: InvoicePayment {
879
+ payment_preimage,
880
+ payment_secret,
881
+ } ;
882
+
883
+ let payment_preimage = payment_preimage
884
+ . unwrap_or_else ( || PaymentPreimage ( entropy_source. get_secure_random_bytes ( ) ) ) ;
885
+ {
886
+ let mut pending_events_lock = pending_events. lock ( ) . unwrap ( ) ;
887
+ pending_events_lock. push_back ( ( Event :: PaymentSent { payment_id : Some ( payment_id) , payment_preimage,
888
+ payment_hash, fee_paid_msat : None } , None ) ) ;
889
+ pending_events_lock. push_back ( ( Event :: PaymentClaimable { receiver_node_id : Some ( payer_pubkey) , payment_hash,
890
+ onion_fields : Some ( recipient_onion) , amount_msat : route_params. final_value_msat , counterparty_skimmed_fee_msat : 0 ,
891
+ purpose : payment_purpose, via_channel_id : None , via_user_channel_id : None , claim_deadline : None } , None ) ) ;
892
+ }
893
+
894
+ let mut pending_outbounds_lock = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
895
+ let payment = pending_outbounds_lock. get_mut ( & payment_id) . unwrap ( ) ;
896
+ payment. mark_fulfilled ( ) ;
897
+ return Ok ( ( ) ) ;
898
+ } ,
899
+ _ => { } ,
900
+ }
901
+
871
902
let res = self . pay_route_internal ( & route, payment_hash, recipient_onion, keysend_preimage, payment_id, None ,
872
903
onion_session_privs, node_signer, best_block_height, & send_payment_along_path) ;
873
904
log_info ! ( logger, "Sending payment with id {} and hash {} returned {:?}" ,
@@ -1790,7 +1821,7 @@ mod tests {
1790
1821
} else { panic ! ( "Unexpected event" ) ; }
1791
1822
} else {
1792
1823
let err = outbound_payments. send_payment (
1793
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1824
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1794
1825
Retry :: Attempts ( 0 ) , expired_route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1795
1826
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1796
1827
if let RetryableSendFailure :: PaymentExpired = err { } else { panic ! ( "Unexpected error" ) ; }
@@ -1832,7 +1863,7 @@ mod tests {
1832
1863
if let Event :: PaymentFailed { .. } = events[ 0 ] . 0 { } else { panic ! ( "Unexpected event" ) ; }
1833
1864
} else {
1834
1865
let err = outbound_payments. send_payment (
1835
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1866
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1836
1867
Retry :: Attempts ( 0 ) , route_params, & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1837
1868
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events, |_| Ok ( ( ) ) ) . unwrap_err ( ) ;
1838
1869
if let RetryableSendFailure :: RouteNotFound = err {
@@ -1878,7 +1909,7 @@ mod tests {
1878
1909
// PaymentPathFailed event.
1879
1910
let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
1880
1911
outbound_payments. send_payment (
1881
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1912
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1882
1913
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1883
1914
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1884
1915
|_| Err ( APIError :: ChannelUnavailable { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
@@ -1896,15 +1927,15 @@ mod tests {
1896
1927
1897
1928
// Ensure that a MonitorUpdateInProgress "error" will not result in a PaymentPathFailed event.
1898
1929
outbound_payments. send_payment (
1899
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1930
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 0 ; 32 ] ) ,
1900
1931
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1901
1932
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1902
1933
|_| Err ( APIError :: MonitorUpdateInProgress ) ) . unwrap ( ) ;
1903
1934
assert_eq ! ( pending_events. lock( ) . unwrap( ) . len( ) , 0 ) ;
1904
1935
1905
1936
// Ensure that any other error will result in a PaymentPathFailed event but no blamed scid.
1906
1937
outbound_payments. send_payment (
1907
- PaymentHash ( [ 0 ; 32 ] ) , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 1 ; 32 ] ) ,
1938
+ PaymentHash ( [ 0 ; 32 ] ) , None , RecipientOnionFields :: spontaneous_empty ( ) , PaymentId ( [ 1 ; 32 ] ) ,
1908
1939
Retry :: Attempts ( 0 ) , route_params. clone ( ) , & & router, vec ! [ ] , || InFlightHtlcs :: new ( ) ,
1909
1940
& & keys_manager, & & keys_manager, 0 , & & logger, & pending_events,
1910
1941
|_| Err ( APIError :: APIMisuseError { err : "test" . to_owned ( ) } ) ) . unwrap ( ) ;
0 commit comments