@@ -78,7 +78,6 @@ const (
7878)
7979
8080type Cfg struct {
81- Mode services.Mode `toml:"mode"`
8281 CLDF CLDF `toml:"cldf" validate:"required"`
8382 JD * jd.Input `toml:"jd" validate:"required"`
8483 Fake * services.FakeInput `toml:"fake" validate:"required"`
@@ -111,6 +110,8 @@ func (c *Cfg) NewAggregatorClientForCommittee(logger zerolog.Logger, committeeNa
111110 return NewAggregatorClient (logger , endpoint , caCertFile )
112111}
113112
113+ // checkKeys performs basic sanity checks on the private key being used depending on which chain is in
114+ // the provided configuration.
114115func checkKeys (in * Cfg ) error {
115116 if getNetworkPrivateKey () != DefaultAnvilKey && in .Blockchains [0 ].ChainID == "1337" && in .Blockchains [1 ].ChainID == "2337" {
116117 return errors .New ("you are trying to run simulated chains with a key that do not belong to Anvil, please run 'unset PRIVATE_KEY'" )
@@ -133,7 +134,7 @@ func NewProductConfigurationFromNetwork(typ string) (cciptestinterfaces.CCIP17Pr
133134 }
134135}
135136
136- // NewEnvironment creates a new CCIP CCV environment either locally in Docker or remotely in K8s .
137+ // NewEnvironment creates a new CCIP CCV environment locally in Docker.
137138func NewEnvironment () (in * Cfg , err error ) {
138139 ctx := context .Background ()
139140 timeTrack := NewTimeTracker (Plog )
@@ -149,6 +150,10 @@ func NewEnvironment() (in *Cfg, err error) {
149150 return nil , err
150151 }
151152
153+ /////////////////////////////
154+ // START: Read Config toml //
155+ /////////////////////////////
156+
152157 configs := strings .Split (os .Getenv (EnvVarTestConfigs ), "," )
153158 if len (configs ) > 1 {
154159 L .Warn ().Msg ("Multiple configuration files detected, this feature may be unsupported in the future." )
@@ -158,15 +163,6 @@ func NewEnvironment() (in *Cfg, err error) {
158163 return nil , fmt .Errorf ("failed to load configuration: %w" , err )
159164 }
160165
161- ///////////////////////////////
162- // Start: Initialize Configs //
163- ///////////////////////////////
164-
165- // Override the default config to "cl"...
166- if in .Mode == "" {
167- in .Mode = services .Standalone
168- }
169-
170166 // Executor config...
171167 if in .Executor != nil {
172168 for _ , exec := range in .Executor {
@@ -175,20 +171,23 @@ func NewEnvironment() (in *Cfg, err error) {
175171 }
176172
177173 /////////////////////////////
178- // End: Initialize Configs //
174+ // END: Read Config toml //
179175 /////////////////////////////
180176
181- if err = checkKeys (in ); err != nil {
182- return nil , err
183- }
184-
185177 // Start fake data provider. This isn't really used, but may be useful in the future.
186178 _ , err = services .NewFake (in .Fake )
187179 if err != nil {
188180 return nil , fmt .Errorf ("failed to create fake data provider: %w" , err )
189181 }
190182
191- // Start blockchains, the services crash if the RPC is not available.
183+ ///////////////////////////////
184+ // START: Deploy blockchains //
185+ // The services crash if the RPC is not available.
186+ ///////////////////////////////
187+ if err = checkKeys (in ); err != nil {
188+ return nil , err
189+ }
190+
192191 impls := make ([]cciptestinterfaces.CCIP17ProductConfiguration , 0 )
193192 for _ , bc := range in .Blockchains {
194193 var impl cciptestinterfaces.CCIP17ProductConfiguration
@@ -204,9 +203,12 @@ func NewEnvironment() (in *Cfg, err error) {
204203 return nil , fmt .Errorf ("failed to deploy local networks: %w" , err )
205204 }
206205 }
206+ /////////////////////////////
207+ // END: Deploy blockchains //
208+ /////////////////////////////
207209
208210 ////////////////////////////
209- // Start : Launch CL Nodes //
211+ // START : Launch CL Nodes //
210212 // We launch the CL nodes first because they don't require any configuration from
211213 // the rest of the system to be up and running.
212214 // In addition, if we need to launch the nodes (i.e if some services are not standalone),
@@ -222,10 +224,12 @@ func NewEnvironment() (in *Cfg, err error) {
222224 timeTrack .Record ("[infra] deployed CL nodes" )
223225
224226 //////////////////////////
225- // End : Launch CL Nodes //
227+ // END : Launch CL Nodes //
226228 //////////////////////////
227229
228- // Verifier configs...
230+ /////////////////////////////////////////////
231+ // START: Assign signing keys to verifiers //
232+ /////////////////////////////////////////////
229233 roundRobin := NewRoundRobinAssignment (onchainPublicKeys [signingKeyChainType ])
230234 for i := range in .Verifier {
231235 ver := services .ApplyVerifierDefaults (* in .Verifier [i ])
@@ -263,34 +267,13 @@ func NewEnvironment() (in *Cfg, err error) {
263267 // Apply changes back to input.
264268 in .Verifier [i ] = & ver
265269 }
266-
267- // JD is not currently used.
268- /*
269- prodJDImage := os.Getenv("JD_IMAGE")
270-
271- if in.JD != nil {
272- if prodJDImage != "" {
273- in.JD.Image = prodJDImage
274- }
275- if len(in.JD.Image) == 0 {
276- Plog.Warn().Msg("No JD image provided, skipping JD service startup")
277- } else {
278- _, err = jd.NewJD(in.JD)
279- if err != nil {
280- return nil, fmt.Errorf("failed to create JD service: %w", err)
281- }
282- }
283- } else {
284- Plog.Warn().Msg("No JD configuration provided, skipping JD service startup")
285- }
286- */
287-
288- timeTrack .Record ("[infra] deploying blockchains" )
270+ /////////////////////////////////////////////
271+ // END: Assign signing keys to verifiers //
272+ /////////////////////////////////////////////
289273
290274 /////////////////////////////
291- // Start : Deploy contracts //
275+ // START : Deploy contracts //
292276 /////////////////////////////
293-
294277 var committees []cciptestinterfaces.OnChainCommittees
295278 {
296279 addrs := make (map [string ][][]byte )
@@ -322,6 +305,7 @@ func NewEnvironment() (in *Cfg, err error) {
322305 }
323306 L .Info ().Any ("Selectors" , selectors ).Msg ("Deploying for chain selectors" )
324307
308+ timeTrack .Record ("[infra] deploying blockchains" )
325309 ds := datastore .NewMemoryDataStore ()
326310 for i , impl := range impls {
327311 var networkInfo chainsel.ChainDetails
@@ -351,6 +335,13 @@ func NewEnvironment() (in *Cfg, err error) {
351335 }
352336 }
353337 e .DataStore = ds .Seal ()
338+ ///////////////////////////
339+ // END: Deploy contracts //
340+ ///////////////////////////
341+
342+ /////////////////////////////////////////
343+ // START: Connect chains to each other //
344+ /////////////////////////////////////////
354345
355346 for i , impl := range impls {
356347 var networkInfo chainsel.ChainDetails
@@ -369,15 +360,15 @@ func NewEnvironment() (in *Cfg, err error) {
369360 return nil , err
370361 }
371362 }
372- ///////////////////////////
373- // END: Deploy contracts //
374- ///////////////////////////
375363
376- ///////////////////////////////////////
377- // Start: Launch standalone services //
378- ///////////////////////////////////////
364+ /////////////////////////////////////////
365+ // END: Connect chains to each other //
366+ /////////////////////////////////////////
367+
368+ ///////////////////////////////
369+ // START: Launch aggregators //
370+ ///////////////////////////////
379371
380- // Start aggregators.
381372 in .AggregatorEndpoints = make (map [string ]string )
382373 in .AggregatorCACertFiles = make (map [string ]string )
383374
@@ -430,9 +421,15 @@ func NewEnvironment() (in *Cfg, err error) {
430421 }
431422 }
432423
433- // Start indexer.
424+ ///////////////////////////////
425+ // START: Launch aggregators //
426+ ///////////////////////////////
427+
428+ ///////////////////////////
429+ // START: Launch indexer //
434430 // start up the indexer after the aggregators are up to avoid spamming of errors
435431 // in the logs when it starts before the aggregators are up.
432+ ///////////////////////////
436433 // Need to update the addresses in the indexer config due to contract deployment nondeterminism.
437434 for _ , agg := range in .Aggregator {
438435 // XXX: in theory addresses should be matching across chains
@@ -497,6 +494,14 @@ func NewEnvironment() (in *Cfg, err error) {
497494
498495 in .IndexerEndpoint = indexerOut .ExternalHTTPURL
499496
497+ /////////////////////////
498+ // END: Launch indexer //
499+ /////////////////////////
500+
501+ /////////////////////////////
502+ // START: Launch executors //
503+ /////////////////////////////
504+
500505 if len (in .Executor ) > 0 {
501506 execs , err := services .ResolveContractsForExecutor (e .DataStore , in .Blockchains , in .Executor )
502507 if err != nil {
@@ -533,6 +538,13 @@ func NewEnvironment() (in *Cfg, err error) {
533538 return nil , fmt .Errorf ("failed to create standalone executor: %w" , err )
534539 }
535540
541+ ///////////////////////////
542+ // END: Launch executors //
543+ ///////////////////////////
544+
545+ /////////////////////////////
546+ // START: Launch verifiers //
547+ /////////////////////////////
536548 // Populate verifier input with contract addresses from the CLDF datastore.
537549 for i := range in .Verifier {
538550 ver , err := services .ResolveContractsForVerifier (e .DataStore , in .Blockchains , * in .Verifier [i ])
@@ -574,6 +586,14 @@ func NewEnvironment() (in *Cfg, err error) {
574586 return nil , fmt .Errorf ("failed to create standalone verifiers: %w" , err )
575587 }
576588
589+ /////////////////////////////
590+ // END: Launch verifiers //
591+ /////////////////////////////
592+
593+ ///////////////////////////////////
594+ // START: Launch token verifiers //
595+ ///////////////////////////////////
596+
577597 for i := range in .TokenVerifier {
578598 ver , err := services .ResolveContractsForTokenVerifier (e .DataStore , in .Blockchains , * in .TokenVerifier [i ])
579599 if err != nil {
@@ -588,15 +608,25 @@ func NewEnvironment() (in *Cfg, err error) {
588608 return nil , fmt .Errorf ("failed to create standalone token verifiers: %w" , err )
589609 }
590610
591- /////////////////////////////////////
592- // End: Launch standalone services //
593- /////////////////////////////////////
611+ ///////////////////////////////////
612+ // END: Launch token verifiers //
613+ ///////////////////////////////////
614+
615+ ////////////////////////////////////////////////////
616+ // START: Create jobs for verifiers and executors //
617+ // Note that if they are started in standalone mode,
618+ // there would be no CL nodes and this would be a no-op.
619+ ////////////////////////////////////////////////////
594620
595621 err = createJobs (in , in .Verifier , in .Executor )
596622 if err != nil {
597623 return nil , fmt .Errorf ("failed to create jobs: %w" , err )
598624 }
599625
626+ //////////////////////////////////////////////////
627+ // END: Create jobs for verifiers and executors //
628+ //////////////////////////////////////////////////
629+
600630 timeTrack .Print ()
601631 if err = PrintCLDFAddresses (in ); err != nil {
602632 return nil , err
0 commit comments