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

refactor: use axum instead of hyper #17

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

ayeletstarkware
Copy link
Contributor

@ayeletstarkware ayeletstarkware commented Apr 2, 2024

This change is Reviewable

Copy link
Contributor

@MohammadNassar1 MohammadNassar1 left a comment

Choose a reason for hiding this comment

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

Nice!

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ayeletstarkware and @giladchase)


-- commits line 5 at r1:
Please squash.

Code quote:

- b8a41a2: Implement add_transaction in Gateway

- ca6fa8f: refactor(gateway): use axum instead of hyper

crates/gateway/src/gateway_test.rs line 18 at r1 (raw file):

async fn test_add_transaction(#[case] json_file_path: &str, #[case] expected_response: &str) {
    let json_str = std::fs::read_to_string(json_file_path).expect("Failed to read JSON file");
    let json: ExternalTransaction = serde_json::from_str(&json_str).expect("Failed to parse JSON");

Suggestion:

transaction

crates/gateway/src/gateway_test.rs line 19 at r1 (raw file):

    let json_str = std::fs::read_to_string(json_file_path).expect("Failed to read JSON file");
    let json: ExternalTransaction = serde_json::from_str(&json_str).expect("Failed to parse JSON");
    let response = add_transaction(json.clone().into()).await.into_response();

Why clone is needed here?

Code quote:

json.clone()

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/implement-add-transaction-in-gateway branch 3 times, most recently from 0b0e349 to ff48db7 Compare April 3, 2024 09:50
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/axum-instead-of-hyper branch from ca6fa8f to 77417a6 Compare April 3, 2024 10:02
Copy link
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


-- commits line 5 at r1:

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Please squash.

Done.


crates/gateway/src/gateway_test.rs line 19 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Why clone is needed here?

not needed

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/implement-add-transaction-in-gateway branch 2 times, most recently from ef951a0 to 1c3d503 Compare April 3, 2024 10:43
Copy link
Collaborator

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 4 files at r1.
Reviewable status: 1 of 4 files reviewed, 6 unresolved discussions (waiting on @ayeletstarkware and @MohammadNassar1)


crates/gateway/src/gateway.rs line 29 at r1 (raw file):

            .route("/add_transaction", post(add_transaction));

        let _ = axum::Server::bind(&addr)

Plz add comment on what this does and how it behaves


crates/gateway/src/gateway.rs line 32 at r1 (raw file):

            .serve(app.into_make_service())
            .await
            .map_err(|_| GatewayError::ServerStartError);

This should be a ?, and also I'm not sure how this works because the actual error is suppressed (with _).

Let's adhere to the docs and unwrap here, but add a TODO to check this out, could this fail with network error? if it can then it should be returned as an error to the user (so they'll fix their network issue)

Code quote:

            .map_err(|_| GatewayError::ServerStartError);

crates/gateway/src/gateway_test.rs line 16 at r1 (raw file):

#[case("./src/json_files_for_testing/invoke_v3.json", "INVOKE")]
#[tokio::test]
async fn test_add_transaction(#[case] json_file_path: &str, #[case] expected_response: &str) {

add negative test, separate test.


crates/gateway/src/gateway_test.rs line 18 at r1 (raw file):

async fn test_add_transaction(#[case] json_file_path: &str, #[case] expected_response: &str) {
    let json_str = std::fs::read_to_string(json_file_path).expect("Failed to read JSON file");
    let json: ExternalTransaction = serde_json::from_str(&json_str).expect("Failed to parse JSON");

Always prefer from_reader over from_string if all you want it so parse a json file

Code quote:

    let json_str = std::fs::read_to_string(json_file_path).expect("Failed to read JSON file");
    let json: ExternalTransaction = serde_json::from_str(&json_str).expect("Failed to parse JSON");

@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/axum-instead-of-hyper branch from 77417a6 to 3a233e8 Compare April 3, 2024 11:33
Copy link
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 4 files reviewed, 6 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


crates/gateway/src/gateway.rs line 29 at r1 (raw file):

Previously, giladchase wrote…

Plz add comment on what this does and how it behaves

Done.


crates/gateway/src/gateway.rs line 32 at r1 (raw file):

Previously, giladchase wrote…

This should be a ?, and also I'm not sure how this works because the actual error is suppressed (with _).

Let's adhere to the docs and unwrap here, but add a TODO to check this out, could this fail with network error? if it can then it should be returned as an error to the user (so they'll fix their network issue)

Done.


crates/gateway/src/gateway_test.rs line 18 at r1 (raw file):

Previously, giladchase wrote…

Always prefer from_reader over from_string if all you want it so parse a json file

Done.

@ayeletstarkware ayeletstarkware changed the base branch from ayelet/mempool/implement-add-transaction-in-gateway to main April 3, 2024 11:35
@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 35.71429% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 23.07%. Comparing base (4408e4b) to head (56fe055).

Files Patch % Lines
crates/gateway/src/gateway.rs 35.71% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #17       +/-   ##
===========================================
- Coverage   47.72%   23.07%   -24.66%     
===========================================
  Files           2        2               
  Lines          44       26       -18     
  Branches       44       26       -18     
===========================================
- Hits           21        6       -15     
- Misses         19       20        +1     
+ Partials        4        0        -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ayeletstarkware ayeletstarkware changed the title refactor(gateway): use axum instead of hyper refactor: use axum instead of hyper Apr 3, 2024
@ayeletstarkware ayeletstarkware force-pushed the ayelet/mempool/axum-instead-of-hyper branch from 3a233e8 to 56fe055 Compare April 3, 2024 11:39
Copy link
Collaborator

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 4 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ayeletstarkware and @MohammadNassar1)

Copy link
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


crates/gateway/src/gateway_test.rs line 16 at r1 (raw file):

Previously, giladchase wrote…

add negative test, separate test.

Done.

Copy link
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


crates/gateway/src/gateway_test.rs line 16 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Done.

will be done in next PR

Copy link
Contributor Author

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @giladchase and @MohammadNassar1)


crates/gateway/src/gateway_test.rs line 16 at r1 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

will be done in next PR

when checking build_server

Copy link
Collaborator

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MohammadNassar1)

Copy link
Contributor

@MohammadNassar1 MohammadNassar1 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ayeletstarkware)

@ayeletstarkware ayeletstarkware merged commit 2e9a1d0 into main Apr 3, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants