Skip to content

Commit

Permalink
fix reorg handler force from block
Browse files Browse the repository at this point in the history
  • Loading branch information
iuwqyir committed Dec 11, 2024
1 parent 6b6d94f commit 1ebfa65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion internal/orchestrator/reorg_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func (rh *ReorgHandler) RunFromBlock(lookbackFrom *big.Int) (lastCheckedBlock *b
return nil, nil
}
mostRecentBlockHeader := blockHeaders[0]
log.Debug().Msgf("Checking for reorgs from block %s to %s", mostRecentBlockHeader.Number.String(), blockHeaders[len(blockHeaders)-1].Number.String())
lastBlockHeader := blockHeaders[len(blockHeaders)-1]
if mostRecentBlockHeader.Number.Cmp(lastBlockHeader.Number) == 0 {
log.Debug().Msgf("Most recent (%s) and last checked (%s) block numbers are equal, skipping reorg check", mostRecentBlockHeader.Number.String(), lastBlockHeader.Number.String())
return nil, nil
}
log.Debug().Msgf("Checking for reorgs from block %s to %s", mostRecentBlockHeader.Number.String(), lastBlockHeader.Number.String())
reorgEndIndex := findReorgEndIndex(blockHeaders)
if reorgEndIndex == -1 {
return mostRecentBlockHeader.Number, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/storage/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ func (c *ClickHouseConnector) SetLastReorgCheckedBlockNumber(chainId *big.Int, b
}

func (c *ClickHouseConnector) LookbackBlockHeaders(chainId *big.Int, limit int, lookbackStart *big.Int) (blockHeaders []common.BlockHeader, err error) {
query := fmt.Sprintf("SELECT number, hash, parent_hash FROM %s.blocks WHERE chain_id = %s AND number <= %s AND is_deleted = 0 ORDER BY number DESC", c.cfg.Database, chainId.String(), lookbackStart.String())
lookbackEnd := new(big.Int).Sub(lookbackStart, big.NewInt(int64(limit)))
query := fmt.Sprintf("SELECT number, hash, parent_hash FROM %s.blocks WHERE chain_id = %s AND number <= %s AND number > %s AND is_deleted = 0 ORDER BY number DESC", c.cfg.Database, chainId.String(), lookbackStart.String(), lookbackEnd.String())
query += getLimitClause(limit)

rows, err := c.conn.Query(context.Background(), query)
Expand Down

0 comments on commit 1ebfa65

Please sign in to comment.