Commit 8a7db419 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-deployer: Fix init bugs (#12230)

- 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
parent 7feffce8
package deployer
import (
"errors"
"fmt"
"os"
"path"
"strings"
......@@ -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
......@@ -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{
......@@ -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()
......@@ -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)
}
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment