@@ -719,16 +719,34 @@ macro_rules! handle_chan_restoration_locked {
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_locked {
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
@@ -795,8 +800,11 @@ macro_rules! post_handle_chan_restoration {
795
800
$self. pending_events. lock( ) . unwrap( ) . push( ev) ;
796
801
}
797
802
798
- $self. fail_holding_cell_htlcs( $forwarding_failures, channel_id) ;
799
- for failure in $pending_failures. drain( ..) {
803
+ let forwarding_failures: Vec <( HTLCSource , PaymentHash ) > = $forwarding_failures; // Force type-checking to resolve
804
+ $self. fail_holding_cell_htlcs( forwarding_failures, channel_id) ;
805
+
806
+ let mut pending_failures: Vec <( HTLCSource , PaymentHash , HTLCFailReason ) > = $pending_failures; // Force type-checking to resolve
807
+ for failure in pending_failures. drain( ..) {
800
808
$self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
801
809
}
802
810
if let Some ( forwards) = htlc_forwards {
@@ -2310,7 +2318,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2310
2318
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2311
2319
let _consistency_lock = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2312
2320
2313
- let ( mut pending_failures, forwarding_failds, chan_restoration_res) = {
2321
+ let ( pending_failures, forwarding_failds, chan_restoration_res) = {
2314
2322
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2315
2323
let channel_state = & mut * channel_lock;
2316
2324
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2913,77 +2921,34 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2913
2921
}
2914
2922
2915
2923
fn internal_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , MsgHandleErrInternal > {
2916
- let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2917
- let channel_state = & mut * channel_state_lock;
2924
+ let chan_restoration_res = {
2925
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2926
+ let channel_state = & mut * channel_state_lock;
2918
2927
2919
- match channel_state. by_id . entry ( msg. channel_id ) {
2920
- hash_map:: Entry :: Occupied ( mut chan) => {
2921
- if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
2922
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
2923
- }
2924
- // Currently, we expect all holding cell update_adds to be dropped on peer
2925
- // disconnect, so Channel's reestablish will never hand us any holding cell
2926
- // freed HTLCs to fail backwards. If in the future we no longer drop pending
2927
- // add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
2928
- let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, mut order, shutdown) =
2929
- try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
2930
- if let Some ( monitor_update) = monitor_update_opt {
2931
- if let Err ( e) = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
2932
- // channel_reestablish doesn't guarantee the order it returns is sensical
2933
- // for the messages it returns, but if we're setting what messages to
2934
- // re-transmit on monitor update success, we need to make sure it is sane.
2935
- if revoke_and_ack. is_none ( ) {
2936
- order = RAACommitmentOrder :: CommitmentFirst ;
2937
- }
2938
- if commitment_update. is_none ( ) {
2939
- order = RAACommitmentOrder :: RevokeAndACKFirst ;
2940
- }
2941
- return_monitor_err ! ( self , e, channel_state, chan, order, revoke_and_ack. is_some( ) , commitment_update. is_some( ) ) ;
2942
- //TODO: Resend the funding_locked if needed once we get the monitor running again
2943
- }
2944
- }
2945
- if let Some ( msg) = funding_locked {
2946
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendFundingLocked {
2947
- node_id : counterparty_node_id. clone ( ) ,
2948
- msg
2949
- } ) ;
2950
- }
2951
- macro_rules! send_raa { ( ) => {
2952
- if let Some ( msg) = revoke_and_ack {
2953
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
2954
- node_id: counterparty_node_id. clone( ) ,
2955
- msg
2956
- } ) ;
2928
+ match channel_state. by_id . entry ( msg. channel_id ) {
2929
+ hash_map:: Entry :: Occupied ( mut chan) => {
2930
+ if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
2931
+ return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
2957
2932
}
2958
- } }
2959
- macro_rules! send_cu { ( ) => {
2960
- if let Some ( updates) = commitment_update {
2961
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
2933
+ // Currently, we expect all holding cell update_adds to be dropped on peer
2934
+ // disconnect, so Channel's reestablish will never hand us any holding cell
2935
+ // freed HTLCs to fail backwards. If in the future we no longer drop pending
2936
+ // add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
2937
+ let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, shutdown) =
2938
+ try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
2939
+ if let Some ( msg) = shutdown {
2940
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
2962
2941
node_id : counterparty_node_id. clone ( ) ,
2963
- updates
2942
+ msg ,
2964
2943
} ) ;
2965
2944
}
2966
- } }
2967
- match order {
2968
- RAACommitmentOrder :: RevokeAndACKFirst => {
2969
- send_raa ! ( ) ;
2970
- send_cu ! ( ) ;
2971
- } ,
2972
- RAACommitmentOrder :: CommitmentFirst => {
2973
- send_cu ! ( ) ;
2974
- send_raa ! ( ) ;
2975
- } ,
2976
- }
2977
- if let Some ( msg) = shutdown {
2978
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
2979
- node_id : counterparty_node_id. clone ( ) ,
2980
- msg,
2981
- } ) ;
2982
- }
2983
- Ok ( ( ) )
2984
- } ,
2985
- hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
2986
- }
2945
+ handle_chan_restoration_locked ! ( self , channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec :: new( ) , false , funding_locked)
2946
+ } ,
2947
+ hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
2948
+ }
2949
+ } ;
2950
+ post_handle_chan_restoration ! ( self , chan_restoration_res, Vec :: new( ) , Vec :: new( ) ) ;
2951
+ Ok ( ( ) )
2987
2952
}
2988
2953
2989
2954
/// Begin Update fee process. Allowed only on an outbound channel.
0 commit comments