@@ -666,22 +666,43 @@ macro_rules! handle_error {
666
666
}
667
667
}
668
668
669
+ macro_rules! convert_chan_err {
670
+ ( $self: ident, $err: expr, $short_to_id: expr, $channel: expr, $channel_id: expr) => {
671
+ match $err {
672
+ ChannelError :: Ignore ( msg) => {
673
+ ( false , MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $channel_id. clone( ) ) )
674
+ } ,
675
+ ChannelError :: Close ( msg) => {
676
+ log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
677
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
678
+ $short_to_id. remove( & short_id) ;
679
+ }
680
+ let shutdown_res = $channel. force_shutdown( true ) ;
681
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
682
+ } ,
683
+ ChannelError :: CloseDelayBroadcast ( msg) => {
684
+ log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
685
+ if let Some ( short_id) = $channel. get_short_channel_id( ) {
686
+ $short_to_id. remove( & short_id) ;
687
+ }
688
+ let shutdown_res = $channel. force_shutdown( false ) ;
689
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update( & $channel) . ok( ) ) )
690
+ }
691
+ }
692
+ }
693
+ }
694
+
669
695
macro_rules! break_chan_entry {
670
696
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
671
697
match $res {
672
698
Ok ( res) => res,
673
- Err ( ChannelError :: Ignore ( msg) ) => {
674
- break Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
675
- } ,
676
- Err ( ChannelError :: Close ( msg) ) => {
677
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
678
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
679
- if let Some ( short_id) = chan. get_short_channel_id( ) {
680
- $channel_state. short_to_id. remove( & short_id) ;
699
+ Err ( e) => {
700
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
701
+ if drop {
702
+ $entry. remove_entry( ) ;
681
703
}
682
- break Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
683
- } ,
684
- 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" ) ; }
704
+ break Err ( res) ;
705
+ }
685
706
}
686
707
}
687
708
}
@@ -690,25 +711,12 @@ macro_rules! try_chan_entry {
690
711
( $self: ident, $res: expr, $channel_state: expr, $entry: expr) => {
691
712
match $res {
692
713
Ok ( res) => res,
693
- Err ( ChannelError :: Ignore ( msg) ) => {
694
- return Err ( MsgHandleErrInternal :: from_chan_no_close( ChannelError :: Ignore ( msg) , $entry. key( ) . clone( ) ) )
695
- } ,
696
- Err ( ChannelError :: Close ( msg) ) => {
697
- log_trace!( $self. logger, "Closing channel {} due to Close-required error: {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
698
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
699
- if let Some ( short_id) = chan. get_short_channel_id( ) {
700
- $channel_state. short_to_id. remove( & short_id) ;
701
- }
702
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, chan. force_shutdown( true ) , $self. get_channel_update( & chan) . ok( ) ) )
703
- } ,
704
- Err ( ChannelError :: CloseDelayBroadcast ( msg) ) => {
705
- log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $entry. key( ) [ ..] ) , msg) ;
706
- let ( channel_id, mut chan) = $entry. remove_entry( ) ;
707
- if let Some ( short_id) = chan. get_short_channel_id( ) {
708
- $channel_state. short_to_id. remove( & short_id) ;
714
+ Err ( e) => {
715
+ let ( drop, res) = convert_chan_err!( $self, e, $channel_state. short_to_id, $entry. get_mut( ) , $entry. key( ) ) ;
716
+ if drop {
717
+ $entry. remove_entry( ) ;
709
718
}
710
- let shutdown_res = chan. force_shutdown( false ) ;
711
- return Err ( MsgHandleErrInternal :: from_finish_shutdown( msg, channel_id, shutdown_res, $self. get_channel_update( & chan) . ok( ) ) )
719
+ return Err ( res) ;
712
720
}
713
721
}
714
722
}
0 commit comments