@@ -817,30 +817,28 @@ macro_rules! maybe_break_monitor_err {
817
817
macro_rules! handle_chan_restoration_locked {
818
818
( $self: expr, $channel_lock: expr, $channel_state: expr, $channel_entry: expr,
819
819
$raa: expr, $commitment_update: expr, $order: expr,
820
- $pending_forwards: expr, $pending_failures: expr, $funding_broadcastable: expr, $funding_locked: expr) => { {
821
- let mut htlc_forwards = Vec :: new( ) ;
822
- let mut htlc_failures = Vec :: new( ) ;
823
- let mut pending_events = Vec :: new( ) ;
820
+ $pending_forwards: expr, $funding_broadcastable: expr, $funding_locked: expr) => { {
821
+ let mut htlc_forwards = None ;
822
+ let counterparty_node_id = $channel_entry. get( ) . get_counterparty_node_id( ) ;
824
823
825
824
{
826
825
if !$pending_forwards. is_empty( ) {
827
- htlc_forwards. push ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
826
+ htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . expect( "We can't have pending forwards before funding confirmation" ) ,
828
827
$channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , $pending_forwards) ) ;
829
828
}
830
- htlc_failures. append( & mut $pending_failures) ;
831
829
832
830
macro_rules! handle_cs { ( ) => {
833
831
if let Some ( update) = $commitment_update {
834
832
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
835
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
833
+ node_id: counterparty_node_id ,
836
834
updates: update,
837
835
} ) ;
838
836
}
839
837
} }
840
838
macro_rules! handle_raa { ( ) => {
841
839
if let Some ( revoke_and_ack) = $raa {
842
840
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
843
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
841
+ node_id: counterparty_node_id ,
844
842
msg: revoke_and_ack,
845
843
} ) ;
846
844
}
@@ -860,31 +858,29 @@ macro_rules! handle_chan_restoration_locked {
860
858
}
861
859
if let Some ( msg) = $funding_locked {
862
860
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendFundingLocked {
863
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
861
+ node_id: counterparty_node_id ,
864
862
msg,
865
863
} ) ;
866
864
if let Some ( announcement_sigs) = $self. get_announcement_sigs( $channel_entry. get( ) ) {
867
865
$channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
868
- node_id: $channel_entry . get ( ) . get_counterparty_node_id ( ) ,
866
+ node_id: counterparty_node_id ,
869
867
msg: announcement_sigs,
870
868
} ) ;
871
869
}
872
870
$channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , $channel_entry. get( ) . channel_id( ) ) ;
873
871
}
874
872
}
875
- ( htlc_forwards, htlc_failures , pending_events )
873
+ htlc_forwards
876
874
} }
877
875
}
878
876
879
877
macro_rules! post_handle_chan_restoration {
880
878
( $self: expr, $locked_res: expr) => { {
881
- let ( mut htlc_forwards, mut htlc_failures, mut pending_events) = $locked_res;
882
- $self. pending_events. lock( ) . unwrap( ) . append( & mut pending_events) ;
879
+ let htlc_forwards = $locked_res;
883
880
884
- for failure in htlc_failures . drain ( .. ) {
885
- $self. fail_htlc_backwards_internal ( $self . channel_state . lock ( ) . unwrap ( ) , failure . 0 , & failure . 1 , failure . 2 ) ;
881
+ if let Some ( forwards ) = htlc_forwards {
882
+ $self. forward_htlcs ( & mut [ forwards ] [ .. ] ) ;
886
883
}
887
- $self. forward_htlcs( & mut htlc_forwards[ ..] ) ;
888
884
} }
889
885
}
890
886
@@ -2510,7 +2506,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2510
2506
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2511
2507
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2512
2508
2513
- let chan_restoration_res = {
2509
+ let ( mut pending_failures , chan_restoration_res) = {
2514
2510
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2515
2511
let channel_state = & mut * channel_lock;
2516
2512
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2521,10 +2517,13 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2521
2517
return ;
2522
2518
}
2523
2519
2524
- let ( raa, commitment_update, order, pending_forwards, mut pending_failures, funding_broadcastable, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2525
- handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, pending_failures , funding_broadcastable, funding_locked)
2520
+ let ( raa, commitment_update, order, pending_forwards, pending_failures, funding_broadcastable, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2521
+ ( pending_failures , handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, pending_forwards, funding_broadcastable, funding_locked) )
2526
2522
} ;
2527
2523
post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2524
+ for failure in pending_failures. drain ( ..) {
2525
+ self . fail_htlc_backwards_internal ( self . channel_state . lock ( ) . unwrap ( ) , failure. 0 , & failure. 1 , failure. 2 ) ;
2526
+ }
2528
2527
}
2529
2528
2530
2529
fn internal_open_channel ( & self , counterparty_node_id : & PublicKey , their_features : InitFeatures , msg : & msgs:: OpenChannel ) -> Result < ( ) , MsgHandleErrInternal > {
0 commit comments