@@ -839,12 +839,6 @@ impl OutboundPayments {
839839 }
840840 }
841841
842- const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
843- let mut onion_session_privs = Vec :: with_capacity ( route. paths . len ( ) ) ;
844- for _ in 0 ..route. paths . len ( ) {
845- onion_session_privs. push ( entropy_source. get_secure_random_bytes ( ) ) ;
846- }
847-
848842 macro_rules! abandon_with_entry {
849843 ( $payment: expr, $reason: expr) => {
850844 $payment. get_mut( ) . mark_abandoned( $reason) ;
@@ -860,26 +854,49 @@ impl OutboundPayments {
860854 }
861855 }
862856 }
863- let ( total_msat, recipient_onion, keysend_preimage) = {
857+ let ( total_msat, recipient_onion, keysend_preimage, onion_session_privs ) = {
864858 let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
865859 match outbounds. entry ( payment_id) {
866860 hash_map:: Entry :: Occupied ( mut payment) => {
867- let res = match payment. get ( ) {
861+ match payment. get ( ) {
868862 PendingOutboundPayment :: Retryable {
869863 total_msat, keysend_preimage, payment_secret, payment_metadata,
870864 custom_tlvs, pending_amt_msat, ..
871865 } => {
866+ const RETRY_OVERFLOW_PERCENTAGE : u64 = 10 ;
872867 let retry_amt_msat = route. get_total_amount ( ) ;
873868 if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
874869 log_error ! ( logger, "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}" , retry_amt_msat, pending_amt_msat, total_msat) ;
875870 abandon_with_entry ! ( payment, PaymentFailureReason :: UnexpectedError ) ;
876871 return
877872 }
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)
883900 } ,
884901 PendingOutboundPayment :: Legacy { .. } => {
885902 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 {
899916 log_error ! ( logger, "Payment already abandoned (with some HTLCs still pending)" ) ;
900917 return
901918 } ,
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) ) ;
911919 }
912- res
913920 } ,
914921 hash_map:: Entry :: Vacant ( _) => {
915922 log_error ! ( logger, "Payment with ID {} not found" , & payment_id) ;
0 commit comments