@@ -593,7 +593,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
593593} 
594594
595595#[ derive( Clone ) ]   // See Channel::revoke_and_ack for why, tl;dr: Rust bug 
596- pub ( super )  enum  HTLCFailReason  { 
596+ pub ( super )  struct  HTLCFailReason ( HTLCFailReasonRepr ) ; 
597+ 
598+ #[ derive( Clone ) ]   // See Channel::revoke_and_ack for why, tl;dr: Rust bug 
599+ enum  HTLCFailReasonRepr  { 
597600	LightningError  { 
598601		err :  msgs:: OnionErrorPacket , 
599602	} , 
@@ -605,18 +608,29 @@ pub(super) enum HTLCFailReason {
605608
606609impl  core:: fmt:: Debug  for  HTLCFailReason  { 
607610	fn  fmt ( & self ,  f :  & mut  core:: fmt:: Formatter )  -> Result < ( ) ,  core:: fmt:: Error >  { 
608- 		match  self  { 
609- 			HTLCFailReason :: Reason  {  ref  failure_code,  .. }  => { 
611+ 		match  self . 0  { 
612+ 			HTLCFailReasonRepr :: Reason  {  ref  failure_code,  .. }  => { 
610613				write ! ( f,  "HTLC error code {}" ,  failure_code) 
611614			} , 
612- 			HTLCFailReason :: LightningError  {  .. }  => { 
615+ 			HTLCFailReasonRepr :: LightningError  {  .. }  => { 
613616				write ! ( f,  "pre-built LightningError" ) 
614617			} 
615618		} 
616619	} 
617620} 
618621
619- impl_writeable_tlv_based_enum ! ( HTLCFailReason , 
622+ impl  Writeable  for  HTLCFailReason  { 
623+ 	fn  write < W :  crate :: util:: ser:: Writer > ( & self ,  writer :  & mut  W )  -> Result < ( ) ,  crate :: io:: Error >  { 
624+ 		self . 0 . write ( writer) 
625+ 	} 
626+ } 
627+ impl  Readable  for  HTLCFailReason  { 
628+ 	fn  read < R :  crate :: io:: Read > ( reader :  & mut  R )  -> Result < Self ,  crate :: ln:: msgs:: DecodeError >  { 
629+ 		Ok ( Self ( Readable :: read ( reader) ?) ) 
630+ 	} 
631+ } 
632+ 
633+ impl_writeable_tlv_based_enum ! ( HTLCFailReasonRepr , 
620634	( 0 ,  LightningError )  => { 
621635		( 0 ,  err,  required) , 
622636	} , 
@@ -628,21 +642,21 @@ impl_writeable_tlv_based_enum!(HTLCFailReason,
628642
629643impl  HTLCFailReason  { 
630644	pub ( super )  fn  reason ( failure_code :  u16 ,  data :  Vec < u8 > )  -> Self  { 
631- 		Self :: Reason  {  failure_code,  data } 
645+ 		Self ( HTLCFailReasonRepr :: Reason  {  failure_code,  data } ) 
632646	} 
633647
634648	pub ( super )  fn  from_failure_code ( failure_code :  u16 )  -> Self  { 
635- 		Self :: Reason  {  failure_code,  data :  Vec :: new ( )  } 
649+ 		Self ( HTLCFailReasonRepr :: Reason  {  failure_code,  data :  Vec :: new ( )  } ) 
636650	} 
637651
638652	pub ( super )  fn  from_msg ( msg :  & msgs:: UpdateFailHTLC )  -> Self  { 
639- 		Self :: LightningError  {  err :  msg. reason . clone ( )  } 
653+ 		Self ( HTLCFailReasonRepr :: LightningError  {  err :  msg. reason . clone ( )  } ) 
640654	} 
641655
642656	pub ( super )  fn  get_encrypted_failure_packet ( & self ,  incoming_packet_shared_secret :  & [ u8 ;  32 ] ,  phantom_shared_secret :  & Option < [ u8 ;  32 ] > ) 
643657	-> msgs:: OnionErrorPacket  { 
644- 		match  self  { 
645- 			HTLCFailReason :: Reason  {  ref  failure_code,  ref  data }  => { 
658+ 		match  self . 0  { 
659+ 			HTLCFailReasonRepr :: Reason  {  ref  failure_code,  ref  data }  => { 
646660				if  let  Some ( phantom_ss)  = phantom_shared_secret { 
647661					let  phantom_packet = build_failure_packet ( phantom_ss,  * failure_code,  & data[ ..] ) . encode ( ) ; 
648662					let  encrypted_phantom_packet = encrypt_failure_packet ( phantom_ss,  & phantom_packet) ; 
@@ -652,7 +666,7 @@ impl HTLCFailReason {
652666					encrypt_failure_packet ( incoming_packet_shared_secret,  & packet) 
653667				} 
654668			} , 
655- 			HTLCFailReason :: LightningError  {  err }  => { 
669+ 			HTLCFailReasonRepr :: LightningError  {   ref  err }  => { 
656670				encrypt_failure_packet ( incoming_packet_shared_secret,  & err. data ) 
657671			} 
658672		} 
@@ -662,11 +676,11 @@ impl HTLCFailReason {
662676		& self ,  secp_ctx :  & Secp256k1 < T > ,  logger :  & L ,  htlc_source :  & HTLCSource 
663677	)  -> ( Option < crate :: routing:: gossip:: NetworkUpdate > ,  Option < u64 > ,  bool ,  Option < u16 > ,  Option < Vec < u8 > > ) 
664678	where  L :: Target :  Logger  { 
665- 		match  self  { 
666- 			HTLCFailReason :: LightningError  {  ref  err }  => { 
679+ 		match  self . 0  { 
680+ 			HTLCFailReasonRepr :: LightningError  {  ref  err }  => { 
667681				process_onion_failure ( secp_ctx,  logger,  & htlc_source,  err. data . clone ( ) ) 
668682			} , 
669- 			HTLCFailReason :: Reason  {  ref  failure_code,  ref  data,  .. }  => { 
683+ 			HTLCFailReasonRepr :: Reason  {  ref  failure_code,  ref  data,  .. }  => { 
670684				// we get a fail_malformed_htlc from the first hop 
671685				// TODO: We'd like to generate a NetworkUpdate for temporary 
672686				// failures here, but that would be insufficient as find_route 
0 commit comments