From 456010983dff30ce10b7288473f8f5610054d48f Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Fri, 29 Sep 2017 00:58:20 +0200
Subject: [PATCH] [fix] #1126 add config prefix nodeId

---
 app/cli.ts                          | 1 +
 app/modules/prover/index.ts         | 5 ++++-
 app/modules/prover/lib/constants.ts | 1 +
 app/modules/prover/lib/prover.ts    | 4 ++--
 app/service/PeeringService.ts       | 4 ++--
 index.ts                            | 2 ++
 6 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/app/cli.ts b/app/cli.ts
index a59414cf7..cedf3a7fa 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('--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 094888333..b0b9cec8b 100644
--- a/app/modules/prover/index.ts
+++ b/app/modules/prover/index.ts
@@ -14,13 +14,16 @@ const async = require('async');
 export const ProverDependency = {
 
   duniter: {
-
+    
     /*********** Permanent prover **************/
     config: {
       onLoading: async (conf:ConfDTO) => {
         if (conf.cpu === null || conf.cpu === undefined) {
           conf.cpu = Constants.DEFAULT_CPU;
         }
+        if (conf.prefix === null || conf.prefix === undefined) {
+          conf.prefix = Constants.DEFAULT_PEER_ID;
+        }
         conf.powSecurityRetryDelay = Constants.POW_SECURITY_RETRY_DELAY;
         conf.powMaxHandicap = Constants.POW_MAXIMUM_ACCEPTABLE_HANDICAP;
       },
diff --git a/app/modules/prover/lib/constants.ts b/app/modules/prover/lib/constants.ts
index 9db6278dd..0b10fbf48 100644
--- a/app/modules/prover/lib/constants.ts
+++ b/app/modules/prover/lib/constants.ts
@@ -6,6 +6,7 @@ export const Constants = {
 
   POW_MINIMAL_TO_SHOW: 2,
   DEFAULT_CPU: 0.6,
+  DEFAULT_PEER_ID: 1,
 
   NONCE_RANGE: 1000 * 1000 * 1000 * 100,
 
diff --git a/app/modules/prover/lib/prover.ts b/app/modules/prover/lib/prover.ts
index d14b21c68..182f5e3fe 100644
--- a/app/modules/prover/lib/prover.ts
+++ b/app/modules/prover/lib/prover.ts
@@ -17,9 +17,9 @@ export class Prover extends stream.Transform {
     if (obj) {
       if (obj.bcEvent && obj.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || obj.bcEvent === OtherConstants.BC_EVENT.SWITCHED) {
         this.permaProver.blockchainChanged(obj.block);
-      } else if (obj.nodeIndexInPeers !== undefined) {
+      } /*else if (obj.nodeIndexInPeers !== undefined) {
         this.permaProver.prover.changePoWPrefix((obj.nodeIndexInPeers + 1) * 10); // We multiply by 10 to give room to computers with < 100 cores
-      } else if (obj.cpu !== undefined) {
+      }*/ else if (obj.cpu !== undefined) {
         this.permaProver.prover.changeCPU(obj.cpu); // We multiply by 10 to give room to computers with < 100 cores
       }
     }
diff --git a/app/service/PeeringService.ts b/app/service/PeeringService.ts
index a19181209..c056fe89f 100644
--- a/app/service/PeeringService.ts
+++ b/app/service/PeeringService.ts
@@ -161,7 +161,7 @@ export class PeeringService {
           const localEndpoints = await this.server.getEndpoints()
           const localNodeNotListed = !peerEntityOld.containsAllEndpoints(localEndpoints)
           const current = localNodeNotListed && (await this.dal.getCurrentBlockOrNull());
-          if (!localNodeNotListed) {
+          /*if (!localNodeNotListed) {
             const indexOfThisNode = PeerDTO.indexOfFirst(localEndpoints, peerEntity.endpoints)
             if (indexOfThisNode !== -1) {
               this.server.push({
@@ -170,7 +170,7 @@ export class PeeringService {
             } else {
               logger.warn('This node has his interface listed in the peer document, but its index cannot be found.');
             }
-          }
+          }*/
           if (localNodeNotListed && (!current || current.number > blockNumber)) {
             // Document with pubkey of local peer, but doesn't contain local interface: we must add it
             this.generateSelfPeer(this.conf);
diff --git a/index.ts b/index.ts
index ce96dcd7a..08eaccdc9 100644
--- a/index.ts
+++ b/index.ts
@@ -443,6 +443,7 @@ function commandLineConf(program:any, conf:any = {}) {
   const cli = {
     currency: program.currency,
     cpu: program.cpu,
+    prefix: program.prefix,
     server: {
       port: program.port,
     },
@@ -467,6 +468,7 @@ function commandLineConf(program:any, conf:any = {}) {
   if (cli.currency)                         conf.currency = cli.currency;
   if (cli.server.port)                      conf.port = cli.server.port;
   if (cli.cpu)                              conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu));
+  if (cli.prefix)                           conf.prefix = Math.max(1, Math.min(9, cli.prefix));
   if (cli.logs.http)                        conf.httplogs = true;
   if (cli.logs.nohttp)                      conf.httplogs = false;
   if (cli.db.mport)                         conf.mport = cli.db.mport;
-- 
GitLab