Skip to content

Commit b456665

Browse files
committed
Removing error parsing. Adopting 2000 range instead
1 parent 594f14d commit b456665

2 files changed

Lines changed: 12 additions & 24 deletions

File tree

src/config/config.local.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
},
3838

3939
polygon: {
40-
enabled: true,
40+
enabled: false,
4141
networkId: 80002,
4242
rpcEndpoint: 'wss://polygon-amoy.g.alchemy.com/v2/#ALCHEMY_API_KEY#',
4343
rpcMaxBlockRange: 1_296_000, // 30 days - Range not limited, only limited by number of logs returned

src/ethers.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export async function safeQueryFilter(
285285
toBlock: number,
286286
): Promise<Array<Event>> {
287287
const allEvents: Event[] = [];
288+
const MAX_RANGE = 2000;
288289
let currentStart = fromBlock;
289290

290291
// Loop until we’ve queried the full range of blocks
@@ -301,32 +302,19 @@ export async function safeQueryFilter(
301302
allEvents.push(...eventsChunk);
302303
break;
303304
} catch (err: any) {
304-
console.warn('ITEST ', err);
305-
// Retry only if failed from query timeout error.
306-
const message = err?.message ?? '';
307-
if (!(typeof message === 'string' && message.includes('Query timeout exceeded'))) {
308-
console.error('QueryFilter Unexpected Error, giving up:', err);
309-
throw err;
310-
}
311-
312-
// Sets the suggested range, otherwise halves the range.
313-
const match = message.match(/\[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/);
314-
if (match) {
315-
const suggestedEnd = parseInt(match[2], 16);
305+
console.warn('ITEST Query filter failed', err);
316306

317-
if (parseInt(match[1], 16) === currentStart && suggestedEnd < currentEnd) {
318-
console.warn(`QueryFilter Timeout - using suggested range: ${currentStart}-${suggestedEnd}`);
319-
currentEnd = suggestedEnd;
320-
}
307+
// Fail if minimum window is reached
308+
if (currentEnd - currentStart <= 8) {
309+
// eslint-disable-next-line
310+
console.error('ITEST Query filter failed with the smallest window, giving up.', currentStart, currentEnd);
311+
throw err;
312+
} else if (currentEnd - currentStart > MAX_RANGE) {
313+
currentEnd = currentStart + MAX_RANGE;
314+
console.warn('ITEST Query filter failed retrying with rage of 2000.', currentStart, currentEnd);
321315
} else {
322-
// Fail if minimum window is reached
323-
if (currentEnd - currentStart < 1) {
324-
// eslint-disable-next-line
325-
console.error('QueryFilter failed with the smallest window, giving up.', currentStart, currentEnd);
326-
throw err;
327-
}
328-
console.warn('QueryFilter Timeout - retrying with halved range');
329316
currentEnd = Math.floor((currentEnd - currentStart) / 2) + currentStart;
317+
console.warn('ITEST Query filter failed retrying with halved range.', currentStart, currentEnd);
330318
}
331319
}
332320
}

0 commit comments

Comments
 (0)