Skip to content

feat: update base fee via cli #1183

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

Merged
merged 3 commits into from
May 14, 2025
Merged

Conversation

Thegaram
Copy link

@Thegaram Thegaram commented May 9, 2025

1. Purpose or design rationale of this PR

Add two new flags --basefee.scalar and --basefee.overhead that allows us to update a node's basefee calculation without publishing a new release.

Example logs:

INFO [05-09|21:07:10.760] Starting l2geth on Scroll Sepolia testnet...
...
INFO [05-09|21:07:10.762] L2 base fee coefficients                 scalar=34,000,000,000,000 overhead=15,680,000
WARN [05-09|21:07:10.762] Updating txpool price limit to min L2 base fee provided=1 updated=15,680,000
...
INFO [05-09|21:10:34.829] Initialised chain configuration          config="{ChainID: 534351, ..., baseFeeScalar: 34000000000000, baseFeeOverhead: 15680000}}"

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • feat: A new feature

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced new command-line flags for configuring L2 base fee parameters, allowing customization of base fee calculation.
    • Added a new "ROLLUP" flag group to the CLI for improved organization of rollup-related options.
  • Improvements
    • Enhanced L2 base fee calculation with configurable scalar and overhead parameters.
    • Updated help output to display new configuration options.
  • Bug Fixes
    • Ensured minimum transaction pool price limit aligns with the configured minimum L2 base fee.
  • Tests
    • Added and extended tests to cover new base fee calculation logic and minimum base fee scenarios.
  • Other
    • Increased patch version to 0.45.

Copy link

coderabbitai bot commented May 9, 2025

"""

Walkthrough

This update introduces new configuration options for L2 base fee calculation, adds relevant CLI flags, and refactors the fee computation logic to use configurable parameters. It also updates documentation, versioning, and test coverage to reflect these changes, and organizes rollup-related CLI flags for better usability.

Changes

Files/Paths Change Summary
cmd/geth/main.go, cmd/utils/flags.go Added new CLI flags for L2 base fee scalar and overhead; integrated into node flag configuration and CLI parsing; implemented logic to set base fee parameters in config and enforce minimum transaction pool price limit.
cmd/geth/usage.go Introduced "ROLLUP" flag group with multiple rollup-related flags; added MaxBlockRangeFlag to "API AND CONSOLE".
eth/ethconfig/config.go, params/config.go Added BaseFeeScalar and BaseFeeOverhead fields to configuration structs; updated ScrollConfig.String() method to include new fields.
consensus/misc/eip1559.go Refactored L2 base fee calculation to use new configurable scalar and overhead parameters; added helper function calcBaseFee and MinBaseFee function; replaced hardcoded additive components with parameterized formula.
consensus/misc/eip1559_test.go Added tests for MinBaseFee; extended TestCalcBaseFee with sub-tests using custom base fee scalar and overhead values.
eth/backend.go Propagated new base fee parameters from ethconfig.Config to chainConfig.Scroll during Ethereum backend initialization.
params/version.go Bumped patch version from 44 to 45.

Sequence Diagram(s)

sequenceDiagram
    participant User as CLI User
    participant Geth as Geth Node (main.go)
    participant Utils as CLI Utils (flags.go)
    participant Config as ethconfig.Config
    participant Params as params.ScrollConfig
    participant Consensus as consensus/misc/eip1559.go

    User->>Geth: Start node with L2 base fee flags
    Geth->>Utils: Parse CLI flags (basefee.scalar, basefee.overhead)
    Utils->>Config: Set BaseFeeScalar, BaseFeeOverhead in config
    Geth->>Params: Pass config parameters to ScrollConfig
    Consensus->>Params: Retrieve scalar, overhead for base fee calculation
    Consensus->>Consensus: Calculate L2 base fee using parameters
Loading

Possibly related PRs

  • feat: update L2 base fee formula #1169: Updates numeric parameters inside the fixed L2 base fee formula without adding configurability or new flags; related in purpose but distinct in implementation.

Suggested labels

bump-version

Suggested reviewers

  • roylou
  • omerfirmak

Poem

A hop and a skip, new flags in the breeze,
L2 base fees now set with such ease!
Scalars and overheads, all neat in a row,
Rollup flags gathered for a CLI show.
With tests and a version bump, we’re ready to go—
The blockchain hops forward, as only rabbits know!
🐇✨
"""

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e181146 and 5f8b65f.

📒 Files selected for processing (2)
  • cmd/utils/flags.go (4 hunks)
  • consensus/misc/eip1559.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/utils/flags.go
  • consensus/misc/eip1559.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 1

🧹 Nitpick comments (1)
eth/ethconfig/config.go (1)

234-237: Configuration fields added for L2 base fee calculation

These new fields appropriately add support for configurable base fee parameters. The accompanying comment clearly explains the formula in which these parameters will be used.

Could you add information about what the default values are for these parameters, or add a reference to where they're defined?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3edb331 and 223bf0c.

📒 Files selected for processing (9)
  • cmd/geth/main.go (1 hunks)
  • cmd/geth/usage.go (2 hunks)
  • cmd/utils/flags.go (4 hunks)
  • consensus/misc/eip1559.go (2 hunks)
  • consensus/misc/eip1559_test.go (2 hunks)
  • eth/backend.go (1 hunks)
  • eth/ethconfig/config.go (1 hunks)
  • params/config.go (2 hunks)
  • params/version.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
cmd/geth/main.go (1)
cmd/utils/flags.go (2)
  • L2BaseFeeScalarFlag (940-944)
  • L2BaseFeeOverheadFlag (945-949)
cmd/geth/usage.go (1)
cmd/utils/flags.go (20)
  • MaxBlockRangeFlag (886-889)
  • L1EndpointFlag (850-853)
  • L1ConfirmationsFlag (854-857)
  • L1DeploymentBlockFlag (858-861)
  • L1DisableMessageQueueV2Flag (862-865)
  • RollupVerifyEnabledFlag (880-883)
  • L2BaseFeeScalarFlag (940-944)
  • L2BaseFeeOverheadFlag (945-949)
  • DASyncEnabledFlag (898-901)
  • DABlobScanAPIEndpointFlag (902-905)
  • DABlockNativeAPIEndpointFlag (906-909)
  • DABeaconNodeAPIEndpointFlag (910-913)
  • DARecoveryModeFlag (914-917)
  • DARecoveryInitialL1BlockFlag (918-921)
  • DARecoveryInitialBatchFlag (922-925)
  • DARecoverySignBlocksFlag (926-929)
  • DARecoveryL2EndBlockFlag (930-933)
  • DARecoveryProduceBlocksFlag (934-937)
  • CircuitCapacityCheckEnabledFlag (868-871)
  • CircuitCapacityCheckWorkersFlag (873-877)
consensus/misc/eip1559_test.go (1)
consensus/misc/eip1559.go (2)
  • CalcBaseFee (59-65)
  • MinBaseFee (91-93)
consensus/misc/eip1559.go (1)
params/config.go (1)
  • ChainConfig (632-675)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: check
  • GitHub Check: Analyze (go)
🔇 Additional comments (18)
params/version.go (1)

27-27: Version increment is appropriate for the new feature

The patch version has been incremented from 44 to 45, which aligns with semantic versioning practices for adding a non-breaking feature.

cmd/geth/main.go (1)

188-189: New CLI flags for base fee parameters

The addition of these flags aligns well with the PR objective to make base fee parameters configurable via CLI, improving operational flexibility.

Based on the snippet from flags.go, these flags are properly defined with descriptive usage messages that explain their purpose in L2 base fee calculation.

eth/backend.go (1)

153-158:

✅ Verification successful

Workaround to propagate base fee parameters to chain configuration

While the comment describes this as a "hacky workaround," it's a reasonable approach to make these parameters accessible to fee calculation logic that uses the chain configuration.

Consider creating a more structured approach in a future refactoring to pass these configuration parameters without relying on this workaround.


🏁 Script executed:

#!/bin/bash
# Check where and how these parameters are used in fee calculation
rg -A 5 "CalcBaseFee" --type go

Length of output: 7106


Approve: Temporary propagation of base-fee parameters is acceptable

I’ve confirmed that BaseFeeScalar and BaseFeeOverhead are defined in params/config.go and consumed by misc.CalcBaseFee across the codebase (e.g., in scroll_worker.go, ethapi/api.go, core/chain_makers.go, etc.). Injecting them via chainConfig.Scroll in eth/backend.go (lines 153–158) is a reasonable short-term solution.

• File to review: eth/backend.go (lines 153–158)
• Context:

// Hacky workaround:
// It's hard to pass these fields to `CalcBaseFee`, etc.
// So pass them as part of the genesis config instead.
chainConfig.Scroll.BaseFeeScalar    = config.BaseFeeScalar
chainConfig.Scroll.BaseFeeOverhead  = config.BaseFeeOverhead

Consider a future refactoring to pass these parameters more explicitly—e.g., by extending the CalcBaseFee API or introducing a dedicated base-fee config struct.

consensus/misc/eip1559_test.go (3)

114-130: Well-structured test suite with custom configuration.

The test code effectively validates the base fee calculation with a custom configuration (scalar = 10,000,000, overhead = 1), demonstrating how the parameterized formula behaves with different coefficients. This tests the core functionality of the new configurable base fee mechanism.


132-148: Good test organization.

Renaming the original test cases to testsWithDefaults improves clarity by separating tests for default configuration from tests with custom configuration. The original test cases are preserved, maintaining backward compatibility testing.


151-163: Complete test coverage for new functionality.

The TestMinBaseFee function correctly verifies the MinBaseFee function with both default and custom configurations. This ensures that the minimum base fee calculation works properly in all scenarios.

params/config.go (3)

708-712: Good documentation of the new configuration fields.

The added fields are clearly documented with a description of their purpose and how they're used in the base fee formula. Marking them with json:"-" correctly indicates these are runtime configuration parameters that shouldn't be serialized.


761-769: Proper string representation for new fields.

The string representation logic correctly handles nil values by displaying "" for unset parameters, maintaining consistency with the existing pattern in the codebase.


771-772: Updated string format to include new parameters.

The string format is updated to include the new base fee parameters, ensuring they're visible in logs and debug output. This is essential for operational monitoring and troubleshooting.

cmd/geth/usage.go (2)

164-164: Added MaxBlockRangeFlag to the API group.

The MaxBlockRangeFlag is appropriately added to the "API AND CONSOLE" flag group, as it relates to API functionality.


231-254: Well-organized ROLLUP flag group.

Creating a dedicated "ROLLUP" flag group improves CLI organization by grouping related rollup parameters together, including the new base fee configuration flags. This makes the CLI more intuitive for users configuring L2 nodes.

consensus/misc/eip1559.go (3)

31-35: Constants and defaults are well-defined.

The introduction of BaseFeePrecision, DefaultBaseFeeScalar, and DefaultBaseFeeOverhead as package variables provides clear defaults and ensures consistency across the codebase.


64-65: Good refactoring to use helper function.

The refactoring to use a helper function calcBaseFee improves code organization and reuse, allowing both CalcBaseFee and MinBaseFee to share the same core logic.


90-93: Clean implementation of MinBaseFee.

The MinBaseFee function is a simple and effective way to calculate the minimum base fee by reusing the calcBaseFee function with a zero L1 base fee. This ensures consistency in the calculation method.

cmd/utils/flags.go (4)

50-50: New import for base fee calculation.

The addition of the misc package import is necessary to access the default L2 base fee parameters and minimum fee calculation functionality.


939-949: Well-structured CLI flags for configurable base fee parameters.

These new global CLI flags allow runtime configuration of L2 base fee calculation parameters without requiring a software release. The flags follow the established pattern in the codebase and are properly documented with clear usage descriptions.


1725-1746: Well-implemented base fee configuration logic.

The new setBaseFee function correctly:

  1. Initializes base fee parameters from flags or falls back to defaults
  2. Logs the configured values for observability
  3. Enforces a minimum transaction pool price limit based on the minimum base fee

This implementation ensures transactions with fees below the calculated minimum base fee will be rejected by the transaction pool, which is important for proper network operation.


1824-1824: Proper integration with existing configuration flow.

The setBaseFee function is correctly integrated into the SetEthConfig function, ensuring the base fee parameters are initialized during Ethereum client configuration.

colinlyguo
colinlyguo previously approved these changes May 12, 2025
@Thegaram Thegaram merged commit 0b6f8f1 into develop May 14, 2025
14 checks passed
@Thegaram Thegaram deleted the feat-update-base-fee-via-cli branch May 14, 2025 10:41
Thegaram added a commit that referenced this pull request May 23, 2025
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.

2 participants