@@ -359,7 +359,7 @@ pub enum FailureCode {
359
359
IncorrectOrUnknownPaymentDetails = 0x4000 | 15 ,
360
360
}
361
361
362
- type ShutdownResult = ( Option < ( OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , PublicKey , [ u8 ; 32 ] ) > ) ;
362
+ type ShutdownResult = ( Option < ( PublicKey , OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , PublicKey , [ u8 ; 32 ] ) > ) ;
363
363
364
364
/// Error type returned across the peer_state mutex boundary. When an Err is generated for a
365
365
/// Channel, we generally end up with a ChannelError::Close for which we have to close the channel
@@ -501,11 +501,19 @@ struct ClaimablePayments {
501
501
/// for some reason. They are handled in timer_tick_occurred, so may be processed with
502
502
/// quite some time lag.
503
503
enum BackgroundEvent {
504
- /// Handle a ChannelMonitorUpdate
504
+ /// Handle a ChannelMonitorUpdate which closes the channel. This is only separated from
505
+ /// [`Self::MonitorUpdateRegeneratedOnStartup`] as the non-closing variant needs a public key
506
+ /// to handle channel resumption, whereas if the channel has been force-closed we do not need
507
+ /// the counterparty node_id.
505
508
///
506
509
/// Note that any such events are lost on shutdown, so in general they must be updates which
507
510
/// are regenerated on startup.
508
- MonitorUpdateRegeneratedOnStartup ( ( OutPoint , ChannelMonitorUpdate ) ) ,
511
+ ClosingMonitorUpdateRegeneratedOnStartup ( ( OutPoint , ChannelMonitorUpdate ) ) ,
512
+ /// Handle a ChannelMonitorUpdate.
513
+ ///
514
+ /// Note that any such events are lost on shutdown, so in general they must be updates which
515
+ /// are regenerated on startup.
516
+ MonitorUpdateRegeneratedOnStartup ( ( PublicKey , OutPoint , ChannelMonitorUpdate ) ) ,
509
517
}
510
518
511
519
#[ derive( Debug ) ]
@@ -2195,7 +2203,7 @@ where
2195
2203
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( counterparty_node_id) , channel_id } ;
2196
2204
self . fail_htlc_backwards_internal ( & source, & payment_hash, & reason, receiver) ;
2197
2205
}
2198
- if let Some ( ( funding_txo, monitor_update) ) = monitor_update_option {
2206
+ if let Some ( ( _ , funding_txo, monitor_update) ) = monitor_update_option {
2199
2207
// There isn't anything we can do if we get an update failure - we're already
2200
2208
// force-closing. The monitor update on the required in-memory copy should broadcast
2201
2209
// the latest local state, which is the best we can do anyway. Thus, it is safe to
@@ -3776,7 +3784,12 @@ where
3776
3784
3777
3785
for event in background_events. drain ( ..) {
3778
3786
match event {
3779
- BackgroundEvent :: MonitorUpdateRegeneratedOnStartup ( ( funding_txo, update) ) => {
3787
+ BackgroundEvent :: ClosingMonitorUpdateRegeneratedOnStartup ( ( funding_txo, update) ) => {
3788
+ // The channel has already been closed, so no use bothering to care about the
3789
+ // monitor updating completing.
3790
+ let _ = self . chain_monitor . update_channel ( funding_txo, & update) ;
3791
+ } ,
3792
+ BackgroundEvent :: MonitorUpdateRegeneratedOnStartup ( ( _, funding_txo, update) ) => {
3780
3793
// The channel has already been closed, so no use bothering to care about the
3781
3794
// monitor updating completing.
3782
3795
let _ = self . chain_monitor . update_channel ( funding_txo, & update) ;
@@ -5691,12 +5704,14 @@ where
5691
5704
// Channel::force_shutdown tries to make us do) as we may still be in initialization,
5692
5705
// so we track the update internally and handle it when the user next calls
5693
5706
// timer_tick_occurred, guaranteeing we're running normally.
5694
- if let Some ( ( funding_txo, update) ) = failure. 0 . take ( ) {
5707
+ if let Some ( ( counterparty_node_id , funding_txo, update) ) = failure. 0 . take ( ) {
5695
5708
assert_eq ! ( update. updates. len( ) , 1 ) ;
5696
5709
if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
5697
5710
assert ! ( should_broadcast) ;
5698
5711
} else { unreachable ! ( ) ; }
5699
- self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: MonitorUpdateRegeneratedOnStartup ( ( funding_txo, update) ) ) ;
5712
+ self . pending_background_events . lock ( ) . unwrap ( ) . push (
5713
+ BackgroundEvent :: MonitorUpdateRegeneratedOnStartup (
5714
+ ( counterparty_node_id, funding_txo, update) ) ) ;
5700
5715
}
5701
5716
self . finish_force_close_channel ( failure) ;
5702
5717
}
@@ -7845,7 +7860,7 @@ where
7845
7860
update_id : CLOSED_CHANNEL_UPDATE_ID ,
7846
7861
updates : vec ! [ ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast: true } ] ,
7847
7862
} ;
7848
- pending_background_events. push ( BackgroundEvent :: MonitorUpdateRegeneratedOnStartup ( ( * funding_txo, monitor_update) ) ) ;
7863
+ pending_background_events. push ( BackgroundEvent :: ClosingMonitorUpdateRegeneratedOnStartup ( ( * funding_txo, monitor_update) ) ) ;
7849
7864
}
7850
7865
}
7851
7866
0 commit comments