feat(core/vm): add configurable jumpdest analysis cache #32143#2321
feat(core/vm): add configurable jumpdest analysis cache #32143#2321gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a configurable cache abstraction for EVM JUMPDEST analysis results so callers can plug in alternative caching strategies.
Changes:
- Introduces a
JumpDestCacheinterface plus a default per-EVM map-backed implementation. - Wires the cache through
EVMandContract(including a newSetJumpDestCachesetter). - Renames internal
bitvectype to exportedBitVecand updates benchmarks accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| core/vm/jumpdests.go | Adds JumpDestCache interface and default map-backed implementation. |
| core/vm/evm.go | Stores jumpdest cache behind the interface and adds SetJumpDestCache. |
| core/vm/contract.go | Uses JumpDestCache for jumpdest lookups/stores during execution. |
| core/vm/analysis_legacy.go | Exports BitVec type and updates bitmap helpers’ signatures. |
| core/vm/analysis_legacy_test.go | Updates benchmark to use BitVec. |
Comments suppressed due to low confidence (1)
core/vm/analysis_legacy.go:75
codeBitmapInternalnow takescodeasBitVec, but all call sites pass a[]byte(e.g.codeBitmap(code []byte)and the benchmark). This will not compile because[]byteis not assignable to the named slice typeBitVecwithout conversion. Change the first parameter back to[]byte(or explicitly convert at the call sites) so the function remains usable fromcodeBitmapand tests/benchmarks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // SetJumpDestCache configures the analysis cache. | ||
| func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) { |
There was a problem hiding this comment.
SetJumpDestCache allows setting evm.jumpDests to nil. If a caller accidentally passes nil, subsequent NewContract(..., evm.jumpDests) calls will fall back to creating a fresh map-based cache per contract (via NewContract's nil check) instead of sharing one cache per EVM instance, which is a surprising semantic change and can increase allocations. Consider treating nil as “reset to default” (e.g. set to newMapJumpDests()), or explicitly document/rename if nil is intended to disable shared caching.
| func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) { | |
| func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) { | |
| if jumpDests == nil { | |
| evm.jumpDests = newMapJumpDests() | |
| return | |
| } |
| // mapJumpDests is the default implementation of JumpDests using a map. | ||
| // This implementation is not thread-safe and is meant to be used per EVM instance. | ||
| type mapJumpDests map[common.Hash]BitVec | ||
|
|
||
| // newMapJumpDests creates a new map-based JumpDests implementation. |
There was a problem hiding this comment.
The comments refer to “JumpDests” even though the introduced type is JumpDestCache (e.g. “default implementation of JumpDests” / “new map-based JumpDests implementation”). Please align the wording with JumpDestCache to avoid confusion for future readers.
| // mapJumpDests is the default implementation of JumpDests using a map. | |
| // This implementation is not thread-safe and is meant to be used per EVM instance. | |
| type mapJumpDests map[common.Hash]BitVec | |
| // newMapJumpDests creates a new map-based JumpDests implementation. | |
| // mapJumpDests is the default implementation of JumpDestCache using a map. | |
| // This implementation is not thread-safe and is meant to be used per EVM instance. | |
| type mapJumpDests map[common.Hash]BitVec | |
| // newMapJumpDests creates a new map-based JumpDestCache implementation. |
Proposed changes
Ref: ethereum#32143
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that