Skip to content
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
18 changes: 6 additions & 12 deletions indexer/src/cache/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ export default async function initCache(context: ResolverContext) {
};
MEMORY_CACHE.set(HASH_RATE_AND_TOTAL_DIFFICULTY_KEY, newValue);
} catch (err) {
console.error(
'[ERROR][CACHE][CONN_TIMEOUT] Failed to get hash rate and total difficulty',
err,
);
console.error('[WARN][CACHE][DB] Failed to get hash rate and total difficulty', err);
}
}

Expand All @@ -94,7 +91,7 @@ export default async function initCache(context: ResolverContext) {
const networkStatistics = await networkRepository.getNetworkStatistics();
MEMORY_CACHE.set(NETWORK_STATISTICS_KEY, networkStatistics);
} catch (err) {
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get network statistics', err);
console.error('[WARN][CACHE][DB] Failed to get network statistics', err);
}
}

Expand All @@ -109,23 +106,20 @@ export default async function initCache(context: ResolverContext) {
const nodeInfo = await networkRepository.getNodeInfo();
MEMORY_CACHE.set(NODE_INFO_KEY, nodeInfo);
} catch (err) {
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get node info', err);
console.error('[WARN][CACHE][DB] Failed to get node info', err);
}
}

/**
* Fetches and caches information about the blockchain node
*
* This includes node version, connectivity status, and other
* node-specific information that helps monitor the node's health.
* Fetches and caches information about number of blocks, transactions,
* and total gas used in each chain.
*/

async function getCountersOfEachChain() {
try {
const counters = await networkRepository.getCountersOfEachChain();
MEMORY_CACHE.set(COUNTERS_OF_EACH_CHAIN_KEY, counters);
} catch (err) {
console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get counters of each chain', err);
console.error('[WARN][CACHE][DB] Failed to get counters of each chain', err);
}
}

Expand Down
3 changes: 1 addition & 2 deletions indexer/src/kadena-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
} from 'graphql';

import initCache from '../cache/init';
import { getArrayEnvString } from '../utils/helpers';
import {
directiveEstimator,
fieldExtensionsEstimator,
Expand Down Expand Up @@ -520,7 +519,7 @@ export async function startGraphqlServer() {
// Capture heap snapshot at 1GB memory threshold
if (mem.heapUsed > 1 * 1024 * 1024 * 1024) {
const filename = `/snapshots/indexer-heap-1GB-${Date.now()}.heapsnapshot`;
console.warn(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`);
console.error(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`);
heapdump.writeSnapshot(filename);
}
};
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/services/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function initializeErrorMonitoring(): void {
]
.filter(Boolean)
.join(', ');
console.warn(`[WARN][MONITORING] Monitoring not initialized. Missing env: ${missing}`);
console.error(`[WARN][MONITORING][ENV] Monitoring not initialized. Missing env: ${missing}`);
return; // Monitoring disabled; keep local logging only
}

Expand Down
25 changes: 19 additions & 6 deletions indexer/src/services/price/price-updater.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import axios from 'axios';

import { PriceService } from './price.service';

export class PriceUpdaterService {
Expand All @@ -23,11 +21,26 @@ export class PriceUpdaterService {

private async updatePrice(): Promise<void> {
try {
const response = await axios.get(this.DIA_API_URL);
const price = response.data.Price;
this.priceService.setKdaUsdPrice(price);
const response = await fetch(this.DIA_API_URL, {
headers: {
Accept: 'application/json',
'User-Agent': 'node-fetch',
},
});

if (!response.ok) {
throw new Error(`HTTP ${response.status} - ${response.statusText}`);
}

const data = await response.json();

if (data?.Price === undefined) {
throw new Error('Price field is missing in API response');
}

this.priceService.setKdaUsdPrice(data.Price);
} catch (error) {
console.error('[ERROR][INT][INT_API] Failed to update KDA/USD price:', error);
console.error('[WARN][INT][INT_API] Failed to update KDA/USD price:', error);
}
}

Expand Down
12 changes: 0 additions & 12 deletions indexer/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ export function getRequiredEnvString(key: string): string {
return value;
}

/**
* Retrieves an optional environment variable as a string array.
* The environment variable is expected to be a comma-separated string.
*
* @param key - The name of the environment variable to retrieve.
* @returns The value of the environment variable as a string array, or an empty array if the variable is not set.
*/
export function getArrayEnvString(key: string): string[] {
const value = process.env[key] ?? '';
return value.split(',').filter(item => item.trim() !== '');
}

/**
* Checks if a value is null or undefined.
*
Expand Down