perf(vm): key the class cache on declaration height instead of load height - #4029
perf(vm): key the class cache on declaration height instead of load height#4029infrmtcs-agent[bot] wants to merge 1 commit into
Conversation
|
Claude finished @infrmtcs-agent[bot]'s task in 6m 24s —— View job Review: perf(vm): key the class cache on declaration height instead of load height
Overall: the core logic change is sound. Important
Nits
No blockers. The design and test coverage for the primary fix (declaration-height keying) look correct; the two "important" items are either already disclosed/scoped by the author or a test-isolation robustness concern rather than a functional bug in the shipped code. |
| // https://voyager.online/class/0x03297a93c52357144b7da71296d7e8231c3e0959f0a1d37222204f2f7712010e | ||
| classHash := felt.NewUnsafeFromString[felt.Felt]( | ||
| "0x3297a93c52357144b7da71296d7e8231c3e0959f0a1d37222204f2f7712010e", |
There was a problem hiding this comment.
This test reuses the class hash 0x3297a93c...2010e that TestCallDeprecatedCairo and TestCallDeprecatedCairoMaxSteps also use. CLASS_CACHE on the Rust side is a process-wide static (vm/rust/src/state_reader/state_reader.rs:32), so it persists across every Go test in this binary — there's no reset hook between tests.
Today this is safe only because those two other tests call the VM with Header.Hash == nil (pending), so per vm/vm.go:328 they resolve to BlockHeight::Pending and never populate the cache for this hash. If a future test is added (or an existing one is edited) to call the VM with a non-pending header for this same class hash, it would silently pre-populate CLASS_CACHE with a declared_at this test doesn't expect, and TestClassCacheKeyedOnDeclarationHeight would start passing/failing based on test execution order rather than the behavior it's meant to verify.
Since the assertions are already relative to fetchesAfterFirstCall rather than absolute counts, this doesn't cause a current flake, but it's a footgun for future edits. Consider using a class hash that's unique to this test (or asserting/documenting the shared-cache dependency explicitly) so the test stays correct regardless of what other tests in the package do.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4029 +/- ##
==========================================
- Coverage 79.21% 79.16% -0.06%
==========================================
Files 464 464
Lines 35751 35793 +42
==========================================
+ Hits 28321 28335 +14
- Misses 7421 7449 +28
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
User description
Summary
DeclaredClassDefinition.At, instead of the height of the state that loaded it. A lookup at heightHhits iffH > declared_at.Nwas invisible to every reader belowN, so historicalstarknet_calland trace flows re-fetched and re-parsed classes that had existed for thousands of blocks.JunoStateGetCompiledClassgains adeclared_atout-param on the FFI. Classes read through a pending state are still never cached.TestClassCacheKeyedOnDeclarationHeightcovers a hit above the declaration height and a miss at the declaration height itself.Notes
Finalisesets the hash in place on the pending header that RPC readers already hold, so apre_confirmedcall can reach the VM with a hashed header over a pending overlay whose classes reportAt: 0, and cache them at height 0. Sync mode is unaffected because pre-confirmed headers never carry a hash. Sequencer mode is experimental and is being removed in refactor(node): remove sequencer support (and other refactors) #3892.RevertHead.PR Type
Enhancement, Tests
Description
Key Rust class cache on declaration height instead of load height
Add
declared_atout-param toJunoStateGetCompiledClassFFIFix stale cache misses for classes declared many blocks ago
Add test
TestClassCacheKeyedOnDeclarationHeightverifying cache behaviorFile Walkthrough
state.go
Add declared_at out-param to JunoStateGetCompiledClassvm/state.go
declaredAt *C.uint64_tout-parameter toJunoStateGetCompiledClassdeclaredAtwithval.At(declaration height) before returningthe compiled class
ffi.rs
Update FFI signature for declared_at parametervm/rust/src/state_reader/ffi.rs
JunoStateGetCompiledClassFFI declaration to include adeclared_at: *mut u64parameterstate_reader.rs
Key class cache lookups on declaration heightvm/rust/src/state_reader/state_reader.rs
cached_on_heightfield todeclared_atinCachedRunnableCompiledClassinstead of load height
declared_atpointer toJunoStateGetCompiledClassFFI call andstores the returned value in the cache
exclusion
vm_test.go
Add test for declaration-height class cache keyingvm/vm_test.go
classFetchCounterwrapper to track class fetch callsTestClassCacheKeyedOnDeclarationHeightverifying cache hitsabove declaration height and misses at declaration height