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): move predeployedAccounts under DevApi and remove KatanaApi #2310

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Aug 16, 2024

Closes #2292.

@kariy as discussed it makes sense to have predeployedAccounts endpoint only available under --dev option.

Also, I had the feeling that KatanaApi would certainly ends up being testing mostly, so I deleted it.

But we may actually keep it even if empty, and be completed later if some endpoints make sense to be present even when not in --dev mode. 👍

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new asynchronous method to retrieve predeployed accounts, enhancing client-server interactions.
    • Updated the KatanaRunnerConfig to support a development mode, improving configurability for developers.
  • Bug Fixes

    • Removed the Katana API from default configurations, streamlining available API options and preventing potential errors in production environments.
  • Documentation

    • Added clarifications regarding the new dev field in KatanaRunnerConfig to guide users on its purpose.
  • Chores

    • Updated API endpoint references in code to reflect the removal of the Katana API.

@glihm glihm marked this pull request as draft August 16, 2024 15:14
Copy link

coderabbitai bot commented Aug 16, 2024

Walkthrough

Ohayo, sensei! The recent changes involve the removal of the Katana API across various components, streamlining the APIs available for interaction. This includes adjustments to the NodeArgs and TestSequencer implementations, as well as modifications in the RPC handling and configuration structures. The focus has shifted towards maintaining a cleaner and more efficient API suite, enabling better usability while accommodating development configurations.

Changes

File(s) Change Summary
bin/katana/src/cli/node.rs, crates/dojo-test-utils/src/sequencer.rs Removed ApiKind::Katana from the apis vector, limiting APIs to Starknet, Torii, Saya, and conditionally adding Dev in development mode.
crates/katana/node/src/lib.rs Eliminated handling of ApiKind::Katana, affecting how the server processes requests for this API, indicating its deprecation.
crates/katana/rpc/rpc-api/src/dev.rs, crates/katana/rpc/rpc/src/dev.rs Added an asynchronous method predeployed_accounts to retrieve a list of predeployed accounts, enhancing functionality within the DevApi.
crates/katana/runner/src/lib.rs Introduced a new dev field in KatanaRunnerConfig for specifying development mode, enhancing configurability for different operational scenarios.
crates/sozo/ops/src/migration/mod.rs Changed the JSON-RPC method from "katana_predeployedAccounts" to "dev_predeployedAccounts", reflecting a shift in the service endpoint.
crates/sozo/ops/src/tests/migration.rs Updated KatanaRunnerConfig to include the dev field set to true, altering the initialization process for development mode.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant DevAPI

    Client->>Server: Request data
    Server->>DevAPI: Call predeployed_accounts
    DevAPI-->>Server: Return accounts data
    Server-->>Client: Send accounts data
Loading

This diagram illustrates the interaction between the client and server when retrieving predeployed accounts through the DevApi.

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76466d6 and 3cb5fec.

Files selected for processing (6)
  • bin/katana/src/cli/node.rs (1 hunks)
  • crates/dojo-test-utils/src/sequencer.rs (1 hunks)
  • crates/katana/node/src/lib.rs (2 hunks)
  • crates/katana/rpc/rpc/src/dev.rs (2 hunks)
  • crates/katana/runner/src/lib.rs (1 hunks)
  • crates/sozo/ops/src/migration/mod.rs (1 hunks)
Additional comments not posted (6)
crates/katana/rpc/rpc/src/dev.rs (1)

9-9: Ohayo! The import statement looks good, sensei.

The Account struct is imported correctly from the katana_rpc_types::account module.

crates/dojo-test-utils/src/sequencer.rs (1)

46-46: Ohayo sensei! Let's verify the impact of removing the ApiKind::Katana entry.

The removal of ApiKind::Katana from the apis field in the ServerConfig struct may affect how the TestSequencer interacts with the Katana API. We should ensure that this change aligns with the intended functionality and supported integrations of the sequencer.

To verify the impact, let's search for usages of the Katana API in the codebase:

If the script returns no results, it indicates that the Katana API is not being used elsewhere in the codebase. In that case, removing it from the apis field should be safe. However, if the script returns usages, we should carefully review those instances to ensure that removing the Katana API does not break any existing functionality.

Verification successful

Ohayo sensei! Let's dig a bit deeper to ensure we're not missing anything. I'll check for any comments or documentation that might mention ApiKind::Katana to confirm its removal is safe.


Ohayo sensei! After a thorough check, it looks like removing ApiKind::Katana from the apis field is all good. The mentions of Katana in the codebase are mostly about the KatanaRunner and its configurations, which are separate from the API kind enumeration. So, no worries about breaking anything with this change. 🌟

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Search for usages of the Katana API
rg --type rust $'ApiKind::Katana'

Length of output: 32


Script:

#!/bin/bash

# Search for comments or documentation mentioning Katana
rg 'Katana' --type rust --type md

Length of output: 26667

crates/katana/runner/src/lib.rs (1)

105-105: Ohayo sensei! The code change looks good to me.

Adding the .dev(config.dev) method to the KatanaRunner builder pattern correctly enables the dev mode configuration based on the config.dev flag.

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

Line range hint 200-212: Ohayo, sensei! The removal of ApiKind::Katana handling looks good to me.

The changes align with the PR objective of removing the KatanaApi, streamlining the API handling to focus on the remaining API kinds.

crates/sozo/ops/src/migration/mod.rs (1)

67-67: Ohayo sensei! Verify the impact of changing the method name.

Changing the method name from "katana_predeployedAccounts" to "dev_predeployedAccounts" suggests a shift in functionality.

Please run the following script to verify the usage and impact of this method name change across the codebase:

Verification successful

Ohayo sensei! The method name change is verified.

The method name katana_predeployedAccounts has been successfully replaced with dev_predeployedAccounts in the codebase. There are no lingering references to the old method name, and the new method name appears only in the intended location. This confirms that the change is localized and correctly implemented.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and impact of changing the method name from `katana_predeployedAccounts` to `dev_predeployedAccounts`.

# Test 1: Search for references to the old method name `katana_predeployedAccounts`. 
# Expect: No occurrences, indicating that the old method is no longer used.
rg --type rust $'katana_predeployedAccounts'

# Test 2: Search for references to the new method name `dev_predeployedAccounts`.
# Expect: Occurrences only in the intended locations, confirming the switch to the new method.
rg --type rust $'dev_predeployedAccounts'

Length of output: 170

bin/katana/src/cli/node.rs (1)

274-274: Ohayo, sensei! The removal of ApiKind::Katana looks good to me.

The change aligns with the PR objective of streamlining the API structure by removing the Katana API from the default configuration. The Dev API is still conditionally added based on the dev flag, preserving the function's overall control flow while limiting the available APIs in non-development modes.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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: 0

Outside diff range, codebase verification and nitpick comments (2)
crates/katana/runner/src/lib.rs (1)

50-51: Document the purpose of the dev field clearly.

The dev field is a crucial addition for configuring development RPC endpoints. Ensure that its purpose and usage are well-documented for clarity.

    /// Whether to run the katana runner with the `dev` rpc endpoints.
+   /// Set this to `true` to enable development-specific features.
    pub dev: bool,
crates/katana/node/src/lib.rs (1)

Ohayo, sensei! It looks like the KatanaApi is still lingering in the codebase, particularly within error handling components. Here are the spots where it's referenced:

  • crates/katana/rpc/rpc/src/dev.rs: Commented out reference to KatanaApiError.
  • crates/katana/rpc/rpc-types/src/error/katana.rs: Definition of KatanaApiError and its conversion implementation.

These references indicate that KatanaApi hasn't been fully removed or refactored. You might want to review these parts to ensure they align with the current objectives of streamlining the API. If these are no longer needed, they should be removed or updated accordingly.

Analysis chain

Line range hint 121-146:
Confirm removal of KatanaApi.

The removal of the ApiKind::Katana variant from the spawn function aligns with the PR's objective to streamline the API. Ensure that any client interactions relying on KatanaApi are updated or documented.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `KatanaApi` is still referenced in the codebase.

# Test: Search for references to `KatanaApi`. Expect: No occurrences.
rg --type rust 'KatanaApi'

Length of output: 390

@glihm glihm changed the title fix: move predeployedAccounts under DevApi and remove KatanaApi refactor(katana): move predeployedAccounts under DevApi and remove KatanaApi Aug 16, 2024
@glihm glihm added the katana This issue is related to Katana label Aug 16, 2024
Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.

Project coverage is 67.85%. Comparing base (1d95782) to head (3cb5fec).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/rpc/rpc/src/dev.rs 0.00% 3 Missing ⚠️
bin/katana/src/cli/node.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2310      +/-   ##
==========================================
- Coverage   67.86%   67.85%   -0.01%     
==========================================
  Files         359      357       -2     
  Lines       46959    46949      -10     
==========================================
- Hits        31869    31859      -10     
  Misses      15090    15090              

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

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

looks alright. removing the katana api seems fine since there's only predeployAccounts under it and it also feels somewhat redundant to have too many namespaces, but maybe we're possibly breaking user code a lil bit by outright changing the namespace of the method? because now they have to do two things; use --dev when starting katana, and change katana_ -> dev_. simply putting katana api under --dev seems less intrusive.

just a lil thought but not married to the idea. what you did is most probably fine.

@glihm
Copy link
Collaborator Author

glihm commented Aug 22, 2024

looks alright. removing the katana api seems fine since there's only predeployAccounts under it and it also feels somewhat redundant to have too many namespaces, but maybe we're possibly breaking user code a lil bit by outright changing the namespace of the method? because now they have to do two things; use --dev when starting katana, and change katana_ -> dev_. simply putting katana api under --dev seems less intrusive.

just a lil thought but not married to the idea. what you did is most probably fine.

Yeah I was thinking the same at first. But then, realized that may be better to have this clearly identified as a dev feature.

This change will impact:

  • sozo: to ensure it uses the new namespace.
  • slot: --dev option must be exposed (or we should first implement the selection of namespace, doing so the --dev becomes obsolete and slot should expose the namespace selection as Katana plans to do).

We may actually make this refactor here? WDYT? Your comment on doing this namespace selection makes the devX very nice for future namespaces addition.

@glihm glihm marked this pull request as ready for review September 3, 2024 22:14
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: 0

Outside diff range, codebase verification and nitpick comments (1)
crates/katana/rpc/rpc/src/dev.rs (1)

94-98: Ohayo, sensei! The new method looks great, but let's add a comment to improve the code quality.

The new method predeployed_accounts is implemented correctly and enhances the functionality of the DevApiServer by allowing it to expose predeployed account information.

The #[allow(deprecated)] attribute is a good practice to indicate that the method may be deprecated in the future.

To improve the code quality, please add a comment to explain the purpose of the method and the reason for the #[allow(deprecated)] attribute:

+/// Returns the predeployed accounts from the backend's genesis configuration.
+/// This method is marked as deprecated because it may be removed in the future.
 #[allow(deprecated)]
 async fn predeployed_accounts(&self) -> Result<Vec<Account>, Error> {
     Ok(self.backend.config.genesis.accounts().map(|e| Account::new(*e.0, e.1)).collect())
 }

@glihm glihm merged commit da96b12 into dojoengine:main Sep 4, 2024
14 of 15 checks passed
kariy pushed a commit to walnuthq/dojo that referenced this pull request Sep 6, 2024
…tanaApi (dojoengine#2310)

fix: move predeployedAccounts under DevApi and remove KatanaApi
glihm added a commit that referenced this pull request Sep 8, 2024
* feat: add sierra to cairo debug information

* Add walnut flag to sozo execute command

* Pass rpc url to handle_transaction_result

* Add walnut flag to sozo migrate apply command

* Move walnut_debug_transaction to walnut crate

* Cargo fmt

* Keep only one global walnut flag

* Add comments

* Add walnut flag to sozo execute command

* Pass rpc url to handle_transaction_result

* Add walnut flag to sozo migrate apply command

* Move walnut_debug_transaction to walnut crate

* Cargo fmt

* Keep only one global walnut flag

* Add comments

* Resolve conflicts

* Fix lint errors

* Put the walnut crate under the /sozo dir

* Add constants with API and app URLs

* Warn where we fail silently

* Remove unnecessary comments

* Check Walnut API key before migration

* Add doc comments

* Disable walnut flag in auto_authorize

* chore; use debug for pending tx log (#2383)

Update engine.rs

* refactor(katana-rpc): `getEvents` include pending block  (#2375)

* refactor(katana): move predeployedAccounts under DevApi and remove KatanaApi (#2310)

fix: move predeployedAccounts under DevApi and remove KatanaApi

* remove world and indexers table in favour of contracts

commit-id:98359f5f

* opt(torii): batch query execution in sync_range

commit-id:72f22f88

* refactor(torii): make select block cancel safe

commit-id:8fbc8e6d

* opt(torii): use hashmap instead of vector of event processors

commit-id:7303cc72

* opt(torii): fetch receipts along with blocks instead of fetching them individually

commit-id:b6db4cb5

* opt(torii): avoid re-processing of transactions in certain case

fix: #2355

commit-id:a510b985

* wip

* chore(dojo-world): enable manifest feature on `migration` feature

* fmt

* refactor: move walnut config into WalnutDebugger

* fix: ensure only WalnutDebugger is exposed

* fix: restore default dojo_dev.toml

* dont print in library code

* use concrete error types in walnut/verification

* use concrete types again

* remove unecessary util function

* use json method instead

* fix: fix test

---------

Co-authored-by: glihm <dev@glihm.net>
Co-authored-by: Larko <59736843+Larkooo@users.noreply.github.com>
Co-authored-by: Ammar Arif <evergreenkary@gmail.com>
Co-authored-by: lambda-0x <0xlambda@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
katana This issue is related to Katana
Projects
None yet
Development

Successfully merging this pull request may close these issues.

katana: put katana api under dev mode
2 participants