Skip to content

Commit

Permalink
Merge pull request #750 from oceanprotocol/issue-728-misleading-msg
Browse files Browse the repository at this point in the history
check if rpcs and indexer_networks are aligned, log
  • Loading branch information
paulo-ocean authored Nov 29, 2024
2 parents 69e082f + af3161c commit 8358d8e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ function getSupportedChains(): RPCS | null {

function getIndexingNetworks(supportedNetworks: RPCS): RPCS | null {
const indexerNetworksEnv = process.env.INDEXER_NETWORKS

const defaultErrorMsg =
'Missing or invalid "INDEXER_NETWORKS" variable. Running Indexer with all supported networks defined in RPCS env variable...'
if (!indexerNetworksEnv) {
CONFIG_LOGGER.logMessageWithEmoji(
'INDEXER_NETWORKS is not defined, running Indexer with all supported networks defined in RPCS env variable ...',
defaultErrorMsg,
true,
GENERIC_EMOJIS.EMOJI_CHECK_MARK,
LOG_LEVELS_STR.LEVEL_INFO
Expand All @@ -114,9 +117,10 @@ function getIndexingNetworks(supportedNetworks: RPCS): RPCS | null {
try {
const indexerNetworks: number[] = JSON.parse(indexerNetworksEnv)

// env var exists but is wrong, so it does not index anything, but we still log the error
if (indexerNetworks.length === 0) {
CONFIG_LOGGER.logMessageWithEmoji(
'INDEXER_NETWORKS is an empty array, Running node without the Indexer component...',
'"INDEXER_NETWORKS" is an empty array, Running node without the Indexer component...',
true,
GENERIC_EMOJIS.EMOJI_CROSS_MARK,
LOG_LEVELS_STR.LEVEL_ERROR
Expand All @@ -132,10 +136,21 @@ function getIndexingNetworks(supportedNetworks: RPCS): RPCS | null {
return acc
}, {})

// if variables are not aligned we might end up not running indexer at all, so at least we should log a warning
if (Object.keys(filteredNetworks).length === 0) {
CONFIG_LOGGER.logMessageWithEmoji(
`"RPCS" chains: "${Object.keys(
supportedNetworks
)}" and "INDEXER_NETWORKS" chains: "${indexerNetworks}" mismatch! Running node without the Indexer component...`,
true,
GENERIC_EMOJIS.EMOJI_CROSS_MARK,
LOG_LEVELS_STR.LEVEL_ERROR
)
}
return filteredNetworks
} catch (e) {
CONFIG_LOGGER.logMessageWithEmoji(
'Missing or Invalid INDEXER_NETWORKS env variable format,running Indexer with all supported networks defined in RPCS env variable ...',
defaultErrorMsg,
true,
GENERIC_EMOJIS.EMOJI_CROSS_MARK,
LOG_LEVELS_STR.LEVEL_ERROR
Expand Down

0 comments on commit 8358d8e

Please sign in to comment.