From 03eb18baa89eda38f87fab0f9ea11f232a76a70d Mon Sep 17 00:00:00 2001
From: Gilles Filippini <gilles.filippini@pini.fr>
Date: Sun, 27 Jun 2021 22:35:41 +0200
Subject: [PATCH] feat: env vars for cpu and nbCores pow parameters

DUNITER_POW_CPU
DUNITER_POW_NBCORES
---
 doc/use/conf_env_var.md | 8 ++++++++
 index.ts                | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/doc/use/conf_env_var.md b/doc/use/conf_env_var.md
index 8cfe5f1ec..60c556b9e 100644
--- a/doc/use/conf_env_var.md
+++ b/doc/use/conf_env_var.md
@@ -22,6 +22,14 @@ By default this keypair is random, so the duniter node is a mirror node.
 
 To modify the keypair of the node, you must create a keypair in a file and indicate the path to this file with the environment variable `DUNITER_KEYFILE`.
 
+## Configuring the proof of work parameters
+
+The PoW prefix, cpu usage, and number of workers can be configured with these environment variables:
+
+* `DUNITER_POW_PREFIX` (integer)
+* `DUNITER_POW_CPU` (decimal number between 0 and 1)
+* `DUNITER_POW_NBCORES` (integer)
+
 ## Configuring the network
 
 ### The APIs
diff --git a/index.ts b/index.ts
index f7dd1363a..42afaec11 100644
--- a/index.ts
+++ b/index.ts
@@ -485,8 +485,8 @@ function commandLineConf(program:any, conf:any = {}) {
   conf = conf || {};
   const cli = {
     currency: program.currency,
-    cpu: program.cpu,
-    nbCores: program.nbCores,
+    cpu: process.env.DUNITER_POW_CPU ? parseFloat(process.env.DUNITER_POW_CPU) : program.cpu,
+    nbCores: process.env.DUNITER_POW_NBCORES ? parseInt(process.env.DUNITER_POW_NBCORES) : program.nbCores,
     prefix: program.prefix,
     server: {
       port: program.port,
-- 
GitLab