Skip to content

Commit 1382702

Browse files
committed
fix: refiltering datasorces and adding a test case to it
1 parent 54eb623 commit 1382702

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

packages/node-core/src/indexer/dynamic-ds.service.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,25 @@ describe('DynamicDsService', () => {
435435
'Datasource at index 2 has template name "Other", not "Test"'
436436
);
437437
});
438+
439+
it('sets endBlock correctly allowing in-place removal during block processing', async () => {
440+
const meta = mockMetadata([testParam1, testParam2, testParam3]);
441+
await service.init(meta);
442+
443+
// Destroy datasource at index 1 at block 50
444+
await service.destroyDynamicDatasource('Test', 50, 1);
445+
446+
// Verify the datasource has endBlock set
447+
const dsParam = service.getDatasourceParamByIndex(1);
448+
expect(dsParam).toBeDefined();
449+
expect(dsParam?.endBlock).toBe(50);
450+
expect(dsParam?.startBlock).toBe(2);
451+
expect(dsParam?.templateName).toBe('Test');
452+
453+
// Verify the internal _datasources array also has endBlock set
454+
const datasources = (service as any)._datasources;
455+
expect(datasources[1]).toBeDefined();
456+
expect((datasources[1] as any).endBlock).toBe(50);
457+
});
438458
});
439459
});

packages/node-core/src/indexer/indexer.manager.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)