-
Notifications
You must be signed in to change notification settings - Fork 3.9k
cannon: Multi VM executor #12072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
cannon: Multi VM executor #12072
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fb92952
cannon: Multi VM executor
Inphi 59f4717
fix run subcmd arg fwding
Inphi 277006d
fix mt prestate
Inphi 72112af
add list subcmd; multicannon in op-stack-go
Inphi 72bfe37
remove cannon-latest
Inphi f3b2b6e
safer strconv
Inphi 235b923
lint
Inphi 185d749
include .gitkeep in embed
Inphi a3c82d7
fix .git copy
Inphi 8cfbd32
add detect.go tests
Inphi b8d8ab1
add nosemgrep
Inphi 8ded99a
review comments
Inphi ad09710
list filtering
Inphi de8a581
add note to MIPS.sol in version stf ref
Inphi 3ed3ce2
use fork-exec
Inphi f48a561
minimal flag parsing
Inphi e8c1c32
load old cannon binaries from docker images
Inphi c726cde
note
Inphi a50b3d8
--help flag defaults
Inphi 77d6d37
remove redundant copy from cannon-builder-0
Inphi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) | ||
Inphi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.