@@ -1765,8 +1765,8 @@ impl_writeable_tlv_based_enum!(LocalHTLCFailureReason,
1765
1765
impl From < & HTLCFailurePayload > for HTLCHandlingFailureReason {
1766
1766
fn from ( value : & HTLCFailurePayload ) -> Self {
1767
1767
match value. 0 {
1768
- HTLCFailReasonRepr :: LightningError { .. } => HTLCHandlingFailureReason :: Downstream ,
1769
- HTLCFailReasonRepr :: Reason { failure_reason, .. } => {
1768
+ HTLCFailure :: LightningError { .. } => HTLCHandlingFailureReason :: Downstream ,
1769
+ HTLCFailure :: Reason { failure_reason, .. } => {
1770
1770
HTLCHandlingFailureReason :: Local { reason : failure_reason }
1771
1771
} ,
1772
1772
}
@@ -1776,19 +1776,21 @@ impl From<&HTLCFailurePayload> for HTLCHandlingFailureReason {
1776
1776
/// Contains the information required to construct the failure message for a failed HTLC.
1777
1777
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
1778
1778
#[ cfg_attr( test, derive( PartialEq ) ) ]
1779
- pub ( super ) struct HTLCFailurePayload ( HTLCFailReasonRepr ) ;
1779
+ pub ( super ) struct HTLCFailurePayload ( HTLCFailure ) ;
1780
1780
1781
1781
#[ derive( Clone ) ] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
1782
1782
#[ 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.
1784
1785
LightningError { err : msgs:: OnionErrorPacket , hold_time : Option < u32 > } ,
1786
+ /// HTLC failed locally and should be failed back with the payload provided.
1785
1787
Reason { data : Vec < u8 > , failure_reason : LocalHTLCFailureReason } ,
1786
1788
}
1787
1789
1788
1790
impl HTLCFailurePayload {
1789
1791
pub fn set_hold_time ( & mut self , hold_time : u32 ) {
1790
1792
match self . 0 {
1791
- HTLCFailReasonRepr :: LightningError { hold_time : ref mut current_hold_time, .. } => {
1793
+ HTLCFailure :: LightningError { hold_time : ref mut current_hold_time, .. } => {
1792
1794
* current_hold_time = Some ( hold_time) ;
1793
1795
} ,
1794
1796
_ => { } ,
@@ -1799,15 +1801,15 @@ impl HTLCFailurePayload {
1799
1801
impl core:: fmt:: Debug for HTLCFailurePayload {
1800
1802
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
1801
1803
match self . 0 {
1802
- HTLCFailReasonRepr :: Reason { ref failure_reason, .. } => {
1804
+ HTLCFailure :: Reason { ref failure_reason, .. } => {
1803
1805
write ! (
1804
1806
f,
1805
1807
"HTLC failure {:?} error code {}" ,
1806
1808
failure_reason,
1807
1809
failure_reason. failure_code( )
1808
1810
)
1809
1811
} ,
1810
- HTLCFailReasonRepr :: LightningError { .. } => {
1812
+ HTLCFailure :: LightningError { .. } => {
1811
1813
write ! ( f, "pre-built LightningError" )
1812
1814
} ,
1813
1815
}
@@ -1825,17 +1827,17 @@ impl Readable for HTLCFailurePayload {
1825
1827
}
1826
1828
}
1827
1829
1828
- impl_writeable_tlv_based_enum ! ( HTLCFailReasonRepr ,
1830
+ impl_writeable_tlv_based_enum ! ( HTLCFailure ,
1829
1831
( 0 , LightningError ) => {
1830
1832
( 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 {
1832
1834
Some ( data)
1833
1835
} else {
1834
1836
None
1835
1837
} )
1836
1838
) ,
1837
1839
( 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 {
1839
1841
attribution_data. as_ref( )
1840
1842
} else {
1841
1843
None
@@ -1846,9 +1848,9 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
1846
1848
} ,
1847
1849
( 1 , Reason ) => {
1848
1850
( 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( ) )
1852
1854
} ) ) ,
1853
1855
// failure_code was required, and is replaced by reason in 0.2 so any time we do not have a
1854
1856
// reason available failure_code will be Some and can be expressed as a reason.
@@ -1930,15 +1932,15 @@ impl HTLCFailurePayload {
1930
1932
} ,
1931
1933
}
1932
1934
1933
- Self ( HTLCFailReasonRepr :: Reason { data, failure_reason } )
1935
+ Self ( HTLCFailure :: Reason { data, failure_reason } )
1934
1936
}
1935
1937
1936
1938
pub ( super ) fn from_failure_code ( failure_reason : LocalHTLCFailureReason ) -> Self {
1937
1939
Self :: reason ( failure_reason, Vec :: new ( ) )
1938
1940
}
1939
1941
1940
1942
pub ( super ) fn from_msg ( msg : & msgs:: UpdateFailHTLC ) -> Self {
1941
- Self ( HTLCFailReasonRepr :: LightningError {
1943
+ Self ( HTLCFailure :: LightningError {
1942
1944
err : OnionErrorPacket {
1943
1945
data : msg. reason . clone ( ) ,
1944
1946
attribution_data : msg. attribution_data . clone ( ) ,
@@ -1956,7 +1958,7 @@ impl HTLCFailurePayload {
1956
1958
& self , incoming_packet_shared_secret : & [ u8 ; 32 ] , secondary_shared_secret : & Option < [ u8 ; 32 ] > ,
1957
1959
) -> msgs:: OnionErrorPacket {
1958
1960
match self . 0 {
1959
- HTLCFailReasonRepr :: Reason { ref data, ref failure_reason } => {
1961
+ HTLCFailure :: Reason { ref data, ref failure_reason } => {
1960
1962
// Final hop always reports zero hold time.
1961
1963
let hold_time: u32 = 0 ;
1962
1964
@@ -1982,7 +1984,7 @@ impl HTLCFailurePayload {
1982
1984
)
1983
1985
}
1984
1986
} ,
1985
- HTLCFailReasonRepr :: LightningError { ref err, hold_time } => {
1987
+ HTLCFailure :: LightningError { ref err, hold_time } => {
1986
1988
let mut err = err. clone ( ) ;
1987
1989
let hold_time = hold_time. unwrap_or ( 0 ) ;
1988
1990
@@ -2001,11 +2003,11 @@ impl HTLCFailurePayload {
2001
2003
L :: Target : Logger ,
2002
2004
{
2003
2005
match self . 0 {
2004
- HTLCFailReasonRepr :: LightningError { ref err, .. } => {
2006
+ HTLCFailure :: LightningError { ref err, .. } => {
2005
2007
process_onion_failure ( secp_ctx, logger, & htlc_source, err. clone ( ) )
2006
2008
} ,
2007
2009
#[ allow( unused) ]
2008
- HTLCFailReasonRepr :: Reason { ref data, ref failure_reason } => {
2010
+ HTLCFailure :: Reason { ref data, ref failure_reason } => {
2009
2011
// we get a fail_malformed_htlc from the first hop
2010
2012
// TODO: We'd like to generate a NetworkUpdate for temporary
2011
2013
// failures here, but that would be insufficient as find_route
0 commit comments