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(genesis): use embedded genesis config for default chains #56

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

jakim929
Copy link
Contributor

@jakim929 jakim929 commented Jul 19, 2024

  • delete original genesis files
  • default orchestrator config now brings in the embedded pre-generated genesis states
  • instead of SourceChainID, ChainConfig now has a L2Config to signify if it is an L2 or not

Summary by CodeRabbit

  • New Features

    • Introduced a streamlined configuration structure for Anvil, removing the intermediate Config type.
    • Added functionality to directly retrieve the Ethereum code at a specified address with the new EthGetCode method.
    • Enhanced blockchain chain configuration by integrating dynamic values from the genesis deployment package.
  • Bug Fixes

    • Simplified logic for managing genesis states and chain configurations within the Orchestrator.
  • Tests

    • Added a new test to validate the deployment status of essential components in the Layer 1 environment.
  • Chores

    • Updated dependencies to include github.com/ethereum-optimism/go-ethereum-hdwallet.

Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent changes primarily streamline the configuration handling for the Anvil struct and introduce enhancements for managing Layer 1 and Layer 2 blockchain deployments. The removal of the intermediate Config type simplifies interactions, while new functionalities such as EthGetCode improve blockchain interaction capabilities. Additionally, the integration of dynamic values for chain configurations enhances accuracy and flexibility, reflecting a significant evolution in the architecture of the application.

Changes

Files Change Summary
anvil/anvil.go, anvil/anvil_test.go Removed the Config struct, simplifying configuration handling. Updated constructor to use *config.ChainConfig. Introduced EthGetCode method for Ethereum interaction, replacing genesis data handling with JSON representation.
config/chain.go Enhanced ChainConfig initialization with dynamic values from genesisdeployment. Added L2Config field for better Layer 2 management. Modified method signatures in the Chain interface to include new functionalities.
genesisdeployment/genesisdeployment.go Introduced a new file handling L1 and L2 genesis deployments with embedded JSON. Defined structures for genesis data and a global variable for GeneratedGenesisDeployment.
go.mod Added new dependency github.com/ethereum-optimism/go-ethereum-hdwallet for Ethereum HD wallet operations.
opsimulator/opsimulator.go Added L2Config field to OpSimulator, modifying how the source chain ID is determined.
orchestrator/fork.go, orchestrator/orchestrator.go, orchestrator/orchestrator_test.go Enhanced configuration management by introducing L2Config. Modified NewOrchestrator for streamlined genesis state application and updated tests to accommodate new configuration structures.
supersim_test.go Introduced TestL1GenesisState to validate essential component deployments in the L1 environment.
testutils/mockchain.go Added EthGetCode method to MockChain for testing Ethereum interactions, returning a placeholder response.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Orchestrator
    participant Anvil
    participant Config

    User->>Orchestrator: Request to deploy L1 & L2 chains
    Orchestrator->>Config: Fetch chain configurations
    Config-->>Orchestrator: Return L2Config with L1ChainID
    Orchestrator->>Anvil: Initialize with ChainConfig
    Anvil->>Anvil: Process genesis data as JSON
    Orchestrator->>User: Confirm deployment success
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@jakim929
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @jakim929 and the rest of your teammates on Graphite Graphite

@jakim929 jakim929 changed the title feat(genesis): embed and unmarshal genesis files feat(genesis): use embedded genesis config for chainConfig Jul 19, 2024
@jakim929 jakim929 force-pushed the 07-18-feat_genesis_embed_and_unmarshal_genesis_files branch 4 times, most recently from 49205cb to ef2689a Compare July 19, 2024 21:34
@jakim929 jakim929 force-pushed the 07-18-feat_genesis_embed_and_unmarshal_genesis_files branch from ef2689a to 1dcae6c Compare July 19, 2024 21:35
@jakim929 jakim929 marked this pull request as ready for review July 19, 2024 21:37
@jakim929 jakim929 requested a review from a team as a code owner July 19, 2024 21:37
@jakim929 jakim929 changed the title feat(genesis): use embedded genesis config for chainConfig feat(genesis): use embedded genesis config for default chains Jul 19, 2024
Copy link
Contributor

@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

Outside diff range, codebase verification and nitpick comments (2)
genesisdeployment/genesisdeployment.go (1)

64-74: Implement proper error handling in newL2GenesisDeployment usage

The newL2GenesisDeployment function is used within a struct initialization without any error handling. This means any error during JSON unmarshalling will cause a panic, which is not ideal for robust error handling.

  • Consider logging the error and handling it gracefully instead of using panic.
Analysis chain

Function implementation looks good. Verify error handling.

The newL2GenesisDeployment function correctly handles JSON unmarshalling and struct initialization.

However, consider logging the error instead of using panic for better error handling.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `newL2GenesisDeployment` function for error handling.

# Test: Search for the function usage. Expect: Proper error handling in calling code.
rg --type go 'newL2GenesisDeployment'

Length of output: 731


Script:

#!/bin/bash
# Description: Extract context around the usages of `newL2GenesisDeployment` in genesisdeployment/genesisdeployment.go.

# Extract 5 lines before and after each match to understand error handling.
rg --type go 'newL2GenesisDeployment' -A 5 -B 5 genesisdeployment/genesisdeployment.go

Length of output: 996

orchestrator/orchestrator.go (1)

Line range hint 33-71:
LGTM! Consider refactoring to reduce complexity.

The changes streamline the configuration process and ensure only one L1 chain is supported. However, the function is becoming complex and could benefit from refactoring to improve readability and maintainability.

func NewOrchestrator(log log.Logger, chainConfigs []config.ChainConfig) (*Orchestrator, error) {
	var opSimInstances []*opsimulator.OpSimulator
	var anvilInstances []*anvil.Anvil

	l1Count := 0
	for _, config := range chainConfigs {
		if config.L2Config == nil {
			l1Count++
		}
	}
	if l1Count > 1 {
		return nil, fmt.Errorf("supersim does not support more than one l1")
	}

	// Spin up anvil instances
	var l1Chain *anvil.Anvil
	anvilInstanceByChainID := make(map[uint64]*anvil.Anvil)
	for _, chainConfig := range chainConfigs {
		anvilConfig := chainConfig
		if chainConfig.L2Config != nil {
			anvilConfig.Port = 0 // internally allocate anvil port as op-simulator port is exposed externally
		}

		// Apply genesis if not forking from a live network
		if chainConfig.ForkConfig == nil {
			anvilConfig.GenesisJSON = chainConfig.GenesisJSON
		}

		anvil := anvil.New(log, &anvilConfig)
		anvilInstances = append(anvilInstances, anvil)
		anvilInstanceByChainID[chainConfig.ChainID] = anvil
		if chainConfig.L2Config == nil {
			l1Chain = anvil
		}
	}

	// Create Op Simulators to front L2 chains.
	for _, chainConfig := range chainConfigs {
		if chainConfig.L2Config != nil {
			opSim := opsimulator.New(log, chainConfig.Port, l1Chain, anvilInstanceByChainID[chainConfig.ChainID], chainConfig.L2Config)
			opSimInstances = append(opSimInstances, opSim)
		}
	}

	return &Orchestrator{log, l1Chain, opSimInstances, anvilInstances, anvilInstanceByChainID}, nil
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d84f3a8 and 1dcae6c.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (11)
  • anvil/anvil.go (7 hunks)
  • anvil/anvil_test.go (1 hunks)
  • config/chain.go (4 hunks)
  • genesisdeployment/genesisdeployment.go (1 hunks)
  • go.mod (1 hunks)
  • opsimulator/opsimulator.go (3 hunks)
  • orchestrator/fork.go (4 hunks)
  • orchestrator/orchestrator.go (4 hunks)
  • orchestrator/orchestrator_test.go (2 hunks)
  • supersim_test.go (1 hunks)
  • testutils/mockchain.go (3 hunks)
Additional comments not posted (28)
anvil/anvil_test.go (1)

18-18: Simplify initialization of cfg variable.

The change simplifies the initialization of the cfg variable by directly using config.ChainConfig instead of wrapping it in an outer Config type. This is a positive change that reduces unnecessary complexity.

testutils/mockchain.go (2)

9-9: New import statement for common package.

The import statement for github.com/ethereum/go-ethereum/common was added to accommodate the new method's parameter type.


46-48: Add EthGetCode method to MockChain.

The new method EthGetCode is a placeholder that returns an empty byte slice and a nil error. This method is likely added for future implementation or testing purposes.

orchestrator/orchestrator_test.go (2)

24-25: Update chain configuration structure in createTestSuite.

The SourceChainID field has been replaced with an L2Config field in the chainConfigs slice. This change aligns with the new logic or requirement related to Layer 2 configurations.


59-59: Update chain configuration structure in TestTooManyL1sError.

The SourceChainID field has been replaced with an L2Config field in the chainConfigs slice. This change aligns with the new logic or requirement related to Layer 2 configurations.

genesisdeployment/genesisdeployment.go (3)

14-15: Correct usage of go:embed directive.

The embedded genesis files and addresses are correctly referenced and organized.

Also applies to: 20-33, 38-51


53-62: Struct definitions look good.

The L1GenesisDeployment and L2GenesisDeployment structs correctly encapsulate the required data.


77-94: Struct and variable initialization look good.

The GenesisDeployment struct and GeneratedGenesisDeployment variable correctly encapsulate the genesis data.

config/chain.go (5)

8-14: Import statements look good.

The imported packages are necessary and correctly referenced.


66-69: Struct definition looks good.

The L2Config struct correctly encapsulates the required data.


75-86: Struct modifications look good.

The ChainConfig struct modifications correctly integrate the new L2Config field.


96-99: Interface modifications look good.

The Chain interface modifications correctly integrate the new method and reorder the existing method.


28-50: Initialization of DefaultChainConfigs looks good. Verify dynamic values.

The initialization correctly references the dynamic values from GeneratedGenesisDeployment.

However, consider verifying that the dynamic values are correctly set and used throughout the codebase.

Verification successful

Initialization of DefaultChainConfigs and dynamic values usage is verified.

The DefaultChainConfigs initialization and its usage in supersim.go are correct. The function ChainConfigsFromForkCLIConfig properly processes the forkConfig and initializes the chain configurations dynamically.

  • supersim.go: Properly uses DefaultChainConfigs and overrides it if cliConfig.ForkConfig is provided.
  • orchestrator/fork.go: Correctly processes forkConfig to initialize dynamic chain configurations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of dynamic values in `DefaultChainConfigs`.

# Test: Search for the usage of `DefaultChainConfigs`. Expect: Proper usage of dynamic values.
rg --type go 'DefaultChainConfigs'

Length of output: 144


Script:

#!/bin/bash
# Description: Extract the context around the usage of `DefaultChainConfigs` in `supersim.go`.

# Get the lines around the usage of `DefaultChainConfigs` in `supersim.go`.
rg --type go --context 10 'DefaultChainConfigs' supersim.go

Length of output: 707


Script:

#!/bin/bash
# Description: Extract the implementation of `orchestrator.ChainConfigsFromForkCLIConfig`.

# Search for the implementation of `ChainConfigsFromForkCLIConfig` in the orchestrator package.
rg --type go 'func ChainConfigsFromForkCLIConfig' --context 10

Length of output: 1167


Script:

#!/bin/bash
# Description: Extract the complete implementation of `ChainConfigsFromForkCLIConfig` from `orchestrator/fork.go`.

# Get the complete implementation of `ChainConfigsFromForkCLIConfig`.
rg --type go --context 50 'func ChainConfigsFromForkCLIConfig' orchestrator/fork.go

Length of output: 2188

opsimulator/opsimulator.go (4)

Line range hint 8-14:
Import statements look good.

The imported packages are necessary and correctly referenced.


33-34: Struct modifications look good.

The OpSimulator struct modifications correctly integrate the new L2Config field.


48-54: Constructor function modifications look good.

The New constructor function modifications correctly accept the new L2Config parameter and initialize the struct.


161-161: Method modifications look good.

The SourceChainID method modifications correctly return the L1ChainID from the L2Config.

orchestrator/orchestrator.go (2)

20-21: LGTM!

The addition of the l1Anvil field to the Orchestrator struct is clear and aligns with the intended functionality.


170-171: LGTM!

The simplification of the L1Anvil function improves performance and clarity.

go.mod (1)

39-39: LGTM!

The addition of the github.com/ethereum-optimism/go-ethereum-hdwallet dependency is clear and aligns with the intended functionality.

orchestrator/fork.go (3)

52-52: Ensure the addressList retrieval is correct.

The retrieval of addressList from the registry looks correct, but verify that config.OpChainToId[chain] always returns a valid key.


68-71: LGTM! The L2Config integration looks good.

The integration of L2Config with L1ChainID and L1DeploymentAddresses is correct and follows the intended design.


113-136: LGTM! The mapping in addressListToL1Deployments is correct.

The mapping from AddressList to L1Deployments is well-implemented and follows the intended design. The comments clearly indicate the temporary nature of the function.

anvil/anvil.go (5)

Line range hint 51-58:
LGTM! The changes in the New method are consistent.

The update to accept *config.ChainConfig instead of *Config is correct and consistent with the new design.


76-81: Ensure proper handling of the genesis file.

The logic for handling GenesisJSON and writing it to a temporary file is correct. Ensure that the temporary file is properly managed and deleted after use.


265-267: LGTM! The EthGetCode method is correctly implemented.

The method correctly retrieves the code at a specified Ethereum address using the ethClient.


268-270: LGTM! The EthGetLogs method is correctly implemented.

The method correctly retrieves logs using the ethClient.


Line range hint 272-274:
LGTM! The SubscribeFilterLogs method is correctly implemented.

The method correctly subscribes to logs using the ethClient.

supersim_test.go Show resolved Hide resolved
Copy link
Contributor

@hamdiallam hamdiallam left a comment

Choose a reason for hiding this comment

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

Looks good!

anvil/anvil.go Show resolved Hide resolved
@jakim929 jakim929 merged commit 2be154a into main Jul 25, 2024
3 checks passed
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