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: Modularize mipsevm packages #11135

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Jul 11, 2024

Description

Refactor the mipsevm package to be more modular.

Basically, this PR creates a bunch of sub-packages for the various files that were previously in the mipsevm package. Generically, this is meant to help create a better separation of concerns, clarify dependencies, improve encapsulation, and make test utilities more reusable. It should also help keep the code legible as we add the new Multithreaded Cannon logic and avoid name conflicts and accidental imports.

Overview of the new package structure:

  • A new test_util package that holds test helpers extracted from the existing tests
  • A tests package to hold non-unit tests
    • This just helps remove some noise and make it clearer which files are production files
  • Move implementation-specific logic (original vs MT Cannon) to subpackages

Other changes:

  • Rename MTState to State (and similarly for related constants, variables, etc)
  • Replace some implementation-specific parameters (State) with the generic interface (FPVMState).

Notes for the reviewer:
There should be no functional changes in this PR. The changes here should mostly consist of package restructuring, visibility changes to some symbols, and shuffling some symbols between files.

Tests

This is a refactor, tests were just moved. One thing to highlight is that some tests in state_test.go were moved to instrumented_test.go to avoid circular dependencies (and because these tests were not really for state.go).

Metadata

Part of: #11642

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 79.38596% with 94 lines in your changes missing coverage. Please review.

Project coverage is 64.41%. Comparing base (f5221f4) to head (15e41f5).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11135      +/-   ##
===========================================
+ Coverage    62.58%   64.41%   +1.83%     
===========================================
  Files           21       27       +6     
  Lines         1935     2147     +212     
  Branches        71       71              
===========================================
+ Hits          1211     1383     +172     
- Misses         687      717      +30     
- Partials        37       47      +10     
Flag Coverage Δ
cannon-go-tests 80.33% <79.38%> (+0.12%) ⬆️
chain-mon-tests 27.14% <ø> (ø)
sdk-tests 16.44% <ø> (ø)

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

Files Coverage Δ
cannon/mipsevm/exec/mips_instructions.go 97.84% <100.00%> (ø)
cannon/mipsevm/exec/mips_syscalls.go 93.33% <100.00%> (ø)
cannon/mipsevm/memory/memory.go 82.89% <ø> (ø)
cannon/mipsevm/memory/page.go 66.21% <ø> (ø)
cannon/mipsevm/program/metadata.go 0.00% <ø> (ø)
cannon/mipsevm/singlethreaded/mips.go 69.52% <100.00%> (ø)
cannon/mipsevm/state.go 100.00% <100.00%> (+12.72%) ⬆️
cannon/mipsevm/testutil/elf.go 100.00% <100.00%> (ø)
cannon/mipsevm/witness.go 100.00% <ø> (ø)
cannon/mipsevm/program/patch.go 75.51% <75.00%> (ø)
... and 8 more

cannon/mipsevm/impls/single_threaded/state_test.go Outdated Show resolved Hide resolved
cannon/mipsevm/core/witness/witness.go Outdated Show resolved Hide resolved
cannon/mipsevm/core/iface.go Outdated Show resolved Hide resolved
cannon/mipsevm/instrumented_test.go Outdated Show resolved Hide resolved
@mbaxter mbaxter requested a review from Inphi July 12, 2024 22:33
@mbaxter mbaxter marked this pull request as ready for review July 12, 2024 22:33
@mbaxter mbaxter requested review from a team as code owners July 12, 2024 22:33
@mbaxter mbaxter requested a review from mslipper July 12, 2024 22:33
Copy link
Contributor

@Inphi Inphi left a comment

Choose a reason for hiding this comment

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

Consider flattening Go packages unless there are visibility concerns.
Specifically, the following files should be directly part of the core package rather than in subpackages:

  • core/witness/witness.go
  • core/oracle/oracle.go
  • core/state/state.go
  • core/debug/debug.go

This frees us identifier uses for debug, state, etc without introducing ambiguity.

Similarly, the impls package doesn't serve any purpose. We can have single_threaded and multi_threaded packages moved up.

cannon/mipsevm/test_util/constants.go Outdated Show resolved Hide resolved
cannon/mipsevm/instrumented_test.go Outdated Show resolved Hide resolved
@mbaxter
Copy link
Contributor Author

mbaxter commented Jul 16, 2024

Consider flattening Go packages unless there are visibility concerns.

Flattened those packages as you suggested, and went ahead and moved the core packages back out to the root mipsevm after reading through that article you posted. Still trying to wrap my head around idiomatic go and I think I went a little overboard once it kind of clicked that encapsulation only happens at the package level :D

@mbaxter mbaxter force-pushed the cp-903/offchain-mtcannon/refactor-mipsevm-pkgs branch from 77ead49 to e39f019 Compare July 17, 2024 21:12
Copy link
Contributor

@Inphi Inphi left a comment

Choose a reason for hiding this comment

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

Nice!

@Inphi Inphi requested a review from ajsutton July 17, 2024 23:35
@Inphi
Copy link
Contributor

Inphi commented Jul 17, 2024

Need a monorepo-ops-reviewer for approval. cc @ajsutton

@mbaxter mbaxter enabled auto-merge July 18, 2024 14:04
@mbaxter mbaxter added this pull request to the merge queue Jul 18, 2024
Merged via the queue into ethereum-optimism:develop with commit 4584c97 Jul 18, 2024
63 checks passed
@mbaxter mbaxter deleted the cp-903/offchain-mtcannon/refactor-mipsevm-pkgs branch July 18, 2024 14:25
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.

3 participants