From 6ccbe4577868e6432a598824ebf473d31a6cb486 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 29 Oct 2024 20:45:18 -0300 Subject: [PATCH] Ignore regtest in get_fee_rate_from_mempool_space (#1388) --- crates/bitcoin-da/src/service.rs | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/bitcoin-da/src/service.rs b/crates/bitcoin-da/src/service.rs index 4f5f318d8..1cddc5c34 100644 --- a/crates/bitcoin-da/src/service.rs +++ b/crates/bitcoin-da/src/service.rs @@ -569,9 +569,9 @@ impl BitcoinService { pub async fn get_fee_rate_as_sat_vb(&self) -> Result { // If network is regtest or signet, mempool space is not available let smart_fee = match get_fee_rate_from_mempool_space(self.network).await { - Ok(fee_rate) => Some(fee_rate), + Ok(fee_rate) => fee_rate, Err(e) => { - tracing::warn!(?e, "Failed to get fee rate from mempool.space"); + tracing::error!(?e, "Failed to get fee rate from mempool.space"); self.client.estimate_smart_fee(1, None).await?.fee_rate } }; @@ -1152,7 +1152,9 @@ fn calculate_witness_root(txdata: &[TransactionWrapper]) -> [u8; 32] { BitcoinMerkleTree::new(hashes).root() } -pub(crate) async fn get_fee_rate_from_mempool_space(network: bitcoin::Network) -> Result { +pub(crate) async fn get_fee_rate_from_mempool_space( + network: bitcoin::Network, +) -> Result> { let url = match network { bitcoin::Network::Bitcoin => format!( // Mainnet @@ -1164,9 +1166,8 @@ pub(crate) async fn get_fee_rate_from_mempool_space(network: bitcoin::Network) - MEMPOOL_SPACE_URL, MEMPOOL_SPACE_RECOMMENDED_FEE_ENDPOINT ), _ => { - return Err(anyhow!( - "Unsupported network for mempool space fee estimation" - )) + trace!("Unsupported network for mempool space fee estimation"); + return Ok(None); } }; let fee_rate = reqwest::get(url) @@ -1178,7 +1179,7 @@ pub(crate) async fn get_fee_rate_from_mempool_space(network: bitcoin::Network) - .map(|fee| Amount::from_sat(fee * 1000)) // multiply by 1000 to convert to sat/vkb .ok_or(anyhow!("Failed to get fee rate from mempool space"))?; - Ok(fee_rate) + Ok(Some(fee_rate)) } pub fn get_relevant_blobs_from_txs_light_client( @@ -1706,11 +1707,17 @@ mod tests { let _fee_rate = get_fee_rate_from_mempool_space(bitcoin::Network::Testnet) .await .unwrap(); - assert!(get_fee_rate_from_mempool_space(bitcoin::Network::Regtest) - .await - .is_err()); - assert!(get_fee_rate_from_mempool_space(bitcoin::Network::Signet) - .await - .is_err()); + assert_eq!( + None, + get_fee_rate_from_mempool_space(bitcoin::Network::Regtest) + .await + .unwrap() + ); + assert_eq!( + None, + get_fee_rate_from_mempool_space(bitcoin::Network::Signet) + .await + .unwrap() + ); } }