mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Add historicalLogsBlockRangeEndFactor config for aligned block ranges in eth_getLogs
This commit is contained in:
parent
d0f88756c3
commit
3cd6491305
@ -29,6 +29,11 @@ export interface JobQueueConfig {
|
|||||||
// Block range in which logs are fetched during historical blocks processing
|
// Block range in which logs are fetched during historical blocks processing
|
||||||
historicalLogsBlockRange?: number;
|
historicalLogsBlockRange?: number;
|
||||||
|
|
||||||
|
// Factor to find the next multiple endBlock number when deciding eth_getLogs block range
|
||||||
|
// Used to fetch logs in aligned block ranges (paired with caching proxy server)
|
||||||
|
// If set to 0, historicalLogsBlockRange will be used to instead to decide block ranges
|
||||||
|
historicalLogsBlockRangeEndFactor?: number
|
||||||
|
|
||||||
// Max block range of historical processing after which it waits for completion of events processing
|
// Max block range of historical processing after which it waits for completion of events processing
|
||||||
// If set to -1 historical processing does not wait for events processing and completes till latest canonical block
|
// If set to -1 historical processing does not wait for events processing and completes till latest canonical block
|
||||||
historicalMaxFetchAhead?: number;
|
historicalMaxFetchAhead?: number;
|
||||||
|
@ -152,6 +152,12 @@ export class EventWatcher {
|
|||||||
endBlockNumber = Math.min(startBlockNumber + historicalMaxFetchAhead, endBlockNumber);
|
endBlockNumber = Math.min(startBlockNumber + historicalMaxFetchAhead, endBlockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._config.jobQueue.historicalLogsBlockRangeEndFactor) {
|
||||||
|
// Set endBlockNumber to a multiple lower than computed endBlockNumber (or canonical block)
|
||||||
|
// For using aligned block ranges
|
||||||
|
endBlockNumber = Math.floor(endBlockNumber / this._config.jobQueue.historicalLogsBlockRangeEndFactor) * this._config.jobQueue.historicalLogsBlockRangeEndFactor;
|
||||||
|
}
|
||||||
|
|
||||||
this._historicalProcessingEndBlockNumber = endBlockNumber;
|
this._historicalProcessingEndBlockNumber = endBlockNumber;
|
||||||
log(`Starting historical block processing in batches from ${startBlockNumber} up to block ${this._historicalProcessingEndBlockNumber}`);
|
log(`Starting historical block processing in batches from ${startBlockNumber} up to block ${this._historicalProcessingEndBlockNumber}`);
|
||||||
|
|
||||||
|
@ -252,7 +252,15 @@ export class JobRunner {
|
|||||||
|
|
||||||
this._lastHistoricalProcessingEndBlockNumber = processingEndBlockNumber;
|
this._lastHistoricalProcessingEndBlockNumber = processingEndBlockNumber;
|
||||||
const logsBlockRange = this._jobQueueConfig.historicalLogsBlockRange ?? DEFAULT_HISTORICAL_LOGS_BLOCK_RANGE;
|
const logsBlockRange = this._jobQueueConfig.historicalLogsBlockRange ?? DEFAULT_HISTORICAL_LOGS_BLOCK_RANGE;
|
||||||
const endBlock = Math.min(startBlock + logsBlockRange, processingEndBlockNumber);
|
let rangeEndBlock = startBlock + logsBlockRange;
|
||||||
|
|
||||||
|
if (this._jobQueueConfig.historicalLogsBlockRangeEndFactor) {
|
||||||
|
// Set rangeEndBlock to the next multiple of historicalLogsBlockRangeEndFactor after startBlock number
|
||||||
|
// For using aligned block ranges
|
||||||
|
rangeEndBlock = Math.ceil(startBlock / this._jobQueueConfig.historicalLogsBlockRangeEndFactor) * this._jobQueueConfig.historicalLogsBlockRangeEndFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const endBlock = Math.min(rangeEndBlock, processingEndBlockNumber);
|
||||||
log(`Processing historical blocks from ${startBlock} to ${endBlock}`);
|
log(`Processing historical blocks from ${startBlock} to ${endBlock}`);
|
||||||
|
|
||||||
const blocks = await fetchAndSaveFilteredLogsAndBlocks(
|
const blocks = await fetchAndSaveFilteredLogsAndBlocks(
|
||||||
|
Loading…
Reference in New Issue
Block a user