From 61ab1f85130de9b8a4346c821b34a145692e85e6 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 20 Sep 2023 14:49:58 -0400 Subject: [PATCH] Struct-ify onion util internal result type Improves readability. --- lightning/src/ln/onion_utils.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index c591010a..db61f0c9 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -444,7 +444,14 @@ pub(super) fn process_onion_failure( } = htlc_source { (path, session_priv, first_hop_htlc_msat) } else { unreachable!() }; - let mut res = None; + + // Learnings from the HTLC failure to inform future payment retries and scoring. + struct FailureLearnings { + network_update: Option, + short_channel_id: Option, + payment_failed_permanently: bool, + } + let mut res: Option = None; let mut htlc_msat = *first_hop_htlc_msat; let mut error_code_ret = None; let mut error_packet_ret = None; @@ -507,7 +514,9 @@ pub(super) fn process_onion_failure( is_permanent: true, }); let short_channel_id = Some(route_hop.short_channel_id); - res = Some((network_update, short_channel_id, is_from_final_node)); + res = Some(FailureLearnings { + network_update, short_channel_id, payment_failed_permanently: is_from_final_node + }); return } }; @@ -659,7 +668,10 @@ pub(super) fn process_onion_failure( short_channel_id = Some(route_hop.short_channel_id); } - res = Some((network_update, short_channel_id, error_code & PERM == PERM && is_from_final_node)); + res = Some(FailureLearnings { + network_update, short_channel_id, + payment_failed_permanently: error_code & PERM == PERM && is_from_final_node + }); let (description, title) = errors::get_onion_error_description(error_code); if debug_field_size > 0 && err_packet.failuremsg.len() >= 4 + debug_field_size { @@ -668,7 +680,9 @@ pub(super) fn process_onion_failure( log_info!(logger, "Onion Error[from {}: {}({:#x})] {}", route_hop.pubkey, title, error_code, description); } }).expect("Route that we sent via spontaneously grew invalid keys in the middle of it?"); - if let Some((network_update, short_channel_id, payment_failed_permanently)) = res { + if let Some(FailureLearnings { + network_update, short_channel_id, payment_failed_permanently + }) = res { DecodedOnionFailure { network_update, short_channel_id, payment_retryable: !payment_failed_permanently, #[cfg(test)] -- 2.30.2