@@ -153,11 +153,13 @@ pub enum ChannelMonitorUpdateErr {
153
153
/// corrupted.
154
154
/// Contains a human-readable error message.
155
155
#[ derive( Debug ) ]
156
- pub struct MonitorUpdateError {
157
- /// The human-readable error message string.
158
- pub msg : & ' static str ,
159
- /// A monitor update may have an error but still need to be persisted to disk.
160
- pub persist_updated_monitor : bool
156
+ pub enum MonitorUpdateError {
157
+ /// While updating the monitor generated an error, still persist the monitor as it has changed
158
+ /// and needs to be updated on-disk. Contains a human-readable error message.
159
+ PersistMonitor ( & ' static str ) ,
160
+ /// Updating the monitor generated an error, no need to persist the updated monitor. Contains
161
+ /// a human-readable error message.
162
+ NoPersistMonitor ( & ' static str )
161
163
}
162
164
163
165
/// An event to be processed by the ChannelManager.
@@ -265,10 +267,7 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref, D: Deref>
265
267
/// Creates a new object which can be used to monitor several channels given the chain
266
268
/// interface with which to register to receive notifications.
267
269
pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , data_persister : D ) -> Result < Self , ChannelMonitorUpdateErr > {
268
- let monitors = match data_persister. load_channel_data ( ) {
269
- Ok ( mons) => mons,
270
- Err ( e) => return Err ( e)
271
- } ;
270
+ let monitors = data_persister. load_channel_data ( ) ?;
272
271
273
272
Ok ( Self {
274
273
monitors : Mutex :: new ( monitors) ,
@@ -294,14 +293,12 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref, D: Deref>
294
293
} ,
295
294
hash_map:: Entry :: Vacant ( e) => e,
296
295
} ;
297
- {
298
- match self . data_persister . persist_channel_data ( outpoint, & monitor) {
299
- Err ( e) => {
300
- log_error ! ( self . logger, "Failed to persist new channel data" ) ;
301
- return Err ( e) ;
302
- } ,
303
- _ => { }
304
- }
296
+ match self . data_persister . persist_channel_data ( outpoint, & monitor) {
297
+ Err ( e) => {
298
+ log_error ! ( self . logger, "Failed to persist new channel data" ) ;
299
+ return Err ( e) ;
300
+ } ,
301
+ _ => { }
305
302
}
306
303
{
307
304
let funding_txo = monitor. get_funding_txo ( ) ;
@@ -327,15 +324,21 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref, D: Deref>
327
324
log_trace ! ( self . logger, "Updating Channel Monitor for channel {}" , log_funding_info!( orig_monitor) ) ;
328
325
let mut should_persist = true ;
329
326
let res = orig_monitor. update_monitor ( & update, & self . broadcaster , & self . logger ) ;
330
- if let Err ( MonitorUpdateError { msg, persist_updated_monitor } ) = res {
331
- log_error ! ( self . logger, "{}" , msg) ;
332
- should_persist = persist_updated_monitor;
327
+ match res {
328
+ Err ( MonitorUpdateError :: PersistMonitor ( msg) ) => {
329
+ log_error ! ( self . logger, "{}" , msg) ;
330
+ } ,
331
+ Err ( MonitorUpdateError :: NoPersistMonitor ( msg) ) => {
332
+ log_error ! ( self . logger, "{}" , msg) ;
333
+ should_persist = false ;
334
+ } ,
335
+ Ok ( ( ) ) => { } ,
333
336
}
334
337
if should_persist {
335
- match self . data_persister . update_channel_data ( outpoint, & update, orig_monitor) {
336
- Err ( e) => return Err ( e) ,
337
- _ => { }
338
- }
338
+ match self . data_persister . update_channel_data ( outpoint, & update, orig_monitor) {
339
+ Err ( e) => return Err ( e) ,
340
+ _ => { }
341
+ }
339
342
}
340
343
if res. is_err ( ) { return Err ( ChannelMonitorUpdateErr :: PermanentFailure ) ; }
341
344
} else {
@@ -1227,10 +1230,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1227
1230
/// commitment transaction's secret, they are de facto pruned (we can use revocation key).
1228
1231
fn provide_secret ( & mut self , idx : u64 , secret : [ u8 ; 32 ] ) -> Result < ( ) , MonitorUpdateError > {
1229
1232
if let Err ( ( ) ) = self . commitment_secrets . provide_secret ( idx, secret) {
1230
- return Err ( MonitorUpdateError {
1231
- msg : "Previous secret did not match new one" ,
1232
- persist_updated_monitor : false
1233
- } ) ;
1233
+ return Err ( MonitorUpdateError :: NoPersistMonitor ( "Previous secret did not match new one" ) ) ;
1234
1234
}
1235
1235
1236
1236
// Prune HTLCs from the previous remote commitment tx so we don't generate failure/fulfill
@@ -1331,10 +1331,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1331
1331
/// Panics if set_on_local_tx_csv has never been called.
1332
1332
fn provide_latest_local_commitment_tx_info ( & mut self , commitment_tx : LocalCommitmentTransaction , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ) -> Result < ( ) , MonitorUpdateError > {
1333
1333
if self . local_tx_signed {
1334
- return Err ( MonitorUpdateError {
1335
- msg : "A local commitment tx has already been signed, no new local commitment txn can be sent to our counterparty" ,
1336
- persist_updated_monitor : false
1337
- } ) ;
1334
+ return Err ( MonitorUpdateError :: NoPersistMonitor (
1335
+ "A local commitment tx has already been signed, no new local commitment txn can be sent to our counterparty" ) ) ;
1338
1336
}
1339
1337
let txid = commitment_tx. txid ( ) ;
1340
1338
let sequence = commitment_tx. unsigned_tx . input [ 0 ] . sequence as u64 ;
@@ -1355,10 +1353,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1355
1353
// for which you want to spend outputs. We're NOT robust again this scenario right
1356
1354
// now but we should consider it later.
1357
1355
if let Err ( _) = self . onchain_tx_handler . provide_latest_local_tx ( commitment_tx) {
1358
- return Err ( MonitorUpdateError {
1359
- msg : "Local commitment signed has already been signed, no further update of LOCAL commitment transaction is allowed" ,
1360
- persist_updated_monitor : false
1361
- } ) ;
1356
+ return Err ( MonitorUpdateError :: PersistMonitor (
1357
+ "Local commitment signed has already been signed, no further update of LOCAL commitment transaction is allowed" ) ) ;
1362
1358
}
1363
1359
self . current_local_commitment_number = 0xffff_ffff_ffff - ( ( ( ( sequence & 0xffffff ) << 3 * 8 ) | ( locktime as u64 & 0xffffff ) ) ^ self . commitment_transaction_number_obscure_factor ) ;
1364
1360
mem:: swap ( & mut new_local_commitment_tx, & mut self . current_local_commitment_tx ) ;
0 commit comments