@@ -1517,76 +1517,11 @@ macro_rules! emit_channel_ready_event {
1517
1517
}
1518
1518
}
1519
1519
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
-
1585
1520
macro_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;
1588
1523
1589
- let _ = handle_error!( $self, res, counterparty_node_id) ;
1524
+ let _ = handle_error!( $self, res, * $ counterparty_node_id) ;
1590
1525
1591
1526
if let Some ( forwards) = htlc_forwards {
1592
1527
$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
4439
4374
self . our_network_pubkey . clone ( )
4440
4375
}
4441
4376
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
+
4442
4443
fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
4443
4444
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
4444
4445
@@ -4469,14 +4470,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4469
4470
} )
4470
4471
} else { None }
4471
4472
} 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 ) ;
4473
4474
if let Some ( upd) = channel_update {
4474
4475
channel_state. pending_msg_events . push ( upd) ;
4475
4476
}
4476
4477
4477
4478
( updates. failed_htlcs , updates. finalized_claimed_htlcs , counterparty_node_id)
4478
4479
} ;
4479
- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
4480
+ post_handle_chan_restoration ! ( self , chan_restoration_res, & counterparty_node_id ) ;
4480
4481
self . finalize_claims ( finalized_claims) ;
4481
4482
for failure in pending_failures. drain ( ..) {
4482
4483
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
5262
5263
}
5263
5264
}
5264
5265
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 ,
5267
5268
Vec :: new ( ) , None , responses. channel_ready , responses. announcement_sigs ) ;
5268
5269
if let Some ( upd) = channel_update {
5269
5270
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
5273
5274
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
5274
5275
}
5275
5276
} ;
5276
- post_handle_chan_restoration ! ( self , chan_restoration_res) ;
5277
+ post_handle_chan_restoration ! ( self , chan_restoration_res, counterparty_node_id ) ;
5277
5278
5278
5279
if let Some ( channel_ready_msg) = need_lnd_workaround {
5279
5280
self . internal_channel_ready ( counterparty_node_id, & channel_ready_msg) ?;
0 commit comments