From 294c2ab52735ae43658fd483dd69166e1ebcc22a Mon Sep 17 00:00:00 2001 From: Manuel <5877862+manuelsc@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:38:25 +0100 Subject: [PATCH] (NOBIDS) fix rare error cases when some data is not yet present --- db/bigtable.go | 3 +++ handlers/api.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/db/bigtable.go b/db/bigtable.go index b6689d2de5..cb32449bcc 100644 --- a/db/bigtable.go +++ b/db/bigtable.go @@ -2677,6 +2677,9 @@ func GetCurrentDayClIncome(validator_indices []uint64) (map[uint64]int64, error) dayIncome := make(map[uint64]int64) lastDay, err := GetLastExportedStatisticDay() if err != nil { + if err == ErrNoStats { + return dayIncome, nil + } return dayIncome, err } diff --git a/handlers/api.go b/handlers/api.go index 5bc1a1497d..5d0d164bfd 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -1198,7 +1198,13 @@ func getSyncCommitteeSlotsStatistics(validators []uint64, epoch uint64) (types.S lastExportedEpoch = ((lastExportedDay + 1) * epochsPerDay) - 1 } - err = db.ReaderDb.Get(&syncStats, `SELECT SUM(COALESCE(participated_sync_total, 0)) AS participated, SUM(COALESCE(missed_sync_total, 0)) AS missed FROM validator_stats WHERE day = $1 AND validatorindex = ANY($2)`, lastExportedDay, pq.Array(validators)) + err = db.ReaderDb.Get(&syncStats, ` + SELECT + COALESCE(SUM(COALESCE(participated_sync_total, 0)), 0) AS participated, + COALESCE(SUM(COALESCE(missed_sync_total, 0)),0) AS missed + FROM validator_stats + WHERE day = $1 AND validatorindex = ANY($2) + `, lastExportedDay, pq.Array(validators)) if err != nil { return types.SyncCommitteesStats{}, err }