@@ -719,16 +719,34 @@ macro_rules! handle_chan_restoration {
719
719
let channel_id = $channel_entry. get( ) . channel_id( ) ;
720
720
721
721
let res = loop {
722
- if !$pending_forwards. is_empty( ) {
722
+ let forwards: Vec <( PendingHTLCInfo , u64 ) > = $pending_forwards; // Force type-checking to resolve
723
+ if !forwards. is_empty( ) {
723
724
htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
724
- $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
725
+ $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , forwards) ) ;
726
+ }
727
+ if $chanmon_update. is_some( ) {
728
+ assert!( $commitment_update. is_some( ) ) ;
729
+ assert!( $funding_locked. is_none( ) ) ;
730
+ }
731
+
732
+ if let Some ( msg) = $funding_locked {
733
+ $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
734
+ node_id: counterparty_node_id,
735
+ msg,
736
+ } ) ;
737
+ if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
738
+ $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
739
+ node_id: counterparty_node_id,
740
+ msg: announcement_sigs,
741
+ } ) ;
742
+ }
743
+ $channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , channel_id) ;
725
744
}
726
745
727
746
macro_rules! handle_cs { ( ) => {
728
747
if let Some ( monitor_update) = $chanmon_update {
729
748
assert!( $order == RAACommitmentOrder :: RevokeAndACKFirst ) ;
730
749
assert!( !$broadcast_safe) ;
731
- assert!( $funding_locked. is_none( ) ) ;
732
750
assert!( $commitment_update. is_some( ) ) ;
733
751
if let Err ( e) = $self. chain_monitor. update_channel( $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , monitor_update) {
734
752
break handle_monitor_err!( $self, e, $channel_state, $channel_entry, RAACommitmentOrder :: CommitmentFirst , false , true ) ;
@@ -765,19 +783,6 @@ macro_rules! handle_chan_restoration {
765
783
user_channel_id: $channel_entry. get( ) . get_user_id( ) ,
766
784
} ) ;
767
785
}
768
- if let Some ( msg) = $funding_locked {
769
- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
770
- node_id: counterparty_node_id,
771
- msg,
772
- } ) ;
773
- if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
774
- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
775
- node_id: counterparty_node_id,
776
- msg: announcement_sigs,
777
- } ) ;
778
- }
779
- $channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , channel_id) ;
780
- }
781
786
break Ok ( ( ) ) ;
782
787
} ;
783
788
@@ -789,8 +794,11 @@ macro_rules! handle_chan_restoration {
789
794
$self. pending_events. lock( ) . unwrap( ) . push( ev) ;
790
795
}
791
796
792
- $self. fail_holding_cell_htlcs( $forwarding_failures, channel_id) ;
793
- for failure in $pending_failures. drain( ..) {
797
+ let forwarding_failures: Vec <( HTLCSource , PaymentHash ) > = $forwarding_failures; // Force type-checking to resolve
798
+ $self. fail_holding_cell_htlcs( forwarding_failures, channel_id) ;
799
+
800
+ let mut pending_failures: Vec <( HTLCSource , PaymentHash , HTLCFailReason ) > = $pending_failures; // Force type-checking to resolve
801
+ for failure in pending_failures. drain( ..) {
794
802
$self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
795
803
}
796
804
if let Some ( forwards) = htlc_forwards {
@@ -2314,7 +2322,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2314
2322
return ;
2315
2323
}
2316
2324
2317
- let ( raa, commitment_update, order, chanmon_update, pending_forwards, mut pending_failures, forwarding_failds, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2325
+ let ( raa, commitment_update, order, chanmon_update, pending_forwards, pending_failures, forwarding_failds, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2318
2326
handle_chan_restoration ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, chanmon_update, pending_forwards, pending_failures, forwarding_failds, needs_broadcast_safe, funding_locked) ;
2319
2327
}
2320
2328
@@ -2916,61 +2924,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2916
2924
// disconnect, so Channel's reestablish will never hand us any holding cell
2917
2925
// freed HTLCs to fail backwards. If in the future we no longer drop pending
2918
2926
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
2919
- let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, mut order, shutdown) =
2927
+ let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, shutdown) =
2920
2928
try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
2921
- if let Some ( monitor_update) = monitor_update_opt {
2922
- if let Err ( e) = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
2923
- // channel_reestablish doesn't guarantee the order it returns is sensical
2924
- // for the messages it returns, but if we're setting what messages to
2925
- // re-transmit on monitor update success, we need to make sure it is sane.
2926
- if revoke_and_ack. is_none ( ) {
2927
- order = RAACommitmentOrder :: CommitmentFirst ;
2928
- }
2929
- if commitment_update. is_none ( ) {
2930
- order = RAACommitmentOrder :: RevokeAndACKFirst ;
2931
- }
2932
- return_monitor_err ! ( self , e, channel_state, chan, order, revoke_and_ack. is_some( ) , commitment_update. is_some( ) ) ;
2933
- //TODO: Resend the funding_locked if needed once we get the monitor running again
2934
- }
2935
- }
2936
- if let Some ( msg) = funding_locked {
2937
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendFundingLocked {
2938
- node_id : counterparty_node_id. clone ( ) ,
2939
- msg
2940
- } ) ;
2941
- }
2942
- macro_rules! send_raa { ( ) => {
2943
- if let Some ( msg) = revoke_and_ack {
2944
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
2945
- node_id: counterparty_node_id. clone( ) ,
2946
- msg
2947
- } ) ;
2948
- }
2949
- } }
2950
- macro_rules! send_cu { ( ) => {
2951
- if let Some ( updates) = commitment_update {
2952
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
2953
- node_id: counterparty_node_id. clone( ) ,
2954
- updates
2955
- } ) ;
2956
- }
2957
- } }
2958
- match order {
2959
- RAACommitmentOrder :: RevokeAndACKFirst => {
2960
- send_raa ! ( ) ;
2961
- send_cu ! ( ) ;
2962
- } ,
2963
- RAACommitmentOrder :: CommitmentFirst => {
2964
- send_cu ! ( ) ;
2965
- send_raa ! ( ) ;
2966
- } ,
2967
- }
2968
2929
if let Some ( msg) = shutdown {
2969
2930
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
2970
2931
node_id : counterparty_node_id. clone ( ) ,
2971
2932
msg,
2972
2933
} ) ;
2973
2934
}
2935
+ handle_chan_restoration ! ( self , channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec :: new( ) , Vec :: new( ) , Vec :: new( ) , false , funding_locked) ;
2974
2936
Ok ( ( ) )
2975
2937
} ,
2976
2938
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
0 commit comments