Skip to content

Support l1_accepted; expand custom blockID; get balance by any blockID#819

Merged
FabijanC merged 10 commits intomainfrom
block-id-reform
Jul 23, 2025
Merged

Support l1_accepted; expand custom blockID; get balance by any blockID#819
FabijanC merged 10 commits intomainfrom
block-id-reform

Conversation

@FabijanC
Copy link
Copy Markdown
Contributor

@FabijanC FabijanC commented Jul 22, 2025

Usage related changes

  • Support l1_accepted block tag.
  • Breaking: accept any block_id (not just block_tag) in devnet_getAccountBalance.
  • Bugfix in getting block events by hash in forking mode if first or last block locally present (i.e. not on fork).
  • Temporarily ignoring l1_accepted block tag in forking mode if the block is present on forking origin.

Development related changes

  • Replace starknet-rs block_id with custom as much as possible in non-integration-testing code.
  • Add ignored tests (un-ignore after updating starknet-rs).

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 support for the l1_accepted block tag, enabling queries for the last block accepted on L1.
  • API Changes

    • Replaced block_tag parameters with block_id in balance and related queries for both HTTP and JSON-RPC endpoints.
    • Updated API to use a unified BlockId type with support for block number, hash, and tag variants.
  • Bug Fixes

    • Improved error messages for invalid block IDs and unsupported l1_accepted queries in certain contexts.
  • Documentation

    • Updated balance check documentation to reference block_id instead of block_tag.
  • Tests

    • Added integration tests for the new l1_accepted block tag behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 22, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This set of changes introduces a new L1Accepted variant to the BlockTag enum and extends the BlockId enum to support this variant throughout the codebase. The StarknetBlocks struct is updated with an optional last_accepted_on_l1 field, and the get_by_block_id method is modified to handle the new block tag. Imports and function signatures across multiple modules are updated to use the local BlockId and BlockTag types from starknet_types::rpc::block. API endpoints, test modules, and documentation are revised to use block_id instead of block_tag for block identification. Additional integration tests are introduced for the new L1Accepted functionality, and deserialization logic is updated to support the new tag.

Estimated code review effort

4 (~90 minutes)

Possibly related PRs

  • 0xSpaceShard/starknet-devnet#810: Adds the accept_on_l1 method to mark blocks as accepted on L1 and updates related logic, directly related to the new L1Accepted block tag and block acceptance status.
  • 0xSpaceShard/starknet-devnet#802: Renames and replaces the "pending" block concept with "pre_confirmed" and updates related types and logic, related at the file and block tag level but addresses a different variant and concept than L1Accepted.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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.

FabijanC added 3 commits July 22, 2025 17:49
- support l1_accepted

- accept any block_id (not just block_tag) in mint
@FabijanC FabijanC changed the title Support l1_accepted block tag; replace starknet-rs block ID with custom Support l1_accepted; expand custom blockID; get balance by any blockID Jul 23, 2025
@FabijanC FabijanC marked this pull request as ready for review July 23, 2025 09:33
@FabijanC
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@FabijanC FabijanC closed this Jul 23, 2025
@FabijanC FabijanC reopened this Jul 23, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 23, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 2

🧹 Nitpick comments (6)
website/docs/balance.md (1)

62-62: Add language specification to fenced code block.

The markdown linter suggests adding a language specification to improve syntax highlighting.

-```
+```http
tests/integration/test_accepting_blocks_on_l1.rs (2)

153-164: Test implementation looks correct but is currently ignored.

The test logic for verifying L1 acceptance appears sound. However, it's marked as ignored pending a starknet-rs update.

Would you like me to help verify if the starknet-rs dependency has been updated and these tests can be un-ignored?


166-176: Incomplete test implementations.

These test functions are placeholders with unimplemented!(). They should either be implemented or removed if not needed.

Would you like me to help implement these test cases for:

  1. Verifying that transactions in blocks accepted on L1 have the correct status
  2. Testing error handling when no blocks have been accepted on L1

I can generate the test implementations based on the existing test patterns in this file.

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

413-419: Consider extracting duplicated L1Accepted handling logic.

The handling of BlockTag::L1Accepted is duplicated for both from_block and to_block. Consider extracting this into a helper method to reduce duplication.

+    async fn get_l1_accepted_block_number(
+        &self,
+        starknet: &tokio::sync::MutexGuard<'_, Starknet>,
+    ) -> Result<u64, ApiError> {
+        let block_id = BlockId::Tag(BlockTag::L1Accepted);
+        match starknet.get_block(&block_id) {
+            Ok(block) => Ok(block.block_number().0),
+            Err(_) => Err(ApiError::UnsupportedAction { msg: L1_ACCEPTED_NOTICE.into() }),
+        }
+    }

     let from_block_number = match from_block {
         Some(BlockId::Tag(BlockTag::Latest | BlockTag::PreConfirmed)) => {
             return Ok((None, from_block, to_block));
         }
-        Some(block_id @ BlockId::Tag(BlockTag::L1Accepted)) => {
-            match starknet.get_block(&block_id) {
-                Ok(block) => block.block_number().0,
-                Err(_) => {
-                    return Err(ApiError::UnsupportedAction { msg: L1_ACCEPTED_NOTICE.into() });
-                }
-            }
-        }
+        Some(BlockId::Tag(BlockTag::L1Accepted)) => {
+            self.get_l1_accepted_block_number(&starknet).await?
+        }

Also applies to: 444-451


453-454: Address the TODO comment regarding origin query behavior.

The TODO suggests uncertainty about immediately querying the origin for hash-based block IDs. This could lead to performance issues or incorrect behavior if the block exists locally.

Would you like me to help implement a solution that first checks locally before querying the origin?

crates/starknet-devnet-core/src/starknet/mod.rs (1)

36-37: Consider removing the "Custom" prefix from BlockId and BlockTag imports.

The renaming to CustomBlockId and CustomBlockTag adds unnecessary complexity. Since these types are already from the local starknet_types module (not the external starknet_rs_core), the prefix doesn't provide additional clarity and makes the code harder to read.

-use starknet_types::rpc::block::{
-    Block, BlockHeader, BlockId as CustomBlockId, BlockResult, BlockStatus,
-    BlockTag as CustomBlockTag, PreConfirmedBlock, PreConfirmedBlockHeader,
-};
+use starknet_types::rpc::block::{
+    Block, BlockHeader, BlockId, BlockResult, BlockStatus,
+    BlockTag, PreConfirmedBlock, PreConfirmedBlockHeader,
+};

Then update all usages throughout the file to use BlockId and BlockTag directly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 08c8c71 and 3675af2.

📒 Files selected for processing (22)
  • crates/starknet-devnet-core/src/blocks/mod.rs (5 hunks)
  • crates/starknet-devnet-core/src/error.rs (1 hunks)
  • crates/starknet-devnet-core/src/messaging/mod.rs (1 hunks)
  • crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs (1 hunks)
  • crates/starknet-devnet-core/src/starknet/estimations.rs (3 hunks)
  • crates/starknet-devnet-core/src/starknet/events.rs (5 hunks)
  • crates/starknet-devnet-core/src/starknet/get_class_impls.rs (2 hunks)
  • crates/starknet-devnet-core/src/starknet/mod.rs (35 hunks)
  • crates/starknet-devnet-core/src/starknet/state_update.rs (2 hunks)
  • crates/starknet-devnet-core/src/state/state_diff.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/http/endpoints/accounts.rs (4 hunks)
  • crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (3 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/endpoints.rs (20 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/endpoints_ws.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/mod.rs (2 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/models.rs (7 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/write_endpoints.rs (1 hunks)
  • crates/starknet-devnet-server/src/test_utils.rs (1 hunks)
  • crates/starknet-devnet-types/src/rpc/block.rs (6 hunks)
  • tests/integration/common/background_devnet.rs (1 hunks)
  • tests/integration/test_accepting_blocks_on_l1.rs (1 hunks)
  • website/docs/balance.md (2 hunks)
🧠 Learnings (20)
crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/state/state_diff.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/state_update.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/error.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

tests/integration/common/background_devnet.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/messaging/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/events.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-server/src/api/http/endpoints/accounts.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/get_class_impls.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/blocks/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/estimations.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

tests/integration/test_accepting_blocks_on_l1.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-types/src/rpc/block.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

🧬 Code Graph Analysis (2)
crates/starknet-devnet-server/src/api/json_rpc/write_endpoints.rs (2)
crates/starknet-devnet-core/src/starknet/mod.rs (1)
  • accept_on_l1 (1025-1054)
tests/integration/test_accepting_blocks_on_l1.rs (1)
  • accept_on_l1 (16-27)
crates/starknet-devnet-server/src/api/json_rpc/mod.rs (1)
crates/starknet-devnet-server/src/test_utils.rs (1)
  • assert_contains (12-21)
🪛 markdownlint-cli2 (0.17.2)
website/docs/balance.md

62-62: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🧰 Additional context used
🧠 Learnings (20)
crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/state/state_diff.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/state_update.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/error.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

tests/integration/common/background_devnet.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/messaging/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/events.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-server/src/api/http/endpoints/accounts.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/get_class_impls.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/blocks/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/estimations.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

tests/integration/test_accepting_blocks_on_l1.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-types/src/rpc/block.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

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

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

crates/starknet-devnet-core/src/starknet/mod.rs (1)

Learnt from: FabijanC
PR: #799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, get_class_hash_at has different behaviors at different layers: at the internal state level (blockifier), it returns Ok(ClassHash(Felt::ZERO)) for undeployed addresses, while at the RPC layer, this gets converted to Err(Error::ContractNotFound). When checking if a contract is deployed at the internal state level, use is_ok_and(|h| h.0 == Felt::ZERO) to detect undeployed addresses.

🧬 Code Graph Analysis (2)
crates/starknet-devnet-server/src/api/json_rpc/write_endpoints.rs (2)
crates/starknet-devnet-core/src/starknet/mod.rs (1)
  • accept_on_l1 (1025-1054)
tests/integration/test_accepting_blocks_on_l1.rs (1)
  • accept_on_l1 (16-27)
crates/starknet-devnet-server/src/api/json_rpc/mod.rs (1)
crates/starknet-devnet-server/src/test_utils.rs (1)
  • assert_contains (12-21)
🪛 markdownlint-cli2 (0.17.2)
website/docs/balance.md

62-62: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (35)
crates/starknet-devnet-core/src/messaging/mod.rs (1)

37-37: LGTM: Import refactoring aligns with BlockId consolidation effort.

This import change is part of the broader refactoring to use the custom BlockId implementation from starknet_types::rpc::block instead of starknet_rs_core::types. The change maintains functionality while improving consistency across the codebase.

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

3-3: LGTM: Clean import consolidation improves maintainability.

Consolidating the block-related type imports (BlockId, BlockTag, etc.) under a single import from starknet_types::rpc::block improves code organization and aligns with the broader type unification effort.

crates/starknet-devnet-core/src/error.rs (1)

13-13: LGTM: Consistent import update maintains error handling functionality.

The import change for BlockId from starknet_types::rpc::block is consistent with the broader refactoring effort and maintains existing error handling behavior.

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

23-25: LGTM: Centralized error message improves consistency and includes new l1_accepted tag.

The addition of EXPECTED_INVALID_BLOCK_ID_MSG constant provides a standardized error message for invalid block ID validation. It correctly includes the new 'l1_accepted' tag alongside existing tags, improving error message consistency across the codebase.

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

156-156: LGTM: Clean removal of unnecessary type conversions.

The removal of .into() calls aligns perfectly with the broader refactor to unify BlockId usage across the codebase. The underlying methods now accept CustomBlockId directly, making these conversions unnecessary.

Also applies to: 162-162

crates/starknet-devnet-core/src/starknet/add_deploy_account_transaction.rs (1)

79-79: LGTM: Import reorganization aligns with codebase refactor.

The import change moves BlockId and BlockTag from starknet_rs_core::types to starknet_types::rpc::block, which is consistent with the broader refactor to unify block identification handling and support the new L1Accepted variant.

crates/starknet-devnet-core/src/starknet/state_update.rs (1)

1-1: LGTM: Consistent import updates for unified block ID handling.

The import changes align with the codebase-wide refactor to source BlockId and BlockTag from starknet_types::rpc::block, supporting the new custom BlockId enum and L1Accepted variant introduction.

Also applies to: 23-23

crates/starknet-devnet-core/src/state/state_diff.rs (1)

185-185: LGTM: Import reorganization follows the established refactor pattern.

The separation of imports correctly maintains Felt from starknet_rs_core::types while moving BlockId and BlockTag to starknet_types::rpc::block, consistent with the codebase-wide unification of block identification types.

Also applies to: 190-190

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

29-29: LGTM: Import reorganization maintains consistency with codebase refactor.

The import updates correctly separate concerns by keeping ContractClass and Felt from starknet_rs_core::types while moving block-related types to the unified starknet_types::rpc::block location.

Also applies to: 31-31


1061-1061: LGTM: Good practice consolidating test utilities.

Moving EXPECTED_INVALID_BLOCK_ID_MSG to the shared test_utils module promotes code reuse and reduces duplication across test modules.

website/docs/balance.md (1)

60-60: LGTM! Documentation correctly updated to reflect API changes.

The parameter name changes from block_tag to block_id are consistent with the broader refactoring to use the more flexible BlockId enum instead of just BlockTag.

Also applies to: 63-63, 75-75

crates/starknet-devnet-core/src/starknet/get_class_impls.rs (1)

7-7: LGTM! Import updates align with the BlockId/BlockTag refactoring.

The changes correctly update imports to use the custom BlockId, BlockStatus, and BlockTag types from starknet_types::rpc::block instead of the starknet-rs versions, which is consistent with the broader refactoring effort.

Also applies to: 78-78, 80-80

crates/starknet-devnet-core/src/starknet/events.rs (2)

1-1: LGTM! Import updates are consistent with the BlockId/BlockTag refactoring.

The changes correctly update imports to use the custom types and all test code properly uses the new import paths.

Also applies to: 4-4, 134-134, 137-137


293-294: Test code correctly updated to use new BlockTag import.

The test functions properly use BlockId::Tag(BlockTag::Latest) with the updated import path.

Also applies to: 308-309, 324-325

crates/starknet-devnet-server/src/api/http/endpoints/accounts.rs (3)

7-7: LGTM! Added necessary imports for BlockId and BlockTag.

The import additions support the API change from block_tag to block_id parameter.


80-80: Breaking change: API parameter updated from block_tag to block_id.

The change from block_tag: Option<BlockTag> to block_id: Option<BlockId> is a breaking change that provides more flexibility by supporting block identification by hash, number, or tag. This aligns with the PR objectives.


39-40: Implementation correctly wraps BlockTag in BlockId::Tag.

The function calls properly use BlockId::Tag(BlockTag::...) to maintain the existing behavior while using the new type structure.

Also applies to: 106-106

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

264-264: LGTM! Simplified imports and removed unnecessary alias.

Removing the ImportedBlockId alias and directly using BlockId improves code clarity and consistency. Moving test utility imports to a central location enhances maintainability.

Also applies to: 268-268, 274-274


490-490: Test assertions correctly updated to use BlockId variants.

The test code properly uses BlockId::Number, BlockId::Hash, and other variants instead of the previous alias.

Also applies to: 513-513, 536-536


694-694: Pattern matching in test helpers correctly updated.

The assertion helper functions properly use BlockId variants in pattern matching instead of the removed alias.

Also applies to: 709-710, 723-723

crates/starknet-devnet-core/src/blocks/mod.rs (4)

10-10: Import change aligns with PR objectives.

The migration from starknet_rs_core::types to starknet_types::rpc::block for BlockId and BlockTag is consistent with the PR's goal to replace starknet-rs block_id with a custom implementation.


29-29: Field addition properly supports L1Accepted functionality.

The last_accepted_on_l1 field correctly uses Option<BlockHash> to track the last block accepted on L1, appropriately handling the case where no blocks have been accepted yet.


54-54: Proper initialization in Default implementation.

The last_accepted_on_l1 field is correctly initialized to None, reflecting that no blocks have been accepted on L1 at startup.


105-107: Correct handling of L1Accepted block tag.

The implementation properly handles the BlockTag::L1Accepted case by using and_then to safely retrieve the block when last_accepted_on_l1 is set, and returning None when no blocks have been accepted on L1 yet.

crates/starknet-devnet-server/src/api/http/endpoints/mint_token.rs (3)

8-8: Import change is consistent with codebase refactor.

The import of BlockId and BlockTag from starknet_types::rpc::block aligns with the project-wide migration to use custom block ID types.


21-21: API enhancement to accept any block_id.

The change from BlockTag to BlockId aligns with the PR objective to allow devnet_getAccountBalance to accept any block_id. This provides more flexibility by supporting block hashes and numbers in addition to tags.

Also applies to: 28-28


70-75: Correct adaptation to new function signature.

The call properly wraps BlockTag::PreConfirmed in BlockId::Tag() to match the updated get_balance function signature.

crates/starknet-devnet-core/src/starknet/estimations.rs (2)

11-11: Consistent migration to custom BlockId type.

The import and parameter type changes correctly migrate to using CustomBlockId from the local types module, with appropriate use of references for better performance.

Also applies to: 21-21, 101-101


104-104: Correct dereferencing for owned value.

The dereference of block_id is necessary since EstimateMessageFeeRequest::new expects an owned BlockId value rather than a reference.

crates/starknet-devnet-types/src/rpc/block.rs (5)

11-19: Well-structured BlockId enum definition.

The custom BlockId enum properly defines all necessary variants for block identification with appropriate derive attributes for common traits.


36-44: Deserialization properly handles L1Accepted tag.

The deserialization logic correctly identifies and constructs the L1Accepted tag variant, and the error message appropriately lists all valid options.


143-143: Consistent L1Accepted support in SubscriptionBlockId.

The L1Accepted variant is properly added to SubscriptionBlockId with correct deserialization and conversion implementations.

Also applies to: 161-161, 178-178


188-188: BlockTag enum properly extended with L1Accepted.

The L1Accepted variant is correctly added to the BlockTag enum.


191-222: Comprehensive test coverage for new functionality.

The tests thoroughly verify deserialization of all BlockId and BlockTag variants, including the new L1Accepted tag, ensuring the implementation works as expected.

Also applies to: 242-244

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

28-29: Good use of a descriptive constant for the error message.

The constant clearly communicates the limitation to users when they attempt to use l1_accepted with forking origin.

@FabijanC FabijanC merged commit eabf8d3 into main Jul 23, 2025
2 checks passed
@FabijanC FabijanC deleted the block-id-reform branch July 23, 2025 10:35
@coderabbitai coderabbitai bot mentioned this pull request Sep 9, 2025
10 tasks
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 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.

1 participant