Skip to content

chore(specs): add final decorator#2934

Merged
danceratopz merged 1 commit into
ethereum:forks/amsterdamfrom
SamWilsn:final!
Jun 9, 2026
Merged

chore(specs): add final decorator#2934
danceratopz merged 1 commit into
ethereum:forks/amsterdamfrom
SamWilsn:final!

Conversation

@SamWilsn

Copy link
Copy Markdown
Contributor

🗒️ Description

mypyc can use the @final decorator for optimizations, so might as well add it.

Cute Animal Picture

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

@SamWilsn SamWilsn requested a review from Carsons-Eels May 28, 2026 16:54
@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.36997% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.52%. Comparing base (d7def91) to head (b503630).

Files with missing lines Patch % Lines
src/ethereum/trace.py 0.00% 10 Missing ⚠️
src/ethereum/merkle_patricia_trie.py 0.00% 4 Missing ⚠️
src/ethereum/state.py 0.00% 4 Missing ⚠️
src/ethereum/genesis.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           forks/amsterdam    #2934      +/-   ##
===================================================
+ Coverage            90.49%   90.52%   +0.02%     
===================================================
  Files                  535      535              
  Lines                32430    32712     +282     
  Branches              3012     3012              
===================================================
+ Hits                 29349    29613     +264     
- Misses                2563     2581      +18     
  Partials               518      518              
Flag Coverage Δ
unittests 90.52% <94.36%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danceratopz danceratopz self-assigned this Jun 9, 2026
@danceratopz danceratopz self-requested a review June 9, 2026 07:13

@danceratopz danceratopz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! I asked Claude if any classes were accidentally left out, but we're good to go.

I'm interested what you got cooking with mypyc and what the results are!

I added Claude's summary below on what which classes get the decorator and which classes are omitted (and why) as documentation.

What got @final

491 classes, all leaf @slotted_freezable @dataclass (or plain @dataclass) types, across all 24 fork directories plus 5 shared modules (crypto/blake2.py, genesis.py, merkle_patricia_trie.py, state.py, trace.py). The decorator is placed outermost (above @slotted_freezable / @dataclass), which is correct: slotted_freezable returns a freshly built class object, and since decorators apply bottom-up, the outermost @final marks that final object.

These data types are the ones that benefit: @dataclass generates __init__, __eq__, and __hash__, which are real calls in the codebase (equality, dict/set keys), and @final lets mypyc bypass the vtable and emit direct native calls for them.

What was omitted, and why it is correct

mypyc's @final optimization only bypasses the vtable for method calls and property accessors. A class with no methods or properties has nothing to devirtualize, so the following omissions cost nothing:

  • Leaf exception classes (OutOfGasError, StackUnderflowError, TransactionTypeError, etc.): pass bodies, no methods or properties, and never method-called in hot paths.
  • KZG scalar types in crypto/kzg.py (KZGCommitment, KZGProof, BLSFieldElement, VersionedHash): also pass bodies, nothing to optimize.
  • ForkCriteria subclasses in fork_criteria.py (ByBlockNumber, ByTimestamp, Unscheduled): these do have methods (check, __repr__), but they are invoked through the ForkCriteria base type (so devirtualization would not fire at the call sites) and only at fork-scheduling time, not a hot path.

These are also correct on the merits regardless of mypyc:

  • GasCosts: a plain namespace class carrying the comment "may be patched at runtime by a future gas repricing utility", so it is intentionally left mutable.
  • Ops and other Enum subclasses: enums with members cannot be subclassed anyway, so @final would be redundant.
  • PreState and EvmTracer: typing.Protocol subclasses, where @final would be semantically wrong since protocols are meant to be implemented.

Sources

@danceratopz danceratopz added A-spec-specs Area: Specification—The Ethereum specification itself (eg. `src/ethereum/*`) C-chore Category: chore labels Jun 9, 2026
@danceratopz danceratopz merged commit 9c2813e into ethereum:forks/amsterdam Jun 9, 2026
26 checks passed
@danceratopz

Copy link
Copy Markdown
Member

Hey @SamWilsn, I added a follow-up here:

@SamWilsn SamWilsn deleted the final! branch June 9, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-spec-specs Area: Specification—The Ethereum specification itself (eg. `src/ethereum/*`) C-chore Category: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants