Skip to content

feat(katana): automatically close block if resources limit reached#3003

Merged
kariy merged 2 commits intomainfrom
katana/block-limit
Feb 10, 2025
Merged

feat(katana): automatically close block if resources limit reached#3003
kariy merged 2 commits intomainfrom
katana/block-limit

Conversation

@kariy
Copy link
Member

@kariy kariy commented Feb 10, 2025

Add resource limit parameter for interval block mining. Blocks will now be prompted to close when the total execution resources of their transactions reaches this configurable threshold. Configure via the new --sequencing.block-max-cairo-steps CLI argument.


Transactions that have been queued to the block producer, but is unable to be included in the current block due to the resources limit, will be pushed to the next block.

Summary by CodeRabbit

  • New Features

    • Introduced a new command-line option for setting a maximum limit on Cairo steps per block, giving users more granular control over block production.
    • Added enhanced sequencing configuration settings that allow customization of block timing and mining behavior.
  • Enhancements

    • Improved transaction handling by better managing block capacity and error reporting during block production.
    • Streamlined configuration integration to provide more reliable and adaptive block execution across the system.
    • Enhanced clarity and efficiency in testing logic for block production.
    • Added a new error handling mechanism for transaction execution, providing more detailed feedback on execution outcomes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

Ohayo sensei! This PR refactors configuration and block production logic across the codebase. It updates function signatures to require a SequencingConfig, reorganizes its module path, and introduces a new CLI option for controlling block Cairo steps. In addition, the PR integrates a new BlockLimits construct with corresponding modifications to executor and block production methods, enhances error handling with an added ExecutorError variant, and adjusts transaction execution to return more detailed results.

Changes

File(s) Change Summary
crates/dojo/test-utils/src/sequencer.rs
crates/katana/cli/src/args.rs
crates/katana/node/src/config/mod.rs
crates/katana/node/src/config/sequencing.rs
crates/katana/rpc/rpc/tests/dev.rs
crates/katana/rpc/rpc/tests/forking.rs
crates/katana/rpc/rpc/tests/messaging.rs
crates/katana/rpc/rpc/tests/proofs.rs
crates/katana/rpc/rpc/tests/saya.rs
crates/katana/rpc/rpc/tests/starknet.rs
crates/katana/rpc/rpc/tests/torii.rs
Reworked sequencing configuration: updated get_default_test_config to accept a SequencingConfig, added new CLI field block_cairo_steps_limit, introduced a dedicated SequencingConfig struct, and updated all relevant import paths to the new module location.
crates/katana/chain-spec/src/rollup/utils.rs
crates/katana/core/src/service/block_producer.rs
crates/katana/core/tests/backend.rs
Integrated BlockLimits: updated import to include BlockLimits, modified executor functions to pass BlockLimits::max(), and added a new method is_block_limit_exhausted along with updates to TxExecutionResult for enhanced block capacity checks.
crates/katana/executor/benches/concurrent.rs
crates/katana/executor/benches/execution.rs
crates/katana/executor/src/abstraction/error.rs
crates/katana/executor/src/abstraction/executor.rs
crates/katana/executor/src/abstraction/mod.rs
crates/katana/executor/src/implementation/blockifier/error.rs
crates/katana/executor/src/implementation/blockifier/mod.rs
crates/katana/executor/src/implementation/blockifier/utils.rs
crates/katana/executor/src/implementation/noop.rs
crates/katana/executor/tests/fixtures/mod.rs
crates/katana/node/src/lib.rs
Enhanced executor and transaction execution: updated execute_transactions to return a tuple (number of transactions and an optional ExecutorError), introduced the new ExecutorError enum, modified BlockifierFactory to include BlockLimits and a bouncer, and refined the transact function to accept an optional bouncer for improved state management and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Node as Node
    participant Config as Config Object
    participant SeqConf as SequencingConfig
    participant BL as BlockLimits
    participant BF as BlockifierFactory

    Node->>Config: Load configuration
    Config->>SeqConf: Retrieve sequencing settings
    SeqConf->>BL: Call block_limits() (uses block_cairo_steps_limit if provided)
    Node->>BF: Initialize BlockifierFactory with cfg, execution flags, and BL
Loading
sequenceDiagram
    participant Executor as BlockExecutor
    participant Transact as transact Function
    participant Bouncer as Bouncer (optional)
    participant State as TransactionalState

    Executor->>Transact: Call transact(state, context, flags, tx, bouncer?)
    Transact->>State: Create transactional state and process tx
    Transact-->>Executor: Return (executed transactions, optionally leftover txs)
    alt Bouncer provided
        Executor->>Bouncer: Use bouncer for additional state validation
    end
    Executor-->>Executor: Update block full status and check for ExecutorError
Loading

Possibly related PRs


🪧 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
Contributor

@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 (9)
crates/katana/executor/src/implementation/blockifier/mod.rs (1)

101-104: Ohayo sensei! Leveraging BouncerWeights::max() and assigning n_steps is neat.
A minor improvement: consider logging or tracing the final n_steps value for debugging resource caps.

crates/katana/core/src/service/block_producer.rs (1)

1-10: Ohayo sensei! These poetic doc comments add a whimsical touch while staying organized.

crates/katana/node/src/config/sequencing.rs (2)

14-22: Ohayo! Consider enhancing documentation for block_cairo_steps_limit

The documentation could be more helpful by including:

  • Example values or recommended ranges
  • Impact on transaction throughput
  • Relationship with Starknet's current limits
     /// The maximum number of Cairo steps in a block.
-    //
     /// The block will automatically be closed when the accumulated Cairo steps across all the
     /// transactions has reached this limit.
     ///
     /// NOTE: This only affect interval block production.
     ///
+    /// Example: Setting this to 1_000_000 would close the block after approximately
+    /// 1M Cairo steps, which is well below Starknet's current limit of ~10M steps.
+    ///
     /// See <https://docs.starknet.io/chain-info/#current_limits>.

26-28: Consider adding validation for block_cairo_steps_limit

The block_limits method could validate that the limit is within reasonable bounds when specified.

     pub fn block_limits(&self) -> BlockLimits {
-        BlockLimits { cairo_steps: self.block_cairo_steps_limit.unwrap_or(u64::MAX) }
+        let steps = self.block_cairo_steps_limit.unwrap_or(u64::MAX);
+        if let Some(limit) = self.block_cairo_steps_limit {
+            assert!(limit > 0, "block_cairo_steps_limit must be positive");
+        }
+        BlockLimits { cairo_steps: steps }
     }
crates/katana/executor/benches/execution.rs (1)

52-54: Document the new None parameter in transact call, sensei

The None parameter appears to be related to block limits, but its purpose isn't immediately clear from the context.

Add a comment explaining the parameter:

            |(mut state, block_context, flags, tx)| {
+               // None: No block limits for benchmarking
                transact(&mut state, block_context, flags, tx, None)
            },
crates/katana/executor/src/abstraction/error.rs (1)

7-13: Enhance LimitsExhausted error with specific limit information

Consider adding context about which limit was exhausted to help with debugging.

 pub enum ExecutorError {
-    #[error("Limits exhausted")]
-    LimitsExhausted,
+    #[error("Limits exhausted: {limit_type} reached {current}/{max}")]
+    LimitsExhausted {
+        limit_type: &'static str,
+        current: u64,
+        max: u64,
+    },

     #[error(transparent)]
     Other(Box<dyn core::error::Error + Send + Sync + 'static>),
 }
crates/katana/executor/src/abstraction/executor.rs (1)

42-46: Enhanced return type for better error handling

The new return type ExecutorResult<(usize, Option<ExecutorError>)> provides valuable information:

  • Number of transactions successfully executed
  • Optional error if execution stopped due to resource limits

This design pattern allows for graceful handling of partial block execution, which is essential for implementing resource limits.

crates/katana/executor/src/abstraction/mod.rs (1)

27-31: Consider using a named constant for maximum steps, sensei!

Instead of using u64::MAX directly, consider defining a constant like MAX_CAIRO_STEPS to make the code more maintainable and self-documenting.

+const MAX_CAIRO_STEPS: u64 = u64::MAX;

 impl BlockLimits {
     pub fn max() -> Self {
-        Self { cairo_steps: u64::MAX }
+        Self { cairo_steps: MAX_CAIRO_STEPS }
     }
 }
crates/katana/node/src/lib.rs (1)

185-189: Ohayo! The BlockifierFactory initialization looks good, sensei!

The addition of block_limits() parameter aligns well with the PR objective of implementing automatic block closure based on resource limits.

Consider adding a comment explaining the significance of the block limits parameter for better code documentation:

 let executor_factory = Arc::new(BlockifierFactory::new(
     cfg_env,
     execution_flags,
+    // Block limits control automatic block closure when resource thresholds are met
     config.sequencing.block_limits(),
 ));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9227db and 8c639e3.

📒 Files selected for processing (26)
  • crates/dojo/test-utils/src/sequencer.rs (1 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (2 hunks)
  • crates/katana/cli/src/args.rs (4 hunks)
  • crates/katana/contracts/piltover (1 hunks)
  • crates/katana/core/src/service/block_producer.rs (12 hunks)
  • crates/katana/core/tests/backend.rs (2 hunks)
  • crates/katana/executor/benches/concurrent.rs (2 hunks)
  • crates/katana/executor/benches/execution.rs (1 hunks)
  • crates/katana/executor/src/abstraction/error.rs (1 hunks)
  • crates/katana/executor/src/abstraction/executor.rs (2 hunks)
  • crates/katana/executor/src/abstraction/mod.rs (1 hunks)
  • crates/katana/executor/src/implementation/blockifier/error.rs (3 hunks)
  • crates/katana/executor/src/implementation/blockifier/mod.rs (9 hunks)
  • crates/katana/executor/src/implementation/blockifier/utils.rs (4 hunks)
  • crates/katana/executor/src/implementation/noop.rs (2 hunks)
  • crates/katana/executor/tests/fixtures/mod.rs (1 hunks)
  • crates/katana/node/src/config/mod.rs (2 hunks)
  • crates/katana/node/src/config/sequencing.rs (1 hunks)
  • crates/katana/node/src/lib.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/dev.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/forking.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/proofs.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/saya.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/torii.rs (1 hunks)
✅ Files skipped from review due to trivial changes (8)
  • crates/katana/contracts/piltover
  • crates/katana/rpc/rpc/tests/proofs.rs
  • crates/katana/rpc/rpc/tests/forking.rs
  • crates/katana/rpc/rpc/tests/saya.rs
  • crates/katana/rpc/rpc/tests/messaging.rs
  • crates/katana/rpc/rpc/tests/starknet.rs
  • crates/katana/rpc/rpc/tests/torii.rs
  • crates/katana/rpc/rpc/tests/dev.rs
🔇 Additional comments (41)
crates/katana/executor/src/implementation/blockifier/mod.rs (13)

3-3: Ohayo sensei! New import looks clean.


26-28: Ohayo sensei! The expanded references are nicely structured for convenience.


37-37: Ohayo sensei! Adding the limits field in the factory is a clear approach to store block constraints.


42-43: Ohayo sensei! The new constructor seamlessly integrates the limits parameter.


65-66: Ohayo sensei! Forwarding the cloned limits to StarknetVMProcessor is a consistent design choice.


86-86: Ohayo sensei! Including the bouncer field enhances resource-limiting logic capabilities.


95-95: Ohayo sensei! Accepting BlockLimits here aligns well with the broadened resource constraints.


105-112: Ohayo sensei! Initializing fields with the new bouncer is well-coordinated.


168-168: Ohayo sensei! Returning (usize, Option<ExecutorError>) is a great way to report partial progress and limit errors.


193-193: Ohayo sensei! Starting total_executed at zero is straightforward for counting executions.


205-211: Ohayo sensei! Passing Some(&mut self.bouncer) properly integrates block capacity checks.


213-239: Ohayo sensei! The LimitsExhausted branch accurately returns partial results when block capacity is reached.


246-246: Ohayo sensei! Returning the executed count with no error suits the completion path for normal execution.

crates/katana/core/src/service/block_producer.rs (8)

60-69: Ohayo sensei! The is_block_limit_exhausted method neatly isolates the error check logic.


89-90: Ohayo sensei! Returning leftover transactions with the main results is a clever enhancement for block capacity handling.


238-239: Ohayo sensei! Tracking whether the block is full with a boolean is straightforward and effective.


337-337: Ohayo sensei! Accepting the transactions vector by mut reference is a clean approach for partial execution logic.


341-341: Ohayo sensei! Extracting (total_executed, is_full) from execute_transactions suits the new resource-limiting scenario.


349-349: Ohayo sensei! The skip offset referencing the newly executed transactions is correct for fetching relevant results.


360-364: Ohayo sensei! Splitting off leftover transactions when block is full is a neat solution to queue them for the next block.


493-504: Ohayo sensei! Re-queueing leftover transactions and waking the context is a smart way to handle block closure mid-interval.

crates/katana/executor/src/implementation/blockifier/utils.rs (8)

6-6: Ohayo sensei! Adding Bouncer and BouncerConfig imports aligns perfectly with the new resource checks.


17-18: Ohayo sensei! Introducing TransactionalState and UpdatableState fosters layered or test-friendly state management.


61-61: Ohayo sensei! Including ExecutorResult in the imports centralizes error handling seamlessly.


68-69: Ohayo sensei! The optional bouncer parameter is a flexible way to enable or skip capacity checks.


70-71: Ohayo sensei! Switching to a generic UpdatableState is an elegant solution for broader state usage patterns.


128-129: Ohayo sensei! The transactional state approach ensures each invocation is atomic and can be safely rolled back if needed.


132-144: Ohayo sensei! Invoking bouncer.try_update(...) here correctly ensures each transaction's resource usage is accounted for before committing.


153-155: Ohayo sensei! Committing state even on error aligns with the design, preserving partial changes and consistent state transitions.

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

9-9: LGTM! Clean integration of sequencing configuration

The sequencing module is well-integrated into the config structure with proper documentation.

Also applies to: 19-19, 47-48

crates/katana/executor/src/abstraction/executor.rs (1)

8-8: Ohayo! New error type import looks good sensei!

The addition of ExecutorError import aligns with the enhanced error handling requirements.

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

8-8: Ohayo! Test configuration looks good sensei!

Using BlockLimits::max() in tests ensures no artificial resource constraints during testing.

Consider if we should add tests with specific resource limits to verify the limiting behavior:

Also applies to: 29-29

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Check if there are any tests with non-max block limits
rg -l "BlockLimits::new|block_limits.*=(?!.*max)" 

Length of output: 328


Ohayo, sensei!

The initial regex check hit a snag due to unsupported look-around. To re-run the check correctly, please verify using the updated command below that enables PCRE2, which supports look-ahead:

If this command produces no output, it confirms that all tests (including the one on line 29) are using BlockLimits::max() consistently. That said, as mentioned in the review comment, we might consider adding tests with specific (non-max) resource limits to verify the limiting behavior where appropriate.


🏁 Script executed:

#!/bin/bash
# Re-run regex with PCRE2 support to check for any tests using non-max block limits
rg --pcre2 -l "BlockLimits::new|block_limits.*=(?!.*max)"

Length of output: 181


Ohayo, sensei!

It looks like our original script included a literal `` line, causing an error that interfered with the expected output. Let’s try a corrected script without the extra text. Please run the following command manually to confirm that no tests are using non-max block limits (this check covers both line 8 and line 29):

If this command produces no output, it confirms that all tests are correctly using BlockLimits::max(). We might, however, consider adding tests that intentionally use specific (non-max) limits to validate the limiting behavior in varied scenarios.


🏁 Script executed:

#!/bin/bash
# Check for non-max block limits usage in tests
rg --pcre2 -l "BlockLimits::new|block_limits.*=(?!.*max)"

Length of output: 59


Ohayo, sensei!

The recent check shows no tests using non-max block limits. Both the relevant lines (8 and 29) in the tests are consistently using BlockLimits::max(). This confirms that the test configuration is intentional and sound. That said, adding tests with specific non-max limits could be an interesting way to verify the limiting behavior if needed.

crates/katana/executor/benches/concurrent.rs (1)

12-12: Ohayo! Benchmark configuration updated appropriately sensei!

Using BlockLimits::max() in benchmarks ensures resource limits don't affect performance measurements.

Consider adding benchmarks with various block limits to measure their impact:

Also applies to: 47-47

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Check if there are any benchmarks with different block limits
rg -l "benchmark.*block.*limit" 

Length of output: 33


Ohayo, sensei! I reviewed the benchmark configuration in crates/katana/executor/benches/concurrent.rs and confirmed that it now imports and uses BlockLimits::max(), both at the top (line 12) and again around line 47. This ensures that resource limits won’t interfere with the performance measurements.

However, no alternative benchmarks using different block limit values were found. If you’d like to evaluate how varying block limits affect performance, you might consider adding extra benchmarks that use non-maximal values.

crates/dojo/test-utils/src/sequencer.rs (1)

9-9: Ohayo! Test utility enhancement looks good sensei!

The addition of SequencingConfig parameter allows tests to specify custom sequencing behavior, including block limits.

Consider if we should add helper methods for common sequencing configurations:

Also applies to: 117-117

❌ Verification inconclusive

🏁 Script executed:

#!/bin/bash
# Check for existing helper methods
rg -l "fn.*sequencing.*config" 

Length of output: 32


Ohayo, sensei! The updated test utility enhancements look solid with the inclusion of the SequencingConfig parameter for flexible sequencing behavior. However, our initial search for helper methods related to common sequencing configurations (using the pattern fn.*sequencing.*config) didn’t turn up any results. If you expected to see such helpers or if they would simplify test setups, please verify manually if adding them is desired. This suggestion also applies to lines 117‑117.

crates/katana/executor/src/implementation/blockifier/error.rs (1)

105-113: Ohayo! Clean error mapping implementation, sensei!

The new From implementation elegantly handles the block resource limits by mapping BlockFull to LimitsExhausted, which aligns perfectly with the PR's objective of managing block resource limits.

crates/katana/executor/src/implementation/noop.rs (1)

101-107: Ohayo! Clean update to execute_transactions, sensei!

The return type change to include transaction count and optional error is well-implemented, maintaining the no-op behavior while supporting the new block resource limit feature.

crates/katana/executor/src/abstraction/mod.rs (1)

20-25: Ohayo! Well-documented struct, sensei!

The BlockLimits struct is clearly documented with a reference to the official Starknet documentation.

crates/katana/executor/tests/fixtures/mod.rs (1)

274-276: Ohayo! Clean factory update, sensei!

The addition of BlockLimits::max() to the factory instantiation is appropriate for test fixtures, ensuring no artificial restrictions during testing.

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

339-339: Ohayo! The BlockLimits integration looks good, sensei!

The addition of BlockLimits import and its usage in the executor function with max() is appropriate for test scenarios where we want to avoid resource constraints.

Also applies to: 389-390

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

195-199: The sequencing config update looks good, sensei!

The integration of the new block_cairo_steps_limit into the SequencingConfig is clean and consistent.


155-156: Ohayo! The log filter update looks good, sensei!

The log filter modification maintains essential debug levels while removing redundant entries.

Comment on lines +62 to +64
#[arg(long = "sequencing.block-max-cairo-steps")]
#[arg(value_name = "TOTAL")]
pub block_cairo_steps_limit: Option<u64>,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding value validation for the block steps limit, sensei!

While the new CLI argument is well-documented, it should validate that the provided value is positive.

Consider adding a value parser that validates the input:

#[arg(long = "sequencing.block-max-cairo-steps")]
#[arg(value_name = "TOTAL")]
#[arg(value_parser = clap::value_parser!(u64).range(1..))]
pub block_cairo_steps_limit: Option<u64>,

@kariy kariy force-pushed the katana/block-limit branch from 8c639e3 to 3038816 Compare February 10, 2025 16:18
Copy link
Contributor

@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

🔭 Outside diff range comments (1)
crates/katana/cli/src/args.rs (1)

349-412: Add config file merge logic for block_cairo_steps_limit.

The new block_cairo_steps_limit field is not included in the config file merging logic. This means the value from the config file won't be used when not specified via CLI.

Add the merge logic in the with_config_file method:

         if self.block_time.is_none() {
             self.block_time = config.block_time;
         }
 
+        if self.block_cairo_steps_limit.is_none() {
+            self.block_cairo_steps_limit = config.block_cairo_steps_limit;
+        }
+
         if self.db_dir.is_none() {
             self.db_dir = config.db_dir;
         }
🧹 Nitpick comments (3)
crates/katana/executor/src/implementation/blockifier/mod.rs (1)

101-103: Consider initializing block_max_capacity with limits.

The block capacity configuration could be initialized directly from the limits parameter.

-let mut block_max_capacity = BouncerWeights::max();
-block_max_capacity.n_steps = limits.cairo_steps as usize;
+let block_max_capacity = BouncerWeights {
+    n_steps: limits.cairo_steps as usize,
+    ..BouncerWeights::max()
+};
crates/katana/core/src/service/block_producer.rs (1)

492-501: Consider adding debug logging for leftover transactions.

Adding debug logs would help track the number of transactions that couldn't fit in the current block.

 if let Some(leftovers) = leftovers {
     pin.is_block_full = true;
+    trace!(
+        target: LOG_TARGET,
+        leftover_count = leftovers.len(),
+        "Block full, queuing leftover transactions for next block"
+    );
     // Push leftover transactions back to front of queue
     pin.queued.push_front(leftovers);
crates/katana/executor/src/implementation/blockifier/utils.rs (1)

1-900: Consider documenting the resource limit behavior.

The implementation of resource limits through the bouncer mechanism is solid. Consider adding documentation about:

  1. How resource limits are enforced
  2. What happens when limits are reached
  3. How transactions are handled when rejected due to resource constraints
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c639e3 and 3038816.

📒 Files selected for processing (25)
  • crates/dojo/test-utils/src/sequencer.rs (1 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (2 hunks)
  • crates/katana/cli/src/args.rs (3 hunks)
  • crates/katana/core/src/service/block_producer.rs (10 hunks)
  • crates/katana/core/tests/backend.rs (2 hunks)
  • crates/katana/executor/benches/concurrent.rs (2 hunks)
  • crates/katana/executor/benches/execution.rs (1 hunks)
  • crates/katana/executor/src/abstraction/error.rs (1 hunks)
  • crates/katana/executor/src/abstraction/executor.rs (2 hunks)
  • crates/katana/executor/src/abstraction/mod.rs (1 hunks)
  • crates/katana/executor/src/implementation/blockifier/error.rs (3 hunks)
  • crates/katana/executor/src/implementation/blockifier/mod.rs (9 hunks)
  • crates/katana/executor/src/implementation/blockifier/utils.rs (4 hunks)
  • crates/katana/executor/src/implementation/noop.rs (2 hunks)
  • crates/katana/executor/tests/fixtures/mod.rs (1 hunks)
  • crates/katana/node/src/config/mod.rs (2 hunks)
  • crates/katana/node/src/config/sequencing.rs (1 hunks)
  • crates/katana/node/src/lib.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/dev.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/forking.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/proofs.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/saya.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/torii.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (18)
  • crates/katana/executor/src/implementation/blockifier/error.rs
  • crates/katana/rpc/rpc/tests/messaging.rs
  • crates/katana/executor/benches/concurrent.rs
  • crates/katana/core/tests/backend.rs
  • crates/katana/rpc/rpc/tests/proofs.rs
  • crates/katana/executor/benches/execution.rs
  • crates/katana/rpc/rpc/tests/torii.rs
  • crates/katana/node/src/config/sequencing.rs
  • crates/katana/executor/tests/fixtures/mod.rs
  • crates/katana/rpc/rpc/tests/starknet.rs
  • crates/dojo/test-utils/src/sequencer.rs
  • crates/katana/executor/src/abstraction/error.rs
  • crates/katana/executor/src/abstraction/mod.rs
  • crates/katana/node/src/lib.rs
  • crates/katana/rpc/rpc/tests/forking.rs
  • crates/katana/rpc/rpc/tests/dev.rs
  • crates/katana/rpc/rpc/tests/saya.rs
  • crates/katana/chain-spec/src/rollup/utils.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ensure-wasm
  • GitHub Check: build
  • GitHub Check: docs
🔇 Additional comments (15)
crates/katana/node/src/config/mod.rs (1)

9-9: LGTM! Clean and well-organized module structure, sensei!

The changes follow Rust's module system best practices, with proper organization of imports and clear documentation.

Also applies to: 19-19, 47-48

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

62-64: Add value validation for the block steps limit.

While the new CLI argument is well-documented, it should validate that the provided value is positive.

crates/katana/executor/src/abstraction/executor.rs (2)

8-8: LGTM!

The import of ExecutorError aligns with the enhanced error handling mechanism.


42-46: Improved return type provides better execution insights.

The updated return type now includes both the count of executed transactions and potential execution errors, enabling better handling of resource limits and execution failures.

crates/katana/executor/src/implementation/noop.rs (2)

16-16: LGTM!

The import of both error types maintains consistency with the trait requirements.


104-106: Appropriate no-op implementation.

The implementation correctly returns zero executed transactions and no error, maintaining the expected behavior of a no-op executor.

crates/katana/executor/src/implementation/blockifier/mod.rs (1)

3-3: LGTM!

The import of bouncer types enables resource limit management.

crates/katana/core/src/service/block_producer.rs (3)

1-10: Ohayo sensei! Beautiful ASCII art and quote.

The ASCII art and quote add a nice touch to the codebase.


62-67: Well-structured error handling.

The is_block_limit_exhausted method provides a clean way to check for resource exhaustion.


341-341: Elegant handling of leftover transactions.

The code efficiently handles transactions that couldn't be included in the current block by:

  1. Tracking the number of executed transactions
  2. Splitting off non-executed transactions
  3. Returning them for future processing

Also applies to: 361-362

crates/katana/executor/src/implementation/blockifier/utils.rs (5)

6-6: Ohayo sensei! The new imports look good!

The addition of Bouncer and state management types aligns well with the PR's objective of implementing resource limits.

Also applies to: 17-18


63-69: Function signature change looks good!

The addition of the optional bouncer parameter enables resource limit checks while maintaining backward compatibility.


70-75: Nice improvement to state management!

The change from StateReader to UpdatableState generic type makes the function more flexible and reusable.


727-898: Great test coverage, sensei!

The test suite thoroughly covers:

  • Chain ID conversions and invariants
  • Call info transformations
  • Event handling

126-144: Verify state management in error cases.

The state changes are committed even in error cases. While this is generally correct for maintaining consistency, please ensure that this behavior is intended and documented.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for tests or documentation about state commitment behavior
rg -A 5 "state.*commit" --type rust

Length of output: 8784


Ohayo, sensei! Verification Summary – State Is Committed on All Branches

  • Our search confirms that tx_state.commit() is explicitly invoked in both the success and error branches.
  • While no separate test explicitly documents error-case state commitment behavior, related documentation in the chain-spec and state provider (e.g., in crates/katana/storage/provider/src/traits/state.rs) implies that maintaining a consistent state commitment is the intended design.
  • This indicates that persisting state changes even when errors occur is deliberate. However, if further clarity is desired, adding inline comments or documentation would be beneficial for future readers.

Copy link
Contributor

@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 (3)
crates/katana/core/src/service/block_producer_tests.rs (1)

71-73: Ohayo sensei! Consider adding resource limit tests.

While the current assertions verify basic block mining functionality, consider adding test cases that specifically verify the new block resource limit feature. This would help ensure that blocks are automatically closed when the --sequencing.block-max-cairo-steps limit is reached.

Would you like me to help generate additional test cases that cover the resource limit scenarios?

crates/katana/core/src/service/block_producer.rs (2)

239-239: Consider using an atomic boolean for thread safety.

The is_block_full flag might be accessed from multiple threads. Consider using AtomicBool for better thread safety.

-    is_block_full: bool,
+    is_block_full: std::sync::atomic::AtomicBool,

487-502: Consider adding metrics for block fullness.

It would be valuable to track how often blocks are being closed due to resource limits.

 if let Some(leftovers) = leftovers {
     pin.is_block_full = true;
+    metrics::increment_counter!("katana_block_full_count");
+    metrics::gauge!("katana_leftover_transactions", leftovers.len() as f64);
 
     // Push leftover transactions back to front of queue
     pin.queued.push_front(leftovers);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3038816 and 2e9d60c.

📒 Files selected for processing (3)
  • crates/katana/core/src/service/block_producer.rs (11 hunks)
  • crates/katana/core/src/service/block_producer_tests.rs (1 hunks)
  • crates/katana/executor/src/implementation/noop.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: docs
  • GitHub Check: ensure-wasm
🔇 Additional comments (8)
crates/katana/executor/src/implementation/noop.rs (2)

16-16: Ohayo sensei! LGTM on the error type import.

The addition of ExecutorError alongside ExecutionError aligns well with the PR's objective of handling resource limits.


101-106: Ohayo sensei! The updated return type looks good.

The change to return (usize, Option<ExecutorError>) provides the necessary information for tracking transaction counts and potential resource limit errors, which is essential for the block auto-closing feature.

The NoopExecutor's implementation correctly maintains its "do-nothing" behavior while conforming to the new interface.

crates/katana/core/src/service/block_producer_tests.rs (2)

49-49: Ohayo sensei! Clear and accurate comment.

The comment effectively describes the expected timer behavior when no block is opened.


57-69: Ohayo sensei! Robust polling implementation.

The new implementation using poll_next with conditional checks effectively tests both scenarios:

  1. When the block is still being produced (pending)
  2. When the block has been mined (completed)

This aligns well with the PR's objective of handling block closure conditions.

crates/katana/core/src/service/block_producer.rs (4)

60-68: LGTM! Clean error handling implementation.

The new is_block_limit_exhausted method provides a clear way to check if a block's resource limit has been reached.


89-90: LGTM! Type signature enhancement.

The updated TxExecutionResult type now properly handles leftover transactions when a block is full.


335-364: Ohayo sensei! The transaction execution logic looks solid.

The function now properly handles block resource limits by:

  1. Tracking the total number of executed transactions
  2. Identifying when a block is full
  3. Returning non-executed transactions for the next block

421-457: LGTM! Robust block mining logic.

The block mining logic has been enhanced to:

  1. Check if block is full before mining
  2. Reset timer appropriately
  3. Handle leftover transactions for the next block

@codecov
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 76.72956% with 37 lines in your changes missing coverage. Please review.

Project coverage is 56.99%. Comparing base (6ee7082) to head (ba30be7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/core/src/service/block_producer.rs 40.47% 25 Missing ⚠️
...na/executor/src/implementation/blockifier/error.rs 0.00% 6 Missing ⚠️
...tana/executor/src/implementation/blockifier/mod.rs 88.23% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3003      +/-   ##
==========================================
+ Coverage   56.98%   56.99%   +0.01%     
==========================================
  Files         430      431       +1     
  Lines       57046    57151     +105     
==========================================
+ Hits        32509    32575      +66     
- Misses      24537    24576      +39     

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

@kariy kariy force-pushed the katana/block-limit branch from 2e9d60c to ba30be7 Compare February 10, 2025 18:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/katana/executor/src/implementation/blockifier/mod.rs (1)

205-211: Consider adding error handling for bouncer initialization.

While the implementation is correct, it would be good to handle potential errors during bouncer initialization.

-            let result = utils::transact(
-                &mut state.inner,
-                block_context,
-                flags,
-                exec_tx,
-                Some(&mut self.bouncer),
-            );
+            let result = match utils::transact(
+                &mut state.inner,
+                block_context,
+                flags,
+                exec_tx,
+                Some(&mut self.bouncer),
+            ) {
+                Ok(result) => Ok(result),
+                Err(e) => {
+                    info!(target: LOG_TARGET, "Transaction failed due to bouncer: {}", e);
+                    Err(e)
+                }
+            };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e9d60c and ba30be7.

📒 Files selected for processing (26)
  • crates/dojo/test-utils/src/sequencer.rs (1 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (2 hunks)
  • crates/katana/cli/src/args.rs (3 hunks)
  • crates/katana/core/src/service/block_producer.rs (11 hunks)
  • crates/katana/core/src/service/block_producer_tests.rs (1 hunks)
  • crates/katana/core/tests/backend.rs (2 hunks)
  • crates/katana/executor/benches/concurrent.rs (2 hunks)
  • crates/katana/executor/benches/execution.rs (1 hunks)
  • crates/katana/executor/src/abstraction/error.rs (1 hunks)
  • crates/katana/executor/src/abstraction/executor.rs (2 hunks)
  • crates/katana/executor/src/abstraction/mod.rs (1 hunks)
  • crates/katana/executor/src/implementation/blockifier/error.rs (3 hunks)
  • crates/katana/executor/src/implementation/blockifier/mod.rs (9 hunks)
  • crates/katana/executor/src/implementation/blockifier/utils.rs (4 hunks)
  • crates/katana/executor/src/implementation/noop.rs (2 hunks)
  • crates/katana/executor/tests/fixtures/mod.rs (1 hunks)
  • crates/katana/node/src/config/mod.rs (2 hunks)
  • crates/katana/node/src/config/sequencing.rs (1 hunks)
  • crates/katana/node/src/lib.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/dev.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/forking.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/proofs.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/saya.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/torii.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (22)
  • crates/katana/executor/benches/concurrent.rs
  • crates/katana/executor/benches/execution.rs
  • crates/katana/rpc/rpc/tests/dev.rs
  • crates/katana/executor/src/implementation/blockifier/error.rs
  • crates/katana/rpc/rpc/tests/saya.rs
  • crates/katana/rpc/rpc/tests/messaging.rs
  • crates/katana/rpc/rpc/tests/forking.rs
  • crates/katana/executor/src/abstraction/error.rs
  • crates/katana/executor/src/abstraction/mod.rs
  • crates/katana/rpc/rpc/tests/proofs.rs
  • crates/katana/rpc/rpc/tests/torii.rs
  • crates/katana/node/src/lib.rs
  • crates/katana/executor/src/abstraction/executor.rs
  • crates/katana/executor/tests/fixtures/mod.rs
  • crates/katana/core/tests/backend.rs
  • crates/dojo/test-utils/src/sequencer.rs
  • crates/katana/core/src/service/block_producer_tests.rs
  • crates/katana/node/src/config/mod.rs
  • crates/katana/node/src/config/sequencing.rs
  • crates/katana/chain-spec/src/rollup/utils.rs
  • crates/katana/cli/src/args.rs
  • crates/katana/rpc/rpc/tests/starknet.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: clippy
  • GitHub Check: ensure-wasm
  • GitHub Check: docs
🔇 Additional comments (11)
crates/katana/core/src/service/block_producer.rs (4)

239-239: Ohayo sensei! Clean state management implementation.

The is_block_full flag effectively tracks block capacity state, enabling automatic block closure when resource limits are reached.


335-364: Excellent transaction overflow handling, sensei!

The implementation elegantly handles transactions that exceed block capacity by:

  1. Tracking executed transaction count
  2. Preserving non-executed transactions for the next block
  3. Maintaining transaction order

427-433: Smart block closure implementation!

The dual-trigger approach ensures blocks are closed either:

  1. When the timer expires (normal case)
  2. Immediately when resource limits are reached
    This provides optimal balance between regular block production and resource management.

Also applies to: 444-457


491-500: Excellent queue management, sensei!

The implementation ensures transaction ordering and continuity by:

  1. Preserving leftover transactions at the front of the queue
  2. Triggering immediate processing in the next block
  3. Maintaining transaction sequence across blocks
crates/katana/executor/src/implementation/blockifier/utils.rs (1)

69-70: Clean bouncer integration, sensei!

The transaction execution logic properly integrates resource tracking by:

  1. Using transactional state for atomic updates
  2. Checking resource limits before committing changes
  3. Properly handling state rollback on limit exhaustion

Also applies to: 127-128, 132-142

crates/katana/executor/src/implementation/noop.rs (2)

16-16: LGTM!

The import of ExecutorError is necessary for the updated return type of execute_transactions.


104-105: LGTM!

The updated return type and implementation correctly handle the new requirements for tracking executed transactions and potential resource limit errors.

crates/katana/executor/src/implementation/blockifier/mod.rs (4)

3-3: LGTM!

Ohayo sensei! The import of Bouncer-related types is necessary for implementing resource limits.


37-37: LGTM!

The addition of BlockLimits to BlockifierFactory and its constructor provides a clean way to configure resource limits.

Also applies to: 42-43


86-86: LGTM!

The bouncer configuration correctly uses the Cairo steps limit from BlockLimits.

Also applies to: 101-103


241-242: LGTM!

The error handling correctly distinguishes between resource exhaustion and other errors, allowing the block producer to handle them appropriately.

@kariy kariy merged commit 9f744a0 into main Feb 10, 2025
15 checks passed
@kariy kariy deleted the katana/block-limit branch February 10, 2025 19:15
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