Skip to content

Commit

Permalink
f Make sure transaction is relayable
Browse files Browse the repository at this point in the history
.. rather than undercutting the fee, we now choose a method that might
slightly overestimate fees, ensuring its relayability. We also make sure
the net fee is always larger than the fee rate floor.
  • Loading branch information
tnull committed Aug 29, 2024
1 parent e561eb6 commit b37f37c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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() {
Expand All @@ -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);

Expand Down

0 comments on commit b37f37c

Please sign in to comment.