Skip to content

Commit

Permalink
Merge pull request #24 from ethereum-optimism/06-25-feat_spin_up_mult…
Browse files Browse the repository at this point in the history
…iple_chains

feat: spin up multiple chains
  • Loading branch information
jakim929 authored Jun 26, 2024
2 parents ab50a52 + df208bc commit aa2d91a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ func SupersimMain(ctx *cli.Context, closeApp context.CancelCauseFunc) (cliapp.Li
}

// use config and setup supersim
return supersim.NewSupersim(log), nil
return supersim.NewSupersim(log, &supersim.DefaultConfig), nil
}
59 changes: 51 additions & 8 deletions supersim.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,77 @@
package supersim

import (
"fmt"

"context"

"github.com/ethereum-optimism/supersim/anvil"

"github.com/ethereum/go-ethereum/log"
)



type Config struct {
l1Chain anvil.Config
l2Chains []anvil.Config
}

var DefaultConfig = Config{
l1Chain: anvil.Config{ChainId: 1, Port: 8545},
l2Chains: []anvil.Config{{ChainId: 10, Port: 9545}, {ChainId: 30, Port: 9555}},
}

type Supersim struct {
log log.Logger

anvil *anvil.Anvil
l1Chain *anvil.Anvil
l2Chains map[uint64]*anvil.Anvil

}

func NewSupersim(log log.Logger) *Supersim {
anvil := anvil.New(log, &anvil.Config{ChainId: 10, Port: 9545})
return &Supersim{log, anvil}
func NewSupersim(log log.Logger, config *Config) *Supersim {
l1Chain := anvil.New(log, &config.l1Chain)

l2Chains := make(map[uint64]*anvil.Anvil)
for _, l2Chain := range config.l2Chains {
l2Chains[l2Chain.ChainId] = anvil.New(log, &l2Chain)
}

return &Supersim{log, l1Chain, l2Chains}
}

func (s *Supersim) Start(ctx context.Context) error {
s.log.Info("starting supersim")
return s.anvil.Start(ctx)

if err := s.l1Chain.Start(ctx); err != nil {
return fmt.Errorf("l1 chain failed to start: %w", err)
}

for _, l2Chain := range s.l2Chains {
if err := l2Chain.Start(ctx); err!= nil {
return fmt.Errorf("l2 chain failed to start: %w", err)
}
}

return nil
}

func (s *Supersim) Stop(_ context.Context) error {
s.log.Info("stopping supersim")
return s.anvil.Stop()
}

for _, l2Chain := range s.l2Chains {
if err := l2Chain.Stop(); err!= nil {
return fmt.Errorf("l2 chain failed to stop: %w", err)
}
}

if err := s.l1Chain.Stop(); err != nil {
return fmt.Errorf("l1 chain failed to stop: %w", err)
}

return nil}

func (s *Supersim) Stopped() bool {
return s.anvil.Stopped()
return s.l1Chain.Stopped()
}

0 comments on commit aa2d91a

Please sign in to comment.