@@ -89,7 +89,7 @@ export abstract class BaseIndexerManager<
8989 const blockHeight = block . getHeader ( ) . blockHeight ;
9090 monitorWrite ( `- BlockHash: ${ block . getHeader ( ) . blockHash } ` ) ;
9191
92- let filteredDataSources = this . filterDataSources ( blockHeight , dataSources ) ;
92+ const filteredDataSources = this . filterDataSources ( blockHeight , dataSources ) ;
9393
9494 this . assertDataSources ( filteredDataSources , blockHeight ) ;
9595
@@ -125,11 +125,21 @@ export abstract class BaseIndexerManager<
125125 vm . freeze ( async ( templateName : string , index : number ) => {
126126 await this . dynamicDsService . destroyDynamicDatasource ( templateName , blockHeight , index ) ;
127127
128- // Re-filter datasources to exclude the destroyed one
129- // The destroyed datasource now has endBlock set, so filterDataSources will exclude it
130- // Note: Reassigning filteredDataSources is intentional - subsequent handlers
131- // within the same block will see the updated filtered list
132- filteredDataSources = this . filterDataSources ( blockHeight , filteredDataSources ) ;
128+ // Remove the destroyed datasource from the current processing array
129+ // Find the datasource by matching the global index stored in the service
130+ const destroyedDsParam = this . dynamicDsService . getDatasourceParamByIndex ( index ) ;
131+ if ( destroyedDsParam ) {
132+ const dsIndex = filteredDataSources . findIndex ( ( fds ) => {
133+ return (
134+ fds . startBlock === destroyedDsParam . startBlock &&
135+ JSON . stringify ( ( fds as any ) . options || ( fds as any ) . processor ?. options || { } ) ===
136+ JSON . stringify ( destroyedDsParam . args || { } )
137+ ) ;
138+ } ) ;
139+ if ( dsIndex !== - 1 ) {
140+ filteredDataSources . splice ( dsIndex , 1 ) ;
141+ }
142+ }
133143 } , 'destroyDynamicDatasource' ) ;
134144
135145 return vm ;
0 commit comments