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

fix(rollup): sender use pending block base fee #1556

Merged
merged 6 commits into from
Oct 29, 2024

Conversation

yiweichi
Copy link
Member

@yiweichi yiweichi commented Oct 25, 2024

Purpose or design rationale of this PR

The baseFee sender get from latest block of L2 is not accurate, since the baseFee on L2 could spike, and sometime make it not high enough even we baseFee*2.
So we can use baseFee of pending block, it's more accurate. and will pervent issue: err: max fee per gas less than block base fee
Check more details here: https://www.notion.so/scrollzkp/l2geth-returns-wrong-gas-price-issue-1297792d22af8045bbb1e57ff974e6c7

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:

  • fix: A bug fix

Deployment tag versioning

Has tag in common/version.go been updated or have you added bump-version label to this PR?

  • No, this PR doesn't involve a new deployment, git tag, docker image tag
  • Yes

Breaking change label

Does this PR have the breaking-change label?

  • No, this PR is not a breaking change
  • Yes

Summary by CodeRabbit

  • New Features

    • Updated method for retrieving block headers to enhance base fee calculations by considering pending block states.
  • Bug Fixes

    • Improved accuracy of base fee and blob base fee calculations.
  • Version Update

    • Incremented version number from v4.4.70 to v4.4.71.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes involve a modification to the getBlockNumberAndBaseFeeAndBlobFee method in the Sender struct located in rollup/internal/controller/sender/sender.go. The method now retrieves the block header for the pending block number instead of the latest confirmed block. This alteration affects the calculation of base fees, as it takes into account the state of the pending block. Additionally, the version number in common/version/version.go has been incremented from "v4.4.70" to "v4.4.71".

Changes

File Path Change Summary
rollup/internal/controller/sender/sender.go Updated method getBlockNumberAndBaseFeeAndBlobFee to fetch block header for pending block number instead of the latest confirmed block.
common/version/version.go Updated version tag from "v4.4.70" to "v4.4.71" to reflect the new version.

Possibly related PRs

Suggested reviewers

  • georgehao
  • 0xmountaintop

Poem

In the burrow deep, where the code does creep,
A change was made, no need for sleep.
From latest to pending, the block we now seek,
To find the base fee, oh what a tweak!
Hopping along, with logic so neat,
Our sender's now swift, oh what a feat! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2405f4 and 6401710.

📒 Files selected for processing (1)
  • rollup/internal/controller/sender/sender.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rollup/internal/controller/sender/sender.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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

🧹 Outside diff range and nitpick comments (1)
rollup/internal/controller/sender/sender.go (1)

Line range hint 629-642: Consider enhancing error handling with specific error types.

The current error handling uses a generic error message. Consider creating specific error types for different failure scenarios (header retrieval, base fee calculation, blob fee calculation) to help with error handling in the caller functions.

Example implementation:

+type HeaderError struct {
+    Op  string
+    Err error
+}
+
+func (e *HeaderError) Error() string {
+    return fmt.Sprintf("header %s failed: %v", e.Op, e.Err)
+}

 func (s *Sender) getBlockNumberAndBaseFeeAndBlobFee(ctx context.Context) (uint64, uint64, uint64, error) {
     header, err := s.client.HeaderByNumber(ctx, big.NewInt(rpc.PendingBlockNumber.Int64()))
     if err != nil {
-        return 0, 0, 0, fmt.Errorf("failed to get header by number, err: %w", err)
+        return 0, 0, 0, &HeaderError{"retrieval", err}
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc8f9db and 21ecaa6.

📒 Files selected for processing (1)
  • rollup/internal/controller/sender/sender.go (1 hunks)
🔇 Additional comments (1)
rollup/internal/controller/sender/sender.go (1)

629-629: LGTM! Important fix for base fee estimation.

The change to use the pending block's base fee instead of the latest block's base fee is a crucial fix. This helps prevent "max fee per gas less than block base fee" errors by providing a more accurate and up-to-date base fee estimation, especially during periods of L2 gas price volatility.

Let's verify if there are any other places in the codebase that might need similar updates:

✅ Verification successful

LGTM! The change to use pending block's base fee is safe and isolated.

The modification to use rpc.PendingBlockNumber instead of the implicit latest block is a targeted fix that only affects the base fee estimation in the getBlockNumberAndBaseFeeAndBlobFee method. The search results confirm that:

  1. This is the only instance where HeaderByNumber is used for base fee estimation
  2. Other usages of HeaderByNumber in the codebase are for different purposes (block syncing, confirmation tracking, etc.)
  3. The change is contained within the transaction sending logic and doesn't affect other components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances where HeaderByNumber is called with nil
rg -A 2 'HeaderByNumber.*nil\)'

# Search for other base fee related functions
ast-grep --pattern 'func $$$BaseFee$$$'

Length of output: 75


Script:

#!/bin/bash
# Let's try a broader search for HeaderByNumber usage
rg -A 2 'HeaderByNumber'

# Also search for base fee related code
rg -A 2 'baseFee|BaseFee'

# And check for any other potential block number usage
rg -A 2 'BlockNumber|blockNumber'

Length of output: 96621

@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.84%. Comparing base (bc8f9db) to head (6401710).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1556      +/-   ##
===========================================
- Coverage    52.84%   52.84%   -0.01%     
===========================================
  Files          157      157              
  Lines        12641    12640       -1     
===========================================
- Hits          6680     6679       -1     
  Misses        5382     5382              
  Partials       579      579              
Flag Coverage Δ
rollup 59.10% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@yiweichi yiweichi added the bump-version Bump the version tag for deployment label Oct 25, 2024
@yiweichi yiweichi requested a review from colinlyguo October 29, 2024 06:37
@georgehao
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Oct 29, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@roylou roylou self-requested a review October 29, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump-version Bump the version tag for deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants