@@ -14,7 +14,7 @@ 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 } ;
@@ -902,15 +902,41 @@ impl OutboundPayments {
902
902
}
903
903
}
904
904
905
- let mut route = router. find_route_with_id (
906
- & node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) , & route_params,
905
+ let payer = node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) ;
906
+ let mut route;
907
+ match router. find_route_with_id (
908
+ & payer, & route_params,
907
909
Some ( & first_hops. iter ( ) . collect :: < Vec < _ > > ( ) ) , inflight_htlcs ( ) ,
908
910
payment_hash, payment_id,
909
- ) . map_err ( |_| {
910
- log_error ! ( logger, "Failed to find route for payment with id {} and hash {}" ,
911
- payment_id, payment_hash) ;
912
- RetryableSendFailure :: RouteNotFound
913
- } ) ?;
911
+ ) {
912
+ Ok ( res) => route = res,
913
+ Err ( error) => {
914
+ if error. err == "Cannot generate a route to ourselves" {
915
+ let payment_secret = match recipient_onion. payment_secret {
916
+ Some ( secret) => secret,
917
+ None => PaymentSecret ( [ 0 ; 32 ] )
918
+ } ;
919
+ let payment_preimage = PaymentPreimage ( [ 0 ; 32 ] ) ;
920
+ let payment_purpose = PaymentPurpose :: InvoicePayment {
921
+ payment_preimage : Some ( payment_preimage) ,
922
+ payment_secret,
923
+ } ;
924
+ let mut pending_outbounds_lock = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
925
+ let payment = pending_outbounds_lock. get_mut ( & payment_id) . unwrap ( ) ;
926
+ payment. mark_fulfilled ( ) ;
927
+ let mut pending_events_lock = pending_events. lock ( ) . unwrap ( ) ;
928
+ pending_events_lock. push_back ( ( Event :: PaymentSent { payment_id : Some ( payment_id) , payment_preimage,
929
+ payment_hash, fee_paid_msat : None } , None ) ) ;
930
+ pending_events_lock. push_back ( ( Event :: PaymentClaimable { receiver_node_id : Some ( payer) , payment_hash,
931
+ onion_fields : Some ( recipient_onion) , amount_msat : route_params. final_value_msat , counterparty_skimmed_fee_msat : 0 ,
932
+ purpose : payment_purpose, via_channel_id : None , via_user_channel_id : None , claim_deadline : None } , None ) ) ;
933
+ return Ok ( ( ) ) ;
934
+ }
935
+ log_error ! ( logger, "Failed to find route for payment with id {} and hash {}" ,
936
+ payment_id, payment_hash) ;
937
+ return Err ( RetryableSendFailure :: RouteNotFound ) ;
938
+ }
939
+ }
914
940
915
941
if route. route_params . as_ref ( ) != Some ( & route_params) {
916
942
debug_assert ! ( false ,
0 commit comments