diff --git a/cmd/bot/run.go b/cmd/bot/run.go index 4a4917c..ba93cb6 100644 --- a/cmd/bot/run.go +++ b/cmd/bot/run.go @@ -48,7 +48,8 @@ func RunCommand(ctx *cli.Context) error { if err != nil { return fmt.Errorf("failed to connect database: %w", err) } - err = db.AutoMigrate(&core.L2ScannedBlockV2{}) + db.Delete(&core.L2ScannedBlock{}) + err = db.AutoMigrate(&core.L2ScannedBlock{}) if err != nil { return fmt.Errorf("failed to migrate l2_scanned_blocks: %w", err) } @@ -254,8 +255,8 @@ func connect(log log.Logger, dbConfig config.DBConfig) (*gorm.DB, error) { } // queryL2ScannedBlock queries the l2_scanned_blocks table for the last scanned block -func queryL2ScannedBlock(db *gorm.DB, l2StartingNumber int64) (*core.L2ScannedBlockV2, error) { - l2ScannedBlock := core.L2ScannedBlockV2{} +func queryL2ScannedBlock(db *gorm.DB, l2StartingNumber int64) (*core.L2ScannedBlock, error) { + l2ScannedBlock := core.L2ScannedBlock{} if result := db.Order("number desc").Last(&l2ScannedBlock); result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { l2ScannedBlock.Number = l2StartingNumber diff --git a/core/indexer.go b/core/indexer.go index 91ab6c0..8d4be40 100644 --- a/core/indexer.go +++ b/core/indexer.go @@ -95,7 +95,7 @@ func NewIndexer(log log.Logger, db *gorm.DB, l2Client *ClientExt, cfg Config) *I } // Start watches for new bot-delegated withdrawals and stores them in the database. -func (i *Indexer) Start(ctx context.Context, l2ScannedBlock *L2ScannedBlockV2) { +func (i *Indexer) Start(ctx context.Context, l2ScannedBlock *L2ScannedBlock) { timer := time.NewTimer(0) fromBlockNumber := big.NewInt(l2ScannedBlock.Number) diff --git a/core/metrics.go b/core/metrics.go index b4a681e..205f342 100644 --- a/core/metrics.go +++ b/core/metrics.go @@ -55,7 +55,7 @@ func StartMetrics(ctx context.Context, cfg *Config, l1Client *ethclient.Client, } TxSignerBalance.Set(float64(balance.Int64())) - var scannedBlock L2ScannedBlockV2 + var scannedBlock L2ScannedBlock result := db.Last(&scannedBlock) if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) { logger.Error("failed to query scanned block", "error", result.Error) diff --git a/core/types.go b/core/types.go index febbcef..588c9a8 100644 --- a/core/types.go +++ b/core/types.go @@ -2,7 +2,7 @@ package core import "time" -type L2ScannedBlockV2 struct { +type L2ScannedBlock struct { Number int64 `gorm:"type:integer;primarykey"` }