Skip to content

Commit 04f39ad

Browse files
mslipperleopoldjoy
authored andcommitted
op-deployer: Add forge autodiscovery (ethereum-optimism#17152)
* op-deployer: Add forge autodiscovery * add limit reader * cr updates
1 parent 112bec7 commit 04f39ad

File tree

18 files changed

+572
-88
lines changed

18 files changed

+572
-88
lines changed

op-deployer/pkg/deployer/apply.go

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

10+
"github.com/ethereum-optimism/optimism/op-service/ioutil"
11+
1012
"github.com/ethereum-optimism/optimism/devnet-sdk/proofs/prestate"
1113
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
1214
"github.com/ethereum-optimism/optimism/op-chain-ops/script"
@@ -170,7 +172,7 @@ func ApplyPipeline(
170172
}
171173
st := opts.State
172174

173-
l1ArtifactsFS, err := artifacts.Download(ctx, intent.L1ContractsLocator, artifacts.BarProgressor(), opts.CacheDir)
175+
l1ArtifactsFS, err := artifacts.Download(ctx, intent.L1ContractsLocator, ioutil.BarProgressor(), opts.CacheDir)
174176
if err != nil {
175177
return fmt.Errorf("failed to download L1 artifacts: %w", err)
176178
}
@@ -179,7 +181,7 @@ func ApplyPipeline(
179181
if intent.L1ContractsLocator.Equal(intent.L2ContractsLocator) {
180182
l2ArtifactsFS = l1ArtifactsFS
181183
} else {
182-
l2Afs, err := artifacts.Download(ctx, intent.L2ContractsLocator, artifacts.BarProgressor(), opts.CacheDir)
184+
l2Afs, err := artifacts.Download(ctx, intent.L2ContractsLocator, ioutil.BarProgressor(), opts.CacheDir)
183185
if err != nil {
184186
return fmt.Errorf("failed to download L2 artifacts: %w", err)
185187
}

op-deployer/pkg/deployer/artifacts/download.go

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"crypto/sha256"
99
"errors"
1010
"fmt"
11-
"io"
1211
"io/fs"
13-
"net/http"
1412
"net/url"
1513
"os"
1614
"path"
1715
"sync"
1816

17+
"github.com/ethereum-optimism/optimism/op-service/httputil"
18+
1919
"github.com/ethereum-optimism/optimism/op-service/ioutil"
2020

2121
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
@@ -24,16 +24,16 @@ import (
2424
var ErrUnsupportedArtifactsScheme = errors.New("unsupported artifacts URL scheme")
2525

2626
type Downloader interface {
27-
Download(ctx context.Context, url string, progress DownloadProgressor, targetDir string) (string, error)
27+
Download(ctx context.Context, url string, progress ioutil.Progressor, targetDir string) (string, error)
2828
}
2929

3030
type Extractor interface {
3131
Extract(src string, dest string) (string, error)
3232
}
3333

34-
func Download(ctx context.Context, loc *Locator, progressor DownloadProgressor, targetDir string) (foundry.StatDirFs, error) {
34+
func Download(ctx context.Context, loc *Locator, progressor ioutil.Progressor, targetDir string) (foundry.StatDirFs, error) {
3535
if progressor == nil {
36-
progressor = NoopProgressor()
36+
progressor = ioutil.NoopProgressor()
3737
}
3838

3939
var err error
@@ -60,7 +60,7 @@ func Download(ctx context.Context, loc *Locator, progressor DownloadProgressor,
6060
return artifactsFS.(foundry.StatDirFs), nil
6161
}
6262

63-
func downloadHTTP(ctx context.Context, u *url.URL, progressor DownloadProgressor, checker integrityChecker, targetDir string) (fs.FS, error) {
63+
func downloadHTTP(ctx context.Context, u *url.URL, progressor ioutil.Progressor, checker integrityChecker, targetDir string) (fs.FS, error) {
6464
cacher := &CachingDownloader{
6565
d: new(HTTPDownloader),
6666
}
@@ -84,38 +84,20 @@ func downloadHTTP(ctx context.Context, u *url.URL, progressor DownloadProgressor
8484

8585
type HTTPDownloader struct{}
8686

87-
func (d *HTTPDownloader) Download(ctx context.Context, url string, progress DownloadProgressor, targetDir string) (string, error) {
88-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
89-
if err != nil {
90-
return "", fmt.Errorf("failed to create request: %w", err)
91-
}
92-
93-
res, err := http.DefaultClient.Do(req)
94-
if err != nil {
95-
return "", fmt.Errorf("failed to download artifacts: %w", err)
96-
}
97-
if res.StatusCode != http.StatusOK {
98-
return "", fmt.Errorf("failed to download artifacts: invalid status code %s", res.Status)
99-
}
100-
defer res.Body.Close()
101-
87+
func (d *HTTPDownloader) Download(ctx context.Context, url string, progress ioutil.Progressor, targetDir string) (string, error) {
10288
if err := os.MkdirAll(targetDir, 0755); err != nil {
10389
return "", fmt.Errorf("failed to ensure cache directory '%s': %w", targetDir, err)
10490
}
10591
tmpFile, err := os.CreateTemp(targetDir, "op-deployer-artifacts-*")
10692
if err != nil {
10793
return "", fmt.Errorf("failed to create temporary file: %w", err)
10894
}
109-
110-
pr := &progressReader{
111-
r: res.Body,
112-
progress: progress,
113-
total: res.ContentLength,
95+
downloader := &httputil.Downloader{
96+
Progressor: progress,
11497
}
115-
if _, err := io.Copy(tmpFile, pr); err != nil {
116-
return "", fmt.Errorf("failed to write to temporary file: %w", err)
98+
if err := downloader.Download(ctx, url, tmpFile); err != nil {
99+
return "", fmt.Errorf("failed to download: %w", err)
117100
}
118-
119101
return tmpFile.Name(), nil
120102
}
121103

@@ -124,7 +106,7 @@ type CachingDownloader struct {
124106
mtx sync.Mutex
125107
}
126108

127-
func (d *CachingDownloader) Download(ctx context.Context, url string, progress DownloadProgressor, targetDir string) (string, error) {
109+
func (d *CachingDownloader) Download(ctx context.Context, url string, progress ioutil.Progressor, targetDir string) (string, error) {
128110
d.mtx.Lock()
129111
defer d.mtx.Unlock()
130112

op-deployer/pkg/deployer/artifacts/progress.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

op-deployer/pkg/deployer/bootstrap/implementations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func Implementations(ctx context.Context, cfg ImplementationsConfig) (opcm.Deplo
144144

145145
lgr := cfg.Logger
146146

147-
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, artifacts.BarProgressor(), cfg.CacheDir)
147+
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, ioutil.BarProgressor(), cfg.CacheDir)
148148
if err != nil {
149149
return dio, fmt.Errorf("failed to download artifacts: %w", err)
150150
}

op-deployer/pkg/deployer/bootstrap/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func Proxy(ctx context.Context, cfg ProxyConfig) (opcm.DeployProxyOutput, error)
114114
}
115115

116116
lgr := cfg.Logger
117-
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, artifacts.BarProgressor(), cfg.CacheDir)
117+
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, ioutil.BarProgressor(), cfg.CacheDir)
118118
if err != nil {
119119
return dpo, fmt.Errorf("failed to download artifacts: %w", err)
120120
}

op-deployer/pkg/deployer/bootstrap/superchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func Superchain(ctx context.Context, cfg SuperchainConfig) (opcm.DeploySuperchai
151151

152152
lgr := cfg.Logger
153153
cacheDir := cfg.CacheDir
154-
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, artifacts.BarProgressor(), cacheDir)
154+
artifactsFS, err := artifacts.Download(ctx, cfg.ArtifactsLocator, ioutil.BarProgressor(), cacheDir)
155155
if err != nil {
156156
return dso, fmt.Errorf("failed to download artifacts: %w", err)
157157
}

0 commit comments

Comments
 (0)