diff --git a/packages/codegen/src/schema.ts b/packages/codegen/src/schema.ts index c6f438e4..f5a56de9 100644 --- a/packages/codegen/src/schema.ts +++ b/packages/codegen/src/schema.ts @@ -587,7 +587,11 @@ export class Schema { latestIndexedBlockHash: 'String!', latestIndexedBlockNumber: 'Int!', latestCanonicalBlockHash: 'String!', - latestCanonicalBlockNumber: 'Int!' + latestCanonicalBlockNumber: 'Int!', + initialIndexedBlockHash: 'String!', + initialIndexedBlockNumber: 'Int!', + latestProcessedBlockHash: 'String!', + latestProcessedBlockNumber: 'Int!' } }); diff --git a/packages/codegen/src/templates/resolvers-template.handlebars b/packages/codegen/src/templates/resolvers-template.handlebars index 9f769744..fd4f99ae 100644 --- a/packages/codegen/src/templates/resolvers-template.handlebars +++ b/packages/codegen/src/templates/resolvers-template.handlebars @@ -157,9 +157,14 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher gqlTotalQueryCount.inc(1); gqlQueryCount.labels('eventsInRange').inc(1); - const { expected, actual } = await indexer.getProcessedBlockCountForRange(fromBlockNumber, toBlockNumber); - if (expected !== actual) { - throw new Error(`Range not available, expected ${expected}, got ${actual} blocks in range`); + const syncStatus = await indexer.getSyncStatus(); + + if (!syncStatus) { + throw new Error('No blocks processed yet'); + } + + if ((fromBlockNumber < syncStatus.initialIndexedBlockNumber) || (toBlockNumber > syncStatus.latestProcessedBlockNumber)) { + throw new Error(`Block range should be between ${syncStatus.initialIndexedBlockNumber} and ${syncStatus.latestProcessedBlockNumber}`); } const events = await indexer.getEventsInRange(fromBlockNumber, toBlockNumber);