Skip to content

Commit

Permalink
Sync @subql dependencies (#109)
Browse files Browse the repository at this point in the history
* Update @subql deps

* Apply changes relating to updated deps

* Update changelogs

---------

Co-authored-by: stwiname <[email protected]>
  • Loading branch information
stwiname and stwiname authored Apr 29, 2024
1 parent c28272f commit 475c840
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 424 deletions.
2 changes: 2 additions & 0 deletions packages/common-near/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 (#109)

## [3.4.0] - 2024-04-10
### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/common-near/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",
"@subql/types-near": "workspace:*",
"js-yaml": "^4.1.0",
"reflect-metadata": "^0.1.13"
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 (#109)

## [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-near": "workspace:*",
"@subql/node-core": "^8.0.1",
"@subql/node-core": "^10.0.0",
"@subql/types-near": "workspace:*",
"cron-converter": "^1.0.2",
"eventemitter2": "^6.4.5",
Expand Down
9 changes: 2 additions & 7 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ export class ApiService extends BaseApiService<
);
}

await this.createConnections(
network,
(endpoint) => NearApiConnection.create(endpoint, this.fetchBlocksBatches),
async (connection: NearApiConnection) => {
const api = connection.unsafeApi;
return (await api.status()).chain_id;
},
await this.createConnections(network, (endpoint) =>
NearApiConnection.create(endpoint, this.fetchBlocksBatches),
);

return this;
Expand Down
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 @@ -20,7 +19,6 @@ import {
SubqueryProject,
} from '../../configure/SubqueryProject';
import { ApiService } from '../api.service';
import { DynamicDsService } from '../dynamic-ds.service';
import { IndexerManager } from '../indexer.manager';
import { BlockContent } from '../types';

Expand All @@ -40,24 +38,20 @@ export class BlockDispatcherService
@Inject('IProjectService') projectService: IProjectService<NearProjectDs>,
@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,
async (blockNums: number[]): Promise<IBlock<BlockContent>[]> => {
//filter out null values, they represent blocks that were not available in chain
return (await this.apiService.fetchBlocks(blockNums)).filter(
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,
StoreCacheService,
IProjectService,
Expand Down Expand Up @@ -43,7 +42,6 @@ export class WorkerBlockDispatcherService
@Inject('IProjectService') projectService: IProjectService<NearProjectDs>,
@Inject('IProjectUpgradeService')
projectUpgradeService: IProjectUpgradeService,
smartBatchService: SmartBatchService,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
Expand All @@ -58,12 +56,10 @@ export class WorkerBlockDispatcherService
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
storeService,
storeCacheService,
poiSyncService,
project,
dynamicDsService,
() =>
createIndexerWorker<
IIndexerWorker,
Expand Down
66 changes: 1 addition & 65 deletions packages/node/src/indexer/ds-processor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,7 @@ import {
NearDatasourceProcessor,
} from '@subql/common-near';
import { BaseDsProcessorService } from '@subql/node-core';
import {
SecondLayerHandlerProcessor_0_0_0,
SecondLayerHandlerProcessor_1_0_0,
NearCustomDatasource,
NearHandlerKind,
NearMapping,
NearCustomHandler,
} from '@subql/types-near';

export function isSecondLayerHandlerProcessor_0_0_0<
K extends NearHandlerKind,
F extends Record<string, unknown>,
E,
DS extends NearCustomDatasource = NearCustomDatasource,
>(
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 NearHandlerKind,
F extends Record<string, unknown>,
E,
DS extends NearCustomDatasource = NearCustomDatasource,
>(
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 NearHandlerKind,
F extends Record<string, unknown>,
E,
DS extends NearCustomDatasource = NearCustomDatasource,
>(
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]),
};
}
import { NearMapping, NearCustomHandler } from '@subql/types-near';

@Injectable()
export class DsProcessorService extends BaseDsProcessorService<
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 @@ -7,37 +7,28 @@ import {
DatasourceParams,
DynamicDsService as BaseDynamicDsService,
} from '@subql/node-core';
import { cloneDeep } from 'lodash';
import { NearProjectDs, SubqueryProject } from '../configure/SubqueryProject';
import { DsProcessorService } from './ds-processor.service';

@Injectable()
export class DynamicDsService extends BaseDynamicDsService<NearProjectDs> {
export class DynamicDsService extends BaseDynamicDsService<
NearProjectDs,
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<NearProjectDs> {
const t = this.project.templates.find(
(t) => t.name === params.templateName,
const dsObj = this.getTemplate<NearProjectDs>(
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 NearProjectDs;

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,
NodeConfig,
ConnectionPoolService,
SmartBatchService,
StoreCacheService,
ConnectionPoolStateManager,
IProjectUpgradeService,
PoiSyncService,
InMemoryCacheService,
SandboxService,
} from '@subql/node-core';
import { SubqueryProject } from '../configure/SubqueryProject';
import { ApiService } from './api.service';
Expand All @@ -30,7 +30,6 @@ import { FetchService } from './fetch.service';
import { IndexerManager } from './indexer.manager';
import { NearApiConnection } from './nearApi.connection';
import { ProjectService } from './project.service';
import { SandboxService } from './sandbox.service';
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';

@Module({
Expand All @@ -42,13 +41,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
IndexerManager,
ConnectionPoolService,
ConnectionPoolStateManager,
{
provide: SmartBatchService,
useFactory: (nodeConfig: NodeConfig) => {
return new SmartBatchService(nodeConfig.batchSize);
},
inject: [NodeConfig],
},
{
provide: 'IBlockDispatcher',
useFactory: (
Expand All @@ -58,7 +50,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
projectUpgradeService: IProjectUpgradeService,
apiService: ApiService,
indexerManager: IndexerManager,
smartBatchService: SmartBatchService,
cacheService: InMemoryCacheService,
storeService: StoreService,
storeCacheService: StoreCacheService,
Expand All @@ -74,7 +65,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
cacheService,
storeService,
storeCacheService,
Expand All @@ -91,12 +81,10 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
eventEmitter,
projectService,
projectUpgradeService,
smartBatchService,
storeService,
storeCacheService,
poiSyncService,
project,
dynamicDsService,
),
inject: [
NodeConfig,
Expand All @@ -105,7 +93,6 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
'IProjectUpgradeService',
ApiService,
IndexerManager,
SmartBatchService,
InMemoryCacheService,
StoreService,
StoreCacheService,
Expand Down
8 changes: 0 additions & 8 deletions packages/node/src/indexer/fetch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { calcInterval, nearHeaderToHeader } from '../utils/near';
import { ApiService } from './api.service';
import { INearBlockDispatcher } from './blockDispatcher';
import { NearDictionaryService } from './dictionary';
import { DsProcessorService } from './ds-processor.service';
import { DynamicDsService } from './dynamic-ds.service';
import { ProjectService } from './project.service';
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';

Expand All @@ -40,8 +38,6 @@ export class FetchService extends BaseFetchService<
@Inject('IBlockDispatcher')
blockDispatcher: INearBlockDispatcher,
dictionaryService: NearDictionaryService,
private dsProcessorService: DsProcessorService,
dynamicDsService: DynamicDsService,
private unfinalizedBlocksService: UnfinalizedBlocksService,
eventEmitter: EventEmitter2,
schedulerRegistry: SchedulerRegistry,
Expand All @@ -61,10 +57,6 @@ export class FetchService extends BaseFetchService<
return this.apiService.unsafeApi;
}

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

protected async getFinalizedHeight(): Promise<number> {
const finalizedHeader = (await this.api.block({ finality: 'final' }))
.header;
Expand Down
Loading

0 comments on commit 475c840

Please sign in to comment.