Skip to content

Commit 7de602a

Browse files
committed
Stop tracking MonitorUpdates from ChainSync in pending_monitor_updates
We no longer need to track them since we no longer hold events for pending MonitorUpdates resulting from ChainSync.
1 parent e084ab2 commit 7de602a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ mod tests {
500500
txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
501501
index: 0
502502
};
503-
match store.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
503+
match store.persist_new_channel(test_txo, &added_monitors[0].1) {
504504
ChannelMonitorUpdateStatus::UnrecoverableError => {},
505505
_ => panic!("unexpected result from persisting new channel")
506506
}

lightning/src/chain/chainmonitor.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ where C::Target: chain::Filter,
350350
let update_id = MonitorUpdateId {
351351
contents: UpdateOrigin::ChainSync(chain_sync_update_id),
352352
};
353-
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
354353

355354
log_trace!(logger, "Syncing Channel Monitor for channel {} for block-data update_id {}",
356355
log_funding_info!(monitor),
@@ -364,7 +363,6 @@ where C::Target: chain::Filter,
364363
),
365364
ChannelMonitorUpdateStatus::InProgress => {
366365
log_debug!(logger, "Channel Monitor sync for channel {} in progress.", log_funding_info!(monitor));
367-
pending_monitor_updates.push(update_id);
368366
},
369367
ChannelMonitorUpdateStatus::UnrecoverableError => {
370368
return Err(());

lightning/src/util/test_utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::chain::chaininterface::ConfirmationTarget;
1616
#[cfg(test)]
1717
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
1818
use crate::chain::chainmonitor;
19-
use crate::chain::chainmonitor::{MonitorUpdateId, UpdateOrigin};
19+
use crate::chain::chainmonitor::{MonitorUpdateId};
2020
use crate::chain::channelmonitor;
2121
use crate::chain::channelmonitor::MonitorEvent;
2222
use crate::chain::transaction::OutPoint;
@@ -516,7 +516,7 @@ pub struct TestPersister {
516516
pub update_rets: Mutex<VecDeque<chain::ChannelMonitorUpdateStatus>>,
517517
/// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
518518
/// MonitorUpdateId here.
519-
pub chain_sync_monitor_persistences: Mutex<HashMap<OutPoint, HashSet<MonitorUpdateId>>>,
519+
pub chain_sync_monitor_persistences: Mutex<VecDeque<OutPoint>>,
520520
/// When we get an update_persisted_channel call *with* a ChannelMonitorUpdate, we insert the
521521
/// MonitorUpdateId here.
522522
pub offchain_monitor_updates: Mutex<HashMap<OutPoint, HashSet<MonitorUpdateId>>>,
@@ -525,7 +525,7 @@ impl TestPersister {
525525
pub fn new() -> Self {
526526
Self {
527527
update_rets: Mutex::new(VecDeque::new()),
528-
chain_sync_monitor_persistences: Mutex::new(new_hash_map()),
528+
chain_sync_monitor_persistences: Mutex::new(VecDeque::new()),
529529
offchain_monitor_updates: Mutex::new(new_hash_map()),
530530
}
531531
}
@@ -543,16 +543,16 @@ impl<Signer: sign::ecdsa::WriteableEcdsaChannelSigner> chainmonitor::Persist<Sig
543543
chain::ChannelMonitorUpdateStatus::Completed
544544
}
545545

546-
fn update_persisted_channel(&self, funding_txo: OutPoint, _update: Option<&channelmonitor::ChannelMonitorUpdate>, _data: &channelmonitor::ChannelMonitor<Signer>, update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
546+
fn update_persisted_channel(&self, funding_txo: OutPoint, update: Option<&channelmonitor::ChannelMonitorUpdate>, _data: &channelmonitor::ChannelMonitor<Signer>, update_id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
547547
let mut ret = chain::ChannelMonitorUpdateStatus::Completed;
548548
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
549549
ret = update_ret;
550550
}
551-
let is_chain_sync = if let UpdateOrigin::ChainSync(_) = update_id.contents { true } else { false };
552-
if is_chain_sync {
553-
self.chain_sync_monitor_persistences.lock().unwrap().entry(funding_txo).or_insert(new_hash_set()).insert(update_id);
554-
} else {
551+
552+
if update.is_some() {
555553
self.offchain_monitor_updates.lock().unwrap().entry(funding_txo).or_insert(new_hash_set()).insert(update_id);
554+
} else {
555+
self.chain_sync_monitor_persistences.lock().unwrap().push_back(funding_txo);
556556
}
557557
ret
558558
}
@@ -564,7 +564,7 @@ impl<Signer: sign::ecdsa::WriteableEcdsaChannelSigner> chainmonitor::Persist<Sig
564564
None => {
565565
// If the channel was not in the offchain_monitor_updates map, it should be in the
566566
// chain_sync_monitor_persistences map.
567-
assert!(self.chain_sync_monitor_persistences.lock().unwrap().remove(&funding_txo).is_some());
567+
self.chain_sync_monitor_persistences.lock().unwrap().retain(|x| x != &funding_txo);
568568
}
569569
};
570570
}

0 commit comments

Comments
 (0)