Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Improve the BlockCommitterHttpApi client to use url apis better #2599

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ impl BlockCommitterApi for BlockCommitterHttpApi {
&self,
l2_block_number: u32,
) -> DaBlockCostsResult<Vec<RawDaBlockCosts>> {
// 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 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}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have the same issue with SS service, could you also apply it there please?=D

let full_path = url.join(&path)?;
Comment on lines +134 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what path was it constructing previously?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting "//v1".

let response = self.client.get(full_path).send().await?;
let parsed = response.json::<Vec<RawDaBlockCosts>>().await?;
Ok(parsed)
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/services/shared-sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
35 changes: 22 additions & 13 deletions crates/services/shared-sequencer/src/http_api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Context;
use base64::prelude::*;
use cosmrs::AccountId;
use url::Url;

mod api_types {
use serde::Deserialize;
Expand Down Expand Up @@ -87,8 +88,10 @@ pub async fn estimate_transaction(
let request = SimulateRequest {
tx_bytes: tx_bytes.to_string(),
};
let path = "/cosmos/tx/v1beta1/simulate";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this problem in all requests=D
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. I just found the first one. Didn't look farther.

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?;
Expand All @@ -99,34 +102,39 @@ pub async fn estimate_transaction(
}

pub async fn get_account_prefix(api_url: &str) -> anyhow::Result<String> {
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}"))?;
Ok(resp.bech32_prefix)
}

pub async fn chain_id(api_url: &str) -> anyhow::Result<String> {
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}"))?;
Ok(resp.default_node_info.network)
}

pub async fn config(api_url: &str) -> anyhow::Result<api_types::Config> {
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}"))?;
Ok(resp)
}

pub async fn coin_denom(api_url: &str) -> anyhow::Result<String> {
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}"))?;
Expand All @@ -137,7 +145,9 @@ pub async fn get_account(
api_url: &str,
id: AccountId,
) -> anyhow::Result<AccountMetadata> {
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}"))?;
Expand Down Expand Up @@ -165,10 +175,9 @@ pub struct TopicInfo {

pub async fn get_topic(api_url: &str, id: [u8; 32]) -> anyhow::Result<Option<TopicInfo>> {
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);
}
Expand Down
Loading