-
Notifications
You must be signed in to change notification settings - Fork 1k
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
reuse code from stategen in the justified balance cache #11961
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
b57a453
to
895935e
Compare
stateGen: &mockStateByRooter{ | ||
err: sentinelCacheMiss, | ||
}, | ||
root: bytesutil.ToBytes32([]byte{'B'}), | ||
}, | ||
err: sentinelCacheMiss, | ||
root: bytesutil.ToBytes32([]byte{'A'}), | ||
name: "cache miss", | ||
}, |
There was a problem hiding this comment.
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?
Avoid code duplication, this is useful in starting to get rid of the justified balance cache and move to tracking this on forkchoice.