@@ -935,4 +935,27 @@ mod tests {
935
935
do_chainsync_pauses_events ( false ) ;
936
936
do_chainsync_pauses_events ( true ) ;
937
937
}
938
+
939
+ #[ test]
940
+ fn update_during_chainsync_fails_channel ( ) {
941
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
942
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
943
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
944
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
945
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
946
+
947
+ chanmon_cfgs[ 0 ] . persister . chain_sync_monitor_persistences . lock ( ) . unwrap ( ) . clear ( ) ;
948
+ chanmon_cfgs[ 0 ] . persister . set_update_ret ( Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ) ;
949
+
950
+ connect_blocks ( & nodes[ 0 ] , 1 ) ;
951
+ // Before processing events, the ChannelManager will still think the Channel is open and
952
+ // there won't be any ChannelMonitorUpdates
953
+ assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 1 ) ;
954
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
955
+ // ... however once we get events once, the channel will close, creating a channel-closed
956
+ // ChannelMonitorUpdate.
957
+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
958
+ check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: ProcessingError { err: "Failed to persist ChannelMonitor update during chain sync" . to_string( ) } ) ;
959
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
960
+ }
938
961
}
0 commit comments