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 main 20240408 #110

Merged
merged 9 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = {
2,
'line',
[
//Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
//Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
{pattern: ' Copyright \\d{4}(-\\d{4})? SubQuery Pte Ltd authors & contributors'},
' SPDX-License-Identifier: GPL-3.0',
],
Expand Down
3 changes: 3 additions & 0 deletions packages/common-algorand/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
- version bump with `@subql/common`

## [3.2.2] - 2024-02-23
### Changed
- version bump with `@subql/common`
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"main": "dist/index.js",
"license": "GPL-3.0",
"dependencies": {
"@subql/common": "^3.4.1",
"@subql/common": "^3.5.0",
"@subql/types-algorand": "workspace:*",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

export * from './project';
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

export * from './load';
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/load.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {AlgorandProjectManifestVersioned, VersionedProjectManifest} from './versioned';
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {BaseDataSource, ProcessorImpl} from '@subql/common';
Expand Down Expand Up @@ -141,7 +141,7 @@
case AlgorandHandlerKind.Transaction:
return plainToClass(TransactionHandler, handler);
default:
throw new Error(`handler ${(handler as any).kind} not supported`);

Check warning on line 144 in packages/common-algorand/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
}
});
})
Expand Down Expand Up @@ -177,7 +177,7 @@
file: string;
}

export class CustomDataSourceBase<K extends string, M extends CustomMapping, O = any>

Check warning on line 180 in packages/common-algorand/src/project/models.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
extends BaseDataSource
implements AlgorandCustomDataSource<K, M>
{
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {AlgorandDataSource} from '@subql/types-algorand';
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {registerDecorator, ValidationOptions} from 'class-validator';

export function IsStringOrObject(validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) {

Check warning on line 7 in packages/common-algorand/src/project/validation/is-string-or-object.validation.ts

View workflow job for this annotation

GitHub Actions / code-style

Missing return type on function
registerDecorator({
name: 'IsStringOrObject',
target: object.constructor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {AlgorandDataSource} from '@subql/types-algorand';
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/src/project/versioned/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

export * from './ProjectManifestVersioned';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

export * from './model';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {
Expand All @@ -23,7 +23,7 @@
import {
Equals,
IsArray,
IsNotEmpty,

Check warning on line 26 in packages/common-algorand/src/project/versioned/v1_0_0/model.ts

View workflow job for this annotation

GitHub Actions / code-style

'IsNotEmpty' is defined but never used
IsObject,
IsOptional,
IsString,
Expand Down Expand Up @@ -80,7 +80,7 @@

export class AlgorandCustomDataSourceV1_0_0Impl<
K extends string = string,
M extends BaseMapping<any> = BaseMapping<any>

Check warning on line 83 in packages/common-algorand/src/project/versioned/v1_0_0/model.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type

Check warning on line 83 in packages/common-algorand/src/project/versioned/v1_0_0/model.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
>
extends CustomDataSourceBase<K, M>
implements AlgorandCustomDataSource<K, M>
Expand Down
7 changes: 7 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Updated with node-core.Now dictionary support multiple dictionary endpoints, indexer will fetch and switch dictionaries base on available blocks
### Fixed
- Updated with node-core ,also fixed:
- Fix modulo block didn't apply correctly with multiple dataSources
- Now when `workers` set to 0, it will use block dispatcher instead of throw and exit

## [3.9.1] - 2024-03-14
### Changed
- Update `@subql/node-core` to 4.7.2 with graphql comments escaping fix
Expand Down
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^3.4.1",
"@subql/common": "^3.5.0",
"@subql/common-algorand": "workspace:*",
"@subql/node-core": "^7.4.2",
"@subql/node-core": "^8.0.1",
"@subql/types-algorand": "workspace:*",
"algosdk": "^2.2.0",
"axios": "^1.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/algorand/algorand.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { INestApplication } from '@nestjs/common';
Expand Down Expand Up @@ -32,7 +32,7 @@
root: './',
schema: new GraphQLSchema({}),
templates: [],
} as any;

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

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
}

// eslint-disable-next-line jest/no-export
Expand Down Expand Up @@ -114,7 +114,7 @@
};

expect(
filterTransaction(tx as any, {

Check warning on line 117 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 All @@ -122,7 +122,7 @@
});

// This is failing since switching from algo explorer api. This is due to a node configuration limit
it.skip('paginate large blocks', async () => {

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

View workflow job for this annotation

GitHub Actions / code-style

Disabled test
[app, apiService] = await prepareApiService(
testnetEndpoint,
testnetChainId,
Expand Down
14 changes: 7 additions & 7 deletions packages/node/src/algorand/api.algorand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { TokenHeader } from '@subql/common-algorand';
import { delay, getLogger } from '@subql/node-core';
import { delay, getLogger, IBlock } from '@subql/node-core';
import {
AlgorandBlock,
AlgorandTransaction,
Expand All @@ -11,7 +11,7 @@ import {
import algosdk, { Indexer } from 'algosdk';
import axios from 'axios';
import { omit } from 'lodash';
import { camelCaseObjectKey } from './utils.algorand';
import { camelCaseObjectKey, formatBlockUtil } from './utils.algorand';

const logger = getLogger('api.algorand');

Expand Down Expand Up @@ -170,7 +170,7 @@ export class AlgorandApi {
getSafeApi(height: number): SafeAPIService {
return new SafeAPIService(this, height, this.endpoint);
}
async fetchBlocks(blockNums: number[]): Promise<AlgorandBlock[]> {
async fetchBlocks(blockNums: number[]): Promise<IBlock<AlgorandBlock>[]> {
let blocks: AlgorandBlock[] = [];

for (let i = 0; i < blockNums.length; i++) {
Expand All @@ -185,14 +185,14 @@ export class AlgorandApi {

blocks = [...blocks, ...fetchedBlocks];

blocks = await Promise.all(
const formattedBlocks = await Promise.all(
blocks.map(async (block) => {
block.hash = await this.getBlockHash(block.round, blocks);
return block;
return formatBlockUtil(block);
}),
);

return blocks;
return formattedBlocks;
}

private blockInCache(number: number): AlgorandBlock {
Expand Down
12 changes: 8 additions & 4 deletions packages/node/src/algorand/api.connection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {
Expand All @@ -7,17 +7,21 @@ import {
IApiConnectionSpecific,
NetworkMetadataPayload,
getLogger,
IBlock,
} from '@subql/node-core';
import { BlockContent } from '../indexer/types';
import { AlgorandApi, SafeAPIService } from './api.algorand';

const logger = getLogger('AlgorandApiConnection');

type FetchFunc = (api: AlgorandApi, batch: number[]) => Promise<BlockContent[]>;
type FetchFunc = (
api: AlgorandApi,
batch: number[],
) => Promise<IBlock<BlockContent>[]>;

export class AlgorandApiConnection
implements
IApiConnectionSpecific<AlgorandApi, SafeAPIService, BlockContent[]>
IApiConnectionSpecific<AlgorandApi, SafeAPIService, IBlock<BlockContent>[]>
{
readonly networkMeta: NetworkMetadataPayload;

Expand Down Expand Up @@ -56,7 +60,7 @@ export class AlgorandApiConnection
logger.debug('apiDisconnect is not implemented');
}

async fetchBlocks(heights: number[]): Promise<BlockContent[]> {
async fetchBlocks(heights: number[]): Promise<IBlock<BlockContent>[]> {
const blocks = await this.fetchBlocksBatches(this.unsafeApi, heights);
return blocks;
}
Expand Down
16 changes: 10 additions & 6 deletions packages/node/src/algorand/api.service.algorand.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Inject, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { ApiService, ConnectionPoolService, getLogger } from '@subql/node-core';
import {
ApiService,
ConnectionPoolService,
getLogger,
IBlock,
} from '@subql/node-core';
import { SubqueryProject } from '../configure/SubqueryProject';
import { BlockContent } from '../indexer/types';
import { AlgorandApi, SafeAPIService } from './api.algorand';
Expand All @@ -15,7 +20,7 @@ const logger = getLogger('api');
export class AlgorandApiService extends ApiService<
AlgorandApi,
SafeAPIService,
BlockContent[]
IBlock<BlockContent>[]
> {
constructor(
@Inject('ISubqueryProject') private project: SubqueryProject,
Expand All @@ -41,8 +46,7 @@ export class AlgorandApiService extends ApiService<
AlgorandApiConnection.create(endpoint, this.fetchBlockBatches),
//eslint-disable-next-line @typescript-eslint/require-await
async (connection: AlgorandApiConnection) => {
const api = connection.unsafeApi;
return api.getGenesisHash();
return connection.unsafeApi.getGenesisHash();
},
);

Expand All @@ -56,7 +60,7 @@ export class AlgorandApiService extends ApiService<
async fetchBlockBatches(
api: AlgorandApi,
blocks: number[],
): Promise<BlockContent[]> {
): Promise<IBlock<BlockContent>[]> {
return api.fetchBlocks(blocks);
}
}
2 changes: 1 addition & 1 deletion packages/node/src/algorand/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

export * from './api.algorand';
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/algorand/utils.algorand.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { INestApplication } from '@nestjs/common';
Expand Down
21 changes: 20 additions & 1 deletion packages/node/src/algorand/utils.algorand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Header, IBlock } from '@subql/node-core';
import {
AlgorandBlock,
AlgorandBlockFilter,
Expand All @@ -9,6 +10,24 @@ import {
} from '@subql/types-algorand';
import { Indexer, TransactionType } from 'algosdk';
import { camelCase, get } from 'lodash';
import { BlockContent } from '../indexer/types';

export function algorandBlockToHeader(block: BlockContent): Header {
return {
blockHeight: block.round,
blockHash: block.round.toString(),
parentHash: block.previousBlockHash,
};
}

export function formatBlockUtil<B extends AlgorandBlock = AlgorandBlock>(
block: B,
): IBlock<B> {
return {
block,
getHeader: () => algorandBlockToHeader(block),
};
}

export function camelCaseObjectKey(object: object) {
if (Array.isArray(object)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { DynamicModule, Global, Module } from '@nestjs/common';
Expand Down
8 changes: 5 additions & 3 deletions packages/node/src/indexer/api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { INestApplication } from '@nestjs/common';
Expand Down Expand Up @@ -67,7 +67,9 @@ describe('ApiService', () => {

const block = (await apiService.api.fetchBlocks([50000]))[0];

expect(block.hash).toEqual('Gss169f22yVUBJzbNT9qXtQukjh0tgecvapaQY5NIRg=');
expect(block.block.hash).toEqual(
'Gss169f22yVUBJzbNT9qXtQukjh0tgecvapaQY5NIRg=',
);
});

it('waits on pending block to fetch hash', async () => {
Expand All @@ -83,6 +85,6 @@ describe('ApiService', () => {
expect(fetchLatestBlock).not.toThrow();

const block = await fetchLatestBlock();
expect(block.hash).toBeDefined();
expect(block.block.hash).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { IBlockDispatcher } from '@subql/node-core';
import { AlgorandBlock } from '@subql/types-algorand';

export interface IAlgorandBlockDispatcher extends IBlockDispatcher {
export interface IAlgorandBlockDispatcher
extends IBlockDispatcher<AlgorandBlock> {
init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
Expand All @@ -13,6 +13,7 @@ import {
BlockDispatcher,
ProcessBlockResponse,
IProjectUpgradeService,
IBlock,
} from '@subql/node-core';
import { AlgorandBlock } from '@subql/types-algorand';
import { AlgorandApiService } from '../../algorand';
Expand Down Expand Up @@ -58,9 +59,7 @@ export class BlockDispatcherService
poiSyncService,
project,
dynamicDsService,
async (blockNums: number[]): Promise<AlgorandBlock[]> => {
return this.apiService.fetchBlocks(blockNums);
},
apiService.fetchBlocks.bind(apiService),
);
}

Expand All @@ -69,11 +68,11 @@ export class BlockDispatcherService
}

protected async indexBlock(
block: AlgorandBlock,
block: IBlock<AlgorandBlock>,
): Promise<ProcessBlockResponse> {
return this.indexerManager.indexBlock(
block,
await this.projectService.getDataSources(this.getBlockHeight(block)),
await this.projectService.getDataSources(block.getHeader().blockHeight),
);
}
}
Loading
Loading