@@ -656,6 +656,19 @@ where C::Target: chain::Filter,
656
656
}
657
657
}
658
658
}
659
+
660
+ pub fn prune_stale_channel_monitors ( & self ) {
661
+ let mut monitors = self . monitors . write ( ) . unwrap ( ) ;
662
+ let mut to_remove = Vec :: new ( ) ;
663
+ for ( funding_outpoint, monitor_holder) in monitors. iter ( ) {
664
+ if monitor_holder. monitor . is_stale ( ) {
665
+ to_remove. push ( * funding_outpoint) ;
666
+ }
667
+ }
668
+ for funding_outpoint in to_remove {
669
+ monitors. remove ( & funding_outpoint) ;
670
+ }
671
+ }
659
672
}
660
673
661
674
impl < ChannelSigner : WriteableEcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
@@ -1108,4 +1121,17 @@ mod tests {
1108
1121
core:: mem:: drop( nodes) ;
1109
1122
} ) . is_err( ) ) ;
1110
1123
}
1124
+
1125
+ #[ test]
1126
+ fn prune_stale_channel_monitor ( ) {
1127
+ // Test that we can prune a ChannelMonitor that has no active channel.
1128
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1129
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1130
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None ] ) ;
1131
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1132
+ let push_msat = 0 ;
1133
+ let channel_id = exchange_open_accept_chan ( & nodes[ 0 ] , & nodes[ 1 ] , 10000 , push_msat) ;
1134
+ nodes[ 0 ] . node . close_channel ( & channel_id, & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
1135
+ // try to prune stale channel monitor
1136
+ }
1111
1137
}
0 commit comments