Skip to content

Commit 57e3a19

Browse files
committed
Support differing container names in profiles
1 parent 488254e commit 57e3a19

File tree

4 files changed

+887
-26
lines changed

4 files changed

+887
-26
lines changed

espresso/devnet-tests/batcher_restart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func testRestart(t *testing.T, tee bool) {
3535
require.NoError(t, d.RunSimpleL2Burn())
3636

3737
// Shut down the batcher and have another transaction submitted while it is down.
38-
require.NoError(t, d.ServiceDown("op-batcher"))
38+
require.NoError(t, d.ServiceDown(ServiceBatcher))
3939
d.SleepOutageDuration()
4040

4141
receipt, err := d.SubmitSimpleL2Burn()
@@ -48,7 +48,7 @@ func testRestart(t *testing.T, tee bool) {
4848

4949
// Bring the batcher back up and check that it processes the transaction which was submitted
5050
// while it was down.
51-
require.NoError(t, d.ServiceUp("op-batcher"))
51+
require.NoError(t, d.ServiceUp(ServiceBatcher))
5252
require.NoError(t, d.VerifySimpleL2Burn(receipt))
5353

5454
// Submit another transaction at the end just to check that things stay working.

espresso/devnet-tests/devnet_tools.go

Lines changed: 119 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,82 @@ import (
3232
"github.com/ethereum-optimism/optimism/op-e2e/config/secrets"
3333
)
3434

35+
type Service uint64
36+
37+
const (
38+
ServiceBatcher Service = iota
39+
ServiceCaffNode
40+
ServiceCaffNodeGeth
41+
ServiceChallenger
42+
ServiceDevNode
43+
ServiceHTTPProxy
44+
ServiceL1Beacon
45+
ServiceL1DataInit
46+
ServiceL1Genesis
47+
ServiceL1Geth
48+
ServiceL1Validator
49+
ServiceL2Genesis
50+
ServiceL2Rollup
51+
ServiceL2Seq
52+
ServiceL2SeqGeth
53+
ServiceL2Verif
54+
ServiceL2VerifGeth
55+
ServiceProposer
56+
)
57+
58+
const (
59+
ProfileDefault = "default"
60+
ProfileTee = "tee"
61+
)
62+
63+
type Profile struct {
64+
BatcherService string
65+
ProposerService string
66+
}
67+
68+
// modifyDefaultProfile creates a new profile based on the default profile with specified modifications
69+
func modifyDefaultProfile(modifications map[Service]string) map[Service]string {
70+
result := make(map[Service]string)
71+
// Copy all services from default profile
72+
for service, container := range defaultProfile {
73+
result[service] = container
74+
}
75+
// Apply modifications
76+
for service, container := range modifications {
77+
result[service] = container
78+
}
79+
return result
80+
}
81+
82+
var defaultProfile = map[Service]string{
83+
ServiceBatcher: "op-batcher",
84+
ServiceCaffNode: "caff-node",
85+
ServiceCaffNodeGeth: "op-geth-caff-node",
86+
ServiceChallenger: "op-challenger",
87+
ServiceDevNode: "espresso-dev-node",
88+
ServiceHTTPProxy: "http-proxy",
89+
ServiceL1Beacon: "l1-beacon",
90+
ServiceL1DataInit: "l1-data-init",
91+
ServiceL1Genesis: "l1-genesis",
92+
ServiceL1Geth: "l1-geth",
93+
ServiceL1Validator: "l1-validator",
94+
ServiceL2Genesis: "l2-genesis",
95+
ServiceL2Rollup: "l2-rollup",
96+
ServiceL2Seq: "op-node-sequencer",
97+
ServiceL2SeqGeth: "op-geth-sequencer",
98+
ServiceL2Verif: "op-node-verifier",
99+
ServiceL2VerifGeth: "op-geth-verifier",
100+
ServiceProposer: "op-proposer",
101+
}
102+
103+
var Profiles = map[string]map[Service]string{
104+
ProfileDefault: defaultProfile,
105+
ProfileTee: modifyDefaultProfile(map[Service]string{
106+
ServiceBatcher: "op-batcher-tee",
107+
ServiceProposer: "op-proposer-tee",
108+
}),
109+
}
110+
35111
type Devnet struct {
36112
ctx context.Context
37113
tee bool
@@ -98,6 +174,27 @@ func (d *Devnet) isRunning() bool {
98174
return len(out) > 0
99175
}
100176

177+
// getProfile returns the current profile name based on devnet configuration
178+
func (d *Devnet) getProfile() string {
179+
if d.tee {
180+
return ProfileTee
181+
}
182+
return ProfileDefault
183+
}
184+
185+
// getServiceName returns the container name for a given service in the current profile
186+
func (d *Devnet) getServiceName(service Service) string {
187+
profile := d.getProfile()
188+
if container, ok := Profiles[profile][service]; ok {
189+
return container
190+
}
191+
// Fall back to default profile if service not found
192+
if container, ok := Profiles[ProfileDefault][service]; ok {
193+
return container
194+
}
195+
return ""
196+
}
197+
101198
func (d *Devnet) Up() (err error) {
102199
if d.isRunning() {
103200
if err := d.Down(); err != nil {
@@ -107,12 +204,9 @@ func (d *Devnet) Up() (err error) {
107204
// up any existing state.
108205
return fmt.Errorf("devnet is already running, this should be a clean state; please shut it down first")
109206
}
110-
var profile string
111-
if d.tee {
112-
profile = "tee"
113-
} else {
114-
profile = "default"
115-
}
207+
208+
profile := d.getProfile()
209+
116210
cmd := exec.CommandContext(
117211
d.ctx,
118212
"docker", "compose", "--profile", profile, "up", "-d",
@@ -150,7 +244,7 @@ func (d *Devnet) Up() (err error) {
150244
// Stream logs to stdout while the test runs. This goroutine will automatically exit when
151245
// the context is cancelled.
152246
go func() {
153-
cmd = exec.CommandContext(d.ctx, "docker", "compose", "logs", "-f")
247+
cmd = exec.CommandContext(d.ctx, "docker", "compose", "--profile", profile, "logs", "-f")
154248
cmd.Stdout = os.Stdout
155249
// We don't care about the error return of this command, since it's always going to be
156250
// killed by the context cancellation.
@@ -159,50 +253,52 @@ func (d *Devnet) Up() (err error) {
159253
}
160254

161255
// Open RPC clients for the different nodes.
162-
d.L2Seq, err = d.serviceClient("op-geth-sequencer", 8546)
256+
d.L2Seq, err = d.serviceClient(d.getServiceName(ServiceL2SeqGeth), 8546)
163257
if err != nil {
164258
return err
165259
}
166-
d.L2SeqRollup, err = d.rollupClient("op-node-sequencer", 9545)
260+
d.L2SeqRollup, err = d.rollupClient(d.getServiceName(ServiceL2Seq), 9545)
167261
if err != nil {
168262
return err
169263
}
170-
d.L2Verif, err = d.serviceClient("op-geth-verifier", 8546)
264+
d.L2Verif, err = d.serviceClient(d.getServiceName(ServiceL2VerifGeth), 8546)
171265
if err != nil {
172266
return err
173267
}
174-
d.L2VerifRollup, err = d.rollupClient("op-node-verifier", 9546)
268+
d.L2VerifRollup, err = d.rollupClient(d.getServiceName(ServiceL2Verif), 9546)
175269
if err != nil {
176270
return err
177271
}
178272

179-
d.L1, err = d.serviceClient("l1-geth", 8545)
273+
d.L1, err = d.serviceClient(d.getServiceName(ServiceL1Geth), 8545)
180274
if err != nil {
181275
return err
182276
}
183277

184278
return nil
185279
}
186280

187-
func (d *Devnet) ServiceUp(service string) error {
188-
log.Info("bringing up service", "service", service)
281+
func (d *Devnet) ServiceUp(service Service) error {
282+
serviceName := d.getServiceName(service)
283+
log.Info("bringing up service", "service", serviceName)
189284
cmd := exec.CommandContext(
190285
d.ctx,
191-
"docker", "compose", "up", "-d", service,
286+
"docker", "compose", "--profile", d.getProfile(), "up", "-d", serviceName,
192287
)
193288
return cmd.Run()
194289
}
195290

196-
func (d *Devnet) ServiceDown(service string) error {
197-
log.Info("shutting down service", "service", service)
291+
func (d *Devnet) ServiceDown(service Service) error {
292+
serviceName := d.getServiceName(service)
293+
log.Info("shutting down service", "service", serviceName)
198294
cmd := exec.CommandContext(
199295
d.ctx,
200-
"docker", "compose", "down", service,
296+
"docker", "compose", "--profile", d.getProfile(), "down", serviceName,
201297
)
202298
return cmd.Run()
203299
}
204300

205-
func (d *Devnet) ServiceRestart(service string) error {
301+
func (d *Devnet) ServiceRestart(service Service) error {
206302
if err := d.ServiceDown(service); err != nil {
207303
return err
208304
}
@@ -428,7 +524,7 @@ func (d *Devnet) Down() error {
428524
// Use timeout flag for faster Docker shutdown
429525
cmd := exec.CommandContext(
430526
d.ctx,
431-
"docker", "compose", "down", "-v", "--remove-orphans", "--timeout", "10",
527+
"docker", "compose", "--profile", d.getProfile(), "down", "-v", "--remove-orphans", "--timeout", "10",
432528
)
433529
return cmd.Run()
434530
}
@@ -574,7 +670,8 @@ func (d *Devnet) OpChallengerOutput(opts ...string) (string, error) {
574670
}
575671

576672
func (d *Devnet) opChallengerCmd(opts ...string) *exec.Cmd {
577-
opts = append([]string{"compose", "exec", "op-challenger", "entrypoint.sh", "op-challenger"}, opts...)
673+
serviceName := d.getServiceName(ServiceChallenger)
674+
opts = append([]string{"compose", "--profile", d.getProfile(), "exec", serviceName, "entrypoint.sh", "op-challenger"}, opts...)
578675
cmd := exec.CommandContext(
579676
d.ctx,
580677
"docker",
@@ -594,7 +691,7 @@ func (d *Devnet) hostPort(service string, privatePort uint16) (uint16, error) {
594691
errBuf := new(bytes.Buffer)
595692
cmd := exec.CommandContext(
596693
d.ctx,
597-
"docker", "compose", "port", service, fmt.Sprint(privatePort),
694+
"docker", "compose", "--profile", d.getProfile(), "port", service, fmt.Sprint(privatePort),
598695
)
599696
cmd.Stdout = buf
600697
cmd.Stderr = errBuf

0 commit comments

Comments
 (0)