@@ -445,6 +445,7 @@ enum BackgroundEvent {
445
445
ClosingMonitorUpdate ( ( OutPoint , ChannelMonitorUpdate ) ) ,
446
446
}
447
447
448
+ #[ derive( Debug ) ]
448
449
pub ( crate ) enum MonitorUpdateCompletionAction {
449
450
/// Indicates that a payment ultimately destined for us was claimed and we should emit an
450
451
/// [`events::Event::PaymentClaimed`] to the user if we haven't yet generated such an event for
@@ -1627,9 +1628,20 @@ macro_rules! handle_new_monitor_update {
1627
1628
} )
1628
1629
} else { None }
1629
1630
} else { None } ;
1630
- let htlc_forwards = $self. handle_channel_resumption( & mut $msg_queue,
1631
- $chan, updates. raa, updates. commitment_update, updates. order, updates. accepted_htlcs,
1632
- updates. funding_broadcastable, updates. channel_ready, updates. announcement_sigs) ;
1631
+
1632
+ let htlc_forwards = {
1633
+ let per_peer_state = $self. per_peer_state. read( ) . unwrap( ) ;
1634
+ let mut peer_state = per_peer_state. get( & counterparty_node_id)
1635
+ . expect( "XXX: This may be reachable today, I believe, but once we move the channel storage to per_peer_state it won't be." )
1636
+ . lock( ) . unwrap( ) ;
1637
+
1638
+ let update_actions = peer_state. monitor_update_blocked_actions
1639
+ . remove( & $chan. channel_id( ) ) . unwrap_or( Vec :: new( ) ) ;
1640
+ $self. handle_channel_resumption( & mut $msg_queue, $chan,
1641
+ update_actions, updates. raa, updates. commitment_update, updates. order,
1642
+ updates. accepted_htlcs, updates. funding_broadcastable,
1643
+ updates. channel_ready, updates. announcement_sigs)
1644
+ } ;
1633
1645
if let Some ( upd) = channel_update {
1634
1646
$msg_queue. push( upd) ;
1635
1647
}
@@ -4510,11 +4522,20 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4510
4522
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
4511
4523
/// update completion.
4512
4524
fn handle_channel_resumption ( & self , pending_msg_events : & mut Vec < MessageSendEvent > ,
4513
- channel : & mut Channel < <K :: Target as KeysInterface >:: Signer > , raa : Option < msgs:: RevokeAndACK > ,
4525
+ channel : & mut Channel < <K :: Target as KeysInterface >:: Signer > ,
4526
+ actions : Vec < MonitorUpdateCompletionAction > , raa : Option < msgs:: RevokeAndACK > ,
4514
4527
commitment_update : Option < msgs:: CommitmentUpdate > , order : RAACommitmentOrder ,
4515
4528
pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > , funding_broadcastable : Option < Transaction > ,
4516
4529
channel_ready : Option < msgs:: ChannelReady > , announcement_sigs : Option < msgs:: AnnouncementSignatures > )
4517
4530
-> Option < ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) > {
4531
+ log_trace ! ( self . logger, "Handling channel resumption for channel {} with {} actions, {} RAA, {} commitment update, {} pending forwards, {}broadcasting funding, {} channel ready, {} announcement" ,
4532
+ log_bytes!( channel. channel_id( ) ) , actions. len( ) ,
4533
+ if raa. is_some( ) { "an" } else { "no" } ,
4534
+ if commitment_update. is_some( ) { "a" } else { "no" } , pending_forwards. len( ) ,
4535
+ if funding_broadcastable. is_some( ) { "" } else { "not " } ,
4536
+ if channel_ready. is_some( ) { "sending" } else { "without" } ,
4537
+ if announcement_sigs. is_some( ) { "sending" } else { "without" } ) ;
4538
+
4518
4539
let mut htlc_forwards = None ;
4519
4540
4520
4541
let counterparty_node_id = channel. get_counterparty_node_id ( ) ;
@@ -4567,6 +4588,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4567
4588
self . tx_broadcaster . broadcast_transaction ( & tx) ;
4568
4589
}
4569
4590
4591
+ self . handle_monitor_update_completion_actions ( actions) ;
4592
+
4570
4593
htlc_forwards
4571
4594
}
4572
4595
@@ -4581,11 +4604,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4581
4604
hash_map:: Entry :: Occupied ( chan) => chan,
4582
4605
hash_map:: Entry :: Vacant ( _) => return ,
4583
4606
} ;
4607
+ log_trace ! ( self . logger, "ChannelMonitor updated to {}. Current highest is {}" ,
4608
+ highest_applied_update_id, channel. get( ) . get_latest_monitor_update_id( ) ) ;
4584
4609
if !channel. get ( ) . is_awaiting_monitor_update ( ) || channel. get ( ) . get_latest_monitor_update_id ( ) != highest_applied_update_id {
4585
4610
return ;
4586
4611
}
4587
4612
4588
4613
let counterparty_node_id = channel. get ( ) . get_counterparty_node_id ( ) ;
4614
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
4615
+ let mut peer_state = match per_peer_state. get ( & counterparty_node_id) {
4616
+ Some ( peer_state) => peer_state. lock ( ) . unwrap ( ) ,
4617
+ None => {
4618
+ debug_assert ! ( false , "XXX: This may be reachable today, I believe, but once we move the channel storage to per_peer_state it won't be." ) ;
4619
+ return ;
4620
+ }
4621
+ } ;
4622
+
4589
4623
let updates = channel. get_mut ( ) . monitor_updating_restored ( & self . logger , self . get_our_node_id ( ) , self . genesis_hash , self . best_block . read ( ) . unwrap ( ) . height ( ) ) ;
4590
4624
let channel_update = if updates. channel_ready . is_some ( ) && channel. get ( ) . is_usable ( ) {
4591
4625
// We only send a channel_update in the case where we are just now sending a
@@ -4600,7 +4634,12 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4600
4634
} )
4601
4635
} else { None }
4602
4636
} else { None } ;
4603
- htlc_forwards = 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 ) ;
4637
+ let update_actions = peer_state. monitor_update_blocked_actions
4638
+ . remove ( & channel. get ( ) . channel_id ( ) ) . unwrap_or ( Vec :: new ( ) ) ;
4639
+ htlc_forwards = self . handle_channel_resumption ( & mut channel_state. pending_msg_events ,
4640
+ channel. get_mut ( ) , update_actions,
4641
+ updates. raa , updates. commitment_update , updates. order , updates. accepted_htlcs ,
4642
+ updates. funding_broadcastable , updates. channel_ready , updates. announcement_sigs ) ;
4604
4643
if let Some ( upd) = channel_update {
4605
4644
channel_state. pending_msg_events . push ( upd) ;
4606
4645
}
@@ -5452,8 +5491,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5452
5491
}
5453
5492
let need_lnd_workaround = chan. get_mut ( ) . workaround_lnd_bug_4006 . take ( ) ;
5454
5493
htlc_forwards = self . handle_channel_resumption (
5455
- & mut channel_state. pending_msg_events , chan. get_mut ( ) , responses. raa , responses. commitment_update , responses. order ,
5456
- Vec :: new ( ) , None , responses. channel_ready , responses. announcement_sigs ) ;
5494
+ & mut channel_state. pending_msg_events , chan. get_mut ( ) , Vec :: new ( ) ,
5495
+ responses. raa , responses. commitment_update , responses. order , Vec :: new ( ) ,
5496
+ None , responses. channel_ready , responses. announcement_sigs ) ;
5457
5497
if let Some ( upd) = channel_update {
5458
5498
channel_state. pending_msg_events . push ( upd) ;
5459
5499
}
0 commit comments