@@ -336,7 +336,7 @@ pub(super) struct ChannelHolder<Signer: Sign> {
336
336
/// Events which we process internally, but which cannot be procsesed immediately at the
337
337
/// generation site for some reason. They are handled in timer_chan_freshness_every_min, so may be
338
338
/// processed with quite some time lag.
339
- enum BackgroundManagerEvent {
339
+ enum BackgroundEvent {
340
340
/// Handle a ChannelMonitorUpdate which closes a channel, broadcasting its current latest holder
341
341
/// commitment transaction.
342
342
ClosingMonitorUpdate ( ( OutPoint , ChannelMonitorUpdate ) ) ,
@@ -445,7 +445,7 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
445
445
per_peer_state : RwLock < HashMap < PublicKey , Mutex < PeerState > > > ,
446
446
447
447
pending_events : Mutex < Vec < events:: Event > > ,
448
- pending_background_events : Mutex < Vec < BackgroundManagerEvent > > ,
448
+ pending_background_events : Mutex < Vec < BackgroundEvent > > ,
449
449
/// Used when we have to take a BIG lock to make sure everything is self-consistent.
450
450
/// Essentially just when we're serializing ourselves out.
451
451
/// Taken first everywhere where we are making changes before any other locks.
@@ -1870,19 +1870,23 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1870
1870
/// BroadcastChannelUpdate events in timer_chan_freshness_every_min.
1871
1871
///
1872
1872
/// Expects the caller to have a total_consistency_lock read lock.
1873
- pub ( crate ) fn process_background_events ( & self ) {
1873
+ fn process_background_events ( & self ) {
1874
1874
let mut background_events = Vec :: new ( ) ;
1875
1875
mem:: swap ( & mut * self . pending_background_events . lock ( ) . unwrap ( ) , & mut background_events) ;
1876
1876
for event in background_events. drain ( ..) {
1877
1877
match event {
1878
- BackgroundManagerEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) => {
1878
+ BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) => {
1879
1879
// The channel has already been closed, so no use bothering to care about the
1880
1880
// monitor updating completing.
1881
1881
let _ = self . chain_monitor . update_channel ( funding_txo, update) ;
1882
1882
} ,
1883
1883
}
1884
1884
}
1885
1885
}
1886
+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
1887
+ pub ( crate ) fn test_process_background_events ( & self ) {
1888
+ self . process_background_events ( ) ;
1889
+ }
1886
1890
1887
1891
/// If a peer is disconnected we mark any channels with that peer as 'disabled'.
1888
1892
/// After some time, if channels are still disabled we need to broadcast a ChannelUpdate
@@ -3301,7 +3305,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3301
3305
if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
3302
3306
assert ! ( should_broadcast) ;
3303
3307
} else { unreachable ! ( ) ; }
3304
- self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundManagerEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3308
+ self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3305
3309
}
3306
3310
self . finish_force_close_channel ( failure) ;
3307
3311
}
@@ -3368,7 +3372,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3368
3372
if let ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } = update. updates [ 0 ] {
3369
3373
assert ! ( should_broadcast) ;
3370
3374
} else { unreachable ! ( ) ; }
3371
- self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundManagerEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3375
+ self . pending_background_events . lock ( ) . unwrap ( ) . push ( BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, update) ) ) ;
3372
3376
}
3373
3377
self . finish_force_close_channel ( failure) ;
3374
3378
}
@@ -3981,7 +3985,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
3981
3985
( background_events. len ( ) as u64 ) . write ( writer) ?;
3982
3986
for event in background_events. iter ( ) {
3983
3987
match event {
3984
- BackgroundManagerEvent :: ClosingMonitorUpdate ( ( funding_txo, monitor_update) ) => {
3988
+ BackgroundEvent :: ClosingMonitorUpdate ( ( funding_txo, monitor_update) ) => {
3985
3989
0u8 . write ( writer) ?;
3986
3990
funding_txo. write ( writer) ?;
3987
3991
monitor_update. write ( writer) ?;
@@ -4214,10 +4218,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
4214
4218
}
4215
4219
4216
4220
let background_event_count: u64 = Readable :: read ( reader) ?;
4217
- let mut pending_background_events_read: Vec < BackgroundManagerEvent > = Vec :: with_capacity ( cmp:: min ( background_event_count as usize , MAX_ALLOC_SIZE /mem:: size_of :: < BackgroundManagerEvent > ( ) ) ) ;
4221
+ let mut pending_background_events_read: Vec < BackgroundEvent > = Vec :: with_capacity ( cmp:: min ( background_event_count as usize , MAX_ALLOC_SIZE /mem:: size_of :: < BackgroundEvent > ( ) ) ) ;
4218
4222
for _ in 0 ..background_event_count {
4219
4223
match <u8 as Readable >:: read ( reader) ? {
4220
- 0 => pending_background_events_read. push ( BackgroundManagerEvent :: ClosingMonitorUpdate ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ) ,
4224
+ 0 => pending_background_events_read. push ( BackgroundEvent :: ClosingMonitorUpdate ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ) ,
4221
4225
_ => return Err ( DecodeError :: InvalidValue ) ,
4222
4226
}
4223
4227
}
0 commit comments