From c9541c41548ae5a3b29bf37db7fc1ad444f306c0 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Tue, 19 Sep 2017 12:08:30 +0200
Subject: [PATCH] [fix] #1098 Proof-of-work should be decoupled from BMA pulls

---
 app/modules/prover/lib/constants.ts       |  2 --
 app/modules/prover/lib/permanentProver.ts | 37 -----------------------
 app/modules/prover/lib/prover.ts          |  7 -----
 3 files changed, 46 deletions(-)

diff --git a/app/modules/prover/lib/constants.ts b/app/modules/prover/lib/constants.ts
index a30bd0ed4..9db6278dd 100644
--- a/app/modules/prover/lib/constants.ts
+++ b/app/modules/prover/lib/constants.ts
@@ -1,7 +1,5 @@
 export const Constants = {
 
-  PULLING_MAX_DURATION: 10 * 1000, // 10 seconds
-
   CORES_MAXIMUM_USE_IN_PARALLEL: 8,
 
   MINIMAL_ZEROS_TO_SHOW_IN_LOGS: 3,
diff --git a/app/modules/prover/lib/permanentProver.ts b/app/modules/prover/lib/permanentProver.ts
index f0c974bbf..29dea08b8 100644
--- a/app/modules/prover/lib/permanentProver.ts
+++ b/app/modules/prover/lib/permanentProver.ts
@@ -1,7 +1,6 @@
 import {BlockGeneratorWhichProves} from "./blockGenerator"
 import {ConfDTO} from "../../../lib/dto/ConfDTO"
 import {BlockProver} from "./blockProver"
-import {Constants} from "./constants"
 import {DBBlock} from "../../../lib/db/DBBlock"
 import {dos2unix} from "../../../lib/common-libs/dos2unix"
 import {parsers} from "../../../lib/common-libs/parsers/index"
@@ -29,10 +28,6 @@ export class PermanentProver {
   private lastComputedBlock:any = null
   private resolveContinuePromise:any = null
   private continuePromise:any = null
-  private pullingResolveCallback:any = null
-  private timeoutPullingCallback:any = null
-  private pullingFinishedPromise:Querable<any>|null = null
-  private timeoutPulling:any = null
 
   constructor(private server:any) {
     this.logger = server.logger;
@@ -43,9 +38,6 @@ export class PermanentProver {
     // Promises triggering the prooving lopp
     this.resolveContinuePromise = null;
     this.continuePromise = new Promise((resolve) => this.resolveContinuePromise = resolve);
-    this.pullingResolveCallback = null
-    this.timeoutPullingCallback = null
-    this.pullingFinishedPromise = querablep(Promise.resolve());
 
     this.loops = 0;
 
@@ -59,30 +51,6 @@ export class PermanentProver {
     this.resolveContinuePromise(true);
   }
 
-  // When we detected a pulling, we stop the PoW loop
-  pullingDetected() {
-    if (this.pullingFinishedPromise && this.pullingFinishedPromise.isResolved()) {
-      this.pullingFinishedPromise = querablep(Promise.race([
-        // We wait for end of pulling signal
-        new Promise((res) => this.pullingResolveCallback = res),
-        // Security: if the end of pulling signal is not emitted after some, we automatically trigger it
-        new Promise((res) => this.timeoutPullingCallback = () => {
-          this.logger.warn('Pulling not finished after %s ms, continue PoW', Constants.PULLING_MAX_DURATION);
-          res();
-        })
-      ]));
-    }
-    // Delay the triggering of pulling timeout
-    if (this.timeoutPulling) {
-      clearTimeout(this.timeoutPulling);
-    }
-    this.timeoutPulling = setTimeout(this.timeoutPullingCallback, Constants.PULLING_MAX_DURATION);
-  }
-
-  pullingFinished() {
-    return this.pullingResolveCallback && this.pullingResolveCallback()
-  }
-
   async startPermanence() {
 
     let permanenceResolve = () => {}
@@ -120,11 +88,6 @@ export class PermanentProver {
           const trial = await this.server.getBcContext().getIssuerPersonalizedDifficulty(selfPubkey);
           this.checkTrialIsNotTooHigh(trial, current, selfPubkey);
           const lastIssuedByUs = current.issuer == selfPubkey;
-          if (this.pullingFinishedPromise && !this.pullingFinishedPromise.isFulfilled()) {
-            this.logger.warn('Waiting for the end of pulling...');
-            await this.pullingFinishedPromise;
-            this.logger.warn('Pulling done. Continue proof-of-work loop.');
-          }
           if (lastIssuedByUs && !this.promiseOfWaitingBetween2BlocksOfOurs) {
             this.promiseOfWaitingBetween2BlocksOfOurs = new Promise((resolve) => setTimeout(resolve, theConf.powDelay));
             this.logger.warn('Waiting ' + theConf.powDelay + 'ms before starting to compute next block...');
diff --git a/app/modules/prover/lib/prover.ts b/app/modules/prover/lib/prover.ts
index e37662e08..50e30f6f9 100644
--- a/app/modules/prover/lib/prover.ts
+++ b/app/modules/prover/lib/prover.ts
@@ -21,13 +21,6 @@ export class Prover extends stream.Transform {
         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) {
         this.permaProver.prover.changeCPU(obj.cpu); // We multiply by 10 to give room to computers with < 100 cores
-      } else if (obj.pulling !== undefined) {
-        if (obj.pulling === 'processing') {
-          this.permaProver.pullingDetected();
-        }
-        else if (obj.pulling === 'finished') {
-          this.permaProver.pullingFinished();
-        }
       }
     }
     done && done();
-- 
GitLab