X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fsweep.rs;h=dd26a8ef844c1a1d4a7bb8c4351481df6d5fe415;hb=336c77c738c792eb8cc1b2ee0e78ff96f106f753;hp=59d3a088c2bf58302383008db6d5b703930013e8;hpb=195e666953afef108ed4c47abba8b6414f8f15fc;p=rust-lightning diff --git a/lightning/src/util/sweep.rs b/lightning/src/util/sweep.rs index 59d3a088..dd26a8ef 100644 --- a/lightning/src/util/sweep.rs +++ b/lightning/src/util/sweep.rs @@ -13,8 +13,8 @@ use crate::chain::channelmonitor::ANTI_REORG_DELAY; use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput}; use crate::io; use crate::ln::msgs::DecodeError; -use crate::ln::ChannelId; -use crate::prelude::Vec; +use crate::ln::types::ChannelId; +use crate::prelude::*; use crate::sign::{ChangeDestinationSource, OutputSpender, SpendableOutputDescriptor}; use crate::sync::Mutex; use crate::util::logger::Logger; @@ -390,31 +390,33 @@ where /// Usually, this should be called based on the values emitted by the /// [`Event::SpendableOutputs`]. /// - /// The given `exclude_static_ouputs` flag controls whether the sweeper will filter out + /// The given `exclude_static_outputs` flag controls whether the sweeper will filter out /// [`SpendableOutputDescriptor::StaticOutput`]s, which may be handled directly by the on-chain /// wallet implementation. /// /// If `delay_until_height` is set, we will delay the spending until the respective block /// height is reached. This can be used to batch spends, e.g., to reduce on-chain fees. /// + /// Returns `Err` on persistence failure, in which case the call may be safely retried. + /// /// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs pub fn track_spendable_outputs( &self, output_descriptors: Vec, channel_id: Option, - exclude_static_ouputs: bool, delay_until_height: Option, - ) { + exclude_static_outputs: bool, delay_until_height: Option, + ) -> Result<(), ()> { let mut relevant_descriptors = output_descriptors .into_iter() .filter(|desc| { - !(exclude_static_ouputs + !(exclude_static_outputs && matches!(desc, SpendableOutputDescriptor::StaticOutput { .. })) }) .peekable(); if relevant_descriptors.peek().is_none() { - return; + return Ok(()); } - let mut spending_tx_opt; + let spending_tx_opt; { let mut state_lock = self.sweeper_state.lock().unwrap(); for descriptor in relevant_descriptors { @@ -438,16 +440,16 @@ where state_lock.outputs.push(output_info); } spending_tx_opt = self.regenerate_spend_if_necessary(&mut *state_lock); - self.persist_state(&*state_lock).unwrap_or_else(|e| { + self.persist_state(&*state_lock).map_err(|e| { log_error!(self.logger, "Error persisting OutputSweeper: {:?}", e); - // Skip broadcasting if the persist failed. - spending_tx_opt = None; - }); + })?; } if let Some(spending_tx) = spending_tx_opt { self.broadcaster.broadcast_transactions(&[&spending_tx]); } + + Ok(()) } /// Returns a list of the currently tracked spendable outputs.