Skip to content

Commit 6d0a376

Browse files
committed
Set mode per service.
WIP
1 parent ffa2e8d commit 6d0a376

File tree

4 files changed

+61
-29
lines changed

4 files changed

+61
-29
lines changed

build/devenv/environment.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,8 @@ const (
6161
`
6262
)
6363

64-
type Mode string
65-
66-
const (
67-
Standalone Mode = "standalone"
68-
CL Mode = "cl"
69-
)
70-
7164
type Cfg struct {
72-
Mode Mode `toml:"mode"`
65+
Mode services.Mode `toml:"mode"`
7366
CLDF CLDF `toml:"cldf" validate:"required"`
7467
JD *jd.Input `toml:"jd" validate:"required"`
7568
Fake *services.FakeInput `toml:"fake" validate:"required"`
@@ -129,16 +122,29 @@ func NewEnvironment() (in *Cfg, err error) {
129122
///////////////////////////////
130123
// Start: Initialize Configs //
131124
///////////////////////////////
125+
126+
var hasCLNodeService bool
127+
132128
// Override the default config to "cl"...
133129
if in.Mode == "" {
134-
in.Mode = Standalone
130+
in.Mode = services.Standalone
135131
}
136132

137133
// Verifier configs...
138-
for _, ver := range in.Verifier {
134+
for i, ver := range in.Verifier {
135+
services.ApplyVerifierDefaults(ver)
139136
// deterministic key generation algorithm.
140137
ver.ConfigFilePath = fmt.Sprintf("/app/cmd/verifier/testconfig/%s/verifier-%d.toml", ver.CommitteeName, ver.NodeIndex+1)
141138
ver.SigningKey = cciptestinterfaces.XXXNewVerifierPrivateKey(ver.CommitteeName, ver.NodeIndex)
139+
in.Verifier[i] = ver // technically not needed because it's a pointer.
140+
141+
hasCLNodeService = hasCLNodeService || (ver.Mode == services.CL)
142+
}
143+
144+
// Executor config...
145+
if in.Executor != nil {
146+
services.ApplyExecutorDefaults(in.Executor)
147+
hasCLNodeService = hasCLNodeService || (in.Executor.Mode == services.CL)
142148
}
143149

144150
/////////////////////////////
@@ -262,7 +268,7 @@ func NewEnvironment() (in *Cfg, err error) {
262268
timeTrack.Record("[infra] deployed CL nodes")
263269
timeTrack.Record("[changeset] deployed product contracts")
264270

265-
if in.Mode == CL { //nolint:nestif // large block needed for clarity, refactor as a cl node component later
271+
if hasCLNodeService { //nolint:nestif // large block needed for clarity, refactor as a cl node component later
266272
clChainConfigs := make([]string, 0)
267273
clChainConfigs = append(clChainConfigs, CommonCLNodesConfig)
268274
for i, impl := range impls {
@@ -311,23 +317,31 @@ func NewEnvironment() (in *Cfg, err error) {
311317
if err != nil {
312318
return nil, fmt.Errorf("decoding verifier signing key (%s): %w", ver.ContainerName, err)
313319
}
314-
cc.ImportEVMKey(pk, ver.CommitteeName)
320+
cc.ImportEVMKey(pk, ver.ContainerName)
315321
}
316322
}
317323
}
318324
}
319325

320-
// Start standalone executor/verifiers if in standalone mode.
321-
if in.Mode == Standalone {
322-
_, err = services.NewExecutor(in.Executor)
323-
if err != nil {
324-
return nil, fmt.Errorf("failed to create executor service: %w", err)
326+
// TODO: remove this if condition once configuration is injected into the node.
327+
// For now, if the core node is started, assume that it will launch all services.
328+
// TODO: Maybe it starts with just the verifiers.
329+
if !hasCLNodeService {
330+
// Start standalone executor if in standalone mode.
331+
if in.Executor != nil && in.Executor.Mode == services.Standalone {
332+
_, err = services.NewExecutor(in.Executor)
333+
if err != nil {
334+
return nil, fmt.Errorf("failed to create executor service: %w", err)
335+
}
325336
}
326337

338+
// Start standalone verifiers if in standalone mode.
327339
for _, ver := range in.Verifier {
328-
_, err = services.NewVerifier(ver)
329-
if err != nil {
330-
return nil, fmt.Errorf("failed to create verifier service: %w", err)
340+
if ver.Mode == services.Standalone {
341+
_, err = services.NewVerifier(ver)
342+
if err != nil {
343+
return nil, fmt.Errorf("failed to create verifier service: %w", err)
344+
}
331345
}
332346
}
333347
}

build/devenv/services/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"github.com/testcontainers/testcontainers-go"
1010
)
1111

12+
type Mode string
13+
14+
const (
15+
Standalone Mode = "standalone"
16+
CL Mode = "cl"
17+
)
18+
1219
const (
1320
AppPathInsideContainer = "/app"
1421
)

build/devenv/services/executor.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ const (
1616
DefaultExecutorName = "executor"
1717
DefaultExecutorImage = "executor:dev"
1818
DefaultExecutorPort = 8101
19+
DefaultExecutorMode = Standalone
1920
)
2021

2122
type ExecutorInput struct {
23+
Mode Mode `toml:"mode"`
2224
Out *ExecutorOutput `toml:"-"`
2325
Image string `toml:"image"`
2426
SourceCodePath string `toml:"source_code_path"`
@@ -35,7 +37,7 @@ type ExecutorOutput struct {
3537
UseCache bool `toml:"use_cache"`
3638
}
3739

38-
func executorDefaults(in *ExecutorInput) {
40+
func ApplyExecutorDefaults(in *ExecutorInput) {
3941
if in.Image == "" {
4042
in.Image = DefaultExecutorImage
4143
}
@@ -45,6 +47,9 @@ func executorDefaults(in *ExecutorInput) {
4547
if in.ContainerName == "" {
4648
in.ContainerName = DefaultExecutorName
4749
}
50+
if in.Mode == "" {
51+
in.Mode = DefaultExecutorMode
52+
}
4853
}
4954

5055
func NewExecutor(in *ExecutorInput) (*ExecutorOutput, error) {
@@ -55,7 +60,7 @@ func NewExecutor(in *ExecutorInput) (*ExecutorOutput, error) {
5560
return in.Out, nil
5661
}
5762
ctx := context.Background()
58-
executorDefaults(in)
63+
ApplyExecutorDefaults(in)
5964
p, err := CwdSourcePath(in.SourceCodePath)
6065
if err != nil {
6166
return in.Out, err

build/devenv/services/verifier.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
DefaultVerifierPort = 8100
2727
DefaultVerifierDBPort = 8432
2828
DefaultVerifierSQLInit = "init.sql"
29+
DefaultVerifierMode = Standalone
2930

3031
DefaultVerifierDBImage = "postgres:16-alpine"
3132
)
@@ -75,11 +76,13 @@ type VerifierEnvConfig struct {
7576
}
7677

7778
type VerifierInput struct {
78-
DB *VerifierDBInput `toml:"db"`
79-
Out *VerifierOutput `toml:"out"`
80-
Image string `toml:"image"`
81-
SourceCodePath string `toml:"source_code_path"`
82-
RootPath string `toml:"root_path"`
79+
Mode Mode `toml:"mode"`
80+
DB *VerifierDBInput `toml:"db"`
81+
Out *VerifierOutput `toml:"out"`
82+
Image string `toml:"image"`
83+
SourceCodePath string `toml:"source_code_path"`
84+
RootPath string `toml:"root_path"`
85+
// TODO: Rename to VerifierID -- maps to this value in verifier.Config
8386
ContainerName string `toml:"container_name"`
8487
VerifierConfig verifier.Config `toml:"verifier_config"`
8588
Port int `toml:"port"`
@@ -102,7 +105,7 @@ type VerifierOutput struct {
102105
UseCache bool `toml:"use_cache"`
103106
}
104107

105-
func verifierDefaults(in *VerifierInput) {
108+
func ApplyVerifierDefaults(in *VerifierInput) {
106109
if in.Image == "" {
107110
in.Image = DefaultVerifierImage
108111
}
@@ -122,6 +125,9 @@ func verifierDefaults(in *VerifierInput) {
122125
if in.ConfigFilePath == "" {
123126
in.ConfigFilePath = fmt.Sprintf("/app/cmd/verifier/testconfig/%s/verifier-%d.toml", in.CommitteeName, in.NodeIndex+1)
124127
}
128+
if in.Mode == "" {
129+
in.Mode = DefaultVerifierMode
130+
}
125131
}
126132

127133
func NewVerifier(in *VerifierInput) (*VerifierOutput, error) {
@@ -133,7 +139,7 @@ func NewVerifier(in *VerifierInput) (*VerifierOutput, error) {
133139
}
134140
ctx := context.Background()
135141

136-
verifierDefaults(in)
142+
ApplyVerifierDefaults(in)
137143
p, err := CwdSourcePath(in.SourceCodePath)
138144
if err != nil {
139145
return in.Out, err

0 commit comments

Comments
 (0)