feat(l2): configure block max gas limit#4211
Conversation
Lines of code reportTotal lines added: Detailed view |
6e19c69 to
a804002
Compare
58ca44a to
a804002
Compare
…lass#4224) **Motivation** Noticed a weird behavior while testing lambdaclass#4211. Once the configured `max_gas_limit` was reached, no further deposits were included in subsequent blocks until a new batch is started. This happens because we first update the `privileged_range`, and if the transaction is later rejected (for example, due to the gas limit), we don’t remove the nonce from the range. As a result, when the next block starts, we try to add the tx again, but since the nonce was already included to the range, the transaction is marked as out-of-order. #### Why haven’t we seen the error before? There is an `if` check that prevents the error from appearing in our daily usage: ```Rust // Check if we have enough space for the StateDiff to run more transactions if acc_size_without_accounts + size_accounts_diffs + SIMPLE_TX_STATE_DIFF_SIZE > safe_bytes_per_blob { warn!("No more StateDiff space to run transactions"); break; }; ``` This is an early return that checks if we have enough space for a simple transfer in our `stateDiff`, and stops adding transactions to the block if we don’t. But, it can happen that we have enough space for a simple transfer, but the transaction we are trying to add occupies more space than that, making us restore the previous state in another check a[ few lines later](https://github.com/lambdaclass/ethrex/blob/0cae720162fd889eb18417010e5f091c6d097d35/crates/l2/sequencer/block_producer/payload_builder.rs#L215). <!-- #### How to trigger the error The easiest way to trigger the error is to comment out the early return, allowing the `payload_builder` to attempt restoring the previous state. Then start the `L2` and `prover` with: ``` make init make init-prover ``` and run a load test with: ``` cargo run --release --manifest-path ./tooling/load_test/Cargo.toml -- -k ./fixtures/keys/private_keys_l1.txt -t eth-transfers -n "http://localhost:1729" ``` Observe the following behavior in the monitor: After a block reaches its max `stateDiff` size allowed, the subsequent blocks contain 0 transactions until a new batch is started. --> **Description** Moves the update of `privileged_range` after all other checks have passed. Issues lambdaclass#4248 and lambdaclass#4243 were created. Closes None
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a configurable maximum gas limit for L2 blocks to prevent overloading the prover by limiting the gas consumption per block.
- Adds a new CLI parameter
max_gas_limitto configure the maximum gas allowed per block - Updates the payload builder to enforce this gas limit during transaction selection
- Fixes a minor bug in privileged transaction counting logic
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/l2/sequencer/configs.rs | Adds max_gas_limit field to BlockProducerConfig |
| crates/l2/sequencer/block_producer/payload_builder.rs | Updates payload building to respect the max gas limit and fixes privileged tx counting |
| crates/l2/sequencer/block_producer.rs | Threads the max gas limit parameter through the block producer |
| cmd/ethrex/l2/options.rs | Adds CLI option for configuring the maximum gas limit |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| help = "Maximum gas limit for the L2 blocks.", | ||
| help_heading = "Block producer options" | ||
| )] | ||
| pub max_gas_limit: Option<u64>, |
There was a problem hiding this comment.
Why not block_gas_limit?
MegaRedHand
left a comment
There was a problem hiding this comment.
Changes LGTM. I think we should also signal the gas limit in the header of the block. I'm not sure if we have special-cased it in the L2, but on the L1 the client sets a "desired gas limit", to which it will converge with enough time, moving the gas limit (and target) a bit on each block.
|
The PR was changed to not only use a |
tomip01
left a comment
There was a problem hiding this comment.
One comment I just realized now
| rollup_store, | ||
| // FIXME: Initialize properly to the last privileged nonce in the chain | ||
| last_privileged_nonce: None, | ||
| block_gas_limit: block_gas_limit.unwrap_or(DEFAULT_BUILDER_GAS_CEIL), |
There was a problem hiding this comment.
Maybe I am wrong but we are always defaulting it to DEFAULT_BUILDER_GAS_CEIL if None.
We could change from Option<u64> to u64 in the BlockProducerOptions. And add default_value_t = DEFAULT_BUILDER_GAS_CEIL, in the clap options
Caution
Merge after #4224
Motivation
We need a way to limit the gas used per block to avoid overloading our prover.
Description
max_gas_limit.payload_builderto check this parameter as well.How to test
Set a low
max_gas_limit, start the L2, and watch in the monitor how the initial deposits are distributed across different blocks, ensuring that the gas used per block is lower than the configured amount.Closes #4207
Closes #2526