Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-deployer: Fix init bug #12230

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
mslipper marked this conversation as resolved.
Show resolved Hide resolved
}

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
}