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 @subql dependencies #115

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions packages/common-algorand/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Update dependencies and apply changes to match (#115)

## [3.3.0] - 2024-04-10
### Changed
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.5.0",
"@subql/common": "^3.5.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we missed update types project/utils.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They already seem to have the right types

"@subql/types-algorand": "workspace:*",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Update dependencies and apply changes to match (#115)

## [3.10.0] - 2024-04-10
### Changed
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.5.0",
"@subql/common": "^3.5.1",
"@subql/common-algorand": "workspace:*",
"@subql/node-core": "^8.0.1",
"@subql/node-core": "^10.0.0",
"@subql/types-algorand": "workspace:*",
"algosdk": "^2.2.0",
"axios": "^1.3.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/algorand/api.algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ export class AlgorandApi {
getGenesisHash(): string {
return this.genesisHash;
}

getChainId(): string {
return this.chain;
}

getSafeApi(height: number): SafeAPIService {
return new SafeAPIService(this, height, this.endpoint);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/algorand/api.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AlgorandApiConnection
{
readonly networkMeta: NetworkMetadataPayload;

constructor(
private constructor(
public unsafeApi: AlgorandApi,
private fetchBlocksBatches: FetchFunc,
) {
Expand Down
25 changes: 17 additions & 8 deletions packages/node/src/algorand/api.service.algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
ConnectionPoolService,
getLogger,
IBlock,
MetadataMismatchError,
} from '@subql/node-core';
import { ProjectNetworkConfig } from '@subql/types-core';
import { SubqueryProject } from '../configure/SubqueryProject';
import { BlockContent } from '../indexer/types';
import { AlgorandApi, SafeAPIService } from './api.algorand';
Expand Down Expand Up @@ -40,14 +42,8 @@ export class AlgorandApiService extends ApiService<
process.exit(1);
}

await this.createConnections(
network,
(endpoint) =>
AlgorandApiConnection.create(endpoint, this.fetchBlockBatches),
//eslint-disable-next-line @typescript-eslint/require-await
async (connection: AlgorandApiConnection) => {
return connection.unsafeApi.getGenesisHash();
},
await this.createConnections(network, (endpoint) =>
AlgorandApiConnection.create(endpoint, this.fetchBlockBatches),
);

return this;
Expand All @@ -63,4 +59,17 @@ export class AlgorandApiService extends ApiService<
): Promise<IBlock<BlockContent>[]> {
return api.fetchBlocks(blocks);
}

protected assertChainId(
network: ProjectNetworkConfig & { chainId: string },
connection: AlgorandApiConnection,
): void {
if (network.chainId !== connection.networkMeta.genesisHash) {
throw new MetadataMismatchError(
'ChainId',
network.chainId,
connection.networkMeta.genesisHash,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {
NodeConfig,
SmartBatchService,
StoreCacheService,
StoreService,
IProjectService,
Expand All @@ -21,7 +20,6 @@ import {
AlgorandProjectDs,
SubqueryProject,
} from '../../configure/SubqueryProject';
import { DynamicDsService } from '../dynamic-ds.service';
import { IndexerManager } from '../indexer.manager';

/**
Expand All @@ -41,24 +39,20 @@ export class BlockDispatcherService
projectService: IProjectService<AlgorandProjectDs>,
@Inject('IProjectUpgradeService')
projectUpgradeService: IProjectUpgradeService,
smartBatchService: SmartBatchService,
storeService: StoreService,
storeCacheService: StoreCacheService,
poiSyncService: PoiSyncService,
@Inject('ISubqueryProject') project: SubqueryProject,
dynamicDsService: DynamicDsService,
) {
super(
nodeConfig,
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
storeService,
storeCacheService,
poiSyncService,
project,
dynamicDsService,
apiService.fetchBlocks.bind(apiService),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {
NodeConfig,
SmartBatchService,
StoreService,
PoiSyncService,
StoreCacheService,
Expand Down Expand Up @@ -44,7 +43,6 @@ export class WorkerBlockDispatcherService
projectService: IProjectService<AlgorandProjectDs>,
@Inject('IProjectUpgradeService')
projectUpgadeService: IProjectUpgradeService,
smartBatchService: SmartBatchService,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
Expand All @@ -59,12 +57,10 @@ export class WorkerBlockDispatcherService
eventEmitter,
projectService,
projectUpgadeService,
smartBatchService,
storeService,
storeCacheService,
poiSyncService,
project,
dynamicDsService,
() =>
createIndexerWorker<
IIndexerWorker,
Expand Down
67 changes: 2 additions & 65 deletions packages/node/src/indexer/ds-processor.service.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,21 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import {
isCustomDs,
AlgorandCustomDataSource as AlgorandCustomDs,
AlgorandDataSource,
AlgorandDataSourceProcessor,
} from '@subql/common-algorand';
import { BaseDsProcessorService } from '@subql/node-core';
import {
SecondLayerHandlerProcessor_0_0_0,
SecondLayerHandlerProcessor_1_0_0,
AlgorandCustomDataSource,
AlgorandHandlerKind,
} from '@subql/types-algorand';
import { AlgorandCustomDataSource } from '@subql/types-algorand';

export interface DsPluginSandboxOption {
root: string;
entry: string;
script: string;
}

export function isSecondLayerHandlerProcessor_0_0_0<
K extends AlgorandHandlerKind,
F extends Record<string, unknown>,
E,
DS extends AlgorandCustomDataSource = AlgorandCustomDataSource,
>(
processor:
| SecondLayerHandlerProcessor_0_0_0<K, F, E, DS>
| SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>,
): processor is SecondLayerHandlerProcessor_0_0_0<K, F, E, DS> {
// Exisiting datasource processors had no concept of specVersion, therefore undefined is equivalent to 0.0.0
return processor.specVersion === undefined;
}

export function isSecondLayerHandlerProcessor_1_0_0<
K extends AlgorandHandlerKind,
F extends Record<string, unknown>,
E,
DS extends AlgorandCustomDataSource = AlgorandCustomDataSource,
>(
processor:
| SecondLayerHandlerProcessor_0_0_0<K, F, E, DS>
| SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>,
): processor is SecondLayerHandlerProcessor_1_0_0<K, F, E, DS> {
return processor.specVersion === '1.0.0';
}

export function asSecondLayerHandlerProcessor_1_0_0<
K extends AlgorandHandlerKind,
F extends Record<string, unknown>,
E,
DS extends AlgorandCustomDataSource = AlgorandCustomDataSource,
>(
processor:
| SecondLayerHandlerProcessor_0_0_0<K, F, E, DS>
| SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>,
): SecondLayerHandlerProcessor_1_0_0<K, F, E, DS> {
if (isSecondLayerHandlerProcessor_1_0_0(processor)) {
return processor;
}

if (!isSecondLayerHandlerProcessor_0_0_0(processor)) {
throw new Error('Unsupported ds processor version');
}

return {
...processor,
specVersion: '1.0.0',
filterProcessor: (params) =>
processor.filterProcessor(params.filter, params.input, params.ds),
transformer: (params) =>
processor
.transformer(params.input, params.ds, params.api, params.assets)
.then((res) => [res]),
};
}

@Injectable()
export class DsProcessorService extends BaseDsProcessorService<
AlgorandDataSource,
Expand Down
27 changes: 9 additions & 18 deletions packages/node/src/indexer/dynamic-ds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,31 @@ import {
DynamicDsService as BaseDynamicDsService,
} from '@subql/node-core';
import { TransactionType } from 'algosdk';
import { cloneDeep } from 'lodash';
import {
AlgorandProjectDs,
SubqueryProject,
} from '../configure/SubqueryProject';
import { DsProcessorService } from './ds-processor.service';

@Injectable()
export class DynamicDsService extends BaseDynamicDsService<AlgorandProjectDs> {
export class DynamicDsService extends BaseDynamicDsService<
AlgorandProjectDs,
SubqueryProject
> {
constructor(
private readonly dsProcessorService: DsProcessorService,
@Inject('ISubqueryProject') private readonly project: SubqueryProject,
@Inject('ISubqueryProject') project: SubqueryProject,
) {
super();
super(project);
}

protected async getDatasource(
params: DatasourceParams,
): Promise<AlgorandProjectDs> {
const t = this.project.templates.find(
(t) => t.name === params.templateName,
const dsObj = this.getTemplate<AlgorandProjectDs>(
params.templateName,
params.startBlock,
);
if (!t) {
throw new Error(
`Unable to find matching template in project for name: "${params.templateName}"`,
);
}
const { name, ...template } = cloneDeep(t);

const dsObj = {
...template,
startBlock: params.startBlock,
} as AlgorandProjectDs;

try {
if (isCustomDs(dsObj)) {
dsObj.processor.options = {
Expand Down
15 changes: 1 addition & 14 deletions packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
PoiService,
PoiSyncService,
NodeConfig,
SmartBatchService,
ConnectionPoolService,
StoreCacheService,
ConnectionPoolStateManager,
IProjectUpgradeService,
InMemoryCacheService,
SandboxService,
} from '@subql/node-core';
import { AlgorandApiConnection, AlgorandApiService } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand All @@ -29,7 +29,6 @@ import { DynamicDsService } from './dynamic-ds.service';
import { FetchService } from './fetch.service';
import { IndexerManager } from './indexer.manager';
import { ProjectService } from './project.service';
import { SandboxService } from './sandbox.service';
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';

@Module({
Expand All @@ -39,13 +38,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
StoreCacheService,
ConnectionPoolService,
UnfinalizedBlocksService,
{
provide: SmartBatchService,
useFactory: (nodeConfig: NodeConfig) => {
return new SmartBatchService(nodeConfig.batchSize);
},
inject: [NodeConfig],
},
{
provide: AlgorandApiService,
useFactory: async (
Expand Down Expand Up @@ -74,7 +66,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
projectUpgradeService: IProjectUpgradeService,
apiService: AlgorandApiService,
indexerManager: IndexerManager,
smartBatchService: SmartBatchService,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
Expand All @@ -90,7 +81,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
cacheService,
storeService,
storeCacheService,
Expand All @@ -107,12 +97,10 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
storeService,
storeCacheService,
poiSyncService,
project,
dynamicDsService,
),
inject: [
NodeConfig,
Expand All @@ -121,7 +109,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
'IProjectUpgradeService',
AlgorandApiService,
IndexerManager,
SmartBatchService,
InMemoryCacheService,
StoreService,
StoreCacheService,
Expand Down
4 changes: 0 additions & 4 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export class FetchService extends BaseFetchService<
return this.apiService.unsafeApi;
}

protected getGenesisHash(): string {
return this.apiService.networkMeta.genesisHash;
}

protected async getFinalizedHeight(): Promise<number> {
const checkHealth = await this.api.api.makeHealthCheck().do();
return checkHealth.round;
Expand Down
Loading
Loading