@@ -1215,7 +1215,8 @@ pub struct ChainParameters {
1215
1215
#[must_use]
1216
1216
enum NotifyOption {
1217
1217
DoPersist,
1218
- SkipPersist,
1218
+ SkipPersistHandleEvents,
1219
+ SkipPersistNoEvents,
1219
1220
}
1220
1221
1221
1222
/// Whenever we release the `ChannelManager`'s `total_consistency_lock`, from read mode, it is
@@ -1253,8 +1254,13 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care w
1253
1254
// Pick the "most" action between `persist_check` and the background events
1254
1255
// processing and return that.
1255
1256
let notify = persist_check();
1256
- if force_notify == NotifyOption::DoPersist { NotifyOption::DoPersist }
1257
- else { notify }
1257
+ match (notify, force_notify) {
1258
+ (NotifyOption::DoPersist, _) => NotifyOption::DoPersist,
1259
+ (_, NotifyOption::DoPersist) => NotifyOption::DoPersist,
1260
+ (NotifyOption::SkipPersistHandleEvents, _) => NotifyOption::SkipPersistHandleEvents,
1261
+ (_, NotifyOption::SkipPersistHandleEvents) => NotifyOption::SkipPersistHandleEvents,
1262
+ _ => NotifyOption::SkipPersistNoEvents,
1263
+ }
1258
1264
},
1259
1265
_read_guard: read_guard,
1260
1266
}
@@ -1278,9 +1284,14 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care w
1278
1284
1279
1285
impl<'a, F: Fn() -> NotifyOption> Drop for PersistenceNotifierGuard<'a, F> {
1280
1286
fn drop(&mut self) {
1281
- if (self.should_persist)() == NotifyOption::DoPersist {
1282
- self.needs_persist_flag.store(true, Ordering::Release);
1283
- self.event_persist_notifier.notify();
1287
+ match (self.should_persist)() {
1288
+ NotifyOption::DoPersist => {
1289
+ self.needs_persist_flag.store(true, Ordering::Release);
1290
+ self.event_persist_notifier.notify()
1291
+ },
1292
+ NotifyOption::SkipPersistHandleEvents =>
1293
+ self.event_persist_notifier.notify(),
1294
+ NotifyOption::SkipPersistNoEvents => {},
1284
1295
}
1285
1296
}
1286
1297
}
@@ -2092,7 +2103,7 @@ macro_rules! process_events_body {
2092
2103
return;
2093
2104
}
2094
2105
2095
- let mut result = NotifyOption::SkipPersist ;
2106
+ let mut result;
2096
2107
2097
2108
{
2098
2109
// We'll acquire our total consistency lock so that we can be sure no other
@@ -2101,7 +2112,7 @@ macro_rules! process_events_body {
2101
2112
2102
2113
// Because `handle_post_event_actions` may send `ChannelMonitorUpdate`s to the user we must
2103
2114
// ensure any startup-generated background events are handled first.
2104
- if $self.process_background_events() == NotifyOption::DoPersist { result = NotifyOption::DoPersist; }
2115
+ result = $self.process_background_events();
2105
2116
2106
2117
// TODO: This behavior should be documented. It's unintuitive that we query
2107
2118
// ChannelMonitors when clearing other events.
@@ -4348,7 +4359,7 @@ where
4348
4359
let mut background_events = Vec::new();
4349
4360
mem::swap(&mut *self.pending_background_events.lock().unwrap(), &mut background_events);
4350
4361
if background_events.is_empty() {
4351
- return NotifyOption::SkipPersist ;
4362
+ return NotifyOption::SkipPersistNoEvents ;
4352
4363
}
4353
4364
4354
4365
for event in background_events.drain(..) {
@@ -4417,17 +4428,17 @@ where
4417
4428
}
4418
4429
4419
4430
fn update_channel_fee(&self, chan_id: &ChannelId, chan: &mut Channel<SP>, new_feerate: u32) -> NotifyOption {
4420
- if !chan.context.is_outbound() { return NotifyOption::SkipPersist ; }
4431
+ if !chan.context.is_outbound() { return NotifyOption::SkipPersistNoEvents ; }
4421
4432
// If the feerate has decreased by less than half, don't bother
4422
4433
if new_feerate <= chan.context.get_feerate_sat_per_1000_weight() && new_feerate * 2 > chan.context.get_feerate_sat_per_1000_weight() {
4423
4434
log_trace!(self.logger, "Channel {} does not qualify for a feerate change from {} to {}.",
4424
- & chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);
4425
- return NotifyOption::SkipPersist ;
4435
+ chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);
4436
+ return NotifyOption::SkipPersistNoEvents ;
4426
4437
}
4427
4438
if !chan.context.is_live() {
4428
4439
log_trace!(self.logger, "Channel {} does not qualify for a feerate change from {} to {} as it cannot currently be updated (probably the peer is disconnected).",
4429
- & chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);
4430
- return NotifyOption::SkipPersist ;
4440
+ chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);
4441
+ return NotifyOption::SkipPersistNoEvents ;
4431
4442
}
4432
4443
log_trace!(self.logger, "Channel {} qualifies for a feerate change from {} to {}.",
4433
4444
&chan_id, chan.context.get_feerate_sat_per_1000_weight(), new_feerate);
@@ -4443,7 +4454,7 @@ where
4443
4454
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
4444
4455
pub fn maybe_update_chan_fees(&self) {
4445
4456
PersistenceNotifierGuard::optionally_notify(self, || {
4446
- let mut should_persist = NotifyOption::SkipPersist ;
4457
+ let mut should_persist = NotifyOption::SkipPersistNoEvents ;
4447
4458
4448
4459
let normal_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
4449
4460
let min_mempool_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MempoolMinimum);
@@ -4488,7 +4499,7 @@ where
4488
4499
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
4489
4500
pub fn timer_tick_occurred(&self) {
4490
4501
PersistenceNotifierGuard::optionally_notify(self, || {
4491
- let mut should_persist = NotifyOption::SkipPersist ;
4502
+ let mut should_persist = NotifyOption::SkipPersistNoEvents ;
4492
4503
4493
4504
let normal_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
4494
4505
let min_mempool_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MempoolMinimum);
@@ -6361,19 +6372,19 @@ where
6361
6372
Ok(())
6362
6373
}
6363
6374
6364
- /// Returns ShouldPersist if anything changed, otherwise either SkipPersist or an Err.
6375
+ /// Returns DoPersist if anything changed, otherwise either SkipPersistNoEvents or an Err.
6365
6376
fn internal_channel_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelUpdate) -> Result<NotifyOption, MsgHandleErrInternal> {
6366
6377
let (chan_counterparty_node_id, chan_id) = match self.short_to_chan_info.read().unwrap().get(&msg.contents.short_channel_id) {
6367
6378
Some((cp_id, chan_id)) => (cp_id.clone(), chan_id.clone()),
6368
6379
None => {
6369
6380
// It's not a local channel
6370
- return Ok(NotifyOption::SkipPersist )
6381
+ return Ok(NotifyOption::SkipPersistNoEvents )
6371
6382
}
6372
6383
};
6373
6384
let per_peer_state = self.per_peer_state.read().unwrap();
6374
6385
let peer_state_mutex_opt = per_peer_state.get(&chan_counterparty_node_id);
6375
6386
if peer_state_mutex_opt.is_none() {
6376
- return Ok(NotifyOption::SkipPersist )
6387
+ return Ok(NotifyOption::SkipPersistNoEvents )
6377
6388
}
6378
6389
let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
6379
6390
let peer_state = &mut *peer_state_lock;
@@ -6385,14 +6396,14 @@ where
6385
6396
// If the announcement is about a channel of ours which is public, some
6386
6397
// other peer may simply be forwarding all its gossip to us. Don't provide
6387
6398
// a scary-looking error message and return Ok instead.
6388
- return Ok(NotifyOption::SkipPersist );
6399
+ return Ok(NotifyOption::SkipPersistNoEvents );
6389
6400
}
6390
6401
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a channel_update for a channel from the wrong node - it shouldn't know about our private channels!".to_owned(), chan_id));
6391
6402
}
6392
6403
let were_node_one = self.get_our_node_id().serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
6393
6404
let msg_from_node_one = msg.contents.flags & 1 == 0;
6394
6405
if were_node_one == msg_from_node_one {
6395
- return Ok(NotifyOption::SkipPersist );
6406
+ return Ok(NotifyOption::SkipPersistNoEvents );
6396
6407
} else {
6397
6408
log_debug!(self.logger, "Received channel_update for channel {}.", chan_id);
6398
6409
try_chan_phase_entry!(self, chan.channel_update(&msg), chan_phase_entry);
@@ -6402,7 +6413,7 @@ where
6402
6413
"Got a channel_update for an unfunded channel!".into())), chan_phase_entry);
6403
6414
}
6404
6415
},
6405
- hash_map::Entry::Vacant(_) => return Ok(NotifyOption::SkipPersist )
6416
+ hash_map::Entry::Vacant(_) => return Ok(NotifyOption::SkipPersistNoEvents )
6406
6417
}
6407
6418
Ok(NotifyOption::DoPersist)
6408
6419
}
@@ -7021,7 +7032,7 @@ where
7021
7032
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
7022
7033
let events = RefCell::new(Vec::new());
7023
7034
PersistenceNotifierGuard::optionally_notify(self, || {
7024
- let mut result = NotifyOption::SkipPersist ;
7035
+ let mut result = NotifyOption::SkipPersistNoEvents ;
7025
7036
7026
7037
// TODO: This behavior should be documented. It's unintuitive that we query
7027
7038
// ChannelMonitors when clearing other events.
@@ -7556,7 +7567,7 @@ where
7556
7567
if let Ok(persist) = handle_error!(self, self.internal_channel_update(counterparty_node_id, msg), *counterparty_node_id) {
7557
7568
persist
7558
7569
} else {
7559
- NotifyOption::SkipPersist
7570
+ NotifyOption::SkipPersistNoEvents
7560
7571
}
7561
7572
});
7562
7573
}
0 commit comments