Skip to content

Commit 87948fa

Browse files
committed
f Return early if nothing to do, scope outputs lock
1 parent 3f26ae9 commit 87948fa

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/sweep.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,26 @@ where
259259
.filter(|desc| !matches!(desc, SpendableOutputDescriptor::StaticOutput { .. }))
260260
.collect::<Vec<_>>();
261261

262-
let mut locked_outputs = self.outputs.lock().unwrap();
263-
for descriptor in non_static_outputs {
264-
let id = self.keys_manager.get_secure_random_bytes();
265-
let output_info = SpendableOutputInfo {
266-
id,
267-
descriptor,
268-
channel_id,
269-
status: SpendableOutputStatus::Pending,
270-
};
262+
if non_static_outputs.is_empty() {
263+
return;
264+
}
271265

272-
locked_outputs.push(output_info.clone());
273-
self.persist_status(&output_info).unwrap_or_else(|e| {
274-
log_error!(self.logger, "Error persisting spendable output status: {:?}", e)
275-
});
266+
{
267+
let mut locked_outputs = self.outputs.lock().unwrap();
268+
for descriptor in non_static_outputs {
269+
let id = self.keys_manager.get_secure_random_bytes();
270+
let output_info = SpendableOutputInfo {
271+
id,
272+
descriptor,
273+
channel_id,
274+
status: SpendableOutputStatus::Pending,
275+
};
276+
277+
locked_outputs.push(output_info.clone());
278+
self.persist_status(&output_info).unwrap_or_else(|e| {
279+
log_error!(self.logger, "Error persisting spendable output status: {:?}", e)
280+
});
281+
}
276282
}
277283

278284
self.rebroadcast_if_necessary();

0 commit comments

Comments
 (0)