11import fs from "fs" ;
2+ import * as db from "../../db" ;
23import { changeEthMultiClient } from "./changeEthMultiClient" ;
34import { listContainerNoThrow } from "../../modules/docker/listContainers" ;
45import { dockerVolumesList , dockerDf } from "../../modules/docker/dockerApi" ;
@@ -8,6 +9,7 @@ import { getUserSettingsSafe } from "../../utils/dockerComposeFile";
89import * as getPath from "../../utils/getPath" ;
910import shell from "../../utils/shell" ;
1011import Logs from "../../logs" ;
12+ import { EthClientTargetPackage } from "../../types" ;
1113const logs = Logs ( module ) ;
1214
1315const ethchainDnpName = "ethchain.dnp.dappnode.eth" ;
@@ -46,6 +48,14 @@ export async function migrateEthchain(): Promise<void> {
4648 ...( userSettings . environment || { } )
4749 } ;
4850 const isNextOpenEthereum = / p a r i t y / 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