Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse code from stategen in the justified balance cache #11961

Merged
merged 7 commits into from
Feb 2, 2023

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Feb 2, 2023

Avoid code duplication, this is useful in starting to get rid of the justified balance cache and move to tracking this on forkchoice.

@potuz potuz added Ready For Review A pull request ready for code review OK to merge Cleanup Code health! labels Feb 2, 2023
@potuz potuz requested a review from a team as a code owner February 2, 2023 12:31
@potuz potuz removed the OK to merge label Feb 2, 2023
Comment on lines -41 to -60
justifiedState, err := c.stateGen.StateByRoot(ctx, justifiedRoot)
if err != nil {
return nil, err
}
if justifiedState == nil || justifiedState.IsNil() {
return nil, errNilStateFromStategen
}
epoch := time.CurrentEpoch(justifiedState)

justifiedBalances := make([]uint64, justifiedState.NumValidators())
var balanceAccumulator = func(idx int, val state.ReadOnlyValidator) error {
if helpers.IsActiveValidatorUsingTrie(val, epoch) {
justifiedBalances[idx] = val.EffectiveBalance()
} else {
justifiedBalances[idx] = 0
}
return nil
}
if err := justifiedState.ReadFromEveryValidator(balanceAccumulator); err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too familiar with any of this code. Are none of these checks necessary anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of that code is duplicated in the function BalanceByRoot, that's the cleanup in this PR

@potuz potuz force-pushed the use_stategen_on_justified_balance_cache branch from b57a453 to 895935e Compare February 2, 2023 13:37
Comment on lines -144 to -152
stateGen: &mockStateByRooter{
err: sentinelCacheMiss,
},
root: bytesutil.ToBytes32([]byte{'B'}),
},
err: sentinelCacheMiss,
root: bytesutil.ToBytes32([]byte{'A'}),
name: "cache miss",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to remove these tests as well?

@prylabs-bulldozer prylabs-bulldozer bot merged commit 0d01deb into develop Feb 2, 2023
@delete-merged-branch delete-merged-branch bot deleted the use_stategen_on_justified_balance_cache branch February 2, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code health! Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants