Skip to content

Support simulation of ACCEPTED_ON_L1#810

Merged
FabijanC merged 9 commits intomainfrom
accepted-on-l1
Jul 17, 2025
Merged

Support simulation of ACCEPTED_ON_L1#810
FabijanC merged 9 commits intomainfrom
accepted-on-l1

Conversation

@FabijanC
Copy link
Copy Markdown
Contributor

@FabijanC FabijanC commented Jul 17, 2025

Usage related changes

  • Close Support for ACCEPTED_ON_L1 #808
  • Introduce a new JSON-RPC method: devnet_acceptOnL1
    • Marks as ACCEPTED_ON_L1 blocks from starting_block_id to last accepted on L1, does the same for their txs.
    • Does not actually perform actions on L1.

Development related changes

  • Improve block abortion docs

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

    • Introduced a new JSON-RPC method to mark blocks and their transactions as accepted on L1, simulating L1 acceptance for blocks currently accepted on L2.
    • Added API request and response models for accepting blocks on L1.
    • Updated API documentation to describe the new block acceptance on L1 feature, including usage examples.
  • Bug Fixes

    • Corrected descriptions and typos in the API documentation for block abortion.
  • Tests

    • Added comprehensive integration tests to verify correct behavior and error handling for the new block acceptance on L1 feature.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 17, 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

A new feature was implemented to support marking blocks and their transactions as ACCEPTED_ON_L1 in the devnet. This includes the addition of a new JSON-RPC method devnet_acceptOnL1, corresponding request and response data structures, and logic to traverse and update the status of blocks and transactions starting from a specified block ID. The server-side logic, API models, and documentation were updated accordingly. Integration tests were added to verify correct status transitions, error handling, and edge cases for this new functionality.

Assessment against linked issues

Objective Addressed Explanation
Implement an endpoint/RPC method to mark all transactions in a block and its ancestors as ACCEPTED_ON_L1 (#808)
Ensure the method updates both block and transaction statuses to ACCEPTED_ON_L1 (#808)
Provide JSON-RPC API support and documentation for the new method (#808)
Add integration tests to verify correct status transitions and error handling for the new feature (#808)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found. All observed changes are directly related to implementing and testing the ACCEPTED_ON_L1 support as described in the linked issue.


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
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 17, 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: 1

🧹 Nitpick comments (4)
website/docs/blocks.md (3)

72-76: Add language specification to code block.

The static analysis tool correctly identifies that this JSON response should have a language specification for better syntax highlighting and clarity.

-Result:
+Result:

-```
+```json
 {"block_hash": "0x115e1b390cafa7942b6ab141ab85040defe7dee9bef3bc31d8b5b3d01cc9c67"}

---

`133-139`: **Add language specification to code block.**

This JSON response should have a language specification for consistency with other code blocks.



```diff
-Result:
+Result:

-```
+```json
 {
     "aborted": [BLOCK_HASH_0, BLOCK_HASH_1, ...]
 }

---

`147-183`: **LGTM! Comprehensive documentation for the new feature.**

The new "Accepting blocks on L1" section provides excellent documentation for the feature:
- Clear explanation of the functionality and its limitations
- Good examples showing the behavior
- Proper request/response format documentation
- Important note about simulation vs actual L1 operations



**Minor improvements for code block formatting:**

```diff
-Result:
+Result:

-```
+```json
 {
     "accepted": [BLOCK_HASH_0, BLOCK_HASH_1, ...]
 }

**Consider rewording to reduce repetitive sentence beginnings:**

The example section (line 159) has three consecutive sentences starting with "If". Consider varying the sentence structure for better readability.

</blockquote></details>
<details>
<summary>tests/integration/test_accepting_blocks_on_l1.rs (1)</summary><blockquote>

`1-226`: **Consider adding edge case test for genesis block.**

The test suite is comprehensive and well-structured, but consider adding a test for the edge case where acceptance starts from the genesis block (block 0). This would verify that the implementation correctly handles the case where there are no parent blocks to traverse.



Add a test like:

```rust
#[tokio::test]
async fn should_accept_genesis_block_only() {
    let devnet = BackgroundDevnet::spawn().await.unwrap();
    
    let accepted_block_hashes = accept_on_l1(&devnet, &BlockId::Number(0)).await.unwrap();
    assert_eq!(accepted_block_hashes.len(), 1);
    
    // Verify only genesis block is accepted
    let genesis_block = devnet.json_rpc_client.get_block_with_tx_hashes(BlockId::Number(0)).await.unwrap();
    assert_eq!(genesis_block.status, BlockStatus::AcceptedOnL1);
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce85ab2 and 105bb61.

📒 Files selected for processing (8)
  • crates/starknet-devnet-core/src/starknet/mod.rs (2 hunks)
  • crates/starknet-devnet-server/src/api/http/models.rs (1 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/mod.rs (7 hunks)
  • crates/starknet-devnet-server/src/api/json_rpc/write_endpoints.rs (2 hunks)
  • tests/integration/lib.rs (1 hunks)
  • tests/integration/test_accepting_blocks_on_l1.rs (1 hunks)
  • website/docs/blocks.md (4 hunks)
  • website/static/devnet_api.json (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: FabijanC
PR: 0xSpaceShard/starknet-devnet#755
File: crates/starknet-devnet-server/test_data/spec/0.8.1/starknet_executables.json:1154-1168
Timestamp: 2025-04-14T09:33:59.391Z
Learning: FabijanC wants to configure CodeRabbit to ignore spec files from review, specifically the JSON schema files in the test_data/spec directory.
crates/starknet-devnet-core/src/starknet/mod.rs (1)
Learnt from: FabijanC
PR: 0xSpaceShard/starknet-devnet#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: 0xSpaceShard/starknet-devnet#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 (1)
crates/starknet-devnet-core/src/starknet/mod.rs (3)
crates/starknet-devnet-server/src/api/json_rpc/write_endpoints.rs (2)
  • abort_blocks (155-158)
  • accept_on_l1 (161-165)
tests/integration/common/background_devnet.rs (1)
  • abort_blocks (397-419)
tests/integration/test_accepting_blocks_on_l1.rs (1)
  • accept_on_l1 (16-27)
🪛 markdownlint-cli2 (0.17.2)
website/docs/blocks.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)

🪛 LanguageTool
website/docs/blocks.md

[style] ~159-~159: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ..., 2, 3 and 4 shall be ACCEPTED_ON_L1. If a new block is mined after that (number...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (18)
tests/integration/lib.rs (1)

11-11: LGTM! Test module addition follows established pattern.

The addition of the test_accepting_blocks_on_l1 module is consistent with the existing test organization structure and clearly indicates the purpose of testing the new L1 acceptance feature.

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

64-74: LGTM! New HTTP models follow established patterns.

The AcceptOnL1Request and AcceptedOnL1Blocks structs are well-designed and consistent with existing models in the codebase. The field names, types, and serde attributes follow the established patterns used by similar structures like AbortingBlocks and AbortedBlocks.

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

22-25: LGTM! Import additions are consistent with the new feature.

The new imports for AcceptOnL1Request and AcceptedOnL1Blocks are properly added and follow the existing import organization in the file.


160-166: LGTM! Implementation follows established patterns.

The accept_on_l1 method implementation is consistent with other write endpoints in the file:

  • Proper async signature with StrictRpcResult return type
  • Appropriate state locking and delegation to core logic
  • Consistent error handling with the ? operator
  • Proper response wrapping in DevnetResponse enum
website/static/devnet_api.json (2)

355-359: LGTM! Improved clarity for abort blocks method.

The refinement of the devnet_abortBlocks method description provides better clarity about the operation scope and parameter usage.


390-426: LGTM! Well-structured API specification for the new method.

The devnet_acceptOnL1 method specification is comprehensive and follows the established patterns in the API documentation. The parameter and response schemas are properly defined with clear descriptions and appropriate references to shared schemas.

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

56-61: LGTM: Import additions are correctly organized

The new imports AcceptOnL1Request and AcceptedOnL1Blocks are properly added to the existing import statement and follow the alphabetical ordering pattern.


549-549: LGTM: Request handling follows established pattern

The new AcceptOnL1 variant is correctly handled in the execute method, following the same pattern as other devnet methods like AbortBlocks. The method properly delegates to self.accept_on_l1(data).await.


734-735: LGTM: Enum variant follows naming conventions

The new AcceptOnL1 variant is properly defined with the correct serde rename attribute "devnet_acceptOnL1" and appropriate parameter type AcceptOnL1Request.


765-765: LGTM: Correctly classified as requiring notification

The AcceptOnL1 variant is appropriately added to the requires_notifying() method, which makes sense since accepting blocks on L1 would be a state-changing operation that subscribers should be notified about.


862-862: LGTM: Correctly classified as not forwardable to origin

The AcceptOnL1 variant is correctly added to the is_forwardable_to_origin() method returning false. This is appropriate since this is a devnet-specific operation that shouldn't be forwarded to the origin network.


887-887: LGTM: Correctly classified as dumpable

The AcceptOnL1 variant is appropriately added to the is_dumpable() method returning true. This is consistent with other state-changing devnet operations like AbortBlocks and CreateBlock.


1045-1045: LGTM: Response enum variant properly defined

The new AcceptedOnL1Blocks(AcceptedOnL1Blocks) variant is correctly added to the DevnetResponse enum, following the same pattern as other devnet response types.

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

931-934: LGTM! Type-safe return type improvement.

The change from Vec<Felt> to Vec<TransactionHash> improves type safety while maintaining functionality, as TransactionHash is a type alias for Felt. This makes the API more semantically meaningful.


1022-1031: LGTM! Well-designed validation method.

The validation logic correctly identifies that only AcceptedOnL2 blocks can be accepted on L1, with clear error messages for invalid states. The implementation follows established patterns in the codebase.

tests/integration/test_accepting_blocks_on_l1.rs (3)

12-59: LGTM! Well-designed test helpers.

The helper functions provide good abstractions for common test operations:

  • send_dummy_tx generates test transactions
  • accept_on_l1 wraps the JSON-RPC call cleanly
  • assert_accepted_on_l1 and assert_latest_accepted_on_l2 provide comprehensive status verification

The helpers follow established test patterns and handle errors appropriately.


61-151: LGTM! Comprehensive happy path test coverage.

The tests thoroughly cover the main functionality:

  • Different block ID types (latest, numeric, hash)
  • Both instant and demand-based block generation modes
  • Verification of both block and transaction status changes
  • Proper boundary testing (blocks not included remain on L2)

The test structure is clear and follows good testing practices with proper setup, execution, and verification phases.


153-225: LGTM! Thorough error case testing.

The error tests comprehensively cover invalid scenarios:

  • Duplicate acceptance attempts
  • Invalid block states (pre-confirmed, rejected)
  • Non-existent block IDs

Each test properly verifies the expected error responses and ensures system state remains consistent after errors. The test cases align well with the validation logic in the core implementation.

@FabijanC FabijanC changed the title Supporting simulation of ACCEPTED_ON_L1 Support simulation of ACCEPTED_ON_L1 Jul 17, 2025
@FabijanC FabijanC merged commit 464ffa5 into main Jul 17, 2025
1 check passed
@FabijanC FabijanC deleted the accepted-on-l1 branch July 17, 2025 10:20
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.

Support for ACCEPTED_ON_L1

1 participant