Skip to content

Commit 9bee392

Browse files
committed
f Fee estimates
1 parent 37752bf commit 9bee392

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/access.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use bitcoin::{BlockHash, Script, Transaction, Txid};
1818

1919
use std::sync::{Arc, Mutex};
2020

21+
/// The minimum feerate we are allowed to send, as specify by LDK.
22+
const MIN_FEERATE: u32 = 253;
23+
2124
pub struct LdkLiteChainAccess<D>
2225
where
2326
D: BatchDatabase,
@@ -261,8 +264,10 @@ where
261264
{
262265
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
263266
let num_blocks = num_blocks_from_conf_target(confirmation_target);
264-
self.blockchain.estimate_fee(num_blocks).map_or(253, |fee_rate| fee_rate.fee_wu(1000))
265-
as u32
267+
let fallback_fee = fallback_fee_from_conf_target(confirmation_target);
268+
self.blockchain
269+
.estimate_fee(num_blocks)
270+
.map_or(fallback_fee, |fee_rate| (fee_rate.fee_wu(1000) as u32).max(MIN_FEERATE)) as u32
266271
}
267272
}
268273

@@ -271,7 +276,10 @@ where
271276
D: BatchDatabase,
272277
{
273278
fn broadcast_transaction(&self, tx: &Transaction) {
274-
self.blockchain.broadcast(tx).ok();
279+
match self.blockchain.broadcast(tx) {
280+
Ok(_) => {}
281+
Err(err) => log_error!(self.logger, "Failed to broadcast transaction: {}", err),
282+
}
275283
}
276284
}
277285

@@ -318,8 +326,16 @@ where
318326

319327
fn num_blocks_from_conf_target(confirmation_target: ConfirmationTarget) -> usize {
320328
match confirmation_target {
321-
ConfirmationTarget::Background => 6,
322-
ConfirmationTarget::Normal => 3,
323-
ConfirmationTarget::HighPriority => 1,
329+
ConfirmationTarget::Background => 12,
330+
ConfirmationTarget::Normal => 6,
331+
ConfirmationTarget::HighPriority => 3,
332+
}
333+
}
334+
335+
fn fallback_fee_from_conf_target(confirmation_target: ConfirmationTarget) -> u32 {
336+
match confirmation_target {
337+
ConfirmationTarget::Background => MIN_FEERATE,
338+
ConfirmationTarget::Normal => 2000,
339+
ConfirmationTarget::HighPriority => 5000,
324340
}
325341
}

0 commit comments

Comments
 (0)