Skip to content

Commit 9440077

Browse files
committed
fix new chain not using configured reorg check start block
1 parent b500ad4 commit 9440077

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

internal/orchestrator/reorg_handler.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ func NewReorgHandler(rpc rpc.IRPCClient, storage storage.IStorage) *ReorgHandler
4949
}
5050

5151
func getInitialCheckedBlockNumber(storage storage.IStorage, chainId *big.Int) *big.Int {
52-
bn := big.NewInt(int64(config.Cfg.ReorgHandler.FromBlock))
53-
if !config.Cfg.ReorgHandler.ForceFromBlock {
54-
storedFromBlock, err := storage.OrchestratorStorage.GetLastReorgCheckedBlockNumber(chainId)
55-
if err != nil {
56-
log.Debug().Err(err).Msgf("Error getting last reorg checked block number, using configured: %s", bn)
57-
return bn
58-
}
59-
if storedFromBlock.Sign() <= 0 {
60-
log.Debug().Msgf("Last reorg checked block number not found, using configured: %s", bn)
61-
return bn
62-
}
63-
log.Debug().Msgf("Last reorg checked block number found, using: %s", storedFromBlock)
64-
return storedFromBlock
52+
configuredBn := big.NewInt(int64(config.Cfg.ReorgHandler.FromBlock))
53+
if config.Cfg.ReorgHandler.ForceFromBlock {
54+
log.Debug().Msgf("Force from block reorg check flag set, using configured: %s", configuredBn)
55+
return configuredBn
56+
}
57+
storedBn, err := storage.OrchestratorStorage.GetLastReorgCheckedBlockNumber(chainId)
58+
if err != nil {
59+
log.Debug().Err(err).Msgf("Error getting last reorg checked block number, using configured: %s", configuredBn)
60+
return configuredBn
61+
}
62+
if storedBn.Sign() <= 0 {
63+
log.Debug().Msgf("Last reorg checked block number not found, using configured: %s", configuredBn)
64+
return configuredBn
6565
}
66-
log.Debug().Msgf("Force from block reorg check flag set, using configured: %s", bn)
67-
return bn
66+
log.Debug().Msgf("Last reorg checked block number found, using: %s", storedBn)
67+
return storedBn
6868
}
6969

7070
func (rh *ReorgHandler) Start(ctx context.Context) {
@@ -148,6 +148,11 @@ func (rh *ReorgHandler) getReorgCheckRange(latestCheckedBlock *big.Int) (*big.In
148148
if err != nil {
149149
return nil, nil, fmt.Errorf("error getting latest committed block: %w", err)
150150
}
151+
if latestCheckedBlock.Cmp(latestCommittedBlock) > 0 {
152+
log.Debug().Msgf("Committing has not reached the configured reorg check start block: %s (reorg start) > %s (last committed)", latestCheckedBlock.String(), latestCommittedBlock.String())
153+
return latestCheckedBlock, latestCheckedBlock, nil
154+
}
155+
151156
if new(big.Int).Sub(latestCommittedBlock, latestCheckedBlock).Cmp(big.NewInt(int64(rh.blocksPerScan))) < 0 {
152157
// diff between latest committed and latest checked is less than blocksPerScan, so we will look back from the latest committed block
153158
fromBlock := new(big.Int).Sub(latestCommittedBlock, big.NewInt(int64(rh.blocksPerScan)))

0 commit comments

Comments
 (0)