Skip to content

Commit 4225cfd

Browse files
committed
Stop storing last_chain_persist_height
1 parent 1ca17d8 commit 4225cfd

File tree

1 file changed

+5
-41
lines changed

1 file changed

+5
-41
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -210,24 +210,13 @@ struct MonitorHolder<ChannelSigner: WriteableEcdsaChannelSigner> {
210210
/// [`ChannelMonitorUpdateStatus::InProgress`], and then calls channel_monitor_updated
211211
/// immediately, racing our insertion of the pending update into the contained Vec.
212212
pending_monitor_updates: Mutex<Vec<MonitorUpdateId>>,
213-
/// The last block height at which no [`UpdateOrigin::ChainSync`] monitor updates were present
214-
/// in `pending_monitor_updates`.
215-
/// If it's been more than [`LATENCY_GRACE_PERIOD_BLOCKS`] since we started waiting on a chain
216-
/// sync event, we let monitor events return to `ChannelManager` because we cannot hold them up
217-
/// forever or we'll end up with HTLC preimages waiting to feed back into an upstream channel
218-
/// forever, risking funds loss.
219-
last_chain_persist_height: AtomicUsize,
220213
}
221214

222215
impl<ChannelSigner: WriteableEcdsaChannelSigner> MonitorHolder<ChannelSigner> {
223216
fn has_pending_offchain_updates(&self, pending_monitor_updates_lock: &MutexGuard<Vec<MonitorUpdateId>>) -> bool {
224217
pending_monitor_updates_lock.iter().any(|update_id|
225218
if let UpdateOrigin::OffChain(_) = update_id.contents { true } else { false })
226219
}
227-
fn has_pending_chainsync_updates(&self, pending_monitor_updates_lock: &MutexGuard<Vec<MonitorUpdateId>>) -> bool {
228-
pending_monitor_updates_lock.iter().any(|update_id|
229-
if let UpdateOrigin::ChainSync(_) = update_id.contents { true } else { false })
230-
}
231220
}
232221

233222
/// A read-only reference to a current ChannelMonitor.
@@ -315,7 +304,7 @@ where C::Target: chain::Filter,
315304
for funding_outpoint in funding_outpoints.iter() {
316305
let monitor_lock = self.monitors.read().unwrap();
317306
if let Some(monitor_state) = monitor_lock.get(funding_outpoint) {
318-
if self.update_monitor_with_chain_data(header, best_height, txdata, &process, funding_outpoint, &monitor_state).is_err() {
307+
if self.update_monitor_with_chain_data(header, txdata, &process, funding_outpoint, &monitor_state).is_err() {
319308
// Take the monitors lock for writing so that we poison it and any future
320309
// operations going forward fail immediately.
321310
core::mem::drop(monitor_lock);
@@ -330,7 +319,7 @@ where C::Target: chain::Filter,
330319
let monitor_states = self.monitors.write().unwrap();
331320
for (funding_outpoint, monitor_state) in monitor_states.iter() {
332321
if !funding_outpoints.contains(funding_outpoint) {
333-
if self.update_monitor_with_chain_data(header, best_height, txdata, &process, funding_outpoint, &monitor_state).is_err() {
322+
if self.update_monitor_with_chain_data(header, txdata, &process, funding_outpoint, &monitor_state).is_err() {
334323
log_error!(self.logger, "{}", err_str);
335324
panic!("{}", err_str);
336325
}
@@ -349,8 +338,8 @@ where C::Target: chain::Filter,
349338
}
350339

351340
fn update_monitor_with_chain_data<FN>(
352-
&self, header: &Header, best_height: Option<u32>, txdata: &TransactionData,
353-
process: FN, funding_outpoint: &OutPoint, monitor_state: &MonitorHolder<ChannelSigner>
341+
&self, header: &Header, txdata: &TransactionData, process: FN, funding_outpoint: &OutPoint,
342+
monitor_state: &MonitorHolder<ChannelSigner>
354343
) -> Result<(), ()> where FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs> {
355344
let monitor = &monitor_state.monitor;
356345
let logger = WithChannelMonitor::from(&self.logger, &monitor);
@@ -362,14 +351,6 @@ where C::Target: chain::Filter,
362351
contents: UpdateOrigin::ChainSync(chain_sync_update_id),
363352
};
364353
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
365-
if let Some(height) = best_height {
366-
if !monitor_state.has_pending_chainsync_updates(&pending_monitor_updates) {
367-
// If there are not ChainSync persists awaiting completion, go ahead and
368-
// set last_chain_persist_height here - we wouldn't want the first
369-
// InProgress to always immediately be considered "overly delayed".
370-
monitor_state.last_chain_persist_height.store(height as usize, Ordering::Release);
371-
}
372-
}
373354

374355
log_trace!(logger, "Syncing Channel Monitor for channel {} for block-data update_id {}",
375356
log_funding_info!(monitor),
@@ -560,23 +541,7 @@ where C::Target: chain::Filter,
560541
monitor_update_id: monitor_data.monitor.get_latest_update_id(),
561542
}], monitor_data.monitor.get_counterparty_node_id()));
562543
},
563-
MonitorUpdateId { contents: UpdateOrigin::ChainSync(completed_update_id) } => {
564-
let monitor_has_pending_updates =
565-
monitor_data.has_pending_chainsync_updates(&pending_monitor_updates);
566-
log_debug!(self.logger, "Completed chain sync monitor update {} for channel with funding outpoint {:?}, {}",
567-
completed_update_id,
568-
funding_txo,
569-
if monitor_has_pending_updates {
570-
"still have pending chain sync updates"
571-
} else {
572-
"all chain sync updates complete, releasing pending MonitorEvents"
573-
});
574-
if !monitor_has_pending_updates {
575-
monitor_data.last_chain_persist_height.store(self.highest_chain_height.load(Ordering::Acquire), Ordering::Release);
576-
// The next time release_pending_monitor_events is called, any events for this
577-
// ChannelMonitor will be returned.
578-
}
579-
},
544+
MonitorUpdateId { contents: UpdateOrigin::ChainSync(_) } => {},
580545
}
581546
self.event_notifier.notify();
582547
Ok(())
@@ -831,7 +796,6 @@ where C::Target: chain::Filter,
831796
entry.insert(MonitorHolder {
832797
monitor,
833798
pending_monitor_updates: Mutex::new(pending_monitor_updates),
834-
last_chain_persist_height: AtomicUsize::new(self.highest_chain_height.load(Ordering::Acquire)),
835799
});
836800
Ok(persist_res)
837801
}

0 commit comments

Comments
 (0)