Currently we cache the pre-state for blocks as a checkpoint state which means the states are held for longer than they are actually useful and compete for space with the states used for validating attestations.
We do want to ensure we continue precaching the epoch transition and could benefit from pre-computing and caching the slot transition for all blocks. However, we only need to maintain a relatively small number of these cached states to facilitate validating and importing newly received blocks. Once they are more than a couple of slots old they are unlikely to be required again.
We need to avoid applying too many empty slots in this cache and definitely don't do this preparation while syncing.
Given slot processing is quite fast so long as an epoch transition isn't required, it may be worth investigating dropping checkpoint states from the cache that are:
more than a few slots behind the current slot (based on clock time)
not for the first slot of an epoch
not for a slot in a later epoch than the state they were created from (this rule may be unnecessary given the previous one)
There may be better approaches - need to test in multiple scenarios, including long periods of non-finalization with multiple branches.
Description
Currently we cache the pre-state for blocks as a checkpoint state which means the states are held for longer than they are actually useful and compete for space with the states used for validating attestations.
We do want to ensure we continue precaching the epoch transition and could benefit from pre-computing and caching the slot transition for all blocks. However, we only need to maintain a relatively small number of these cached states to facilitate validating and importing newly received blocks. Once they are more than a couple of slots old they are unlikely to be required again.
We need to avoid applying too many empty slots in this cache and definitely don't do this preparation while syncing.
Given slot processing is quite fast so long as an epoch transition isn't required, it may be worth investigating dropping checkpoint states from the cache that are:
There may be better approaches - need to test in multiple scenarios, including long periods of non-finalization with multiple branches.