Skip to content

Commit

Permalink
Ignore regtest in get_fee_rate_from_mempool_space (#1388)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp authored Oct 29, 2024
1 parent 57f9b46 commit 6ccbe45
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions crates/bitcoin-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ impl BitcoinService {
pub async fn get_fee_rate_as_sat_vb(&self) -> Result<u64, anyhow::Error> {
// 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
}
};
Expand Down Expand Up @@ -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<Amount> {
pub(crate) async fn get_fee_rate_from_mempool_space(
network: bitcoin::Network,
) -> Result<Option<Amount>> {
let url = match network {
bitcoin::Network::Bitcoin => format!(
// Mainnet
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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()
);
}
}

0 comments on commit 6ccbe45

Please sign in to comment.