diff --git a/src/wallet.rs b/src/wallet.rs index c00150af..948968a1 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -4,7 +4,7 @@ use crate::config::BDK_WALLET_SYNC_TIMEOUT_SECS; use crate::fee_estimator::{ConfirmationTarget, FeeEstimator}; use crate::Error; -use lightning::chain::chaininterface::BroadcasterInterface; +use lightning::chain::chaininterface::{BroadcasterInterface, FEERATE_FLOOR_SATS_PER_KW}; use lightning::events::bump_transaction::{Utxo, WalletSource}; use lightning::ln::msgs::{DecodeError, UnsignedGossipMessage}; @@ -258,13 +258,9 @@ where OnchainSendType::SendAllRetainingReserve { cur_anchor_reserve_sats } => { let spendable_amount_sats = self.get_spendable_amount_sats(cur_anchor_reserve_sats).unwrap_or(0); - // TODO: can we make this closer resemble the actual transaction? - // As draining the wallet always will only add one output, this method likely - // under-estimates the fee rate a bit. let mut tmp_tx_builder = locked_wallet.build_tx(); tmp_tx_builder - .drain_wallet() - .drain_to(address.script_pubkey()) + .add_recipient(address.script_pubkey(), spendable_amount_sats) .fee_rate(fee_rate) .enable_rbf(); let tmp_tx_details = match tmp_tx_builder.finish() { @@ -279,7 +275,8 @@ where }, }; - let estimated_tx_fee_sats = tmp_tx_details.fee.unwrap_or(0); + let estimated_tx_fee_sats = + tmp_tx_details.fee.unwrap_or(0).max(FEERATE_FLOOR_SATS_PER_KW as u64); let estimated_spendable_amount_sats = spendable_amount_sats.saturating_sub(estimated_tx_fee_sats);