@@ -420,8 +420,10 @@ export class IndexerClient {
420420 return request
421421 }
422422
423- // If timeoutTimestamp is 0, request never times out
424423 if ( request . timeoutTimestamp === 0n ) {
424+ // Early exit for requests with no timeout configured
425+ // This prevents unnecessary timeout processing and expensive chain queries
426+ // The events array is still empty at this point, so no timeout events are added
425427 return addTimeoutEvents ( request )
426428 }
427429
@@ -432,7 +434,7 @@ export class IndexerClient {
432434
433435 const is_finished = request . statuses . find ( ( item ) => item . status === RequestStatus . DESTINATION )
434436
435- if ( ! is_finished ) {
437+ if ( ! is_finished && request . timeoutTimestamp > 0n ) {
436438 events . push ( {
437439 status : TimeoutStatus . PENDING_TIMEOUT ,
438440 metadata : { blockHash : "0x" , blockNumber : 0 , transactionHash : "0x" } ,
@@ -459,17 +461,17 @@ export class IndexerClient {
459461 chain : this . config . hyperbridge . stateMachineId ,
460462 } )
461463
462- if ( ! destFinalized ) return addTimeoutEvents ( request )
463-
464- events . push ( {
465- status : TimeoutStatus . DESTINATION_FINALIZED_TIMEOUT ,
466- metadata : {
467- blockHash : destFinalized . blockHash ,
468- blockNumber : destFinalized . blockNumber ,
469- transactionHash : destFinalized . transactionHash ,
470- timestamp : destFinalized . timestamp ,
471- } ,
472- } )
464+ if ( destFinalized && request . timeoutTimestamp > 0n ) {
465+ events . push ( {
466+ status : TimeoutStatus . DESTINATION_FINALIZED_TIMEOUT ,
467+ metadata : {
468+ blockHash : destFinalized . blockHash ,
469+ blockNumber : destFinalized . blockNumber ,
470+ transactionHash : destFinalized . transactionHash ,
471+ timestamp : destFinalized . timestamp ,
472+ } ,
473+ } )
474+ }
473475
474476 // if the source is the hyperbridge state machine, no further action is needed
475477 // use the timeout stream to timeout on hyperbridge
@@ -513,16 +515,18 @@ export class IndexerClient {
513515 ] ,
514516 } )
515517
516- events . push ( {
517- status : TimeoutStatus . HYPERBRIDGE_FINALIZED_TIMEOUT ,
518- metadata : {
519- blockHash : hyperbridgeFinalized . blockHash ,
520- blockNumber : hyperbridgeFinalized . blockNumber ,
521- transactionHash : hyperbridgeFinalized . transactionHash ,
522- timestamp : hyperbridgeFinalized . timestamp ,
523- calldata,
524- } ,
525- } )
518+ if ( request . timeoutTimestamp > 0n ) {
519+ events . push ( {
520+ status : TimeoutStatus . HYPERBRIDGE_FINALIZED_TIMEOUT ,
521+ metadata : {
522+ blockHash : hyperbridgeFinalized . blockHash ,
523+ blockNumber : hyperbridgeFinalized . blockNumber ,
524+ transactionHash : hyperbridgeFinalized . transactionHash ,
525+ timestamp : hyperbridgeFinalized . timestamp ,
526+ calldata,
527+ } ,
528+ } )
529+ }
526530
527531 return addTimeoutEvents ( request )
528532 }
@@ -589,7 +593,7 @@ export class IndexerClient {
589593 logger . trace ( "`Request` found" )
590594 const chain = await getChain ( this . config . dest )
591595 const timeoutStream =
592- request . timeoutTimestamp > 0 ? this . timeoutStream ( request . timeoutTimestamp , chain ) : undefined
596+ request . timeoutTimestamp > 0n ? this . timeoutStream ( request . timeoutTimestamp , chain ) : undefined
593597 const statusStream = this . postRequestStatusStreamInternal ( hash )
594598
595599 logger . trace ( "Listening for events" )
@@ -617,13 +621,7 @@ export class IndexerClient {
617621 async * timeoutStream ( timeoutTimestamp : bigint , chain : IChain ) : AsyncGenerator < RequestStatusWithMetadata , void > {
618622 const logger = this . logger . withTag ( "[timeoutStream()]" )
619623
620- // If timeoutTimestamp is 0, request never times out
621- if ( timeoutTimestamp === 0n ) {
622- logger . trace ( "Request has timeoutTimestamp = 0, never timing out" )
623- return
624- }
625-
626- if ( timeoutTimestamp > 0 ) {
624+ if ( timeoutTimestamp > 0n ) {
627625 let timestamp = await chain . timestamp ( )
628626
629627 while ( timestamp < timeoutTimestamp ) {
@@ -1082,12 +1080,6 @@ export class IndexerClient {
10821080 const request = await this . queryPostRequest ( hash )
10831081 if ( ! request ) throw new Error ( "Request not found" )
10841082
1085- // If timeoutTimestamp is 0, request never times out - end stream immediately
1086- if ( request . timeoutTimestamp === 0n ) {
1087- logger . trace ( "Request has timeoutTimestamp = 0, ending timeout stream" )
1088- return
1089- }
1090-
10911083 logger . trace ( "Reading destination chain" )
10921084 const destChain = await getChain ( this . config . dest )
10931085
0 commit comments