Skip to content

Commit a2cc359

Browse files
committed
fix: do not panic if electrum server does not support fee estimation
1 parent 44fafc7 commit a2cc359

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

swap/src/bitcoin/wallet.rs

+6
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ where
468468
) -> Result<bitcoin::Amount> {
469469
let client = self.client.lock().await;
470470
let fee_rate = client.estimate_feerate(self.target_block)?;
471+
471472
let min_relay_fee = client.min_relay_fee()?;
472473

473474
estimate_fee(weight, transfer_amount, fee_rate, min_relay_fee)
@@ -871,6 +872,11 @@ impl EstimateFeeRate for Client {
871872
// https://github.com/romanz/electrs/blob/f9cf5386d1b5de6769ee271df5eef324aa9491bc/src/rpc.rs#L213
872873
// Returned estimated fees are per BTC/kb.
873874
let fee_per_byte = self.electrum.estimate_fee(target_block)?;
875+
876+
if fee_per_byte < 0.0 {
877+
bail!("Fee per byte returned by electrum server is negative: {}. This may indicate that fee estimation is not supported by this server", fee_per_byte);
878+
}
879+
874880
// we do not expect fees being that high.
875881
#[allow(clippy::cast_possible_truncation)]
876882
Ok(FeeRate::from_btc_per_kvb(fee_per_byte as f32))

0 commit comments

Comments
 (0)