Skip to content

Commit 6351a99

Browse files
Decode onion fail outside of outbound_payments lock
It's not ideal to do all this computation while the lock is held. We also want to decode the failure *before* taking the lock, so we can store the failed scid in the relevant outbound for retry in the next commit(s).
1 parent c0a22f7 commit 6351a99

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ impl OutboundPayments {
783783
payment_params: &Option<PaymentParameters>, probing_cookie_secret: [u8; 32],
784784
secp_ctx: &Secp256k1<secp256k1::All>, pending_events: &Mutex<Vec<events::Event>>, logger: &L
785785
) where L::Target: Logger {
786+
#[cfg(test)]
787+
let (network_update, short_channel_id, payment_retryable, onion_error_code, onion_error_data) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
788+
#[cfg(not(test))]
789+
let (network_update, short_channel_id, payment_retryable, _, _) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
790+
786791
let mut session_priv_bytes = [0; 32];
787792
session_priv_bytes.copy_from_slice(&session_priv[..]);
788793
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
@@ -811,6 +816,7 @@ impl OutboundPayments {
811816
log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
812817
return
813818
}
819+
core::mem::drop(outbounds);
814820
let mut retry = if let Some(payment_params_data) = payment_params {
815821
let path_last_hop = path.last().expect("Outbound payments must have had a valid path");
816822
Some(RouteParameters {
@@ -822,11 +828,6 @@ impl OutboundPayments {
822828
log_trace!(logger, "Failing outbound payment HTLC with payment_hash {}", log_bytes!(payment_hash.0));
823829

824830
let path_failure = {
825-
#[cfg(test)]
826-
let (network_update, short_channel_id, payment_retryable, onion_error_code, onion_error_data) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
827-
#[cfg(not(test))]
828-
let (network_update, short_channel_id, payment_retryable, _, _) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
829-
830831
if payment_is_probe(payment_hash, &payment_id, probing_cookie_secret) {
831832
if !payment_retryable {
832833
events::Event::ProbeSuccessful {

0 commit comments

Comments
 (0)