Conversation
WalkthroughThe 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 Changes
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)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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 forCASM_COMPILED_CONTRACT_CLASSis comprehensive, covering properties such asentry_points_by_type,bytecode,prime, andcompiler_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
📒 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.1The 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 updatedThe
RPC_SPEC_VERSIONconstant 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 patternsTwo important validation patterns have been added:
- 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).- 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.1The 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 readabilityThe "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 fieldsThe "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 generationThe subscription ID generation has been improved to explicitly convert a random
u64to aSubscriptionIdtype using theinto()method. This change aligns with the update to theSubscriptionIdfrom 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:
- Using
as_deref().unwrap_or(DEFAULT_STRING_REGEX)pattern to provide a default regex- 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
SubscriptionIdstruct 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:
- Parses the string representation back to a u64
- Provides clear error messages on parsing failure
- 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_feehas 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 thestarknet_getCompiledCasmmethod with clear parameters, result, and error definitions. The use of$reffor the parameter schema (referencingFELT) and for the result (referencingCASM_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$refto 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.
crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json
Show resolved
Hide resolved
crates/starknet-devnet-server/test_data/spec/0.8.1/edit_spec_instructions.yaml
Outdated
Show resolved
Hide resolved
crates/starknet-devnet-server/src/api/json_rpc/spec_reader/data_generator.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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
📒 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
u64values where aSubscriptionIdis expected.
207-211: Implementation of From trait provides ergonomic conversion.The
From<u64>implementation allows for clean conversion from rawu64values toSubscriptionIdinstances, 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.
Usage related changes
Compliant with 0.8.1 spec
Development related changes
Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit
New Features
API Updates
Internal Improvements