Skip to content

Commit

Permalink
op-deployer: Fix init bugs (ethereum-optimism#12230)
Browse files Browse the repository at this point in the history
- The array was being appended to, but it was already a fixed length. This cause an empty chain to be added during `init`.
- The outdir will now be created if it does not exist and is not a file
- Hardcodes the contract artifacts to a good URL
  • Loading branch information
mslipper authored Oct 1, 2024
1 parent 7feffce commit 8a7db41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
26 changes: 21 additions & 5 deletions op-chain-ops/deployer/init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package deployer

import (
"errors"
"fmt"
"os"
"path"
"strings"

Expand All @@ -13,6 +15,8 @@ import (
"github.com/urfave/cli/v2"
)

var V160ArtifactsURL = state.MustParseArtifactsURL("https://storage.googleapis.com/oplabs-contract-artifacts/artifacts-v1-155f65e7dcbea1b7b3d37a0fc39cc8b6a1c03b6c5b677886ca2420e10e9c1ea6.tar.gz")

type InitConfig struct {
L1ChainID uint64
Outdir string
Expand Down Expand Up @@ -43,12 +47,12 @@ func InitCLI() func(ctx *cli.Context) error {
l2ChainIDsRaw := ctx.String(L2ChainIDsFlagName)
l2ChainIDsStr := strings.Split(strings.TrimSpace(l2ChainIDsRaw), ",")
l2ChainIDs := make([]common.Hash, len(l2ChainIDsStr))
for _, idStr := range l2ChainIDsStr {
for i, idStr := range l2ChainIDsStr {
id, err := op_service.Parse256BitChainID(idStr)
if err != nil {
return fmt.Errorf("invalid chain ID: %w", err)
}
l2ChainIDs = append(l2ChainIDs, id)
l2ChainIDs[i] = id
}

return Init(InitConfig{
Expand All @@ -65,9 +69,10 @@ func Init(cfg InitConfig) error {
}

intent := &state.Intent{
L1ChainID: cfg.L1ChainID,
FundDevAccounts: true,
ContractsRelease: "dev",
L1ChainID: cfg.L1ChainID,
FundDevAccounts: true,
ContractsRelease: "op-contracts/v1.6.0",
ContractArtifactsURL: V160ArtifactsURL,
}

l1ChainIDBig := intent.L1ChainIDBig()
Expand Down Expand Up @@ -111,6 +116,17 @@ func Init(cfg InitConfig) error {
Version: 1,
}

stat, err := os.Stat(cfg.Outdir)
if errors.Is(err, os.ErrNotExist) {
if err := os.MkdirAll(cfg.Outdir, 0755); err != nil {
return fmt.Errorf("failed to create outdir: %w", err)
}
} else if err != nil {
return fmt.Errorf("failed to stat outdir: %w", err)
} else if !stat.IsDir() {
return fmt.Errorf("outdir is not a directory")
}

if err := intent.WriteToFile(path.Join(cfg.Outdir, "intent.toml")); err != nil {
return fmt.Errorf("failed to write intent to file: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions op-chain-ops/deployer/state/artifacts_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ func (a *ArtifactsURL) UnmarshalText(text []byte) error {
*a = ArtifactsURL(*u)
return nil
}

func ParseArtifactsURL(in string) (*ArtifactsURL, error) {
u, err := url.Parse(in)
if err != nil {
return nil, err
}
return (*ArtifactsURL)(u), nil
}

func MustParseArtifactsURL(in string) *ArtifactsURL {
u, err := ParseArtifactsURL(in)
if err != nil {
panic(err)
}
return u
}

0 comments on commit 8a7db41

Please sign in to comment.