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

Feat: pass coinbase from consensus node #179

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

FletcherMan
Copy link
Collaborator

@FletcherMan FletcherMan commented Mar 7, 2025

1. Purpose or design rationale of this PR

...

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:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

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

  • New Features
    • Integrated the coinbase address in block creation, enabling users to specify the reward recipient during assembly.
    • Added configurable support for the Morph204 upgrade, allowing activation via a new time-based parameter.
  • Refactor
    • Enhanced logging to include coinbase details during block assembly for improved transparency.
    • Streamlined processing and parameter handling across block creation workflows.
  • Tests
    • Updated test cases to use default address values, ensuring consistency with the new approach to block assembly.

@FletcherMan FletcherMan requested a review from a team as a code owner March 7, 2025 11:36
@FletcherMan FletcherMan requested a review from SecurityLife March 7, 2025 11:36
Copy link

coderabbitai bot commented Mar 7, 2025

Walkthrough

This pull request removes the coinbase error checks from consensus validation and introduces a new coinbase field for L2 block assembly. The changes update JSON serialization, logging, method signatures, and test invocations across multiple packages. In addition, miner work preparation now conditionally assigns the coinbase based on the Morph204 upgrade state, with a corresponding configuration enhancement in ChainConfig.

Changes

File(s) Change Summary
consensus/l2/consensus.go Removed errInvalidCoinbase and associated coinbase validation checks in verifyHeader and Prepare methods.
eth/catalyst/api_types.go, eth/catalyst/gen_l2blockparams.go Added Coinbase field to AssembleL2BlockParams; updated JSON marshal/unmarshal methods to include the new field.
eth/catalyst/l2_api.go, ethclient/authclient/engine.go, miner/miner.go Updated block assembly methods to include the Coinbase parameter in logging, API calls, and the BuildBlock function.
eth/catalyst/l2_api_test.go Replaced nil with common.Address{} in BuildBlock invocation tests for parameter consistency.
miner/worker.go Introduced a conditional check using IsMorph204 so that coinbase assignment occurs only when the Morph204 feature is active.
params/config.go Added a new Morph204Time field and an IsMorph204 method to ChainConfig to support activation timing for the Morph204 upgrade.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as L2ConsensusAPI
    participant Engine
    participant Miner
    participant Worker
    participant Config as ChainConfig

    Client->>API: AssembleL2Block(params with coinbase)
    API->>Engine: Forward request with coinbase, transactions
    Engine->>Miner: BuildBlock(parentHash, timestamp, coinbase, transactions)
    Miner->>Worker: prepareWork(genParams with coinbase)
    Worker->>Config: IsMorph204(timestamp)?
    Config-->>Worker: true/false
    Worker->>Miner: Update coinbase assignment based on Morph204 check
Loading
sequenceDiagram
    participant Worker
    participant ChainConfig

    Worker->>ChainConfig: IsMorph204(now)
    alt Morph204 active
        ChainConfig-->>Worker: true
        Worker->>Worker: Set coinbase from genParams
    else Morph204 inactive
        ChainConfig-->>Worker: false
        Worker->>Worker: Skip coinbase assignment
    end
Loading

Suggested Reviewers

  • SecurityLife
  • curryxbo

Poem

In the code meadow I cheerfully roam,
Hopping on changes that now feel like home.
Coinbase fields gleam in a blockchain delight,
While Morph204 makes my work shine bright.
With every commit, my heart skips a beat—
A rabbit's dance in code, ever so sweet! 🐰✨

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

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 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)
ethclient/authclient/engine.go (1)

15-15: Client API signature properly updated to include coinbase parameter.

The AssembleL2Block method has been correctly updated to accept the coinbase parameter and pass it to the engine API. This completes the chain of modifications needed to pass the coinbase from the consensus node through to the block creation process.

Consider adding documentation comments to explain the purpose and expected format of the coinbase parameter to help API users.

-// AssembleL2Block assembles L2 Block used for L2 sequencer to propose a block in L2 consensus progress
+// AssembleL2Block assembles L2 Block used for L2 sequencer to propose a block in L2 consensus progress
+// The coinbase parameter specifies the address that will receive the mining rewards for the block.

Also applies to: 27-28

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between de5160c and 6039a12.

📒 Files selected for processing (9)
  • consensus/l2/consensus.go (0 hunks)
  • eth/catalyst/api_types.go (1 hunks)
  • eth/catalyst/gen_l2blockparams.go (4 hunks)
  • eth/catalyst/l2_api.go (2 hunks)
  • eth/catalyst/l2_api_test.go (3 hunks)
  • ethclient/authclient/engine.go (2 hunks)
  • miner/miner.go (1 hunks)
  • miner/worker.go (1 hunks)
  • params/config.go (2 hunks)
💤 Files with no reviewable changes (1)
  • consensus/l2/consensus.go
🔇 Additional comments (10)
params/config.go (1)

541-541: Field addition for Morph204 upgrade checkpoint

The addition of Morph204Time field to the ChainConfig struct allows for a time-based activation of the coinbase passing feature.

eth/catalyst/api_types.go (1)

41-45:

✅ Verification successful

Added Coinbase field to AssembleL2BlockParams struct

The addition of the Coinbase field to the AssembleL2BlockParams struct allows passing the coinbase address from the consensus node, which aligns with the PR objective.

Make sure to update any JSON serialization/deserialization code for this struct if needed.


🏁 Script executed:

#!/bin/bash
# Check if the generated code for this struct has been updated
find . -name "gen_l2blockparams.go" -exec cat {} \; | grep -i "coinbase"

Length of output: 253


Coinbase Field Addition Verified

The addition of the Coinbase field to the AssembleL2BlockParams struct now correctly propagates into the generated JSON serialization/deserialization code. The verification script confirms that the Coinbase field is being encoded and decoded as expected, matching the json:"coinbase" tag.

  • File: eth/catalyst/api_types.go (Lines 41-45) – The struct now includes the Coinbase field.
  • Generated code: The output from gen_l2blockparams.go confirms proper handling of Coinbase in both encoding and decoding.

No further updates are required.

miner/worker.go (1)

171-172: Conditional coinbase setting based on Morph204 activation

This change adds a feature gate for setting the coinbase based on the Morph204 upgrade activation status. This ensures the coinbase can only be set from the consensus node when the Morph204 feature is active.

The condition properly checks both for the Morph204 activation time and that the coinbase address is not empty.

eth/catalyst/l2_api_test.go (3)

114-115: Updated BuildBlock call with empty coinbase parameter

Tests have been updated to pass an empty address instead of nil to match the updated method signature.


173-174: Updated BuildBlock call with empty coinbase parameter

Tests have been updated to pass an empty address instead of nil to match the updated method signature.


226-227: Updated BuildBlock call with empty coinbase parameter

Tests have been updated to pass an empty address instead of nil to match the updated method signature.

eth/catalyst/gen_l2blockparams.go (1)

9-9: Looks good: Coinbase field implementation is correctly handled.

The addition of the Coinbase field to the AssembleL2BlockParams struct is properly implemented for both JSON marshaling and unmarshaling. The implementation correctly handles both required fields and the new optional Coinbase field.

Also applies to: 19-19, 24-24, 38-38, 49-51

eth/catalyst/l2_api.go (2)

67-67: Good: Enhanced logging with coinbase information.

Adding the coinbase address to the log message provides better context for debugging and monitoring block assembly operations.


84-84: Properly integrated coinbase parameter in BuildBlock call.

The coinbase parameter is correctly passed to the BuildBlock method, ensuring the specified coinbase address is used in the block creation process.

miner/miner.go (1)

170-178:

✅ Verification successful

BuildBlock signature change is properly implemented.

The signature change to include the coinbase parameter is well implemented. This modification allows external callers to specify the coinbase address for block creation, which aligns with the PR objective of passing the coinbase from the consensus node.

You might want to verify that all existing call sites to this method have been updated to include the coinbase parameter to avoid breaking changes.


🏁 Script executed:

#!/bin/bash
# Find all calls to BuildBlock to ensure they're updated with the new signature
rg -A 2 "BuildBlock\(" --type go

Length of output: 1599


Approved: BuildBlock signature update correctly integrates the coinbase parameter

The coinbase parameter has been properly added to the Miner.BuildBlock method, and our verification confirms that all call sites (e.g., in eth/catalyst/l2_api.go and eth/catalyst/l2_api_test.go) now include the coinbase argument. Note that the BuildBlock function in cmd/evm/internal/t8ntool/block.go is unrelated and does not require this change.

Comment on lines +752 to +754
func (c *ChainConfig) IsMorph204(now uint64) bool {
return isForkedTime(now, c.Morph204Time)
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Consistent implementation for new fork activation check

The IsMorph204 method follows the established pattern for fork detection by leveraging the existing isForkedTime helper function, maintaining codebase consistency.

Note that you'll need to update the CheckConfigForkOrder method to include this new fork in the sequence to properly enforce fork ordering.


🏁 Script executed:

#!/bin/bash
# Check if Morph204Time has been added to the fork ordering check
grep -A 30 "CheckConfigForkOrder.*func" params/config.go | grep -B 5 -A 15 "for.*range.*fork" | grep "morph204Time"

Length of output: 115


Action Required: Update Fork Ordering in CheckConfigForkOrder

The new fork activation check in IsMorph204 is implemented consistently using the existing isForkedTime helper. However, our verification indicates that CheckConfigForkOrder has not yet been updated to include Morph204Time. Please update the fork ordering logic in CheckConfigForkOrder (located in params/config.go) to incorporate this new fork, ensuring that fork activation is enforced in the intended sequence.

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