Skip to content

Commit c2aee57

Browse files
committed
Make PersistenceNotifierGuard::optionally_notify take a ChanMan ref
Long ago, for reasons lost to the ages, the `PersistenceNotifierGuard::optionally_notify` constructor didn't take a `ChannelManager` reference, but rather explicit references to the fields of it that it needs. This is cumbersome and useless, so we fix it here.
1 parent 9228f90 commit c2aee57

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,11 +1249,12 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care w
12491249

12501250
/// Note that if any [`ChannelMonitorUpdate`]s are possibly generated,
12511251
/// [`ChannelManager::process_background_events`] MUST be called first.
1252-
fn optionally_notify<F: Fn() -> NotifyOption>(lock: &'a RwLock<()>, notifier: &'a Notifier, persist_check: F) -> PersistenceNotifierGuard<'a, F> {
1253-
let read_guard = lock.read().unwrap();
1252+
fn optionally_notify<F: Fn() -> NotifyOption, C: AChannelManager>(cm: &'a C, persist_check: F)
1253+
-> PersistenceNotifierGuard<'a, F> {
1254+
let read_guard = cm.get_cm().total_consistency_lock.read().unwrap();
12541255

12551256
PersistenceNotifierGuard {
1256-
event_persist_notifier: notifier,
1257+
event_persist_notifier: &cm.get_cm().event_persist_notifier,
12571258
should_persist: persist_check,
12581259
_read_guard: read_guard,
12591260
}
@@ -4422,7 +4423,7 @@ where
44224423
/// these a fuzz failure (as they usually indicate a channel force-close, which is exactly what
44234424
/// it wants to detect). Thus, we have a variant exposed here for its benefit.
44244425
pub fn maybe_update_chan_fees(&self) {
4425-
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.event_persist_notifier, || {
4426+
PersistenceNotifierGuard::optionally_notify(self, || {
44264427
let mut should_persist = self.process_background_events();
44274428

44284429
let normal_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
@@ -4467,7 +4468,7 @@ where
44674468
/// [`ChannelUpdate`]: msgs::ChannelUpdate
44684469
/// [`ChannelConfig`]: crate::util::config::ChannelConfig
44694470
pub fn timer_tick_occurred(&self) {
4470-
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.event_persist_notifier, || {
4471+
PersistenceNotifierGuard::optionally_notify(self, || {
44714472
let mut should_persist = self.process_background_events();
44724473

44734474
let normal_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
@@ -7000,7 +7001,7 @@ where
70007001
/// the `MessageSendEvent`s to the specific peer they were generated under.
70017002
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
70027003
let events = RefCell::new(Vec::new());
7003-
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.event_persist_notifier, || {
7004+
PersistenceNotifierGuard::optionally_notify(self, || {
70047005
let mut result = self.process_background_events();
70057006

70067007
// TODO: This behavior should be documented. It's unintuitive that we query
@@ -7082,8 +7083,8 @@ where
70827083
}
70837084

70847085
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
7085-
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock,
7086-
&self.event_persist_notifier, || -> NotifyOption { NotifyOption::DoPersist });
7086+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self,
7087+
|| -> NotifyOption { NotifyOption::DoPersist });
70877088
let new_height = height - 1;
70887089
{
70897090
let mut best_block = self.best_block.write().unwrap();
@@ -7117,8 +7118,8 @@ where
71177118
let block_hash = header.block_hash();
71187119
log_trace!(self.logger, "{} transactions included in block {} at height {} provided", txdata.len(), block_hash, height);
71197120

7120-
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock,
7121-
&self.event_persist_notifier, || -> NotifyOption { NotifyOption::DoPersist });
7121+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self,
7122+
|| -> NotifyOption { NotifyOption::DoPersist });
71227123
self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger)
71237124
.map(|(a, b)| (a, Vec::new(), b)));
71247125

@@ -7137,8 +7138,8 @@ where
71377138
let block_hash = header.block_hash();
71387139
log_trace!(self.logger, "New best block: {} at height {}", block_hash, height);
71397140

7140-
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock,
7141-
&self.event_persist_notifier, || -> NotifyOption { NotifyOption::DoPersist });
7141+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self,
7142+
|| -> NotifyOption { NotifyOption::DoPersist });
71427143
*self.best_block.write().unwrap() = BestBlock::new(block_hash, height);
71437144

71447145
self.do_chain_event(Some(height), |channel| channel.best_block_updated(height, header.time, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger));
@@ -7181,8 +7182,8 @@ where
71817182
}
71827183

71837184
fn transaction_unconfirmed(&self, txid: &Txid) {
7184-
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock,
7185-
&self.event_persist_notifier, || -> NotifyOption { NotifyOption::DoPersist });
7185+
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self,
7186+
|| -> NotifyOption { NotifyOption::DoPersist });
71867187
self.do_chain_event(None, |channel| {
71877188
if let Some(funding_txo) = channel.context.get_funding_txo() {
71887189
if funding_txo.txid == *txid {
@@ -7520,7 +7521,7 @@ where
75207521
}
75217522

75227523
fn handle_channel_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelUpdate) {
7523-
PersistenceNotifierGuard::optionally_notify(&self.total_consistency_lock, &self.event_persist_notifier, || {
7524+
PersistenceNotifierGuard::optionally_notify(self, || {
75247525
let force_persist = self.process_background_events();
75257526
if let Ok(persist) = handle_error!(self, self.internal_channel_update(counterparty_node_id, msg), *counterparty_node_id) {
75267527
if force_persist == NotifyOption::DoPersist { NotifyOption::DoPersist } else { persist }

0 commit comments

Comments
 (0)