diff --git a/packages/stakers/src/consensus.ts b/packages/stakers/src/consensus.ts index 8f0bf28bd..d4967041d 100644 --- a/packages/stakers/src/consensus.ts +++ b/packages/stakers/src/consensus.ts @@ -88,10 +88,8 @@ export class Consensus extends StakerComponent { const userSettings = await this.getUserSettings(network, currentConsensusDnpName); - await this.persistSelectedIfInstalled({ - dnpName: currentConsensusDnpName, - userSettings - }); + await this.setStakerPkgConfig({ dnpName: currentConsensusDnpName, isInstalled, userSettings }); + await this.DbHandlers[network].set(currentConsensusDnpName); } } diff --git a/packages/stakers/src/execution.ts b/packages/stakers/src/execution.ts index 6bba262b2..7aed8d533 100644 --- a/packages/stakers/src/execution.ts +++ b/packages/stakers/src/execution.ts @@ -79,10 +79,10 @@ export class Execution extends StakerComponent { return; } - await this.persistSelectedIfInstalled({ - dnpName: currentExecutionDnpName, - userSettings: this.getUserSettings(network, currentExecutionDnpName) - }); + const userSettings = this.getUserSettings(network, currentExecutionDnpName); + + await this.setStakerPkgConfig({ dnpName: currentExecutionDnpName, isInstalled, userSettings }); + await this.DbHandlers[network].set(currentExecutionDnpName); } } diff --git a/packages/stakers/src/mevBoost.ts b/packages/stakers/src/mevBoost.ts index 853542d86..9d57c65c1 100644 --- a/packages/stakers/src/mevBoost.ts +++ b/packages/stakers/src/mevBoost.ts @@ -56,22 +56,25 @@ export class MevBoost extends StakerComponent { } async persistMevBoostIfInstalledAndRunning(network: Network): Promise { - const currentMevBoostDnpName = MevBoost.CompatibleMevBoost[network]?.dnpName; - if (currentMevBoostDnpName) { - const isInstalledAndRunning = ( - await listPackageNoThrow({ - dnpName: currentMevBoostDnpName - }) - )?.containers.some((container) => container.running); - - if (!isInstalledAndRunning) { + const mevBoostDnpName = MevBoost.CompatibleMevBoost[network]?.dnpName; + + if (mevBoostDnpName) { + const mevBoostDnp = await listPackageNoThrow({ dnpName: mevBoostDnpName }); + const isRunning = mevBoostDnp?.containers.some((container) => container.running); + + if (!isRunning) { this.DbHandlers[network].set(false); return; } - await this.persistSelectedIfInstalled({ - dnpName: currentMevBoostDnpName, - userSettings: this.getUserSettings(network, null) + + const userSettings = this.getUserSettings(network, null); + + await this.setStakerPkgConfig({ + dnpName: mevBoostDnpName, + isInstalled: true, + userSettings }); + this.DbHandlers[network].set(true); } } diff --git a/packages/stakers/src/signer.ts b/packages/stakers/src/signer.ts index ff78d11a0..3ea1cc453 100644 --- a/packages/stakers/src/signer.ts +++ b/packages/stakers/src/signer.ts @@ -51,17 +51,16 @@ export class Signer extends StakerComponent { } async persistSignerIfInstalledAndRunning(network: Network): Promise { - if ( - ( - await listPackageNoThrow({ - dnpName: Signer.CompatibleSigners[network].dnpName - }) - )?.containers.some((container) => container.running) - ) - await this.persistSelectedIfInstalled({ - dnpName: Signer.CompatibleSigners[network].dnpName, - userSettings: this.getUserSettings(network) - }); + const signerDnpName = Signer.CompatibleSigners[network].dnpName; + const signerDnp = await listPackageNoThrow({ dnpName: signerDnpName }); + const isRunning = signerDnp?.containers.some((container) => container.running); + + if (isRunning) { + const dnpName = Signer.CompatibleSigners[network].dnpName; + const userSettings = this.getUserSettings(network); + + await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings }); + } } async setNewSigner(network: Network, newWeb3signerDnpName: string | null) { diff --git a/packages/stakers/src/stakerComponent.ts b/packages/stakers/src/stakerComponent.ts index 48cd8bcd5..461d9271b 100644 --- a/packages/stakers/src/stakerComponent.ts +++ b/packages/stakers/src/stakerComponent.ts @@ -2,7 +2,7 @@ import { dockerComposeUpPackage, listPackageNoThrow, listPackages } from "@dappn import { ComposeFileEditor } from "@dappnode/dockercompose"; import { DappnodeInstaller, packageGetData, packageInstall } from "@dappnode/installer"; import { logs } from "@dappnode/logger"; -import { InstalledPackageData, UserSettingsAllDnps, StakerItem, UserSettings, Network } from "@dappnode/types"; +import { InstalledPackageData, StakerItem, UserSettings, Network } from "@dappnode/types"; import { getIsInstalled, getIsUpdated, getIsRunning, fileToGatewayUrl } from "@dappnode/utils"; import { lt } from "semver"; import { isMatch } from "lodash-es"; @@ -53,17 +53,6 @@ export class StakerComponent { ); } - protected async persistSelectedIfInstalled({ - dnpName, - userSettings - }: { - dnpName: string; - userSettings: UserSettings; - }): Promise { - logs.info(`Persisting ${dnpName}`); - await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings }); - } - protected async setNew({ newStakerDnpName, dockerNetworkName, @@ -130,7 +119,7 @@ export class StakerComponent { * - adds the staker network to the docker-compose file * - starts the staker pkg */ - private async setStakerPkgConfig({ + protected async setStakerPkgConfig({ dnpName, isInstalled, userSettings @@ -161,14 +150,15 @@ export class StakerComponent { if (userSettings) { const composeEditor = new ComposeFileEditor(dnpName, false); - const previousSettings: UserSettingsAllDnps = { - [dnpName]: composeEditor.getUserSettings() - }; + const previousSettings = composeEditor.getUserSettings(); + + composeEditor.applyUserSettings(userSettings, { dnpName }); + const newSettings = composeEditor.getUserSettings(); - if (!isMatch(previousSettings, userSettings)) { - composeEditor.applyUserSettings(userSettings, { dnpName }); + if (!isMatch(previousSettings, newSettings)) { composeEditor.write(); - forceRecreate = true; // Only recreate if userSettings changed + forceRecreate = true; + logs.info(`Settings for ${dnpName} have changed. Forcing recreation of containers.`); } }