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

Sync 2023/07/28 #71

Merged
merged 4 commits into from
Jul 28, 2023
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: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^2.3.0",
"@subql/common-algorand": "workspace:*",
"@subql/node-core": "^3.1.2",
"@subql/node-core": "^4.0.0",
"@subql/types-algorand": "workspace:*",
"@willsoto/nestjs-prometheus": "^4.4.0",
"algosdk": "^2.2.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/algorand/algorand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {
ApiService,
ConnectionPoolService,
ConnectionPoolStateManager,
NodeConfig,
} from '@subql/node-core';
import { GraphQLSchema } from 'graphql';
Expand Down Expand Up @@ -45,6 +46,7 @@
useFactory: () => testSubqueryProject(endpoint, chainId),
},
NodeConfig,
ConnectionPoolStateManager,
ConnectionPoolService,
AlgorandApiService,
],
Expand Down Expand Up @@ -111,7 +113,7 @@
};

expect(
filterTransaction(tx as any, {

Check warning on line 116 in packages/node/src/algorand/algorand.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
txType: 'acfg',
sender: '7JMGBIDKQRR4MC3DNC73QU4QUNNN43VNY5RYPN2FRWEG6NXAHQMCPD4BIQ',
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/algorand/api.service.algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AlgorandApiService extends ApiService<
);
}

this.connectionPoolService.addToConnections(connection, endpoint);
await this.connectionPoolService.addToConnections(connection, endpoint);
} catch (error) {
if (retries < maxRetries) {
retries++;
Expand Down
10 changes: 9 additions & 1 deletion packages/node/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ function warnDeprecations() {
@Global()
@Module({})
export class ConfigureModule {
static async register(): Promise<DynamicModule> {
static async getInstance(): Promise<{
config: NodeConfig;
project: () => Promise<SubqueryProject>;
}> {
const { argv } = yargsOptions;
let config: NodeConfig;
let rawManifest: unknown;
Expand Down Expand Up @@ -131,6 +134,11 @@ export class ConfigureModule {
return p;
};

return { config, project };
}
static async register(): Promise<DynamicModule> {
const { config, project } = await ConfigureModule.getInstance();

return {
module: ConfigureModule,
providers: [
Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/indexer/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import { INestApplication } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { Test } from '@nestjs/testing';
import { ConnectionPoolService, NodeConfig } from '@subql/node-core';
import {
ConnectionPoolService,
ConnectionPoolStateManager,
NodeConfig,
} from '@subql/node-core';
import { GraphQLSchema } from 'graphql';
import { AlgorandApiService } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand Down Expand Up @@ -43,6 +47,7 @@ describe('ApiService', () => {
provide: 'ISubqueryProject',
useFactory: () => testSubqueryProject(endpoint),
},
ConnectionPoolStateManager,
ConnectionPoolService,
NodeConfig,
AlgorandApiService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import {
HostDynamicDS,
WorkerBlockDispatcher,
IUnfinalizedBlocksService,
HostConnectionPoolState,
ConnectionPoolStateManager,
connectionPoolStateHostFunctions,
} from '@subql/node-core';
import { Store } from '@subql/types';
import { AlgorandApiConnection } from '../../algorand';
import {
SubqlProjectDs,
SubqueryProject,
Expand All @@ -37,11 +41,16 @@ async function createIndexerWorker(
store: Store,
dynamicDsService: IDynamicDsService<SubqlProjectDs>,
unfinalizedBlocksService: IUnfinalizedBlocksService<BlockContent>,
connectionPoolState: ConnectionPoolStateManager<AlgorandApiConnection>,
root: string,
): Promise<IndexerWorker> {
const indexerWorker = Worker.create<
IInitIndexerWorker,
HostDynamicDS<SubqlProjectDs> & HostStore & HostUnfinalizedBlocks
// HostDynamicDS<SubqlProjectDs> & HostStore & HostUnfinalizedBlocks
HostDynamicDS<SubqlProjectDs> &
HostStore &
HostUnfinalizedBlocks &
HostConnectionPoolState<AlgorandApiConnection>
>(
path.resolve(__dirname, '../../../dist/indexer/worker/worker.js'),
[
Expand Down Expand Up @@ -71,6 +80,7 @@ async function createIndexerWorker(
unfinalizedBlocksService.processUnfinalizedBlockHeader.bind(
unfinalizedBlocksService,
),
...connectionPoolStateHostFunctions(connectionPoolState),
},
root,
);
Expand All @@ -96,6 +106,7 @@ export class WorkerBlockDispatcherService
@Inject('ISubqueryProject') project: SubqueryProject,
dynamicDsService: DynamicDsService,
unfinalizedBlocksService: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<AlgorandApiConnection>,
) {
super(
nodeConfig,
Expand All @@ -112,6 +123,7 @@ export class WorkerBlockDispatcherService
storeService.getStore(),
dynamicDsService,
unfinalizedBlocksService,
connectionPoolState,
project.root,
),
);
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
StoreCacheService,
PgMmrCacheService,
MmrQueryService,
ConnectionPoolStateManager,
} from '@subql/node-core';
import { AlgorandApiConnection, AlgorandApiService } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand Down Expand Up @@ -62,6 +63,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
inject: ['ISubqueryProject', ConnectionPoolService, EventEmitter2],
},
IndexerManager,
ConnectionPoolStateManager,
{
provide: 'IBlockDispatcher',
useFactory: (
Expand All @@ -77,6 +79,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
project: SubqueryProject,
dynamicDsService: DynamicDsService,
unfinalizedBlocksService: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<AlgorandApiConnection>,
) =>
nodeConfig.workers !== undefined
? new WorkerBlockDispatcherService(
Expand All @@ -90,6 +93,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
project,
dynamicDsService,
unfinalizedBlocksService,
connectionPoolState,
)
: new BlockDispatcherService(
apiService,
Expand Down Expand Up @@ -117,9 +121,11 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
'ISubqueryProject',
DynamicDsService,
UnfinalizedBlocksService,
ConnectionPoolStateManager,
],
},
FetchService,
ConnectionPoolService,
IndexingBenchmarkService,
PoiBenchmarkService,
DictionaryService,
Expand Down
11 changes: 11 additions & 0 deletions packages/node/src/indexer/indexer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
WorkerDynamicDsService,
PgMmrCacheService,
MmrQueryService,
ConnectionPoolStateManager,
WorkerConnectionPoolStateManager,
} from '@subql/node-core';
import { AlgorandApiService, AlgorandApiConnection } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand All @@ -29,6 +31,15 @@ import { WorkerService } from './worker/worker.service';
IndexerManager,
StoreCacheService,
StoreService,
{
provide: ConnectionPoolStateManager,
useFactory: () => {
if (isMainThread) {
throw new Error('Expected to be worker thread');
}
return new WorkerConnectionPoolStateManager((global as any).host);
},
},
ConnectionPoolService,
UnfinalizedBlocksService,
{
Expand Down
19 changes: 17 additions & 2 deletions packages/node/src/indexer/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
hostDynamicDsKeys,
HostDynamicDS,
ProcessBlockResponse,
HostConnectionPoolState,
hostConnectionPoolStateKeys,
} from '@subql/node-core';
import { AlgorandApiConnection } from '../../algorand';
import { SubqlProjectDs } from '../../configure/SubqueryProject';
import { IndexerManager } from '../indexer.manager';
import { WorkerModule } from './worker.module';
Expand All @@ -40,6 +43,10 @@ import {
WorkerService,
WorkerStatusResponse,
} from './worker.service';
import {
HostUnfinalizedBlocks,
hostUnfinalizedBlocksKeys,
} from './worker.unfinalizedBlocks.service';
let app: INestApplication;
let workerService: WorkerService;

Expand Down Expand Up @@ -116,10 +123,18 @@ async function waitForWorkerBatchSize(heapSizeInBytes: number): Promise<void> {

// Register these functions to be exposed to worker host
(global as any).host = WorkerHost.create<
HostStore & HostDynamicDS<SubqlProjectDs>,
HostStore &
HostDynamicDS<SubqlProjectDs> &
HostUnfinalizedBlocks &
HostConnectionPoolState<AlgorandApiConnection>,
IInitIndexerWorker
>(
[...hostStoreKeys, ...hostDynamicDsKeys],
[
...hostStoreKeys,
...hostDynamicDsKeys,
...hostUnfinalizedBlocksKeys,
...hostConnectionPoolStateKeys,
],
{
initWorker,
fetchBlock,
Expand Down
3 changes: 0 additions & 3 deletions packages/node/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export async function bootstrap(): Promise<void> {

const projectService = app.get('IProjectService');
const fetchService = app.get(FetchService);
const apiService = app.get(AlgorandApiService);

// Initialise async services, we do this here rather than in factories, so we can capture one off events
await apiService.init();
await projectService.init();
await fetchService.init(projectService.startHeight);

Expand Down
22 changes: 5 additions & 17 deletions packages/node/src/subcommands/testing.init.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { NestFactory } from '@nestjs/core';
import { getLogger, NestLogger } from '@subql/node-core';
import { AlgorandApiService } from '../algorand';
import { ProjectService } from '../indexer/project.service';
import { TestingModule } from './testing.module';
import { getLogger } from '@subql/node-core';
import { ConfigureModule } from '../configure/configure.module';
import { TestingService } from './testing.service';

const logger = getLogger('Testing');
export async function testingInit(): Promise<void> {
try {
const app = await NestFactory.create(TestingModule, {
logger: new NestLogger(),
});
const { config, project } = await ConfigureModule.getInstance();
const subqueryProject = await project();

await app.init();
const projectService = app.get(ProjectService);
const apiService = app.get(AlgorandApiService);

// Initialise async services, we do this here rather than in factories, so we can capture one off events
await apiService.init();
await projectService.init();

const testingService = app.get(TestingService);
const testingService = new TestingService(config, subqueryProject);
await testingService.init();
await testingService.run();
} catch (e) {
Expand Down
13 changes: 13 additions & 0 deletions packages/node/src/subcommands/testing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NodeConfig,
PoiService,
StoreService,
TestRunner,
} from '@subql/node-core';
import { AlgorandApiConnection, AlgorandApiService } from '../algorand';
import { ConfigureModule } from '../configure/configure.module';
Expand All @@ -20,6 +21,7 @@ import { FetchModule } from '../indexer/fetch.module';
import { IndexerManager } from '../indexer/indexer.manager';
import { ProjectService } from '../indexer/project.service';
import { SandboxService } from '../indexer/sandbox.service';
import { UnfinalizedBlocksService } from '../indexer/unfinalizedBlocks.service';
import { MetaModule } from '../meta/meta.module';
import { TestingService } from './testing.service';

Expand All @@ -33,6 +35,7 @@ import { TestingService } from './testing.service';
DsProcessorService,
DynamicDsService,
ProjectService,
UnfinalizedBlocksService,
ConnectionPoolService,
{
provide: 'IProjectService',
Expand All @@ -57,10 +60,20 @@ import { TestingService } from './testing.service';
},
IndexerManager,
SchedulerRegistry,
TestRunner,
{
provide: 'IApi',
useClass: AlgorandApiService,
},
{
provide: 'IIndexerManager',
useClass: IndexerManager,
},
],

imports: [MetaModule, FetchModule],
controllers: [],
exports: [TestRunner],
})
export class TestingFeatureModule {}

Expand Down
Loading
Loading