Refactor state and contract modules
Description
This PR has 2 major changes:
-
Combine
ContractNonce,ContractClassHash, andContractDeploymentHeightinto a single bucket calledContract. Separation of the contract fields in different buckets creates data duplication. Instead, we can encode them into a single object and store them in a single bucket. The slight performance degradation of encoding/decoding is insignificant as the fields are small. Migration codes are added along with the unit tests. -
Refactor
State.Update,State.Revertand the removal ofhistory. In the previous implementation, after applying each state diff (i.e. nonce, class hash, storage), the contract commitment is recalculated. This indicates that the higher the number of individual state diffs, the more times we need to recalculate the contract commitment. In this new implementation, a contract's commitment is calculated only once after all state diffs are applied to a contract object. Now, the number of contract commitment calculations depends on the number of contracts updated.
Benchmark Results
goos: darwin
goarch: arm64
pkg: github.com/NethermindEth/juno/core
cpu: Apple M3 Pro
│ new.txt │ old.txt │
│ sec/op │ sec/op vs base │
StateUpdate-11 3.316m ± 2% 4.146m ± 2% +25.03% (p=0.000 n=10)
│ new.txt │ old.txt │
│ B/op │ B/op vs base │
StateUpdate-11 144.1Ki ± 0% 182.4Ki ± 0% +26.53% (p=0.000 n=10)
│ new.txt │ old.txt │
│ allocs/op │ allocs/op vs base │
StateUpdate-11 3.037k ± 0% 4.056k ± 0% +33.54% (p=0.000 n=10)
Codecov Report
Attention: Patch coverage is 65.50976% with 159 lines in your changes missing coverage. Please review.
Project coverage is 75.35%. Comparing base (
3093ca8) to head (c466cca). Report is 202 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #2224 +/- ##
==========================================
- Coverage 75.63% 75.35% -0.28%
==========================================
Files 104 103 -1
Lines 11102 11168 +66
==========================================
+ Hits 8397 8416 +19
- Misses 2073 2104 +31
- Partials 632 648 +16
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This pull request is stale because it has been open 35 days with no activity. Remove stale label or comment or this will be closed in 14 days.
Latest changes here