mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-30 03:32:07 +00:00
Avoid historical sync for block handlers and eth_getLogs without event handlers
This commit is contained in:
parent
981f70ec9b
commit
115c9de0f0
@ -60,6 +60,9 @@ export class GraphWatcher {
|
||||
|
||||
_context: Context;
|
||||
|
||||
_blockHandlerExists = false;
|
||||
_eventHandlerExists = false;
|
||||
|
||||
constructor (database: GraphDatabase, ethClient: EthClient, ethProvider: providers.BaseProvider, serverConfig: ServerConfig) {
|
||||
this._database = database;
|
||||
this._ethClient = ethClient;
|
||||
@ -110,6 +113,10 @@ export class GraphWatcher {
|
||||
};
|
||||
}, {});
|
||||
|
||||
// Check if handlers exist for deciding watcher behaviour
|
||||
this._blockHandlerExists = this._dataSources.some(dataSource => Boolean(dataSource.mapping.blockHandlers));
|
||||
this._eventHandlerExists = this._dataSources.some(dataSource => Boolean(dataSource.mapping.eventHandlers));
|
||||
|
||||
const data = await Promise.all(dataPromises);
|
||||
|
||||
// Create a map from dataSource contract address to instance and contract interface.
|
||||
@ -151,6 +158,14 @@ export class GraphWatcher {
|
||||
return this._dataSources;
|
||||
}
|
||||
|
||||
get blockHandlerExists (): boolean {
|
||||
return this._blockHandlerExists;
|
||||
}
|
||||
|
||||
get eventHandlerExists (): boolean {
|
||||
return this._eventHandlerExists;
|
||||
}
|
||||
|
||||
async addContracts () {
|
||||
assert(this._indexer);
|
||||
assert(this._indexer.watchContract);
|
||||
|
@ -123,9 +123,15 @@ export class EventWatcher {
|
||||
startBlockNumber = syncStatus.chainHeadBlockNumber + 1;
|
||||
}
|
||||
|
||||
// Check if filter for logs is enabled
|
||||
// Check if starting block for watcher is before latest canonical block
|
||||
if (this._config.jobQueue.useBlockRanges && startBlockNumber < latestCanonicalBlockNumber) {
|
||||
// Perform checks before starting historical block processing
|
||||
if (
|
||||
// Check if useBlockRanges is enabled for historical blocks processing
|
||||
this._config.jobQueue.useBlockRanges &&
|
||||
// Check if starting block for watcher is before latest canonical block
|
||||
startBlockNumber < latestCanonicalBlockNumber &&
|
||||
// Check if any block handler exists in subgraph config
|
||||
!this._indexer.graphWatcher?.blockHandlerExists
|
||||
) {
|
||||
await this.startHistoricalBlockProcessing(startBlockNumber, latestCanonicalBlockNumber);
|
||||
|
||||
return;
|
||||
|
@ -288,6 +288,7 @@ export interface GraphDatabaseInterface {
|
||||
}
|
||||
|
||||
export interface GraphWatcherInterface {
|
||||
readonly blockHandlerExists: boolean;
|
||||
init (): Promise<void>;
|
||||
setIndexer (indexer: IndexerInterface): void;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user