feat: regen to consume state cache reload api#6456
Conversation
Performance Report✔️ no performance regression detected 🚀🚀 Significant benchmark improvement detected
Full benchmark results
|
|
|
||
| /** | ||
| * Get state after block `blockRoot` dialed forward to `slot` | ||
| * - shouldReload should be used with care, as it will cause the state to be reloaded from disk |
There was a problem hiding this comment.
Do you think it is better to rename shouldReload to shouldReloadFromDisk to emphasize and warn about the consequence of setting this flag to true?
There was a problem hiding this comment.
I'm open to change, cc @wemeetagain for your preference
There was a problem hiding this comment.
I think that is a good suggestion. shouldReloadFromDisk is more descriptive and expressive
There was a problem hiding this comment.
yes allowDiskReload really matches the usage of this flag 👍
| opts: StateCloneOpts, | ||
| rCaller: RegenCaller | ||
| rCaller: RegenCaller, | ||
| shouldReload = false |
There was a problem hiding this comment.
should this flag move in StateCloneOpts?
There was a problem hiding this comment.
shouldReload is designed to use within this file only, I don't want to publish shouldReload flag to all consumers, it should only be true when we get state for block processing, or updateHeadState. It's easier to control it within this file
| opts: StateCloneOpts, | ||
| rCaller: RegenCaller | ||
| rCaller: RegenCaller, | ||
| shouldReload = false |
There was a problem hiding this comment.
may be can move in StateCloneOpts here as well?
|
|
||
| /** | ||
| * Get state after block `blockRoot` dialed forward to `slot` | ||
| * - shouldReload should be used with care, as it will cause the state to be reloaded from disk |
There was a problem hiding this comment.
I think that is a good suggestion. shouldReloadFromDisk is more descriptive and expressive
| const cp = getCheckpointFromState(checkpointState); | ||
| checkpointStateCache.add(cp, checkpointState); | ||
| emitter.emit(ChainEvent.checkpoint, cp, checkpointState); | ||
| emitter.emit(ChainEvent.checkpoint, cp, checkpointState.clone()); |
There was a problem hiding this comment.
Why add the costly clone() here?
There was a problem hiding this comment.
- if downstream event handlers mutate the state mistakenly, it does not affect our cache
clone()is really cheap and that's awesome feature of our tree backed state, see https://github.com/ChainSafe/ssz/blob/6220d320b004ea80bd30925487ac0f3299295528/packages/persistent-merkle-tree/src/tree.ts#L80
in fact I will add more clone() when returning an item from cache to avoid this mistake, see #6178 (comment)
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6456 +/- ##
============================================
+ Coverage 61.63% 61.69% +0.05%
============================================
Files 553 555 +2
Lines 57975 58253 +278
Branches 1832 1844 +12
============================================
+ Hits 35733 35937 +204
- Misses 22205 22277 +72
- Partials 37 39 +2 |
g11tech
left a comment
There was a problem hiding this comment.
seems to have addressed all concerns lgtm
|
🎉 This PR is included in v1.17.0 🎉 |
Motivation
getPreStateapi), we want to reload state if neededDescription
INVALID_STATE_ROOTerror during regen and add logsthis is cherry-picked from #6359, it does not affect production code because we haven't configured new state caches yet,
getOrReload*is just the same toget*part of #5968