@@ -736,22 +736,43 @@ macro_rules! handle_error {
736
736
}
737
737
}
738
738
739
+ macro_rules! convert_chan_err {
740
+ ( $self: ident, $err: expr, $short_to_id: expr, $channel: expr, $channel_id: expr) => {
741
+ match $err {
742
+ ChannelError :: Ignore ( msg) => {
743
+ ( false , MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $channel_id. clone( ) ) )
744
+ } ,
745
+ ChannelError :: Close ( msg) => {
746
+ log_trace!( $self. logger, "Closing channel {} due to close-required error: {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
747
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
748
+ $short_to_id. remove( & short_id) ;
749
+ }
750
+ let shutdown_res = $channel. force_shutdown( true ) ;
751
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
752
+ } ,
753
+ ChannelError :: CloseDelayBroadcast ( msg) => {
754
+ log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
755
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
756
+ $short_to_id. remove( & short_id) ;
757
+ }
758
+ let shutdown_res = $channel. force_shutdown( false ) ;
759
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
760
+ }
761
+ }
762
+ }
763
+ }
764
+
739
765
macro_rules! break_chan_entry {
740
766
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
741
767
match $res {
742
768
Ok ( res) => res,
743
- Err ( ChannelError :: Ignore ( msg) ) => {
744
- break Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
745
- } ,
746
- Err ( ChannelError :: Close ( msg) ) => {
747
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
748
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
749
- if let Some ( short_id) = chan. get_short_channel_id( ) {
750
- $channel_state. short_to_id. remove( & short_id) ;
769
+ Err ( e) => {
770
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
771
+ if drop {
772
+ $entry. remove_entry( ) ;
751
773
}
752
- break Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
753
- } ,
754
- 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" ) ; }
774
+ break Err ( res) ;
775
+ }
755
776
}
756
777
}
757
778
}
@@ -760,25 +781,12 @@ macro_rules! try_chan_entry {
760
781
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
761
782
match $res {
762
783
Ok ( res) => res,
763
- Err ( ChannelError :: Ignore ( msg) ) => {
764
- return Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
765
- } ,
766
- Err ( ChannelError :: Close ( msg) ) => {
767
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
768
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
769
- if let Some ( short_id) = chan. get_short_channel_id( ) {
770
- $channel_state. short_to_id. remove( & short_id) ;
771
- }
772
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
773
- } ,
774
- Err ( ChannelError :: CloseDelayBroadcast ( msg) ) => {
775
- log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
776
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
777
- if let Some ( short_id) = chan. get_short_channel_id( ) {
778
- $channel_state. short_to_id. remove( & short_id) ;
784
+ Err ( e) => {
785
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
786
+ if drop {
787
+ $entry. remove_entry( ) ;
779
788
}
780
- let shutdown_res = chan. force_shutdown( false ) ;
781
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, shutdown_res, $self. get_channel_update( & chan) . ok( ) ) )
789
+ return Err ( res) ;
782
790
}
783
791
}
784
792
}
0 commit comments