-
Notifications
You must be signed in to change notification settings - Fork 70
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
supersim: config refactors #52
Conversation
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (3)
orchestrator/fork.go (1)
36-41
: Ensure consistency in struct initialization.When initializing
config.ChainConfig
, it's good practice to specify field names for all fields to avoid future errors if the struct definition changes.- chainConfigs = append(chainconfigs, config.ChainConfig{ + chainConfigs = append(chainConfigs, config.ChainConfig{ + Port: 0, + Name: cfg.Network, + ChainID: superchain.Config.L1.ChainID, + SecretsConfig: config.DefaultSecretsConfig, + ForkConfig: &config.ForkConfig{ + RPCUrl: superchain.Config.L1.PublicRPC, + BlockNumber: l1Header.Number.Uint64(), + }, + })orchestrator/orchestrator.go (1)
Update test file to match new function signature
The
orchestrator/orchestrator_test.go
file is still using the oldOrchestratorConfig
structure. This needs to be updated to pass a slice ofconfig.ChainConfig
directly to theNewOrchestrator
function.
- File:
orchestrator/orchestrator_test.go
- Lines to update:
- Replace
OrchestratorConfig
with a direct slice ofconfig.ChainConfig
increateTestSuite
andTestTooManyL1sError
.Please ensure these updates are made to match the new function signature and maintain consistency across the codebase.
Analysis chain
Line range hint
33-82
: RefactorNewOrchestrator
to handle multiple chain configurations.The refactoring of
NewOrchestrator
to accept a slice ofconfig.ChainConfig
instead of a singleOrchestratorConfig
is a significant change. This allows for more flexible configuration, especially in environments with multiple chains. The error handling when more than one L1 chain is configured is appropriate and prevents potential runtime issues.However, ensure that all calls to this function across the codebase have been updated to pass the correct parameters.
The search results indicate that the
NewOrchestrator
function is being called with the new signature insupersim.go
andorchestrator/orchestrator_test.go
. The next step is to verify that thechainConfigs
parameter is correctly passed as a slice ofconfig.ChainConfig
in these files.
The verification for
supersim.go
confirms thatchainConfigs
is correctly defined and passed. However, we need to verify the same fororchestrator/orchestrator_test.go
.
To ensure that the
chainConfigs
parameter is correctly defined and passed inorchestrator/orchestrator_test.go
, we need to search for theNewOrchestrator
function calls and inspect the surrounding lines for the definition ofchainConfigs
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `NewOrchestrator` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type go -A 5 $'NewOrchestrator'Length of output: 1260
Script:
#!/bin/bash # Verify that the `chainConfigs` parameter is correctly passed as a slice of `config.ChainConfig` in `supersim.go` and `orchestrator/orchestrator_test.go`. # Check `supersim.go` for the definition and passing of `chainConfigs`. rg --type go -A 10 'chainConfigs' supersim.go # Check `orchestrator/orchestrator_test.go` for the definition and passing of `chainConfigs`. rg --type go -A 10 'chainConfigs' orchestrator/orchestrator_test.goLength of output: 1162
Script:
#!/bin/bash # Verify that the `chainConfigs` parameter is correctly passed as a slice of `config.ChainConfig` in `orchestrator/orchestrator_test.go`. # Check `orchestrator/orchestrator_test.go` for the definition and passing of `chainConfigs`. rg --type go -A 10 'chainConfigs' orchestrator/orchestrator_test.goLength of output: 67
Script:
#!/bin/bash # Verify the definition and usage of `chainConfigs` in `orchestrator/orchestrator_test.go` by inspecting the lines around `NewOrchestrator` function calls. # Search for `NewOrchestrator` function calls in `orchestrator/orchestrator_test.go` and include surrounding lines for context. rg --type go -A 10 -B 10 'NewOrchestrator' orchestrator/orchestrator_test.goLength of output: 1007
anvil/anvil.go (1)
Line range hint
76-154
: RefactorStart
method to handle dynamic configurations.The
Start
method has been significantly refactored to handle dynamic configurations, especially related to genesis and forking. The method now properly handles temporary files and logs, which enhances both security and maintainability.However, the error handling could be improved by ensuring that temporary files are cleaned up in error scenarios to prevent potential resource leaks.
if _, err = tempFile.Write(a.cfg.Genesis); err != nil { + tempFile.Close() + os.Remove(tempFile.Name()) return fmt.Errorf("error writing to genesis file: %w", err) }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- anvil/anvil.go (10 hunks)
- config/chain.go (1 hunks)
- opsimulator/deposits.go (2 hunks)
- opsimulator/opsimulator.go (3 hunks)
- orchestrator/fork.go (3 hunks)
- orchestrator/orchestrator.go (7 hunks)
- supersim.go (3 hunks)
Additional comments not posted (10)
opsimulator/deposits.go (1)
9-9
: Verify compatibility ofconfig.Chain
withchainapi.Chain
.The import path and type of
l1Chain
have been changed fromchainapi.Chain
toconfig.Chain
. It's crucial to ensure that theconfig.Chain
type supports all functionalities of thechainapi.Chain
, especially theSubscribeFilterLogs
method used here.Also applies to: 36-36
Verification successful
Verified compatibility of
config.Chain
withchainapi.Chain
.The
config.Chain
type includes theSubscribeFilterLogs
method, ensuring compatibility with the existing usage in theSubscribeDepositTx
function indeposits.go
.
config/chain.go:76
:SubscribeFilterLogs
method inChain
interface.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Searching for the 'SubscribeFilterLogs' method implementation in the 'config.Chain' interface. ast-grep --lang go --pattern $'type Chain interface { $$$ SubscribeFilterLogs($_, $_, $_) $_ $$$ }' src/config/chain.goLength of output: 187
Script:
#!/bin/bash # Searching for the 'Chain' interface definition in the entire repository. ast-grep --lang go --pattern $'type Chain interface { $$$ }' # Searching for the 'SubscribeFilterLogs' method in the entire repository. rg 'SubscribeFilterLogs'Length of output: 1485
supersim.go (1)
9-9
: Review refactoring of configuration handling inNewSupersim
.The
NewSupersim
function has been refactored to usecliConfig
instead of a genericconfig
. Ensure that all properties accessed fromcliConfig
are correctly initialized and used within the function. Additionally, verify that the newchainConfigs
setup does not omit any necessary configuration details previously handled.Also applies to: 21-50
config/chain.go (1)
1-105
: Review the newconfig/chain.go
file for correctness and integration.This new file introduces several key configurations and interfaces related to chain management. Verify that all configurations are correctly defined and that the interfaces (
Chain
) are properly implemented in other parts of the system. Additionally, ensure that the default configurations do not expose sensitive information or lead to unintended behavior.opsimulator/opsimulator.go (1)
16-16
: Review structural changes inOpSimulator
.The
OpSimulator
struct has undergone significant changes, including the removal of theConfig
struct and the integration of its fields directly. Verify that all functionalities previously handled byConfig
are preserved and correctly implemented in the new structure. Additionally, ensure that the new methods and fields integrate seamlessly with the rest of the system.Also applies to: 36-119
Verification successful
Let's adjust the script to locate the correct directory structure and re-run the verification.
The import statement for
config
is necessary and correctly implemented.The
OpSimulator
struct relies on theconfig.Chain
type for itsl1Chain
andl2Chain
fields. The methods withinOpSimulator
utilize these fields, confirming the necessity of the import statement.
opsimulator/opsimulator.go
:
OpSimulator
struct definition- Methods utilizing
l1Chain
andl2Chain
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct implementation of new methods and fields in `OpSimulator`. # Test: Search for usage of new methods and fields in `OpSimulator`. rg --type go -A 5 $'OpSimulator' src/Length of output: 81
Script:
#!/bin/bash # Locate the directory containing `opsimulator.go` opsim_dir=$(fd opsimulator.go | xargs dirname) # Verify the correct implementation of new methods and fields in `OpSimulator`. if [ -n "$opsim_dir" ]; then rg --type go -A 5 $'OpSimulator' "$opsim_dir" else echo "opsimulator.go not found" fiLength of output: 3222
orchestrator/fork.go (2)
50-60
: Refactor error handling in loop for better clarity.The error handling inside the loop could be refactored to reduce nesting and improve readability.
- l2ForkHeight, err := latestL2HeightFromL1Header(chainCfg, l1Header) - if err != nil { - return nil, fmt.Errorf("failed to find right l2 height: %w", err) - } + l2ForkHeight, err := latestL2HeightFromL1Header(chainCfg, l1Header) + if err != nil { + return nil, fmt.Errorf("failed to find right l2 height for chain %s: %w", chainCfg.Chain, err) + }Likely invalid or redundant comment.
70-70
: Visibility change of function needs review.The function
latestL2HeightFromL1Header
was changed from public to private. Verify that this change does not affect other parts of the codebase where it might be used.Verification successful
Visibility change of function is safe.
The function
latestL2HeightFromL1Header
is not used outside thefork.go
file, so changing its visibility from public to private does not impact other parts of the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the function `latestL2HeightFromL1Header` is not used outside this file. # Test: Search for the function usage outside this file. Expect: No occurrences. rg --type python -g '!fork.go' 'latestL2HeightFromL1Header'Length of output: 90
Script:
#!/bin/bash # Description: Verify that the function `latestL2HeightFromL1Header` is not used outside this file. # Test: Search for the function usage outside this file. Expect: No occurrences. rg --type go -g '!fork.go' 'latestL2HeightFromL1Header'Length of output: 55
orchestrator/orchestrator.go (2)
92-99
: Enhanced error handling inStart
method.The enhanced error handling and logging in the
Start
method improve the observability and robustness of the orchestrator. The use of formatted error messages with wrapped errors (%w
) is a best practice that aids in debugging.
Line range hint
107-127
: Refined logging inStop
method.The changes to the
Stop
method, including the addition of debug-level logging, align with the PR's objective to reduce verbosity at higher log levels. This is a good practice as it helps in reducing log clutter in production environments while still providing necessary information when debugging.anvil/anvil.go (2)
Line range hint
215-262
: Addition ofName
andString
methods to improve usability.The addition of the
Name
method and the modification of theString
method to include more details about theAnvil
instance are useful for debugging and logging purposes. These changes enhance the usability of theAnvil
class by making it easier to identify instances in logs and debug outputs.
Line range hint
16-36
: Configuration management improvements inConfig
struct.The integration of
config.ChainConfig
directly into theConfig
struct simplifies the configuration management forAnvil
instances. This change, coupled with the removal ofForkConfig
, indicates a shift towards a more unified configuration approach.Ensure that all dependent code has been updated to work with these changes.
WalkthroughWalkthroughThe update involves significant restructuring and refactoring across multiple files to streamline the configuration management of blockchain chains. The main changes include the consolidation of configuration structs, improved logging, and error handling, and the introduction of new methods and functions to better manage and interact with the blockchain chains. This refactor also replaces old import paths with a new Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
orchestrator/orchestrator_test.go (1)
22-25
: Inconsistency increateTestSuite
function usageThe
createTestSuite
function insupersim_test.go
does not use the newchainConfigs
initialization, while the one inorchestrator/orchestrator_test.go
does. Please update thecreateTestSuite
function insupersim_test.go
to match the newchainConfigs
initialization.
supersim_test.go
: Update thecreateTestSuite
function to use the newchainConfigs
initialization.Analysis chain
LGTM! But verify the function usage in the codebase.
The code changes are approved.
However, ensure that all function calls to
createTestSuite
match the newchainConfigs
initialization.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `createTestSuite` match the new `chainConfigs` initialization. # Test: Search for the function usage. Expect: Only occurances of the new `chainConfigs` initialization. rg --type go -A 5 $'createTestSuite'Length of output: 2452
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (11)
- anvil/anvil.go (9 hunks)
- anvil/anvil_test.go (1 hunks)
- config/chain.go (1 hunks)
- opsimulator/deposits.go (2 hunks)
- opsimulator/deposits_test.go (2 hunks)
- opsimulator/opsimulator.go (3 hunks)
- orchestrator/fork.go (2 hunks)
- orchestrator/orchestrator.go (7 hunks)
- orchestrator/orchestrator_test.go (3 hunks)
- supersim.go (3 hunks)
- testutils/mockchain.go (2 hunks)
Files skipped from review as they are similar to previous changes (7)
- anvil/anvil.go
- config/chain.go
- opsimulator/deposits.go
- opsimulator/opsimulator.go
- orchestrator/fork.go
- orchestrator/orchestrator.go
- supersim.go
Additional comments not posted (9)
anvil/anvil_test.go (2)
8-8
: Import change approved.The import change aligns with the refactoring goals mentioned in the PR summary.
18-18
: LGTM! But verify the function usage in the codebase.The code changes are approved.
However, ensure that all function calls to
TestAnvil
match the newcfg
initialization.Verification successful
Let's verify if there are any other references to
TestAnvil
in the entire codebase to ensure comprehensive verification.
Verified: The changes to the
cfg
initialization inTestAnvil
do not impact other parts of the codebase.
- The
TestAnvil
function is only defined and used withinanvil/anvil_test.go
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `TestAnvil` match the new `cfg` initialization. # Test: Search for the function usage. Expect: Only occurances of the new `cfg` initialization. rg --type go -A 5 $'TestAnvil'Length of output: 372
Script:
#!/bin/bash # Description: Verify if there are any other references to `TestAnvil` in the entire codebase. # Test: Search for any references to `TestAnvil` in the entire codebase. rg 'TestAnvil'Length of output: 65
testutils/mockchain.go (2)
6-6
: Import change approved.The import change aligns with the refactoring goals mentioned in the PR summary.
29-31
: Addition ofName
method approved.The addition of the
Name
method enhances theMockChain
struct by providing a way to retrieve the name of the chain.orchestrator/orchestrator_test.go (2)
7-7
: Import change approved.The import change aligns with the refactoring goals mentioned in the PR summary.
56-59
: LGTM! But verify the function usage in the codebase.The code changes are approved.
However, ensure that all function calls to
TestTooManyL1sError
match the newchainConfigs
initialization.Verification successful
Verification successful!
The function
TestTooManyL1sError
is not called elsewhere in the codebase, so there are no additional instances to verify for the newchainConfigs
initialization.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `TestTooManyL1sError` match the new `chainConfigs` initialization. # Test: Search for the function usage. Expect: Only occurances of the new `chainConfigs` initialization. rg --type go -A 5 $'TestTooManyL1sError'Length of output: 421
Script:
#!/bin/bash # Description: Verify all function calls to `TestTooManyL1sError` match the new `chainConfigs` initialization. # Test: Search for any occurrences of `TestTooManyL1sError` being called in the codebase. rg --type go 'TestTooManyL1sError'Length of output: 109
opsimulator/deposits_test.go (3)
12-12
: Import changes approved.The import changes align with the refactoring goals mentioned in the PR summary.
Also applies to: 19-19
22-22
: Declaration of_ config.Chain
approved.The declaration ensures that
MockChainWithSubscriptions
implements theconfig.Chain
interface.
Line range hint
70-70
:
Usage ofMockChainWithSubscriptions
approved.The
TestSubscribeDepositTx
function correctly utilizes the updatedMockChainWithSubscriptions
.
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.
lgtm!
I do think the chainApi stuff should live in a separate package - since it's not exactly "config". But it will prob get clearer where we want to keep it as add more method interfaces so we can just change it then.
okay sounds good! yeah i think it's useful for now to reduce the number of packages but we can rip it out again as more methods get added |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (11)
- anvil/anvil.go (9 hunks)
- anvil/anvil_test.go (1 hunks)
- config/chain.go (1 hunks)
- opsimulator/deposits.go (2 hunks)
- opsimulator/deposits_test.go (2 hunks)
- opsimulator/opsimulator.go (4 hunks)
- orchestrator/fork.go (2 hunks)
- orchestrator/orchestrator.go (7 hunks)
- orchestrator/orchestrator_test.go (3 hunks)
- supersim.go (3 hunks)
- testutils/mockchain.go (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- anvil/anvil.go
- anvil/anvil_test.go
- config/chain.go
- opsimulator/deposits.go
- opsimulator/deposits_test.go
- opsimulator/opsimulator.go
- orchestrator/fork.go
- orchestrator/orchestrator.go
- orchestrator/orchestrator_test.go
- supersim.go
- testutils/mockchain.go
Not every package needs to define it's external configuration and can instead be shared.
config
package and foldchainapi
into configdebug
so that they are available if neededSummary by CodeRabbit
New Features
Bug Fixes
Refactor
ChainConfig
structure.ChainConfig
instead of individual parameters.Tests
ChainConfig
structure.Chores