@@ -397,11 +397,13 @@ where
397
397
/// If `delay_until_height` is set, we will delay the spending until the respective block
398
398
/// height is reached. This can be used to batch spends, e.g., to reduce on-chain fees.
399
399
///
400
+ /// Returns `Err` on persistence failure, in which case the call may be safely retried.
401
+ ///
400
402
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
401
403
pub fn track_spendable_outputs (
402
404
& self , output_descriptors : Vec < SpendableOutputDescriptor > , channel_id : Option < ChannelId > ,
403
405
exclude_static_outputs : bool , delay_until_height : Option < u32 > ,
404
- ) {
406
+ ) -> Result < ( ) , ( ) > {
405
407
let mut relevant_descriptors = output_descriptors
406
408
. into_iter ( )
407
409
. filter ( |desc| {
@@ -411,10 +413,10 @@ where
411
413
. peekable ( ) ;
412
414
413
415
if relevant_descriptors. peek ( ) . is_none ( ) {
414
- return ;
416
+ return Ok ( ( ) ) ;
415
417
}
416
418
417
- let mut spending_tx_opt;
419
+ let spending_tx_opt;
418
420
{
419
421
let mut state_lock = self . sweeper_state . lock ( ) . unwrap ( ) ;
420
422
for descriptor in relevant_descriptors {
@@ -438,16 +440,16 @@ where
438
440
state_lock. outputs . push ( output_info) ;
439
441
}
440
442
spending_tx_opt = self . regenerate_spend_if_necessary ( & mut * state_lock) ;
441
- self . persist_state ( & * state_lock) . unwrap_or_else ( |e| {
443
+ self . persist_state ( & * state_lock) . map_err ( |e| {
442
444
log_error ! ( self . logger, "Error persisting OutputSweeper: {:?}" , e) ;
443
- // Skip broadcasting if the persist failed.
444
- spending_tx_opt = None ;
445
- } ) ;
445
+ } ) ?;
446
446
}
447
447
448
448
if let Some ( spending_tx) = spending_tx_opt {
449
449
self . broadcaster . broadcast_transactions ( & [ & spending_tx] ) ;
450
450
}
451
+
452
+ Ok ( ( ) )
451
453
}
452
454
453
455
/// Returns a list of the currently tracked spendable outputs.
0 commit comments