From a0221df6361989775d78ef9589e159dc0e2d15a3 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Tue, 26 Nov 2024 12:36:00 +1300 Subject: [PATCH] Fix monitor write with workers, fix events iteration --- .../src/indexer/worker/worker.monitor.service.ts | 8 +++++--- packages/node/src/indexer/indexer.manager.ts | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/node-core/src/indexer/worker/worker.monitor.service.ts b/packages/node-core/src/indexer/worker/worker.monitor.service.ts index 62be0f64fb..57fa1b5add 100644 --- a/packages/node-core/src/indexer/worker/worker.monitor.service.ts +++ b/packages/node-core/src/indexer/worker/worker.monitor.service.ts @@ -14,7 +14,7 @@ export const hostMonitorKeys: (keyof HostMonitorService)[] = ['hostMonitorServic export function monitorHostFunctions(host: MonitorServiceInterface): HostMonitorService { return { - hostMonitorServiceWrite: host.write.bind(host), + hostMonitorServiceWrite: host?.write.bind(host), }; } @@ -27,8 +27,10 @@ export class WorkerMonitorService implements MonitorServiceInterface { setMonitorService(this); } - write(blockData: string): void { - return this.host?.hostMonitorServiceWrite ? this.host.hostMonitorServiceWrite(blockData) : undefined; + write(blockData: string | (() => string)): void { + return this.host?.hostMonitorServiceWrite + ? this.host.hostMonitorServiceWrite(typeof blockData === 'string' ? blockData : blockData()) + : undefined; } createBlockFork(blockHeight: number): void { diff --git a/packages/node/src/indexer/indexer.manager.ts b/packages/node/src/indexer/indexer.manager.ts index dde11c5be7..bc19f5ffed 100644 --- a/packages/node/src/indexer/indexer.manager.ts +++ b/packages/node/src/indexer/indexer.manager.ts @@ -119,7 +119,7 @@ export class IndexerManager extends BaseIndexerManager< const idx = evt.extrinsic.idx; acc[idx] ??= []; acc[idx].push(evt); - } else { + } else if (!evt.phase.isApplyExtrinsic) { logger.warn( `Unrecognized event type, skipping. block="${block.block.header.number.toNumber()}" eventIdx="${idx}"`, ); @@ -141,9 +141,9 @@ export class IndexerManager extends BaseIndexerManager< await this.indexExtrinsic(extrinsic, dataSources, getVM); // Process extrinsic events - const extrinsicEvents = events - .filter((e) => e.extrinsic?.idx === extrinsic.idx) - .sort((a, b) => a.idx - b.idx); + const extrinsicEvents = (groupedEvents[extrinsic.idx] ?? []).sort( + (a, b) => a.idx - b.idx, + ); for (const event of extrinsicEvents) { await this.indexEvent(event, dataSources, getVM);