@@ -839,11 +839,6 @@ impl OutboundPayments {
839
839
}
840
840
}
841
841
842
- let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
843
- for _ in 0 ..route. paths . len ( ) {
844
- onion_session_privs. push ( entropy_source. get_secure_random_bytes ( ) ) ;
845
- }
846
-
847
842
macro_rules! abandon_with_entry {
848
843
( $payment: expr, $reason: expr) => {
849
844
$payment. get_mut( ) . mark_abandoned( $reason) ;
@@ -859,11 +854,11 @@ impl OutboundPayments {
859
854
}
860
855
}
861
856
}
862
- let ( total_msat, recipient_onion, keysend_preimage) = {
857
+ let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs ) = {
863
858
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
864
859
match outbounds. entry ( payment_id) {
865
860
hash_map:: Entry :: Occupied ( mut payment) => {
866
- let res = match payment. get ( ) {
861
+ match payment. get ( ) {
867
862
PendingOutboundPayment :: Retryable {
868
863
total_msat, keysend_preimage, payment_secret, payment_metadata,
869
864
custom_tlvs, pending_amt_msat, ..
@@ -875,11 +870,33 @@ impl OutboundPayments {
875
870
abandon_with_entry ! ( payment, PaymentFailureReason :: UnexpectedError ) ;
876
871
return
877
872
}
878
- ( * total_msat, RecipientOnionFields {
879
- payment_secret : * payment_secret,
880
- payment_metadata : payment_metadata. clone ( ) ,
881
- custom_tlvs : custom_tlvs. clone ( ) ,
882
- } , * keysend_preimage)
873
+
874
+ if !payment. get ( ) . is_retryable_now ( ) {
875
+ log_error ! ( logger, "Retries exhausted for payment id {}" , & payment_id) ;
876
+ abandon_with_entry ! ( payment, PaymentFailureReason :: RetriesExhausted ) ;
877
+ return
878
+ }
879
+
880
+ let total_msat = * total_msat;
881
+ let recipient_onion = RecipientOnionFields {
882
+ payment_secret : * payment_secret,
883
+ payment_metadata : payment_metadata. clone ( ) ,
884
+ custom_tlvs : custom_tlvs. clone ( ) ,
885
+ } ;
886
+ let keysend_preimage = * keysend_preimage;
887
+
888
+ let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
889
+ for _ in 0 ..route. paths . len ( ) {
890
+ onion_session_privs. push ( entropy_source. get_secure_random_bytes ( ) ) ;
891
+ }
892
+
893
+ for ( path, session_priv_bytes) in route. paths . iter ( ) . zip ( onion_session_privs. iter ( ) ) {
894
+ assert ! ( payment. get_mut( ) . insert( * session_priv_bytes, path) ) ;
895
+ }
896
+
897
+ payment. get_mut ( ) . increment_attempts ( ) ;
898
+
899
+ ( total_msat, recipient_onion, keysend_preimage, onion_session_privs)
883
900
} ,
884
901
PendingOutboundPayment :: Legacy { .. } => {
885
902
log_error ! ( logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102" ) ;
@@ -899,17 +916,7 @@ impl OutboundPayments {
899
916
log_error ! ( logger, "Payment already abandoned (with some HTLCs still pending)" ) ;
900
917
return
901
918
} ,
902
- } ;
903
- if !payment. get ( ) . is_retryable_now ( ) {
904
- log_error ! ( logger, "Retries exhausted for payment id {}" , & payment_id) ;
905
- abandon_with_entry ! ( payment, PaymentFailureReason :: RetriesExhausted ) ;
906
- return
907
- }
908
- payment. get_mut ( ) . increment_attempts ( ) ;
909
- for ( path, session_priv_bytes) in route. paths . iter ( ) . zip ( onion_session_privs. iter ( ) ) {
910
- assert ! ( payment. get_mut( ) . insert( * session_priv_bytes, path) ) ;
911
919
}
912
- res
913
920
} ,
914
921
hash_map:: Entry :: Vacant ( _) => {
915
922
log_error ! ( logger, "Payment with ID {} not found" , & payment_id) ;
0 commit comments