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

Refactor current VM computations to be message computations #2097

Merged
merged 4 commits into from
Apr 21, 2023

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Apr 18, 2023

What was wrong?

Related to Issue #2089

Computations currently require a message and a transaction context. This is because, up until EOF, computations were built from a message with transaction-like fields. This PR opens support for computations that do not come from messages. One such example will be an EOF computation which is built from instructions in the bytecode of a message computation.

How was it fixed?

To make way for the above changes, the BaseComputation class is refactored in this PR to be more basic. It strips out the the idea that all computations rely on a message. This is now a property of the MessageComputation class that we are more familiar with, which is still configured as part of all VMs at present, and inherits from and builds upon the BaseComputation.

This PR does not attempt to add any new computation classes. It is simply paving the way for them by splitting the current BaseComputation class into these two classes.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@fselmo fselmo force-pushed the refactor-computation-class branch 3 times, most recently from c762500 to bf7f3aa Compare April 19, 2023 16:33
…utation``:

- The current implementation of the computation classes (and the base computation class) will become stale when EOF is introduced because it always assumes a "message" which has transaction fields. We should refactor the actual base computation class to have only the inherent properties of base computations.

- The ``MessageComputation`` class then inherits from a simpler, stripped-down ``BaseComputation`` class. Existing VM computation classes are now ``MessageComputation`` classes since they inherently require a ``message`` and ``transaction_context`` starting at the ``__init__()`` method and stretching across some of its methods and properties.

- This hierarchy paves the way for EOF computations, and possibly other computations, to exist within a more flexible model. EOF computations are likely to be properties of message computations since an EOF computation cannot be executed without a message / transaction.
@fselmo fselmo force-pushed the refactor-computation-class branch 3 times, most recently from f2a916e to c640856 Compare April 19, 2023 20:43
- Define computation children in the ``BaseComputation`` class and narrow the type as needed for subclasses - e.g. for ``MessageComputation`` narrow the children to be ``MessageComputationAPI``.
- Some minor cleanup along the way.
- Add newsfragment
@fselmo fselmo force-pushed the refactor-computation-class branch from c640856 to c7bc4cf Compare April 19, 2023 20:48
@fselmo fselmo marked this pull request as ready for review April 19, 2023 20:48
@fselmo fselmo requested review from kclowes and pacrob April 19, 2023 20:48
fselmo added a commit to fselmo/py-evm that referenced this pull request Apr 20, 2023
Copy link
Collaborator

@pacrob pacrob left a comment

Choose a reason for hiding this comment

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

lgtm!

@fselmo fselmo force-pushed the refactor-computation-class branch from fc27ebb to 0c30193 Compare April 20, 2023 23:16
Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

LGTM! Just had a couple small comments.

docs/release_notes.rst Outdated Show resolved Hide resolved
C = TypeVar("C", bound="ComputationAPI")


class BaseComputation(ComputationAPI, Configurable, Generic[C]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This changes the MRO from the old Computation class. Is that intentional?

Copy link
Collaborator Author

@fselmo fselmo Apr 21, 2023

Choose a reason for hiding this comment

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

Do you mean since Configurable and ComputationAPI were swapped in order? I don't think it matters much (since there are breaking changes here already) but I can restore the order. I was going for API (abstract class) -> inherited non-abstract class -> and then the generic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to merge this since it was mostly approved and this seems like a smaller change. I'd like to be able to start rebasing the EOF PR from these changes. I can address some more computation refactoring in the that PR as well. Happy to move this conversation over there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mean since Configurable and ComputationAPI were swapped in order?

Yep, that's what I was looking at. I was more worried about it just being a copy/pasta rather than a breaking change for users. I didn't look into it too much, so if it doesn't matter this seems fine to me!

@fselmo fselmo merged commit fb4bb48 into ethereum:master Apr 21, 2023
@fselmo fselmo mentioned this pull request May 3, 2023
3 tasks
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