mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
validator count
This commit is contained in:
@@ -185,7 +185,7 @@ func (s *Service) Start() {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not retrieve genesis state: %v", err)
|
||||
}
|
||||
go slotutil.CountdownToGenesis(s.ctx, s.genesisTime, uint64(gState.NumValidators()))
|
||||
go slotutil.CountdownToGenesis(s.ctx, s.genesisTime, gState.NumValidators())
|
||||
|
||||
justifiedCheckpoint, err := s.beaconDB.JustifiedCheckpoint(s.ctx)
|
||||
if err != nil {
|
||||
@@ -266,7 +266,7 @@ func (s *Service) processChainStartTime(ctx context.Context, genesisTime time.Ti
|
||||
log.Fatalf("Could not initialize beacon chain: %v", err)
|
||||
}
|
||||
// We start a counter to genesis, if needed.
|
||||
go slotutil.CountdownToGenesis(ctx, genesisTime, uint64(initializedState.NumValidators()))
|
||||
go slotutil.CountdownToGenesis(ctx, genesisTime, initializedState.NumValidators())
|
||||
|
||||
// We send out a state initialized event to the rest of the services
|
||||
// running in the beacon node.
|
||||
|
||||
@@ -245,7 +245,7 @@ func ComputeProposerIndex(bState *stateTrie.BeaconState, activeIndices []uint64,
|
||||
return 0, err
|
||||
}
|
||||
candidateIndex = activeIndices[candidateIndex]
|
||||
if candidateIndex >= uint64(bState.NumValidators()) {
|
||||
if candidateIndex >= bState.NumValidators() {
|
||||
return 0, errors.New("active index out of range")
|
||||
}
|
||||
b := append(seed[:], bytesutil.Bytes8(i/32)...)
|
||||
|
||||
@@ -205,7 +205,7 @@ func (s *Service) saveGenesisState(ctx context.Context, genesisState *stateTrie.
|
||||
|
||||
pubKeys := make([][48]byte, 0, genesisState.NumValidators())
|
||||
indices := make([]uint64, 0, genesisState.NumValidators())
|
||||
for i := uint64(0); i < uint64(genesisState.NumValidators()); i++ {
|
||||
for i := uint64(0); i < genesisState.NumValidators(); i++ {
|
||||
pk := genesisState.PubkeyAtIndex(i)
|
||||
pubKeys = append(pubKeys, pk)
|
||||
indices = append(indices, i)
|
||||
|
||||
@@ -104,7 +104,7 @@ func (bs *Server) ListValidatorAssignments(
|
||||
}
|
||||
|
||||
for _, index := range filteredIndices[start:end] {
|
||||
if index >= uint64(requestedState.NumValidators()) {
|
||||
if index >= requestedState.NumValidators() {
|
||||
return nil, status.Errorf(codes.OutOfRange, "Validator index %d >= validator count %d",
|
||||
index, requestedState.NumValidators())
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ func (bs *Server) GetWeakSubjectivityCheckpoint(ctx context.Context, _ *ptypes.E
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get head state")
|
||||
}
|
||||
valCount := uint64(hs.NumValidators())
|
||||
valCount := hs.NumValidators()
|
||||
wsEpoch, err := helpers.WeakSubjectivityCheckptEpoch(valCount)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get weak subjectivity epoch")
|
||||
|
||||
@@ -263,7 +263,7 @@ func (bs *Server) ListValidators(
|
||||
})
|
||||
|
||||
if len(req.PublicKeys) == 0 && len(req.Indices) == 0 {
|
||||
for i := 0; i < reqState.NumValidators(); i++ {
|
||||
for i := uint64(0); i < reqState.NumValidators(); i++ {
|
||||
val, err := reqState.ValidatorAtIndex(uint64(i))
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get validator: %v", err)
|
||||
@@ -338,7 +338,7 @@ func (bs *Server) GetValidator(
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
||||
}
|
||||
if requestingIndex {
|
||||
if index >= uint64(headState.NumValidators()) {
|
||||
if index >= headState.NumValidators() {
|
||||
return nil, status.Errorf(
|
||||
codes.OutOfRange,
|
||||
"Requesting index %d, but there are only %d validators",
|
||||
@@ -349,7 +349,7 @@ func (bs *Server) GetValidator(
|
||||
return headState.ValidatorAtIndex(index)
|
||||
}
|
||||
pk48 := bytesutil.ToBytes48(pubKey)
|
||||
for i := 0; i < headState.NumValidators(); i++ {
|
||||
for i := uint64(0); i < headState.NumValidators(); i++ {
|
||||
keyFromState := headState.PubkeyAtIndex(uint64(i))
|
||||
if keyFromState == pk48 {
|
||||
return headState.ValidatorAtIndex(uint64(i))
|
||||
|
||||
@@ -229,7 +229,7 @@ func retrieveStatusForPubKey(headState *stateTrie.BeaconState, pubKey []byte) (e
|
||||
return ethpb.ValidatorStatus_UNKNOWN_STATUS, 0, errors.New("head state does not exist")
|
||||
}
|
||||
idx, ok := headState.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey))
|
||||
if !ok || idx >= uint64(headState.NumValidators()) {
|
||||
if !ok || idx >= headState.NumValidators() {
|
||||
return ethpb.ValidatorStatus_UNKNOWN_STATUS, 0, errPubkeyDoesNotExist
|
||||
}
|
||||
return assignmentStatus(headState, idx), idx, nil
|
||||
|
||||
@@ -684,14 +684,14 @@ func (b *BeaconState) PubkeyAtIndex(idx uint64) [48]byte {
|
||||
}
|
||||
|
||||
// NumValidators returns the size of the validator registry.
|
||||
func (b *BeaconState) NumValidators() int {
|
||||
func (b *BeaconState) NumValidators() uint64 {
|
||||
if !b.HasInnerState() {
|
||||
return 0
|
||||
}
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
|
||||
return len(b.state.Validators)
|
||||
return uint64(len(b.state.Validators))
|
||||
}
|
||||
|
||||
// ReadFromEveryValidator reads values from every validator and applies it to the provided function.
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s *Service) validateVoluntaryExit(ctx context.Context, pid peer.ID, msg *p
|
||||
return pubsub.ValidationIgnore
|
||||
}
|
||||
|
||||
if exit.Exit.ValidatorIndex >= uint64(headState.NumValidators()) {
|
||||
if exit.Exit.ValidatorIndex >= headState.NumValidators() {
|
||||
return pubsub.ValidationReject
|
||||
}
|
||||
val, err := headState.ValidatorAtIndexReadOnly(exit.Exit.ValidatorIndex)
|
||||
|
||||
Reference in New Issue
Block a user