@@ -16,9 +16,6 @@ import {
1616 getLocalFallbackContentHash
1717} from "../../modules/ethClient" ;
1818
19- // Enforces that the default value of status is correct
20- type InstallStatus = EthClientInstallStatus [ "status" ] ;
21-
2219/**
2320 * Check status of the Ethereum client and do next actions
2421 * This function should be run:
@@ -32,7 +29,8 @@ type InstallStatus = EthClientInstallStatus["status"];
3229 * It also retries each step automatically without added logic
3330 */
3431export async function runEthClientInstaller (
35- target : EthClientTarget
32+ target : EthClientTarget ,
33+ status : EthClientInstallStatus | undefined
3634) : Promise < EthClientInstallStatus | null > {
3735 // Re-check just in case, on run the installer for local target clients
3836 if ( target === "remote" ) return null ;
@@ -42,18 +40,13 @@ export async function runEthClientInstaller(
4240 const { dnpName, version, userSettings } = clientData ;
4341 const dnp = await listPackageNoThrow ( { dnpName } ) ;
4442
45- const installStatus = db . ethClientInstallStatus . get ( target ) ;
46- const status : InstallStatus = installStatus
47- ? installStatus . status
48- : "TO_INSTALL" ;
49-
5043 if ( dnp ) {
5144 // OK: Client is already installed
5245 return { status : "INSTALLED" } ;
5346 } else {
5447 // Client is not installed
5548
56- switch ( status ) {
49+ switch ( status ?. status || "TO_INSTALL" ) {
5750 case "INSTALLING" :
5851 // NOTE: This status has to be verified on DAPPMANAGER startup. Otherwise it can
5952 // stay in installing state forever if the dappmanager resets during the installation
@@ -95,11 +88,6 @@ export async function runEthClientInstaller(
9588 }
9689 }
9790
98- // Map fullnode.dappnode to package
99- db . fullnodeDomainTarget . set ( dnpName ) ;
100- // Run nsupdate
101- eventBus . packagesModified . emit ( { dnpNames : [ dnpName ] } ) ;
102-
10391 return { status : "INSTALLED" } ;
10492 } catch ( e ) {
10593 return { status : "INSTALLING_ERROR" , error : serializeError ( e ) } ;
@@ -147,14 +135,22 @@ export default function runWatcher(): void {
147135 runOnlyOneSequentially ( async ( ) => {
148136 try {
149137 const target = db . ethClientTarget . get ( ) ;
150- if ( target && target !== "remote" ) {
151- const prevStatus = db . ethClientInstallStatus . get ( target ) ;
152- const nextStatus = await runEthClientInstaller ( target ) ;
153- if ( nextStatus ) {
154- db . ethClientInstallStatus . set ( target , nextStatus ) ;
155- if ( ! prevStatus || prevStatus . status !== nextStatus . status )
156- // Next run MUST be defered to next event loop for prevStatus to refresh
157- setTimeout ( eventBus . runEthClientInstaller . emit , 1000 ) ;
138+ if ( ! target || target === "remote" ) return ; // Nothing to install
139+
140+ const prev = db . ethClientInstallStatus . get ( target ) ;
141+ const next = await runEthClientInstaller ( target , prev ) ;
142+ if ( ! next ) return ; // Package is uninstalled
143+
144+ db . ethClientInstallStatus . set ( target , next ) ;
145+
146+ if ( ! prev || prev . status !== next . status ) {
147+ // Next run MUST be defered to next event loop for prevStatus to refresh
148+ setTimeout ( eventBus . runEthClientInstaller . emit , 1000 ) ;
149+
150+ if ( next . status === "INSTALLED" ) {
151+ // If status switched to "INSTALLED", map to fullnode.dappnode
152+ // Must be done here in case the package is already installed
153+ db . fullnodeDomainTarget . set ( ethClientData [ target ] . dnpName ) ;
158154 }
159155 }
160156 } catch ( e ) {
0 commit comments