Skip to content

Commit

Permalink
remove unnecessary service injection for worker
Browse files Browse the repository at this point in the history
  • Loading branch information
guplersaxanoid committed Sep 27, 2023
1 parent c0bfc44 commit 89dbf3a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/node/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node -r dotenv/config -r tsconfig-paths/register -r ts-node/register src/main.ts"
"exec": "node --trace-exit --trace-sigint --trace-warnings --trace-uncaught --trace-deprecation -r dotenv/config -r tsconfig-paths/register -r ts-node/register src/main.ts"
}
11 changes: 10 additions & 1 deletion packages/node/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ export class ConfigureModule {
provide: 'IProjectUpgradeService',
useValue: project,
},
{
provide: 'Null',
useValue: null,
},
],
exports: [
NodeConfig,
'ISubqueryProject',
'IProjectUpgradeService',
'Null',
],
exports: [NodeConfig, 'ISubqueryProject', 'IProjectUpgradeService'],
};
}
}
9 changes: 6 additions & 3 deletions packages/node/src/indexer/project.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { isMainThread } from 'worker_threads';
import { Inject, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {
Expand All @@ -9,6 +10,7 @@ import {
StoreService,
NodeConfig,
IProjectUpgradeService,
mainThreadOnly,
} from '@subql/node-core';
import { Sequelize } from '@subql/x-sequelize';
import { AlgorandApiService } from '../algorand';
Expand All @@ -33,12 +35,12 @@ export class ProjectService extends BaseProjectService<
constructor(
dsProcessorService: DsProcessorService,
apiService: AlgorandApiService,
poiService: PoiService,
sequelize: Sequelize,
@Inject(isMainThread ? PoiService : 'Null') poiService: PoiService,
@Inject(isMainThread ? Sequelize : 'Null') sequelize: Sequelize,
@Inject('ISubqueryProject') project: SubqueryProject,
@Inject('IProjectUpgradeService')
protected readonly projectUpgradeService: IProjectUpgradeService<SubqueryProject>,
storeService: StoreService,
@Inject(isMainThread ? StoreService : 'Null') storeService: StoreService,
nodeConfig: NodeConfig,
dynamicDsService: DynamicDsService,
eventEmitter: EventEmitter2,
Expand All @@ -65,6 +67,7 @@ export class ProjectService extends BaseProjectService<
return new Date(block.timestamp);
}

@mainThreadOnly()
protected onProjectChange(project: SubqueryProject): void | Promise<void> {
// TODO update this when implementing skipBlock feature for Eth
// this.apiService.updateBlockFetching();
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/indexer/sandbox.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class SandboxService<Api> {

constructor(
private readonly apiService: AlgorandApiService,
@Inject(isMainThread ? StoreService : 'Null')
private readonly storeService: StoreService,
private readonly nodeConfig: NodeConfig,
@Inject('ISubqueryProject') private readonly project: ISubqueryProject,
Expand Down
5 changes: 5 additions & 0 deletions packages/node/src/indexer/unfinalizedBlocks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Header,
NodeConfig,
StoreCacheService,
mainThreadOnly,
} from '@subql/node-core';
import { AlgorandApiService } from '../algorand';
import { BlockContent } from './types';
Expand All @@ -29,20 +30,24 @@ export class UnfinalizedBlocksService extends BaseUnfinalizedBlocksService<Block
super(nodeConfig, storeCache);
}

@mainThreadOnly()
protected blockToHeader(block: BlockContent): Header {
return algorandBlockToHeader(block);
}

@mainThreadOnly()
protected async getFinalizedHead(): Promise<Header> {
const checkHealth = await this.apiService.api.api.makeHealthCheck().do();
const latestHeight = checkHealth.round;
return this.getHeaderForHeight(latestHeight);
}

@mainThreadOnly()
protected async getHeaderForHash(hash: string): Promise<Header> {
return this.getHeaderForHeight(parseInt(hash, 10));
}

@mainThreadOnly()
protected async getHeaderForHeight(height: number): Promise<Header> {
return algorandBlockToHeader(
await this.apiService.api.getBlockByHeight(height),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@ import { isMainThread } from 'worker_threads';
import { Module } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {
StoreService,
PoiService,
ConnectionPoolService,
StoreCacheService,
WorkerDynamicDsService,
ConnectionPoolStateManager,
WorkerConnectionPoolStateManager,
} from '@subql/node-core';
import { AlgorandApiService, AlgorandApiConnection } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
import { DsProcessorService } from './ds-processor.service';
import { DynamicDsService } from './dynamic-ds.service';
import { IndexerManager } from './indexer.manager';
import { ProjectService } from './project.service';
import { SandboxService } from './sandbox.service';
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
import { WorkerService } from './worker/worker.service';
import { AlgorandApiService, AlgorandApiConnection } from '../../algorand';
import { SubqueryProject } from '../../configure/SubqueryProject';
import { DsProcessorService } from '../ds-processor.service';
import { DynamicDsService } from '../dynamic-ds.service';
import { IndexerManager } from '../indexer.manager';
import { ProjectService } from '../project.service';
import { SandboxService } from '../sandbox.service';
import { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';
import { WorkerService } from './worker.service';

@Module({
providers: [
IndexerManager,
StoreCacheService,
StoreService,
{
provide: ConnectionPoolStateManager,
useFactory: () => {
Expand Down Expand Up @@ -67,13 +62,12 @@ import { WorkerService } from './worker/worker.service';
return new WorkerDynamicDsService((global as any).host);
},
},
PoiService,
{
provide: 'IProjectService',
useClass: ProjectService,
},
WorkerService,
],
exports: [StoreService],
exports: [],
})
export class IndexerModule {}
export class WorkerFetchModule {}
4 changes: 2 additions & 2 deletions packages/node/src/indexer/worker/worker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
import { ScheduleModule } from '@nestjs/schedule';
import { DbModule } from '@subql/node-core';
import { ConfigureModule } from '../../configure/configure.module';
import { IndexerModule } from '../indexer.module';
import { WorkerFetchModule } from './worker-fetch.module';

@Module({
imports: [
DbModule.forRoot(),
EventEmitterModule.forRoot(),
ConfigureModule.register(),
ScheduleModule.forRoot(),
IndexerModule,
WorkerFetchModule,
],
controllers: [],
})
Expand Down

0 comments on commit 89dbf3a

Please sign in to comment.