Skip to content
Open
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
4 changes: 2 additions & 2 deletions ops/cmd/import_devnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path"
"path/filepath"

"github.com/ethereum-optimism/superchain-registry/ops/internal/deployer"
"github.com/ethereum-optimism/superchain-registry/ops/internal/deployer/state"
"github.com/ethereum-optimism/superchain-registry/ops/internal/manage"
"github.com/ethereum-optimism/superchain-registry/ops/internal/output"
"github.com/ethereum-optimism/superchain-registry/ops/internal/paths"
Expand Down Expand Up @@ -81,7 +81,7 @@ func action(cliCtx *cli.Context) error {
return fmt.Errorf("failed to read manifest file: %w", err)
}

st, err := deployer.ReadOpaqueStateFile(statePath)
st, err := state.ReadOpaqueStateFile(statePath)
if err != nil {
return fmt.Errorf("failed to read opaque state file: %w", err)
}
Expand Down
28 changes: 15 additions & 13 deletions ops/internal/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/BurntSushi/toml"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/superchain-registry/ops/internal/deployer/opaque_map"
"github.com/ethereum-optimism/superchain-registry/ops/internal/deployer/state"
"github.com/ethereum/go-ethereum/log"
)

Expand All @@ -25,23 +27,23 @@ var contractVersions map[string]string

type BinaryPicker interface {
Path() string
Merger() StateMerger
Merger() state.StateMerger
}

type FixedBinaryPicker struct {
binaryPath string
merger StateMerger
merger state.StateMerger
}

func (f *FixedBinaryPicker) Path() string {
return f.binaryPath
}

func (f *FixedBinaryPicker) Merger() StateMerger {
func (f *FixedBinaryPicker) Merger() state.StateMerger {
return f.merger
}

func WithFixedBinary(binaryPath string, merger StateMerger) *FixedBinaryPicker {
func WithFixedBinary(binaryPath string, merger state.StateMerger) *FixedBinaryPicker {
return &FixedBinaryPicker{
binaryPath: binaryPath,
merger: merger,
Expand All @@ -64,7 +66,7 @@ func WithReleaseBinary(binDir string, l1ContractsRelease string) (*FixedBinaryPi

binaryPath := VersionedBinaryPath(binDir, deployerVersion)

merger, err := GetStateMerger(deployerVersion)
merger, err := state.GetStateMerger(deployerVersion)
if err != nil {
return nil, fmt.Errorf("failed to get state merger: %w", err)
}
Expand All @@ -86,7 +88,7 @@ func init() {
// then shelling out to that binary for various cli commands
type OpDeployer struct {
binaryPath string
merger StateMerger
merger state.StateMerger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly, but there's an opportunity to rename here so we have e.g. state.Merger a la Effective Go guidelines https://go.dev/doc/effective_go#package-names . Same goes for many other symbols that have "state" in the name.

lgr log.Logger
}

Expand All @@ -110,7 +112,7 @@ func NewOpDeployer(lgr log.Logger, binaryPicker BinaryPicker) (*OpDeployer, erro
// in the specified working directory.
func (d *OpDeployer) setupStateAndIntent(inputStatePath, workdir string) error {
// Read the state file
state, err := ReadOpaqueStateFile(inputStatePath)
state, err := state.ReadOpaqueStateFile(inputStatePath)
if err != nil {
return fmt.Errorf("failed to read state file: %w", err)
}
Expand All @@ -132,7 +134,7 @@ func (d *OpDeployer) setupStateAndIntent(inputStatePath, workdir string) error {
d.lgr.Info("Wrote state to temporary file", "path", stateTempPath)

// Write intent.toml in the temp directory
useInts(mergedIntent)
opaque_map.UseInts(mergedIntent)
intentTOML, err := toml.Marshal(mergedIntent)
if err != nil {
return fmt.Errorf("failed to marshal intent to TOML: %w", err)
Expand Down Expand Up @@ -176,7 +178,7 @@ func (d *OpDeployer) inspectCommand(workdir, chainId, subcommand string, result

// GenerateStandardGenesis runs op-deployer binary to generate a genesis
// - l1RpcUrl must match the state's L1 and is required by op-deployer, even though we aren't sending any txs
func (d *OpDeployer) GenerateStandardGenesis(statePath, chainId, l1RpcUrl string) (*OpaqueMap, error) {
func (d *OpDeployer) GenerateStandardGenesis(statePath, chainId, l1RpcUrl string) (*opaque_map.OpaqueMap, error) {
workdir, err := d.copyStateFileToTempDir(statePath)
if err != nil {
return nil, fmt.Errorf("failed to copy state file to temporary directory: %w", err)
Expand All @@ -203,7 +205,7 @@ func (d *OpDeployer) GenerateStandardGenesis(statePath, chainId, l1RpcUrl string
}

// Run `op-deployer inspect genesis` to read the expected genesis
var genesis OpaqueMap
var genesis opaque_map.OpaqueMap
if err := d.inspectCommand(workdir, chainId, "genesis", &genesis); err != nil {
return nil, err
}
Expand All @@ -218,7 +220,7 @@ func (d *OpDeployer) copyStateFileToTempDir(statePath string) (string, error) {
return "", fmt.Errorf("failed to create temporary directory: %w", err)
}

state, err := ReadOpaqueStateFile(statePath)
state, err := state.ReadOpaqueStateFile(statePath)
if err != nil {
return "", fmt.Errorf("failed to read state file: %w", err)
}
Expand All @@ -238,14 +240,14 @@ func (d *OpDeployer) copyStateFileToTempDir(statePath string) (string, error) {
return workdir, nil
}

func (d *OpDeployer) InspectGenesis(statePath, chainId string) (*OpaqueMap, error) {
func (d *OpDeployer) InspectGenesis(statePath, chainId string) (*opaque_map.OpaqueMap, error) {
workdir, err := d.copyStateFileToTempDir(statePath)
if err != nil {
return nil, fmt.Errorf("failed to copy state file: %w", err)
}
defer os.RemoveAll(workdir)

var genesis OpaqueMap
var genesis opaque_map.OpaqueMap
if err := d.inspectCommand(workdir, chainId, "genesis", &genesis); err != nil {
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions ops/internal/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"testing"

"github.com/ethereum-optimism/superchain-registry/ops/internal/deployer/state"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
Expand All @@ -17,35 +18,35 @@ func TestAutodetectBinary(t *testing.T) {
tests := []struct {
name string
l1ContractsRelease string
merger StateMerger
merger state.StateMerger
binPath string
shouldError bool
}{
{
name: "op-contracts/v1.6.0",
l1ContractsRelease: "tag://op-contracts/v1.6.0",
merger: MergeStateV1,
merger: state.MergeStateV1,
binPath: "op-deployer_v0.0.14",
shouldError: false,
},
{
name: "op-contracts/v2.0.0",
l1ContractsRelease: "tag://op-contracts/v2.0.0",
merger: MergeStateV2,
merger: state.MergeStateV2,
binPath: "op-deployer_v0.2.3",
shouldError: false,
},
{
name: "op-contracts/v3.0.0",
l1ContractsRelease: "tag://op-contracts/v3.0.0",
merger: MergeStateV3,
merger: state.MergeStateV3,
binPath: "op-deployer_v0.3.2",
shouldError: false,
},
{
name: "op-contracts/v4.0.0",
l1ContractsRelease: "tag://op-contracts/v4.0.0",
merger: MergeStateV4,
merger: state.MergeStateV4,
binPath: "op-deployer_v0.4.0-rc.3",
shouldError: false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deployer
package opaque_map

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deployer
package opaque_map

import (
"testing"
Expand Down
29 changes: 29 additions & 0 deletions ops/internal/deployer/opaque_map/opaque_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package opaque_map

type OpaqueMap map[string]any
Comment on lines +1 to +3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could call the package opaque and the map Map ?


// UseInts converts all float64 values without fractional parts to int64 values in a map
// so that they are properly marshaled to TOML
func UseInts(m map[string]any) {
for k, v := range m {
switch val := v.(type) {
case float64:
// If the float has no fractional part, convert to int
if val == float64(int64(val)) {
m[k] = int64(val)
}
case map[string]any:
// Recursively process nested maps
UseInts(val)
case []any:
// Process arrays
for i, item := range val {
if fItem, ok := item.(float64); ok && fItem == float64(int64(fItem)) {
val[i] = int64(fItem)
} else if mapItem, ok := item.(map[string]any); ok {
UseInts(mapItem)
}
}
}
}
}
Loading