@@ -159,13 +159,18 @@ impl FilesystemPersister {
159
159
}
160
160
161
161
impl < ChannelSigner : Sign > chainmonitor:: Persist < ChannelSigner > for FilesystemPersister {
162
- fn persist_new_channel ( & self , funding_txo : OutPoint , monitor : & ChannelMonitor < ChannelSigner > ) -> Result < ( ) , chain:: ChannelMonitorUpdateErr > {
162
+ // TODO: We really need a way for the persister to inform the user that its time to crash/shut
163
+ // down once these start returning failure.
164
+ // A PermanentFailure implies we need to shut down since we're force-closing channels without
165
+ // even broadcasting!
166
+
167
+ fn persist_new_channel ( & self , funding_txo : OutPoint , monitor : & ChannelMonitor < ChannelSigner > , _update_id : chainmonitor:: MonitorUpdateId ) -> Result < ( ) , chain:: ChannelMonitorUpdateErr > {
163
168
let filename = format ! ( "{}_{}" , funding_txo. txid. to_hex( ) , funding_txo. index) ;
164
169
util:: write_to_file ( self . path_to_monitor_data ( ) , filename, monitor)
165
170
. map_err ( |_| chain:: ChannelMonitorUpdateErr :: PermanentFailure )
166
171
}
167
172
168
- fn update_persisted_channel ( & self , funding_txo : OutPoint , _update : & ChannelMonitorUpdate , monitor : & ChannelMonitor < ChannelSigner > ) -> Result < ( ) , chain:: ChannelMonitorUpdateErr > {
173
+ fn update_persisted_channel ( & self , funding_txo : OutPoint , _update : & Option < ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > , _update_id : chainmonitor :: MonitorUpdateId ) -> Result < ( ) , chain:: ChannelMonitorUpdateErr > {
169
174
let filename = format ! ( "{}_{}" , funding_txo. txid. to_hex( ) , funding_txo. index) ;
170
175
util:: write_to_file ( self . path_to_monitor_data ( ) , filename, monitor)
171
176
. map_err ( |_| chain:: ChannelMonitorUpdateErr :: PermanentFailure )
@@ -296,6 +301,8 @@ mod tests {
296
301
nodes[ 1 ] . node . force_close_channel ( & chan. 2 ) . unwrap ( ) ;
297
302
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: HolderForceClosed ) ;
298
303
let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
304
+ let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
305
+ let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
299
306
300
307
// Set the persister's directory to read-only, which should result in
301
308
// returning a permanent failure when we then attempt to persist a
@@ -309,7 +316,7 @@ mod tests {
309
316
txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
310
317
index : 0
311
318
} ;
312
- match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 ) {
319
+ match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id . 2 ) {
313
320
Err ( ChannelMonitorUpdateErr :: PermanentFailure ) => { } ,
314
321
_ => panic ! ( "unexpected result from persisting new channel" )
315
322
}
@@ -333,6 +340,8 @@ mod tests {
333
340
nodes[ 1 ] . node . force_close_channel ( & chan. 2 ) . unwrap ( ) ;
334
341
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: HolderForceClosed ) ;
335
342
let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
343
+ let update_map = nodes[ 1 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) ;
344
+ let update_id = update_map. get ( & added_monitors[ 0 ] . 0 . to_channel_id ( ) ) . unwrap ( ) ;
336
345
337
346
// Create the persister with an invalid directory name and test that the
338
347
// channel fails to open because the directories fail to be created. There
@@ -344,7 +353,7 @@ mod tests {
344
353
txid : Txid :: from_hex ( "8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be" ) . unwrap ( ) ,
345
354
index : 0
346
355
} ;
347
- match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 ) {
356
+ match persister. persist_new_channel ( test_txo, & added_monitors[ 0 ] . 1 , update_id . 2 ) {
348
357
Err ( ChannelMonitorUpdateErr :: PermanentFailure ) => { } ,
349
358
_ => panic ! ( "unexpected result from persisting new channel" )
350
359
}
0 commit comments