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: Completed implementation of customizable anvil hosts #264

Merged

Conversation

s29papi
Copy link
Contributor

@s29papi s29papi commented Nov 13, 2024

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:

  • Added L1Host and L2Host configuration flags
  • Implemented host configuration in chain and network configs
  • Added host validation and default fallbacks
  • Integrated with anvil startup and orchestrator

Tests verify:

  • Default host fallback (127.0.0.1)
  • Custom host configurations (0.0.0.0)
  • Mixed host scenarios
  • Host validation
  • Integration with anvil and orchestrator

Additional context

This implementation allows users to run anvil instances on different host addresses, enabling:

  • Custom network configurations
  • Flexible deployment scenarios
  • Better container support
  • Improved network isolation options

Metadata

Closes #262

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
@s29papi s29papi requested a review from a team as a code owner November 13, 2024 20:43
- Add Host field to ChainConfig struct
- Add L2Host field to NetworkConfig struct
- Enable custom host configuration for anvil instances

Part of ethereum-optimism#262
@s29papi s29papi changed the title feat: begin implementation of customizable anvil hosts feat: progress on implementation of customizable anvil hosts Nov 13, 2024
- 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
@s29papi s29papi changed the title feat: progress on implementation of customizable anvil hosts feat: Completed implementation of customizable anvil hosts Nov 14, 2024
@s29papi
Copy link
Contributor Author

s29papi commented Nov 14, 2024

@jakim929 The customizable host implementation is now complete!

You can now configure host addresses using the CLI flags

Copy link
Contributor

@jakim929 jakim929 left a 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

wantErr bool
}

func createTestSuite(t *testing.T, tc *TestCase) *TestSuite {
Copy link
Contributor

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 {

Comment on lines 31 to 43
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
}
Copy link
Contributor

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.

Comment on lines 45 to 113
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)
}
})
}
}
Copy link
Contributor

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

Comment on lines 20 to 26
type TestCase struct {
name string
l1Host string
l2Host string
wantErr bool
}

Copy link
Contributor

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

Comment on lines 54 to 56
if cfg.Host == "" {
cfg.Host = defaultHost
}
Copy link
Contributor

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"
Copy link
Contributor

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

Comment on lines 34 to 35
const defaultHost = "127.0.0.1"

Copy link
Contributor

Choose a reason for hiding this comment

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

to remove

Comment on lines 54 to 56
if cfg.Host == "" {
cfg.Host = defaultHost
}
Copy link
Contributor

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

@@ -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 == "" {
Copy link
Contributor

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

Copy link
Contributor Author

@s29papi s29papi Nov 16, 2024

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)
	

@@ -33,7 +33,7 @@ import (
)

const (
host = "127.0.0.1"
defaultHost = "127.0.0.1"
Copy link
Contributor

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

@s29papi
Copy link
Contributor Author

s29papi commented Nov 16, 2024

@jakim929

Changes:

  1. Removed default hosts
  2. Removed checks in createsuite
  3. Seperates host tests on orchestrator

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.

Copy link
Contributor

@jakim929 jakim929 left a 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

anvil/anvil_test.go Outdated Show resolved Hide resolved
@jakim929 jakim929 merged commit 31bf6be into ethereum-optimism:main Nov 19, 2024
3 of 4 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.

Allow customizing anvil hosts
2 participants