From 2359529b8c26f83074216fbb2ef986bc88d5d58c Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Mon, 9 Dec 2024 14:03:52 +0000 Subject: [PATCH 1/2] recalculate hash if needed --- src/index.ts | 10 +++++++--- src/utils/config.ts | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1796a87b9..a66577c9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,12 @@ declare global { } } +export async function recalculateCodeHash(): Promise { + const __filename = fileURLToPath(import.meta.url) + const __dirname = path.dirname(__filename) + const codeHash = await computeCodebaseHash(__dirname) + return codeHash +} // we have 5 json examples // we should have some DDO class too function loadInitialDDOS(): any[] { @@ -74,9 +80,7 @@ OCEAN_NODE_LOGGER.logMessageWithEmoji( ) const config = await getConfiguration(true, isStartup) -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) -config.codeHash = await computeCodebaseHash(__dirname) +config.codeHash = await recalculateCodeHash() OCEAN_NODE_LOGGER.info(`Codebase hash: ${config.codeHash}`) if (!config) { diff --git a/src/utils/config.ts b/src/utils/config.ts index 17d4fc020..afc495c74 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -26,6 +26,7 @@ import { } from '../utils/address.js' import { CONFIG_LOGGER } from './logging/common.js' import { create256Hash } from './crypt.js' +import { recalculateCodeHash } from '..' // usefull for lazy loading and avoid boilerplate on other places let previousConfiguration: OceanNodeConfig = null @@ -475,6 +476,10 @@ export async function getConfiguration( if (!previousConfiguration || forceReload) { previousConfiguration = await getEnvConfig(isStartup) } + if (!previousConfiguration.codeHash) { + previousConfiguration.codeHash = await recalculateCodeHash() + } + return previousConfiguration } From b3c26dcaa9c710c3d6fcdac88c15d569dda6d7e6 Mon Sep 17 00:00:00 2001 From: paulo-ocean Date: Mon, 9 Dec 2024 14:22:11 +0000 Subject: [PATCH 2/2] remove import function, dependency problem --- src/index.ts | 10 +++------- src/utils/config.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index a66577c9b..1796a87b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,12 +37,6 @@ declare global { } } -export async function recalculateCodeHash(): Promise { - const __filename = fileURLToPath(import.meta.url) - const __dirname = path.dirname(__filename) - const codeHash = await computeCodebaseHash(__dirname) - return codeHash -} // we have 5 json examples // we should have some DDO class too function loadInitialDDOS(): any[] { @@ -80,7 +74,9 @@ OCEAN_NODE_LOGGER.logMessageWithEmoji( ) const config = await getConfiguration(true, isStartup) -config.codeHash = await recalculateCodeHash() +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) +config.codeHash = await computeCodebaseHash(__dirname) OCEAN_NODE_LOGGER.info(`Codebase hash: ${config.codeHash}`) if (!config) { diff --git a/src/utils/config.ts b/src/utils/config.ts index afc495c74..b15d63df7 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -9,6 +9,7 @@ import { C2DClusterType } from '../@types/C2D.js' import { createFromPrivKey } from '@libp2p/peer-id-factory' import { keys } from '@libp2p/crypto' import { + computeCodebaseHash, DEFAULT_RATE_LIMIT_PER_SECOND, ENVIRONMENT_VARIABLES, EnvVariable, @@ -26,7 +27,8 @@ import { } from '../utils/address.js' import { CONFIG_LOGGER } from './logging/common.js' import { create256Hash } from './crypt.js' -import { recalculateCodeHash } from '..' +import { fileURLToPath } from 'url' +import path from 'path' // usefull for lazy loading and avoid boilerplate on other places let previousConfiguration: OceanNodeConfig = null @@ -477,7 +479,9 @@ export async function getConfiguration( previousConfiguration = await getEnvConfig(isStartup) } if (!previousConfiguration.codeHash) { - previousConfiguration.codeHash = await recalculateCodeHash() + const __filename = fileURLToPath(import.meta.url) + const __dirname = path.dirname(__filename.replace('utils/', '')) + previousConfiguration.codeHash = await computeCodebaseHash(__dirname) } return previousConfiguration