Skip to content

Commit

Permalink
Merge pull request #47 from subquery/export-modular-concordium
Browse files Browse the repository at this point in the history
Export modular Concordium
  • Loading branch information
jiqiang90 authored Jul 2, 2024
2 parents a2a57d4 + e56fdbf commit 4d0efdc
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 178 deletions.
3 changes: 3 additions & 0 deletions packages/common-concordium/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 alias `parseProjectManifest`, also follow type of `INetworkCommonModule` (#47)

## [3.6.0] - 2024-05-02
### Changed
- Update dependencies and apply changes to match (#40)
Expand Down
2 changes: 1 addition & 1 deletion packages/common-concordium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "GPL-3.0",
"dependencies": {
"@concordium/node-sdk": "9.4.0",
"@subql/common": "^3.5.1",
"@subql/common": "^4.0.0",
"@subql/types-concordium": "workspace:*",
"js-yaml": "^4.1.0",
"pino": "^6.13.3",
Expand Down
10 changes: 10 additions & 0 deletions packages/common-concordium/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
// SPDX-License-Identifier: GPL-3.0

export * from './project';

import {ConcordiumDatasource, ConcordiumRuntimeDatasource, ConcordiumCustomDatasource} from '@subql/types-concordium';
import {INetworkCommonModule} from '@subql/types-core';
import * as p from './project';

// This provides a compiled time check to ensure that the correct exports are provided
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = {
...p,
} satisfies INetworkCommonModule<ConcordiumDatasource, ConcordiumRuntimeDatasource, ConcordiumCustomDatasource>;
3 changes: 3 additions & 0 deletions packages/common-concordium/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export * from './models';
export * from './types';
export * from './utils';
export * from './versioned';

import {parseConcordiumProjectManifest} from './load';
export {parseConcordiumProjectManifest as parseProjectManifest};
2 changes: 1 addition & 1 deletion packages/common-concordium/src/project/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class CustomDataSourceBase<K extends string, M extends SubqlMapping = Sub
mapping: M;
@IsOptional()
@IsInt()
startBlock?: number;
startBlock?: number = undefined;
@Type(() => FileReferenceImpl)
@ValidateNested({each: true})
assets: Map<string, CustomDataSourceAsset>;
Expand Down
11 changes: 3 additions & 8 deletions packages/common-concordium/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ import {CustomDataSourceBase, ConcordiumMapping, RuntimeDataSourceBase} from '..
const Concordium_NODE_NAME = `@subql/node-concordium`;
const Flare_NODE_NAME = `@subql/node-flare`;

export class ConcordiumProjectMapping extends ConcordiumMapping {
@IsString()
file: string;
}

export class ConcordiumRunnerNodeImpl extends RunnerNodeImpl {
@IsIn([Concordium_NODE_NAME, Flare_NODE_NAME], {
message: `Runner Substrate node name incorrect, suppose be '${Concordium_NODE_NAME}'`,
})
name: string;
name: string = Concordium_NODE_NAME;
}

function validateObject(object: any, errorMessage = 'failed to validate object.'): void {
Expand Down Expand Up @@ -115,7 +110,7 @@ export class ProjectNetworkV1_0_0 extends CommonProjectNetworkV1_0_0<FileType> {
@ValidateNested()
@Type(() => FileType)
@IsOptional()
chaintypes?: FileType;
chaintypes?: FileType = undefined;
}

export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
Expand Down Expand Up @@ -164,7 +159,7 @@ export class ProjectManifestV1_0_0Impl
}

@Equals('1.0.0')
specVersion: string;
specVersion = '1.0.0';
@Type(() => ConcordiumCustomDataSourceImpl, {
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]

### Changed
- Bump version with `@subql/common-concordium`,sync with `@subql/node-core`, add admin module

## [3.11.1] - 2024-05-02
### Fixed
- Sandbox Uint8Array and missing pg dep issue
Expand Down
6 changes: 5 additions & 1 deletion packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ RUN npm i -g app.tgz
# Clean up unused deps
RUN rm /app.tgz && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache
rm -rf /root/.npm /root/.cache \

# Create ./.monitor directory and set permissions
RUN mkdir -p .monitor && \
chown 1000:1000 .monitor

# Make the user not ROOT
USER 1000
Expand Down
3 changes: 1 addition & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^3.5.1",
"@subql/common-concordium": "workspace:*",
"@subql/node-core": "^10.1.1",
"@subql/node-core": "^10.10.0",
"@subql/types-concordium": "workspace:*",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
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';
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
6 changes: 3 additions & 3 deletions packages/node/src/concordium/api.service.concordium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getLogger,
IBlock,
NodeConfig,
exitWithError,
} from '@subql/node-core';
import { ConcordiumBlock } from '@subql/types-concordium';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand Down Expand Up @@ -42,8 +43,7 @@ export class ConcordiumApiService extends ApiService<
network.endpoint.push(this.nodeConfig.primaryNetworkEndpoint);
}
} catch (e) {
logger.error(Object.keys(e));
process.exit(1);
exitWithError(new Error(`Failed to init api`, { cause: e }), logger);
}

await this.createConnections(
Expand All @@ -54,7 +54,7 @@ export class ConcordiumApiService extends ApiService<
this.fetchBlockBatches,
this.eventEmitter,
),
//eslint-disable-next-line @typescript-eslint/require-await
// eslint-disable-next-line @typescript-eslint/require-await,@typescript-eslint/no-misused-promises
async (connection: ConcordiumApiConnection) => {
const api = connection.unsafeApi;
return api.getChainId();
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 { ConcordiumBlock, ConcordiumDatasource } from '@subql/types-concordium';
import { ConcordiumApiConnection } from '../../concordium/api.connection';
Expand Down Expand Up @@ -52,6 +53,7 @@ export class WorkerBlockDispatcherService
dynamicDsService: DynamicDsService,
unfinalizedBlocksSevice: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<ConcordiumApiConnection>,
monitorService?: MonitorServiceInterface,
) {
super(
nodeConfig,
Expand All @@ -78,7 +80,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 { ConcordiumApiConnection } from '../concordium/api.connection';
import { ConcordiumApiService } from '../concordium/api.service.concordium';
Expand Down Expand Up @@ -83,6 +84,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService: DynamicDsService,
unfinalizedBlocks: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<ConcordiumApiConnection>,
monitorService?: MonitorService,
) =>
nodeConfig.workers
? new WorkerBlockDispatcherService(
Expand All @@ -98,6 +100,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService,
unfinalizedBlocks,
connectionPoolState,
monitorService,
)
: new BlockDispatcherService(
apiService,
Expand Down Expand Up @@ -126,6 +129,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
DynamicDsService,
UnfinalizedBlocksService,
ConnectionPoolStateManager,
MonitorService,
],
},
FetchService,
Expand All @@ -142,7 +146,8 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
provide: 'IProjectService',
},
UnfinalizedBlocksService,
MonitorService,
],
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 { ConcordiumApiService } from '../../concordium';
import { ConcordiumApiConnection } from '../../concordium/api.connection';
Expand Down Expand Up @@ -74,6 +76,10 @@ import { WorkerService } from './worker.service';
useFactory: () =>
new WorkerUnfinalizedBlocksService((global as any).host),
},
{
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 @@ -27,12 +27,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 @@ -60,7 +60,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 { getLogger, exitWithError } 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
3 changes: 3 additions & 0 deletions packages/types/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
- Bump version with `@subql/types-core`

## [3.6.0] - 2024-05-02
### Changed
- Update dependencies and apply changes to match (#40)
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "GPL-3.0",
"dependencies": {
"@concordium/node-sdk": "9.4.0",
"@subql/types-core": "^0.7.0"
"@subql/types-core": "^0.9.0"
},
"files": [
"src/global.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"target": "es2022",
"noImplicitAny": false,
"noImplicitThis": true,
"moduleResolution": "node",
Expand All @@ -11,7 +11,7 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2017", "ES2020"],
"lib": ["ES2022"],
"emitDecoratorMetadata": true,
"declaration": true,
"sourceMap": true,
Expand Down
Loading

0 comments on commit 4d0efdc

Please sign in to comment.