Skip to content

Commit

Permalink
TEMPORALY: reset l2scannedblock table
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan committed Mar 3, 2024
1 parent 204485a commit d453f74
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cmd/bot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion core/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package core

import "time"

type L2ScannedBlockV2 struct {
type L2ScannedBlock struct {
Number int64 `gorm:"type:integer;primarykey"`
}

Expand Down

0 comments on commit d453f74

Please sign in to comment.