Skip to content

Commit f20facf

Browse files
committed
Persist settings of the ethchain during the eth client migration
1 parent d891574 commit f20facf

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

build/src/src/db/ethClient.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
EthClientTarget,
55
UserSettings,
66
EthClientFallback,
7-
EthClientStatus
7+
EthClientStatus,
8+
EthClientTargetPackage
89
} from "../types";
910
import { joinWithDot, stripDots } from "./dbUtils";
1011
import { EthClientInstallStatus } from "../modules/ethClient/types";
@@ -18,6 +19,8 @@ const ETH_CLIENT_USER_SETTINGS = "eth-client-user-settings";
1819
const ETH_CLIENT_INSTALL_STATUS = "eth-client-install-status";
1920
const ETH_CLIENT_STATUS = "eth-client-status";
2021
const ETH_PROVIDER_URL = "eth-provider-url";
22+
// Cached temp status
23+
const ETH_CLIENT_MIGRATION_TEMP_SETTINGS = "eth-client-migration-temp-status";
2124

2225
// Re-export to consider the first value (when it's not set)
2326
// but do not allow to set null again. Using to express intentionality
@@ -96,3 +99,13 @@ function interceptOnSet<F extends Function, T extends { set: F }>(
9699
}
97100
};
98101
}
102+
103+
/**
104+
* Temporal cache settings that must survive a reset
105+
* Store settings in the cache. It is possible that the migration is stopped
106+
* because the DAPPMANAGER resets and then the eth client will not be installed
107+
*/
108+
export const ethClientMigrationTempSettings = dbCache.staticKey<{
109+
target: EthClientTargetPackage;
110+
EXTRA_OPTS: string;
111+
} | null>(ETH_CLIENT_MIGRATION_TEMP_SETTINGS, null);

build/src/src/modules/ethClient/migrateEthchain.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "fs";
2+
import * as db from "../../db";
23
import { changeEthMultiClient } from "./changeEthMultiClient";
34
import { listContainerNoThrow } from "../../modules/docker/listContainers";
45
import { dockerVolumesList, dockerDf } from "../../modules/docker/dockerApi";
@@ -8,6 +9,7 @@ import { getUserSettingsSafe } from "../../utils/dockerComposeFile";
89
import * as getPath from "../../utils/getPath";
910
import shell from "../../utils/shell";
1011
import Logs from "../../logs";
12+
import { EthClientTargetPackage } from "../../types";
1113
const logs = Logs(module);
1214

1315
const ethchainDnpName = "ethchain.dnp.dappnode.eth";
@@ -46,6 +48,14 @@ export async function migrateEthchain(): Promise<void> {
4648
...(userSettings.environment || {})
4749
};
4850
const isNextOpenEthereum = /parity/i.test(envs.DEFAULT_CLIENT || "");
51+
let target: EthClientTargetPackage = isNextOpenEthereum
52+
? "openethereum"
53+
: "geth";
54+
let EXTRA_OPTS =
55+
(isNextOpenEthereum ? envs.EXTRA_OPTS : envs.EXTRA_OPTS_GETH) || "";
56+
// Store settings in the cache. It is possible that the migration is stopped
57+
// because the DAPPMANAGER resets and then the eth client will not be installed
58+
db.ethClientMigrationTempSettings.set({ target, EXTRA_OPTS });
4959

5060
const volumesToMigrate = [
5161
{
@@ -142,16 +152,23 @@ export async function migrateEthchain(): Promise<void> {
142152
}
143153

144154
// Install new package. fullnode.dappnode is assigned after install
145-
if (ethchain) {
146-
const target = isNextOpenEthereum ? "openethereum" : "geth";
147-
const EXTRA_OPTS = isNextOpenEthereum
148-
? envs.EXTRA_OPTS
149-
: envs.EXTRA_OPTS_GETH;
150-
logs.info(`Installing eth multi-client ${target}: ${JSON.stringify(envs)}`);
155+
const migrationTempSettings = db.ethClientMigrationTempSettings.get();
156+
if (ethchain || migrationTempSettings) {
157+
logs.info(
158+
`Installing eth multi-client ${target}: with EXTRA_OPTS ${EXTRA_OPTS}`
159+
);
160+
161+
if (migrationTempSettings) {
162+
target = migrationTempSettings.target || target;
163+
EXTRA_OPTS = migrationTempSettings.EXTRA_OPTS || EXTRA_OPTS;
164+
}
151165

152166
await changeEthMultiClient(target, false, {
153167
portMappings: userSettings.portMappings,
154168
environment: EXTRA_OPTS ? { EXTRA_OPTS } : undefined
155169
});
170+
171+
// Once the client has been successfully changed, delete temp migration settings
172+
db.ethClientMigrationTempSettings.set(null);
156173
}
157174
}

0 commit comments

Comments
 (0)