Skip to content

Commit

Permalink
more debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Feb 24, 2024
1 parent eb0bb87 commit 46bea87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func (s *DatabaseService) GetDataAPILatestBid(relay string) (*DataAPIBuilderBidE
}

func (s *DatabaseService) GetTopRelays(since, until time.Time) (res []*TopRelayEntry, err error) {
query := `SELECT relay, count(relay) as payloads FROM mainnet_data_api_payload_delivered WHERE inserted_at > $1 AND inserted_at < $2 GROUP BY relay ORDER BY payloads DESC;`
query := `SELECT relay, count(relay) as payloads FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2 GROUP BY relay ORDER BY payloads DESC;`
err = s.DB.Select(&res, query, since.UTC(), until.UTC())
return res, err
}

func (s *DatabaseService) GetTopBuilders(since, until time.Time, relay string) (res []*TopBuilderEntry, err error) {
query := `SELECT extra_data, count(extra_data) as blocks FROM (
SELECT distinct(slot), extra_data FROM mainnet_data_api_payload_delivered WHERE inserted_at > $1 AND inserted_at < $2`
SELECT distinct(slot), extra_data FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2`
if relay != "" {
query += ` AND relay = '` + relay + `'`
}
Expand All @@ -144,7 +144,7 @@ func (s *DatabaseService) GetBuilderProfits(since, until time.Time) (res []*Buil
round(sum(CASE WHEN coinbase_diff_eth IS NOT NULL THEN coinbase_diff_eth ELSE 0 END), 4) as total_profit,
round(abs(sum(CASE WHEN coinbase_diff_eth < 0 THEN coinbase_diff_eth ELSE 0 END)), 4) as total_subsidies
FROM (
SELECT distinct(slot), extra_data, coinbase_diff_eth FROM mainnet_data_api_payload_delivered WHERE inserted_at > $1 AND inserted_at < $2
SELECT distinct(slot), extra_data, coinbase_diff_eth FROM ` + TableDataAPIPayloadDelivered + ` WHERE inserted_at > $1 AND inserted_at < $2
) AS x
GROUP BY extra_data
ORDER BY total_profit DESC;`
Expand Down
12 changes: 8 additions & 4 deletions services/website/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,29 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er
now := time.Now().UTC()
since := now.Add(-1 * duration.Abs())

srv.log.Debug("- loading top relays...")
startTime := time.Now()
topRelays, err := srv.db.GetTopRelays(since, now)
if err != nil {
return nil, err
}
srv.log.WithField("duration", time.Since(startTime).String()).Debug("got top relays")
srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got top relays")

srv.log.Debug("- loading top builders...")
startTime = time.Now()
topBuilders, err := srv.db.GetTopBuilders(since, now, "")
if err != nil {
return nil, err
}
srv.log.WithField("duration", time.Since(startTime).String()).Debug("got top builders")
srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got top builders")

srv.log.Debug("- loading builder profits...")
startTime = time.Now()
builderProfits, err := srv.db.GetBuilderProfits(since, now)
if err != nil {
return nil, err
}
srv.log.WithField("duration", time.Since(startTime).String()).Debug("got builder profits")
srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got builder profits")

stats = &Stats{
Since: since,
Expand All @@ -184,6 +187,7 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er
}

// Query builders for each relay
srv.log.Debug("- loading builders per relay...")
startTime = time.Now()
for _, relay := range topRelays {
topBuildersForRelay, err := srv.db.GetTopBuilders(since, now, relay.Relay)
Expand All @@ -192,7 +196,7 @@ func (srv *Webserver) getStatsForHours(duration time.Duration) (stats *Stats, er
}
stats.TopBuildersByRelay[relay.Relay] = consolidateBuilderEntries(topBuildersForRelay)
}
srv.log.WithField("duration", time.Since(startTime).String()).Debug("got builders per relay")
srv.log.WithField("duration", time.Since(startTime).String()).Debug("- got builders per relay")

return stats, nil
}
Expand Down

0 comments on commit 46bea87

Please sign in to comment.