fix(evm_tools): avoid cloning unchanged fork template in ForkCache#2738
Conversation
SamWilsn
left a comment
There was a problem hiding this comment.
How does this affect test runs? Worthwhile speedup I assume?
|
|
||
| gas_costs = getattr(gas_mod, "GasCosts", None) | ||
|
|
||
| def gas_default( |
There was a problem hiding this comment.
My naive implementation would be to do something like:
GasCosts = template.module("vm.gas").GasCosts
if gas_per_blob is not None:
if gas_per_blob != getattr(GasCosts, "per_blob", None):
return False
...I assume this is insufficient for some reason. Why?
There was a problem hiding this comment.
Yeah,after I re-checking the current fork layout, comparing against vm.gas.GasCosts directly was enough here.
I kept the conservative fallback of cloning if vm.gas / GasCosts cannot be read, and added coverage for that case too.
| blob_base_fee_update_fraction=blob_base_fee_update_fraction, | ||
| max_blob_gas_per_block=max_blob_gas_per_block, | ||
| blob_schedule_target=blob_schedule_target, | ||
| blob_schedule_max=blob_schedule_max, |
There was a problem hiding this comment.
I think it's probably time to introduce a dataclass to organize this pile of arguments 🤣
There was a problem hiding this comment.
Thanks. I wrapped the override values in _ForkOverrides so the internal plumbing is a bit less noisy without changing the external get(...) signature.😺
| return Unscheduled(order_index=1) | ||
| return zero_order | ||
|
|
||
| raise AssertionError(f"unsupported fork criteria type: {type(criteria)}") |
There was a problem hiding this comment.
Should use assert_never here if possible.
There was a problem hiding this comment.
Fixed, this now uses assert_never.
| """Return a gas default from module-level or `GasCosts` attributes.""" | ||
| value = getattr(gas_mod, module_attr, None) | ||
| if value is not None: | ||
| return cast(U64 | Uint, value) |
There was a problem hiding this comment.
Should we use asserts here instead of casts?
There was a problem hiding this comment.
Fixed, I replaced the casts here with assert isinstance(...) checks.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## forks/amsterdam #2738 +/- ##
===================================================
+ Coverage 86.47% 88.17% +1.69%
===================================================
Files 599 577 -22
Lines 37632 35659 -1973
Branches 3795 3490 -305
===================================================
- Hits 32542 31442 -1100
+ Misses 4526 3654 -872
+ Partials 564 563 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Yes, looks worthwhile for the case this PR is targeting. When the requested blob overrides are identical to the template defaults, the old path still paid the full For actually changed overrides, both versions still clone, and I did not see a meaningful regression there ( |
SamWilsn
left a comment
There was a problem hiding this comment.
I wonder if we should move the _ForkOverrides dataclass into ethereum_spec_tools.forks and use it for Hardfork.clone directly. The parameter list for that function is getting unwieldy.
That makes sense. I can open a follow-up PR for this. |
🗒️ Description
ForkCache.get(...)to avoid creating a temporary fork clone when requested overrides are identical to the template._ForkOverridesto organize temporary override values internally._template_matches(...)to compare requested values against template defaults before cloning.vm.gasorGasCostscannot be read, the request is treated as non-identical and still clones.tests/evm_tools/test_fork_cache.pyto include:vm.gas/GasCostsfalls back to cloning🔗 Related Issues or PRs
Fixes #1864.
✅ Checklist
just staticjust staticcommand set directly viauv run ...becausejustis not available in local environment.)type(scope):.mkdocs servelocally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_frommarker.Cute Animal Picture