Skip to content

0.8.1 JSON-RPC spec#755

Merged
marioiordanov merged 16 commits intomainfrom
v0.8.1-spec
Apr 15, 2025
Merged

0.8.1 JSON-RPC spec#755
marioiordanov merged 16 commits intomainfrom
v0.8.1-spec

Conversation

@marioiordanov
Copy link
Copy Markdown
Contributor

@marioiordanov marioiordanov commented Apr 11, 2025

Usage related changes

Compliant with 0.8.1 spec

Development related changes

  • each string component from JSON-RPC schema that doesn't have pattern, is assigned the default regex pattern (string of 1-10 characters )
  • remove server dependency in tests/integration crate

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

Summary by CodeRabbit

  • New Features

    • Added enhanced validation rules for subscription IDs and contract class ABI parameters.
    • Introduced updated API specifications for accessing compiled contract artifacts.
  • API Updates

    • Upgraded the API version from 0.8.0 to 0.8.1 across multiple endpoints.
    • Improved subscription identifier handling for increased consistency and clarity.
  • Internal Improvements

    • Streamlined data generation with default patterns.
    • Consolidated utilities and removed redundant dependencies to simplify the testing environment.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2025

Walkthrough

The changes update the API specification and subscription mechanisms across the project. The RPC spec version is incremented from "0.8.0" to "0.8.1". The SubscriptionId type now transitions from a simple alias to a structured type with custom serialization, with tests adapting by treating it as a string. New regex defaults and stricter schema validations have been introduced in data generators and YAML spec instructions. In addition, deprecated JSON files are removed, OpenRPC spec files are updated for clarity, and test imports have been reorganized (e.g., centralizing assert_contains), with a dependency on the server package eliminated.

Changes

File(s) Change Summary
crates/starknet-devnet-server/src/api/json_rpc/mod.rs
tests/integration/general_rpc_tests.rs
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_api_openrpc.json
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_trace_api_openrpc.json
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_write_api.json
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_ws_api.json
Updated API specification version from "0.8.0" to "0.8.1" and adjusted schema references/formatting.
crates/starknet-devnet-server/src/api/json_rpc/models.rs
crates/starknet-devnet-server/src/subscribe.rs
Replaced the type alias with a new SubscriptionId struct (with conversion and serialization) and adjusted subscription ID generation (using explicit conversion via .into()).
crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs Introduced a DEFAULT_STRING_REGEX constant and streamlined regex pattern handling for string primitive generation.
crates/starknet-devnet-server/test_data/spec/0.8.0/starknet_executables.json
crates/starknet-devnet-server/test_data/spec/0.8.1/edit_spec_instructions.yaml
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json
Removed outdated OpenRPC spec file and schemas; added new YAML entries and a new executables spec offering compiled contract retrieval.
tests/integration/common/utils.rs Updated SubscriptionId from u64 to String; refined error messaging and added the assert_contains helper function.
tests/integration/test_subscription_to_blocks.rs
tests/integration/test_subscription_to_events.rs
tests/integration/test_subscription_to_pending_txs.rs
tests/integration/test_subscription_to_reorg.rs
Modified subscription handling in tests to use cloning, string conversion, and proper deserialization for enhanced type safety.
Multiple test files:
test_abort_blocks.rs, test_account_impersonation.rs, test_account_selection.rs, test_call.rs, test_deploy.rs, test_estimate_fee.rs, test_messaging.rs, test_minting.rs, test_simulate_transactions.rs, test_transaction_handling.rs, test_v3_transactions.rs
Updated import paths for assert_contains, moving it from server::test_utils to crate::common/utils.
tests/integration/Cargo.toml Removed the dependency on the server package to streamline integration test dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant SC as SocketContext
    participant RNG as Random u64 Generator
    participant Conv as SubscriptionId Converter

    C->>SC: Request subscription
    SC->>RNG: Generate random u64
    RNG-->>SC: Return random number
    SC->>Conv: Convert number using .into()
    Conv-->>SC: Return SubscriptionId struct
    SC->>C: Send SubscriptionId (as string)
Loading

Possibly related PRs

Suggested reviewers

  • FabijanC

Poem

Hoppin' through the code I go,
Upgrading specs with a gentle flow.
From numbers to strings, the IDs now gleam,
Regex and schemas form the dream.
I nibble imports with a joyful cheer,
CodeRabbit’s changes bring magic near!
🐇✨ Happy hops and cleaner code!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eece354 and f6aa2d8.

📒 Files selected for processing (1)
  • tests/integration/test_subscription_to_reorg.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/test_subscription_to_reorg.rs

🪧 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 generate docstrings to generate docstrings for this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@marioiordanov marioiordanov marked this pull request as ready for review April 11, 2025 14:33
@marioiordanov marioiordanov requested a review from FabijanC April 11, 2025 14:35
Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (2)
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json (2)

1-7: Metadata and Info Validation
The metadata section correctly sets the OpenRPC version and the API version ("0.8.1") as well as the title. One point to note is that the "license" object is currently empty. If a license is known (e.g., MIT, Apache, etc.), it might be beneficial to populate its fields or remove the empty object if it is not in use.


45-122: Schema: CASM_COMPILED_CONTRACT_CLASS
The schema for CASM_COMPILED_CONTRACT_CLASS is comprehensive, covering properties such as entry_points_by_type, bytecode, prime, and compiler_version. One observation is that string fields like "compiler_version" (line 85) do not include a regex pattern. According to the PR objectives, string components without an explicitly defined pattern should default to a regex that permits 1 to 10 characters. Please verify if this omission is intentional (perhaps handled elsewhere) or if you wish to explicitly include a "pattern" property.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28592a7 and 4855e40.

📒 Files selected for processing (11)
  • crates/starknet-devnet-server/src/api/json_rpc/mod.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/models.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs (2 hunks)
  • crates/starknet-devnet-server/src/subscribe.rs (1 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.0/starknet_executables.json (0 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/edit_spec_instructions.yaml (1 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_api_openrpc.json (12 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json (1 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_trace_api_openrpc.json (3 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_write_api.json (1 hunks)
  • crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_ws_api.json (5 hunks)
💤 Files with no reviewable changes (1)
  • crates/starknet-devnet-server/test_data/spec/0.8.0/starknet_executables.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/starknet-devnet-server/src/api/json_rpc/models.rs (9)
crates/starknet-devnet-core/src/state/state_diff.rs (1)
  • from (126-176)
crates/starknet-devnet-server/src/api/json_rpc/mod.rs (2)
  • from (1018-1020)
  • from (1024-1026)
crates/starknet-devnet-types/src/rpc/transactions.rs (5)
  • from (334-340)
  • from (384-412)
  • deserialize (797-820)
  • deserialize (824-841)
  • deserialize (845-862)
crates/starknet-devnet-core/src/blocks/mod.rs (2)
  • from (204-260)
  • from (264-323)
crates/starknet-devnet-types/src/rpc/contract_class.rs (3)
  • from (62-64)
  • from (68-70)
  • serialize (41-49)
crates/starknet-devnet-types/src/rpc/transaction_receipt.rs (1)
  • from (84-90)
crates/starknet-devnet-core/src/starknet/starknet_config.rs (1)
  • value (52-53)
crates/starknet-devnet-server/src/subscribe.rs (2)
  • serialize (157-162)
  • deserialize (166-173)
crates/starknet-devnet-types/src/rpc/contract_address.rs (2)
  • serialize (31-36)
  • deserialize (40-45)
🔇 Additional comments (24)
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_write_api.json (1)

4-4: Version correctly updated to 0.8.1

The API version has been properly incremented from 0.8.0 to 0.8.1, maintaining consistency with other specification files in the codebase.

crates/starknet-devnet-server/src/api/json_rpc/mod.rs (1)

10-10: RPC specification version correctly updated

The RPC_SPEC_VERSION constant has been properly updated to "0.8.1", maintaining consistency with the JSON specification files in the codebase.

crates/starknet-devnet-server/test_data/spec/0.8.1/edit_spec_instructions.yaml (1)

30-33: Enhanced schema validation with regex patterns

Two important validation patterns have been added:

  1. For SUBSCRIPTION_ID: The pattern ^[1-9]{1}[0-9]{0,4}$ ensures subscription IDs are 1-5 digit numbers starting with a non-zero digit (range: 1-99999).
  2. For CONTRACT_CLASS/properties/abi: The pattern ^$ validates that the ABI property can be an empty string.

These additions improve type safety and ensure consistent formatting in the API.

crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_trace_api_openrpc.json (3)

4-4: Version correctly updated to 0.8.1

The API version has been properly incremented from 0.8.0 to 0.8.1, maintaining consistency with other specification files in the codebase.


82-92: Improved JSON formatting for better readability

The "items" object structure has been reformatted with proper indentation, making the code more readable while preserving its semantic meaning.


258-262: Enhanced readability of required fields

The "required" array has been reformatted from a single line to a multi-line format, improving readability and making future modifications easier.

crates/starknet-devnet-server/src/subscribe.rs (1)

254-254: Enhanced type safety for subscription ID generation

The subscription ID generation has been improved to explicitly convert a random u64 to a SubscriptionId type using the into() method. This change aligns with the update to the SubscriptionId from a simple type alias to a dedicated struct with proper serialization/deserialization, improving type safety throughout the codebase.

crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs (2)

17-18: Good addition of a default string pattern.

Adding this constant improves code maintainability by centralizing the string generation pattern and making its purpose clear with the explanatory comment.


72-87: Well refactored string primitive handling.

The code has been simplified effectively by:

  1. Using as_deref().unwrap_or(DEFAULT_STRING_REGEX) pattern to provide a default regex
  2. Eliminating unnecessary intermediate steps in the return flow

This change is more idiomatic Rust and improves readability.

crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_ws_api.json (5)

4-4: Version updated to 0.8.1 correctly.

This change properly updates the API version to match the new specification.


147-147: Improved empty array formatting.

The empty array formatting has been made more consistent.


263-263: Updated subscription ID reference.

References to subscription ID have been properly updated to match the new schema type.


305-305: Changed subscription ID type from integer to string.

This change aligns with the new SubscriptionId struct in models.rs that serializes values as strings.


371-376: Improved formatting of required fields.

The multi-line formatting of the required fields improves readability and makes future changes easier to track in version control.

crates/starknet-devnet-server/src/api/json_rpc/models.rs (3)

204-212: Good replacement of primitive type with structured type.

Replacing the type alias with a proper struct improves type safety and makes the codebase more robust. The implementation of From<u64> provides a clean conversion path.


214-221: Well-implemented serialization for SubscriptionId.

The serialization logic correctly converts the internal u64 value to a string representation, which matches the updated spec requirements.


223-235: Robust deserialization with proper error handling.

The deserialization implementation correctly:

  1. Parses the string representation back to a u64
  2. Provides clear error messages on parsing failure
  3. Constructs the proper struct on success

This ensures type safety while maintaining compatibility with the JSON-RPC specification.

crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_api_openrpc.json (5)

4-4: Version updated to 0.8.1 correctly.

The API version has been properly updated to match the new specification.


252-296: Improved formatting for starknet_getMessagesStatus method.

The method definition has been reformatted for better readability without changing functionality.


315-315: Updated transaction reference to use TXN_WITH_HASH.

References have been updated consistently to use the appropriate schema.

Also applies to: 352-352


3325-3356: Improved type specificity for gas-related fields.

The schema references have been updated from generic FELT to more specific u64 and u128 types, which better reflects their expected ranges and formats. The description for overall_fee has also been enhanced with the calculation formula.


3363-3372: Well-formatted required fields section.

The required fields have been reformatted for better readability, making the specification more maintainable.

crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json (2)

9-41: Method Definition and Reference Check
The "methods" section defines the starknet_getCompiledCasm method with clear parameters, result, and error definitions. The use of $ref for the parameter schema (referencing FELT) and for the result (referencing CASM_COMPILED_CONTRACT_CLASS) seems appropriate. One detail to verify is the relative reference in the errors array (line 37) pointing to "./api/starknet_api_openrpc.json#/components/errors/CLASS_HASH_NOT_FOUND". Please confirm that this path is correct and resolves as expected in your project structure.


1144-1151: External Schema References
The schemas "FELT", "NUM_AS_HEX", and "DEPRECATED_CAIRO_ENTRY_POINT" are referenced via $ref to external files (lines 1144–1151). Ensure that these external JSON schema references exist at the specified paths and that the external definitions conform to the expectations of this spec.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
crates/starknet-devnet-server/src/api/json_rpc/models.rs (1)

222-235: Consider adding more specific error message for parsing failures.

The custom deserialization logically complements the serialization. However, the error message when parsing fails could be more informative about the expected format.

 let subscription_id = u64_as_string.parse::<u64>().map_err(|_| {
-    serde::de::Error::invalid_type(serde::de::Unexpected::Str(&u64_as_string), &"u64")
+    serde::de::Error::custom(format!("Failed to parse '{}' as a u64 subscription ID", &u64_as_string))
 })?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e712b5a and 17a9c86.

📒 Files selected for processing (2)
  • crates/starknet-devnet-server/src/api/json_rpc/models.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/starknet-devnet-server/src/api/json_rpc/models.rs (8)
crates/starknet-devnet-types/src/rpc/transactions.rs (5)
  • from (334-340)
  • from (384-412)
  • deserialize (797-820)
  • deserialize (824-841)
  • deserialize (845-862)
crates/starknet-devnet-types/src/rpc/contract_class.rs (3)
  • from (62-64)
  • from (68-70)
  • serialize (41-49)
crates/starknet-devnet-types/src/rpc/block.rs (6)
  • from (24-26)
  • from (36-38)
  • from (163-165)
  • from (169-175)
  • deserialize (42-61)
  • deserialize (146-159)
crates/starknet-devnet-types/src/rpc/transaction_receipt.rs (1)
  • from (84-90)
crates/starknet-devnet-core/src/starknet/starknet_config.rs (1)
  • value (52-53)
crates/starknet-devnet-server/src/subscribe.rs (2)
  • serialize (157-162)
  • deserialize (166-173)
crates/starknet-devnet-types/src/rpc/contract_address.rs (2)
  • serialize (31-36)
  • deserialize (40-45)
crates/starknet-devnet-types/src/rpc/contract_class/deprecated/mod.rs (2)
  • serialize (21-29)
  • deserialize (33-38)
🔇 Additional comments (3)
crates/starknet-devnet-server/src/api/json_rpc/models.rs (3)

204-205: Refactor from type alias to struct enhances type safety.

This change replaces a type alias with a dedicated struct, providing better type safety and clarity by preventing accidental use of raw u64 values where a SubscriptionId is expected.


207-211: Implementation of From trait provides ergonomic conversion.

The From<u64> implementation allows for clean conversion from raw u64 values to SubscriptionId instances, supporting the type-safe approach while maintaining ergonomics.


213-220: Custom serialization ensures consistent string representation.

The custom serialization implementation ensures that subscription IDs are always transmitted as strings in the JSON-RPC protocol, which is essential for client compatibility, especially for clients that might have difficulty handling large integer values directly.

@marioiordanov marioiordanov merged commit 95852ff into main Apr 15, 2025
1 check passed
@marioiordanov marioiordanov deleted the v0.8.1-spec branch April 15, 2025 10:56
@coderabbitai coderabbitai bot mentioned this pull request Sep 5, 2025
10 tasks
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.

2 participants