Skip to content

Commit

Permalink
backfilling and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsc committed Mar 6, 2024
1 parent c91aeb6 commit eeca87d
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 55 deletions.
41 changes: 41 additions & 0 deletions backend/pkg/exporter/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,44 @@ func GetLatestDashboardEpoch() (uint64, error) {
}
return epoch, nil
}

func HasDashboardDataForEpoch(targetEpoch uint64) (bool, error) {
var epoch uint64
err := db.AlloyReader.Get(&epoch, "SELECT epoch FROM dashboard_data_epoch WHERE epoch = $1 LIMIT 1", targetEpoch)
if err != nil {
if err == sql.ErrNoRows {
return false, nil
}
return false, err
}
return true, nil
}

func GetDashboardEpochGaps(targetEpoch uint64) ([]uint64, error) {
var minEpoch uint64
err := db.AlloyReader.Get(&minEpoch, "SELECT COALESCE(min(epoch), 0) FROM dashboard_data_epoch;")
if err != nil {
return nil, err
}

var epochs []uint64
err = db.AlloyReader.Select(&epochs, `
WITH
epoch_range AS (
SELECT generate_series($1::bigint, $2::bigint) AS epoch
),
distinct_present_epochs AS (
SELECT DISTINCT epoch
FROM dashboard_data_epoch
)
SELECT epoch_range.epoch
FROM epoch_range
LEFT JOIN distinct_present_epochs ON epoch_range.epoch = distinct_present_epochs.epoch
WHERE distinct_present_epochs.epoch IS NULL
ORDER BY epoch_range.epoch
`, minEpoch, targetEpoch)
if err != nil {
return nil, err
}
return epochs, nil
}
37 changes: 32 additions & 5 deletions backend/pkg/exporter/modules/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ type ModuleInterface interface {
OnChainReorg(*types.StandardEventChainReorg) error
}

type ModuleContext struct {
CL consapi.Client
ConsClient *rpc.LighthouseClient
}

var Client *rpc.Client

// Start will start the export of data from rpc into the database
Expand Down Expand Up @@ -195,3 +190,35 @@ func GetModuleContext() (ModuleContext, error) {

return moduleContext, nil
}

type ModuleContext struct {
CL consapi.Client
ConsClient *rpc.LighthouseClient
}

type ModuleLog struct {
module ModuleInterface
}

func (m ModuleLog) Info(message string) {
log.InfoWithFields(log.Fields{"module": m.module.GetName()}, message)
}

func (m ModuleLog) Infof(format string, args ...interface{}) {
log.InfoWithFields(log.Fields{"module": m.module.GetName()}, fmt.Sprintf(format, args...))
}

func (m ModuleLog) Error(err error, errorMsg interface{}, callerSkip int, additionalInfos ...log.Fields) {
additionalInfos = append(additionalInfos, log.Fields{"module": m.module.GetName()})
log.Error(err, errorMsg, callerSkip, additionalInfos...)
}

func (m ModuleLog) Warn(err error, errorMsg interface{}, callerSkip int, additionalInfos ...log.Fields) {
additionalInfos = append(additionalInfos, log.Fields{"module": m.module.GetName()})
log.Warn(err, errorMsg, callerSkip, additionalInfos...)
}

func (m ModuleLog) Fatal(err error, errorMsg interface{}, callerSkip int, additionalInfos ...log.Fields) {
additionalInfos = append(additionalInfos, log.Fields{"module": m.module.GetName()})
log.Fatal(err, errorMsg, callerSkip, additionalInfos...)
}
Loading

0 comments on commit eeca87d

Please sign in to comment.