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