@@ -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 ( / \[ ( 0 x [ 0 - 9 a - f A - F ] + ) , \s * ( 0 x [ 0 - 9 a - f A - 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