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

feat(katana): sequencer feeder gateway client #2732

Merged
merged 10 commits into from
Nov 30, 2024
Merged

feat(katana): sequencer feeder gateway client #2732

merged 10 commits into from
Nov 30, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Nov 28, 2024

ref #2724

why need to implement our own client instead of using an existing one (ie from starknet-rs) ? to ease type conversions. right now the only methods implemented are the ones that will be used for the syncing through the feeder gateway. there are still some types/conversions that haven't been defined yet but can be done progressively.

@kariy kariy force-pushed the katana/fgw-client branch from dc20773 to 1cbf24e Compare November 30, 2024 16:23
@kariy kariy marked this pull request as ready for review November 30, 2024 16:23
Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

Ohayo! This pull request introduces significant updates to the Cargo.toml files, incorporating a new workspace member and dependency for the katana-feeder-gateway crate. Additionally, it establishes a new Cargo.toml for the feeder-gateway, defining its dependencies and metadata. New source files are added, including client.rs for client interactions with the Starknet feeder gateway and types.rs for data structures related to contract classes and state updates. The changes enhance the structure and organization of the codebase, facilitating better management of dependencies and functionality.

Changes

File Path Change Summary
Cargo.toml - New workspace member: "crates/katana/feeder-gateway"
- New dependency: katana-feeder-gateway
crates/katana/feeder-gateway/Cargo.toml - New package declaration and metadata
- New dependencies and dev-dependencies sections
crates/katana/feeder-gateway/src/client.rs - Introduced SequencerGateway struct with methods for network interactions and error handling
crates/katana/feeder-gateway/src/lib.rs - Added new public modules: client and types
crates/katana/feeder-gateway/src/types.rs - Defined data structures for contract classes and state updates, including ContractClass, StateUpdate, etc.
crates/katana/primitives/src/class.rs - Updated imports and added a type alias for CasmContractClass

Possibly related PRs

  • Convert katana/contracts into a Scarb workspace #2523: This PR establishes a Scarb workspace for the katana/contracts directory, which is relevant as it relates to the workspace structure mentioned in the main PR's updates to Cargo.toml.
  • feat: katana config file #2668: This PR adds a new dependency for the workspace related to serialization/deserialization capabilities, which aligns with the main PR's updates to the Cargo.toml file for the katana crate.
  • Initialize katana grpc api #2682: This PR initializes the gRPC API for Katana, which involves updates to the Cargo.toml file to include the new gRPC crate, aligning with the main PR's focus on adding a new member related to the katana crate.

Suggested reviewers

  • glihm: A suitable reviewer for this PR given their expertise in the relevant areas.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1cbf24e and 4ceae39.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/katana/feeder-gateway/Cargo.toml (1 hunks)
  • crates/katana/feeder-gateway/src/lib.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/katana/feeder-gateway/src/lib.rs
  • crates/katana/feeder-gateway/Cargo.toml

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (11)
crates/katana/feeder-gateway/src/types.rs (2)

3-6: Consolidate CasmContractClass Import and Alias

Ohayo, sensei! I noticed that CasmContractClass is re-exported on line 3 from katana_primitives::class::CasmContractClass, and a type alias is also defined on lines 22-23 from katana_cairo::lang::starknet_classes::casm_contract_class::CasmContractClass. This might cause confusion due to multiple sources. Consider consolidating these to a single import to improve code clarity.


82-120: Optimize Iteration in From<StateDiff> Implementation

Ohayo, sensei! The From<StateDiff> implementation involves multiple iterations and collections. To improve performance and readability, consider optimizing these iterations, possibly by using combinators to reduce the number of transient collections.

crates/katana/primitives/src/class.rs (3)

21-24: Evaluate Placement of CasmContractClass Type Alias

Ohayo, sensei! The type alias for CasmContractClass is introduced on lines 22-23. Since this type is essential and used across multiple modules, consider re-exporting it from a central location to enhance maintainability and reduce redundancy.


Line range hint 26-55: Ensure Consistency in Error Handling

Ohayo, sensei! In the definitions around ContractClassCompilationError and ComputeClassHashError, make sure that error handling is consistent and provides meaningful messages. This will aid in debugging and improve user experience.


Line range hint 79-97: Consistency in Hash Computation Functions

Ohayo, sensei! The compute_sierra_class_hash and compute_legacy_class_hash functions are implemented differently. Consider aligning their structures or providing comments to clarify their differences, enhancing code readability.

Cargo.toml (2)

23-23: Maintain Alphabetical Order in Workspace Members

Ohayo, sensei! For better readability, consider adding "crates/katana/feeder-gateway" to the workspace members list in alphabetical order.


101-101: Consistency in Dependency Naming Conventions

Ohayo, sensei! In the [workspace.dependencies] section, the new dependency is added as katana-feeder-gateway. To maintain consistency with the rest of the dependencies, consider using underscores (_) instead of hyphens (-), like katana_feeder_gateway.

crates/katana/feeder-gateway/src/client.rs (4)

35-35: Ohayo, sensei! Consider handling URL parsing errors without using unwrap().

Using unwrap() on Url::parse can lead to panics if the URL is invalid. Even though the URLs are hardcoded and unlikely to fail, handling the potential error gracefully improves robustness.

Apply this diff:

-pub fn sn_mainnet() -> Self {
-    Self::new(Url::parse("https://alpha-mainnet.starknet.io/").unwrap())
+pub fn sn_mainnet() -> Result<Self, Error> {
+    let url = Url::parse("https://alpha-mainnet.starknet.io/")?;
+    Ok(Self::new(url))
 }

And update the method's return type and usage accordingly.


42-42: Ohayo, sensei! Handle URL parsing errors in sn_sepolia method as well.

Similarly, avoid using unwrap() to prevent potential panics.

Apply this diff:

-pub fn sn_sepolia() -> Self {
-    Self::new(Url::parse("https://alpha-sepolia.starknet.io/").unwrap())
+pub fn sn_sepolia() -> Result<Self, Error> {
+    let url = Url::parse("https://alpha-sepolia.starknet.io/")?;
+    Ok(Self::new(url))
 }

90-93: Ohayo, sensei! Handle potential errors in the feeder_gateway method to prevent panics.

Using expect("invalid base url") can cause a panic if the base URL cannot have path segments appended. Consider handling this error to enhance stability.

Apply this diff:

 fn feeder_gateway(&self, method: &str) -> RequestBuilder<'_> {
     let mut url = self.base_url.clone();
-    url.path_segments_mut().expect("invalid base url").extend(["feeder_gateway", method]);
+    if let Ok(mut segments) = url.path_segments_mut() {
+        segments.extend(["feeder_gateway", method]);
+    } else {
+        // Handle the error appropriately, perhaps by returning an error
+        // or logging an error message
+    }
     RequestBuilder { client: &self.client, url }
 }

229-251: Ohayo, sensei! Reassess the ignored test request_block_id_overwrite.

The test request_block_id_overwrite is marked with #[ignore]. Ignored tests might hide potential issues. Consider enabling the test or documenting the reason for ignoring it.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1aab149 and 1cbf24e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • Cargo.toml (2 hunks)
  • crates/katana/feeder-gateway/Cargo.toml (1 hunks)
  • crates/katana/feeder-gateway/src/client.rs (1 hunks)
  • crates/katana/feeder-gateway/src/lib.rs (1 hunks)
  • crates/katana/feeder-gateway/src/types.rs (1 hunks)
  • crates/katana/primitives/src/class.rs (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • crates/katana/feeder-gateway/src/lib.rs
  • crates/katana/feeder-gateway/Cargo.toml
🔇 Additional comments (2)
crates/katana/feeder-gateway/src/types.rs (1)

15-20: Verify All Variants in ContractClass Enum

Ohayo, sensei! The ContractClass enum uses #[serde(untagged)] for deserialization. Please ensure that all possible contract class variants returned by the feeder gateway API are accounted for to prevent potential deserialization errors.

Cargo.toml (1)

Line range hint 171-176: Update Version Constraints for Dependencies

Ohayo, sensei! Verify that the version constraints for the tonic and wasm-tonic dependencies are compatible, especially since they are used in different contexts (standard vs. WASM). This will help prevent potential build or runtime issues.

crates/katana/feeder-gateway/src/types.rs Show resolved Hide resolved
crates/katana/feeder-gateway/src/client.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 24.57143% with 132 lines in your changes missing coverage. Please review.

Project coverage is 56.34%. Comparing base (ebcc23d) to head (4ceae39).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/feeder-gateway/src/client.rs 34.40% 82 Missing ⚠️
crates/katana/feeder-gateway/src/types.rs 0.00% 50 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2732      +/-   ##
==========================================
+ Coverage   56.24%   56.34%   +0.09%     
==========================================
  Files         415      423       +8     
  Lines       53241    54166     +925     
==========================================
+ Hits        29948    30521     +573     
- Misses      23293    23645     +352     

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

@kariy kariy merged commit 3774731 into main Nov 30, 2024
13 of 14 checks passed
@kariy kariy deleted the katana/fgw-client branch November 30, 2024 17:00
augustin-v pushed a commit to augustin-v/dojo that referenced this pull request Dec 4, 2024
why need to implement our own client instead of using an existing one (ie from starknet-rs) ? to ease type conversions.
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.

1 participant