@@ -395,6 +395,13 @@ where C::Target: chain::Filter,
395
395
self . monitors . read ( ) . unwrap ( ) . keys ( ) . map ( |outpoint| * outpoint) . collect ( )
396
396
}
397
397
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
+
398
405
#[ cfg( test) ]
399
406
pub fn remove_monitor ( & self , funding_txo : & OutPoint ) -> ChannelMonitor < ChannelSigner > {
400
407
self . monitors . write ( ) . unwrap ( ) . remove ( funding_txo) . unwrap ( ) . monitor
@@ -798,7 +805,14 @@ mod tests {
798
805
// Note that updates is a HashMap so the ordering here is actually random. This shouldn't
799
806
// fail either way but if it fails intermittently it's depending on the ordering of updates.
800
807
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) ) ;
802
816
assert ! ( nodes[ 1 ] . chain_monitor. release_pending_monitor_events( ) . is_empty( ) ) ;
803
817
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
804
818
nodes[ 1 ] . chain_monitor . chain_monitor . channel_monitor_updated ( * funding_txo, update_iter. next ( ) . unwrap ( ) . clone ( ) ) . unwrap ( ) ;
0 commit comments