From 1750be4d365bd1d02a90855516fe805e3f094b80 Mon Sep 17 00:00:00 2001 From: Max Fang Date: Tue, 4 Jul 2023 20:21:23 -0700 Subject: [PATCH] bugfix: Return early if no non-static outputs If there is a cooperative closure, there will only be one output to spend, and it will be a `StaticOutput`. Since `WalletKeysManager`'s `spend_spendable_outputs` filters out static outputs, `KeysManager`'s `spend_spendable_outputs` gets passed an empty list of descriptors to spend, which results in an error (with no further information provided). --- src/event.rs | 5 ++++- src/wallet.rs | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/event.rs b/src/event.rs index 285856291..1a0c99231 100644 --- a/src/event.rs +++ b/src/event.rs @@ -564,7 +564,10 @@ where &Secp256k1::new(), ); match res { - Ok(spending_tx) => self.wallet.broadcast_transaction(&spending_tx), + Ok(Some(spending_tx)) => self.wallet.broadcast_transaction(&spending_tx), + Ok(None) => { + log_info!(self.logger, "All outputs already handled"); + } Err(err) => { log_error!(self.logger, "Error spending outputs: {:?}", err); } diff --git a/src/wallet.rs b/src/wallet.rs index 78fa6e567..8d1310798 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -362,19 +362,24 @@ where &self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec, change_destination_script: Script, feerate_sat_per_1000_weight: u32, secp_ctx: &Secp256k1, - ) -> Result { + ) -> Result, ()> { let only_non_static = &descriptors .iter() .filter(|desc| !matches!(desc, SpendableOutputDescriptor::StaticOutput { .. })) .copied() .collect::>(); - self.inner.spend_spendable_outputs( - only_non_static, - outputs, - change_destination_script, - feerate_sat_per_1000_weight, - secp_ctx, - ) + if only_non_static.is_empty() { + return Ok(None); + } + self.inner + .spend_spendable_outputs( + only_non_static, + outputs, + change_destination_script, + feerate_sat_per_1000_weight, + secp_ctx, + ) + .map(Some) } pub fn sign_message(&self, msg: &[u8]) -> Result {