@@ -788,30 +788,29 @@ macro_rules! maybe_break_monitor_err {
788
788
macro_rules! handle_chan_restoration_locked {
789
789
( $self: expr, $channel_lock: expr, $channel_state: expr, $channel_entry: expr,
790
790
$raa: expr, $commitment_update: expr, $order: expr,
791
- $pending_forwards: expr, $pending_failures : expr , $ broadcast_safe: expr, $funding_locked: expr) => { {
792
- let mut htlc_forwards = Vec :: new ( ) ;
793
- let mut htlc_failures = Vec :: new ( ) ;
794
- let mut pending_events = Vec :: new ( ) ;
791
+ $pending_forwards: expr, $broadcast_safe: expr, $funding_locked: expr) => { {
792
+ let mut htlc_forwards = None ;
793
+ let mut funding_broadcast_safe = None ;
794
+ let counterparty_node_id = $channel_entry . get ( ) . get_counterparty_node_id ( ) ;
795
795
796
796
{
797
797
if !$pending_forwards. is_empty( ) {
798
- htlc_forwards. push ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
798
+ htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
799
799
$channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
800
800
}
801
- htlc_failures. append( & mut $pending_failures) ;
802
801
803
802
macro_rules! handle_cs { ( ) => {
804
803
if let Some ( update) = $commitment_update {
805
804
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
806
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
805
+ node_id: counterparty_node_id ,
807
806
updates: update,
808
807
} ) ;
809
808
}
810
809
} }
811
810
macro_rules! handle_raa { ( ) => {
812
811
if let Some ( revoke_and_ack) = $raa {
813
812
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
814
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
813
+ node_id: counterparty_node_id ,
815
814
msg: revoke_and_ack,
816
815
} ) ;
817
816
}
@@ -827,38 +826,40 @@ macro_rules! handle_chan_restoration_locked {
827
826
} ,
828
827
}
829
828
if $broadcast_safe {
830
- pending_events . push ( events:: Event :: FundingBroadcastSafe {
829
+ funding_broadcast_safe = Some ( events:: Event :: FundingBroadcastSafe {
831
830
funding_txo: $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) ,
832
831
user_channel_id: $channel_entry. get( ) . get_user_id( ) ,
833
832
} ) ;
834
833
}
835
834
if let Some ( msg) = $funding_locked {
836
835
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
837
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
836
+ node_id: counterparty_node_id ,
838
837
msg,
839
838
} ) ;
840
839
if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
841
840
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
842
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
841
+ node_id: counterparty_node_id ,
843
842
msg: announcement_sigs,
844
843
} ) ;
845
844
}
846
845
$channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , $channel_entry. get( ) . channel_id( ) ) ;
847
846
}
848
847
}
849
- ( htlc_forwards, htlc_failures , pending_events )
848
+ ( htlc_forwards, funding_broadcast_safe )
850
849
} }
851
850
}
852
851
853
852
macro_rules! post_handle_chan_restoration {
854
853
( $self: expr, $locked_res: expr) => { {
855
- let ( mut htlc_forwards, mut htlc_failures, mut pending_events) = $locked_res;
856
- $self. pending_events. lock( ) . unwrap( ) . append( & mut pending_events) ;
854
+ let ( htlc_forwards, funding_broadcast_safe) = $locked_res;
857
855
858
- for failure in htlc_failures. drain( ..) {
859
- $self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
856
+ if let Some ( ev) = funding_broadcast_safe {
857
+ $self. pending_events. lock( ) . unwrap( ) . push( ev) ;
858
+ }
859
+
860
+ if let Some ( forwards) = htlc_forwards {
861
+ $self. forward_htlcs( & mut [ forwards] [ ..] ) ;
860
862
}
861
- $self. forward_htlcs( & mut htlc_forwards[ ..] ) ;
862
863
} }
863
864
}
864
865
@@ -2413,7 +2414,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2413
2414
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2414
2415
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2415
2416
2416
- let chan_restoration_res = {
2417
+ let ( mut pending_failures , chan_restoration_res) = {
2417
2418
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2418
2419
let channel_state = & mut * channel_lock;
2419
2420
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2424,10 +2425,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2424
2425
return ;
2425
2426
}
2426
2427
2427
- let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2428
- handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, pending_failures , needs_broadcast_safe, funding_locked)
2428
+ let ( raa, commitment_update, order, pending_forwards, pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2429
+ ( pending_failures , handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, needs_broadcast_safe, funding_locked) )
2429
2430
} ;
2430
2431
post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2432
+ for failure in pending_failures. drain ( ..) {
2433
+ self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
2434
+ }
2431
2435
}
2432
2436
2433
2437
fn internal_open_channel ( & self , counterparty_node_id : & PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments