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(katana-rpc): remove some components dependency from starknet rpc handler #2759

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Dec 3, 2024

the idea is to make the StarknetApi struct not depend on components that are not shared in a full and sequencer node configuration.

this is just a small refactor for now and still doesn't unblock anything just yet.

@kariy kariy changed the title refactor(katana-rpc): remove components dependency from starknet rpc handler refactor(katana-rpc): remove some components dependency from starknet rpc handler Dec 3, 2024
Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

Ohayo, sensei! This pull request introduces significant modifications to the katana crate, particularly in the Node and LaunchedNode structures. The TxValidator has been removed from the spawn function, simplifying the instantiation of StarknetApi. A new StarknetApiConfig struct has been added to manage API configuration, including an optional max_event_page_size. The StarknetApi struct has been restructured to enhance clarity and maintainability, with the validator field replaced by a pool field. Overall, these changes streamline component management and improve code organization.

Changes

File Path Change Summary
crates/katana/node/src/lib.rs Removed TxValidator from spawn function; updated stop and launch methods in LaunchedNode and Node.
crates/katana/rpc/rpc/src/starknet/config.rs Introduced StarknetApiConfig struct with max_event_page_size field.
crates/katana/rpc/rpc/src/starknet/mod.rs Reorganized StarknetApi struct; removed validator, added pool; updated constructor methods for StarknetApi.

Possibly related PRs

Suggested labels

katana, contributor

Suggested reviewers

  • glihm

🪧 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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 75c43a8 and d9faf1a.

📒 Files selected for processing (3)
  • crates/katana/node/src/lib.rs (3 hunks)
  • crates/katana/rpc/rpc/src/starknet/config.rs (1 hunks)
  • crates/katana/rpc/rpc/src/starknet/mod.rs (4 hunks)
🔇 Additional comments (6)
crates/katana/rpc/rpc/src/starknet/mod.rs (2)

53-53: Great work exporting StarknetApiConfig publicly, sensei!

This allows for better modularity and flexibility in configuring the Starknet API.


1129-1136: Solid implementation of the Clone trait.

The Clone implementation correctly clones the inner Arc, ensuring proper reference counting.

crates/katana/rpc/rpc/src/starknet/config.rs (1)

1-7: Nice addition of StarknetApiConfig, sensei!

The StarknetApiConfig struct is well-defined, and the documentation clearly explains the usage of max_event_page_size.

crates/katana/node/src/lib.rs (3)

139-139: Updated node_components tuple looks good.

By removing TxValidator from the node_components, you've streamlined the node initialization. Ensure all references to TxValidator are updated accordingly.


251-254: Adjusted spawn function signature and node components.

The spawn function now accepts (TxPool, Arc<Backend<EF>>, BlockProducer<EF>, Option<ForkedClient>), aligning with the updated components. Please verify that all usages of node_components reflect this change and handle the optional forked_client appropriately.


271-271: Passing Some(block_producer.clone()) to StarknetApi::new.

Ensure that the optional block_producer is correctly handled within StarknetApi::new, and any cases where block_producer might be None are safely managed.

Comment on lines +79 to +80
blocking_task_pool: BlockingTaskPool,
block_producer: Option<BlockProducer<EF>>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Sensei, ensure proper handling of None for block_producer.

Since block_producer is now an Option, please verify that all usages of block_producer in StarknetApiInner safely handle the None case to prevent potential None dereferences and runtime errors.

Comment on lines +190 to +193
self.inner.block_producer.as_ref().and_then(|bp| match &*bp.producer.read() {
BlockProducerMode::Instant(_) => None,
BlockProducerMode::Interval(producer) => Some(producer.executor()),
}
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential None dereference in pending_executor method.

In the pending_executor method, when accessing self.inner.block_producer.as_ref(), please ensure that the scenario where block_producer is None is properly handled to avoid panics.

@@ -357,7 +360,7 @@
// TODO: this is a temporary solution, we should have a better way to handle this.
// perhaps a pending/pool state provider that implements all the state provider traits.
let result = if let BlockIdOrTag::Tag(BlockTag::Pending) = block_id {
this.inner.validator.pool_nonce(contract_address)?
this.inner.pool.validator().pool_nonce(contract_address)?
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Careful, sensei! validator() may no longer be available.

The call to this.inner.pool.validator() might be invalid since TxValidator has been removed from StarknetApi dependencies. Please update this call to reflect the new structure or provide an alternative means to access the required functionality.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 54.44%. Comparing base (e9f286c) to head (d9faf1a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/rpc/rpc/src/starknet/mod.rs 55.00% 9 Missing ⚠️
crates/katana/node/src/lib.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2759      +/-   ##
==========================================
- Coverage   54.69%   54.44%   -0.26%     
==========================================
  Files         427      427              
  Lines       53918    54118     +200     
==========================================
- Hits        29490    29463      -27     
- Misses      24428    24655     +227     

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

@kariy kariy merged commit 9d57b4b into main Dec 3, 2024
13 of 14 checks passed
@kariy kariy deleted the katana/rpc-server branch December 3, 2024 23:27
augustin-v pushed a commit to augustin-v/dojo that referenced this pull request Dec 4, 2024
… rpc handler (dojoengine#2759)

the idea is to make the StarknetApi struct not depend on components that are not shared in a full and sequencer node configuration.
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