@@ -712,30 +712,29 @@ macro_rules! maybe_break_monitor_err {
712
712
macro_rules! handle_chan_restoration_locked {
713
713
( $self: expr, $channel_lock: expr, $channel_state: expr, $channel_entry: expr,
714
714
$raa: expr, $commitment_update: expr, $order: expr,
715
- $pending_forwards: expr, $pending_failures : expr , $ broadcast_safe: expr, $funding_locked: expr) => { {
716
- let mut htlc_forwards = Vec :: new ( ) ;
717
- let mut htlc_failures = Vec :: new ( ) ;
718
- let mut pending_events = Vec :: new ( ) ;
715
+ $pending_forwards: expr, $broadcast_safe: expr, $funding_locked: expr) => { {
716
+ let mut htlc_forwards = None ;
717
+ let mut funding_broadcast_safe = None ;
718
+ let counterparty_node_id = $channel_entry . get ( ) . get_counterparty_node_id ( ) ;
719
719
720
720
{
721
721
if !$pending_forwards. is_empty( ) {
722
- htlc_forwards. push ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
722
+ htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
723
723
$channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
724
724
}
725
- htlc_failures. append( & mut $pending_failures) ;
726
725
727
726
macro_rules! handle_cs { ( ) => {
728
727
if let Some ( update) = $commitment_update {
729
728
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
730
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
729
+ node_id: counterparty_node_id ,
731
730
updates: update,
732
731
} ) ;
733
732
}
734
733
} }
735
734
macro_rules! handle_raa { ( ) => {
736
735
if let Some ( revoke_and_ack) = $raa {
737
736
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
738
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
737
+ node_id: counterparty_node_id ,
739
738
msg: revoke_and_ack,
740
739
} ) ;
741
740
}
@@ -751,38 +750,43 @@ macro_rules! handle_chan_restoration_locked {
751
750
} ,
752
751
}
753
752
if $broadcast_safe {
754
- pending_events . push ( events:: Event :: FundingBroadcastSafe {
753
+ funding_broadcast_safe = Some ( events:: Event :: FundingBroadcastSafe {
755
754
funding_txo: $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) ,
756
755
user_channel_id: $channel_entry. get( ) . get_user_id( ) ,
757
756
} ) ;
758
757
}
759
758
if let Some ( msg) = $funding_locked {
760
759
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
761
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
760
+ node_id: counterparty_node_id ,
762
761
msg,
763
762
} ) ;
764
763
if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
765
764
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
766
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
765
+ node_id: counterparty_node_id ,
767
766
msg: announcement_sigs,
768
767
} ) ;
769
768
}
770
769
$channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , $channel_entry. get( ) . channel_id( ) ) ;
771
770
}
772
771
}
773
- ( htlc_forwards, htlc_failures , pending_events )
772
+ ( htlc_forwards, funding_broadcast_safe )
774
773
} }
775
774
}
776
775
777
776
macro_rules! post_handle_chan_restoration {
778
- ( $self: expr, $locked_res: expr) => { {
779
- let ( mut htlc_forwards, mut htlc_failures, mut pending_events) = $locked_res;
780
- $self. pending_events. lock( ) . unwrap( ) . append( & mut pending_events) ;
777
+ ( $self: expr, $locked_res: expr, $pending_failures: expr) => { {
778
+ let ( htlc_forwards, funding_broadcast_safe) = $locked_res;
781
779
782
- for failure in htlc_failures. drain( ..) {
780
+ if let Some ( ev) = funding_broadcast_safe {
781
+ $self. pending_events. lock( ) . unwrap( ) . push( ev) ;
782
+ }
783
+
784
+ for failure in $pending_failures. drain( ..) {
783
785
$self. fail_htlc_backwards_internal( $self. channel_state. lock( ) . unwrap( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
784
786
}
785
- $self. forward_htlcs( & mut htlc_forwards[ ..] ) ;
787
+ if let Some ( forwards) = htlc_forwards {
788
+ $self. forward_htlcs( & mut [ forwards] [ ..] ) ;
789
+ }
786
790
} }
787
791
}
788
792
@@ -2287,7 +2291,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2287
2291
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2288
2292
let _consistency_lock = self . total_consistency_lock . read ( ) . unwrap ( ) ;
2289
2293
2290
- let chan_restoration_res = {
2294
+ let ( mut pending_failures , chan_restoration_res) = {
2291
2295
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2292
2296
let channel_state = & mut * channel_lock;
2293
2297
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2298,10 +2302,10 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
2298
2302
return ;
2299
2303
}
2300
2304
2301
- let ( raa, commitment_update, order, pending_forwards, mut pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2302
- handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, pending_failures , needs_broadcast_safe, funding_locked)
2305
+ let ( raa, commitment_update, order, pending_forwards, pending_failures, needs_broadcast_safe, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2306
+ ( pending_failures , handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, needs_broadcast_safe, funding_locked) )
2303
2307
} ;
2304
- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2308
+ post_handle_chan_restoration ! ( self , chan_restoration_res, pending_failures ) ;
2305
2309
}
2306
2310
2307
2311
fn internal_open_channel ( & self , counterparty_node_id : & PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments