forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cannon: Multi VM executor (ethereum-optimism#12072)
* cannon: Multi VM executor * fix run subcmd arg fwding * fix mt prestate * add list subcmd; multicannon in op-stack-go * remove cannon-latest * safer strconv * lint * include .gitkeep in embed * fix .git copy * add detect.go tests * add nosemgrep * review comments * list filtering * add note to MIPS.sol in version stf ref * use fork-exec * minimal flag parsing * load old cannon binaries from docker images * note * --help flag defaults * remove redundant copy from cannon-builder-0
- Loading branch information
Showing
21 changed files
with
618 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ state.json | |
*.pprof | ||
*.out | ||
bin | ||
multicannon/embeds/cannon* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package versions | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/ethereum-optimism/optimism/cannon/serialize" | ||
"github.com/ethereum-optimism/optimism/op-service/ioutil" | ||
) | ||
|
||
func DetectVersion(path string) (StateVersion, error) { | ||
if !serialize.IsBinaryFile(path) { | ||
return VersionSingleThreaded, nil | ||
} | ||
|
||
var f io.ReadCloser | ||
f, err := ioutil.OpenDecompressed(path) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to open file %q: %w", path, err) | ||
} | ||
defer f.Close() | ||
|
||
var ver StateVersion | ||
bin := serialize.NewBinaryReader(f) | ||
if err := bin.ReadUInt(&ver); err != nil { | ||
return 0, err | ||
} | ||
|
||
switch ver { | ||
case VersionSingleThreaded, VersionMultiThreaded: | ||
return ver, nil | ||
default: | ||
return 0, fmt.Errorf("%w: %d", ErrUnknownVersion, ver) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package versions | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimism/cannon/mipsevm/multithreaded" | ||
"github.com/ethereum-optimism/optimism/cannon/mipsevm/singlethreaded" | ||
"github.com/ethereum-optimism/optimism/op-service/ioutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetectVersion(t *testing.T) { | ||
t.Run("SingleThreadedJSON", func(t *testing.T) { | ||
state, err := NewFromState(singlethreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
path := writeToFile(t, "state.json", state) | ||
version, err := DetectVersion(path) | ||
require.NoError(t, err) | ||
require.Equal(t, VersionSingleThreaded, version) | ||
}) | ||
|
||
t.Run("SingleThreadedBinary", func(t *testing.T) { | ||
state, err := NewFromState(singlethreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
path := writeToFile(t, "state.bin.gz", state) | ||
version, err := DetectVersion(path) | ||
require.NoError(t, err) | ||
require.Equal(t, VersionSingleThreaded, version) | ||
}) | ||
|
||
t.Run("MultiThreadedBinary", func(t *testing.T) { | ||
state, err := NewFromState(multithreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
path := writeToFile(t, "state.bin.gz", state) | ||
version, err := DetectVersion(path) | ||
require.NoError(t, err) | ||
require.Equal(t, VersionMultiThreaded, version) | ||
}) | ||
} | ||
|
||
func TestDetectVersionInvalid(t *testing.T) { | ||
t.Run("bad gzip", func(t *testing.T) { | ||
dir := t.TempDir() | ||
filename := "state.bin.gz" | ||
path := filepath.Join(dir, filename) | ||
require.NoError(t, os.WriteFile(path, []byte("ekans"), 0o644)) | ||
|
||
_, err := DetectVersion(path) | ||
require.ErrorContains(t, err, "failed to open file") | ||
}) | ||
|
||
t.Run("unknown version", func(t *testing.T) { | ||
dir := t.TempDir() | ||
filename := "state.bin.gz" | ||
path := filepath.Join(dir, filename) | ||
const badVersion = 0xFF | ||
err := ioutil.WriteCompressedBytes(path, []byte{badVersion}, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644) | ||
require.NoError(t, err) | ||
|
||
_, err = DetectVersion(path) | ||
require.ErrorIs(t, err, ErrUnknownVersion) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.