Add upper bound for bitcoin fees of 100,000 satoshi.

Fees are hard to compute and it is too easy to get wrong and lose a lot of money. Hence, a hardcoded maximum of 100,000 satoshi for a single transaction is in place.
pull/466/head
Philipp Hoenisch 3 years ago
parent 46e0449b8e
commit 14c5a4f025
No known key found for this signature in database
GPG Key ID: E5F8E74C672BC666

@ -22,6 +22,7 @@ use std::time::{Duration, Instant};
use tokio::sync::{watch, Mutex};
const SLED_TREE_NAME: &str = "default_tree";
const MAX_TX_FEE: u64 = 100_000;
pub struct Wallet<B = ElectrumBlockchain, D = bdk::sled::Tree, C = Client> {
client: Arc<Mutex<C>>,
@ -344,6 +345,7 @@ where
fee_rate,
sats_per_vbyte
);
if sats_per_vbyte < min_relay_fee.as_sat() {
tracing::warn!(
"Estimated fee of {} is smaller than the min relay fee, defaulting to min relay fee {}",
@ -351,6 +353,12 @@ where
min_relay_fee.as_sat()
);
Ok(min_relay_fee)
} else if sats_per_vbyte > MAX_TX_FEE {
tracing::warn!(
"Hard bound of max transaction fees reached. Falling back to: {} sats",
MAX_TX_FEE
);
Ok(bitcoin::Amount::from_sat(MAX_TX_FEE))
} else {
Ok(bitcoin::Amount::from_sat(sats_per_vbyte))
}

Loading…
Cancel
Save