From 83bf21a490f810f661bb4b388652872b430f7527 Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Sat, 18 Jan 2025 12:44:21 -0700 Subject: [PATCH 1/6] Use Url apis to build the full url path --- .../src/v1/da_source_service/block_committer_costs.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs index 2e93ed452d..c48b86e896 100644 --- a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs +++ b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs @@ -131,8 +131,9 @@ impl BlockCommitterApi for BlockCommitterHttpApi { // Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5 if let Some(url) = &self.url { tracing::debug!("getting da costs by l2 block number: {l2_block_number}"); - let formatted_url = format!("{url}/v1/costs?variant=specific&value={l2_block_number}&limit={NUMBER_OF_BUNDLES}"); - let response = self.client.get(formatted_url).send().await?; + let path = format!("/v1/costs?variant=specific&value={l2_block_number}&limit={NUMBER_OF_BUNDLES}"); + let full_path = url.join(&path)?; + let response = self.client.get(full_path).send().await?; let parsed = response.json::>().await?; Ok(parsed) } else { @@ -147,6 +148,7 @@ mod test_block_committer_http_api { use super::*; use fake_server::FakeServer; + use url::Url; #[test] fn get_costs_by_l2_block_number__when_url_is_none__then_returns_empty_vec() { From b9977d40aad69afb237d0898c814551f7f1015b9 Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Sat, 18 Jan 2025 12:56:42 -0700 Subject: [PATCH 2/6] Remove unused import --- .../src/v1/da_source_service/block_committer_costs.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs index c48b86e896..3cf295c32c 100644 --- a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs +++ b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs @@ -148,7 +148,6 @@ mod test_block_committer_http_api { use super::*; use fake_server::FakeServer; - use url::Url; #[test] fn get_costs_by_l2_block_number__when_url_is_none__then_returns_empty_vec() { From e8d72c830d45afaf1b479a61d28a9ee840634ffd Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Sat, 18 Jan 2025 13:03:08 -0700 Subject: [PATCH 3/6] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0513c5eb1e..b7c557b4c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id. +### Fixed +- [2599](https://github.com/FuelLabs/fuel-core/pull/2599): Use the proper `url` apis to construct full url path in `BlockCommitterHttpApi` client + ## [Version 0.41.0] ### Added From 968fd69e3167e35915d1c5492cce51e2717a62ee Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Sat, 18 Jan 2025 13:08:08 -0700 Subject: [PATCH 4/6] Make comment more inclusive --- .../src/v1/da_source_service/block_committer_costs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs index 3cf295c32c..429880bae4 100644 --- a/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs +++ b/crates/services/gas_price_service/src/v1/da_source_service/block_committer_costs.rs @@ -128,7 +128,7 @@ impl BlockCommitterApi for BlockCommitterHttpApi { &self, l2_block_number: u32, ) -> DaBlockCostsResult> { - // Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5 + // Specific: http://committer.url/v1/costs?variant=specific&value=19098935&limit=5 if let Some(url) = &self.url { tracing::debug!("getting da costs by l2 block number: {l2_block_number}"); let path = format!("/v1/costs?variant=specific&value={l2_block_number}&limit={NUMBER_OF_BUNDLES}"); From cdfec32986a3b0831dbbe823e27ead684d8a6164 Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Mon, 20 Jan 2025 13:55:02 -0700 Subject: [PATCH 5/6] Apply fix to shared sequencer service --- Cargo.lock | 1 + crates/services/shared-sequencer/Cargo.toml | 1 + crates/services/shared-sequencer/src/http_api.rs | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9dd90e6a94..6ea19abf74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3891,6 +3891,7 @@ dependencies = [ "tendermint-rpc", "tokio", "tracing", + "url", ] [[package]] diff --git a/crates/services/shared-sequencer/Cargo.toml b/crates/services/shared-sequencer/Cargo.toml index f10f592dcf..1d9a68b1c6 100644 --- a/crates/services/shared-sequencer/Cargo.toml +++ b/crates/services/shared-sequencer/Cargo.toml @@ -28,6 +28,7 @@ serde_json = "1.0" tendermint-rpc = { version = "0.36", features = ["http-client"] } tokio = { workspace = true } tracing = { workspace = true } +url = { workspace = true } [features] test-helpers = [] diff --git a/crates/services/shared-sequencer/src/http_api.rs b/crates/services/shared-sequencer/src/http_api.rs index 96233f0189..49d26d3507 100644 --- a/crates/services/shared-sequencer/src/http_api.rs +++ b/crates/services/shared-sequencer/src/http_api.rs @@ -1,6 +1,7 @@ use anyhow::Context; use base64::prelude::*; use cosmrs::AccountId; +use url::Url; mod api_types { use serde::Deserialize; @@ -87,8 +88,10 @@ pub async fn estimate_transaction( let request = SimulateRequest { tx_bytes: tx_bytes.to_string(), }; + let path = "/cosmos/tx/v1beta1/simulate"; + let full_url = Url::parse(api_url)?.join(path).unwrap(); let r = reqwest::Client::new() - .post(format!("{api_url}/cosmos/tx/v1beta1/simulate")) + .post(full_url) .json(&request) .send() .await?; From c57b645a582c0420369ca571fb1271aa3ba9f23b Mon Sep 17 00:00:00 2001 From: Mitch Turner Date: Mon, 20 Jan 2025 15:51:06 -0700 Subject: [PATCH 6/6] Add missing api endpoints --- .../services/shared-sequencer/src/http_api.rs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/services/shared-sequencer/src/http_api.rs b/crates/services/shared-sequencer/src/http_api.rs index 49d26d3507..e1a3c8c531 100644 --- a/crates/services/shared-sequencer/src/http_api.rs +++ b/crates/services/shared-sequencer/src/http_api.rs @@ -102,7 +102,9 @@ pub async fn estimate_transaction( } pub async fn get_account_prefix(api_url: &str) -> anyhow::Result { - let r = reqwest::get(format!("{api_url}/cosmos/auth/v1beta1/bech32")).await?; + let path = "/cosmos/auth/v1beta1/bech32"; + let full_url = Url::parse(api_url)?.join(path).unwrap(); + let r = reqwest::get(full_url).await?; let text = r.text().await?; let resp: api_types::AccountPrefix = serde_json::from_str(&text).with_context(|| format!("response text {text}"))?; @@ -110,10 +112,9 @@ pub async fn get_account_prefix(api_url: &str) -> anyhow::Result { } pub async fn chain_id(api_url: &str) -> anyhow::Result { - let r = reqwest::get(format!( - "{api_url}/cosmos/base/tendermint/v1beta1/node_info" - )) - .await?; + let path = "/cosmos/base/tendermint/v1beta1/node_info"; + let full_url = Url::parse(api_url)?.join(path).unwrap(); + let r = reqwest::get(full_url).await?; let text = r.text().await?; let resp: api_types::NodeInfo = serde_json::from_str(&text).with_context(|| format!("response text {text}"))?; @@ -121,7 +122,9 @@ pub async fn chain_id(api_url: &str) -> anyhow::Result { } pub async fn config(api_url: &str) -> anyhow::Result { - let r = reqwest::get(format!("{api_url}/cosmos/base/node/v1beta1/config")).await?; + let path = "/cosmos/base/node/v1beta1/config"; + let full_url = Url::parse(api_url)?.join(path).unwrap(); + let r = reqwest::get(full_url).await?; let text = r.text().await?; let resp: api_types::Config = serde_json::from_str(&text).with_context(|| format!("response text {text}"))?; @@ -129,7 +132,9 @@ pub async fn config(api_url: &str) -> anyhow::Result { } pub async fn coin_denom(api_url: &str) -> anyhow::Result { - let r = reqwest::get(format!("{api_url}/cosmos/staking/v1beta1/params")).await?; + let path = "/cosmos/staking/v1beta1/params"; + let full_url = Url::parse(api_url)?.join(path).unwrap(); + let r = reqwest::get(full_url).await?; let text = r.text().await?; let resp: api_types::StakingParams = serde_json::from_str(&text).with_context(|| format!("response text {text}"))?; @@ -140,7 +145,9 @@ pub async fn get_account( api_url: &str, id: AccountId, ) -> anyhow::Result { - let r = reqwest::get(format!("{api_url}/cosmos/auth/v1beta1/accounts/{id}")).await?; + let path = format!("/cosmos/auth/v1beta1/accounts/{id}"); + let full_url = Url::parse(api_url)?.join(&path).unwrap(); + let r = reqwest::get(full_url).await?; let text = r.text().await?; let resp: api_types::AccountResponse = serde_json::from_str(&text).with_context(|| format!("response text {text}"))?; @@ -168,10 +175,9 @@ pub struct TopicInfo { pub async fn get_topic(api_url: &str, id: [u8; 32]) -> anyhow::Result> { let id_b64 = BASE64_STANDARD.encode(id); - let r = reqwest::get(format!( - "{api_url}/fuelsequencer/sequencing/v1/topic/{id_b64}" - )) - .await?; + let path = format!("/fuelsequencer/sequencing/v1/topic/{id_b64}"); + let full_url = Url::parse(api_url)?.join(&path).unwrap(); + let r = reqwest::get(full_url).await?; if r.status() == 404 { return Ok(None); }