Skip to content

Commit

Permalink
Fix: Resolve Type Warnings for ConfigService.get() (#3350)
Browse files Browse the repository at this point in the history
* fix: resolve type warnings for ConfigService.get()

 - Ensured type consistency in all affected test cases.
 - Removed unnecessary type casting or added necessary casting.

Signed-off-by: belloibrahv <[email protected]>

* fix: resolve type warnings for ConfigService.get()

 - Ensured type consistency in all affected test cases.
 - Removed unnecessary type casting or added necessary casting.

Signed-off-by: belloibrahv <[email protected]>

* Refactor GlobalConfig and revert header changes as per feedback

Signed-off-by: belloibrahv <[email protected]>

* Reverting License Header Changes

Signed-off-by: belloibrahv <[email protected]>

* Refinment of ConfigService.get() (to conform to newly suggested changes)

Signed-off-by: belloibrahv <[email protected]>

* Refactor ConfigService.get to enhance type safety and remove manual casting

Signed-off-by: belloibrahv <[email protected]>

* fix bugs in workflow

Signed-off-by: belloibrahv <[email protected]>

* Remove assesrtion

Signed-off-by: belloibrahv <[email protected]>

* Remove assesrtion

Signed-off-by: belloibrahv <[email protected]>

* Add assertion to _CONFIG (in the globalConfig.ts file)

Signed-off-by: belloibrahv <[email protected]>

* chore: renamed types and added explanation

Signed-off-by: Logan Nguyen <[email protected]>

* fix: loosen strict type checking for array types in config variables

Signed-off-by: Logan Nguyen <[email protected]>

* fix: modified GetTypeOfConfigKey to resolve to better types

Signed-off-by: Logan Nguyen <[email protected]>

* fix: updated properly default values to all global configs

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed ConfigService unit test

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed LocalLRUCache suite

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed HbarSpendingPlanConfigService suite

Signed-off-by: Logan Nguyen <[email protected]>

* chore: updated type explanation

Signed-off-by: Logan Nguyen <[email protected]>

Revert "chore: updated type explanation"

This reverts commit ecd8d6e.

Reapply "chore: updated type explanation"

This reverts commit 6756ecb1ee558c7d20fb8f7a71e2fbee70bb75ad.

* fix: modified typeCasting to always convert CHAIN_ID to hexadecimal value

Signed-off-by: Logan Nguyen <[email protected]>

* fix: further tighten ConfigService.get()

Signed-off-by: Logan Nguyen <[email protected]>

* Update web3.ts

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed test in net

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed test in web3

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed eth_feeHistory

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed filter API

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed HbarLimitService unit test

Signed-off-by: Logan Nguyen <[email protected]>

Revert "fixed shouldLimit v1"

This reverts commit 2f745e6f6188d7c4d84da931793544200420d073.

Reapply "fixed shouldLimit v1"

This reverts commit f280bbf311a4e407ed2c158d372581e2b8b36e25.

s

Signed-off-by: Logan Nguyen <[email protected]>

Revert "fix: fixed HbarLimitService unit test"

This reverts commit ec28eee.

Reapply "fix: fixed HbarLimitService unit test"

This reverts commit e27bae25cb51f5a49db525c5e66e08b3da2c3c15.
Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed utils.spec.ts

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed BATCH_REQUESTS_ENABLED enabled by default

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed ws-server unit

Signed-off-by: Logan Nguyen <[email protected]>

* chore: switch MULTI_SET to false

Signed-off-by: Logan Nguyen <[email protected]>

* fix: fixed newHeads test

Signed-off-by: Logan Nguyen <[email protected]>

* fix: removed type array in GlobalConfig

Signed-off-by: Logan Nguyen <[email protected]>

* fix: reverted Copyright

Signed-off-by: Logan Nguyen <[email protected]>

* chore: converted JSDoc to TSDoc

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constant CACHE_MAX with config

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constant CACHE_TTL.ONEHOUR with config 'CACHE_TTL'

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constants.SEND_RAW_TRANSACTION_SIZE_LIMIT with config

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constants. DEFAULT_ETH_GET_LOGS_BLOCK_RANGE_LIMIT with config value

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constants.ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE with config

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constants.MIRROR_NODE_RETRY_DELAY_DEFAULT with config

Signed-off-by: Logan Nguyen <[email protected]>

* chore: replaced constants.MIRROR_NODE_REQUEST_RETRY_COUNT_DEFAULT with config

Signed-off-by: Logan Nguyen <[email protected]>

* fix(ci): fixed ci test with fallback log level

Signed-off-by: Logan Nguyen <[email protected]>

Revert "fix(ci): fixed ci test with fallback log level"

This reverts commit 9af4396.

Reapply "fix(ci): fixed ci test with fallback log level"

This reverts commit bd81c5729ffa7e4e20cf07cccbec718aff61af9b.

Revert "fix(ci): fixed ci test with fallback log level"

This reverts commit 981cad0a66a4e487d6e396dfcc0fa1123f19296f.

Reapply "fix(ci): fixed ci test with fallback log level"

This reverts commit 87eb44fd5fcd09156210cd431d7a0d00e9f8e720.

* fix: alphabeticalized configuration tables

Signed-off-by: Logan Nguyen <[email protected]>

---------

Signed-off-by: belloibrahv <[email protected]>
Signed-off-by: Logan Nguyen <[email protected]>
Co-authored-by: Logan Nguyen <[email protected]>
  • Loading branch information
belloibrahv and quiet-node authored Feb 6, 2025
1 parent 4389821 commit 237b452
Show file tree
Hide file tree
Showing 73 changed files with 1,331 additions and 1,255 deletions.
129 changes: 69 additions & 60 deletions docs/configuration.md

Large diffs are not rendered by default.

1,517 changes: 796 additions & 721 deletions packages/config-service/src/services/globalConfig.ts

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions packages/config-service/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import dotenv from 'dotenv';
import findConfig from 'find-config';
import pino from 'pino';

import type { ConfigKey, GetTypeOfConfigKey } from './globalConfig';
import { GlobalConfig } from './globalConfig';
import { LoggerService } from './loggerService';
import { ValidationService } from './validationService';

Expand Down Expand Up @@ -93,11 +95,35 @@ export class ConfigService {
}

/**
* Get an env var by name
* @param name string
* @returns string | undefined
* Retrieves the value of a specified configuration property using its key name.
*
* The method incorporates validation to ensure required configuration values are provided.
*
* **Note:** The validations in this method, in addition to the `ValidationService.startUp(process.env)` in the constructor, are crucial
* as this method is frequently invoked in testing environments where configuration values might be dynamically
* overridden. Additionally, since this method is the most exposed method across different packages, serving as the
* main gateway for accessing configurations, these validations help strengthen security and prevent undefined
* behavior in both production and testing scenarios.
*
* For the CHAIN_ID key, the value is converted to a hexadecimal format prefixed with '0x'.
*
* @param name - The configuration key to retrieve.
* @typeParam K - The specific type parameter representing the ConfigKey.
* @returns The value associated with the specified key, or the default value from its GlobalConfig entry, properly typed based on the key's configuration.
* @throws Error if a required configuration value is missing.
*/
public static get(name: string): string | number | boolean | null | undefined {
return this.getInstance().envs[name];
public static get<K extends ConfigKey>(name: K): GetTypeOfConfigKey<K> {
const configEntry = GlobalConfig.ENTRIES[name];
let value = this.getInstance().envs[name] == undefined ? configEntry?.defaultValue : this.getInstance().envs[name];

if (value == undefined && configEntry?.required) {
throw new Error(`Configuration error: ${name} is a mandatory configuration for relay operation.`);
}

if (name === 'CHAIN_ID' && value !== undefined) {
value = `0x${Number(value).toString(16)}`;
}

return value as GetTypeOfConfigKey<K>;
}
}
17 changes: 12 additions & 5 deletions packages/config-service/src/services/validationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,33 @@ export class ValidationService {
Object.entries(GlobalConfig.ENTRIES).forEach(([entryName, entryInfo]) => {
if (entryInfo.required) {
if (!envs.hasOwnProperty(entryName)) {
throw new Error(`${entryName} is a mandatory and the relay cannot operate without its value.`);
throw new Error(`Configuration error: ${entryName} is a mandatory configuration for relay operation.`);
}

if (entryInfo.type === 'number' && isNaN(Number(envs[entryName]))) {
throw new Error(`${entryName} must be a valid number.`);
throw new Error(`Configuration error: ${entryName} must be a valid number.`);
}
}
});
}

/**
* Transform string env variables to the proper formats (number/boolean/string)
* @param envs
* Transform string environment variables to their proper types based on GlobalConfig.ENTRIES.
* For each entry:
* - If the env var is missing but has a default value, use the default
* - For 'number' type, converts to Number
* - For 'boolean' type, converts 'true' string to true boolean
* - For 'string' and 'array' types, keeps as string
*
* @param envs - Dictionary of environment variables and their string values
* @returns Dictionary with environment variables cast to their proper types
*/
static typeCasting(envs: NodeJS.Dict<string>): NodeJS.Dict<any> {
const typeCastedEnvs: NodeJS.Dict<any> = {};

Object.entries(GlobalConfig.ENTRIES).forEach(([entryName, entryInfo]) => {
if (!envs.hasOwnProperty(entryName)) {
if (entryInfo.defaultValue) {
if (entryInfo.defaultValue != null) {
typeCastedEnvs[entryName] = entryInfo.defaultValue;
}
return;
Expand Down
71 changes: 68 additions & 3 deletions packages/config-service/tests/src/services/configService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import { ConfigService } from '../../../src/services';
import { type ConfigKey, GlobalConfig } from '../../../src/services/globalConfig';

chai.use(chaiAsPromised);

Expand Down Expand Up @@ -50,13 +52,76 @@ describe('ConfigService tests', async function () {

it('should be able to get existing env var', async () => {
const res = ConfigService.get('CHAIN_ID');

expect(res).to.equal('0x12a');
});

it('should return undefined for non-existing variable', async () => {
const res = ConfigService.get('NON_EXISTING_VAR');

const res = ConfigService.get('NON_EXISTING_VAR' as ConfigKey);
expect(res).to.equal(undefined);
});

it('should return the default value for configurations not set in process.env', async () => {
const targetKey = 'FILE_APPEND_MAX_CHUNKS';
const envValue = process.env[targetKey];

// ensure the key is not listed in env
expect(envValue).to.be.undefined;

const expectedDefaultValue = GlobalConfig.ENTRIES[targetKey].defaultValue;

const res = ConfigService.get(targetKey);
expect(res).to.equal(expectedDefaultValue);
});

it('should infer the explicit type for configuration which is either required or has a valid defaultValue', () => {
const targetKeys = [
'FILE_APPEND_MAX_CHUNKS',
'GET_RECORD_DEFAULT_TO_CONSENSUS_NODE',
'E2E_RELAY_HOST',
'ETH_CALL_ACCEPTED_ERRORS',
] as ConfigKey[];

targetKeys.forEach((targetKey) => {
const result = ConfigService.get(targetKey);
const expectedTypeString = GlobalConfig.ENTRIES[targetKey].type;

switch (expectedTypeString) {
case 'number':
expect(typeof result === 'number').to.be.true;
break;
case 'boolean':
expect(typeof result === 'boolean').to.be.true;
break;
case 'string':
expect(typeof result === 'string').to.be.true;
break;
}
});
});

it('Should always convert CHAIN_ID to a hexadecimal string, regardless of input value type.', async () => {
const originalEnv = process.env;

const testChainId = (input: string, expected: string) => {
process.env = { ...originalEnv, CHAIN_ID: input };
// Reset the ConfigService singleton instance to force a new initialization
// This is necessary because ConfigService caches the env values when first instantiated,
// so we need to clear that cache to test with our new CHAIN_ID value
// @ts-ignore - accessing private property for testing
delete ConfigService.instance;
expect(ConfigService.get('CHAIN_ID')).to.equal(expected);
};

try {
// Test cases
testChainId('298', '0x12a'); // decimal number
testChainId('0x12a', '0x12a'); // hexadecimal with prefix
testChainId('1000000', '0xf4240'); // larger number
testChainId('0xhedera', '0xNaN'); // invalid number
} finally {
process.env = originalEnv;
// @ts-ignore - accessing private property for testing
delete ConfigService.instance;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('LoggerService tests', async function () {
});

it('should be able to return plain information', async () => {
const envName = GlobalConfig.ENTRIES.CHAIN_ID.envName;
const envName = 'CHAIN_ID';
const res = ConfigService.get(envName);

expect(LoggerService.maskUpEnv(envName, res)).to.equal(`${envName} = ${res}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ValidationService tests', async function () {

it('should fail fast if mandatory env is not passed', async () => {
expect(() => ValidationService.startUp({})).to.throw(
'CHAIN_ID is a mandatory and the relay cannot operate without its value.',
'Configuration error: CHAIN_ID is a mandatory configuration for relay operation.',
);
});

Expand Down Expand Up @@ -77,7 +77,7 @@ describe('ValidationService tests', async function () {
ValidationService.startUp({
...mandatoryStartUpFields,
}),
).to.throw('npm_package_version is a mandatory and the relay cannot operate without its value.');
).to.throw('Configuration error: npm_package_version is a mandatory configuration for relay operation.');
});
});

Expand All @@ -92,8 +92,8 @@ describe('ValidationService tests', async function () {

it('should skip adding value if it is missing and there is no default value set', async () => {
const castedEnvs = ValidationService.typeCasting({});
expect(castedEnvs).to.not.haveOwnProperty(GlobalConfig.ENTRIES.FILTER_TTL.envName);
expect(castedEnvs[GlobalConfig.ENTRIES.FILTER_TTL.envName]).to.be.undefined;
expect(castedEnvs).to.not.haveOwnProperty(GlobalConfig.ENTRIES.GH_ACCESS_TOKEN.envName);
expect(castedEnvs[GlobalConfig.ENTRIES.GH_ACCESS_TOKEN.envName]).to.be.undefined;
});

it('should to cast string type', async () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/relay/src/lib/clients/cache/localLRUCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import { Logger } from 'pino';
import { Gauge, Registry } from 'prom-client';
import { ICacheClient } from './ICacheClient';
import constants from '../../constants';
import LRUCache, { LimitedByCount, LimitedByTTL } from 'lru-cache';
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { RequestDetails } from '../../types';
Expand All @@ -40,11 +39,9 @@ export class LocalLRUCache implements ICacheClient {
*/
private readonly options: LimitedByCount & LimitedByTTL = {
// The maximum number (or size) of items that remain in the cache (assuming no TTL pruning or explicit deletions).
// @ts-ignore
max: Number.parseInt(ConfigService.get('CACHE_MAX') ?? constants.CACHE_MAX.toString()),
max: ConfigService.get('CACHE_MAX'),
// Max time to live in ms, for items before they are considered stale.
// @ts-ignore
ttl: Number.parseInt(ConfigService.get('CACHE_TTL') ?? constants.CACHE_TTL.ONE_HOUR.toString()),
ttl: ConfigService.get('CACHE_TTL'),
};

/**
Expand Down
6 changes: 2 additions & 4 deletions packages/relay/src/lib/clients/cache/redisCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export class RedisCache implements IRedisCacheClient {
*/
private readonly options = {
// Max time to live in ms, for items before they are considered stale.
// @ts-ignore
ttl: Number.parseInt(ConfigService.get('CACHE_TTL') ?? constants.CACHE_TTL.ONE_HOUR.toString()),
ttl: ConfigService.get('CACHE_TTL'),
};

/**
Expand Down Expand Up @@ -79,8 +78,7 @@ export class RedisCache implements IRedisCacheClient {
this.register = register;

const redisUrl = ConfigService.get('REDIS_URL')!;
// @ts-ignore
const reconnectDelay = parseInt(ConfigService.get('REDIS_RECONNECT_DELAY_MS') || '1000');
const reconnectDelay = ConfigService.get('REDIS_RECONNECT_DELAY_MS');
this.client = createClient({
// @ts-ignore
url: redisUrl,
Expand Down
64 changes: 20 additions & 44 deletions packages/relay/src/lib/clients/mirrorNodeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ export class MirrorNodeClient {
private static readonly GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT = `contracts/${MirrorNodeClient.ADDRESS_PLACEHOLDER}/results/logs`;
private static readonly GET_CONTRACT_RESULTS_DETAILS_BY_CONTRACT_ID_ENDPOINT = `contracts/${MirrorNodeClient.CONTRACT_ID_PLACEHOLDER}/results/${MirrorNodeClient.TIMESTAMP_PLACEHOLDER}`;
private static readonly GET_CONTRACT_RESULTS_DETAILS_BY_ADDRESS_AND_TIMESTAMP_ENDPOINT = `contracts/${MirrorNodeClient.ADDRESS_PLACEHOLDER}/results/${MirrorNodeClient.TIMESTAMP_PLACEHOLDER}`;
private readonly MIRROR_NODE_RETRY_DELAY = parseNumericEnvVar(
'MIRROR_NODE_RETRY_DELAY',
'MIRROR_NODE_RETRY_DELAY_DEFAULT',
);
private readonly MIRROR_NODE_REQUEST_RETRY_COUNT = parseNumericEnvVar(
'MIRROR_NODE_REQUEST_RETRY_COUNT',
'MIRROR_NODE_REQUEST_RETRY_COUNT_DEFAULT',
);
private readonly MIRROR_NODE_RETRY_DELAY = ConfigService.get('MIRROR_NODE_RETRY_DELAY');
private readonly MIRROR_NODE_REQUEST_RETRY_COUNT = ConfigService.get('MIRROR_NODE_REQUEST_RETRY_COUNT');

static acceptedErrorStatusesResponsePerRequestPathMap: Map<string, Array<number>> = new Map([
[MirrorNodeClient.GET_ACCOUNTS_BY_ID_ENDPOINT, [404]],
Expand Down Expand Up @@ -161,47 +155,29 @@ export class MirrorNodeClient {

static readonly EVM_ADDRESS_REGEX: RegExp = /\/accounts\/([\d\.]+)/;

public static readonly mirrorNodeContractResultsPageMax = parseInt(
// @ts-ignore
ConfigService.get('MIRROR_NODE_CONTRACT_RESULTS_PG_MAX') || 25,
public static readonly mirrorNodeContractResultsPageMax = ConfigService.get('MIRROR_NODE_CONTRACT_RESULTS_PG_MAX');
public static readonly mirrorNodeContractResultsLogsPageMax = ConfigService.get(
'MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX',
);
public static readonly mirrorNodeContractResultsLogsPageMax =
// @ts-ignore
parseInt(ConfigService.get('MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX') || 200);

protected createAxiosClient(baseUrl: string): AxiosInstance {
// defualt values for axios clients to mirror node
// @ts-ignore
const mirrorNodeTimeout = parseInt(ConfigService.get('MIRROR_NODE_TIMEOUT') || '10000');
// @ts-ignore
const mirrorNodeMaxRedirects = parseInt(ConfigService.get('MIRROR_NODE_MAX_REDIRECTS') || '5');
const mirrorNodeTimeout = ConfigService.get('MIRROR_NODE_TIMEOUT');
const mirrorNodeMaxRedirects = ConfigService.get('MIRROR_NODE_MAX_REDIRECTS');
const mirrorNodeHttpKeepAlive = ConfigService.get('MIRROR_NODE_HTTP_KEEP_ALIVE');
// @ts-ignore
const mirrorNodeHttpKeepAliveMsecs = parseInt(ConfigService.get('MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS') || '1000');
// @ts-ignore
const mirrorNodeHttpMaxSockets = parseInt(ConfigService.get('MIRROR_NODE_HTTP_MAX_SOCKETS') || '300');
// @ts-ignore
const mirrorNodeHttpMaxTotalSockets = parseInt(ConfigService.get('MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS') || '300');
// @ts-ignore
const mirrorNodeHttpSocketTimeout = parseInt(ConfigService.get('MIRROR_NODE_HTTP_SOCKET_TIMEOUT') || '60000');
const mirrorNodeHttpKeepAliveMsecs = ConfigService.get('MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS');
const mirrorNodeHttpMaxSockets = ConfigService.get('MIRROR_NODE_HTTP_MAX_SOCKETS');
const mirrorNodeHttpMaxTotalSockets = ConfigService.get('MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS');
const mirrorNodeHttpSocketTimeout = ConfigService.get('MIRROR_NODE_HTTP_SOCKET_TIMEOUT');
const isDevMode = ConfigService.get('DEV_MODE');
// @ts-ignore
const mirrorNodeRetries = parseInt(ConfigService.get('MIRROR_NODE_RETRIES') || '0'); // we are in the process of deprecating this feature
// @ts-ignore
const mirrorNodeRetriesDevMode = parseInt(ConfigService.get('MIRROR_NODE_RETRIES_DEVMODE') || '5');
const mirrorNodeRetries = ConfigService.get('MIRROR_NODE_RETRIES'); // we are in the process of deprecating this feature
const mirrorNodeRetriesDevMode = ConfigService.get('MIRROR_NODE_RETRIES_DEVMODE');
const mirrorNodeRetryDelay = this.MIRROR_NODE_RETRY_DELAY;
// @ts-ignore
const mirrorNodeRetryDelayDevMode = parseInt(ConfigService.get('MIRROR_NODE_RETRY_DELAY_DEVMODE') || '200');
const mirrorNodeRetryErrorCodes = ConfigService.get('MIRROR_NODE_RETRY_CODES')
? // @ts-ignore
JSON.parse(ConfigService.get('MIRROR_NODE_RETRY_CODES'))
: []; // we are in the process of deprecating this feature
// by default will be true, unless explicitly set to false.
// @ts-ignore
const mirrorNodeRetryDelayDevMode = ConfigService.get('MIRROR_NODE_RETRY_DELAY_DEVMODE');
const mirrorNodeRetryErrorCodes = JSON.parse(ConfigService.get('MIRROR_NODE_RETRY_CODES')); // we are in the process of deprecating this feature by default will be true, unless explicitly set to false.
const useCacheableDnsLookup: boolean = ConfigService.get('MIRROR_NODE_AGENT_CACHEABLE_DNS');

const httpAgent = new http.Agent({
// @ts-ignore
keepAlive: mirrorNodeHttpKeepAlive,
keepAliveMsecs: mirrorNodeHttpKeepAliveMsecs,
maxSockets: mirrorNodeHttpMaxSockets,
Expand Down Expand Up @@ -258,6 +234,7 @@ export class MirrorNodeClient {
return delay;
},
retryCondition: (error) => {
// @ts-ignore
return !error?.response?.status || mirrorNodeRetryErrorCodes.includes(error?.response?.status);
},
shouldResetTimeout: true,
Expand Down Expand Up @@ -313,11 +290,11 @@ export class MirrorNodeClient {
this.cacheService = cacheService;

// set up eth call accepted error codes.
if (ConfigService.get('ETH_CALL_ACCEPTED_ERRORS')) {
const parsedAcceptedError = JSON.parse(ConfigService.get('ETH_CALL_ACCEPTED_ERRORS'));
if (parsedAcceptedError.length != 0) {
MirrorNodeClient.acceptedErrorStatusesResponsePerRequestPathMap.set(
MirrorNodeClient.CONTRACT_CALL_ENDPOINT,
// @ts-ignore
JSON.parse(ConfigService.get('ETH_CALL_ACCEPTED_ERRORS')),
parsedAcceptedError,
);
}
}
Expand Down Expand Up @@ -1326,8 +1303,7 @@ export class MirrorNodeClient {
this.setQueryParam(queryParamObject, 'limit', limitOrderParams.limit);
this.setQueryParam(queryParamObject, 'order', limitOrderParams.order);
} else {
// @ts-ignore
this.setQueryParam(queryParamObject, 'limit', parseInt(ConfigService.get('MIRROR_NODE_LIMIT_PARAM') || '100'));
this.setQueryParam(queryParamObject, 'limit', ConfigService.get('MIRROR_NODE_LIMIT_PARAM'));
this.setQueryParam(queryParamObject, 'order', constants.ORDER.ASC);
}
}
Expand Down
Loading

0 comments on commit 237b452

Please sign in to comment.