Skip to content

Commit b98967d

Browse files
committed
Add public method to list pending monitor updates from ChainMonitor
Users have requested the feature to list pending monitor updates from `ChainMonitor` so this adds that.
1 parent 554fc02 commit b98967d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ where C::Target: chain::Filter,
395395
self.monitors.read().unwrap().keys().map(|outpoint| *outpoint).collect()
396396
}
397397

398+
/// Lists the pending updates for each [`ChannelMonitor`] (by `OutPoint` being monitored).
399+
pub fn list_pending_monitor_updates(&self) -> HashMap<OutPoint, Vec<MonitorUpdateId>> {
400+
self.monitors.read().unwrap().iter().map(|(outpoint, holder)| {
401+
(*outpoint, holder.pending_monitor_updates.lock().unwrap().clone())
402+
}).collect()
403+
}
404+
398405
#[cfg(test)]
399406
pub fn remove_monitor(&self, funding_txo: &OutPoint) -> ChannelMonitor<ChannelSigner> {
400407
self.monitors.write().unwrap().remove(funding_txo).unwrap().monitor
@@ -798,7 +805,14 @@ mod tests {
798805
// Note that updates is a HashMap so the ordering here is actually random. This shouldn't
799806
// fail either way but if it fails intermittently it's depending on the ordering of updates.
800807
let mut update_iter = updates.iter();
801-
nodes[1].chain_monitor.chain_monitor.channel_monitor_updated(*funding_txo, update_iter.next().unwrap().clone()).unwrap();
808+
let next_update = update_iter.next().unwrap().clone();
809+
// Should contain next_update when pending updates listed.
810+
assert!(nodes[1].chain_monitor.chain_monitor.list_pending_monitor_updates().get(funding_txo)
811+
.unwrap().contains(&next_update));
812+
nodes[1].chain_monitor.chain_monitor.channel_monitor_updated(*funding_txo, next_update.clone()).unwrap();
813+
// Should not contain the previously pending next_update when pending updates listed.
814+
assert!(!nodes[1].chain_monitor.chain_monitor.list_pending_monitor_updates().get(funding_txo)
815+
.unwrap().contains(&next_update));
802816
assert!(nodes[1].chain_monitor.release_pending_monitor_events().is_empty());
803817
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
804818
nodes[1].chain_monitor.chain_monitor.channel_monitor_updated(*funding_txo, update_iter.next().unwrap().clone()).unwrap();

0 commit comments

Comments
 (0)