-
Notifications
You must be signed in to change notification settings - Fork 73
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: Completed implementation of customizable anvil hosts #264
feat: Completed implementation of customizable anvil hosts #264
Conversation
WIP: Adding host configuration options to CLI - Added L1Host and L2Host flags - Added initial config structure changes - TODO: Complete host validation - TODO: Integrate with anvil startup Refs ethereum-optimism#262
- Add Host field to ChainConfig struct - Add L2Host field to NetworkConfig struct - Enable custom host configuration for anvil instances Part of ethereum-optimism#262
- Add host configuration tests in anvil_test.go - Add host configuration tests in orchestrator_test.go - Implement default host (127.0.0.1) fallbacks in: - opsimulator.go - orchestrator.go - anvil.go Part of ethereum-optimism#262
- Add host configuration tests in anvil_test.go - Add host configuration tests in orchestrator_test.go - Implement default host (127.0.0.1) fallbacks in: - opsimulator.go - orchestrator.go - anvil.go Part of ethereum-optimism#262
@jakim929 The customizable host implementation is now complete! You can now configure host addresses using the CLI flags |
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.
Thank you for the contribution! This looks pretty close - just some changes requested to how the config is passed down from the CLI flags, and also some test changes
orchestrator/orchestrator_test.go
Outdated
wantErr bool | ||
} | ||
|
||
func createTestSuite(t *testing.T, tc *TestCase) *TestSuite { |
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.
think it will be more flexible to just pass it a networkConfig as a param
func createTestSuite(t *testing.T, networkConfig *NetworkConfig) *TestSuite {
orchestrator/orchestrator_test.go
Outdated
l1Host := defaultHost | ||
l2Host := defaultHost | ||
if tc != nil { | ||
l1Host = tc.l1Host | ||
l2Host = tc.l2Host | ||
} | ||
|
||
networkConfig.L1Config.Host = l1Host | ||
networkConfig.L1Config.Port = 9471 | ||
for i := range networkConfig.L2Configs { | ||
networkConfig.L2Configs[i].Host = l2Host | ||
networkConfig.L2StartingPort = 9473 | ||
} |
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.
can we leave the starting ports to remain default 0? The test run in parallel so it will clash on port usage.
orchestrator/orchestrator_test.go
Outdated
testSuite := createTestSuite(t) | ||
testSuite := createTestSuite(t, nil) | ||
verifyChainConfigs(t, testSuite) | ||
} | ||
|
||
func TestOrchestratorWithHosts(t *testing.T) { | ||
t.Run("default configuration", func(t *testing.T) { | ||
testSuite := createTestSuite(t, nil) | ||
verifyChainConfigs(t, testSuite) | ||
}) | ||
testCases := []TestCase{ | ||
{ | ||
name: "custom hosts", | ||
l1Host: "0.0.0.0", | ||
l2Host: "0.0.0.0", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "mixed custom hosts", | ||
l1Host: defaultHost, | ||
l2Host: "0.0.0.0", | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Logf("Testing with L1 Host: %s, L2 Host: %s", tc.l1Host, tc.l2Host) | ||
|
||
testSuite := createTestSuite(t, &tc) | ||
if !tc.wantErr { | ||
require.NotNil(t, testSuite) | ||
verifyChainConfigs(t, testSuite) | ||
} | ||
}) | ||
} | ||
} |
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.
the createTestSuite should ideally not have any tests in it.
If you want to test for the orchestrator failing to start I would add another test that runs
orchestrator, err := NewOrchestrator(testlog, closeApp, &networkConfig)
and checks for error with out using createTestSuite
orchestrator/orchestrator_test.go
Outdated
type TestCase struct { | ||
name string | ||
l1Host string | ||
l2Host string | ||
wantErr bool | ||
} | ||
|
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.
to remove - see comment below - these can just be individual tests that don't use createTestSuite
orchestrator/orchestrator.go
Outdated
if cfg.Host == "" { | ||
cfg.Host = defaultHost | ||
} |
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.
by default the cli flags will fall back to 127.0.0.1 so this can be removed, no need to have defaultHost
anvil/anvil.go
Outdated
@@ -36,7 +36,7 @@ var ( | |||
) | |||
|
|||
const ( | |||
host = "127.0.0.1" | |||
defaultHost = "127.0.0.1" |
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.
this can be removed, since host will default to "127.0.0.1" based on the default CLI flag value
orchestrator/orchestrator.go
Outdated
const defaultHost = "127.0.0.1" | ||
|
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.
to remove
orchestrator/orchestrator.go
Outdated
if cfg.Host == "" { | ||
cfg.Host = defaultHost | ||
} |
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.
right now the CLI flags are not passed to the L2 chains. I think you need to pass something like
cfg.Host = networkConfig.L2Host
orchestrator/orchestrator.go
Outdated
@@ -49,7 +51,10 @@ func NewOrchestrator(log log.Logger, closeApp context.CancelCauseFunc, networkCo | |||
// Sping up OpSim to fornt the L2 instances | |||
for i := range networkConfig.L2Configs { | |||
cfg := networkConfig.L2Configs[i] | |||
l2OpSims[cfg.ChainID] = opsimulator.New(log, closeApp, nextL2Port, l1Anvil, l2Anvils[cfg.ChainID], l2Anvils, networkConfig.InteropDelay) | |||
if cfg.Host == "" { |
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.
right now the CLI flags are not passed to the chains for the L1 chain as well. I think you need to pass something like
cfg.Host = networkConfig.L1Host
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.
Hey man thanks for the reviews.
Based on my understanding of this, I see the
// Forward set ports. Setting `0` will work to allocate a random port
networkConfig.L1Config.Port = cliConfig.L1Port
networkConfig.L2StartingPort = cliConfig.L2StartingPort
// Forward interop config
networkConfig.InteropAutoRelay = cliConfig.InteropAutoRelay
networkConfig.InteropDelay = cliConfig.InteropDelay
cliConfig params are forwaded to the network config from outside the orchestrator so i decided to follow same
// Forward host config
networkConfig.L1Config.Host = cliConfig.L1Host
for i := range networkConfig.L2Configs {
networkConfig.L2Configs[i].Host = cliConfig.L2Host
}
But I might be wrong, My thinking is that the l1Chain is handled by this
// Spin up L1 anvil instance
l1Anvil := anvil.New(log, closeApp, &networkConfig.L1Config)
opsimulator/opsimulator.go
Outdated
@@ -33,7 +33,7 @@ import ( | |||
) | |||
|
|||
const ( | |||
host = "127.0.0.1" | |||
defaultHost = "127.0.0.1" |
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.
remove default host, make it always passed down
…ts in orchestrator
Changes:
Would appreciate if you clarify the comment "cli flags are not passed down", they are currently being forwarded from supersim and also the test suite, and printing to the console within anvil, and opsim also suggests this. |
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.
This looks correct and apologize for the delay.
by cli flag not being passed down I just meant that we don't need a default value to be compared against at every level - the implementation looks correct now
Description
Adding customizable host configuration options for anvil nodes. This allows users to specify custom host addresses for L1 and L2 instances.
✅ Implementation Complete
Features:
Tests verify:
Additional context
This implementation allows users to run anvil instances on different host addresses, enabling:
Metadata
Closes #262