Skip to content

Commit

Permalink
Merge pull request #1167 from dappnode/pablo/fix-stakers-ui-no-cc-sel…
Browse files Browse the repository at this point in the history
…ected

Stop previous clients in stakers UI if no options provided
  • Loading branch information
pablomendezroyo authored Oct 26, 2022
2 parents 58c7034 + 93a505b commit 99109b2
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions packages/dappmanager/src/modules/stakerConfig/setStakerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,25 @@ export async function setStakerConfig({
);

// EXECUTION CLIENT
if (stakerConfig.executionClient !== undefined)
await setExecutionClientConfig({
currentExecClient,
targetExecutionClient: stakerConfig.executionClient,
currentExecClientPkg
});
await setExecutionClientConfig({
currentExecClient,
targetExecutionClient: stakerConfig.executionClient,
currentExecClientPkg
});

// CONSENSUS CLIENT (+ Fee recipient address + Graffiti + Checkpointsync)
if (stakerConfig.consensusClient !== undefined)
await setConsensusClientConfig({
currentConsClient,
targetConsensusClient: stakerConfig.consensusClient,
currentConsClientPkg
}).catch(e => {
// The previous EXECUTION CLIENT must be persisted
setStakerConfigOnDb({
...stakerConfig,
executionClient: currentExecClient
});
throw e;
await setConsensusClientConfig({
currentConsClient,
targetConsensusClient: stakerConfig.consensusClient,
currentConsClientPkg
}).catch(e => {
// The previous EXECUTION CLIENT must be persisted
setStakerConfigOnDb({
...stakerConfig,
executionClient: currentExecClient
});
throw e;
});

// WEB3SIGNER
if (stakerConfig.enableWeb3signer !== undefined)
Expand Down Expand Up @@ -182,9 +180,9 @@ async function setExecutionClientConfig({
targetExecutionClient,
currentExecClientPkg
}: {
currentExecClient: string | undefined;
targetExecutionClient: string;
currentExecClientPkg: InstalledPackageDataApiReturn | undefined;
currentExecClient?: string;
targetExecutionClient?: string;
currentExecClientPkg?: InstalledPackageDataApiReturn;
}): Promise<void> {
if (!targetExecutionClient && !currentExecClient) {
// Stop the current execution client if no option and not currentu execution client
Expand All @@ -210,7 +208,10 @@ async function setExecutionClientConfig({
true
).catch(err => logs.error(err));
}
} else if (targetExecutionClient === currentExecClient) {
} else if (
targetExecutionClient &&
targetExecutionClient === currentExecClient
) {
if (!currentExecClientPkg) {
logs.info("Installing execution client " + targetExecutionClient);
await packageInstall({ name: targetExecutionClient });
Expand All @@ -222,7 +223,10 @@ async function setExecutionClientConfig({
true
).catch(err => logs.error(err));
}
} else if (targetExecutionClient !== currentExecClient) {
} else if (
targetExecutionClient &&
targetExecutionClient !== currentExecClient
) {
const targetExecClientPkg = await listPackageNoThrow({
dnpName: targetExecutionClient
});
Expand Down Expand Up @@ -252,17 +256,17 @@ async function setConsensusClientConfig({
targetConsensusClient,
currentConsClientPkg
}: {
currentConsClient: string | undefined;
targetConsensusClient: ConsensusClient;
currentConsClientPkg: InstalledPackageDataApiReturn | undefined;
currentConsClient?: string;
targetConsensusClient?: ConsensusClient;
currentConsClientPkg?: InstalledPackageDataApiReturn;
}): Promise<void> {
if (!targetConsensusClient.dnpName) {
if (!targetConsensusClient?.dnpName) {
if (!currentConsClient) {
// Stop the current consensus client if no option and not current consensus client
logs.info(`Not consensus client selected`);
if (currentConsClientPkg)
await stopAllPkgContainers(currentConsClientPkg);
} else if (!targetConsensusClient.dnpName && currentConsClient) {
} else if (!targetConsensusClient?.dnpName && currentConsClient) {
// Stop the current consensus client if no target provided
logs.info(`Not consensus client selected`);
if (currentConsClientPkg)
Expand Down

0 comments on commit 99109b2

Please sign in to comment.