@@ -1517,76 +1517,11 @@ macro_rules! emit_channel_ready_event {
15171517 }
15181518}
15191519
1520- macro_rules! handle_chan_restoration_locked {
1521- ( $self: ident, $channel_state: expr, $channel_entry: expr,
1522- $raa: expr, $commitment_update: expr, $order: expr,
1523- $pending_forwards: expr, $funding_broadcastable: expr, $channel_ready: expr, $announcement_sigs: expr) => { {
1524- let mut htlc_forwards = None ;
1525-
1526- let counterparty_node_id = $channel_entry. get( ) . get_counterparty_node_id( ) ;
1527- let res = loop {
1528- let forwards: Vec <( PendingHTLCInfo , u64 ) > = $pending_forwards; // Force type-checking to resolve
1529- if !forwards. is_empty( ) {
1530- htlc_forwards = Some ( ( $channel_entry. get( ) . get_short_channel_id( ) . unwrap_or( $channel_entry. get( ) . outbound_scid_alias( ) ) ,
1531- $channel_entry. get( ) . get_funding_txo( ) . unwrap( ) , forwards) ) ;
1532- }
1533-
1534- if let Some ( msg) = $channel_ready {
1535- send_channel_ready!( $self, $channel_state. pending_msg_events, $channel_entry. get( ) , msg) ;
1536- }
1537- if let Some ( msg) = $announcement_sigs {
1538- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendAnnouncementSignatures {
1539- node_id: counterparty_node_id,
1540- msg,
1541- } ) ;
1542- }
1543-
1544- emit_channel_ready_event!( $self, $channel_entry. get_mut( ) ) ;
1545-
1546- macro_rules! handle_cs { ( ) => {
1547- if let Some ( update) = $commitment_update {
1548- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
1549- node_id: counterparty_node_id,
1550- updates: update,
1551- } ) ;
1552- }
1553- } }
1554- macro_rules! handle_raa { ( ) => {
1555- if let Some ( revoke_and_ack) = $raa {
1556- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
1557- node_id: counterparty_node_id,
1558- msg: revoke_and_ack,
1559- } ) ;
1560- }
1561- } }
1562- match $order {
1563- RAACommitmentOrder :: CommitmentFirst => {
1564- handle_cs!( ) ;
1565- handle_raa!( ) ;
1566- } ,
1567- RAACommitmentOrder :: RevokeAndACKFirst => {
1568- handle_raa!( ) ;
1569- handle_cs!( ) ;
1570- } ,
1571- }
1572-
1573- let funding_broadcastable: Option <Transaction > = $funding_broadcastable; // Force type-checking to resolve
1574- if let Some ( tx) = funding_broadcastable {
1575- log_info!( $self. logger, "Broadcasting funding transaction with txid {}" , tx. txid( ) ) ;
1576- $self. tx_broadcaster. broadcast_transaction( & tx) ;
1577- }
1578- break Ok ( ( ) ) ;
1579- } ;
1580-
1581- ( htlc_forwards, res, counterparty_node_id)
1582- } }
1583- }
1584-
15851520macro_rules! post_handle_chan_restoration {
1586- ( $self: ident, $locked_res: expr) => { {
1587- let ( htlc_forwards, res, counterparty_node_id ) = $locked_res;
1521+ ( $self: ident, $locked_res: expr, $counterparty_node_id : expr ) => { {
1522+ let ( htlc_forwards, res) = $locked_res;
15881523
1589- let _ = handle_error!( $self, res, counterparty_node_id) ;
1524+ let _ = handle_error!( $self, res, * $ counterparty_node_id) ;
15901525
15911526 if let Some ( forwards) = htlc_forwards {
15921527 $self. forward_htlcs( & mut [ forwards] [ ..] ) ;
@@ -4439,6 +4374,72 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44394374 self . our_network_pubkey . clone ( )
44404375 }
44414376
4377+ /// Handles a channel reentering a functional state, either due to reconnect or a monitor
4378+ /// update completion.
4379+ fn handle_channel_resumption ( & self , pending_msg_events : & mut Vec < MessageSendEvent > ,
4380+ channel : & mut Channel < <K :: Target as KeysInterface >:: Signer > , raa : Option < msgs:: RevokeAndACK > ,
4381+ commitment_update : Option < msgs:: CommitmentUpdate > , order : RAACommitmentOrder ,
4382+ pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > , funding_broadcastable : Option < Transaction > ,
4383+ channel_ready : Option < msgs:: ChannelReady > , announcement_sigs : Option < msgs:: AnnouncementSignatures > )
4384+ -> ( Option < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > , Result < ( ) , MsgHandleErrInternal > ) {
4385+ let mut htlc_forwards = None ;
4386+
4387+ let counterparty_node_id = channel. get_counterparty_node_id ( ) ;
4388+ let res = loop {
4389+ if !pending_forwards. is_empty ( ) {
4390+ htlc_forwards = Some ( ( channel. get_short_channel_id ( ) . unwrap_or ( channel. outbound_scid_alias ( ) ) ,
4391+ channel. get_funding_txo ( ) . unwrap ( ) , pending_forwards) ) ;
4392+ }
4393+
4394+ if let Some ( msg) = channel_ready {
4395+ send_channel_ready ! ( self , pending_msg_events, channel, msg) ;
4396+ }
4397+ if let Some ( msg) = announcement_sigs {
4398+ pending_msg_events. push ( events:: MessageSendEvent :: SendAnnouncementSignatures {
4399+ node_id : counterparty_node_id,
4400+ msg,
4401+ } ) ;
4402+ }
4403+
4404+ emit_channel_ready_event ! ( self , channel) ;
4405+
4406+ macro_rules! handle_cs { ( ) => {
4407+ if let Some ( update) = commitment_update {
4408+ pending_msg_events. push( events:: MessageSendEvent :: UpdateHTLCs {
4409+ node_id: counterparty_node_id,
4410+ updates: update,
4411+ } ) ;
4412+ }
4413+ } }
4414+ macro_rules! handle_raa { ( ) => {
4415+ if let Some ( revoke_and_ack) = raa {
4416+ pending_msg_events. push( events:: MessageSendEvent :: SendRevokeAndACK {
4417+ node_id: counterparty_node_id,
4418+ msg: revoke_and_ack,
4419+ } ) ;
4420+ }
4421+ } }
4422+ match order {
4423+ RAACommitmentOrder :: CommitmentFirst => {
4424+ handle_cs ! ( ) ;
4425+ handle_raa ! ( ) ;
4426+ } ,
4427+ RAACommitmentOrder :: RevokeAndACKFirst => {
4428+ handle_raa ! ( ) ;
4429+ handle_cs ! ( ) ;
4430+ } ,
4431+ }
4432+
4433+ if let Some ( tx) = funding_broadcastable {
4434+ log_info ! ( self . logger, "Broadcasting funding transaction with txid {}" , tx. txid( ) ) ;
4435+ self . tx_broadcaster . broadcast_transaction ( & tx) ;
4436+ }
4437+ break Ok ( ( ) ) ;
4438+ } ;
4439+
4440+ ( htlc_forwards, res)
4441+ }
4442+
44424443 fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
44434444 let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
44444445
@@ -4469,14 +4470,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44694470 } )
44704471 } else { None }
44714472 } else { None } ;
4472- chan_restoration_res = handle_chan_restoration_locked ! ( self , channel_state, channel, updates. raa, updates. commitment_update, updates. order, updates. accepted_htlcs, updates. funding_broadcastable, updates. channel_ready, updates. announcement_sigs) ;
4473+ chan_restoration_res = self . handle_channel_resumption ( & mut channel_state. pending_msg_events , channel. get_mut ( ) , updates. raa , updates. commitment_update , updates. order , updates. accepted_htlcs , updates. funding_broadcastable , updates. channel_ready , updates. announcement_sigs ) ;
44734474 if let Some ( upd) = channel_update {
44744475 channel_state. pending_msg_events . push ( upd) ;
44754476 }
44764477
44774478 ( updates. failed_htlcs , updates. finalized_claimed_htlcs , counterparty_node_id)
44784479 } ;
4479- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
4480+ post_handle_chan_restoration ! ( self , chan_restoration_res, & counterparty_node_id ) ;
44804481 self . finalize_claims ( finalized_claims) ;
44814482 for failure in pending_failures. drain ( ..) {
44824483 let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id : funding_txo. to_channel_id ( ) } ;
@@ -5262,8 +5263,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
52625263 }
52635264 }
52645265 let need_lnd_workaround = chan. get_mut ( ) . workaround_lnd_bug_4006 . take ( ) ;
5265- chan_restoration_res = handle_chan_restoration_locked ! (
5266- self , channel_state, chan, responses. raa, responses. commitment_update, responses. order,
5266+ chan_restoration_res = self . handle_channel_resumption (
5267+ & mut channel_state. pending_msg_events , chan. get_mut ( ) , responses. raa , responses. commitment_update , responses. order ,
52675268 Vec :: new ( ) , None , responses. channel_ready , responses. announcement_sigs ) ;
52685269 if let Some ( upd) = channel_update {
52695270 channel_state. pending_msg_events . push ( upd) ;
@@ -5273,7 +5274,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
52735274 hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
52745275 }
52755276 } ;
5276- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
5277+ post_handle_chan_restoration ! ( self , chan_restoration_res, counterparty_node_id ) ;
52775278
52785279 if let Some ( channel_ready_msg) = need_lnd_workaround {
52795280 self . internal_channel_ready ( counterparty_node_id, & channel_ready_msg) ?;
0 commit comments