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