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 #282

Merged
merged 3 commits into from
Aug 23, 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-cosmos/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 deps (#282)

## [5.0.2] - 2024-08-12
### Changed
Expand Down
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": "^5.1.0",
"@subql/common": "^5.1.1",
"@subql/types-cosmos": "workspace:*",
"@subql/x-cosmology-telescope": "^1.4.14",
"fs-extra": "^11.1.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/common-cosmos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"rootDir": "src",
"tsBuildInfoFile": "dist/.tsbuildinfo",
"outDir": "dist",
"noImplicitAny": true,
"strict": true
"noImplicitAny": true
},
"references": [{"path": "../types"}],
"include": ["src/**/*"]
Expand Down
3 changes: 3 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Filter out transactions that can't be decoded (#280)
### Changed
- Enable strict ts setting (#282)
- Update deps (#282)

## [4.1.0] - 2024-08-12
### Added
Expand Down
3 changes: 2 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^5.1.1",
"@subql/common-cosmos": "workspace:*",
"@subql/node-core": "^14.1.1",
"@subql/node-core": "^14.1.2",
"@subql/types-cosmos": "workspace:*",
"lodash": "^4.17.21",
"protobufjs": "^6.11.4",
Expand Down
29 changes: 20 additions & 9 deletions packages/node/src/indexer/api.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function testCosmosProject(
schema: new GraphQLSchema({}),
templates: [],
tempDir: fileCacheDir,
} as SubqueryProject;
} as unknown as SubqueryProject;
}

jest.setTimeout(200000);
Expand All @@ -64,22 +64,32 @@ describe('ApiService', () => {
},
{
provide: NodeConfig,
useFactory: () => ({}),
useFactory: () =>
new NodeConfig(
{
kyveEndpoint: 'https://api-us-1.kyve.network',
kyveStorageUrl: 'https://arweave.net',
} as any,
true,
),
},
EventEmitter2,
ApiService,
NodeConfig,
{
provide: ApiService,
useFactory: ApiService.create.bind(ApiService),
inject: [
'ISubqueryProject',
ConnectionPoolService,
EventEmitter2,
NodeConfig,
],
},
],
imports: [EventEmitterModule.forRoot()],
}).compile();
app = module.createNestApplication();
await app.init();
apiService = app.get(ApiService);
(apiService as any).nodeConfig._config.kyveEndpoint =
'https://api-us-1.kyve.network';
(apiService as any).nodeConfig._config.kyveStorageUrl =
'https://arweave.net';
await apiService.init();
};

const ENDPOINT = 'https://rpc-juno.itastakers.com/';
Expand All @@ -89,6 +99,7 @@ describe('ApiService', () => {
beforeAll(async () => {
tmpPath = await makeTempDir();
});

it('Falls back on rpc if kyve fails', async () => {
const endpoint = 'https://rpc.mainnet.archway.io:443';
const chainId = 'archway-1';
Expand Down
82 changes: 48 additions & 34 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
import { CosmWasmClient, IndexedTx } from '@cosmjs/cosmwasm-stargate';
import { toHex } from '@cosmjs/encoding';
import { Uint53 } from '@cosmjs/math';
import { GeneratedType, Registry } from '@cosmjs/proto-signing';
import { Block, defaultRegistryTypes, SearchTxQuery } from '@cosmjs/stargate';
import { CometClient, toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { CosmosProjectNetConfig } from '@subql/common-cosmos';
import {
Expand Down Expand Up @@ -43,23 +44,19 @@ export class ApiService
extends BaseApiService<CosmosClient, CosmosSafeClient, IBlock<BlockContent>[]>
implements OnApplicationShutdown
{
private fetchBlocksBatches = CosmosUtil.fetchBlocksBatches;
private nodeConfig: CosmosNodeConfig;
private kyveApi?: KyveApi;
registry: Registry;

constructor(
@Inject('ISubqueryProject') private project: SubqueryProject,
private constructor(
connectionPoolService: ConnectionPoolService<CosmosClientConnection>,
eventEmitter: EventEmitter2,
nodeConfig: NodeConfig,
public registry: Registry,
private kyveApi?: KyveApi,
) {
super(connectionPoolService, eventEmitter);
this.nodeConfig = new CosmosNodeConfig(nodeConfig);
}

private async buildRegistry(): Promise<Registry> {
const chaintypes = await this.getChainType(this.project.network);
private static async buildRegistry(
network: Partial<CosmosProjectNetConfig>,
): Promise<Registry> {
const chaintypes = await this.getChainType(network);

const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [
['/cosmwasm.wasm.v1.MsgClearAdmin', MsgClearAdmin],
Expand All @@ -83,32 +80,33 @@ export class ApiService
await this.connectionPoolService.onApplicationShutdown();
}

async init(): Promise<ApiService> {
const { network } = this.project;
static async create(
project: SubqueryProject,
connectionPoolService: ConnectionPoolService<CosmosClientConnection>,
eventEmitter: EventEmitter2,
nodeConfig: NodeConfig,
): Promise<ApiService> {
const { network } = project;
const cosmosNodeConfig = new CosmosNodeConfig(nodeConfig);

this.registry = await this.buildRegistry();
const registry = await this.buildRegistry(network);

await this.createConnections(network, (endpoint, config) =>
CosmosClientConnection.create(
endpoint,
this.fetchBlocksBatches,
this.registry,
config,
),
);
let kyveApi: KyveApi | undefined;

if (
this.nodeConfig.kyveEndpoint &&
this.nodeConfig.kyveEndpoint !== 'false'
cosmosNodeConfig.kyveEndpoint &&
cosmosNodeConfig.kyveEndpoint !== 'false'
) {
try {
this.kyveApi = await KyveApi.create(
// TODO test
assert(project.tempDir, 'Expected temp dir to exist for using Kyve');
kyveApi = await KyveApi.create(
network.chainId,
this.nodeConfig.kyveEndpoint,
this.nodeConfig.kyveStorageUrl,
this.nodeConfig.kyveChainId,
this.project.tempDir,
KYVE_BUFFER_RANGE * this.nodeConfig.batchSize,
cosmosNodeConfig.kyveEndpoint,
cosmosNodeConfig.kyveStorageUrl,
cosmosNodeConfig.kyveChainId,
project.tempDir,
KYVE_BUFFER_RANGE * nodeConfig.batchSize,
);
} catch (e) {
logger.warn(`Kyve Api is not connected. ${e}`);
Expand All @@ -117,7 +115,23 @@ export class ApiService
logger.info(`Kyve not connected`);
}

return this;
const apiService = new ApiService(
connectionPoolService,
eventEmitter,
registry,
kyveApi,
);

await apiService.createConnections(network, (endpoint, config) =>
CosmosClientConnection.create(
endpoint,
CosmosUtil.fetchBlocksBatches,
registry,
config,
),
);

return apiService;
}

// Overrides the super function because of the kyve integration
Expand All @@ -129,7 +143,7 @@ export class ApiService
if (this.kyveApi) {
try {
return await this.kyveApi.fetchBlocksBatches(this.registry, heights);
} catch (e) {
} catch (e: any) {
logger.warn(
e,
`Failed to fetch blocks: ${JSON.stringify(
Expand All @@ -154,7 +168,7 @@ export class ApiService
}

// eslint-disable-next-line @typescript-eslint/require-await
async getChainType(
private static async getChainType(
network: Partial<CosmosProjectNetConfig>,
): Promise<Record<string, GeneratedType>> {
if (!network.chaintypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import { IBlockDispatcher } from '@subql/node-core';
import { BlockContent } from '../types';

export interface ICosmosBlockDispatcher extends IBlockDispatcher<BlockContent> {
init(onDynamicDsCreated: (height: number) => Promise<void>): Promise<void>;
init(
onDynamicDsCreated: (height: number) => void | Promise<void>,
): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class WorkerBlockDispatcherService
height: number,
): Promise<void> {
// const start = new Date();
await worker.fetchBlock(height, null);
await worker.fetchBlock(height, 0 /* Value is not used with cosmos*/);
// const end = new Date();

// const waitTime = end.getTime() - start.getTime();
Expand Down
16 changes: 6 additions & 10 deletions packages/node/src/indexer/cosmosClient.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ export class CosmosClientConnection
IBlock<BlockContent>[]
>
{
private cometClient: CometClient;
private registry: Registry;
readonly networkMeta: NetworkMetadataPayload;

private constructor(
public unsafeApi: CosmosClient,
private fetchBlocksBatches: FetchFunc,
chainId: string,
private cometClient: CometClient,
private registry: Registry,
) {
this.networkMeta = {
chain: chainId,
specName: undefined,
genesisHash: undefined,
specName: undefined as any,
genesisHash: undefined as any, // Cant always get the genesis hash because of pruning
};
}

Expand Down Expand Up @@ -115,9 +115,9 @@ export class CosmosClientConnection
api,
fetchBlocksBatches,
await api.getChainId(),
cometClient,
registry,
);
connection.cometClient = cometClient;
connection.setRegistry(registry);

logger.info(`connected to ${endpoint}`);

Expand All @@ -128,10 +128,6 @@ export class CosmosClientConnection
return new CosmosSafeClient(this.cometClient, height);
}

private setRegistry(registry: Registry): void {
this.registry = registry;
}

// eslint-disable-next-line @typescript-eslint/require-await
async apiConnect(): Promise<void> {
this.unsafeApi = new CosmosClient(this.cometClient, this.registry);
Expand Down
Loading
Loading