Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitor write with workers, fix events iteration #2607

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Workers crashing because of lazy monitor write (#2607)

## [15.0.2] - 2024-11-26
### Fixed
Expand Down
14 changes: 8 additions & 6 deletions packages/node-core/src/indexer/worker/worker.monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ import {setMonitorService} from '../../process';
import {MonitorServiceInterface} from '../monitor.service';

type HostMonitorService = {
hostMonitorServiceWrite: (blockData: string) => void;
hostMonitorServiceWrite?: (blockData: string) => void;
};

export const hostMonitorKeys: (keyof HostMonitorService)[] = ['hostMonitorServiceWrite'];

export function monitorHostFunctions(host: MonitorServiceInterface): HostMonitorService {
export function monitorHostFunctions(host?: MonitorServiceInterface): HostMonitorService {
return {
hostMonitorServiceWrite: host.write.bind(host),
hostMonitorServiceWrite: host?.write.bind(host),
};
}

@Injectable()
export class WorkerMonitorService implements MonitorServiceInterface {
constructor(private host: HostMonitorService) {
constructor(private host?: HostMonitorService) {
if (isMainThread) {
throw new Error('Expected to be worker thread');
}
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
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Not using grouped events (#2607)

## [5.4.1] - 2024-11-26
### Fixed
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
Loading