Skip to content

Commit c746f63

Browse files
committed
f Avoid double-lock of best block
1 parent 0118cbc commit c746f63

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/sweep.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ where
6161
pub(crate) fn add_outputs(&self, output_descriptors: Vec<SpendableOutputDescriptor>) {
6262
let mut locked_outputs = self.outputs.lock().unwrap();
6363

64-
let (spending_tx, broadcast_height) = match self.get_spending_tx(&output_descriptors) {
64+
let cur_height = self.best_block.lock().unwrap().height();
65+
66+
let (spending_tx, broadcast_height) = match self.get_spending_tx(&output_descriptors, cur_height) {
6567
Ok(Some(spending_tx)) => {
6668
self.wallet.broadcast_transactions(&[&spending_tx]);
67-
(Some(spending_tx), Some(self.best_block.lock().unwrap().height()))
69+
(Some(spending_tx), Some(cur_height))
6870
}
6971
Ok(None) => {
7072
log_debug!(
@@ -101,15 +103,14 @@ where
101103
}
102104

103105
fn get_spending_tx(
104-
&self, output_descriptors: &Vec<SpendableOutputDescriptor>,
106+
&self, output_descriptors: &Vec<SpendableOutputDescriptor>, cur_height: u32,
105107
) -> Result<Option<Transaction>, ()> {
106108
let tx_feerate = self.wallet.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
107109

108110
let destination_address = self.wallet.get_new_address().map_err(|e| {
109111
log_error!(self.logger, "Failed to get destination address from wallet: {}", e);
110112
})?;
111113

112-
let cur_height = self.best_block.lock().unwrap().height();
113114
let locktime: PackedLockTime =
114115
LockTime::from_height(cur_height).map_or(PackedLockTime::ZERO, |l| l.into());
115116

0 commit comments

Comments
 (0)