feat: implement BalancesTreeCache #7084
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
balances
tree from scratch and it causes memory spikes atprocessRewardsAndPenalties
step (10m) chart:while after a state is finalized, we remove checkpoint state and don't use it anymore. We can recreate the
balances
tree using that unusedbalances
tree from that state leveraging feat: ListUintNum64Type create ViewDU from existing tree ssz#402see also Improve processRewardsAndPenalties #6229
Description
BalancesTreeCache
which is populated after we remove a checkpoint state, and consume by epoch transition using same design of feat: async shuffling refactor #6938IBalancesTreeCache
interface and consume it if existsBalancesTreeCache
and put that toEpochCache
ListUintNum64Type.toViewDU(value, viewDU)
Resolves #6229
Testing
processRewardsAndPenalties
10m is improved a lot, there are 2 spikes in 12h time frame, most likely due tobatchHashTreeRoot()
we used insideListUintNum64Type.toViewDU(value, viewDU)
prepareNextEpoch
is saved ~350ms because we hashedstate.balances
inListUintNum64Type.toViewDU(value, viewDU)
, and that's majority of hash work forprepareNextEpoch
state.hashTreeRoot()
isnota little bit confusing, but majority of work is done by this work andstate.validators.commit()