Skip to content

Commit

Permalink
fix: move registry request constants to env
Browse files Browse the repository at this point in the history
  • Loading branch information
avsetsin committed Sep 11, 2022
1 parent 3c7d40c commit d15feed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/common/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export interface Configuration {
KAFKA_SASL_MECHANISM: SASLMechanism;
KAFKA_USERNAME: string;
KAFKA_PASSWORD: string;
REGISTRY_KEYS_QUERY_BATCH_SIZE: number;
REGISTRY_KEYS_QUERY_CONCURRENCY: number;
}
21 changes: 20 additions & 1 deletion src/common/config/in-memory-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Transform } from 'class-transformer';
import { IsIn, IsNotEmpty, IsNumber, IsString, Min } from 'class-validator';
import {
IsIn,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Min,
} from 'class-validator';
import { Injectable } from '@nestjs/common';
import { Configuration, PubsubService } from './configuration';
import { SASLMechanism } from '../../transport';
Expand Down Expand Up @@ -69,4 +76,16 @@ export class InMemoryConfiguration implements Configuration {
@IsNotEmpty()
@IsString()
KAFKA_PASSWORD = '';

@IsOptional()
@IsNumber()
@Min(1)
@Transform(({ value }) => parseInt(value, 10), { toClassOnly: true })
REGISTRY_KEYS_QUERY_BATCH_SIZE = 200;

@IsOptional()
@IsNumber()
@Min(1)
@Transform(({ value }) => parseInt(value, 10), { toClassOnly: true })
REGISTRY_KEYS_QUERY_CONCURRENCY = 5;
}
2 changes: 0 additions & 2 deletions src/contracts/registry/registry.constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { NodeOperatorsCache } from './interfaces';

export const REGISTRY_KEYS_QUERY_BATCH_SIZE = 200;
export const REGISTRY_KEYS_QUERY_CONCURRENCY = 5;
export const REGISTRY_KEYS_CACHE_UPDATE_BLOCK_RATE = 20;

export const REGISTRY_CACHE_FILE_NAME = 'registry.keys.json';
Expand Down
16 changes: 8 additions & 8 deletions src/contracts/registry/registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { ProviderService, BlockTag } from 'provider';
import { SecurityService } from 'contracts/security';
import { DepositService } from 'contracts/deposit';
import { RepositoryService } from 'contracts/repository';
import {
REGISTRY_KEYS_CACHE_UPDATE_BLOCK_RATE,
REGISTRY_KEYS_QUERY_BATCH_SIZE,
REGISTRY_KEYS_QUERY_CONCURRENCY,
} from './registry.constants';
import { REGISTRY_KEYS_CACHE_UPDATE_BLOCK_RATE } from './registry.constants';
import {
NodeOperator,
NodeOperatorsCache,
Expand All @@ -19,6 +15,7 @@ import {
import { range, rangePromise, splitPubKeys } from 'utils';
import { CacheService } from 'cache';
import { OneAtTime } from 'common/decorators';
import { Configuration } from 'common/config';
import { BlockData } from 'guardian';
import { APP_VERSION } from 'app.constants';

Expand All @@ -31,6 +28,7 @@ export class RegistryService {
private depositService: DepositService,
private repositoryService: RepositoryService,
private cacheService: CacheService<NodeOperatorsCache>,
private config: Configuration,
) {}

@OneAtTime()
Expand Down Expand Up @@ -245,8 +243,8 @@ export class RegistryService {
return await this.getNodeOperatorKey(operatorId, keyId, blockTag);
};

const batchSize = REGISTRY_KEYS_QUERY_BATCH_SIZE;
const concurrency = REGISTRY_KEYS_QUERY_CONCURRENCY;
const batchSize = this.config.REGISTRY_KEYS_QUERY_BATCH_SIZE;
const concurrency = this.config.REGISTRY_KEYS_QUERY_CONCURRENCY;
const groupSize = batchSize * concurrency;

return await rangePromise(fetcher, from, to, groupSize);
Expand All @@ -263,7 +261,9 @@ export class RegistryService {
keyId: number,
blockTag?: BlockTag,
): Promise<NodeOperatorsKey> {
const seedKey = Math.floor(keyId / REGISTRY_KEYS_QUERY_BATCH_SIZE);
const seedKey = Math.floor(
keyId / this.config.REGISTRY_KEYS_QUERY_BATCH_SIZE,
);
const contract = await this.getCachedBatchContract(seedKey);
const overrides = { blockTag: blockTag as any };

Expand Down

0 comments on commit d15feed

Please sign in to comment.