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 20240702 #128

Merged
merged 4 commits into from
Jul 2, 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
16 changes: 3 additions & 13 deletions packages/common-algorand/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@
} from '@subql/types-algorand';
import {BaseMapping, NodeSpec, ParentProject, QuerySpec, RunnerSpecs} from '@subql/types-core';
import {plainToInstance, Transform, Type} from 'class-transformer';
import {
Equals,
IsArray,
IsNotEmpty,
IsObject,
IsOptional,
IsString,
Validate,
ValidateNested,
validateSync,
} from 'class-validator';
import {Equals, IsArray, IsObject, IsOptional, IsString, Validate, ValidateNested, validateSync} from 'class-validator';
import yaml from 'js-yaml';
import {CustomDataSourceBase, RuntimeDataSourceBase} from '../../models';
import {TokenHeader} from '../../types';
Expand All @@ -43,7 +33,7 @@

@IsString()
@Validate(SemverVersionValidator)
version: string;
version: string = ALGORAND_NODE_NAME;
}

export class AlgorandRunnerSpecsImpl implements RunnerSpecs {
Expand Down Expand Up @@ -80,7 +70,7 @@

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

Check warning on line 73 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 73 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 Expand Up @@ -153,7 +143,7 @@
}

@Equals('1.0.0')
specVersion: string;
specVersion = '1.0.0';

@IsString()
name: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed
- Bump version with `@subql/common-algorand`,`@subql/node-core`
- Bump version with `@subql/common-algorand`, sync with `@subql/node-core`, add admin module

## [3.11.3] - 2024-05-14
### Fixed
Expand Down
4 changes: 4 additions & 0 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ RUN rm /app.tgz && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache

# Create ./.monitor directory and set permissions
RUN mkdir -p .monitor && \
chown 1000:1000 .monitor

# Make the user not ROOT
USER 1000

Expand Down
13 changes: 13 additions & 0 deletions packages/node/src/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { Module } from '@nestjs/common';
import { adminControllers, adminServices } from '@subql/node-core';
import { FetchModule } from '../indexer/fetch.module';

@Module({
imports: [FetchModule],
controllers: [...adminControllers],
providers: [...adminServices],
})
export class AdminModule {}
7 changes: 5 additions & 2 deletions packages/node/src/algorand/api.service.algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getLogger,
IBlock,
MetadataMismatchError,
exitWithError,
} from '@subql/node-core';
import { ProjectNetworkConfig } from '@subql/types-core';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand Down Expand Up @@ -38,8 +39,10 @@ export class AlgorandApiService extends ApiService<
try {
network = this.project.network;
} catch (e) {
logger.error(Object.keys(e));
process.exit(1);
exitWithError(
new Error(`Failed to init api`, { cause: e }),
logger,
);
}

await this.createConnections(network, (endpoint) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { ScheduleModule } from '@nestjs/schedule';
import { DbModule } from '@subql/node-core';
import { AdminModule } from './admin/admin.module';
import { ConfigureModule } from './configure/configure.module';
import { FetchModule } from './indexer/fetch.module';
import { MetaModule } from './meta/meta.module';
Expand All @@ -17,6 +18,7 @@ import { MetaModule } from './meta/meta.module';
ScheduleModule.forRoot(),
FetchModule,
MetaModule,
AdminModule,
],
controllers: [],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IProjectUpgradeService,
InMemoryCacheService,
createIndexerWorker,
MonitorServiceInterface,
} from '@subql/node-core';
import { AlgorandBlock, AlgorandDataSource } from '@subql/types-algorand';
import { AlgorandApiConnection } from '../../algorand';
Expand Down Expand Up @@ -52,6 +53,7 @@ export class WorkerBlockDispatcherService
dynamicDsService: DynamicDsService,
unfinalizedBlocksService: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<AlgorandApiConnection>,
monitorService?: MonitorServiceInterface,
) {
super(
nodeConfig,
Expand All @@ -78,7 +80,9 @@ export class WorkerBlockDispatcherService
connectionPoolState,
project.root,
projectService.startHeight,
monitorService,
),
monitorService,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,35 @@
import { EventEmitter2 } from '@nestjs/event-emitter';
import { NETWORK_FAMILY } from '@subql/common';
import { DictionaryService, NodeConfig } from '@subql/node-core';
import {
AlgorandDataSource,
AlgorandDataSourceKind,
} from '@subql/types-algorand';
import { MetaData } from '@subql/utils';
import { AlgorandDictionaryV1 } from './algorandDictionaryV1';

const mockDs = [
{
startBlock: 8712119,
kind: AlgorandDataSourceKind.Runtime,
mapping: {
handlers: [
{
filter: {
txType: 'axfer',
sender:
'ZW3ISEHZUHPO7OZGMKLKIIMKVICOUDRCERI454I3DB2BH52HGLSO67W754',
assetId: 27165954,
},
kind: 'algorand/TransactionHandler',
handler: 'handleTransaction',
},
],
file: './dist/index.js',
},
},
] as AlgorandDataSource[];

const nodeConfig = {
dictionaryTimeout: 10000,
dictionaryRegistry:
Expand All @@ -16,6 +42,7 @@ const project = {
network: {
chainId: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
},
dataSources: mockDs,
} as any;

class TestDictionaryService extends DictionaryService<any, any> {
Expand Down Expand Up @@ -48,6 +75,7 @@ describe('dictionary v1', () => {
chainId: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
dictionary: dictionaryEndpoints[1],
},
dataSources: mockDs,
} as any,
{ dictionaryTimeout: 10000 } as NodeConfig,
jest.fn(),
Expand All @@ -72,4 +100,29 @@ describe('dictionary v1', () => {
),
).toBeTruthy();
});

it('build correct dictionary entries and remove undefined fields in filter', () => {
expect(dictionary.buildDictionaryQueryEntries(mockDs)).toEqual([
{
conditions: [
{
field: 'txType',
matcher: 'equalTo',
value: 'axfer',
},
{
field: 'sender',
matcher: 'equalTo',
value: 'ZW3ISEHZUHPO7OZGMKLKIIMKVICOUDRCERI454I3DB2BH52HGLSO67W754',
},
{
field: 'assetId',
matcher: 'equalTo',
value: 27165954,
},
],
entity: 'transactions',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ function buildDictionaryV1QueryEntries<
case AlgorandHandlerKind.Transaction:
filterList.forEach((f) => {
const conditions: DictionaryQueryCondition[] = Object.entries(f)
.filter(([field]) => field !== 'applicationArgs') // Dictionary doesn't support applciation args
.filter(
([field, value]) =>
field !== 'applicationArgs' && value !== undefined,
)
.map(([field, value]) => ({
field,
value,
Expand Down
7 changes: 6 additions & 1 deletion packages/node/src/indexer/fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IProjectUpgradeService,
InMemoryCacheService,
SandboxService,
MonitorService,
} from '@subql/node-core';
import { AlgorandApiConnection, AlgorandApiService } from '../algorand';
import { SubqueryProject } from '../configure/SubqueryProject';
Expand Down Expand Up @@ -74,6 +75,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService: DynamicDsService,
unfinalizedBlocksService: UnfinalizedBlocksService,
connectionPoolState: ConnectionPoolStateManager<AlgorandApiConnection>,
monitorService?: MonitorService,
) =>
nodeConfig.workers
? new WorkerBlockDispatcherService(
Expand All @@ -89,6 +91,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
dynamicDsService,
unfinalizedBlocksService,
connectionPoolState,
monitorService,
)
: new BlockDispatcherService(
apiService,
Expand Down Expand Up @@ -117,6 +120,7 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
DynamicDsService,
UnfinalizedBlocksService,
ConnectionPoolStateManager,
MonitorService,
],
},
FetchService,
Expand All @@ -133,7 +137,8 @@ import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
useClass: ProjectService,
provide: 'IProjectService',
},
MonitorService,
],
exports: [StoreService, StoreCacheService],
exports: [StoreService, StoreCacheService, MonitorService, PoiService],
})
export class FetchModule {}
6 changes: 6 additions & 0 deletions packages/node/src/indexer/worker/worker-fetch.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
InMemoryCacheService,
WorkerInMemoryCacheService,
SandboxService,
MonitorService,
WorkerMonitorService,
WorkerUnfinalizedBlocksService,
} from '@subql/node-core';
import { AlgorandApiService, AlgorandApiConnection } from '../../algorand';
Expand Down Expand Up @@ -63,6 +65,10 @@ import { WorkerService } from './worker.service';
useFactory: () =>
new WorkerUnfinalizedBlocksService((global as any).host),
},
{
provide: MonitorService,
useFactory: () => new WorkerMonitorService((global as any).host),
},
{
provide: InMemoryCacheService,
useFactory: () => new WorkerInMemoryCacheService((global as any).host),
Expand Down
9 changes: 4 additions & 5 deletions packages/node/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { NestFactory } from '@nestjs/core';
import { findAvailablePort } from '@subql/common';
import { getLogger, NestLogger } from '@subql/node-core';
import { exitWithError, getLogger, NestLogger } from '@subql/node-core';
import { AppModule } from './app.module';
import { FetchService } from './indexer/fetch.service';
import { yargsOptions } from './yargs';
Expand All @@ -24,12 +24,12 @@ export async function bootstrap(): Promise<void> {

const port = validate(argv.port) ?? (await findAvailablePort(DEFAULT_PORT));
if (!port) {
logger.error(
exitWithError(
`Unable to find available port (tried ports in range (${port}..${
port + 10
})). Try setting a free port manually by setting the --port flag`,
logger,
);
process.exit(1);
}

if (argv.unsafe) {
Expand All @@ -56,7 +56,6 @@ export async function bootstrap(): Promise<void> {

logger.info(`Node started on port: ${port}`);
} catch (e) {
logger.error(e, 'Node failed to start');
process.exit(1);
exitWithError(new Error('Node failed to start', { cause: e }), logger);
}
}
5 changes: 2 additions & 3 deletions packages/node/src/subcommands/testing.init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import { getLogger } from '@subql/node-core';
import { getLogger, exitWithError } from '@subql/node-core';
import { ConfigureModule } from '../configure/configure.module';
import { TestingService } from './testing.service';

Expand All @@ -13,8 +13,7 @@ export async function testingInit(): Promise<void> {
const testingService = new TestingService(nodeConfig, project);
await testingService.run();
} catch (e) {
logger.error(e, 'Testing failed');
process.exit(1);
exitWithError(new Error('Testing failed', { cause: e }), logger);
}
process.exit(0);
}
1 change: 0 additions & 1 deletion packages/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2017",
"sourceMap": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"rootDir": "src",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"target": "es2022",
"noImplicitAny": false,
"noImplicitThis": true,
"moduleResolution": "node",
Expand All @@ -11,7 +11,7 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2017", "ES2020"],
"lib": ["ES2022"],
"emitDecoratorMetadata": true,
"declaration": true,
"sourceMap": true,
Expand Down
Loading