Skip to content

Commit 99d0eed

Browse files
committed
ln: handle DecodedOnionFailure for local trampoline failures
While proper error handling will be added in a followup, we add the bare minimum required here for testing. Note that we intentionally keep the behavior of not setting `payment_failed_permanently` for local failures because we can possibly retry it because we're the sender as a trampoline forwarder. For example, a local ChannelClosed error is considered to be permanent, but we can still retry along another channel.
1 parent 6f538dc commit 99d0eed

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

lightning/src/ln/onion_utils.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,23 @@ impl HTLCFailReason {
21432143
pub(super) fn decode_onion_failure<T: secp256k1::Signing, L: Logger>(
21442144
&self, secp_ctx: &Secp256k1<T>, logger: &L, htlc_source: &HTLCSource,
21452145
) -> DecodedOnionFailure {
2146+
macro_rules! decoded_onion_failure {
2147+
($short_channel_id:expr, $failure_reason:expr, $data:expr) => {
2148+
DecodedOnionFailure {
2149+
network_update: None,
2150+
payment_failed_permanently: false,
2151+
short_channel_id: $short_channel_id,
2152+
failed_within_blinded_path: false,
2153+
hold_times: Vec::new(),
2154+
#[cfg(any(test, feature = "_test_utils"))]
2155+
onion_error_code: Some($failure_reason),
2156+
#[cfg(any(test, feature = "_test_utils"))]
2157+
onion_error_data: Some($data.clone()),
2158+
#[cfg(test)]
2159+
attribution_failed_channel: None,
2160+
}
2161+
};
2162+
}
21462163
match self.0 {
21472164
HTLCFailReasonRepr::LightningError { ref err, .. } => {
21482165
process_onion_failure(secp_ctx, logger, &htlc_source, err.clone())
@@ -2154,22 +2171,19 @@ impl HTLCFailReason {
21542171
// failures here, but that would be insufficient as find_route
21552172
// generally ignores its view of our own channels as we provide them via
21562173
// ChannelDetails.
2157-
if let &HTLCSource::OutboundRoute { ref path, .. } = htlc_source {
2158-
DecodedOnionFailure {
2159-
network_update: None,
2160-
payment_failed_permanently: false,
2161-
short_channel_id: Some(path.hops[0].short_channel_id),
2162-
failed_within_blinded_path: false,
2163-
hold_times: Vec::new(),
2164-
#[cfg(any(test, feature = "_test_utils"))]
2165-
onion_error_code: Some(*failure_reason),
2166-
#[cfg(any(test, feature = "_test_utils"))]
2167-
onion_error_data: Some(data.clone()),
2168-
#[cfg(test)]
2169-
attribution_failed_channel: None,
2170-
}
2171-
} else {
2172-
unreachable!();
2174+
match htlc_source {
2175+
&HTLCSource::OutboundRoute { ref path, .. } => {
2176+
decoded_onion_failure!(
2177+
(Some(path.hops[0].short_channel_id)),
2178+
*failure_reason,
2179+
data
2180+
)
2181+
},
2182+
&HTLCSource::TrampolineForward { ref outbound_payment, .. } => {
2183+
debug_assert!(outbound_payment.is_none());
2184+
decoded_onion_failure!(None, *failure_reason, data)
2185+
},
2186+
_ => unreachable!(),
21732187
}
21742188
},
21752189
}

0 commit comments

Comments
 (0)