Skip to content

Commit

Permalink
Fix monitor write with workers, fix events iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Nov 25, 2024
1 parent 085765b commit a0221df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/indexer/indexer.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`,
);
Expand All @@ -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);
Expand Down

0 comments on commit a0221df

Please sign in to comment.