@@ -559,24 +559,24 @@ impl OutboundPayments {
559
559
560
560
pub ( super ) fn claim_htlc < L : Deref > ( & self , payment_id : PaymentId ,
561
561
payment_preimage : PaymentPreimage , session_priv : SecretKey , path : Vec < RouteHop > ,
562
- from_onchain : bool , logger : & L )
563
- -> ( Option < events:: Event > , Option < events:: Event > ) where L :: Target : Logger {
564
- let mut payment_sent_ev = None ;
565
- let mut path_success_ev = None ;
562
+ from_onchain : bool , pending_events : & Mutex < Vec < events:: Event > > , logger : & L )
563
+ where L :: Target : Logger {
566
564
let mut session_priv_bytes = [ 0 ; 32 ] ;
567
565
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
568
566
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
567
+ let mut pending_events = pending_events. lock ( ) . unwrap ( ) ;
569
568
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
570
569
if !payment. get ( ) . is_fulfilled ( ) {
571
570
let payment_hash = PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ;
572
571
let fee_paid_msat = payment. get ( ) . get_pending_fee_msat ( ) ;
573
- payment_sent_ev =
574
- Some ( events:: Event :: PaymentSent {
572
+ pending_events . push (
573
+ events:: Event :: PaymentSent {
575
574
payment_id : Some ( payment_id) ,
576
575
payment_preimage,
577
576
payment_hash,
578
577
fee_paid_msat,
579
- } ) ;
578
+ }
579
+ ) ;
580
580
payment. get_mut ( ) . mark_fulfilled ( ) ;
581
581
}
582
582
@@ -589,31 +589,31 @@ impl OutboundPayments {
589
589
// irrevocably fulfilled.
590
590
if payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
591
591
let payment_hash = Some ( PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 ) . into_inner ( ) ) ) ;
592
- path_success_ev =
593
- Some ( events:: Event :: PaymentPathSuccessful {
592
+ pending_events . push (
593
+ events:: Event :: PaymentPathSuccessful {
594
594
payment_id,
595
595
payment_hash,
596
596
path,
597
- } ) ;
597
+ }
598
+ ) ;
598
599
}
599
600
}
600
601
} else {
601
602
log_trace ! ( logger, "Received duplicative fulfill for HTLC with payment_preimage {}" , log_bytes!( payment_preimage. 0 ) ) ;
602
603
}
603
- ( payment_sent_ev, path_success_ev)
604
604
}
605
605
606
- pub ( super ) fn finalize_claims ( & self , mut sources : Vec < HTLCSource > ) -> Vec < events:: Event > {
606
+ pub ( super ) fn finalize_claims ( & self , mut sources : Vec < HTLCSource > , pending_events : & Mutex < Vec < events:: Event > > ) {
607
607
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
608
- let mut success_events = Vec :: new ( ) ;
608
+ let mut pending_events = pending_events . lock ( ) . unwrap ( ) ;
609
609
for source in sources. drain ( ..) {
610
610
if let HTLCSource :: OutboundRoute { session_priv, payment_id, path, .. } = source {
611
611
let mut session_priv_bytes = [ 0 ; 32 ] ;
612
612
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
613
613
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
614
614
assert ! ( payment. get( ) . is_fulfilled( ) ) ;
615
615
if payment. get_mut ( ) . remove ( & session_priv_bytes, None ) {
616
- success_events . push (
616
+ pending_events . push (
617
617
events:: Event :: PaymentPathSuccessful {
618
618
payment_id,
619
619
payment_hash : payment. get ( ) . payment_hash ( ) ,
@@ -624,7 +624,6 @@ impl OutboundPayments {
624
624
}
625
625
}
626
626
}
627
- success_events
628
627
}
629
628
630
629
pub ( super ) fn remove_stale_resolved_payments ( & self , pending_events : & Mutex < Vec < events:: Event > > ) {
@@ -669,8 +668,9 @@ impl OutboundPayments {
669
668
pub ( super ) fn fail_htlc < L : Deref > ( & self , source : & HTLCSource , payment_hash : & PaymentHash ,
670
669
onion_error : & HTLCFailReason , path : & Vec < RouteHop > , session_priv : & SecretKey ,
671
670
payment_id : & PaymentId , payment_params : & Option < PaymentParameters > ,
672
- probing_cookie_secret : [ u8 ; 32 ] , secp_ctx : & Secp256k1 < secp256k1:: All > , logger : & L )
673
- -> ( Option < events:: Event > , Option < events:: Event > ) where L :: Target : Logger {
671
+ probing_cookie_secret : [ u8 ; 32 ] , secp_ctx : & Secp256k1 < secp256k1:: All > ,
672
+ pending_events : & Mutex < Vec < events:: Event > > , logger : & L )
673
+ where L :: Target : Logger {
674
674
let mut session_priv_bytes = [ 0 ; 32 ] ;
675
675
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
676
676
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -679,11 +679,11 @@ impl OutboundPayments {
679
679
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( * payment_id) {
680
680
if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) {
681
681
log_trace ! ( logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
682
- return ( None , None ) ;
682
+ return
683
683
}
684
684
if payment. get ( ) . is_fulfilled ( ) {
685
685
log_trace ! ( logger, "Received failure of HTLC with payment_hash {} after payment completion" , log_bytes!( payment_hash. 0 ) ) ;
686
- return ( None , None ) ;
686
+ return
687
687
}
688
688
if payment. get ( ) . remaining_parts ( ) == 0 {
689
689
all_paths_failed = true ;
@@ -697,7 +697,7 @@ impl OutboundPayments {
697
697
}
698
698
} else {
699
699
log_trace ! ( logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
700
- return ( None , None ) ;
700
+ return
701
701
}
702
702
let mut retry = if let Some ( payment_params_data) = payment_params {
703
703
let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
@@ -753,7 +753,9 @@ impl OutboundPayments {
753
753
}
754
754
}
755
755
} ;
756
- ( Some ( path_failure) , full_failure_ev)
756
+ let mut pending_events = pending_events. lock ( ) . unwrap ( ) ;
757
+ pending_events. push ( path_failure) ;
758
+ if let Some ( ev) = full_failure_ev { pending_events. push ( ev) ; }
757
759
}
758
760
759
761
pub ( super ) fn abandon_payment ( & self , payment_id : PaymentId ) -> Option < events:: Event > {
0 commit comments