diff --git a/db/db.go b/db/db.go index a4204c052f..9ca297c989 100644 --- a/db/db.go +++ b/db/db.go @@ -1767,12 +1767,13 @@ func GetQueueAheadOfValidator(validatorIndex uint64) (uint64, error) { return res, err } -func GetValidatorNames() (map[uint64]string, error) { +func GetValidatorNames(validators []uint64) (map[uint64]string, error) { + logger.Infof("getting validator names for %d validators", len(validators)) rows, err := ReaderDb.Query(` SELECT validatorindex, validator_names.name FROM validators LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey - WHERE validator_names.name IS NOT NULL`) + WHERE validators.validatorindex = ANY($1) AND validator_names.name IS NOT NULL`, pq.Array(validators)) if err != nil { return nil, err diff --git a/handlers/validators_slashings.go b/handlers/validators_slashings.go index 067859e968..54d10c30a2 100644 --- a/handlers/validators_slashings.go +++ b/handlers/validators_slashings.go @@ -101,8 +101,24 @@ func ValidatorsSlashingsData(w http.ResponseWriter, r *http.Request) { tableData := make([][]interface{}, 0, len(slashings)) - validatorNames, err := db.GetValidatorNames() + validatorsForNameSearch := []uint64{} + for _, slashing := range slashings { + validatorsForNameSearch = append(validatorsForNameSearch, slashing.Proposer) + if slashing.Type == "Attestation Violation" { + inter := intersect.Simple(slashing.Attestestation1Indices, slashing.Attestestation2Indices) + if len(inter) == 0 { + logger.Warningf("No intersection found for attestation violation, proposer: %v, slot: %v", slashing.Proposer, slashing.Slot) + } + for _, v := range inter { + validatorsForNameSearch = append(validatorsForNameSearch, uint64(v.(int64))) + } + } + if slashing.Type == "Proposer Violation" { + validatorsForNameSearch = append(validatorsForNameSearch, *slashing.SlashedValidator) + } + } + validatorNames, err := db.GetValidatorNames(validatorsForNameSearch) if err != nil { logger.Errorf("error retrieving validator names from the database: %v", err) http.Error(w, "Internal server error", http.StatusInternalServerError)