@@ -747,30 +747,29 @@ macro_rules! maybe_break_monitor_err {
747
747
macro_rules! handle_chan_restoration_locked {
748
748
( $self: expr, $channel_lock: expr, $channel_state: expr, $channel_entry: expr,
749
749
$raa: expr, $commitment_update: expr, $order: expr,
750
- $pending_forwards: expr, $pending_failures : expr , $ broadcast_safe: expr, $funding_locked: expr) => { {
751
- let mut htlc_forwards = Vec :: new ( ) ;
752
- let mut htlc_failures = Vec :: new ( ) ;
753
- let mut pending_events = Vec :: new ( ) ;
750
+ $pending_forwards: expr, $broadcast_safe: expr, $funding_locked: expr) => { {
751
+ let mut htlc_forwards = None ;
752
+ let mut funding_broadcast_safe = None ;
753
+ let counterparty_node_id = $channel_entry . get ( ) . get_counterparty_node_id ( ) ;
754
754
755
755
{
756
756
if !$pending_forwards. is_empty( ) {
757
- htlc_forwards. push ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
757
+ htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
758
758
$channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
759
759
}
760
- htlc_failures. append( & mut $pending_failures) ;
761
760
762
761
macro_rules! handle_cs { ( ) => {
763
762
if let Some ( update) = $commitment_update {
764
763
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
765
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
764
+ node_id: counterparty_node_id ,
766
765
updates: update,
767
766
} ) ;
768
767
}
769
768
} }
770
769
macro_rules! handle_raa { ( ) => {
771
770
if let Some ( revoke_and_ack) = $raa {
772
771
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
773
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
772
+ node_id: counterparty_node_id ,
774
773
msg: revoke_and_ack,
775
774
} ) ;
776
775
}
@@ -786,38 +785,43 @@ macro_rules! handle_chan_restoration_locked {
786
785
} ,
787
786
}
788
787
if $broadcast_safe {
789
- pending_events . push ( events:: Event :: FundingBroadcastSafe {
788
+ funding_broadcast_safe = Some ( events:: Event :: FundingBroadcastSafe {
790
789
funding_txo: $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) ,
791
790
user_channel_id: $channel_entry. get( ) . get_user_id( ) ,
792
791
} ) ;
793
792
}
794
793
if let Some ( msg) = $funding_locked {
795
794
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
796
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
795
+ node_id: counterparty_node_id ,
797
796
msg,
798
797
} ) ;
799
798
if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
800
799
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
801
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
800
+ node_id: counterparty_node_id ,
802
801
msg: announcement_sigs,
803
802
} ) ;
804
803
}
805
804
$channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , $channel_entry. get( ) . channel_id( ) ) ;
806
805
}
807
806
}
808
- ( htlc_forwards, htlc_failures , pending_events )
807
+ ( htlc_forwards, funding_broadcast_safe )
809
808
} }
810
809
}
811
810
812
811
macro_rules! post_handle_chan_restoration {
813
- ( $self: expr, $locked_res: expr) => { {
814
- let ( mut htlc_forwards, mut htlc_failures, mut pending_events) = $locked_res;
815
- $self. pending_events. lock( ) . unwrap( ) . append( & mut pending_events) ;
812
+ ( $self: expr, $locked_res: expr, $pending_failures: expr) => { {
813
+ let ( htlc_forwards, funding_broadcast_safe) = $locked_res;
816
814
817
- for failure in htlc_failures. drain( ..) {
815
+ if let Some ( ev) = funding_broadcast_safe {
816
+ $self. pending_events. lock( ) . unwrap( ) . push( ev) ;
817
+ }
818
+
819
+ for failure in $pending_failures. drain( ..) {
818
820
$self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
819
821
}
820
- $self. forward_htlcs( & mut htlc_forwards[ ..] ) ;
822
+ if let Some ( forwards) = htlc_forwards {
823
+ $self. forward_htlcs( & mut [ forwards] [ ..] ) ;
824
+ }
821
825
} }
822
826
}
823
827
@@ -2339,7 +2343,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2339
2343
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2340
2344
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2341
2345
2342
- let chan_restoration_res = {
2346
+ let ( mut pending_failures , chan_restoration_res) = {
2343
2347
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2344
2348
let channel_state = & mut * channel_lock;
2345
2349
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2350,10 +2354,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2350
2354
return ;
2351
2355
}
2352
2356
2353
- let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2354
- handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, pending_failures , needs_broadcast_safe, funding_locked)
2357
+ let ( raa, commitment_update, order, pending_forwards, pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2358
+ ( pending_failures , handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, needs_broadcast_safe, funding_locked) )
2355
2359
} ;
2356
- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2360
+ post_handle_chan_restoration ! ( self , chan_restoration_res, pending_failures ) ;
2357
2361
}
2358
2362
2359
2363
fn internal_open_channel ( & self , counterparty_node_id : & PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments