Skip to content

Commit

Permalink
Sync with main, fix testing service
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Jul 26, 2024
1 parent ec4993f commit b408ea7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 94 deletions.
2 changes: 1 addition & 1 deletion packages/common-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@protobufs/google": "^0.0.10",
"@protobufs/ibc": "^0.1.0",
"@protobufs/tendermint": "^0.0.10",
"@subql/common": "^4.1.0",
"@subql/common": "^4.1.1",
"@subql/types-cosmos": "workspace:*",
"@subql/x-cosmology-telescope": "^1.4.14",
"fs-extra": "^11.1.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/common-cosmos/src/project/utils.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 {FileReference} from '@subql/types-core';
import {FileReference, BaseTemplateDataSource} from '@subql/types-core';
import {
SecondLayerHandlerProcessor,
CosmosCustomDatasource,
Expand All @@ -15,11 +15,15 @@ import {
import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface} from 'class-validator';
import {gte} from 'semver';

export function isCustomCosmosDs(ds: CosmosDatasource): ds is CosmosCustomDatasource<string> {
export function isCustomCosmosDs(
ds: CosmosDatasource | BaseTemplateDataSource<CosmosDatasource>
): ds is CosmosCustomDatasource<string> {
return ds.kind !== CosmosDatasourceKind.Runtime && !!(ds as CosmosCustomDatasource<string>).processor;
}

export function isRuntimeCosmosDs(ds: CosmosDatasource): ds is CosmosRuntimeDatasource {
export function isRuntimeCosmosDs(
ds: CosmosDatasource | BaseTemplateDataSource<CosmosDatasource>
): ds is CosmosRuntimeDatasource {
return ds.kind === CosmosDatasourceKind.Runtime;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Update cosmos and subql dependencies (#270)
- Update to latest `@subql/node-core` (#272)
- Use Subquery Project code from node core
- Breaking change: Update to latest `@subql/node-core`, require indexing environment timezone set to UTC (#272)

### Fixed
- Fix testing service missing inject nodeConfig
Expand Down
2 changes: 1 addition & 1 deletion packages/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build stage
FROM node:18-alpine as builder

ENV TZ ='UTC'
# Set working directory
WORKDIR /app

Expand Down
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^4.1.0",
"@subql/common": "^4.1.1",
"@subql/common-cosmos": "workspace:*",
"@subql/node-core": "^12.0.0",
"@subql/node-core": "^13.0.0",
"@subql/types-cosmos": "workspace:*",
"lodash": "^4.17.21",
"protobufjs": "^6.11.4",
Expand Down
96 changes: 29 additions & 67 deletions packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import fs from 'fs';
import os from 'os';
import { sep } from 'path';
import { isMainThread } from 'worker_threads';
import { Injectable } from '@nestjs/common';
import { validateSemver } from '@subql/common';
import {
CosmosProjectNetworkConfig,
Expand All @@ -17,13 +16,12 @@ import {
} from '@subql/common-cosmos';
import {
CronFilter,
insertBlockFiltersCronSchedules,
ISubqueryProject,
loadProjectTemplates,
updateDataSourcesV1_0_0,
WorkerHost,
BaseSubqueryProject,
} from '@subql/node-core';
import { ParentProject, Reader, RunnerSpecs } from '@subql/types-core';
import { Reader } from '@subql/types-core';
import {
CosmosDatasource,
CustomDatasourceTemplate,
Expand All @@ -32,11 +30,12 @@ import {
CosmosBlockFilter,
} from '@subql/types-cosmos';
import { buildSchemaFromString } from '@subql/utils';
import { GraphQLSchema } from 'graphql';
import { processNetworkConfig } from '../utils/project';

const { version: packageVersion } = require('../../package.json');

export type CosmosProjectDs = CosmosDatasource;

export type CosmosProjectDsTemplate =
| RuntimeDatasourceTemplate
| CustomDatasourceTemplate;
Expand All @@ -50,70 +49,33 @@ const NOT_SUPPORT = (name: string) => {
// This is the runtime type after we have mapped genesisHash to chainId and endpoint/dict have been provided when dealing with deployments
type NetworkConfig = CosmosProjectNetworkConfig & { chainId: string };

@Injectable()
export class SubqueryProject implements ISubqueryProject {
#dataSources: CosmosDatasource[];

constructor(
readonly id: string,
readonly root: string,
readonly network: NetworkConfig,
dataSources: CosmosDatasource[],
readonly schema: GraphQLSchema,
readonly templates: CosmosProjectDsTemplate[],
readonly runner?: RunnerSpecs,
readonly parent?: ParentProject,
readonly tempDir?: string,
) {
this.#dataSources = dataSources;
}

get dataSources(): CosmosDatasource[] {
return this.#dataSources;
}
export type SubqueryProject = BaseSubqueryProject<
CosmosProjectDs,
CosmosProjectDsTemplate,
NetworkConfig
>;

async applyCronTimestamps(
getTimestamp: (height: number) => Promise<Date>,
): Promise<void> {
this.#dataSources = await insertBlockFiltersCronSchedules(
this.dataSources,
getTimestamp,
isRuntimeCosmosDs,
CosmosHandlerKind.Block,
);
}
export async function createSubQueryProject(
path: string,
rawManifest: unknown,
reader: Reader,
root: string, // If project local then directory otherwise temp directory
networkOverrides?: Partial<NetworkConfig>,
): Promise<SubqueryProject> {
const project = await BaseSubqueryProject.create<SubqueryProject>({
parseManifest: (raw) => parseCosmosProjectManifest(raw).asV1_0_0,
path,
rawManifest,
reader,
root,
nodeSemver: packageVersion,
blockHandlerKind: CosmosHandlerKind.Block,
networkOverrides,
isRuntimeCosmosDs,
isCustomCosmosDs,
});

static async create(
path: string,
rawManifest: unknown,
reader: Reader,
root: string,
networkOverrides?: Partial<CosmosProjectNetworkConfig>,
): Promise<SubqueryProject> {
// rawManifest and reader can be reused here.
// It has been pre-fetched and used for rebase manifest runner options with args
// in order to generate correct configs.

// But we still need reader here, because path can be remote or local
// and the `loadProjectManifest(projectPath)` only support local mode
if (rawManifest === undefined) {
throw new Error(`Get manifest from project path ${path} failed`);
}

const manifest = parseCosmosProjectManifest(rawManifest);

if (!manifest.isV1_0_0) {
NOT_SUPPORT('<1.0.0');
}

return loadProjectFromManifestBase(
manifest.asV1_0_0,
reader,
path,
root,
networkOverrides,
);
}
return project;
}

type SUPPORT_MANIFEST = ProjectManifestV1_0_0Impl;
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { DynamicModule, Global, Module } from '@nestjs/common';
import { NodeConfig, registerApp } from '@subql/node-core';
import { yargsOptions } from '../yargs';
import { SubqueryProject } from './SubqueryProject';
import { createSubQueryProject, SubqueryProject } from './SubqueryProject';

const pjson = require('../../package.json');

Expand All @@ -18,7 +18,7 @@ export class ConfigureModule {
const { argv } = yargsOptions;
return registerApp<SubqueryProject>(
argv,
SubqueryProject.create.bind(SubqueryProject),
createSubQueryProject,
yargsOptions.showHelp.bind(yargsOptions),
pjson,
);
Expand Down
34 changes: 17 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6362,7 +6362,7 @@ __metadata:
"@protobufs/google": ^0.0.10
"@protobufs/ibc": ^0.1.0
"@protobufs/tendermint": ^0.0.10
"@subql/common": ^4.1.0
"@subql/common": ^4.1.1
"@subql/types-cosmos": "workspace:*"
"@subql/x-cosmology-telescope": ^1.4.14
"@types/bn.js": 4.11.6
Expand All @@ -6385,9 +6385,9 @@ __metadata:
languageName: unknown
linkType: soft

"@subql/common@npm:4.1.0, @subql/common@npm:^4.1.0":
version: 4.1.0
resolution: "@subql/common@npm:4.1.0"
"@subql/common@npm:4.1.1, @subql/common@npm:^4.1.1":
version: 4.1.1
resolution: "@subql/common@npm:4.1.1"
dependencies:
"@subql/types-core": 0.10.0
axios: ^0.28.0
Expand All @@ -6398,22 +6398,22 @@ __metadata:
reflect-metadata: ^0.1.13
semver: ^7.5.2
update-notifier: 5.1.0
checksum: 8beac982f53ad99efb9a5725d73768f945a4fb52ff50222c3db047e4143013a9e716c0cb63d561dd8ae40fa2f0a8ceb472516d6e3fc2beb58ee888361a7798a7
checksum: 2f578678b5af8190639ada7e2f22401b3ca7b7c7cab1bfdeb5860365c14e6c6a8724b02c95f1f8fedfcc01205d02d3de45cd486e2c3ee10ff5f898f973d6e0dc
languageName: node
linkType: hard

"@subql/node-core@npm:^12.0.0":
version: 12.0.0
resolution: "@subql/node-core@npm:12.0.0"
"@subql/node-core@npm:^13.0.0":
version: 13.0.0
resolution: "@subql/node-core@npm:13.0.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": 4.1.0
"@subql/common": 4.1.1
"@subql/testing": 2.2.1
"@subql/types": 3.9.0
"@subql/utils": 2.13.0
"@subql/utils": 2.13.1
"@willsoto/nestjs-prometheus": ^5.4.0
async-lock: ^1.4.0
async-mutex: ^0.4.0
Expand All @@ -6431,7 +6431,7 @@ __metadata:
toposort-class: ^1.0.1
vm2: ^3.9.19
yargs: ^16.2.0
checksum: a37ab972f75dee4ecda070aafb125194a03952bcc8c6f2dacbae4c8c4f97cb5228b53ab09614d24658ad576f8f9de7a5d07c491f288ea1f449a2f80040235731
checksum: 91ebd7999da59470ef13923db694b81353e810892d63aa15174ff1c2688e61d6b0860fb53efdb31700fccf0772a42fbe19afff66efac5fb9ca258c9aa4012b2f
languageName: node
linkType: hard

Expand All @@ -6451,9 +6451,9 @@ __metadata:
"@nestjs/schedule": ^3.0.1
"@nestjs/schematics": ^9.2.0
"@nestjs/testing": ^9.4.0
"@subql/common": ^4.1.0
"@subql/common": ^4.1.1
"@subql/common-cosmos": "workspace:*"
"@subql/node-core": ^12.0.0
"@subql/node-core": ^13.0.0
"@subql/types-cosmos": "workspace:*"
"@types/express": ^4.17.13
"@types/jest": ^27.4.0
Expand Down Expand Up @@ -6524,9 +6524,9 @@ __metadata:
languageName: node
linkType: hard

"@subql/utils@npm:2.13.0":
version: 2.13.0
resolution: "@subql/utils@npm:2.13.0"
"@subql/utils@npm:2.13.1":
version: 2.13.1
resolution: "@subql/utils@npm:2.13.1"
dependencies:
"@polkadot/util": ^12.6.2
"@polkadot/util-crypto": ^12.6.2
Expand All @@ -6542,7 +6542,7 @@ __metadata:
rotating-file-stream: ^3.0.2
semver: ^7.5.2
tar: ^6.2.1
checksum: e2c43c0c2865f5e014572da3ec0a41691e5c534f90b0f008f12770ab9871783bba348cb929f5d51e36527d11344107718c3f86ef1b227dbc344ee03233c48031
checksum: eab0f5d4933dc6c56bbadbd82235c37beeaa9789372187ff523e08b46b41ce39eff406cfd6dfb955e396e0183def56901ef52396fb5f778b1247762a7e95a439
languageName: node
linkType: hard

Expand Down

0 comments on commit b408ea7

Please sign in to comment.