diff --git a/beacon-chain/core/epoch/precompute/slashing.go b/beacon-chain/core/epoch/precompute/slashing.go index dba22bbf2..5a55b1355 100644 --- a/beacon-chain/core/epoch/precompute/slashing.go +++ b/beacon-chain/core/epoch/precompute/slashing.go @@ -26,18 +26,20 @@ func ProcessSlashingsPrecompute(state *stateTrie.BeaconState, pBal *Balance) err minSlashing := mathutil.Min(totalSlashing*params.BeaconConfig().ProportionalSlashingMultiplier, pBal.ActiveCurrentEpoch) epochToWithdraw := currentEpoch + exitLength/2 - vs := state.ValidatorsReadOnly() var hasSlashing bool // Iterate through validator list in state, stop until a validator satisfies slashing condition of current epoch. - for _, v := range vs { - if v == nil { + err := state.ReadFromEveryValidator(func(idx int, val *stateTrie.ReadOnlyValidator) error { + if val == nil { return errors.New("nil validator in state") } - correctEpoch := epochToWithdraw == v.WithdrawableEpoch() - if v.Slashed() && correctEpoch { + correctEpoch := epochToWithdraw == val.WithdrawableEpoch() + if val.Slashed() && correctEpoch { hasSlashing = true - break } + return nil + }) + if err != nil { + return err } // Exit early if there's no meaningful slashing to process. if !hasSlashing { diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index 86381a6b1..3676c6899 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -806,13 +806,17 @@ func (bs *Server) GetIndividualVotes( if err != nil { return nil, status.Errorf(codes.Internal, "Could not pre compute attestations: %v", err) } - vals := requestedState.ValidatorsReadOnly() for _, index := range filteredIndices { if index >= uint64(len(v)) { votes = append(votes, ðpb.IndividualVotesRespond_IndividualVote{ValidatorIndex: index}) continue } - pb := vals[index].PublicKey() + val, err := requestedState.ValidatorAtIndexReadOnly(index) + if err != nil { + return nil, status.Errorf(codes.Internal, "Could not retrieve validator: %v", err) + + } + pb := val.PublicKey() votes = append(votes, ðpb.IndividualVotesRespond_IndividualVote{ Epoch: req.Epoch, PublicKey: pb[:],