Skip to content

Commit 326cc38

Browse files
committed
f Make sure transaction is relayable
.. 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.
1 parent e86d843 commit 326cc38

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/wallet.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config::BDK_WALLET_SYNC_TIMEOUT_SECS;
44
use crate::fee_estimator::{ConfirmationTarget, FeeEstimator};
55
use crate::Error;
66

7-
use lightning::chain::chaininterface::BroadcasterInterface;
7+
use lightning::chain::chaininterface::{BroadcasterInterface, FEERATE_FLOOR_SATS_PER_KW};
88

99
use lightning::events::bump_transaction::{Utxo, WalletSource};
1010
use lightning::ln::msgs::{DecodeError, UnsignedGossipMessage};
@@ -258,13 +258,9 @@ where
258258
OnchainSendType::SendAllRetainingReserve { cur_anchor_reserve_sats } => {
259259
let spendable_amount_sats =
260260
self.get_spendable_amount_sats(cur_anchor_reserve_sats).unwrap_or(0);
261-
// TODO: can we make this closer resemble the actual transaction?
262-
// As draining the wallet always will only add one output, this method likely
263-
// under-estimates the fee rate a bit.
264261
let mut tmp_tx_builder = locked_wallet.build_tx();
265262
tmp_tx_builder
266-
.drain_wallet()
267-
.drain_to(address.script_pubkey())
263+
.add_recipient(address.script_pubkey(), spendable_amount_sats)
268264
.fee_rate(fee_rate)
269265
.enable_rbf();
270266
let tmp_tx_details = match tmp_tx_builder.finish() {
@@ -279,7 +275,8 @@ where
279275
},
280276
};
281277

282-
let estimated_tx_fee_sats = tmp_tx_details.fee.unwrap_or(0);
278+
let estimated_tx_fee_sats =
279+
tmp_tx_details.fee.unwrap_or(0).max(FEERATE_FLOOR_SATS_PER_KW as u64);
283280
let estimated_spendable_amount_sats =
284281
spendable_amount_sats.saturating_sub(estimated_tx_fee_sats);
285282

0 commit comments

Comments
 (0)