Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
37c44291
Unverified
Commit
37c44291
authored
Jan 13, 2025
by
Yann Hodique
Committed by
GitHub
Jan 13, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(kurtosis-devnet): ensure localPrestate is idempotent (#13725)
parent
86632e48
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
71 deletions
+126
-71
main.go
kurtosis-devnet/cmd/main.go
+95
-68
main_test.go
kurtosis-devnet/cmd/main_test.go
+31
-3
No files found.
kurtosis-devnet/cmd/main.go
View file @
37c44291
...
@@ -110,18 +110,36 @@ type PrestateInfo struct {
...
@@ -110,18 +110,36 @@ type PrestateInfo struct {
Hashes
map
[
string
]
string
`json:"hashes"`
Hashes
map
[
string
]
string
`json:"hashes"`
}
}
func
(
m
*
Main
)
localPrestateOption
(
dir
string
)
tmpl
.
TemplateContextOptions
{
type
localPrestateHolder
struct
{
prestateBuilder
:=
build
.
NewPrestateBuilder
(
info
*
PrestateInfo
build
.
WithPrestateBaseDir
(
m
.
cfg
.
baseDir
),
baseDir
string
build
.
WithPrestateDryRun
(
m
.
cfg
.
dryRun
),
buildDir
string
)
dryRun
bool
builder
*
build
.
PrestateBuilder
}
func
newLocalPrestateHolder
(
baseDir
string
,
buildDir
string
,
dryRun
bool
)
*
localPrestateHolder
{
return
&
localPrestateHolder
{
baseDir
:
baseDir
,
buildDir
:
buildDir
,
dryRun
:
dryRun
,
builder
:
build
.
NewPrestateBuilder
(
build
.
WithPrestateBaseDir
(
baseDir
),
build
.
WithPrestateDryRun
(
dryRun
),
),
}
}
func
(
h
*
localPrestateHolder
)
GetPrestateInfo
()
(
*
PrestateInfo
,
error
)
{
if
h
.
info
!=
nil
{
return
h
.
info
,
nil
}
return
tmpl
.
WithFunction
(
"localPrestate"
,
func
()
(
*
PrestateInfo
,
error
)
{
prestatePath
:=
[]
string
{
"proofs"
,
"op-program"
,
"cannon"
}
prestatePath
:=
[]
string
{
"proofs"
,
"op-program"
,
"cannon"
}
prestateURL
:=
fileserverURL
(
prestatePath
...
)
prestateURL
:=
fileserverURL
(
prestatePath
...
)
// Create build directory with the final path structure
// Create build directory with the final path structure
buildDir
:=
filepath
.
Join
(
append
([]
string
{
d
ir
},
prestatePath
...
)
...
)
buildDir
:=
filepath
.
Join
(
append
([]
string
{
h
.
buildD
ir
},
prestatePath
...
)
...
)
if
err
:=
os
.
MkdirAll
(
buildDir
,
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
buildDir
,
0755
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to create prestate build directory: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to create prestate build directory: %w"
,
err
)
}
}
...
@@ -131,7 +149,8 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
...
@@ -131,7 +149,8 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
Hashes
:
make
(
map
[
string
]
string
),
Hashes
:
make
(
map
[
string
]
string
),
}
}
if
m
.
cfg
.
dryRun
{
if
h
.
dryRun
{
h
.
info
=
info
return
info
,
nil
return
info
,
nil
}
}
...
@@ -143,7 +162,7 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
...
@@ -143,7 +162,7 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
}
}
// Build all prestate files directly in the target directory
// Build all prestate files directly in the target directory
if
err
:=
prestateB
uilder
.
Build
(
buildDir
);
err
!=
nil
{
if
err
:=
h
.
b
uilder
.
Build
(
buildDir
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to build prestates: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to build prestates: %w"
,
err
)
}
}
...
@@ -190,7 +209,15 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
...
@@ -190,7 +209,15 @@ func (m *Main) localPrestateOption(dir string) tmpl.TemplateContextOptions {
log
.
Printf
(
"%s available at: %s/%s
\n
"
,
filepath
.
Base
(
binFilePath
),
prestateURL
,
newBinFileName
)
log
.
Printf
(
"%s available at: %s/%s
\n
"
,
filepath
.
Base
(
binFilePath
),
prestateURL
,
newBinFileName
)
}
}
h
.
info
=
info
return
info
,
nil
return
info
,
nil
}
func
(
m
*
Main
)
localPrestateOption
(
dir
string
)
tmpl
.
TemplateContextOptions
{
holder
:=
newLocalPrestateHolder
(
m
.
cfg
.
baseDir
,
dir
,
m
.
cfg
.
dryRun
)
return
tmpl
.
WithFunction
(
"localPrestate"
,
func
()
(
*
PrestateInfo
,
error
)
{
return
holder
.
GetPrestateInfo
()
})
})
}
}
...
...
kurtosis-devnet/cmd/main_test.go
View file @
37c44291
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
)
)
type
mockDeployer
struct
{
type
mockDeployer
struct
{
...
@@ -290,8 +291,17 @@ _prestate-build target:
...
@@ -290,8 +291,17 @@ _prestate-build target:
// Create template context with just the prestate function
// Create template context with just the prestate function
tmplCtx
:=
tmpl
.
NewTemplateContext
(
m
.
localPrestateOption
(
tmpDir
))
tmplCtx
:=
tmpl
.
NewTemplateContext
(
m
.
localPrestateOption
(
tmpDir
))
// Test template
// Test template with multiple calls to localPrestate
template
:=
`prestate_url: {{(localPrestate).URL}}`
template
:=
`first:
url: {{(localPrestate).URL}}
hashes:
game: {{index (localPrestate).Hashes "game"}}
proof: {{index (localPrestate).Hashes "proof"}}
second:
url: {{(localPrestate).URL}}
hashes:
game: {{index (localPrestate).Hashes "game"}}
proof: {{index (localPrestate).Hashes "proof"}}`
buf
:=
bytes
.
NewBuffer
(
nil
)
buf
:=
bytes
.
NewBuffer
(
nil
)
err
=
tmplCtx
.
InstantiateTemplate
(
bytes
.
NewBufferString
(
template
),
buf
)
err
=
tmplCtx
.
InstantiateTemplate
(
bytes
.
NewBufferString
(
template
),
buf
)
...
@@ -305,7 +315,25 @@ _prestate-build target:
...
@@ -305,7 +315,25 @@ _prestate-build target:
output
:=
buf
.
String
()
output
:=
buf
.
String
()
assert
.
Contains
(
t
,
output
,
"url: http://fileserver/proofs/op-program/cannon"
)
assert
.
Contains
(
t
,
output
,
"url: http://fileserver/proofs/op-program/cannon"
)
// Verify the directory was created
// Verify both calls return the same values
var
result
struct
{
First
struct
{
URL
string
`yaml:"url"`
Hashes
map
[
string
]
string
`yaml:"hashes"`
}
`yaml:"first"`
Second
struct
{
URL
string
`yaml:"url"`
Hashes
map
[
string
]
string
`yaml:"hashes"`
}
`yaml:"second"`
}
err
=
yaml
.
Unmarshal
(
buf
.
Bytes
(),
&
result
)
require
.
NoError
(
t
,
err
)
// Check that both calls returned identical results
assert
.
Equal
(
t
,
result
.
First
.
URL
,
result
.
Second
.
URL
,
"URLs should match"
)
assert
.
Equal
(
t
,
result
.
First
.
Hashes
,
result
.
Second
.
Hashes
,
"Hashes should match"
)
// Verify the directory was created only once
prestateDir
:=
filepath
.
Join
(
tmpDir
,
"proofs"
,
"op-program"
,
"cannon"
)
prestateDir
:=
filepath
.
Join
(
tmpDir
,
"proofs"
,
"op-program"
,
"cannon"
)
assert
.
DirExists
(
t
,
prestateDir
)
assert
.
DirExists
(
t
,
prestateDir
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment