Skip to content

Commit

Permalink
Merge pull request #2960 from gobitfly/NOBIDS/limit_validator_name_se…
Browse files Browse the repository at this point in the history
…arch

Nobids/limit validator name search
  • Loading branch information
guybrush authored Sep 30, 2024
2 parents a3bcdf8 + fa241d2 commit d31f503
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion handlers/validators_slashings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d31f503

Please sign in to comment.