@@ -754,16 +754,34 @@ macro_rules! handle_chan_restoration_locked {
754
754
let channel_id = $channel_entry. get( ) . channel_id( ) ;
755
755
756
756
let res = loop {
757
- if !$pending_forwards. is_empty( ) {
757
+ let forwards: Vec <( PendingHTLCInfo , u64 ) > = $pending_forwards; // Force type-checking to resolve
758
+ if !forwards. is_empty( ) {
758
759
htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
759
- $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
760
+ $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , forwards) ) ;
761
+ }
762
+ if $chanmon_update. is_some( ) {
763
+ assert!( $commitment_update. is_some( ) ) ;
764
+ assert!( $funding_locked. is_none( ) ) ;
765
+ }
766
+
767
+ if let Some ( msg) = $funding_locked {
768
+ $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
769
+ node_id: counterparty_node_id,
770
+ msg,
771
+ } ) ;
772
+ if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
773
+ $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
774
+ node_id: counterparty_node_id,
775
+ msg: announcement_sigs,
776
+ } ) ;
777
+ }
778
+ $channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , channel_id) ;
760
779
}
761
780
762
781
macro_rules! handle_cs { ( ) => {
763
782
if let Some ( monitor_update) = $chanmon_update {
764
783
assert!( $order == RAACommitmentOrder :: RevokeAndACKFirst ) ;
765
784
assert!( !$broadcast_safe) ;
766
- assert!( $funding_locked. is_none( ) ) ;
767
785
assert!( $commitment_update. is_some( ) ) ;
768
786
if let Err ( e) = $self. chain_monitor. update_channel( $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , monitor_update) {
769
787
break handle_monitor_err!( $self, e, $channel_state, $channel_entry, RAACommitmentOrder :: CommitmentFirst , false , true ) ;
@@ -800,19 +818,6 @@ macro_rules! handle_chan_restoration_locked {
800
818
user_channel_id: $channel_entry. get( ) . get_user_id( ) ,
801
819
} ) ;
802
820
}
803
- if let Some ( msg) = $funding_locked {
804
- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
805
- node_id: counterparty_node_id,
806
- msg,
807
- } ) ;
808
- if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
809
- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
810
- node_id: counterparty_node_id,
811
- msg: announcement_sigs,
812
- } ) ;
813
- }
814
- $channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , channel_id) ;
815
- }
816
821
break Ok ( ( ) ) ;
817
822
} ;
818
823
@@ -830,8 +835,11 @@ macro_rules! post_handle_chan_restoration {
830
835
$self. pending_events. lock( ) . unwrap( ) . push( ev) ;
831
836
}
832
837
833
- $self. fail_holding_cell_htlcs( $forwarding_failures, channel_id) ;
834
- for failure in $pending_failures. drain( ..) {
838
+ let forwarding_failures: Vec <( HTLCSource , PaymentHash ) > = $forwarding_failures; // Force type-checking to resolve
839
+ $self. fail_holding_cell_htlcs( forwarding_failures, channel_id) ;
840
+
841
+ let mut pending_failures: Vec <( HTLCSource , PaymentHash , HTLCFailReason ) > = $pending_failures; // Force type-checking to resolve
842
+ for failure in pending_failures. drain( ..) {
835
843
$self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
836
844
}
837
845
if let Some ( forwards) = htlc_forwards {
@@ -2364,7 +2372,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2364
2372
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2365
2373
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2366
2374
2367
- let ( mut pending_failures, forwarding_failures, chan_restoration_res) = {
2375
+ let ( pending_failures, forwarding_failures, chan_restoration_res) = {
2368
2376
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2369
2377
let channel_state = & mut * channel_lock;
2370
2378
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2967,77 +2975,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2967
2975
}
2968
2976
2969
2977
fn internal_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , MsgHandleErrInternal > {
2970
- let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2971
- let channel_state = & mut * channel_state_lock;
2978
+ let chan_restoration_res = {
2979
+ let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2980
+ let channel_state = & mut * channel_state_lock;
2972
2981
2973
- match channel_state. by_id . entry ( msg. channel_id ) {
2974
- hash_map:: Entry :: Occupied ( mut chan) => {
2975
- if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
2976
- return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
2977
- }
2978
- // Currently, we expect all holding cell update_adds to be dropped on peer
2979
- // disconnect, so Channel's reestablish will never hand us any holding cell
2980
- // freed HTLCs to fail backwards. If in the future we no longer drop pending
2981
- // add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
2982
- let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, mut order, shutdown) =
2983
- try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
2984
- if let Some ( monitor_update) = monitor_update_opt {
2985
- if let Err ( e) = self . chain_monitor . update_channel ( chan. get ( ) . get_funding_txo ( ) . unwrap ( ) , monitor_update) {
2986
- // channel_reestablish doesn't guarantee the order it returns is sensical
2987
- // for the messages it returns, but if we're setting what messages to
2988
- // re-transmit on monitor update success, we need to make sure it is sane.
2989
- if revoke_and_ack. is_none ( ) {
2990
- order = RAACommitmentOrder :: CommitmentFirst ;
2991
- }
2992
- if commitment_update. is_none ( ) {
2993
- order = RAACommitmentOrder :: RevokeAndACKFirst ;
2994
- }
2995
- return_monitor_err ! ( self , e, channel_state, chan, order, revoke_and_ack. is_some( ) , commitment_update. is_some( ) ) ;
2996
- //TODO: Resend the funding_locked if needed once we get the monitor running again
2997
- }
2998
- }
2999
- if let Some ( msg) = funding_locked {
3000
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendFundingLocked {
3001
- node_id : counterparty_node_id. clone ( ) ,
3002
- msg
3003
- } ) ;
3004
- }
3005
- macro_rules! send_raa { ( ) => {
3006
- if let Some ( msg) = revoke_and_ack {
3007
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
3008
- node_id: counterparty_node_id. clone( ) ,
3009
- msg
3010
- } ) ;
2982
+ match channel_state. by_id . entry ( msg. channel_id ) {
2983
+ hash_map:: Entry :: Occupied ( mut chan) => {
2984
+ if chan. get ( ) . get_counterparty_node_id ( ) != * counterparty_node_id {
2985
+ return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a message for a channel from the wrong node!" . to_owned ( ) , msg. channel_id ) ) ;
3011
2986
}
3012
- } }
3013
- macro_rules! send_cu { ( ) => {
3014
- if let Some ( updates) = commitment_update {
3015
- channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
2987
+ // Currently, we expect all holding cell update_adds to be dropped on peer
2988
+ // disconnect, so Channel's reestablish will never hand us any holding cell
2989
+ // freed HTLCs to fail backwards. If in the future we no longer drop pending
2990
+ // add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
2991
+ let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, shutdown) =
2992
+ try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
2993
+ if let Some ( msg) = shutdown {
2994
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
3016
2995
node_id : counterparty_node_id. clone ( ) ,
3017
- updates
2996
+ msg ,
3018
2997
} ) ;
3019
2998
}
3020
- } }
3021
- match order {
3022
- RAACommitmentOrder :: RevokeAndACKFirst => {
3023
- send_raa ! ( ) ;
3024
- send_cu ! ( ) ;
3025
- } ,
3026
- RAACommitmentOrder :: CommitmentFirst => {
3027
- send_cu ! ( ) ;
3028
- send_raa ! ( ) ;
3029
- } ,
3030
- }
3031
- if let Some ( msg) = shutdown {
3032
- channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
3033
- node_id : counterparty_node_id. clone ( ) ,
3034
- msg,
3035
- } ) ;
3036
- }
3037
- Ok ( ( ) )
3038
- } ,
3039
- hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
3040
- }
2999
+ 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)
3000
+ } ,
3001
+ hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
3002
+ }
3003
+ } ;
3004
+ post_handle_chan_restoration ! ( self , chan_restoration_res, Vec :: new( ) , Vec :: new( ) ) ;
3005
+ Ok ( ( ) )
3041
3006
}
3042
3007
3043
3008
/// Begin Update fee process. Allowed only on an outbound channel.
0 commit comments