mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Use multi lock
This commit is contained in:
@@ -36,6 +36,7 @@ go_library(
|
||||
"//validator:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//async:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
|
||||
@@ -2,9 +2,11 @@ package helpers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/async"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
@@ -85,6 +87,12 @@ func ActiveValidatorIndices(s state.ReadOnlyBeaconState, epoch types.Epoch) ([]t
|
||||
if activeIndices != nil {
|
||||
return activeIndices, nil
|
||||
}
|
||||
|
||||
// Smoothing out committee cache update with a multi lock by seed.
|
||||
mLock := async.NewMultilock(committeeCacheLockKey(seed))
|
||||
mLock.Lock()
|
||||
defer mLock.Unlock()
|
||||
|
||||
var indices []types.ValidatorIndex
|
||||
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
if IsActiveValidatorUsingTrie(val, epoch) {
|
||||
@@ -117,6 +125,11 @@ func ActiveValidatorCount(s state.ReadOnlyBeaconState, epoch types.Epoch) (uint6
|
||||
return uint64(activeCount), nil
|
||||
}
|
||||
|
||||
// Smoothing out committee cache update with a multi lock by seed.
|
||||
mLock := async.NewMultilock(committeeCacheLockKey(seed))
|
||||
mLock.Lock()
|
||||
defer mLock.Unlock()
|
||||
|
||||
count := uint64(0)
|
||||
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
|
||||
if IsActiveValidatorUsingTrie(val, epoch) {
|
||||
@@ -363,3 +376,7 @@ func isEligibleForActivation(activationEligibilityEpoch, activationEpoch, finali
|
||||
return activationEligibilityEpoch <= finalizedEpoch &&
|
||||
activationEpoch == params.BeaconConfig().FarFutureEpoch
|
||||
}
|
||||
|
||||
func committeeCacheLockKey(seed [32]byte) string {
|
||||
return fmt.Sprintf("%s-%s", "committee_cache_update", string(seed[:]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user