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 <neeraj.rtly@gmail.com>
This commit is contained in:
Nabarun Gogoi 2023-11-21 14:14:36 +05:30 committed by GitHub
parent d0aca37a74
commit 4a88ff76e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -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!'
}
});

View File

@ -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);