Skip to content

Commit

Permalink
feat: correctly purge corrupted rewards calculations on restart (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary authored Dec 5, 2024
2 parents 505da55 + 6d9d283 commit 0571275
Show file tree
Hide file tree
Showing 65 changed files with 277 additions and 70 deletions.
2 changes: 1 addition & 1 deletion cmd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var runDatabaseCmd = &cobra.Command{
l.Fatal("Failed to create gorm instance", zap.Error(err))
}

migrator := migrations.NewMigrator(pg.Db, grm, l)
migrator := migrations.NewMigrator(pg.Db, grm, l, cfg)
if err = migrator.MigrateAll(); err != nil {
l.Fatal("Failed to migrate", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/debugger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
l.Fatal("Failed to create gorm instance", zap.Error(err))
}

migrator := migrations.NewMigrator(pg.Db, grm, l)
migrator := migrations.NewMigrator(pg.Db, grm, l, cfg)
if err = migrator.MigrateAll(); err != nil {
l.Fatal("Failed to migrate", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/operatorRestakedStrategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var runOperatorRestakedStrategiesCmd = &cobra.Command{
l.Fatal("Failed to create gorm instance", zap.Error(err))
}

migrator := migrations.NewMigrator(pg.Db, grm, l)
migrator := migrations.NewMigrator(pg.Db, grm, l, cfg)
if err = migrator.MigrateAll(); err != nil {
l.Fatal("Failed to migrate", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var runCmd = &cobra.Command{
l.Fatal("Failed to create gorm instance", zap.Error(err))
}

migrator := migrations.NewMigrator(pg.Db, grm, l)
migrator := migrations.NewMigrator(pg.Db, grm, l, cfg)
if err = migrator.MigrateAll(); err != nil {
l.Fatal("Failed to migrate", zap.Error(err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/avsOperators/avsOperators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/eigenstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/operatorShares/operatorShares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/rewardSubmissions/rewardSubmissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/stakerDelegations/stakerDelegations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/stakerShares/stakerShares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/stateManager/stateManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/indexer/restakedStrategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/pipelineIntegration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func setup(ethConfig *ethereum.EthereumClientConfig) (
ethConfig.BaseUrl = rpcUrl
client := ethereum.NewClient(ethConfig, l)

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409061249_bootstrapDb/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package _202409061249_bootstrapDb
import (
"database/sql"
"fmt"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS blocks (
number bigint NOT NULL PRIMARY KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package _202409061250_eigenlayerStateTables
import (
"database/sql"
"fmt"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists registered_avs_operators (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409061720_operatorShareChanges

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists operator_shares (
operator varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409062151_stakerDelegations/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409062151_stakerDelegations

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists delegated_stakers (
staker varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409080918_staterootTable/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409080918_staterootTable

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS state_roots (
eth_block_number bigint not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409082234_stakerShare/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409082234_stakerShare

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists staker_shares (
staker varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409101144_submittedDistributionRoot

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists submitted_distribution_roots (
root varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409101540_rewardSubmissions/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409101540_rewardSubmissions

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
query := `
create table if not exists reward_submissions (
avs varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202409161057_avsOperatorDeltas/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package _202409161057_avsOperatorDeltas
import (
"database/sql"
"fmt"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`create table if not exists avs_operator_state_changes (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202409181340_stakerDelegationDelta

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
query := `
create table if not exists staker_delegation_changes (
staker varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202410241239_combinedRewards/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202410241239_combinedRewards

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS combined_rewards (
avs varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202410241313_operatorAvsRegistrationSnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS operator_avs_registration_snapshots (
avs varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202410241417_operatorAvsStrategySnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS operator_avs_strategy_snapshots (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202410241431_operatorShareSnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS operator_share_snapshots (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package _202410241450_stakerDelegationSnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"
"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS staker_delegation_snapshots (
staker varchar not null,
Expand Down
Loading

0 comments on commit 0571275

Please sign in to comment.