diff --git a/packages/daemons/src/ethMultiClient/index.ts b/packages/daemons/src/ethMultiClient/index.ts index d03cfb208..3645e193d 100644 --- a/packages/daemons/src/ethMultiClient/index.ts +++ b/packages/daemons/src/ethMultiClient/index.ts @@ -1,7 +1,7 @@ import * as db from "@dappnode/db"; import { eventBus } from "@dappnode/eventbus"; import { params } from "@dappnode/params"; -import { runAtMostEvery, runOnlyOneSequentially, getConsensusUserSettings } from "@dappnode/utils"; +import { runAtMostEvery, runOnlyOneSequentially, getDefaultConsensusUserSettings } from "@dappnode/utils"; import { logs } from "@dappnode/logger"; import { EthClientRemote, @@ -70,10 +70,11 @@ export async function runEthClientInstaller( if (isConsensusClientMainnet(target)) await packageInstall(dappnodeInstaller, { name: target, - userSettings: getConsensusUserSettings({ - dnpName: target, - network: Network.Mainnet - }) + userSettings: { + [target]: getDefaultConsensusUserSettings({ + network: Network.Mainnet + }) + } }); else await packageInstall(dappnodeInstaller, { name: target }); } catch (e) { diff --git a/packages/dappmanager/src/calls/packageInstall.ts b/packages/dappmanager/src/calls/packageInstall.ts index e938c19d2..5059aa91e 100644 --- a/packages/dappmanager/src/calls/packageInstall.ts +++ b/packages/dappmanager/src/calls/packageInstall.ts @@ -1,6 +1,8 @@ -import { Routes } from "@dappnode/types"; +import { Network, Routes } from "@dappnode/types"; import { packageInstall as pkgInstall } from "@dappnode/installer"; import { dappnodeInstaller } from "../index.js"; +import { Consensus } from "@dappnode/stakers"; +import { logs } from "@dappnode/logger"; /** * Installs a DAppNode Package. @@ -26,4 +28,42 @@ export async function packageInstall({ userSettings, options }); + + ensureNimbusConnection(reqName); +} + +/** + * Nimbus package will be migrated from a monoservice to a multiservice package. + * beacon-validator will be split into beacon-chain and validator services. + * + * This function ensures both services are properly connected to the staker network + * after installing the new version. + * + * TODO: Remove this once all Nimbus packages are multiservice + */ +function ensureNimbusConnection(dnpName: string): void { + if (!dnpName.includes("nimbus")) { + logs.debug("Not a Nimbus package, skipping network reconnection"); + } + + logs.info("Ensuring Nimbus services are connected to the staker network"); + + const consensus: Consensus = new Consensus(dappnodeInstaller); + + const nimbusNetwork: Record = { + "nimbus.dnp.dappnode.eth": Network.Mainnet, + "nimbus-prater.dnp.dappnode.eth": Network.Prater, + "nimbus-gnosis.dnp.dappnode.eth": Network.Gnosis, + "nimbus-holesky.dnp.dappnode.eth": Network.Holesky + }; + + const network = nimbusNetwork[dnpName]; + + if (!network) { + logs.error("Could not determine the network for the Nimbus package"); + return; + } + + // Not awaited + consensus.persistSelectedConsensusIfInstalled(network); } diff --git a/packages/installer/src/ethClient/apiUrl.ts b/packages/installer/src/ethClient/apiUrl.ts index 2034abff5..246e9d67a 100644 --- a/packages/installer/src/ethClient/apiUrl.ts +++ b/packages/installer/src/ethClient/apiUrl.ts @@ -1,4 +1,4 @@ -import { buildNetworkAlias, getBeaconServiceName } from "@dappnode/utils"; +import { buildNetworkAlias } from "@dappnode/utils"; import { listPackageNoThrow } from "@dappnode/dockerapi"; /** @@ -27,27 +27,30 @@ export function getEthExecClientApiUrl(dnpName: string, port = 8545): string { * @param dnpName */ export async function getEthConsClientApiUrl(dnpName: string): Promise { - let port = 3500; - let domain = ""; + const defaultPort = 3500; + const defaultServiceName = "beacon-chain"; + + // TODO: Use beacon-chain..dncore.dappnode + const dnp = await listPackageNoThrow({ dnpName }); - if (dnp && typeof dnp.chain === "object" && dnp.chain.portNumber && dnp.chain.serviceName) { - port = dnp.chain.portNumber; - domain = buildNetworkAlias({ - dnpName: dnpName, - serviceName: dnp.chain.serviceName, - isMainOrMonoservice: false - }); - } else { - // Lighthouse, Teku and Prysm use 3500 - // Nimbus uses 4500 because it is a monoservice and the validator API is using that port - if (dnpName.includes("nimbus")) { - port = 4500; - } - domain = buildNetworkAlias({ - dnpName: dnpName, - serviceName: getBeaconServiceName(dnpName), + + if (!dnp || typeof dnp.chain !== "object") { + const domain = buildNetworkAlias({ + dnpName, + serviceName: defaultServiceName, isMainOrMonoservice: false }); + + return `http://${domain}:${defaultPort}`; } - return `http://${domain}:${port}`; + + const { chain: { portNumber = defaultPort, serviceName = defaultServiceName } = {} } = dnp; + + const domain = buildNetworkAlias({ + dnpName, + serviceName, + isMainOrMonoservice: false + }); + + return `http://${domain}:${portNumber}`; } diff --git a/packages/installer/src/ethClient/ethereumClient.ts b/packages/installer/src/ethClient/ethereumClient.ts index c003d419c..f8520bff7 100644 --- a/packages/installer/src/ethClient/ethereumClient.ts +++ b/packages/installer/src/ethClient/ethereumClient.ts @@ -3,7 +3,7 @@ import { Eth2ClientTarget, EthClientRemote, InstalledPackageDetailData } from "@ import * as db from "@dappnode/db"; import { eventBus } from "@dappnode/eventbus"; import { logs } from "@dappnode/logger"; -import { getConsensusUserSettings } from "@dappnode/utils"; +import { getDefaultConsensusUserSettings } from "@dappnode/utils"; import { packageInstall, packageGet, packageRemove } from "../calls/index.js"; import { ComposeFileEditor, parseServiceNetworks } from "@dappnode/dockercompose"; import { params } from "@dappnode/params"; @@ -317,10 +317,12 @@ export class EthereumClient { }); if (!consClientPkg) { // Get default cons client user settings and install cons client - const userSettings = getConsensusUserSettings({ - dnpName: consClient, - network: Network.Mainnet - }); + const userSettings = { + [consClient]: getDefaultConsensusUserSettings({ + network: Network.Mainnet + }) + }; + await packageInstall(dappnodeInstaller, { name: consClient, userSettings diff --git a/packages/stakers/src/consensus.ts b/packages/stakers/src/consensus.ts index 79c948d59..8f0bf28bd 100644 --- a/packages/stakers/src/consensus.ts +++ b/packages/stakers/src/consensus.ts @@ -11,8 +11,8 @@ import { import { StakerComponent } from "./stakerComponent.js"; import { DappnodeInstaller } from "@dappnode/installer"; import * as db from "@dappnode/db"; -import { listPackageNoThrow } from "@dappnode/dockerapi"; import { params } from "@dappnode/params"; +import { getDefaultConsensusUserSettings } from "@dappnode/utils"; // TODO: move ethereumClient logic here @@ -30,13 +30,6 @@ export class Consensus extends StakerComponent { [Network.Holesky]: db.consensusClientHolesky, [Network.Lukso]: db.consensusClientLukso }; - protected static readonly DefaultCheckpointSync: Record = { - [Network.Mainnet]: "https://checkpoint-sync.dappnode.io", - [Network.Prater]: "https://checkpoint-sync-prater.dappnode.io", - [Network.Gnosis]: "https://checkpoint-sync-gnosis.dappnode.io", - [Network.Holesky]: "https://checkpoint-sync-holesky.dappnode.io", - [Network.Lukso]: "https://checkpoints.mainnet.lukso.network" - }; protected static readonly CompatibleConsensus: Record = { [Network.Mainnet]: [ { dnpName: ConsensusClientMainnet.Prysm, minVersion: "3.0.4" }, @@ -85,16 +78,19 @@ export class Consensus extends StakerComponent { async persistSelectedConsensusIfInstalled(network: Network): Promise { const currentConsensusDnpName = this.DbHandlers[network].get(); if (currentConsensusDnpName) { - const isInstalled = Boolean(await listPackageNoThrow({ dnpName: currentConsensusDnpName })); + const isInstalled = await this.isPackageInstalled(currentConsensusDnpName); if (!isInstalled) { // update status in db this.DbHandlers[network].set(undefined); return; } + + const userSettings = await this.getUserSettings(network, currentConsensusDnpName); + await this.persistSelectedIfInstalled({ dnpName: currentConsensusDnpName, - userSettings: this.getUserSettings(currentConsensusDnpName, isInstalled, network) + userSettings }); await this.DbHandlers[network].set(currentConsensusDnpName); } @@ -103,115 +99,57 @@ export class Consensus extends StakerComponent { async setNewConsensus(network: Network, newConsensusDnpName: string | null) { const prevConsClientDnpName = this.DbHandlers[network].get(); + const userSettings = await this.getUserSettings(network, newConsensusDnpName); + await super.setNew({ newStakerDnpName: newConsensusDnpName, dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network], compatibleClients: Consensus.CompatibleConsensus[network], - userSettings: newConsensusDnpName - ? this.getUserSettings( - newConsensusDnpName, - !(await listPackageNoThrow({ dnpName: newConsensusDnpName })), - network - ) - : {}, + userSettings, prevClient: prevConsClientDnpName }); // persist on db if (newConsensusDnpName !== prevConsClientDnpName) await this.DbHandlers[network].set(newConsensusDnpName); } - private getUserSettings(newConsensusDnpName: string, shouldSetEnvironment: boolean, network: Network): UserSettings { - const validatorServiceName = this.getValidatorServiceName(newConsensusDnpName); - const beaconServiceName = this.getBeaconServiceName(newConsensusDnpName); - const defaultDappnodeGraffiti = "validating_from_DAppNode"; - const defaultFeeRecipient = "0x0000000000000000000000000000000000000000"; + private async getUserSettings(network: Network, newConsensusDnpName: string | null): Promise { + if (!newConsensusDnpName) return {}; + + const isPkgInstalled = await this.isPackageInstalled(newConsensusDnpName); + + const userSettings = { + // If the package is not installed, we use the default environment + environment: isPkgInstalled ? {} : getDefaultConsensusUserSettings({ network }).environment, + networks: this.getStakerNetworkSettings(network) + }; + + return userSettings; + } + + private getStakerNetworkSettings(network: Network): UserSettings["networks"] { + const validatorServiceName = "validator"; + const beaconServiceName = "beacon-chain"; + return { - environment: shouldSetEnvironment - ? beaconServiceName === validatorServiceName - ? { - [validatorServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, // TODO: consider setting the MEV fee recipient as the default - // Graffiti is a mandatory value - ["GRAFFITI"]: defaultDappnodeGraffiti, - // Checkpoint sync is an optional value - ["CHECKPOINT_SYNC_URL"]: Consensus.DefaultCheckpointSync[network] - } - } - : { - [validatorServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, - // Graffiti is a mandatory value - ["GRAFFITI"]: defaultDappnodeGraffiti - }, - - [beaconServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, - // Checkpoint sync is an optional value - ["CHECKPOINT_SYNC_URL"]: Consensus.DefaultCheckpointSync[network] - } - } - : {}, - networks: { - rootNetworks: { + rootNetworks: this.getComposeRootNetworks(network), + serviceNetworks: { + [beaconServiceName]: { [params.DOCKER_STAKER_NETWORKS[network]]: { - external: true + aliases: [`${beaconServiceName}.${network}.staker.dappnode`] }, [params.DOCKER_PRIVATE_NETWORK_NAME]: { - external: true + aliases: [`${beaconServiceName}.${network}.dncore.dappnode`] } }, - serviceNetworks: - beaconServiceName === validatorServiceName - ? { - "beacon-validator": { - [params.DOCKER_STAKER_NETWORKS[network]]: { - aliases: [`beacon-chain.${network}.staker.dappnode`, `validator.${network}.staker.dappnode`] - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - aliases: [`beacon-chain.${network}.dncore.dappnode`, `validator.${network}.dncore.dappnode`] - } - } - } - : { - "beacon-chain": { - [params.DOCKER_STAKER_NETWORKS[network]]: { - aliases: [`beacon-chain.${network}.staker.dappnode`] - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - aliases: [`beacon-chain.${network}.dncore.dappnode`] - } - }, - validator: { - [params.DOCKER_STAKER_NETWORKS[network]]: { - aliases: [`validator.${network}.staker.dappnode`] - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - aliases: [`validator.${network}.dncore.dappnode`] - } - } - } + [validatorServiceName]: { + [params.DOCKER_STAKER_NETWORKS[network]]: { + aliases: [`${validatorServiceName}.${network}.staker.dappnode`] + }, + [params.DOCKER_PRIVATE_NETWORK_NAME]: { + aliases: [`${validatorServiceName}.${network}.dncore.dappnode`] + } + } } }; } - - /** - * Get the validator service name. - * - Nimbus package is monoservice (beacon-validator) - * - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator) - */ - private getValidatorServiceName(newConsensusDnpName: string | null): string { - return newConsensusDnpName ? (newConsensusDnpName.includes("nimbus") ? "beacon-validator" : "validator") : ""; - } - - /** - * Get the beacon service name - * - Nimbus package is monoservice (beacon-validator) - * - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator) - */ - private getBeaconServiceName(newConsensusDnpName: string | null): string { - return newConsensusDnpName ? (newConsensusDnpName.includes("nimbus") ? "beacon-validator" : "beacon-chain") : ""; - } } diff --git a/packages/stakers/src/execution.ts b/packages/stakers/src/execution.ts index 0bc8a3d2d..6bba262b2 100644 --- a/packages/stakers/src/execution.ts +++ b/packages/stakers/src/execution.ts @@ -11,7 +11,6 @@ import { import { StakerComponent } from "./stakerComponent.js"; import { DappnodeInstaller, ethereumClient } from "@dappnode/installer"; import * as db from "@dappnode/db"; -import { listPackageNoThrow } from "@dappnode/dockerapi"; import { params } from "@dappnode/params"; // TODO: move ethereumClient logic here @@ -72,15 +71,14 @@ export class Execution extends StakerComponent { async persistSelectedExecutionIfInstalled(network: Network): Promise { const currentExecutionDnpName = this.DbHandlers[network].get(); if (currentExecutionDnpName) { - const isInstalled = await listPackageNoThrow({ - dnpName: currentExecutionDnpName - }); + const isInstalled = await this.isPackageInstalled(currentExecutionDnpName); if (!isInstalled) { // update status in db this.DbHandlers[network].set(undefined); return; } + await this.persistSelectedIfInstalled({ dnpName: currentExecutionDnpName, userSettings: this.getUserSettings(network, currentExecutionDnpName) @@ -96,7 +94,7 @@ export class Execution extends StakerComponent { newStakerDnpName: newExecutionDnpName, dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network], compatibleClients: Execution.CompatibleExecutions[network], - userSettings: newExecutionDnpName ? this.getUserSettings(network, newExecutionDnpName) : {}, + userSettings: this.getUserSettings(network, newExecutionDnpName), prevClient: prevExecClientDnpName }); @@ -112,17 +110,12 @@ export class Execution extends StakerComponent { } } - private getUserSettings(network: Network, dnpName: string): UserSettings { + private getUserSettings(network: Network, dnpName: string | null): UserSettings { + if (!dnpName) return {}; + return { networks: { - rootNetworks: { - [params.DOCKER_STAKER_NETWORKS[network]]: { - external: true - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - external: true - } - }, + rootNetworks: this.getComposeRootNetworks(network), serviceNetworks: { [this.getExecutionServiceName(dnpName)]: { [params.DOCKER_STAKER_NETWORKS[network]]: { diff --git a/packages/stakers/src/mevBoost.ts b/packages/stakers/src/mevBoost.ts index ae3a651c8..853542d86 100644 --- a/packages/stakers/src/mevBoost.ts +++ b/packages/stakers/src/mevBoost.ts @@ -70,7 +70,7 @@ export class MevBoost extends StakerComponent { } await this.persistSelectedIfInstalled({ dnpName: currentMevBoostDnpName, - userSettings: this.getUserSettings([], false, network) + userSettings: this.getUserSettings(network, null) }); this.DbHandlers[network].set(true); } @@ -82,7 +82,7 @@ export class MevBoost extends StakerComponent { newStakerDnpName: newMevBoostDnpName, dockerNetworkName: params.DOCKER_STAKER_NETWORKS[network], compatibleClients: compatibleMevBoost ? [compatibleMevBoost] : null, - userSettings: newMevBoostDnpName ? this.getUserSettings(newRelays, true, network) : {}, + userSettings: newMevBoostDnpName ? this.getUserSettings(network, newRelays) : {}, prevClient: compatibleMevBoost ? compatibleMevBoost.dnpName : null }); // persist on db @@ -90,11 +90,14 @@ export class MevBoost extends StakerComponent { await this.DbHandlers[network].set(newMevBoostDnpName ? true : false); } - private getUserSettings(newRelays: string[], shouldSetEnvironment: boolean, network: Network): UserSettings { - return { - environment: shouldSetEnvironment + private getUserSettings(network: Network, newRelays: string[] | null): UserSettings { + const mevBoostServiceName = "mev-boost"; + + const userSettings: UserSettings = { + // If the package is not installed, we use the default environment + environment: newRelays ? { - "mev-boost": { + [mevBoostServiceName]: { ["RELAYS"]: newRelays .join(",") @@ -103,23 +106,24 @@ export class MevBoost extends StakerComponent { } } : {}, - networks: { - rootNetworks: { + networks: this.getStakerNetworkSettings(network) + }; + + return userSettings; + } + + private getStakerNetworkSettings(network: Network): UserSettings["networks"] { + const mevBoostServiceName = "mev-boost"; + + return { + rootNetworks: this.getComposeRootNetworks(network), + serviceNetworks: { + [mevBoostServiceName]: { [params.DOCKER_STAKER_NETWORKS[network]]: { - external: true + aliases: [`${mevBoostServiceName}.${network}.staker.dappnode`] }, [params.DOCKER_PRIVATE_NETWORK_NAME]: { - external: true - } - }, - serviceNetworks: { - ["mev-boost"]: { - [params.DOCKER_STAKER_NETWORKS[network]]: { - aliases: [`mev-boost.${network}.staker.dappnode`] - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - aliases: [`mev-boost.${network}.dncore.dappnode`] - } + aliases: [`${mevBoostServiceName}.${network}.dncore.dappnode`] } } } diff --git a/packages/stakers/src/signer.ts b/packages/stakers/src/signer.ts index e18e0c373..ff78d11a0 100644 --- a/packages/stakers/src/signer.ts +++ b/packages/stakers/src/signer.ts @@ -77,14 +77,7 @@ export class Signer extends StakerComponent { private getUserSettings(network: Network): UserSettings { return { networks: { - rootNetworks: { - [params.DOCKER_STAKER_NETWORKS[network]]: { - external: true - }, - [params.DOCKER_PRIVATE_NETWORK_NAME]: { - external: true - } - }, + rootNetworks: this.getComposeRootNetworks(network), serviceNetworks: { web3signer: { [params.DOCKER_STAKER_NETWORKS[network]]: { diff --git a/packages/stakers/src/stakerComponent.ts b/packages/stakers/src/stakerComponent.ts index e2d897036..045b48687 100644 --- a/packages/stakers/src/stakerComponent.ts +++ b/packages/stakers/src/stakerComponent.ts @@ -1,24 +1,12 @@ -import { - dockerComposeUpPackage, - dockerContainerStop, - dockerNetworkDisconnect, - listPackageNoThrow, - listPackages -} from "@dappnode/dockerapi"; +import { dockerComposeUpPackage, listPackageNoThrow, listPackages } from "@dappnode/dockerapi"; import { ComposeFileEditor } from "@dappnode/dockercompose"; import { DappnodeInstaller, packageGetData, packageInstall } from "@dappnode/installer"; import { logs } from "@dappnode/logger"; -import { - InstalledPackageDataApiReturn, - InstalledPackageData, - UserSettingsAllDnps, - PackageContainer, - StakerItem, - UserSettings -} from "@dappnode/types"; +import { InstalledPackageData, UserSettingsAllDnps, StakerItem, UserSettings, Network } from "@dappnode/types"; import { getIsInstalled, getIsUpdated, getIsRunning, fileToGatewayUrl } from "@dappnode/utils"; import { lt } from "semver"; import { isMatch } from "lodash-es"; +import { params } from "@dappnode/params"; export class StakerComponent { protected dappnodeInstaller: DappnodeInstaller; @@ -118,6 +106,23 @@ export class StakerComponent { }); } + protected async isPackageInstalled(dnpName: string): Promise { + const dnp = await listPackageNoThrow({ dnpName }); + + return Boolean(dnp); + } + + protected getComposeRootNetworks(network: Network): NonNullable["rootNetworks"] { + return { + [params.DOCKER_STAKER_NETWORKS[network]]: { + external: true + }, + [params.DOCKER_PRIVATE_NETWORK_NAME]: { + external: true + } + }; + } + /** * Set the staker pkg: * - ensures the staker pkg is installed @@ -151,7 +156,7 @@ export class StakerComponent { } // start all containers - await dockerComposeUpPackage({ dnpName }, true); + await dockerComposeUpPackage({ dnpName }, true, undefined, { forceRecreate: true }); } /** @@ -161,20 +166,11 @@ export class StakerComponent { * - removes the staker network from the docker-compose file */ private async unsetStakerPkgConfig(pkg: InstalledPackageData, dockerNetworkName: string): Promise { - // disconnect pkg from staker network - await this.disconnectPkgFromStakerNetwork(dockerNetworkName, pkg.containers); - - // stop all containers - await this.stopAllPkgContainers(pkg); - // remove staker network from the compose file this.removeStakerNetworkFromCompose(pkg.dnpName, dockerNetworkName); - } - private async disconnectPkgFromStakerNetwork(networkName: string, pkgContainers: PackageContainer[]): Promise { - const connectedContainers = pkgContainers - .filter((container) => container.networks.some((network) => network.name === networkName)) - .map((container) => container.containerName); - for (const container of connectedContainers) await dockerNetworkDisconnect(networkName, container); + // This recreates the package containers so that they include the recently added configuration + // The flag --no-start is added so that the containers remain stopped after recreation + await dockerComposeUpPackage({ dnpName: pkg.dnpName }, false, undefined, { forceRecreate: true, noStart: true }); } private removeStakerNetworkFromCompose(dnpName: string, dockerNetworkName: string): void { @@ -221,16 +217,4 @@ export class StakerComponent { ); } } - - /** - * Stop all the containers from a given package dnpName - */ - // TODO: Move this to where packages and containers are started/stopped - private async stopAllPkgContainers(pkg: InstalledPackageDataApiReturn | InstalledPackageData): Promise { - await Promise.all( - pkg.containers - .filter((c) => c.running) - .map(async (c) => dockerContainerStop(c.containerName, { timeout: c.dockerTimeout })) - ).catch((e) => logs.error(e.message)); - } } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 989320ea7..b2625f759 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -27,7 +27,7 @@ export * from "./asyncFlows.js"; export * from "./pid.js"; export { urlJoin } from "./urlJoin.js"; export { prettyDnpName } from "./prettyDnpName.js"; -export { getBeaconServiceName, getConsensusUserSettings } from "./stakerUtils.js"; +export { getDefaultConsensusUserSettings } from "./stakerUtils.js"; export * from "./ethers.js"; export { shellSafe } from "./shellSafe.js"; export { getIsInstalled } from "./getIsInstalled.js"; diff --git a/packages/utils/src/stakerUtils.ts b/packages/utils/src/stakerUtils.ts index f346f8c05..866aa4bc9 100644 --- a/packages/utils/src/stakerUtils.ts +++ b/packages/utils/src/stakerUtils.ts @@ -1,70 +1,43 @@ -import { UserSettingsAllDnps, Network } from "@dappnode/types"; +import { UserSettings, Network } from "@dappnode/types"; -// TODO: remove these utils - -/** - * Get the validator service name. - * - Nimbus package is monoservice (beacon-validator) - * - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator) - */ -function getValidatorServiceName(dnpName: string): string { - return dnpName.includes("nimbus") ? "beacon-validator" : "validator"; -} - -/** - * Get the beacon service name - * - Nimbus package is monoservice (beacon-validator) - * - Prysm, Teku, Lighthouse, and Lodestar are multiservice (beacon, validator) - */ -export function getBeaconServiceName(dnpName: string): string { - return dnpName.includes("nimbus") ? "beacon-validator" : "beacon-chain"; -} +// TODO: The code in this file should be included in the stakers module /** * Get the user settings for the consensus client. * It may be different depending if it is multiservice or monoservice and all the envs are * set in the same service */ -export function getConsensusUserSettings({ - dnpName, - network -}: { - dnpName: string; - network: Network; -}): UserSettingsAllDnps { - const validatorServiceName = getValidatorServiceName(dnpName); - const beaconServiceName = getBeaconServiceName(dnpName); +export function getDefaultConsensusUserSettings({ network }: { network: Network }): UserSettings { + const validatorServiceName = "validator"; + const beaconServiceName = "beacon-chain"; + const beaconValidatorServiceName = "beacon-validator"; const defaultDappnodeGraffiti = "validating_from_DAppNode"; const defaultFeeRecipient = "0x0000000000000000000000000000000000000000"; return { - [dnpName]: { - environment: - beaconServiceName === validatorServiceName - ? { - [validatorServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, // TODO: consider setting the MEV fee recipient as the default - // Graffiti is a mandatory value - ["GRAFFITI"]: defaultDappnodeGraffiti, - // Checkpoint sync is an optional value - ["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network) - } - } - : { - [validatorServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, - // Graffiti is a mandatory value - ["GRAFFITI"]: defaultDappnodeGraffiti - }, + environment: { + // TODO: Remove once Nimbus is split into 2 services + [beaconValidatorServiceName]: { + // Fee recipient is set as global env, keep this for backwards compatibility + ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, // TODO: consider setting the MEV fee recipient as the default + // Graffiti is a mandatory value + ["GRAFFITI"]: defaultDappnodeGraffiti, + // Checkpoint sync is an optional value + ["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network) + }, + + [validatorServiceName]: { + // Fee recipient is set as global env, keep this for backwards compatibility + ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, + // Graffiti is a mandatory value + ["GRAFFITI"]: defaultDappnodeGraffiti + }, - [beaconServiceName]: { - // Fee recipient is set as global env, keep this for backwards compatibility - ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, - // Checkpoint sync is an optional value - ["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network) - } - } + [beaconServiceName]: { + // Fee recipient is set as global env, keep this for backwards compatibility + ["FEE_RECIPIENT_ADDRESS"]: defaultFeeRecipient, + // Checkpoint sync is an optional value + ["CHECKPOINT_SYNC_URL"]: getDefaultCheckpointSync(network) + } } }; }