Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(katana): move messaging into its own crate #3013

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Feb 12, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced deployment feedback that now displays both the contract address and the corresponding block number.
    • Updated CLI interactions that prompt for and require the block number when specifying a settlement contract.
    • Chain specifications now include block number details for improved settlement layer transparency.
    • Introduced a unified messaging configuration integration for streamlined message handling.
    • Added a new messaging module to support improved message processing capabilities.
    • New workspace member katana-messaging added, enhancing messaging functionalities across components.
  • Refactor

    • Refined dependency management and configuration across multiple components for improved consistency and performance.

@kariy kariy marked this pull request as ready for review February 12, 2025 18:31
Copy link

coderabbitai bot commented Feb 12, 2025

Ohayo, sensei!

Walkthrough

This pull request expands the workspace by adding a new messaging package and updating several Cargo.toml files to include or adjust dependencies and feature flags. It refines the settlement contract deployment process by introducing a new DeploymentOutcome struct, ensuring both contract address and block number are captured accurately. The chain specification is also enhanced by adding block fields to settlement layers. Additionally, the messaging configuration is updated across CLI, node, and service modules to shift from a fixed executor factory to a flexible provider-based interface, while the core service decouples messaging logic.

Changes

File(s) Change Summary
Cargo.toml, crates/katana/cli/Cargo.toml, crates/katana/node/Cargo.toml, crates/katana/rpc/rpc/Cargo.toml, crates/katana/sync/stage/Cargo.toml, crates/katana/core/Cargo.toml, crates/katana/chain-spec/Cargo.toml, crates/katana/storage/provider/Cargo.toml, crates/katana/messaging/Cargo.toml Added new workspace member crates/katana/messaging; introduced or adjusted dependencies (e.g., katana-messaging.workspace = true); updated dependency features and formatting; removed obsolete dependencies.
bin/katana/src/cli/init/deployment.rs, bin/katana/src/cli/init/mod.rs, bin/katana/src/cli/init/prompt.rs Introduced the DeploymentOutcome struct; updated functions and argument handling to return detailed deployment info (contract address and block number).
crates/katana/chain-spec/src/lib.rs, .../rollup/file.rs, .../rollup/utils.rs, crates/katana/core/tests/backend.rs Added block number fields to the SettlementLayer (both Ethereum and Starknet variants) and chain specification structures.
crates/katana/cli/src/args.rs, crates/katana/cli/src/file.rs, crates/katana/node/src/config/mod.rs, crates/katana/rpc/rpc/tests/messaging.rs, crates/katana/sync/stage/src/sequencing.rs, crates/katana/messaging/src/lib.rs, crates/katana/messaging/src/service.rs Updated MessagingConfig import sources from katana_core to katana_messaging; refactored CLI argument parsing to return an optional messaging config; modified MessagingService and MessagingTask to use a flexible provider (traits: BlockNumberProvider, ReceiptProvider).
crates/katana/core/src/service/mod.rs Removed the messaging module declaration, decoupling messaging functionality from the core service.

Sequence Diagram(s)

sequenceDiagram
    participant User as Client
    participant CLI as Init Module
    participant Deploy as deploy_settlement_contract
    participant Receipt as Receipt Service
    participant Block as BlockNumber Service
    User->>CLI: Initiate settlement contract deployment
    CLI->>Deploy: Call deploy_settlement_contract()
    Deploy->>Receipt: Request deployment receipt concurrently
    Deploy->>Block: Query current block number via tokio::join!
    Receipt-->>Deploy: Return contract address & block (if available)
    Block-->>Deploy: Return current block number
    Deploy->>CLI: Return DeploymentOutcome { contract_address, block_number }
Loading
sequenceDiagram
    participant App as Node/Application
    participant MS as MessagingService
    participant Prov as Provider (BlockNumber & Receipt)
    App->>MS: new(config, chain_spec, pool, provider)
    MS->>Prov: Fetch block number and receipts
    Prov-->>MS: Return latest block data and receipts
    MS-->>App: MessagingService initialized and ready
Loading

Possibly related PRs

  • feat(katana): chain spec file management tools #2945: Involves similar modifications to Cargo.toml files—adding dependencies and workspace members—which directly relate to the dependency management adjustments in this PR.
  • Merge katana/chainspec  #2947: Contains updates to the Cargo.toml file, focusing on the inclusion of the katana-chain-spec dependency, which is crucial for the functionality of the ChainSpec struct.

Suggested reviewers

  • glihm: Suggested for review due to familiarity with the messaging and deployment changes.

🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
crates/katana/messaging/src/service.rs (2)

18-18: Ohayo sensei, consider removing commented code.
Leaving commented-out imports can clutter the code and confuse future maintainers.


132-137: Ohayo sensei, robust approach to reading receipts by block.
However, using unwrap() could lead to panics if provider fails; consider a more graceful error handling.

crates/katana/sync/stage/src/sequencing.rs (1)

10-10: Ohayo! Nice architectural improvement, sensei!

The refactoring to use chain_spec and provider directly improves dependency injection and makes the messaging service more modular. The updated import path also reflects better code organization.

Also applies to: 42-45

bin/katana/src/cli/init/prompt.rs (1)

120-124: Add block number validation, sensei!

While the prompt for block number is well-documented, consider adding validation to ensure:

  1. The block number is not in the future
  2. The contract exists at the specified block
 let block_number =
     CustomType::<BlockNumber>::new("Settlement contract deployment block")
         .with_help_message("The block at which the settlement contract was deployed")
+        .with_validator(|input: &BlockNumber| {
+            // Fetch latest block number
+            let latest = l1_provider.block_number().await?;
+            if *input > latest {
+                return Err("Block number cannot be in the future".into());
+            }
+            // Verify contract exists at this block
+            let _ = l1_provider.get_class_hash_at(
+                BlockId::Number(*input),
+                address.into()
+            ).await?;
+            Ok(())
+        })
         .prompt()?;
crates/katana/messaging/src/lib.rs (1)

130-163: Ohayo! Nice implementation of from_chain_spec, sensei!

The method handles both Ethereum and Starknet settlement layers cleanly. However, consider extracting the magic number 2 for the interval into a named constant for better maintainability.

+const DEFAULT_MESSAGING_INTERVAL: u64 = 2;
 pub fn from_chain_spec(spec: &katana_chain_spec::rollup::ChainSpec) -> Self {
     match &spec.settlement {
         katana_chain_spec::SettlementLayer::Ethereum {
             rpc_url,
             core_contract,
             account,
             block,
             ..
         } => Self {
             chain: CONFIG_CHAIN_ETHEREUM.to_string(),
             rpc_url: rpc_url.to_string(),
             contract_address: core_contract.to_string(),
             sender_address: account.to_string(),
             private_key: Felt::ZERO.to_string(),
             from_block: *block,
-            interval: 2,
+            interval: DEFAULT_MESSAGING_INTERVAL,
         },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 130adb1 and d9d515a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • Cargo.toml (3 hunks)
  • bin/katana/src/cli/init/deployment.rs (4 hunks)
  • bin/katana/src/cli/init/mod.rs (6 hunks)
  • bin/katana/src/cli/init/prompt.rs (4 hunks)
  • crates/katana/chain-spec/Cargo.toml (1 hunks)
  • crates/katana/chain-spec/src/lib.rs (3 hunks)
  • crates/katana/chain-spec/src/rollup/file.rs (1 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (1 hunks)
  • crates/katana/cli/Cargo.toml (1 hunks)
  • crates/katana/cli/src/args.rs (5 hunks)
  • crates/katana/cli/src/file.rs (1 hunks)
  • crates/katana/core/Cargo.toml (1 hunks)
  • crates/katana/core/src/service/mod.rs (0 hunks)
  • crates/katana/core/tests/backend.rs (1 hunks)
  • crates/katana/messaging/Cargo.toml (1 hunks)
  • crates/katana/messaging/src/lib.rs (4 hunks)
  • crates/katana/messaging/src/service.rs (10 hunks)
  • crates/katana/node/Cargo.toml (1 hunks)
  • crates/katana/node/src/config/mod.rs (1 hunks)
  • crates/katana/rpc/rpc/Cargo.toml (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
  • crates/katana/storage/provider/Cargo.toml (1 hunks)
  • crates/katana/sync/stage/Cargo.toml (1 hunks)
  • crates/katana/sync/stage/src/sequencing.rs (2 hunks)
💤 Files with no reviewable changes (1)
  • crates/katana/core/src/service/mod.rs
✅ Files skipped from review due to trivial changes (3)
  • crates/katana/chain-spec/Cargo.toml
  • crates/katana/rpc/rpc/tests/messaging.rs
  • crates/katana/messaging/Cargo.toml
🔇 Additional comments (33)
crates/katana/messaging/src/service.rs (10)

7-9: Ohayo sensei, these new imports align perfectly with the new provider approach.
They properly reflect the shift from a backend-based approach to a flexible provider-based interface. Great job!


25-28: Ohayo sensei, nice approach to generics!
Ensuring P implements BlockNumberProvider, ReceiptProvider, and Clone fosters a clean architecture.


31-32: Ohayo sensei, these new fields look good.
Storing the provider and chain_spec is essential for the messaging logic.


46-49: Ohayo sensei, consistent approach to implementing the service with generics.
This is a straightforward reflection of the struct's constraints.


54-56: Ohayo sensei, verifying chain_spec and provider in the constructor.
This helps ensure the service is properly decoupled from a specific backend. Great job!


72-75: Ohayo sensei, correct usage of provider and chain_spec in struct construction.
Everything is consistent and properly assigned.


83-86: Ohayo sensei, consistent usage of chain_id in gathering messages.
This clarifies which chain is used to fetch receipts.


96-113: Ohayo sensei, multi-chain support is well-handled here.
Passing chain_id to gather messages in different modes is thoughtful and extends flexibility.


181-184: Ohayo sensei, the Stream implementation is neatly structured.
The generics ensure that both block numbers and receipts integrate seamlessly.


196-205: Ohayo sensei, great polling logic.
Still, consider safely handling provider.latest_number() errors instead of relying on unwrap().

crates/katana/node/src/config/mod.rs (1)

16-16: Ohayo sensei, nice refactoring of the MessagingConfig import.
Switching to katana_messaging ensures consistent architecture across the codebase.

crates/katana/cli/src/file.rs (1)

4-4: Ohayo sensei, consistent MessagingConfig import path update.
This harmonizes well with the new messaging module changes.

crates/katana/chain-spec/src/lib.rs (1)

84-85: Ohayo! Clean addition of block tracking, sensei!

The addition of the block field to track contract deployment blocks is well-structured and consistently implemented across both Ethereum and Starknet variants.

Also applies to: 101-102

crates/katana/core/tests/backend.rs (1)

61-67: Consider validating the default block value, sensei!

While initializing block: 0 works for testing, consider adding test cases that verify behavior with non-zero block numbers to ensure the system handles real deployment scenarios correctly.

bin/katana/src/cli/init/mod.rs (3)

46-52: Ohayo! Nice addition of block number tracking, sensei!

The new settlement_contract_deployed_block field with its corresponding requirements ensures that we always have the block number when a settlement contract is provided. This improves data consistency and traceability.


115-126: Clean implementation of DeploymentOutcome, sensei!

Good job encapsulating both the contract address and block number in a single structure. The code properly handles the block number extraction from the arguments.


73-74: Excellent propagation of block information, sensei!

The block number is correctly propagated to the settlement layer, maintaining consistency with the new deployment outcome structure.

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

247-250: Great trait abstraction, sensei!

The change from a concrete ExecutorFactory to trait bounds (BlockNumberProvider + ReceiptProvider) improves flexibility and follows good design principles.

crates/katana/chain-spec/src/rollup/file.rs (1)

338-338: Good test coverage maintenance, sensei!

The test has been properly updated to include the new block field initialization, maintaining test coverage.

bin/katana/src/cli/init/deployment.rs (3)

74-80: Clean struct definition with good documentation, sensei!

The DeploymentOutcome struct is well-designed and documented, clearly capturing both the contract address and deployment block number.


174-192: Excellent concurrent block number handling, sensei!

Smart use of tokio::join! to minimize timing discrepancies, with proper handling of the pending block case. The code effectively prevents race conditions.


265-268: Clear and informative success message, sensei!

The success message now includes both the contract address and block number, providing complete deployment information.

crates/katana/chain-spec/src/rollup/utils.rs (1)

370-370: Ohayo! The block field initialization looks good, sensei!

Initializing the block field to 0 for new settlement layer deployments is a sensible default.

crates/katana/cli/src/args.rs (3)

14-14: Ohayo! Clean import update, sensei!

Moving the messaging config to its own crate improves modularity.


83-85: Nice CLI argument constraints, sensei!

The conflicts_with = "chain" attribute prevents confusing configurations by ensuring messaging config comes from either CLI or chain spec, but not both.


189-194: Good handling of messaging config precedence, sensei!

The logic correctly prioritizes messaging config from chain spec over CLI arguments, with clear comments explaining the temporary nature of this approach.

crates/katana/sync/stage/Cargo.toml (1)

12-12: Ohayo! Clean dependency addition, sensei!

Adding katana-messaging as a workspace dependency aligns with the messaging module refactoring.

crates/katana/cli/Cargo.toml (1)

11-11: Ohayo! Clean dependency addition, sensei!

Adding katana-messaging as a workspace dependency aligns with the messaging module refactoring.

crates/katana/storage/provider/Cargo.toml (1)

18-21: Ohayo sensei! Dependencies reorganization looks good!

The dependencies have been properly moved from feature-gated to direct dependencies, making the dependency tree more explicit and easier to maintain.

Also applies to: 33-33

crates/katana/core/Cargo.toml (1)

14-15: Ohayo sensei! Feature flags are properly configured!

The katana-provider dependency now correctly specifies required features, and development dependencies have been appropriately added.

Also applies to: 39-44

crates/katana/rpc/rpc/Cargo.toml (1)

38-38: Ohayo sensei! Dev-dependency addition is well-placed!

Adding katana-messaging as a dev-dependency is appropriate for testing the RPC layer's interaction with messaging functionality.

crates/katana/node/Cargo.toml (1)

13-13: Ohayo sensei! Core dependency addition is spot on!

Adding katana-messaging as a direct dependency is essential for the node to handle messaging functionality.

Cargo.toml (1)

24-24: Ohayo sensei! Workspace configuration is well-structured!

The changes properly:

  • Establish the new messaging crate in the workspace
  • Configure dependencies with appropriate feature flags
  • Reintroduce necessary torii components

Also applies to: 102-102, 108-110, 124-128

@kariy kariy force-pushed the katana/messaging-move branch from d9d515a to 0ea3a76 Compare February 12, 2025 18:36
@kariy kariy force-pushed the katana/messaging-move branch from 0ea3a76 to f24f437 Compare February 12, 2025 18:39
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/katana/cli/src/args.rs (1)

190-193: Consider documenting the deprecation timeline.

While the comment explains that this is temporary, it would be helpful to document when this messaging configuration will be removed.

Add a TODO comment with the expected deprecation timeline:

-// the `katana init` will automatically generate a messaging config. so if katana is run
-// with `--chain` then the `--messaging` flag is not required. this is temporary and
-// the messagign config will eventually be removed slowly.
+// TODO(messaging): The messaging configuration will be deprecated and removed in future versions.
+// Timeline for deprecation:
+// 1. Mark as deprecated in v0.X
+// 2. Remove in v0.Y
+//
+// For now, katana init automatically generates a messaging config, so the --messaging flag
+// is not required when using --chain.
🛑 Comments failed to post (1)
crates/katana/messaging/src/service.rs (1)

135-139: 🛠️ Refactor suggestion

Consider enhancing error handling.

The unwrap call on line 135 could be replaced with proper error handling:

-        let Some(messages) = provider.receipts_by_block(block_num.into()).unwrap().map(|r| {
+        let Some(messages) = provider.receipts_by_block(block_num.into())
+            .map_err(|e| Error::Provider(e.into()))?
+            .map(|r| {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

        let Some(messages) = provider.receipts_by_block(block_num.into())
            .map_err(|e| Error::Provider(e.into()))?
            .map(|r| {
                r.iter().flat_map(|r| r.messages_sent().to_vec()).collect::<Vec<MessageToL1>>()
            }) else {
                return Ok(None);
            };

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/katana/messaging/src/lib.rs (1)

247-250: Excellent architectural improvement, sensei!

The shift from ExecutorFactory to specific provider traits (BlockNumberProvider + ReceiptProvider) improves:

  • Modularity: Components can implement just the traits they need
  • Testability: Easier to mock specific provider behaviors
  • Flexibility: More implementation options for consumers
crates/katana/cli/src/args.rs (1)

190-193: Consider enhancing the comment clarity.

While the comment explains the current behavior, it could be more explicit about:

  1. The timeline for removing messaging config
  2. The migration path for users
-// the `katana init` will automatically generate a messaging config. so if katana is run
-// with `--chain` then the `--messaging` flag is not required. this is temporary and
-// the messagign config will eventually be removed slowly.
+// TODO(messaging): The messaging config is being deprecated in favor of chain-spec-based configuration.
+// Currently, if katana is run with `--chain`, the `--messaging` flag is not required as the config
+// is automatically generated. This dual-configuration support is temporary and will be removed in
+// future versions.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ea3a76 and f24f437.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • Cargo.toml (3 hunks)
  • bin/katana/src/cli/init/deployment.rs (4 hunks)
  • bin/katana/src/cli/init/mod.rs (6 hunks)
  • bin/katana/src/cli/init/prompt.rs (4 hunks)
  • crates/katana/chain-spec/Cargo.toml (1 hunks)
  • crates/katana/chain-spec/src/lib.rs (3 hunks)
  • crates/katana/chain-spec/src/rollup/file.rs (1 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (1 hunks)
  • crates/katana/cli/Cargo.toml (1 hunks)
  • crates/katana/cli/src/args.rs (5 hunks)
  • crates/katana/cli/src/file.rs (1 hunks)
  • crates/katana/core/Cargo.toml (1 hunks)
  • crates/katana/core/src/service/mod.rs (0 hunks)
  • crates/katana/core/tests/backend.rs (1 hunks)
  • crates/katana/messaging/Cargo.toml (1 hunks)
  • crates/katana/messaging/src/lib.rs (4 hunks)
  • crates/katana/messaging/src/service.rs (10 hunks)
  • crates/katana/node/Cargo.toml (1 hunks)
  • crates/katana/node/src/config/mod.rs (1 hunks)
  • crates/katana/rpc/rpc/Cargo.toml (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
  • crates/katana/storage/provider/Cargo.toml (1 hunks)
  • crates/katana/sync/stage/Cargo.toml (1 hunks)
  • crates/katana/sync/stage/src/sequencing.rs (2 hunks)
💤 Files with no reviewable changes (1)
  • crates/katana/core/src/service/mod.rs
🚧 Files skipped from review as they are similar to previous changes (20)
  • crates/katana/sync/stage/Cargo.toml
  • crates/katana/cli/Cargo.toml
  • crates/katana/node/src/config/mod.rs
  • crates/katana/chain-spec/Cargo.toml
  • crates/katana/chain-spec/src/rollup/utils.rs
  • crates/katana/node/Cargo.toml
  • crates/katana/core/tests/backend.rs
  • crates/katana/cli/src/file.rs
  • crates/katana/rpc/rpc/tests/messaging.rs
  • bin/katana/src/cli/init/prompt.rs
  • crates/katana/chain-spec/src/rollup/file.rs
  • crates/katana/messaging/Cargo.toml
  • crates/katana/chain-spec/src/lib.rs
  • crates/katana/rpc/rpc/Cargo.toml
  • crates/katana/storage/provider/Cargo.toml
  • crates/katana/sync/stage/src/sequencing.rs
  • crates/katana/core/Cargo.toml
  • Cargo.toml
  • crates/katana/messaging/src/service.rs
  • bin/katana/src/cli/init/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (7)
crates/katana/messaging/src/lib.rs (2)

1-1: Ohayo! Clean dependency management and provider traits.

The crate attribute helps catch unused dependencies, and the new imports support the shift to a provider-based interface.

Also applies to: 54-57


130-163: Verify the security implications of using a zero private key.

The from_chain_spec method uses Felt::ZERO as the private key, which could be a security risk in production environments.

Consider:

  1. Is this intended only for development/testing?
  2. Should there be a warning or assertion to prevent accidental use in production?
crates/katana/cli/src/args.rs (2)

83-84: Ohayo! Good conflict prevention.

The conflicts_with = "chain" attribute prevents confusion by ensuring users don't try to use both chain and messaging options simultaneously.


250-256: Nice UX improvement, sensei!

The method now automatically generates messaging config from chain specs when available, reducing manual configuration needs.

bin/katana/src/cli/init/deployment.rs (3)

74-80: Ohayo! Clean and well-documented struct definition, sensei!

The DeploymentOutcome struct is well-designed with clear field documentation.


264-268: Nice success message update, sensei!

The updated success message now provides comprehensive deployment information including both the contract address and block number.


174-192: Ohayo sensei! Let's verify the block number calculation for edge cases.

While the concurrent fetching of deployment receipt and block number is a good improvement, there might be edge cases where the block number could be off by more than 1 if there are multiple pending transactions.

Could you verify if this edge case needs handling by checking if there are any tests or documentation addressing this scenario? You might want to search for:

✅ Verification successful

🌐 Web query:

How to handle multiple pending transactions when determining block numbers in Starknet?

💡 Result:

To handle multiple pending transactions when determining block numbers in Starknet:

Transaction Status & Block Association

  • Pending transactions exist in Starknet's mempool but haven't been finalized in a closed block[1][10]
  • They belong to either:
    • The pending block (block under active construction)
    • The transaction pool (awaiting inclusion)[4]

Key Implementation Strategies

  1. Block Number Queries
    Use blockNumber=pending parameter in API calls to:

    account.get_nonce(block_number="pending")  # From starknet.py[3]

    This reflects state changes from all pending transactions[1]

  2. Transaction Ordering
    Pending transactions don't have final ordering until:

    • Block reaches ACCEPTED_ON_L2 status[1][5]
    • Block hash gets assigned[2]
  3. Nonce Management
    Handle potential conflicts using:

    async def handle_pending_txs():
        current_nonce = await account.get_nonce(block_number="pending")
        for i, tx in enumerate(pending_transactions):
            tx.nonce = current_nonce + i

    Requires monitoring mempool for nonce gaps[7]

  4. Block Construction Analysis
    Query current pending block details:

    SELECT hash, transaction_count 
    FROM starknet.blocks 
    WHERE status = 'PENDING'  # Example Dune Analytics query[8]

Critical Considerations

  • Transaction Replacement: Higher fee transactions can replace stuck ones with same nonce[7]
  • State Diff Tracking: Use state_diff_commitment field to monitor pending changes[2][10]
  • Sequencer Behavior: Blocks transition from PENDINGACCEPTED_ON_L2ACCEPTED_ON_L1[5][10]

Best practice is to treat pending blocks as provisional until reaching ACCEPTED_ON_L2 status, using Starknet's specific pending-block APIs rather than assuming L1-style finality[1][3][5]. Transactions in the same pending block share temporal sequencing but lack canonical ordering until block closure[2][10].

Citations:


Ohayo sensei! After checking the latest documentation on how Starknet handles pending transactions, it turns out that pending transactions are grouped into a single pending block—meaning that regardless of how many transactions are waiting, the pending block’s number is still just the latest block number plus one. This aligns with your current logic, which defaults to using block_number + 1 when the receipt doesn't include a block number.

No additional edge-case handling appears necessary based on standard practices for Starknet. However, it's always a good idea to ensure your tests cover scenarios where the receipt is missing the block number.

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 24.46809% with 71 lines in your changes missing coverage. Please review.

Project coverage is 56.40%. Comparing base (130adb1) to head (f24f437).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/messaging/src/lib.rs 3.12% 31 Missing ⚠️
bin/katana/src/cli/init/deployment.rs 0.00% 19 Missing ⚠️
bin/katana/src/cli/init/mod.rs 0.00% 11 Missing ⚠️
bin/katana/src/cli/init/prompt.rs 0.00% 7 Missing ⚠️
crates/katana/cli/src/args.rs 66.66% 2 Missing ⚠️
crates/katana/messaging/src/service.rs 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3013      +/-   ##
==========================================
+ Coverage   56.38%   56.40%   +0.01%     
==========================================
  Files         434      434              
  Lines       58075    58077       +2     
==========================================
+ Hits        32748    32759      +11     
+ Misses      25327    25318       -9     

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

@kariy kariy merged commit a1b21bf into main Feb 12, 2025
14 of 15 checks passed
@kariy kariy deleted the katana/messaging-move branch February 12, 2025 19:19
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