Skip to content

Commit 1ebfa65

Browse files
committed
fix reorg handler force from block
1 parent 6b6d94f commit 1ebfa65

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/orchestrator/reorg_handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ func (rh *ReorgHandler) RunFromBlock(lookbackFrom *big.Int) (lastCheckedBlock *b
102102
return nil, nil
103103
}
104104
mostRecentBlockHeader := blockHeaders[0]
105-
log.Debug().Msgf("Checking for reorgs from block %s to %s", mostRecentBlockHeader.Number.String(), blockHeaders[len(blockHeaders)-1].Number.String())
105+
lastBlockHeader := blockHeaders[len(blockHeaders)-1]
106+
if mostRecentBlockHeader.Number.Cmp(lastBlockHeader.Number) == 0 {
107+
log.Debug().Msgf("Most recent (%s) and last checked (%s) block numbers are equal, skipping reorg check", mostRecentBlockHeader.Number.String(), lastBlockHeader.Number.String())
108+
return nil, nil
109+
}
110+
log.Debug().Msgf("Checking for reorgs from block %s to %s", mostRecentBlockHeader.Number.String(), lastBlockHeader.Number.String())
106111
reorgEndIndex := findReorgEndIndex(blockHeaders)
107112
if reorgEndIndex == -1 {
108113
return mostRecentBlockHeader.Number, nil

internal/storage/clickhouse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ func (c *ClickHouseConnector) SetLastReorgCheckedBlockNumber(chainId *big.Int, b
932932
}
933933

934934
func (c *ClickHouseConnector) LookbackBlockHeaders(chainId *big.Int, limit int, lookbackStart *big.Int) (blockHeaders []common.BlockHeader, err error) {
935-
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())
935+
lookbackEnd := new(big.Int).Sub(lookbackStart, big.NewInt(int64(limit)))
936+
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())
936937
query += getLimitClause(limit)
937938

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

0 commit comments

Comments
 (0)