Skip to content

Commit

Permalink
(BIDS-2261) do not overwrite total performance stats when exporting o…
Browse files Browse the repository at this point in the history
…ld statistic days
  • Loading branch information
peterbitfly committed Sep 27, 2023
1 parent cb974ce commit b3bde78
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"sync"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/stdlib"
Expand Down Expand Up @@ -181,10 +180,6 @@ func WriteValidatorStatisticsForDay(day uint64) error {

// update mev reward total
data.MEVRewardsWeiTotal = previousDayData.MEVRewardsWeiTotal.Add(data.MEVRewardsWei)

if data.ValidatorIndex == 10 {
spew.Dump(data)
}
}

conn, err := WriterDb.Conn(context.Background())
Expand Down Expand Up @@ -290,8 +285,17 @@ func WriteValidatorStatisticsForDay(day uint64) error {

logger.Infof("batch insert of statistics data completed")

if err := WriteValidatorTotalPerformance(day, tx); err != nil {
return fmt.Errorf("error in WriteValidatorTotalPerformance: %w", err)
lastExportedStatsDay, err := GetLastExportedStatisticDay()
if err != nil && err != ErrNoStats {
return fmt.Errorf("error retrieving last exported statistics day: %w", err)
}

if day > lastExportedStatsDay {
if err := WriteValidatorTotalPerformance(day, tx); err != nil {
return fmt.Errorf("error in WriteValidatorTotalPerformance: %w", err)
}
} else {
logger.Infof("skipping total performance export as last exported day (%v) is greater than the exported day (%v)", lastExportedStatsDay, day)
}

if err := WriteValidatorStatsExported(day, tx); err != nil {
Expand Down

0 comments on commit b3bde78

Please sign in to comment.