diff --git a/app/cli.ts b/app/cli.ts index 6a6d3924b91387ab71fc3c49700c429352d3277c..aaae51f89a95d8cb61782247f995d21a547759af 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 b6ff36a94ed90531156ecdc7b6beb4023491c7fd..e6e750ca0fdcabd773dabad7ae7bf2998c903a2c 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 856e1423761bde02af8b9da064ffb307c0b65d18..98e01179391d457ad88027ad3834ce030a2566dd 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 1b6d051c2f284f3040a95bf6606548837c2d022a..03676a8f4daa5f6bc7a8cb0f8716615a68544adf 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 0a454d38fd9c85e58115c2f971bbb6cb1cea812e..2b8299c335620178aa08a47f85452b6e53eef058 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 daf1b333be0293972a011a2c4e59ff9eaf949bd2..4a8679e7d834a09af44290d7710b544b744b3634 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;