diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 969c1fba4f..4814cc2200 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -3,6 +3,7 @@ package handlers import ( "bytes" "context" + "encoding/hex" "encoding/json" "errors" "eth2-exporter/db" @@ -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) @@ -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() @@ -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) }