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

Add kyve support #235

Merged
merged 82 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
8e4f4ba
add kyve support, add matching tests
bz888 Mar 3, 2024
9ab621d
update comments
bz888 Mar 4, 2024
5938615
add typing and add cached blocks
bz888 Mar 4, 2024
bedd2c4
fix up binary search, add tests
bz888 Mar 25, 2024
460b7c6
revert jest config changes
bz888 Mar 25, 2024
c5511b7
revert jest config chnages on bad rebase
bz888 Mar 25, 2024
64ddf08
wip on rebuild logs
bz888 Mar 26, 2024
7aa1a5e
add parser for wrapEvents without using logs, add tests
bz888 Mar 28, 2024
3778763
add cli support for kyve
bz888 Mar 29, 2024
841287d
add cli support for kyve
bz888 Mar 29, 2024
e4b7def
use nodeConfig for kyve cli integration, update kyve api, add storage…
bz888 Apr 2, 2024
e17a4e9
add kyveConnection class, refactor cosmos wrappers to use registry ov…
bz888 Apr 4, 2024
0e850fc
update and refactor based on review
bz888 Apr 4, 2024
db397be
remove todo
bz888 Apr 4, 2024
f928774
update logic for lazyBlock and refactored based on comments, added te…
bz888 Apr 5, 2024
27d6ad1
update logic and test
bz888 Apr 5, 2024
b7f6757
update logic on getBlockByHeight
bz888 Apr 5, 2024
ea4fce9
update test cache
bz888 Apr 5, 2024
79fd593
update changelog
bz888 Apr 5, 2024
aa0090c
fixed kyve test
bz888 Apr 5, 2024
b345316
update yargs
bz888 Apr 5, 2024
0440ed9
tidy ups
bz888 Apr 7, 2024
18acfa9
refactor with worker and file cache logic, addeds tests
bz888 Apr 8, 2024
5bf216c
added more test, refactored polling logic and added write stream
bz888 Apr 9, 2024
1f6f3fa
update tmpDir root
bz888 Apr 9, 2024
c94b218
fixed tests, refactor based on comments
bz888 Apr 10, 2024
8c5c57a
fix kyve connections
bz888 Apr 10, 2024
8ebb313
refactor fetch block funciton on api service to support kyve
bz888 Apr 11, 2024
c5e3657
update tests
bz888 Apr 11, 2024
dc371fe
fix mock stream tests
bz888 Apr 11, 2024
f62e1b0
update workers fetch module and changelog
bz888 Apr 11, 2024
1ac6fad
rebase main
bz888 Apr 12, 2024
c8d1070
fix up on bad rebase
bz888 Apr 12, 2024
fdcd23c
add clean up on failed bundle handling, rework error handle to ensure…
bz888 Apr 12, 2024
1d4a41c
update with fixes on kyveApi cache, add test for more batchSize and w…
bz888 Apr 14, 2024
44a5280
add fileCache support for local reader
bz888 Apr 15, 2024
dd70d21
add listener on fetch block
bz888 Apr 15, 2024
34c8597
add listener for clear cache
bz888 Apr 15, 2024
510f70b
fix removal bundle on failed fetch test
bz888 Apr 15, 2024
6d0f85a
update clear cache, added test
bz888 Apr 16, 2024
0178985
ensure working tests on cache file removal
bz888 Apr 16, 2024
39d4318
add fetch cache on bundles
bz888 Apr 16, 2024
e802860
update tests with correct values and fixes
bz888 Apr 16, 2024
f0d3051
update tests
bz888 Apr 16, 2024
d5da980
refactor based on review, removed fetchingBundle cache, fixed polling…
bz888 Apr 17, 2024
f37102a
tidy up
bz888 Apr 17, 2024
3ba4fa1
fix api service kyve test
bz888 Apr 17, 2024
491989d
refactor based on review, update tmpDir, update error handling on str…
bz888 Apr 17, 2024
72d0947
update tests
bz888 Apr 17, 2024
d57f260
fix up poller;
bz888 Apr 17, 2024
14b2b5a
fix test cases, update logic in removal
bz888 Apr 17, 2024
6fbf6b0
update bundle regex, tidy up based on review
bz888 Apr 21, 2024
606501c
fix regex, update changelog
bz888 Apr 22, 2024
1a3e9c4
update tests
bz888 Apr 22, 2024
af78550
tidy up test
bz888 Apr 22, 2024
0abf7f7
add logging
bz888 Apr 22, 2024
da5cb94
add await for poller and fix bundleCache id
bz888 Apr 22, 2024
2d1d76b
refactor cacheBundle to be object
bz888 Apr 22, 2024
4e91cb3
Fixes and improvements (#252)
bz888 Apr 23, 2024
5367715
Fix cache gaps, added timeout on stream
bz888 Apr 23, 2024
a3e2e1e
Fixes and Improvements
bz888 Apr 23, 2024
96b2fbc
Update bundleId increment
bz888 Apr 23, 2024
5070979
Fix for stale polling
bz888 Apr 23, 2024
ee55964
fix chmod permission
bz888 Apr 23, 2024
56b245f
Fixes and improvements based on review
bz888 Apr 24, 2024
cde6d33
Remove finally on download, fix reconstructed logs
bz888 Apr 24, 2024
fc3a159
add stale file remover
bz888 Apr 24, 2024
bd12975
tidy up
bz888 Apr 25, 2024
ee3f727
add log
bz888 Apr 25, 2024
c1e1b6d
tidy up based on review, add test
bz888 Apr 26, 2024
8d0a87b
update unlink file;
bz888 Apr 26, 2024
f4ba219
tidy up and add test for stale cleaner, disable kyve with false
bz888 Apr 26, 2024
3602f0a
Merge branch 'main' into add/kyve-api
bz888 Apr 26, 2024
81ff31b
update yarn.lock
bz888 Apr 26, 2024
e5c0e67
update tests with non prune block
bz888 Apr 26, 2024
a000f6d
fix up tests
bz888 Apr 26, 2024
4c8f230
Fix timeout, move buffer arg to constructor
stwiname Apr 30, 2024
8e1e1e6
Fix up types, improve kyve error handling, fix kyve temp dir
stwiname May 1, 2024
6cdccf2
Clean up deps
stwiname May 1, 2024
125a2ac
Fix not applying timestamp block filers
stwiname May 1, 2024
997c94d
Update deps and use code from node-core
stwiname May 1, 2024
e138dc5
Add script for updating versions:
stwiname May 1, 2024
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@actions/core": "^1.10.0",
"@babel/preset-env": "^7.16.11",
"@octokit/request": "^5.6.3",
"@types/cron-converter": "^1",
"@types/node": "^18.16.10",
"@types/node-fetch": "2.6.2",
"@typescript-eslint/eslint-plugin": "^5.10.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ 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]
### Added
- Support for KYVE integration with supporting flags (#235)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are the defaults to enable kyve by default?

- `--kyve-endpoint` (default value is `https://api-us-1.kyve.network`, To disable use `false`)
- `--kyve-chain-id` (default value is `kyve-1`)
- `--kyve-storage-url` (default value is `https://arweave.net`)
### Removed
- Unused @apollo/client dependency causing version conflicts (#253)

### Changed
- Update dependencies and apply changes to match (#254)

Expand Down
9 changes: 3 additions & 6 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/proto-signing": "^0.32.3",
"@cosmjs/stargate": "^0.32.3",
"@kyvejs/protocol": "^1.0.12",
"@kyvejs/sdk": "^1.1.1",
"@nestjs/common": "^9.4.0",
"@nestjs/core": "^9.4.0",
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^3.5.1",
"@subql/common-cosmos": "workspace:*",
"@subql/node-core": "^10.0.0",
"@subql/node-core": "^10.1.0",
"@subql/types-cosmos": "workspace:*",
"cron-converter": "^1.0.2",
"eventemitter2": "^6.4.5",
"lodash": "^4.17.21",
"pg": "^8.7.1",
"protobufjs": "^6.11.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.2",
"vm2": "^3.9.9",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
41 changes: 41 additions & 0 deletions packages/node/src/configure/NodeConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { SupportedChains } from '@kyvejs/sdk/src/constants';
import { IConfig, NodeConfig } from '@subql/node-core';

export interface ICosmosConfig extends IConfig {
kyveChainId: SupportedChains;
kyveEndpoint: string;
kyveStorageUrl: string;
}

export class CosmosNodeConfig extends NodeConfig<ICosmosConfig> {
bz888 marked this conversation as resolved.
Show resolved Hide resolved
/**
* This is a wrapper around the core NodeConfig to get additional properties that are provided through args or node runner options
* NOTE: This isn't injected anywhere, so you need to wrap the injected node config
*
* @example
* constructor(
* nodeConfig: NodeConfig,
* ) {
* this.nodeConfig = new CosmosNodeConfig(nodeConfig);
* }
* */
constructor(config: NodeConfig) {
// Rebuild with internal config
super((config as any)._config, (config as any)._isTest);
}

get kyveEndpoint(): string {
return this._config.kyveEndpoint;
}

get kyveChainId(): SupportedChains {
return this._config.kyveChainId;
}

get kyveStorageUrl(): string {
return this._config.kyveStorageUrl;
}
}
44 changes: 34 additions & 10 deletions packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
import fs from 'fs';
import os from 'os';
import { sep } from 'path';
import { isMainThread } from 'worker_threads';
import { Injectable } from '@nestjs/common';
import { validateSemver } from '@subql/common';
import {
CosmosProjectNetworkConfig,
parseCosmosProjectManifest,
CosmosDataSource,
ProjectManifestV1_0_0Impl,
isRuntimeCosmosDs,
isCustomCosmosDs,
} from '@subql/common-cosmos';
import {
CronFilter,
insertBlockFiltersCronSchedules,
ISubqueryProject,
loadProjectTemplates,
SubqlProjectDs,
updateDataSourcesV1_0_0,
WorkerHost,
} from '@subql/node-core';
import { ParentProject, Reader, RunnerSpecs } from '@subql/types-core';
import {
CosmosDatasource,
CustomDatasourceTemplate,
RuntimeDatasourceTemplate,
CosmosHandlerKind,
CosmosBlockFilter,
} from '@subql/types-cosmos';
import { buildSchemaFromString } from '@subql/utils';
import Cron from 'cron-converter';
import { GraphQLSchema } from 'graphql';
import { processNetworkConfig } from '../utils/project';

const { version: packageVersion } = require('../../package.json');

export type CosmosProjectDs = SubqlProjectDs<CosmosDataSource>;

export type CosmosProjectDsTemplate =
| SubqlProjectDs<RuntimeDatasourceTemplate>
| SubqlProjectDs<CustomDatasourceTemplate>;
| RuntimeDatasourceTemplate
| CustomDatasourceTemplate;

export type SubqlProjectBlockFilter = CosmosBlockFilter & CronFilter;

const NOT_SUPPORT = (name: string) => {
throw new Error(`Manifest specVersion ${name} is not supported`);
Expand All @@ -47,22 +52,23 @@ type NetworkConfig = CosmosProjectNetworkConfig & { chainId: string };

@Injectable()
export class SubqueryProject implements ISubqueryProject {
#dataSources: CosmosProjectDs[];
#dataSources: CosmosDatasource[];

constructor(
readonly id: string,
readonly root: string,
readonly network: NetworkConfig,
dataSources: CosmosProjectDs[],
dataSources: CosmosDatasource[],
readonly schema: GraphQLSchema,
readonly templates: CosmosProjectDsTemplate[],
readonly runner?: RunnerSpecs,
readonly parent?: ParentProject,
readonly tempDir?: string,
) {
this.#dataSources = dataSources;
}

get dataSources(): CosmosProjectDs[] {
get dataSources(): CosmosDatasource[] {
return this.#dataSources;
}

Expand Down Expand Up @@ -112,6 +118,23 @@ export class SubqueryProject implements ISubqueryProject {

type SUPPORT_MANIFEST = ProjectManifestV1_0_0Impl;

/**
* Gets a temp dir shared between main thread and workers
* */
function getTempDir(): string {
if (isMainThread) return fs.mkdtempSync(`${os.tmpdir()}${sep}`);
const workerTempDir = (
(global as any).host as WorkerHost<any> | undefined
)?.getWorkerData()?.tempDir;

if (!workerTempDir) {
throw new Error(
'Worker expected tempDir to be provided through workerData',
);
}
return workerTempDir;
}

async function loadProjectFromManifestBase(
projectManifest: SUPPORT_MANIFEST,
reader: Reader,
Expand Down Expand Up @@ -177,5 +200,6 @@ async function loadProjectFromManifestBase(
templates,
runner,
projectManifest.parent,
getTempDir(),
);
}
120 changes: 82 additions & 38 deletions packages/node/src/indexer/api.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,59 @@ import { toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
import { INestApplication } from '@nestjs/common';
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
import { Test } from '@nestjs/testing';
import { loadFromJsonOrYaml } from '@subql/common';
import { ConnectionPoolService, delay, NodeConfig } from '@subql/node-core';
import { loadFromJsonOrYaml, makeTempDir } from '@subql/common';
import {
ConnectionPoolService,
ConnectionPoolStateManager,
NodeConfig,
} from '@subql/node-core';
import { GraphQLSchema } from 'graphql';
import { SubqueryProject } from '../configure/SubqueryProject';
import { ApiService } from './api.service';

const ENDPOINT = 'https://rpc-juno.itastakers.com/';
const CHAINID = 'juno-1';

const TEST_BLOCKNUMBER = 3266772;

const projectsDir = path.join(__dirname, '../../test');

function testCosmosProject(): SubqueryProject {
function testCosmosProject(
endpoint: string,
chainId: string,
fileCacheDir?: string,
): SubqueryProject {
return {
network: {
endpoint: ENDPOINT,
chainId: CHAINID,
endpoint: [endpoint],
chainId: chainId,
},
dataSources: [],
id: 'test',
root: './',
schema: new GraphQLSchema({}),
templates: [],
tempDir: fileCacheDir,
} as SubqueryProject;
}

jest.setTimeout(200000);

describe.skip('ApiService', () => {
describe('ApiService', () => {
let app: INestApplication;
let apiService: ApiService;
const prepareApiService = async () => {

let tmpPath: string;

const prepareApiService = async (
endpoint: string,
chainId: string,
fileCacheDir?: string,
) => {
const module = await Test.createTestingModule({
providers: [
ConnectionPoolStateManager,
ConnectionPoolService,
{
provide: 'ISubqueryProject',
useFactory: () => testCosmosProject(),
useFactory: () => testCosmosProject(endpoint, chainId, fileCacheDir),
},
{
provide: NodeConfig,
Expand All @@ -61,38 +75,68 @@ describe.skip('ApiService', () => {
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();
};

beforeAll(async () => {
await prepareApiService();
});
const ENDPOINT = 'https://rpc-juno.itastakers.com/';
const CHAINID = 'juno-1';

describe('RPC api service', () => {
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';

await prepareApiService(endpoint, chainId, tmpPath);

it('query block info', async () => {
const api = apiService.api;
const blockInfo = await api.blockInfo(TEST_BLOCKNUMBER);
const doc: any = loadFromJsonOrYaml(
path.join(projectsDir, 'block_3266772.json'),
);
const realBlockInfo = {
id: toHex(doc.block_id.hash).toUpperCase(),
header: {
version: {
block: new Uint53(+doc.block.header.version.block).toString(),
app: blockInfo.block.header.version.app,
jest
.spyOn((apiService as any).kyveApi, 'retrieveBundleData')
.mockRejectedValueOnce(
'Error: Client network socket disconnected before secure TLS connection was established',
);

const rpcFetchSpy = jest.spyOn(apiService as any, 'retryFetch');

await apiService.fetchBlocks([4282099]);

expect(rpcFetchSpy).toHaveBeenCalledTimes(1);
});
it.skip('query block info', async () => {
await prepareApiService(ENDPOINT, CHAINID, tmpPath);

const api = apiService.api;
const blockInfo = await api.blockInfo(TEST_BLOCKNUMBER);
const doc: any = loadFromJsonOrYaml(
path.join(projectsDir, 'block_3266772.json'),
);
const realBlockInfo = {
id: toHex(doc.block_id.hash).toUpperCase(),
header: {
version: {
block: new Uint53(+doc.block.header.version.block).toString(),
app: blockInfo.block.header.version.app,
},
height: doc.block.header.height,
chainId: doc.block.header.chainId,
time: toRfc3339WithNanoseconds(doc.block.header.time),
},
height: doc.block.header.height,
chainId: doc.block.header.chainId,
time: toRfc3339WithNanoseconds(doc.block.header.time),
},
txs: doc.block.txs,
};
expect(blockInfo).toMatchObject(realBlockInfo);
});
txs: doc.block.txs,
};
expect(blockInfo).toMatchObject(realBlockInfo);
});

it.skip('query tx info by height', async () => {
await prepareApiService(ENDPOINT, CHAINID, tmpPath);

it('query tx info by height', async () => {
const api = apiService.api;
const txInfos = await api.txInfoByHeight(TEST_BLOCKNUMBER);
expect(txInfos.length).toEqual(4);
const api = apiService.api;
const txInfos = await api.txInfoByHeight(TEST_BLOCKNUMBER);
expect(txInfos.length).toEqual(4);
});
});
});
Loading
Loading