Skip to content

Commit 0a46b14

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into sc/asr-single-root
2 parents a622ff3 + 2fb8c66 commit 0a46b14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2248
-1195
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8
2626
github.com/hashicorp/go-multierror v1.1.1
2727
github.com/hashicorp/golang-lru/v2 v2.0.7
28-
github.com/hashicorp/raft v1.7.1
28+
github.com/hashicorp/raft v1.7.2
2929
github.com/hashicorp/raft-boltdb/v2 v2.3.0
3030
github.com/holiman/uint256 v1.3.2
3131
github.com/ipfs/go-datastore v0.6.0
@@ -36,7 +36,7 @@ require (
3636
github.com/libp2p/go-libp2p-mplex v0.9.0
3737
github.com/libp2p/go-libp2p-pubsub v0.12.0
3838
github.com/libp2p/go-libp2p-testing v0.12.0
39-
github.com/lmittmann/w3 v0.17.3
39+
github.com/lmittmann/w3 v0.17.4
4040
github.com/mattn/go-isatty v0.0.20
4141
github.com/minio/minio-go/v7 v7.0.81
4242
github.com/multiformats/go-base32 v0.1.0
@@ -124,6 +124,7 @@ require (
124124
github.com/hashicorp/go-bexpr v0.1.11 // indirect
125125
github.com/hashicorp/go-hclog v1.6.2 // indirect
126126
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
127+
github.com/hashicorp/go-metrics v0.5.4 // indirect
127128
github.com/hashicorp/go-msgpack/v2 v2.1.2 // indirect
128129
github.com/hashicorp/golang-lru v0.5.0 // indirect
129130
github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect

go.sum

Lines changed: 30 additions & 4 deletions
Large diffs are not rendered by default.

kurtosis-devnet/cmd/main.go

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,25 @@ import (
1414
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/build"
1515
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
1616
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/engine"
17-
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/backend"
1817
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
19-
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/serve"
2018
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/tmpl"
2119
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/util"
2220
"github.com/urfave/cli/v2"
2321
)
2422

2523
const FILESERVER_PACKAGE = "fileserver"
2624

25+
func fileserverURL(path ...string) string {
26+
return fmt.Sprintf("http://%s/%s", FILESERVER_PACKAGE, strings.Join(path, "/"))
27+
}
28+
2729
type config struct {
2830
templateFile string
2931
dataFile string
3032
kurtosisPackage string
3133
enclave string
3234
environment string
3335
dryRun bool
34-
localHostName string
3536
baseDir string
3637
kurtosisBinary string
3738
}
@@ -44,7 +45,6 @@ func newConfig(c *cli.Context) (*config, error) {
4445
enclave: c.String("enclave"),
4546
environment: c.String("environment"),
4647
dryRun: c.Bool("dry-run"),
47-
localHostName: c.String("local-hostname"),
4848
kurtosisBinary: c.String("kurtosis-binary"),
4949
}
5050

@@ -57,11 +57,6 @@ func newConfig(c *cli.Context) (*config, error) {
5757
return cfg, nil
5858
}
5959

60-
type staticServer struct {
61-
dir string
62-
*serve.Server
63-
}
64-
6560
type engineManager interface {
6661
EnsureRunning() error
6762
}
@@ -72,34 +67,6 @@ type Main struct {
7267
engineManager engineManager
7368
}
7469

75-
func (m *Main) launchStaticServer(ctx context.Context) (*staticServer, func(), error) {
76-
// we will serve content from this tmpDir for the duration of the devnet creation
77-
tmpDir, err := os.MkdirTemp("", m.cfg.enclave)
78-
if err != nil {
79-
return nil, nil, fmt.Errorf("error creating temporary directory: %w", err)
80-
}
81-
82-
server := serve.NewServer(
83-
serve.WithStaticDir(tmpDir),
84-
serve.WithHostname(m.cfg.localHostName),
85-
)
86-
if err := server.Start(ctx); err != nil {
87-
return nil, nil, fmt.Errorf("error starting server: %w", err)
88-
}
89-
90-
return &staticServer{
91-
dir: tmpDir,
92-
Server: server,
93-
}, func() {
94-
if err := server.Stop(ctx); err != nil {
95-
log.Printf("Error stopping server: %v\n", err)
96-
}
97-
if err := os.RemoveAll(tmpDir); err != nil {
98-
log.Printf("Error removing temporary directory: %v\n", err)
99-
}
100-
}, nil
101-
}
102-
10370
func (m *Main) localDockerImageOption() tmpl.TemplateContextOptions {
10471
dockerBuilder := build.NewDockerBuilder(
10572
build.WithDockerBaseDir(m.cfg.baseDir),
@@ -115,11 +82,12 @@ func (m *Main) localDockerImageOption() tmpl.TemplateContextOptions {
11582
})
11683
}
11784

118-
func (m *Main) localContractArtifactsOption(server *staticServer) tmpl.TemplateContextOptions {
85+
func (m *Main) localContractArtifactsOption(dir string) tmpl.TemplateContextOptions {
11986
contractsBundle := fmt.Sprintf("contracts-bundle-%s.tar.gz", m.cfg.enclave)
12087
contractsBundlePath := func(_ string) string {
121-
return filepath.Join(server.dir, contractsBundle)
88+
return filepath.Join(dir, contractsBundle)
12289
}
90+
contractsURL := fileserverURL(contractsBundle)
12391

12492
contractBuilder := build.NewContractBuilder(
12593
build.WithContractBaseDir(m.cfg.baseDir),
@@ -128,18 +96,12 @@ func (m *Main) localContractArtifactsOption(server *staticServer) tmpl.TemplateC
12896

12997
return tmpl.WithFunction("localContractArtifacts", func(layer string) (string, error) {
13098
bundlePath := contractsBundlePath(layer)
131-
// we're in a temp dir, so we can skip the build if the file already
132-
// exists: it'll be the same file! In particular, since we're ignoring
133-
// layer for now, skip the 2nd build.
134-
if _, err := os.Stat(bundlePath); err != nil {
135-
if err := contractBuilder.Build(layer, bundlePath); err != nil {
136-
return "", err
137-
}
99+
if err := contractBuilder.Build(layer, bundlePath); err != nil {
100+
return "", err
138101
}
139102

140-
url := fmt.Sprintf("%s/%s", server.URL(), contractsBundle)
141-
log.Printf("%s: contract artifacts available at: %s\n", layer, url)
142-
return url, nil
103+
log.Printf("%s: contract artifacts available at: %s\n", layer, contractsURL)
104+
return contractsURL, nil
143105
})
144106
}
145107

@@ -148,27 +110,24 @@ type PrestateInfo struct {
148110
Hashes map[string]string `json:"hashes"`
149111
}
150112

151-
func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOptions {
113+
func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
152114
prestateBuilder := build.NewPrestateBuilder(
153115
build.WithPrestateBaseDir(m.cfg.baseDir),
154116
build.WithPrestateDryRun(m.cfg.dryRun),
155117
)
156118

157119
return tmpl.WithFunction("localPrestate", func() (*PrestateInfo, error) {
120+
prestatePath := []string{"proofs", "op-program", "cannon"}
121+
prestateURL := fileserverURL(prestatePath...)
122+
158123
// Create build directory with the final path structure
159-
buildDir := filepath.Join(server.dir, "proofs", "op-program", "cannon")
124+
buildDir := filepath.Join(append([]string{dir}, prestatePath...)...)
160125
if err := os.MkdirAll(buildDir, 0755); err != nil {
161126
return nil, fmt.Errorf("failed to create prestate build directory: %w", err)
162127
}
163128

164-
// Get the relative path from server.dir to buildDir for the URL
165-
relPath, err := filepath.Rel(server.dir, buildDir)
166-
if err != nil {
167-
return nil, fmt.Errorf("failed to get relative path: %w", err)
168-
}
169-
170129
info := &PrestateInfo{
171-
URL: fmt.Sprintf("%s/%s", server.URL(), relPath),
130+
URL: prestateURL,
172131
Hashes: make(map[string]string),
173132
}
174133

@@ -219,7 +178,7 @@ func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOpt
219178
if err := os.Rename(filePath, hashedPath); err != nil {
220179
return nil, fmt.Errorf("failed to rename prestate %s: %w", filepath.Base(filePath), err)
221180
}
222-
log.Printf("%s available at: %s/%s/%s\n", filepath.Base(filePath), server.URL(), relPath, newFileName)
181+
log.Printf("%s available at: %s/%s\n", filepath.Base(filePath), prestateURL, newFileName)
223182

224183
// Rename the corresponding binary file
225184
binFilePath := strings.Replace(strings.TrimSuffix(filePath, ".json"), "-proof", "", 1) + ".bin.gz"
@@ -228,18 +187,18 @@ func (m *Main) localPrestateOption(server *staticServer) tmpl.TemplateContextOpt
228187
if err := os.Rename(binFilePath, binHashedPath); err != nil {
229188
return nil, fmt.Errorf("failed to rename prestate %s: %w", filepath.Base(binFilePath), err)
230189
}
231-
log.Printf("%s available at: %s/%s/%s\n", filepath.Base(binFilePath), server.URL(), relPath, newBinFileName)
190+
log.Printf("%s available at: %s/%s\n", filepath.Base(binFilePath), prestateURL, newBinFileName)
232191
}
233192

234193
return info, nil
235194
})
236195
}
237196

238-
func (m *Main) renderTemplate(server *staticServer) (*bytes.Buffer, error) {
197+
func (m *Main) renderTemplate(dir string) (*bytes.Buffer, error) {
239198
opts := []tmpl.TemplateContextOptions{
240199
m.localDockerImageOption(),
241-
m.localContractArtifactsOption(server),
242-
m.localPrestateOption(server),
200+
m.localContractArtifactsOption(dir),
201+
m.localPrestateOption(dir),
243202
}
244203

245204
// Read and parse the data file if provided
@@ -391,19 +350,19 @@ func (m *Main) run() error {
391350
}
392351
}
393352

394-
server, cleanup, err := m.launchStaticServer(ctx)
353+
tmpDir, err := os.MkdirTemp("", m.cfg.enclave)
395354
if err != nil {
396-
return fmt.Errorf("error launching static server: %w", err)
355+
return fmt.Errorf("error creating temporary directory: %w", err)
397356
}
398-
defer cleanup()
357+
defer os.RemoveAll(tmpDir)
399358

400-
buf, err := m.renderTemplate(server)
359+
buf, err := m.renderTemplate(tmpDir)
401360
if err != nil {
402361
return fmt.Errorf("error rendering template: %w", err)
403362
}
404363

405364
// TODO: clean up consumers of static server and replace with fileserver
406-
err = m.deployFileserver(ctx, server.dir)
365+
err = m.deployFileserver(ctx, tmpDir)
407366
if err != nil {
408367
return fmt.Errorf("error deploying fileserver: %w", err)
409368
}
@@ -455,11 +414,6 @@ func getFlags() []cli.Flag {
455414
Name: "dry-run",
456415
Usage: "Dry run mode (optional)",
457416
},
458-
&cli.StringFlag{
459-
Name: "local-hostname",
460-
Usage: "DNS for localhost from Kurtosis perspective (optional)",
461-
Value: backend.DefaultDockerHost(),
462-
},
463417
&cli.StringFlag{
464418
Name: "kurtosis-binary",
465419
Usage: "Path to kurtosis binary (optional)",

kurtosis-devnet/cmd/main_test.go

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ func TestParseFlags(t *testing.T) {
6161
args: []string{
6262
"--template", "path/to/template.yaml",
6363
"--enclave", "test-enclave",
64-
"--local-hostname", "test.local",
6564
},
6665
wantCfg: &config{
6766
templateFile: "path/to/template.yaml",
6867
enclave: "test-enclave",
69-
localHostName: "test.local",
7068
kurtosisPackage: kurtosis.DefaultPackageName,
7169
},
7270
wantError: false,
@@ -86,7 +84,6 @@ func TestParseFlags(t *testing.T) {
8684
wantCfg: &config{
8785
templateFile: "path/to/template.yaml",
8886
dataFile: "path/to/data.json",
89-
localHostName: "host.docker.internal",
9087
enclave: kurtosis.DefaultEnclave,
9188
kurtosisPackage: kurtosis.DefaultPackageName,
9289
},
@@ -118,7 +115,6 @@ func TestParseFlags(t *testing.T) {
118115
require.NotNil(t, cfg)
119116
assert.Equal(t, tt.wantCfg.templateFile, cfg.templateFile)
120117
assert.Equal(t, tt.wantCfg.enclave, cfg.enclave)
121-
assert.Equal(t, tt.wantCfg.localHostName, cfg.localHostName)
122118
assert.Equal(t, tt.wantCfg.kurtosisPackage, cfg.kurtosisPackage)
123119
if tt.wantCfg.dataFile != "" {
124120
assert.Equal(t, tt.wantCfg.dataFile, cfg.dataFile)
@@ -127,27 +123,6 @@ func TestParseFlags(t *testing.T) {
127123
}
128124
}
129125

130-
func TestLaunchStaticServer(t *testing.T) {
131-
cfg := &config{
132-
localHostName: "test.local",
133-
}
134-
135-
m := newTestMain(cfg)
136-
ctx := context.Background()
137-
server, cleanup, err := m.launchStaticServer(ctx)
138-
require.NoError(t, err)
139-
defer cleanup()
140-
141-
// Verify server properties
142-
assert.NotEmpty(t, server.dir)
143-
assert.DirExists(t, server.dir)
144-
assert.NotNil(t, server.Server)
145-
146-
// Verify cleanup works
147-
cleanup()
148-
assert.NoDirExists(t, server.dir)
149-
}
150-
151126
func TestRenderTemplate(t *testing.T) {
152127
// Create a temporary directory for test files
153128
tmpDir, err := os.MkdirTemp("", "template-test")
@@ -178,18 +153,13 @@ artifacts: {{localContractArtifacts "l1"}}`
178153
}
179154

180155
m := newTestMain(cfg)
181-
ctx := context.Background()
182-
server, cleanup, err := m.launchStaticServer(ctx)
183-
require.NoError(t, err)
184-
defer cleanup()
185156

186-
buf, err := m.renderTemplate(server)
157+
buf, err := m.renderTemplate(tmpDir)
187158
require.NoError(t, err)
188159

189160
// Verify template rendering
190161
assert.Contains(t, buf.String(), "test-deployment")
191162
assert.Contains(t, buf.String(), "test-project:test-enclave")
192-
assert.Contains(t, buf.String(), server.URL())
193163
}
194164

195165
func TestDeploy(t *testing.T) {
@@ -312,16 +282,16 @@ _prestate-build target:
312282
}
313283

314284
m := newTestMain(cfg)
315-
ctx := context.Background()
316-
server, cleanup, err := m.launchStaticServer(ctx)
285+
286+
tmpDir, err := os.MkdirTemp("", "prestate-test")
317287
require.NoError(t, err)
318-
defer cleanup()
288+
defer os.RemoveAll(tmpDir)
319289

320290
// Create template context with just the prestate function
321-
tmplCtx := tmpl.NewTemplateContext(m.localPrestateOption(server))
291+
tmplCtx := tmpl.NewTemplateContext(m.localPrestateOption(tmpDir))
322292

323293
// Test template
324-
template := `{"prestate": "{{localPrestate}}"}`
294+
template := `prestate_url: {{(localPrestate).URL}}`
325295
buf := bytes.NewBuffer(nil)
326296
err = tmplCtx.InstantiateTemplate(bytes.NewBufferString(template), buf)
327297

@@ -331,19 +301,12 @@ _prestate-build target:
331301
}
332302
require.NoError(t, err)
333303

334-
// Parse the output
335-
var output struct {
336-
Prestate string `json:"prestate"`
337-
}
338-
err = json.Unmarshal(buf.Bytes(), &output)
339-
require.NoError(t, err)
340-
341-
// Verify the URL structure
342-
assert.Contains(t, output.Prestate, server.URL())
343-
assert.Contains(t, output.Prestate, "/proofs/op-program/cannon")
304+
// Verify the output is valid YAML and contains the static path
305+
output := buf.String()
306+
assert.Contains(t, output, "url: http://fileserver/proofs/op-program/cannon")
344307

345308
// Verify the directory was created
346-
prestateDir := filepath.Join(server.dir, "proofs", "op-program", "cannon")
309+
prestateDir := filepath.Join(tmpDir, "proofs", "op-program", "cannon")
347310
assert.DirExists(t, prestateDir)
348311
})
349312
}

0 commit comments

Comments
 (0)