Skip to content

Commit

Permalink
admin api (#293)
Browse files Browse the repository at this point in the history
* admin api

* update dependencies
  • Loading branch information
jiqiang90 authored Jun 5, 2024
1 parent cd4b50d commit 503cdbc
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 28 deletions.
3 changes: 3 additions & 0 deletions packages/common-ethereum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Add default value in model class to follow ES2022 rule

## [3.6.1] - 2024-05-27
### Changed
- Update ejs dependency (#287)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {
BaseDeploymentV1_0_0,
CommonProjectNetworkV1_0_0,
FileType,
ParentProjectModel,
ProjectManifestBaseImpl,
Expand Down Expand Up @@ -41,7 +40,7 @@ export class EthereumRunnerNodeImpl extends RunnerNodeImpl {
@IsIn([Ethereum_NODE_NAME, Flare_NODE_NAME], {
message: `Runner Substrate node name incorrect, suppose be '${Ethereum_NODE_NAME}'`,
})
name: string;
name: string = Ethereum_NODE_NAME;
}

function validateObject(object: any, errorMessage = 'failed to validate object.'): void {
Expand Down Expand Up @@ -165,7 +164,7 @@ export class ProjectManifestV1_0_0Impl
}

@Equals('1.0.0')
specVersion: string;
specVersion = '1.0.0';
@Type(() => EthereumCustomDataSourceImpl, {
discriminator: {
property: 'kind',
Expand Down
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add monitor service to record block indexing actions in order to improve POI accuracy, and provide debug info for Admin api

## [4.3.2] - 2024-05-27
### Fixed
- Wrong value being injected for unsafeApi into sandbox (#291)
Expand Down
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": "^3.5.1",
"@subql/common-ethereum": "workspace:*",
"@subql/node-core": "^10.3.2",
"@subql/node-core": "10.4.0",
"@subql/testing": "^2.1.1",
"@subql/types-ethereum": "workspace:*",
"cacheable-lookup": "6",
Expand Down
13 changes: 13 additions & 0 deletions packages/node/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
import { adminControllers, adminServices } from '@subql/node-core/dist/admin';
import { FetchModule } from '../indexer/fetch.module';

@Module({
imports: [FetchModule],
controllers: [...adminControllers],
providers: [...adminServices],
})
export class AdminModule {}
2 changes: 2 additions & 0 deletions packages/node/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { ScheduleModule } from '@nestjs/schedule';
import { DbModule } from '@subql/node-core';
import { AdminModule } from './admin/admin.module';
import { ConfigureModule } from './configure/configure.module';
import { FetchModule } from './indexer/fetch.module';
import { MetaModule } from './meta/meta.module';
Expand All @@ -17,6 +18,7 @@ import { MetaModule } from './meta/meta.module';
ScheduleModule.forRoot(),
FetchModule,
MetaModule,
AdminModule,
],
controllers: [],
})
Expand Down
7 changes: 5 additions & 2 deletions packages/node/src/ethereum/api.service.ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NodeConfig,
profilerWrap,
IBlock,
exitWithError,
} from '@subql/node-core';
import {
EthereumBlock,
Expand Down Expand Up @@ -56,8 +57,10 @@ export class EthereumApiService extends ApiService<
try {
network = this.project.network;
} catch (e) {
logger.error(Object.keys(e));
process.exit(1);
exitWithError(
new Error(`Failed to init api`, { cause: Object.keys(e) }),
logger,
);
}

const endpoints = Array.isArray(network.endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PoiSyncService,
InMemoryCacheService,
createIndexerWorker,
MonitorServiceInterface,
} from '@subql/node-core';
import { EthereumBlock } from '@subql/types-ethereum';
import {
Expand Down Expand Up @@ -51,6 +52,7 @@ export class WorkerBlockDispatcherService
dynamicDsService: DynamicDsService,
unfinalizedBlocksSevice: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,
monitorService?: MonitorServiceInterface,
) {
super(
nodeConfig,
Expand All @@ -77,7 +79,9 @@ export class WorkerBlockDispatcherService
connectionPoolState,
project.root,
projectService.startHeight,
monitorService,
),
monitorService,
);
}

Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PoiSyncService,
InMemoryCacheService,
SandboxService,
MonitorService,
} from '@subql/node-core';
import { SubqueryProject } from '../configure/SubqueryProject';
import { EthereumApiConnection } from '../ethereum/api.connection';
Expand Down Expand Up @@ -82,6 +83,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService: DynamicDsService,
unfinalizedBlocks: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,
monitorService?: MonitorService,
) =>
nodeConfig.workers
? new WorkerBlockDispatcherService(
Expand All @@ -97,6 +99,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService,
unfinalizedBlocks,
connectionPoolState,
monitorService,
)
: new BlockDispatcherService(
apiService,
Expand Down Expand Up @@ -125,6 +128,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
DynamicDsService,
UnfinalizedBlocksService,
ConnectionPoolStateManager,
MonitorService,
],
},
FetchService,
Expand All @@ -141,8 +145,9 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
useClass: ProjectService,
provide: 'IProjectService',
},
MonitorService,
UnfinalizedBlocksService,
],
exports: [StoreService, StoreCacheService],
exports: [StoreService, StoreCacheService, MonitorService, PoiService],
})
export class FetchModule {}
6 changes: 6 additions & 0 deletions packages/node/src/indexer/worker/worker-fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
WorkerInMemoryCacheService,
WorkerUnfinalizedBlocksService,
SandboxService,
MonitorService,
WorkerMonitorService,
} from '@subql/node-core';
import { SubqueryProject } from '../../configure/SubqueryProject';
import { EthereumApiService } from '../../ethereum';
Expand Down Expand Up @@ -74,6 +76,10 @@ import { WorkerService } from './worker.service';
new WorkerUnfinalizedBlocksService((global as any).host),
},
WorkerService,
{
provide: MonitorService,
useFactory: () => new WorkerMonitorService((global as any).host),
},
{
provide: InMemoryCacheService,
useFactory: () => new WorkerInMemoryCacheService((global as any).host),
Expand Down
9 changes: 4 additions & 5 deletions packages/node/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { NestFactory } from '@nestjs/core';
import { findAvailablePort, notifyUpdates } from '@subql/common';
import { getLogger, NestLogger } from '@subql/node-core';
import { exitWithError, getLogger, NestLogger } from '@subql/node-core';
import { AppModule } from './app.module';
import { FetchService } from './indexer/fetch.service';
import { ProjectService } from './indexer/project.service';
Expand All @@ -28,12 +28,12 @@ export async function bootstrap(): Promise<void> {

const port = validate(argv.port) ?? (await findAvailablePort(DEFAULT_PORT));
if (!port) {
logger.error(
exitWithError(
`Unable to find available port (tried ports in range (${port}..${
port + 10
})). Try setting a free port manually by setting the --port flag`,
logger,
);
process.exit(1);
}

if (argv.unsafe) {
Expand Down Expand Up @@ -61,7 +61,6 @@ export async function bootstrap(): Promise<void> {

logger.info(`Node started on port: ${port}`);
} catch (e) {
logger.error(e, 'Node failed to start');
process.exit(1);
exitWithError(new Error('Node failed to start', { cause: e }), logger);
}
}
5 changes: 2 additions & 3 deletions packages/node/src/subcommands/testing.init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { getLogger } from '@subql/node-core';
import { exitWithError, getLogger } from '@subql/node-core';
import { ConfigureModule } from '../configure/configure.module';
import { TestingService } from './testing.service';

Expand All @@ -13,8 +13,7 @@ export async function testingInit(): Promise<void> {
const testingService = new TestingService(nodeConfig, project);
await testingService.run();
} catch (e) {
logger.error(e, 'Testing failed');
process.exit(1);
exitWithError(new Error('Testing failed', { cause: e }), logger);
}
process.exit(0);
}
1 change: 0 additions & 1 deletion packages/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2017",
"sourceMap": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"rootDir": "src",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"module": "commonjs",
"target": "es2017",
"noImplicitAny": false,
"noImplicitThis": true,
"moduleResolution": "node",
Expand All @@ -11,7 +12,6 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2017", "ES2020", "ES2021"],
"emitDecoratorMetadata": true,
"declaration": true,
"sourceMap": true,
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3075,9 +3075,9 @@ __metadata:
languageName: unknown
linkType: soft

"@subql/common@npm:3.6.0":
version: 3.6.0
resolution: "@subql/common@npm:3.6.0"
"@subql/common@npm:3.7.0":
version: 3.7.0
resolution: "@subql/common@npm:3.7.0"
dependencies:
"@subql/types-core": 0.7.0
axios: ^0.28.0
Expand All @@ -3089,7 +3089,7 @@ __metadata:
reflect-metadata: ^0.1.13
semver: ^7.5.2
update-notifier: 5.1.0
checksum: 65c35581969ba31965c1176b57c0881e29e20beb764623cd4fcb5bdf2fb68d632ea8c76149f773514081c4aa23f31be64fbea117dd1c1bbec12196ef1e86199e
checksum: 3aad6b35ff4931c3047dc2631516ada328f0a2092d46197a5041ea5588294f85b9e3a88fa6ec9829e527c7bd1c863d69a42c0b58a65eb861ba8ee3f9233f1dea
languageName: node
linkType: hard

Expand All @@ -3111,15 +3111,15 @@ __metadata:
languageName: node
linkType: hard

"@subql/node-core@npm:^10.3.2":
version: 10.3.2
resolution: "@subql/node-core@npm:10.3.2"
"@subql/node-core@npm:10.4.0":
version: 10.4.0
resolution: "@subql/node-core@npm:10.4.0"
dependencies:
"@apollo/client": ^3.8.8
"@nestjs/common": ^9.4.0
"@nestjs/event-emitter": ^2.0.0
"@nestjs/schedule": ^3.0.1
"@subql/common": 3.6.0
"@subql/common": 3.7.0
"@subql/testing": 2.1.1
"@subql/types": 3.6.0
"@subql/utils": 2.10.0
Expand All @@ -3140,7 +3140,7 @@ __metadata:
toposort-class: ^1.0.1
vm2: ^3.9.19
yargs: ^16.2.0
checksum: bc73b8e11103c4b25edbcd5385f45043722f883db6a1c7aef1eeebc97dc9dd2b1a7a8c7d60e61b45817aadce1362359cf30bf15001231f407f9ae80aad6a2b12
checksum: 5834ec1cdac3cf1e8d2e09d0351e73c5616c24e096ecb32652517d606c2509f39f546dfe176a9767c3ed638f30566d9a899b3e27bf46f5ec00c2544181606682
languageName: node
linkType: hard

Expand All @@ -3157,7 +3157,7 @@ __metadata:
"@nestjs/testing": ^9.4.0
"@subql/common": ^3.5.1
"@subql/common-ethereum": "workspace:*"
"@subql/node-core": ^10.3.2
"@subql/node-core": 10.4.0
"@subql/testing": ^2.1.1
"@subql/types-ethereum": "workspace:*"
"@types/express": ^4.17.13
Expand Down

0 comments on commit 503cdbc

Please sign in to comment.