Skip to content
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

cannon: Autodetect VM type from state #11803

Merged
merged 13 commits into from
Sep 10, 2024
Merged

Conversation

ajsutton
Copy link
Contributor

@ajsutton ajsutton commented Sep 9, 2024

Description

Modifies cannon to automatically detect the VM type from the supplied state.

  • The version byte in serialisation is now added by a new VersionedState struct which wraps the vm type specific state.
  • VersionedState returns an error when attempting to serialise a multithreaded state as JSON since JSON states are always assumed to be single threaded.
  • FPVMState now exposes a CreateVM method so it can create the appropriate VM (aka InstrumentedState) for the type of state. The run command uses this so its implementation is now completely agnostic to the type of state.
    • While it's a little bit odd to have the State create the VM, it actually fits the model of what we're doing much better given we do in fact want the state to determine what VM to use.
  • Modified the singlethreaded InitDebug to accept the metadata as an arg rather than requiring it in the InstrumentedState constructor so it matches the multithreaded version
  • Added an interface for Metadata to avoid introducing package cycles

Tests

Added unit tests for the new code that detects versions.

Metadata

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 68.35443% with 25 lines in your changes missing coverage. Please review.

Project coverage is 78.47%. Comparing base (f64d817) to head (1dd1668).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
cannon/mipsevm/versions/state.go 66.07% 14 Missing and 5 partials ⚠️
cannon/mipsevm/multithreaded/state.go 0.00% 3 Missing ⚠️
cannon/mipsevm/singlethreaded/state.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11803      +/-   ##
===========================================
+ Coverage    78.13%   78.47%   +0.34%     
===========================================
  Files           40       41       +1     
  Lines         3179     3206      +27     
===========================================
+ Hits          2484     2516      +32     
+ Misses         533      529       -4     
+ Partials       162      161       -1     
Flag Coverage Δ
cannon-go-tests 78.47% <68.35%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cannon/mipsevm/exec/stack.go 66.66% <100.00%> (ø)
cannon/mipsevm/multithreaded/instrumented.go 68.57% <100.00%> (+5.41%) ⬆️
cannon/mipsevm/multithreaded/stack.go 73.07% <100.00%> (ø)
cannon/mipsevm/program/metadata.go 53.84% <100.00%> (ø)
cannon/mipsevm/singlethreaded/instrumented.go 64.78% <100.00%> (+5.04%) ⬆️
cannon/mipsevm/tests/helpers.go 100.00% <100.00%> (ø)
cannon/serialize/binary.go 36.84% <100.00%> (ø)
cannon/serialize/detect.go 100.00% <100.00%> (ø)
cannon/mipsevm/multithreaded/state.go 56.45% <0.00%> (+1.33%) ⬆️
cannon/mipsevm/singlethreaded/state.go 55.39% <0.00%> (+1.58%) ⬆️
... and 1 more

@ajsutton ajsutton force-pushed the aj/cannon-autodetect-state-type branch from 83a6cfc to dd797d1 Compare September 9, 2024 03:58
@ajsutton ajsutton marked this pull request as ready for review September 9, 2024 04:13
@ajsutton ajsutton requested review from a team as code owners September 9, 2024 04:13
Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! Looks good - approving optimistically but I think the sleepCheck comment needs to be addressed.

cannon/mipsevm/singlethreaded/instrumented.go Outdated Show resolved Hide resolved
cannon/mipsevm/program/metadata.go Show resolved Hide resolved
cannon/mipsevm/versions/state_test.go Outdated Show resolved Hide resolved
@ajsutton ajsutton added this pull request to the merge queue Sep 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Sep 9, 2024
@ajsutton ajsutton force-pushed the aj/cannon-autodetect-state-type branch from 297e9c1 to 1dd1668 Compare September 9, 2024 23:51
@ajsutton ajsutton added this pull request to the merge queue Sep 10, 2024
Merged via the queue into develop with commit 2116126 Sep 10, 2024
62 checks passed
@ajsutton ajsutton deleted the aj/cannon-autodetect-state-type branch September 10, 2024 00:11
samlaf pushed a commit to samlaf/optimism that referenced this pull request Nov 10, 2024
* cannon: Autodetect VM type from state in run command

* cannon: Autodetect VM type from state in witness command

* cannon: Remove vm type flag from run and witness

* cannon: Only peek the version byte

* cannon: Move all version handling to VersionedState, simplify a lot and forbid serializing multithreaded states to JSON

* cannon: Rename method

* op-challenger: Update cannon state parsing to use version detecting methods

* cannon: Move CreateVM to FPVMState for simplicity

Test read/write/create for VersionedState

* cannon: Readd detect_test

* cannon: Remove json names from multithreaded.State.

Multithreaded states always use binary serialization.

* cannon: Move vmtype to load_elf since it is no longer shared.

* cannon: Ensure metadata is available and sleepCheck used even if debug is disabled.

* op-challenger: Update canon state loading test to cover multiple state versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

op-challenger: Integrate MT Cannon
2 participants