@@ -695,22 +695,43 @@ macro_rules! handle_error {
695
695
}
696
696
}
697
697
698
+ macro_rules! convert_chan_err {
699
+ ( $self: ident, $err: expr, $short_to_id: expr, $channel: expr, $channel_id: expr) => {
700
+ match $err {
701
+ ChannelError :: Ignore ( msg) => {
702
+ ( false , MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $channel_id. clone( ) ) )
703
+ } ,
704
+ ChannelError :: Close ( msg) => {
705
+ log_trace!( $self. logger, "Closing channel {} due to close-required error: {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
706
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
707
+ $short_to_id. remove( & short_id) ;
708
+ }
709
+ let shutdown_res = $channel. force_shutdown( true ) ;
710
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
711
+ } ,
712
+ ChannelError :: CloseDelayBroadcast ( msg) => {
713
+ log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
714
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
715
+ $short_to_id. remove( & short_id) ;
716
+ }
717
+ let shutdown_res = $channel. force_shutdown( false ) ;
718
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
719
+ }
720
+ }
721
+ }
722
+ }
723
+
698
724
macro_rules! break_chan_entry {
699
725
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
700
726
match $res {
701
727
Ok ( res) => res,
702
- Err ( ChannelError :: Ignore ( msg) ) => {
703
- break Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
704
- } ,
705
- Err ( ChannelError :: Close ( msg) ) => {
706
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
707
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
708
- if let Some ( short_id) = chan. get_short_channel_id( ) {
709
- $channel_state. short_to_id. remove( & short_id) ;
728
+ Err ( e) => {
729
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
730
+ if drop {
731
+ $entry. remove_entry( ) ;
710
732
}
711
- break Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
712
- } ,
713
- 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" ) ; }
733
+ break Err ( res) ;
734
+ }
714
735
}
715
736
}
716
737
}
@@ -719,25 +740,12 @@ macro_rules! try_chan_entry {
719
740
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
720
741
match $res {
721
742
Ok ( res) => res,
722
- Err ( ChannelError :: Ignore ( msg) ) => {
723
- return Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
724
- } ,
725
- Err ( ChannelError :: Close ( msg) ) => {
726
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
727
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
728
- if let Some ( short_id) = chan. get_short_channel_id( ) {
729
- $channel_state. short_to_id. remove( & short_id) ;
730
- }
731
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
732
- } ,
733
- Err ( ChannelError :: CloseDelayBroadcast ( msg) ) => {
734
- log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
735
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
736
- if let Some ( short_id) = chan. get_short_channel_id( ) {
737
- $channel_state. short_to_id. remove( & short_id) ;
743
+ Err ( e) => {
744
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
745
+ if drop {
746
+ $entry. remove_entry( ) ;
738
747
}
739
- let shutdown_res = chan. force_shutdown( false ) ;
740
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, shutdown_res, $self. get_channel_update( & chan) . ok( ) ) )
748
+ return Err ( res) ;
741
749
}
742
750
}
743
751
}
0 commit comments