-
Notifications
You must be signed in to change notification settings - Fork 153
feat(l2): implement l1 fee #4781
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
Conversation
This reverts commit 40948ec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements L1 fee charging for L2 transactions to account for the cost of posting state diffs to L1. The L1 fee is calculated based on the transaction's state diff size and the L1 blob base fee, then charged as additional gas to the transaction sender.
Key changes:
- Added
L1FeeConfigto track L1 fee vault address and blob base fee per gas - Modified
L2Hookto calculate and charge L1 fees after transaction execution - Integrated L1 blob base fee fetching from L1 at configurable intervals
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/common/types/l2/fee_config.rs | Added L1FeeConfig struct to fee configuration |
| crates/common/types/l2/account_diff.rs | New file with account diff encoding/decoding logic moved from state_diff.rs |
| crates/vm/levm/src/hooks/l2_hook.rs | Implemented L1 fee calculation and charging logic in transaction finalization |
| crates/vm/levm/src/utils.rs | Added get_account_diffs_in_tx utility function |
| crates/l2/sequencer/block_producer.rs | Added periodic L1 blob base fee updates from L1 |
| crates/l2/tests/tests.rs | Updated integration tests to verify L1 fee vault balances |
| crates/blockchain/blockchain.rs | Added L2Config with RwLock-wrapped FeeConfig for runtime updates |
| docs/l2/fundamentals/transaction_fees.md | Documented L1 fee mechanism and configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| ))?; | ||
| if params.len() != 1 { | ||
| return Err(ethrex_rpc::RpcErr::BadParams( | ||
| "Expected 1 params".to_owned(), |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message says 'Expected 1 params' but should be 'Expected 1 param' (singular) for grammatical correctness.
| "Expected 1 params".to_owned(), | |
| "Expected 1 param".to_owned(), |
| ); | ||
| CastResponse::NoReply | ||
| } | ||
| InMessage::UpdateL1BlobBaseFee => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this task to a different L2 genserver (maybe watcher?), because the request to get the base fee could take a while (seconds) if network conditions are not ideal or something else happens, which would in the meantime prevent block production from continuing if the block production interval is low enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to watcher 6c34abb!
**Motivation** Implements the L1 fee. For more information about the L1 fee, see `transaction_fees.md`. **Description** - Adds `L1FeeConfig` to `FeeConfig`. - Modifies `L2Hook` to charge the L1 fee to transaction senders. - Updates integration tests to include the new fee type. Closes #4696 --------- Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Motivation
Implements the L1 fee. For more information about the L1 fee, see
transaction_fees.md.Description
L1FeeConfigtoFeeConfig.L2Hookto charge the L1 fee to transaction senders.Closes #4696