Skip to content

Commit 93dd3b5

Browse files
authored
op-deployer: record opDeployerVersion in intent and state (#18333)
1 parent 5b96584 commit 93dd3b5

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

op-deployer/.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ builds:
2727
goarch: arm64
2828
mod_timestamp: "{{ .CommitTimestamp }}"
2929
ldflags:
30-
- -X main.GitCommit={{ .FullCommit }}
31-
- -X main.GitDate={{ .CommitDate }}
30+
- -X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.GitCommit={{ .FullCommit }}
31+
- -X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.GitDate={{ .CommitDate }}
3232
- -X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.Version={{ .Version }}
3333
- -X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.Meta=
3434

op-deployer/cmd/op-deployer/main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@ import (
66

77
"github.com/ethereum-optimism/optimism/op-deployer/pkg/cli"
88
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version"
9-
10-
opservice "github.com/ethereum-optimism/optimism/op-service"
11-
)
12-
13-
var (
14-
GitCommit = ""
15-
GitDate = ""
169
)
1710

18-
// VersionWithMeta holds the textual version string including the metadata.
19-
var VersionWithMeta = opservice.FormatVersion(version.Version, GitCommit, GitDate, version.Meta)
20-
2111
func main() {
22-
app := cli.NewApp(VersionWithMeta)
12+
app := cli.NewApp(version.VersionWithMeta)
2313
app.Writer = os.Stdout
2414
app.ErrWriter = os.Stderr
2515
err := app.Run(os.Args)

op-deployer/justfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ copy-contract-artifacts:
1919
--exclude="*.t.sol"
2020

2121
_LDFLAGSSTRING := "'" + trim(
22-
"-X main.GitCommit=" + GITCOMMIT + " " + \
23-
"-X main.GitDate=" + GITDATE + " " + \
24-
"-X main.Version=" + VERSION + " " + \
25-
"-X main.Meta=" + VERSION_META + " " + \
22+
"-X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.GitCommit=" + GITCOMMIT + " " + \
23+
"-X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.GitDate=" + GITDATE + " " + \
24+
"-X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.Version=" + VERSION + " " + \
25+
"-X github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version.Meta=" + VERSION_META + " " + \
2626
"") + "'"
2727

2828
build-go: (go_build "./bin/op-deployer" "./cmd/op-deployer" "-ldflags" _LDFLAGSSTRING)
2929

3030
docker-build: build-contracts copy-contract-artifacts
3131
#!/bin/bash
3232
cd ..
33+
export GIT_VERSION="untagged"
34+
export GIT_COMMIT=$(git rev-parse HEAD)
35+
export GIT_DATE=$(git show -s --format=%ct HEAD)
3336
docker buildx bake op-deployer --load --set op-deployer.tags=op-deployer:local
3437

3538
# Updates pkg/deployer/forge/version.json with version and checksum of tarball for each supported OS/arch

op-deployer/pkg/deployer/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
11+
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version"
1112

1213
op_service "github.com/ethereum-optimism/optimism/op-service"
1314

@@ -85,12 +86,13 @@ func Init(cfg InitConfig) error {
8586
}
8687

8788
st := &state.State{
88-
Version: 1,
89+
Version: 1,
90+
OpDeployerVersion: version.VersionWithMeta,
8991
}
9092

9193
stat, err := os.Stat(cfg.Outdir)
9294
if errors.Is(err, os.ErrNotExist) {
93-
if err := os.MkdirAll(cfg.Outdir, 0755); err != nil {
95+
if err := os.MkdirAll(cfg.Outdir, 0o755); err != nil {
9496
return fmt.Errorf("failed to create outdir: %w", err)
9597
}
9698
} else if err != nil {

op-deployer/pkg/deployer/state/intent.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ethereum-optimism/optimism/op-chain-ops/addresses"
1414
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
1515
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/standard"
16+
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/version"
1617
"github.com/ethereum-optimism/optimism/op-service/ioutil"
1718
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
1819
"github.com/ethereum-optimism/superchain-registry/validation"
@@ -26,8 +27,10 @@ const (
2627
IntentTypeStandardOverrides IntentType = "standard-overrides"
2728
)
2829

29-
var emptyAddress common.Address
30-
var emptyHash common.Hash
30+
var (
31+
emptyAddress common.Address
32+
emptyHash common.Hash
33+
)
3134

3235
type SuperchainProofParams struct {
3336
WithdrawalDelaySeconds uint64 `json:"faultGameWithdrawalDelay" toml:"faultGameWithdrawalDelay"`
@@ -81,6 +84,7 @@ type L1DevGenesisParams struct {
8184

8285
type Intent struct {
8386
ConfigType IntentType `json:"configType" toml:"configType"`
87+
OpDeployerVersion string `json:"opDeployerVersion" toml:"opDeployerVersion"`
8488
L1ChainID uint64 `json:"l1ChainID" toml:"l1ChainID"`
8589
OPCMAddress *common.Address `json:"opcmAddress" toml:"opcmAddress"`
8690
SuperchainConfigProxy *common.Address `json:"superchainConfigProxy" toml:"superchainConfigProxy"`
@@ -96,8 +100,10 @@ type Intent struct {
96100
L1DevGenesisParams *L1DevGenesisParams `json:"l1DevGenesisParams"`
97101
}
98102

99-
var ErrL1ContractsLocatorUndefined = errors.New("L1ContractsLocator undefined")
100-
var ErrL2ContractsLocatorUndefined = errors.New("L2ContractsLocator undefined")
103+
var (
104+
ErrL1ContractsLocatorUndefined = errors.New("L1ContractsLocator undefined")
105+
ErrL2ContractsLocatorUndefined = errors.New("L2ContractsLocator undefined")
106+
)
101107

102108
func (c *Intent) L1ChainIDBig() *big.Int {
103109
return big.NewInt(int64(c.L1ChainID))
@@ -305,6 +311,7 @@ func NewIntent(configType IntentType, l1ChainId uint64, l2ChainIds []common.Hash
305311
return
306312
}
307313
intent.ConfigType = configType
314+
intent.OpDeployerVersion = version.VersionWithMeta
308315
return
309316
}
310317

@@ -313,6 +320,7 @@ func NewIntent(configType IntentType, l1ChainId uint64, l2ChainIds []common.Hash
313320
func NewIntentCustom(l1ChainId uint64, l2ChainIds []common.Hash) (Intent, error) {
314321
intent := Intent{
315322
ConfigType: IntentTypeCustom,
323+
OpDeployerVersion: version.VersionWithMeta,
316324
L1ChainID: l1ChainId,
317325
L1ContractsLocator: &artifacts.Locator{URL: &url.URL{}},
318326
L2ContractsLocator: &artifacts.Locator{URL: &url.URL{}},
@@ -336,6 +344,7 @@ func NewIntentStandard(l1ChainId uint64, l2ChainIds []common.Hash) (Intent, erro
336344

337345
intent := Intent{
338346
ConfigType: IntentTypeStandard,
347+
OpDeployerVersion: version.VersionWithMeta,
339348
L1ChainID: l1ChainId,
340349
L1ContractsLocator: artifacts.DefaultL1ContractsLocator,
341350
L2ContractsLocator: artifacts.DefaultL2ContractsLocator,

op-deployer/pkg/deployer/state/state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type State struct {
2525
// Version versions the state so we can update it later.
2626
Version int `json:"version"`
2727

28+
// OpDeployerVersion is the version of op-deployer that was used to create the state
29+
OpDeployerVersion string `json:"opDeployerVersion"`
30+
2831
// Create2Salt is the salt used for CREATE2 deployments.
2932
Create2Salt common.Hash `json:"create2Salt"`
3033

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package version
22

3+
import opservice "github.com/ethereum-optimism/optimism/op-service"
4+
35
var (
4-
Version = "v0.0.0"
5-
Meta = "dev"
6+
GitCommit = ""
7+
GitDate = ""
8+
Version = "v0.0.0"
9+
Meta = "dev"
610
)
11+
12+
// VersionWithMeta holds the textual version string including the metadata.
13+
var VersionWithMeta = opservice.FormatVersion(Version, GitCommit, GitDate, Meta)

ops/docker/op-stack-go/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache
181181

182182
FROM --platform=$BUILDPLATFORM builder AS op-deployer-builder
183183
ARG OP_DEPLOYER_VERSION=v0.0.0
184-
185-
# Add forge
186184
COPY --from=builder_foundry /usr/local/bin/forge /usr/local/bin/forge
187-
188185
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build just \
189186
GOOS=$TARGETOS GOARCH=$TARGETARCH GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE VERSION="$OP_DEPLOYER_VERSION" \
190187
op-deployer/build-go

0 commit comments

Comments
 (0)