Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cli-modulor-import
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Jul 3, 2024
2 parents 546d84b + 2ea8cf6 commit 4f1922d
Show file tree
Hide file tree
Showing 50 changed files with 382 additions and 215 deletions.
Empty file added .yarn/versions/ba8ed0a5.yml
Empty file.
4 changes: 4 additions & 0 deletions .yarn/versions/e4f4b87b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
undecided:
- "@subql/node"
- "@subql/node-core"
- "@subql/types"
3 changes: 3 additions & 0 deletions packages/cli/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]

### Fixed
- The IPFS CID for multi-chain requires the directory CID.

### Changed
- Breaking Change: Removed common network packages from dependencies, only import required module from local/global when using. (#2456)

Expand Down
32 changes: 16 additions & 16 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ npm install -g @subql/cli
$ subql COMMAND
running command...
$ subql (--version)
@subql/cli/4.13.2-0 linux-x64 node-v18.20.3
@subql/cli/4.15.1-0 linux-x64 node-v18.20.3
$ subql --help [COMMAND]
USAGE
$ subql COMMAND
Expand Down Expand Up @@ -71,7 +71,7 @@ DESCRIPTION
Build this SubQuery project code
```

_See code: [lib/commands/build/index.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/build/index.js)_
_See code: [lib/commands/build/index.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/build/index.js)_

## `subql codegen`

Expand All @@ -89,7 +89,7 @@ DESCRIPTION
Generate schemas for graph node
```

_See code: [lib/commands/codegen/index.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/codegen/index.js)_
_See code: [lib/commands/codegen/index.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/codegen/index.js)_

## `subql codegen:generate`

Expand All @@ -112,7 +112,7 @@ DESCRIPTION
Generate Project.yaml and mapping functions based on provided ABI
```

_See code: [lib/commands/codegen/generate.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/codegen/generate.js)_
_See code: [lib/commands/codegen/generate.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/codegen/generate.js)_

## `subql deployment`

Expand Down Expand Up @@ -161,7 +161,7 @@ DESCRIPTION
Deploy to hosted service
```

_See code: [lib/commands/deployment/index.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/deployment/index.js)_
_See code: [lib/commands/deployment/index.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/deployment/index.js)_

## `subql deployment:delete`

Expand All @@ -180,7 +180,7 @@ DESCRIPTION
Delete Deployment
```

_See code: [lib/commands/deployment/delete.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/deployment/delete.js)_
_See code: [lib/commands/deployment/delete.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/deployment/delete.js)_

## `subql deployment:deploy`

Expand Down Expand Up @@ -225,7 +225,7 @@ DESCRIPTION
Deployment to hosted service
```

_See code: [lib/commands/deployment/deploy.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/deployment/deploy.js)_
_See code: [lib/commands/deployment/deploy.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/deployment/deploy.js)_

## `subql deployment:promote`

Expand All @@ -244,7 +244,7 @@ DESCRIPTION
Promote Deployment
```

_See code: [lib/commands/deployment/promote.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/deployment/promote.js)_
_See code: [lib/commands/deployment/promote.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/deployment/promote.js)_

## `subql init [PROJECTNAME]`

Expand All @@ -268,7 +268,7 @@ DESCRIPTION
Initialize a scaffold subquery project
```

_See code: [lib/commands/init.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/init.js)_
_See code: [lib/commands/init.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/init.js)_

## `subql migrate`

Expand All @@ -287,7 +287,7 @@ DESCRIPTION
Schema subgraph project to subquery project
```

_See code: [lib/commands/migrate.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/migrate.js)_
_See code: [lib/commands/migrate.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/migrate.js)_

## `subql multi-chain:add`

Expand All @@ -306,7 +306,7 @@ DESCRIPTION
Add new chain manifest to multi-chain configuration
```

_See code: [lib/commands/multi-chain/add.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/multi-chain/add.js)_
_See code: [lib/commands/multi-chain/add.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/multi-chain/add.js)_

## `subql multi-chain:deploy`

Expand Down Expand Up @@ -352,7 +352,7 @@ DESCRIPTION
Multi-chain deployment to hosted service
```

_See code: [lib/commands/multi-chain/deploy.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/multi-chain/deploy.js)_
_See code: [lib/commands/multi-chain/deploy.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/multi-chain/deploy.js)_

## `subql project`

Expand All @@ -378,7 +378,7 @@ DESCRIPTION
Create/Delete project
```

_See code: [lib/commands/project/index.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/project/index.js)_
_See code: [lib/commands/project/index.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/project/index.js)_

## `subql project:create-project`

Expand All @@ -403,7 +403,7 @@ DESCRIPTION
Create Project on Hosted Service
```

_See code: [lib/commands/project/create-project.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/project/create-project.js)_
_See code: [lib/commands/project/create-project.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/project/create-project.js)_

## `subql project:delete-project`

Expand All @@ -421,7 +421,7 @@ DESCRIPTION
Delete Project on Hosted Service
```

_See code: [lib/commands/project/delete-project.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/project/delete-project.js)_
_See code: [lib/commands/project/delete-project.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/project/delete-project.js)_

## `subql publish`

Expand All @@ -440,6 +440,6 @@ DESCRIPTION
Upload this SubQuery project to IPFS
```

_See code: [lib/commands/publish.js](https://github.com/packages/cli/blob/v4.13.2-0/lib/commands/publish.js)_
_See code: [lib/commands/publish.js](https://github.com/packages/cli/blob/v4.15.1-0/lib/commands/publish.js)_

<!-- commandsstop -->
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@subql/cli",
"description": "cli for subquery",
"version": "4.15.0",
"version": "4.15.1-0",
"author": "Ian He",
"bin": {
"subql": "./bin/run"
Expand Down Expand Up @@ -87,5 +87,6 @@
"types": "lib/index.d.ts",
"resolutions": {
"node-fetch": "2.6.7"
}
},
"stableVersion": "4.15.0"
}
10 changes: 6 additions & 4 deletions packages/cli/src/commands/multi-chain/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
import fs from 'fs';
import path from 'path';
import {Command, Flags} from '@oclif/core';
Expand All @@ -21,7 +22,7 @@ import {
projectsInfo,
splitMultichainDataFields,
} from '../../controller/deploy-controller';
import {uploadToIpfs} from '../../controller/publish-controller';
import {getDirectoryCid, uploadToIpfs} from '../../controller/publish-controller';
import {MultichainDataFieldType, V3DeploymentIndexerType} from '../../types';
import {addV, checkToken, promptWithDefaultValues, resolveToAbsolutePath, valueOrPrompt} from '../../utils';

Expand Down Expand Up @@ -70,8 +71,9 @@ export default class MultiChainDeploy extends Command {
flags.org = await valueOrPrompt(flags.org, 'Enter organisation', 'Organisation is required');
flags.projectName = await valueOrPrompt(flags.projectName, 'Enter project name', 'Project name is required');

// Multichain query descriptor
const ipfsCID = fileToCidMap.get(path.basename(multichainManifestPath));
// Multichain query descriptor, The IPFS provided for deployment here must be a directory
const ipfsCID = getDirectoryCid(fileToCidMap);
assert(ipfsCID, 'Multichain deployment CID not found');

const projectInfo = await projectsInfo(authToken, flags.org, flags.projectName, ROOT_API_URL_PROD, flags.type);
const chains: V3DeploymentIndexerType[] = [];
Expand Down Expand Up @@ -184,7 +186,7 @@ export default class MultiChainDeploy extends Command {
);
}

this.log('Deploying SubQuery multi-chain project to Hosted Service');
this.log('Deploying SubQuery multi-chain project to Hosted Service, IPFS: ', ipfsCID);

await executeProjectDeployment({
log: this.log.bind(this),
Expand Down
18 changes: 14 additions & 4 deletions packages/cli/src/controller/publish-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
import {promisify} from 'util';
import {mapToObject, NETWORK_FAMILY, ReaderFactory, toJsonObject} from '@subql/common';
import rimraf from 'rimraf';
import {createTestProject} from '../createProject.fixtures';
import {createMultiChainTestProject, createTestProject} from '../createProject.fixtures';
import {loadDependency} from '../modulars';
import {uploadToIpfs} from './publish-controller';
import {getDirectoryCid, uploadToIpfs} from './publish-controller';

// Replace/Update your access token when test locally
const testAuth = process.env.SUBQL_ACCESS_TOKEN;

jest.setTimeout(300_000); // 300s
describe('Cli publish', () => {
let projectDir: string;

let multiChainProjectDir: string;
let fullPaths: string[];
beforeAll(async () => {
projectDir = await createTestProject();
const res = await Promise.all([createTestProject(), createMultiChainTestProject()]);
projectDir = res[0];
multiChainProjectDir = res[1].multichainManifestPath;
fullPaths = res[1].fullPaths;
});

afterAll(async () => {
Expand Down Expand Up @@ -60,4 +64,10 @@ describe('Cli publish', () => {
});
expect(mapToObject(mockMap)).toStrictEqual({'1': 'aaa', '2': 'bbb'});
});

it('Get directory CID from multi-chain project', async () => {
const cidMap = await uploadToIpfs(fullPaths, testAuth, multiChainProjectDir);
const directoryCid = getDirectoryCid(cidMap);
expect(directoryCid).toBeDefined();
});
});
5 changes: 5 additions & 0 deletions packages/cli/src/controller/publish-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ export async function uploadFile(

return cid;
}

export function getDirectoryCid(fileToCidMap: Map<string, string>): string | undefined {
const directoryCid = fileToCidMap.get('');
return directoryCid;
}
48 changes: 48 additions & 0 deletions packages/cli/src/createProject.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import childProcess from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {getMultichainManifestPath, getProjectRootAndManifest} from '@subql/common';
import fetch from 'cross-fetch';
import Build from './commands/build';
import Codegen from './commands/codegen';
Expand All @@ -29,6 +30,24 @@ const projectSpecV1_0_0: ProjectSpecV1_0_0 = {
},
};

const multiProjectSpecV1_0_0: ProjectSpecV1_0_0 = {
name: 'multi_mocked_starter',
chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
endpoint: 'https://arbitrum.llamarpc.com',
author: 'jay',
description: 'this is test for init controller',
runner: {
node: {
name: '@subql/node-ethereum',
version: '>=3.0.0',
},
query: {
name: '@subql/query',
version: '*',
},
},
};

async function getExampleProject(networkFamily: string, network: string): Promise<ExampleProjectInterface | undefined> {
const res = await fetch('https://raw.githubusercontent.com/subquery/templates/main/dist/output.json');

Expand Down Expand Up @@ -62,3 +81,32 @@ export async function createTestProject(): Promise<string> {

return projectDir;
}

export async function createMultiChainTestProject(): Promise<{multichainManifestPath: string; fullPaths: string[]}> {
const tmpdir = await fs.promises.mkdtemp(`${os.tmpdir()}${path.sep}`);
const projectDir = path.join(tmpdir, multiProjectSpecV1_0_0.name);

const exampleProject = await getExampleProject('multi', 'multi');

await cloneProjectTemplate(tmpdir, multiProjectSpecV1_0_0.name, exampleProject);

// Install dependencies
childProcess.execSync(`npm i`, {cwd: projectDir});
// Set test env to be develop mode, only limit to test
process.env.NODE_ENV = 'develop';

await Codegen.run(['-l', projectDir]);
await Build.run(['-f', projectDir]);

const project = getProjectRootAndManifest(projectDir);
const fullPaths = project.manifests.map((manifest) => path.join(project.root, manifest));
let multichainManifestPath = getMultichainManifestPath(projectDir);
if (!multichainManifestPath) {
throw new Error(
'Selected project is not multi-chain. Please set correct file.\n\n https://academy.subquery.network/build/multi-chain.html'
);
}

multichainManifestPath = path.join(project.root, multichainManifestPath);
return {multichainManifestPath, fullPaths};
}
2 changes: 2 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Enable ts strict model
## [10.10.0] - 2024-07-01
### Changed
- Bump version with `@subql/common`
Expand Down
5 changes: 3 additions & 2 deletions packages/node-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/node-core",
"version": "10.10.0",
"version": "10.10.1-0",
"description": "Common node features that are agnostic to blockchains",
"homepage": "https://github.com/subquery/subql",
"repository": "github:subquery/subql",
Expand Down Expand Up @@ -48,5 +48,6 @@
},
"devDependencies": {
"@types/async-lock": "^1"
}
},
"stableVersion": "10.10.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
protected _processedBlockCount = 0;
protected _latestProcessedHeight = 0;
protected currentProcessingHeight = 0;
private _onDynamicDsCreated?: (height: number) => Promise<void>;
private _onDynamicDsCreated?: (height: number) => void;
private _pendingRewindHeight?: number;

protected smartBatchService: SmartBatchService;
Expand All @@ -72,7 +72,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB

abstract enqueueBlocks(heights: (IBlock<B> | number)[], latestBufferHeight?: number): void | Promise<void>;

async init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void> {
async init(onDynamicDsCreated: (height: number) => void): Promise<void> {
this._onDynamicDsCreated = onDynamicDsCreated;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.setProcessedBlockCount((await this.storeCacheService.metadata.find('processedBlockCount', 0))!);
Expand Down Expand Up @@ -103,7 +103,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
this._latestProcessedHeight = height;
}

protected get onDynamicDsCreated(): (height: number) => Promise<void> {
protected get onDynamicDsCreated(): (height: number) => void {
if (!this._onDynamicDsCreated) {
throw new Error('BaseBlockDispatcher has not been initialized');
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
this.createPOI(height, blockHash, operationHash);

if (dynamicDsCreated) {
await this.onDynamicDsCreated(height);
this.onDynamicDsCreated(height);
}
assert(
!this.latestProcessedHeight || height > this.latestProcessedHeight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export abstract class WorkerBlockDispatcher<DS, W extends Worker, B>
this.numWorkers = nodeConfig.workers!;
}

async init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void> {
async init(onDynamicDsCreated: (height: number) => void): Promise<void> {
this.workers = await Promise.all(new Array(this.numWorkers).fill(0).map(() => this.createIndexerWorker()));
return super.init(onDynamicDsCreated);
}
Expand Down
Loading

0 comments on commit 4f1922d

Please sign in to comment.