From 0b78ba9f361740fd605a472d87c95fbe2ddb8232 Mon Sep 17 00:00:00 2001 From: Hamdi Allam Date: Thu, 12 Sep 2024 22:15:07 +0200 Subject: [PATCH] kickOffMining concurrent again --- orchestrator/orchestrator.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index 6be88976..00932173 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -7,6 +7,7 @@ import ( "fmt" "sort" "strings" + "sync" "github.com/ethereum-optimism/supersim/anvil" "github.com/ethereum-optimism/supersim/config" @@ -168,12 +169,22 @@ func (o *Orchestrator) kickOffMining(ctx context.Context) error { if err := o.l1Chain.SetIntervalMining(ctx, nil, 2); err != nil { return errors.New("failed to start interval mining on l1") } - for _, chain := range o.l2Chains { - if err := chain.SetIntervalMining(ctx, nil, 2); err != nil { - return fmt.Errorf("failed to start interval mining for chain %s", chain.Config().Name) - } + + var wg sync.WaitGroup + wg.Add(len(o.l2Chains)) + + errs := make([]error, len(o.l2Chains)) + for i, chain := range o.l2Chains { + go func(i uint64) { + if err := chain.SetIntervalMining(ctx, nil, 2); err != nil { + errs[i] = fmt.Errorf("failed to start interval mining for chain %s", chain.Config().Name) + } + + wg.Done() + }(i) } - return nil + + return errors.Join(errs...) } func (o *Orchestrator) L1Chain() config.Chain {