Skip to content

Commit f0d560d

Browse files
Struct-ify onion util internal result type
Improves readability.
1 parent ed444c4 commit f0d560d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,14 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
444444
} = htlc_source {
445445
(path, session_priv, first_hop_htlc_msat)
446446
} else { unreachable!() };
447-
let mut res = None;
447+
448+
// Learnings from the HTLC failure to inform future payment retries and scoring.
449+
struct FailureLearnings {
450+
network_update: Option<NetworkUpdate>,
451+
short_channel_id: Option<u64>,
452+
recipient_rejected: bool,
453+
}
454+
let mut res: Option<FailureLearnings> = None;
448455
let mut htlc_msat = *first_hop_htlc_msat;
449456
let mut error_code_ret = None;
450457
let mut error_packet_ret = None;
@@ -507,7 +514,9 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
507514
is_permanent: true,
508515
});
509516
let short_channel_id = Some(route_hop.short_channel_id);
510-
res = Some((network_update, short_channel_id, is_from_final_node));
517+
res = Some(FailureLearnings {
518+
network_update, short_channel_id, recipient_rejected: is_from_final_node
519+
});
511520
return
512521
}
513522
};
@@ -659,7 +668,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
659668
short_channel_id = Some(route_hop.short_channel_id);
660669
}
661670

662-
res = Some((network_update, short_channel_id, error_code & PERM == PERM && is_from_final_node));
671+
res = Some(FailureLearnings {
672+
network_update, short_channel_id,
673+
recipient_rejected: error_code & PERM == PERM && is_from_final_node
674+
});
663675

664676
let (description, title) = errors::get_onion_error_description(error_code);
665677
if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size {
@@ -668,7 +680,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
668680
log_info!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description);
669681
}
670682
}).expect("Route that we sent via spontaneously grew invalid keys in the middle of it?");
671-
if let Some((network_update, short_channel_id, recipient_rejected)) = res {
683+
if let Some(FailureLearnings { network_update, short_channel_id, recipient_rejected }) = res {
672684
DecodedOnionFailure {
673685
network_update, short_channel_id, payment_retryable: !recipient_rejected,
674686
#[cfg(test)]

0 commit comments

Comments
 (0)