From 4a88ff76e017f32ceb514e7444bd498b14403a27 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Tue, 21 Nov 2023 14:14:36 +0530 Subject: [PATCH] Remove check for blocks count in `eventsInRange` query and check sync status instead (#482) * Add check for from and to block in eventsInRange query * Update sync status query for more fields --------- Co-authored-by: neeraj --- packages/codegen/src/schema.ts | 6 +++++- .../src/templates/resolvers-template.handlebars | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) 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);