@@ -253,29 +253,31 @@ mod tests {
253253 let chan = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
254254 nodes[ 1 ] . node . force_close_broadcasting_latest_txn ( & chan. 2 , & nodes[ 0 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
255255 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: HolderForceClosed ) ;
256- let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
257- let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
258- let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
259-
260- // Set the persister's directory to read-only, which should result in
261- // returning a permanent failure when we then attempt to persist a
262- // channel update.
263- let path = & persister. path_to_channel_data ;
264- let mut perms = fs:: metadata ( path) . unwrap ( ) . permissions ( ) ;
265- perms. set_readonly ( true ) ;
266- fs:: set_permissions ( path, perms) . unwrap ( ) ;
267-
268- let test_txo = OutPoint {
269- txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
270- index : 0
271- } ;
272- match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id. 2 ) {
273- ChannelMonitorUpdateStatus :: PermanentFailure => { } ,
274- _ => panic ! ( "unexpected result from persisting new channel" )
275- }
256+ {
257+ let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
258+ let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
259+ let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
260+
261+ // Set the persister's directory to read-only, which should result in
262+ // returning a permanent failure when we then attempt to persist a
263+ // channel update.
264+ let path = & persister. path_to_channel_data ;
265+ let mut perms = fs:: metadata ( path) . unwrap ( ) . permissions ( ) ;
266+ perms. set_readonly ( true ) ;
267+ fs:: set_permissions ( path, perms) . unwrap ( ) ;
268+
269+ let test_txo = OutPoint {
270+ txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
271+ index : 0
272+ } ;
273+ match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id. 2 ) {
274+ ChannelMonitorUpdateStatus :: PermanentFailure => { } ,
275+ _ => panic ! ( "unexpected result from persisting new channel" )
276+ }
276277
278+ added_monitors. clear ( ) ;
279+ }
277280 nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
278- added_monitors. clear ( ) ;
279281 }
280282
281283 // Test that if a persister's directory name is invalid, monitor persistence
@@ -292,27 +294,29 @@ mod tests {
292294 let chan = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
293295 nodes[ 1 ] . node . force_close_broadcasting_latest_txn ( & chan. 2 , & nodes[ 0 ] . node . get_our_node_id ( ) ) . unwrap ( ) ;
294296 check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: HolderForceClosed ) ;
295- let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
296- let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
297- let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
298-
299- // Create the persister with an invalid directory name and test that the
300- // channel fails to open because the directories fail to be created. There
301- // don't seem to be invalid filename characters on Unix that Rust doesn't
302- // handle, hence why the test is Windows-only.
303- let persister = FilesystemPersister :: new ( ":<>/" . to_string ( ) ) ;
304-
305- let test_txo = OutPoint {
306- txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
307- index : 0
308- } ;
309- match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id. 2 ) {
310- ChannelMonitorUpdateStatus :: PermanentFailure => { } ,
311- _ => panic ! ( "unexpected result from persisting new channel" )
312- }
297+ {
298+ let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
299+ let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
300+ let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
301+
302+ // Create the persister with an invalid directory name and test that the
303+ // channel fails to open because the directories fail to be created. There
304+ // don't seem to be invalid filename characters on Unix that Rust doesn't
305+ // handle, hence why the test is Windows-only.
306+ let persister = FilesystemPersister :: new ( ":<>/" . to_string ( ) ) ;
307+
308+ let test_txo = OutPoint {
309+ txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
310+ index : 0
311+ } ;
312+ match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id. 2 ) {
313+ ChannelMonitorUpdateStatus :: PermanentFailure => { } ,
314+ _ => panic ! ( "unexpected result from persisting new channel" )
315+ }
313316
317+ added_monitors. clear ( ) ;
318+ }
314319 nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
315- added_monitors. clear ( ) ;
316320 }
317321}
318322
0 commit comments