Skip to content

Commit

Permalink
Merge pull request #2380 from gobitfly/NOBIDS/FixDoubleValidatorsInDa…
Browse files Browse the repository at this point in the history
…shboard

(NOBIDS) Fix double validators in dashboard
  • Loading branch information
recy21 authored Jun 29, 2023
2 parents 015c2be + ff7a157 commit 96aa2ea
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"errors"
"eth2-exporter/db"
Expand Down Expand Up @@ -747,12 +748,10 @@ func DashboardDataValidators(w http.ResponseWriter, r *http.Request) {
(SELECT COUNT(*) FROM blocks WHERE proposer = validators.validatorindex AND status = '2') as missedproposals,
COALESCE(validator_performance.cl_performance_7d, 0) as performance7d,
COALESCE(validator_names.name, '') AS name,
validators.status AS state,
eth1_deposits.from_address
validators.status AS state
FROM validators
LEFT JOIN validator_names ON validators.pubkey = validator_names.publickey
LEFT JOIN validator_performance ON validators.validatorindex = validator_performance.validatorindex
LEFT JOIN eth1_deposits ON validators.pubkey = eth1_deposits.publickey
WHERE validators.validatorindex = ANY($1)
LIMIT $2`, filter, validatorLimit)

Expand All @@ -762,6 +761,37 @@ func DashboardDataValidators(w http.ResponseWriter, r *http.Request) {
return
}

validatorsByIndexPubKeys := make([][]byte, len(validatorsByIndex))
for idx := range validatorsByIndex {
validatorsByIndexPubKeys[idx] = validatorsByIndex[idx].PublicKey
}
pubkeyFilter := pq.ByteaArray(validatorsByIndexPubKeys)

validatorsDeposits := []struct {
Pubkey []byte `db:"publickey"`
Address []byte `db:"from_address"`
}{}
err = db.ReaderDb.Select(&validatorsDeposits, `
SELECT
publickey,
from_address
FROM eth1_deposits
WHERE publickey = ANY($1)`, pubkeyFilter)
if err != nil {
logger.WithError(err).WithField("route", r.URL.String()).Errorf("error retrieving validator deposists")
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
}

validatorsDepositsMap := make(map[string][]string)
for _, deposit := range validatorsDeposits {
key := hex.EncodeToString(deposit.Pubkey)
if _, ok := validatorsDepositsMap[key]; !ok {
validatorsDepositsMap[key] = make([]string, 0)
}
validatorsDepositsMap[key] = append(validatorsDepositsMap[key], fmt.Sprintf("%#x", deposit.Address))
}

latestEpoch := services.LatestEpoch()

stats := services.GetLatestStats()
Expand Down Expand Up @@ -890,8 +920,9 @@ func DashboardDataValidators(w http.ResponseWriter, r *http.Request) {

tableData[i] = append(tableData[i], utils.FormatIncome(v.Performance7d, currency))

if v.DepositAddress != nil {
tableData[i] = append(tableData[i], fmt.Sprintf("0x%x", *v.DepositAddress))
validatorDeposits := validatorsDepositsMap[hex.EncodeToString(v.PublicKey)]
if validatorDeposits != nil {
tableData[i] = append(tableData[i], validatorDeposits)
} else {
tableData[i] = append(tableData[i], nil)
}
Expand Down

0 comments on commit 96aa2ea

Please sign in to comment.