@@ -766,22 +766,43 @@ macro_rules! handle_error {
766
766
}
767
767
}
768
768
769
+ macro_rules! convert_chan_err {
770
+ ( $self: ident, $err: expr, $short_to_id: expr, $channel: expr, $channel_id: expr) => {
771
+ match $err {
772
+ ChannelError :: Ignore ( msg) => {
773
+ ( false , MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $channel_id. clone( ) ) )
774
+ } ,
775
+ ChannelError :: Close ( msg) => {
776
+ log_trace!( $self. logger, "Closing channel {} due to close-required error: {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
777
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
778
+ $short_to_id. remove( & short_id) ;
779
+ }
780
+ let shutdown_res = $channel. force_shutdown( true ) ;
781
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
782
+ } ,
783
+ ChannelError :: CloseDelayBroadcast ( msg) => {
784
+ log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
785
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
786
+ $short_to_id. remove( & short_id) ;
787
+ }
788
+ let shutdown_res = $channel. force_shutdown( false ) ;
789
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
790
+ }
791
+ }
792
+ }
793
+ }
794
+
769
795
macro_rules! break_chan_entry {
770
796
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
771
797
match $res {
772
798
Ok ( res) => res,
773
- Err ( ChannelError :: Ignore ( msg) ) => {
774
- break Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
775
- } ,
776
- Err ( ChannelError :: Close ( msg) ) => {
777
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
778
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
779
- if let Some ( short_id) = chan. get_short_channel_id( ) {
780
- $channel_state. short_to_id. remove( & short_id) ;
799
+ Err ( e) => {
800
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
801
+ if drop {
802
+ $entry. remove_entry( ) ;
781
803
}
782
- break Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
783
- } ,
784
- Err ( ChannelError :: CloseDelayBroadcast ( _) ) => { panic!( "Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here" ) ; }
804
+ break Err ( res) ;
805
+ }
785
806
}
786
807
}
787
808
}
@@ -790,25 +811,12 @@ macro_rules! try_chan_entry {
790
811
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
791
812
match $res {
792
813
Ok ( res) => res,
793
- Err ( ChannelError :: Ignore ( msg) ) => {
794
- return Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
795
- } ,
796
- Err ( ChannelError :: Close ( msg) ) => {
797
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
798
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
799
- if let Some ( short_id) = chan. get_short_channel_id( ) {
800
- $channel_state. short_to_id. remove( & short_id) ;
801
- }
802
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
803
- } ,
804
- Err ( ChannelError :: CloseDelayBroadcast ( msg) ) => {
805
- log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
806
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
807
- if let Some ( short_id) = chan. get_short_channel_id( ) {
808
- $channel_state. short_to_id. remove( & short_id) ;
814
+ Err ( e) => {
815
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
816
+ if drop {
817
+ $entry. remove_entry( ) ;
809
818
}
810
- let shutdown_res = chan. force_shutdown( false ) ;
811
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, shutdown_res, $self. get_channel_update( & chan) . ok( ) ) )
819
+ return Err ( res) ;
812
820
}
813
821
}
814
822
}
0 commit comments