Skip to content

Commit 6638118

Browse files
committed
ln/refactor: rename HTLCFailReasonRepr to HTLCFailure
This type is only used internally in onion_utils, so we can rename it to HTLCFailure to be more concise.
1 parent a880b73 commit 6638118

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,8 +1765,8 @@ impl_writeable_tlv_based_enum!(LocalHTLCFailureReason,
17651765
impl From<&HTLCFailurePayload> for HTLCHandlingFailureReason {
17661766
fn from(value: &HTLCFailurePayload) -> Self {
17671767
match value.0 {
1768-
HTLCFailReasonRepr::LightningError { .. } => HTLCHandlingFailureReason::Downstream,
1769-
HTLCFailReasonRepr::Reason { failure_reason, .. } => {
1768+
HTLCFailure::LightningError { .. } => HTLCHandlingFailureReason::Downstream,
1769+
HTLCFailure::Reason { failure_reason, .. } => {
17701770
HTLCHandlingFailureReason::Local { reason: failure_reason }
17711771
},
17721772
}
@@ -1776,19 +1776,21 @@ impl From<&HTLCFailurePayload> for HTLCHandlingFailureReason {
17761776
/// Contains the information required to construct the failure message for a failed HTLC.
17771777
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
17781778
#[cfg_attr(test, derive(PartialEq))]
1779-
pub(super) struct HTLCFailurePayload(HTLCFailReasonRepr);
1779+
pub(super) struct HTLCFailurePayload(HTLCFailure);
17801780

17811781
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
17821782
#[cfg_attr(test, derive(PartialEq))]
1783-
enum HTLCFailReasonRepr {
1783+
enum HTLCFailure {
1784+
/// HTLC failed downstream and should be failed back with the encrypted error packet.
17841785
LightningError { err: msgs::OnionErrorPacket, hold_time: Option<u32> },
1786+
/// HTLC failed locally and should be failed back with the payload provided.
17851787
Reason { data: Vec<u8>, failure_reason: LocalHTLCFailureReason },
17861788
}
17871789

17881790
impl HTLCFailurePayload {
17891791
pub fn set_hold_time(&mut self, hold_time: u32) {
17901792
match self.0 {
1791-
HTLCFailReasonRepr::LightningError { hold_time: ref mut current_hold_time, .. } => {
1793+
HTLCFailure::LightningError { hold_time: ref mut current_hold_time, .. } => {
17921794
*current_hold_time = Some(hold_time);
17931795
},
17941796
_ => {},
@@ -1799,15 +1801,15 @@ impl HTLCFailurePayload {
17991801
impl core::fmt::Debug for HTLCFailurePayload {
18001802
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
18011803
match self.0 {
1802-
HTLCFailReasonRepr::Reason { ref failure_reason, .. } => {
1804+
HTLCFailure::Reason { ref failure_reason, .. } => {
18031805
write!(
18041806
f,
18051807
"HTLC failure {:?} error code {}",
18061808
failure_reason,
18071809
failure_reason.failure_code()
18081810
)
18091811
},
1810-
HTLCFailReasonRepr::LightningError { .. } => {
1812+
HTLCFailure::LightningError { .. } => {
18111813
write!(f, "pre-built LightningError")
18121814
},
18131815
}
@@ -1825,17 +1827,17 @@ impl Readable for HTLCFailurePayload {
18251827
}
18261828
}
18271829

1828-
impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
1830+
impl_writeable_tlv_based_enum!(HTLCFailure,
18291831
(0, LightningError) => {
18301832
(0, data, (legacy, Vec<u8>, |us|
1831-
if let &HTLCFailReasonRepr::LightningError { err: msgs::OnionErrorPacket { ref data, .. }, .. } = us {
1833+
if let &HTLCFailure::LightningError { err: msgs::OnionErrorPacket { ref data, .. }, .. } = us {
18321834
Some(data)
18331835
} else {
18341836
None
18351837
})
18361838
),
18371839
(1, attribution_data, (legacy, AttributionData, |us|
1838-
if let &HTLCFailReasonRepr::LightningError { err: msgs::OnionErrorPacket { ref attribution_data, .. }, .. } = us {
1840+
if let &HTLCFailure::LightningError { err: msgs::OnionErrorPacket { ref attribution_data, .. }, .. } = us {
18391841
attribution_data.as_ref()
18401842
} else {
18411843
None
@@ -1846,9 +1848,9 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
18461848
},
18471849
(1, Reason) => {
18481850
(0, _failure_code, (legacy, u16,
1849-
|r: &HTLCFailReasonRepr| match r {
1850-
HTLCFailReasonRepr::LightningError{ .. } => None,
1851-
HTLCFailReasonRepr::Reason{ failure_reason, .. } => Some(failure_reason.failure_code())
1851+
|r: &HTLCFailure| match r {
1852+
HTLCFailure::LightningError{ .. } => None,
1853+
HTLCFailure::Reason{ failure_reason, .. } => Some(failure_reason.failure_code())
18521854
})),
18531855
// failure_code was required, and is replaced by reason in 0.2 so any time we do not have a
18541856
// reason available failure_code will be Some and can be expressed as a reason.
@@ -1930,15 +1932,15 @@ impl HTLCFailurePayload {
19301932
},
19311933
}
19321934

1933-
Self(HTLCFailReasonRepr::Reason { data, failure_reason })
1935+
Self(HTLCFailure::Reason { data, failure_reason })
19341936
}
19351937

19361938
pub(super) fn from_failure_code(failure_reason: LocalHTLCFailureReason) -> Self {
19371939
Self::reason(failure_reason, Vec::new())
19381940
}
19391941

19401942
pub(super) fn from_msg(msg: &msgs::UpdateFailHTLC) -> Self {
1941-
Self(HTLCFailReasonRepr::LightningError {
1943+
Self(HTLCFailure::LightningError {
19421944
err: OnionErrorPacket {
19431945
data: msg.reason.clone(),
19441946
attribution_data: msg.attribution_data.clone(),
@@ -1956,7 +1958,7 @@ impl HTLCFailurePayload {
19561958
&self, incoming_packet_shared_secret: &[u8; 32], secondary_shared_secret: &Option<[u8; 32]>,
19571959
) -> msgs::OnionErrorPacket {
19581960
match self.0 {
1959-
HTLCFailReasonRepr::Reason { ref data, ref failure_reason } => {
1961+
HTLCFailure::Reason { ref data, ref failure_reason } => {
19601962
// Final hop always reports zero hold time.
19611963
let hold_time: u32 = 0;
19621964

@@ -1982,7 +1984,7 @@ impl HTLCFailurePayload {
19821984
)
19831985
}
19841986
},
1985-
HTLCFailReasonRepr::LightningError { ref err, hold_time } => {
1987+
HTLCFailure::LightningError { ref err, hold_time } => {
19861988
let mut err = err.clone();
19871989
let hold_time = hold_time.unwrap_or(0);
19881990

@@ -2001,11 +2003,11 @@ impl HTLCFailurePayload {
20012003
L::Target: Logger,
20022004
{
20032005
match self.0 {
2004-
HTLCFailReasonRepr::LightningError { ref err, .. } => {
2006+
HTLCFailure::LightningError { ref err, .. } => {
20052007
process_onion_failure(secp_ctx, logger, &htlc_source, err.clone())
20062008
},
20072009
#[allow(unused)]
2008-
HTLCFailReasonRepr::Reason { ref data, ref failure_reason } => {
2010+
HTLCFailure::Reason { ref data, ref failure_reason } => {
20092011
// we get a fail_malformed_htlc from the first hop
20102012
// TODO: We'd like to generate a NetworkUpdate for temporary
20112013
// failures here, but that would be insufficient as find_route

0 commit comments

Comments
 (0)