From f58c7c7568aad3fec027b38cccc5c5c0d42f81fa Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Mon, 13 Nov 2017 14:03:01 +0100
Subject: [PATCH] [fix] #1198

---
 app/cli.ts                       | 1 +
 app/modules/prover/index.ts      | 3 +++
 app/modules/prover/lib/engine.ts | 2 +-
 index.ts                         | 1 +
 4 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/app/cli.ts b/app/cli.ts
index 26accf24f..3c2e49515 100644
--- a/app/cli.ts
+++ b/app/cli.ts
@@ -42,6 +42,7 @@ export const ExecuteCommand = () => {
         .option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node')
 
         .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)
         .option('--prefix <nodeId>', 'Prefix node id for the first character of nonce', parseInt)
 
         .option('-c, --currency <name>', 'Name of the currency managed by this node.')
diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts
index 7bdd83464..01b4bc719 100644
--- a/app/modules/prover/index.ts
+++ b/app/modules/prover/index.ts
@@ -21,6 +21,9 @@ export const ProverDependency = {
         if (conf.cpu === null || conf.cpu === undefined) {
           conf.cpu = Constants.DEFAULT_CPU;
         }
+        if (conf.nbCores === null || conf.nbCores === undefined) {
+          conf.nbCores = Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length)
+        }
         if (conf.prefix === null || conf.prefix === undefined) {
           conf.prefix = Constants.DEFAULT_PEER_ID;
         }
diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts
index 12d2751d6..116963e47 100644
--- a/app/modules/prover/lib/engine.ts
+++ b/app/modules/prover/lib/engine.ts
@@ -20,7 +20,7 @@ export class PowEngine {
   constructor(private conf:ConfDTO, logger:any) {
 
     // We use as much cores as available, but not more than CORES_MAXIMUM_USE_IN_PARALLEL
-    this.nbWorkers = (conf && conf.nbCores) || Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length)
+    this.nbWorkers = conf.nbCores
     this.cluster = new PowCluster(this.nbWorkers, logger)
     this.id = this.cluster.clusterId
   }
diff --git a/index.ts b/index.ts
index f9e3cf445..1086b3aa0 100644
--- a/index.ts
+++ b/index.ts
@@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) {
   const cli = {
     currency: program.currency,
     cpu: program.cpu,
+    nbCores: program.nbCores,
     prefix: program.prefix,
     server: {
       port: program.port,
-- 
GitLab