From f543ec7008462b05ed84f07b01a90112db435ae9 Mon Sep 17 00:00:00 2001 From: spletka Date: Thu, 29 Jun 2023 13:09:45 +0200 Subject: [PATCH 1/2] (NOBIDS) Fix double validators in dashboard --- handlers/dashboard.go | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 969c1fba4f..337340517f 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 + } + filter = pq.Array(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)`, filter) + 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) } From ff7a1571b30e27698d06a51439ceec160beb9f6d Mon Sep 17 00:00:00 2001 From: spletka Date: Thu, 29 Jun 2023 14:01:30 +0200 Subject: [PATCH 2/2] (NOBIDS) Change filter type --- handlers/dashboard.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index 337340517f..4814cc2200 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -765,7 +765,7 @@ func DashboardDataValidators(w http.ResponseWriter, r *http.Request) { for idx := range validatorsByIndex { validatorsByIndexPubKeys[idx] = validatorsByIndex[idx].PublicKey } - filter = pq.Array(validatorsByIndexPubKeys) + pubkeyFilter := pq.ByteaArray(validatorsByIndexPubKeys) validatorsDeposits := []struct { Pubkey []byte `db:"publickey"` @@ -776,7 +776,7 @@ func DashboardDataValidators(w http.ResponseWriter, r *http.Request) { publickey, from_address FROM eth1_deposits - WHERE publickey = ANY($1)`, filter) + 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)