Skip to content

Commit

Permalink
Add config option for block processing offset
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Jun 10, 2024
1 parent 52082fc commit c11c88d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/codegen/src/templates/config-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
subgraphEventsOrder = true
blockDelayInMilliSecs = 2000

# Number of blocks by which block processing lags behind head
blockProcessingOffset = 0

# Boolean to switch between modes of processing events when starting the server.
# Setting to true will fetch filtered events and required blocks in a range of blocks and then process them.
# Setting to false will fetch blocks consecutively with its events and then process them (Behaviour is followed in realtime processing near head).
Expand Down
3 changes: 3 additions & 0 deletions packages/util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface JobQueueConfig {
subgraphEventsOrder: boolean;
blockDelayInMilliSecs: number;

// Number of blocks by which block processing lags behind head (default: 0)
blockProcessingOffset?: number;

// Block range in which logs are fetched during historical blocks processing
historicalLogsBlockRange?: number;

Expand Down
4 changes: 2 additions & 2 deletions packages/util/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export class EventWatcher {
while (true) {
const { block: latestBlock } = await this._ethClient.getBlockByHash();

// Process block if it is MAX_REORG_DEPTH behind latest block
if (latestBlock.number >= blockNumber + MAX_REORG_DEPTH) {
// Process block if it is blockProcessingOffset blocks behind latest block
if (latestBlock.number >= blockNumber + (this._config.jobQueue.blockProcessingOffset ?? 0)) {
await processBlockByNumber(this._jobQueue, blockNumber + 1);
break;
}
Expand Down

0 comments on commit c11c88d

Please sign in to comment.