From 97d0de7336c5f4718c1bec90c089d6226354d258 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sun, 3 Dec 2017 00:54:59 +0100 Subject: [PATCH] [fix] cli option ecoMode : treat cleanly default and undefined value --- app/cli.ts | 1 + app/lib/dto/ConfDTO.ts | 2 +- app/modules/prover/index.ts | 3 +++ app/modules/prover/lib/blockProver.ts | 2 +- app/modules/prover/lib/constants.ts | 1 + index.ts | 4 +++- 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/cli.ts b/app/cli.ts index 6a6d3924b..aaae51f89 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -41,6 +41,7 @@ export const ExecuteCommand = () => { .option('--addep <endpoint>', 'With `config` command, add given endpoint to the list of endpoints of this node') .option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node') + .option('--eco-mode', 'reduce CPU usage for proof-of-work computation') .option('--no-eco-mode', 'Do not reduce CPU usage for proof-of-work computation') .option('--cpu <percent>', 'Percent of CPU usage for proof-of-work computation', parsePercent) .option('--nb-cores <number>', 'Number of cores uses for proof-of-work computation', parseInt) diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index b6ff36a94..e6e750ca0 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -91,7 +91,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, public rmEndpoints: string[], public rootoffset: number, public upInterval: number, - public ecoMode: boolean|true, + public ecoMode: boolean|undefined, public cpu: number, public nbCores: number, public prefix: number, diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 856e14237..98e011793 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -18,6 +18,9 @@ export const ProverDependency = { /*********** Permanent prover **************/ config: { onLoading: async (conf:ConfDTO) => { + if (conf.ecoMode === null || conf.ecoMode === undefined) { + conf.ecoMode = ProverConstants.DEFAULT_ECO_MODE; + } if (conf.cpu === null || conf.cpu === undefined) { conf.cpu = ProverConstants.DEFAULT_CPU; } diff --git a/app/modules/prover/lib/blockProver.ts b/app/modules/prover/lib/blockProver.ts index 1b6d051c2..03676a8f4 100644 --- a/app/modules/prover/lib/blockProver.ts +++ b/app/modules/prover/lib/blockProver.ts @@ -201,7 +201,7 @@ export class BlockProver { this.logger.info('Done: #%s, %s in %ss instead of %ss (%s tests, ~%s tests/s)', block.number, proof.hash, (duration / 1000).toFixed(2), this.conf.avgGenTime, testsCount, testsPerSecond.toFixed(2)); this.logger.info('FOUND proof-of-work with %s leading zeros followed by [0-' + highMark + ']!', nbZeros); - if(this.conf.ecoMode && this.conf.nbCores*testsPerSecond > 300) { + if(this.conf.ecoMode === true && this.conf.nbCores*testsPerSecond > 300) { if(this.conf.nbCores > 1) { this.logger.info("Reducing number of CPU cores "+this.conf.nbCores) this.conf.nbCores = this.conf.nbCores -1 diff --git a/app/modules/prover/lib/constants.ts b/app/modules/prover/lib/constants.ts index 0a454d38f..2b8299c33 100644 --- a/app/modules/prover/lib/constants.ts +++ b/app/modules/prover/lib/constants.ts @@ -5,6 +5,7 @@ export const ProverConstants = { MINIMAL_ZEROS_TO_SHOW_IN_LOGS: 3, POW_MINIMAL_TO_SHOW: 2, + DEFAULT_ECO_MODE: true, DEFAULT_CPU: 0.6, DEFAULT_PEER_ID: 1, MIN_PEER_ID: 1, diff --git a/index.ts b/index.ts index daf1b333b..4a8679e7d 100644 --- a/index.ts +++ b/index.ts @@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) { const cli = { currency: program.currency, ecoMode: program.ecoMode, + noEcoMode: program.noEcoMode, cpu: program.cpu, nbCores: program.nbCores, prefix: program.prefix, @@ -486,7 +487,8 @@ function commandLineConf(program:any, conf:any = {}) { // Update the rest of the conf if (cli.currency) conf.currency = cli.currency; if (cli.server.port) conf.port = cli.server.port; - if (cli.ecoMode) conf.ecoMode = cli.ecoMode + if (cli.ecoMode) conf.ecoMode = true + if (cli.noEcoMode) conf.ecoMode = false if (cli.cpu) conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu)); if (cli.prefix) conf.prefix = Math.max(ProverConstants.MIN_PEER_ID, Math.min(ProverConstants.MAX_PEER_ID, cli.prefix)); if (cli.logs.http) conf.httplogs = true; -- GitLab