Skip to content

Commit

Permalink
refactor block range processing into helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Nov 15, 2023
1 parent 1626219 commit 26277bf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vms/evm/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ func (s *subscriber) ProcessFromHeight(height *big.Int) error {
// Filter logs from the latest processed block to the latest block
// Since initializationFilterQuery does not modify existing fields of warpFilterQuery,
// we can safely reuse warpFilterQuery with only a shallow copy
processBlockRange := func (fromBlock *big.Int, toBlock *big.Int) error {
initializationFilterQuery := interfaces.FilterQuery{
Topics: warpFilterQuery.Topics,
Addresses: warpFilterQuery.Addresses,
FromBlock: height,
FromBlock: fromBlock,
ToBlock: toBlock,
}
logs, err := ethClient.FilterLogs(context.Background(), initializationFilterQuery)
Expand All @@ -198,7 +199,7 @@ func (s *subscriber) ProcessFromHeight(height *big.Int) error {
// Queue each of the logs to be processed
s.logger.Info(
"Processing logs on initialization",
zap.String("fromBlockHeight", height.String()),
zap.String("fromBlockHeight", fromBlock.String()),
zap.String("toBlockHeight", toBlock.String()),
zap.String("chainID", s.chainID.String()),
)
Expand All @@ -214,8 +215,10 @@ func (s *subscriber) ProcessFromHeight(height *big.Int) error {
}
s.logsChan <- *messageInfo
}
return nil
}

return nil
return processBlockRange(height, toBlock)
}

func (s *subscriber) SetProcessedBlockHeightToLatest() error {
Expand Down

0 comments on commit 26277bf

Please sign in to comment.