mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Use balancesLength and randaoMixesLength to save copy on read (#4769)
* Use balancesLength and randaoMixesLength to save copy on read * Update beacon-chain/state/getters.go Co-Authored-By: shayzluf <thezluf@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: shayzluf <thezluf@gmail.com>
This commit is contained in:
parent
69c3d9dec2
commit
a9f1de354b
@ -274,11 +274,10 @@ func ProcessFinalUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconState,
|
||||
|
||||
// Set RANDAO mix.
|
||||
randaoMixLength := params.BeaconConfig().EpochsPerHistoricalVector
|
||||
mixes := state.RandaoMixes()
|
||||
if len(mixes) != int(randaoMixLength) {
|
||||
if state.RandaoMixesLength() != int(randaoMixLength) {
|
||||
return nil, fmt.Errorf(
|
||||
"state randao length %d different than EpochsPerHistoricalVector %d",
|
||||
len(mixes),
|
||||
state.RandaoMixesLength(),
|
||||
randaoMixLength,
|
||||
)
|
||||
}
|
||||
|
@ -22,9 +22,8 @@ func ProcessRewardsAndPenaltiesPrecompute(
|
||||
}
|
||||
|
||||
numOfVals := state.NumValidators()
|
||||
bals := state.Balances()
|
||||
// Guard against an out-of-bounds using validator balance precompute.
|
||||
if len(vp) != numOfVals || len(vp) != len(bals) {
|
||||
if len(vp) != numOfVals || len(vp) != state.BalancesLength() {
|
||||
return state, errors.New("precomputed registries not the same length as state registries")
|
||||
}
|
||||
|
||||
|
@ -431,6 +431,18 @@ func (b *BeaconState) BalanceAtIndex(idx uint64) (uint64, error) {
|
||||
return b.state.Balances[idx], nil
|
||||
}
|
||||
|
||||
// BalancesLength returns the length of the balances slice.
|
||||
func (b *BeaconState) BalancesLength() int {
|
||||
if b.state.Balances == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
|
||||
return len(b.state.Balances)
|
||||
}
|
||||
|
||||
// RandaoMixes of block proposers on the beacon chain.
|
||||
func (b *BeaconState) RandaoMixes() [][]byte {
|
||||
if b.state.RandaoMixes == nil {
|
||||
@ -467,6 +479,18 @@ func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) {
|
||||
return root, nil
|
||||
}
|
||||
|
||||
// RandaoMixesLength returns the length of the randao mixes slice.
|
||||
func (b *BeaconState) RandaoMixesLength() int {
|
||||
if b.state.RandaoMixes == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
|
||||
return len(b.state.RandaoMixes)
|
||||
}
|
||||
|
||||
// Slashings of validators on the beacon chain.
|
||||
func (b *BeaconState) Slashings() []uint64 {
|
||||
if b.state.Slashings == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user