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

Use reqwest, remove http, ureq and hyper #1632

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

overcat
Copy link
Contributor

@overcat overcat commented Sep 27, 2024

What

We only use reqwest to make HTTP requests in our code, no longer directly using http, ureq, and hyper, to enhance consistency.

Why

fix #1629

Known limitations

N/A

@overcat
Copy link
Contributor Author

overcat commented Sep 27, 2024

CI failed, possibly due to #1631

Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

This looks fantastic. One question inline. Also one ask, but it can be deferred and isn't required.

cmd/soroban-cli/src/commands/snapshot/create.rs Outdated Show resolved Hide resolved
.bytes_stream()
.map(|result| result.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e)));
let stream_reader = StreamReader::new(stream);
let buf_reader = BufReader::new(stream_reader);
Copy link
Member

Choose a reason for hiding this comment

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

Why the introduction of the buf reader before the GzipDecoder? Where to place the buffers is somewhat sensitive in this area code to performance. I saw massive differences depending on where they were placed. I'll test it out on my side too before merging to see what the performance is like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't seem necessary. I saw this kind of writing in libsql, and I'll do some benchmarking later to see the performance differences between them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the source code perspective, using it should theoretically bring performance improvements. However, when using snapshot create, we don't notice any performance differences between the two implementations.

cmd/soroban-cli/src/config/network.rs Show resolved Hide resolved
cmd/soroban-cli/src/config/network.rs Outdated Show resolved Hide resolved
Comment on lines 211 to 219

#[tokio::test]
async fn test_helper_url_test_network() {
// It might be a bit difficult to conduct client mock here.
let friendbot_url = "https://friendbot.stellar.org/secret_key";
let addr = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";
let url = Url::from_str(&format!("{friendbot_url}?addr={addr}")).unwrap();
assert_eq!(url.as_str(), "https://friendbot.stellar.org/secret_key?addr=GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI");
}
Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't appear to actually test any logic in the application.

Suggested change
#[tokio::test]
async fn test_helper_url_test_network() {
// It might be a bit difficult to conduct client mock here.
let friendbot_url = "https://friendbot.stellar.org/secret_key";
let addr = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";
let url = Url::from_str(&format!("{friendbot_url}?addr={addr}")).unwrap();
assert_eq!(url.as_str(), "https://friendbot.stellar.org/secret_key?addr=GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the mock client here is a bit complex, I only verified that let url = Url::from_str(&format!("{friendbot_url}?addr={addr}")).unwrap(); works as expected. This line of code is copied from the codebase. If you would like me to remove it, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added mock testing.

cmd/soroban-cli/src/upgrade_check.rs Outdated Show resolved Hide resolved
"json",
"blocking",
"stream",
"native-tls-vendored",
Copy link
Member

Choose a reason for hiding this comment

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

We should check which tls the https://github.com/stellar/rs-stellar-rpc-client uses, so that both ideally use the same. I thought it used rustls, but I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stellar-rpc-client v21.4.0
├── jsonrpsee-http-client v0.20.3
│   ├── hyper-rustls v0.24.2
...

I think it uses hyper-rustls. Do you want to use hyper-rustls on all platforms? Reqwest defaults to using the system's TLS library. See https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@overcat overcat changed the title Use reqwest and remove http, ureq and hyper Use reqwest, remove http, ureq and hyper Sep 27, 2024
let _mock = server
.mock("POST", "/")
.with_body_from_request(|req| {
let body: Value = serde_json::from_slice(req.body().unwrap()).unwrap();
Copy link
Contributor Author

@overcat overcat Sep 27, 2024

Choose a reason for hiding this comment

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

I noticed that other place used httpmock, but it doesn't meet our needs; it can't retrieve the id from the request. So, I add mockito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog (Not Ready)
Development

Successfully merging this pull request may close these issues.

Consolidate HTTP client libraries to reduce complexity
2 participants