From 14c5a4f0256a53305e3a6da0322df768716a47b0 Mon Sep 17 00:00:00 2001 From: Philipp Hoenisch Date: Mon, 3 May 2021 11:48:21 +1000 Subject: [PATCH] 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. --- swap/src/bitcoin/wallet.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 48eb1eb5..64b48939 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -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 { client: Arc>, @@ -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)) }