Skip to content

Commit 4abedbb

Browse files
committed
f cleanups jeff suggested
1 parent 9bbb8db commit 4abedbb

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub(super) struct ChannelHolder<Signer: Sign> {
336336
/// Events which we process internally, but which cannot be procsesed immediately at the
337337
/// generation site for some reason. They are handled in timer_chan_freshness_every_min, so may be
338338
/// processed with quite some time lag.
339-
enum BackgroundManagerEvent {
339+
enum BackgroundEvent {
340340
/// Handle a ChannelMonitorUpdate which closes a channel, broadcasting its current latest holder
341341
/// commitment transaction.
342342
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)),
@@ -445,7 +445,7 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
445445
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
446446

447447
pending_events: Mutex<Vec<events::Event>>,
448-
pending_background_events: Mutex<Vec<BackgroundManagerEvent>>,
448+
pending_background_events: Mutex<Vec<BackgroundEvent>>,
449449
/// Used when we have to take a BIG lock to make sure everything is self-consistent.
450450
/// Essentially just when we're serializing ourselves out.
451451
/// 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
18701870
/// BroadcastChannelUpdate events in timer_chan_freshness_every_min.
18711871
///
18721872
/// 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) {
18741874
let mut background_events = Vec::new();
18751875
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
18761876
for event in background_events.drain(..) {
18771877
match event {
1878-
BackgroundManagerEvent::ClosingMonitorUpdate((funding_txo, update)) => {
1878+
BackgroundEvent::ClosingMonitorUpdate((funding_txo, update)) => {
18791879
// The channel has already been closed, so no use bothering to care about the
18801880
// monitor updating completing.
18811881
let _ = self.chain_monitor.update_channel(funding_txo, update);
18821882
},
18831883
}
18841884
}
18851885
}
1886+
#[cfg(any(test, feature = "_test_utils"))]
1887+
pub(crate) fn test_process_background_events(&self) {
1888+
self.process_background_events();
1889+
}
18861890

18871891
/// If a peer is disconnected we mark any channels with that peer as 'disabled'.
18881892
/// 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
33013305
if let ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update.updates[0] {
33023306
assert!(should_broadcast);
33033307
} 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)));
33053309
}
33063310
self.finish_force_close_channel(failure);
33073311
}
@@ -3368,7 +3372,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33683372
if let ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } = update.updates[0] {
33693373
assert!(should_broadcast);
33703374
} 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)));
33723376
}
33733377
self.finish_force_close_channel(failure);
33743378
}
@@ -3981,7 +3985,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
39813985
(background_events.len() as u64).write(writer)?;
39823986
for event in background_events.iter() {
39833987
match event {
3984-
BackgroundManagerEvent::ClosingMonitorUpdate((funding_txo, monitor_update)) => {
3988+
BackgroundEvent::ClosingMonitorUpdate((funding_txo, monitor_update)) => {
39853989
0u8.write(writer)?;
39863990
funding_txo.write(writer)?;
39873991
monitor_update.write(writer)?;
@@ -4214,10 +4218,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
42144218
}
42154219

42164220
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>()));
42184222
for _ in 0..background_event_count {
42194223
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)?))),
42214225
_ => return Err(DecodeError::InvalidValue),
42224226
}
42234227
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block,
8383
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
8484
node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
8585
node.node.block_connected(&block.header, &txdata, height);
86-
node.node.process_background_events();
86+
node.node.test_process_background_events();
8787
}
8888

8989
pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) {
9090
node.chain_monitor.chain_monitor.block_disconnected(header, height);
9191
node.node.block_disconnected(header);
92-
node.node.process_background_events();
92+
node.node.test_process_background_events();
9393
}
9494

9595
pub struct TestChanMonCfg {

lightning/src/ln/reorg_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fn test_unconf_chan() {
207207
nodes[0].node.block_disconnected(&headers.pop().unwrap());
208208
}
209209
check_closed_broadcast!(nodes[0], false);
210-
nodes[0].node.process_background_events(); // Required to free the pending background monitor update
210+
nodes[0].node.test_process_background_events(); // Required to free the pending background monitor update
211211
check_added_monitors!(nodes[0], 1);
212212
let channel_state = nodes[0].node.channel_state.lock().unwrap();
213213
assert_eq!(channel_state.by_id.len(), 0);

0 commit comments

Comments
 (0)