From 14850d462ce4bf567077f2f11541405ce61f2ef7 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sun, 27 Aug 2017 11:09:44 +0200
Subject: [PATCH] [fix] #1089 Add a semaphore on block computation

---
 app/modules/prover/lib/permanentProver.ts | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/app/modules/prover/lib/permanentProver.ts b/app/modules/prover/lib/permanentProver.ts
index 033fdb4c7..f0c974bbf 100644
--- a/app/modules/prover/lib/permanentProver.ts
+++ b/app/modules/prover/lib/permanentProver.ts
@@ -156,11 +156,15 @@ export class PermanentProver {
             // The generation
             (async () => {
               try {
-                const current = await this.server.dal.getCurrentBlockOrNull();
-                const selfPubkey = this.server.keyPair.publicKey;
-                const trial2 = await this.server.getBcContext().getIssuerPersonalizedDifficulty(selfPubkey);
-                this.checkTrialIsNotTooHigh(trial2, current, selfPubkey);
-                this.lastComputedBlock = await this.generator.makeNextBlock(null, trial2);
+                let unsignedBlock = null, trial2 = 0
+                await this.server.BlockchainService.pushFIFO('generatingNextBlock', async () => {
+                  const current = await this.server.dal.getCurrentBlockOrNull();
+                  const selfPubkey = this.server.keyPair.publicKey;
+                  trial2 = await this.server.getBcContext().getIssuerPersonalizedDifficulty(selfPubkey);
+                  this.checkTrialIsNotTooHigh(trial2, current, selfPubkey);
+                  unsignedBlock = await this.generator.nextBlock()
+                })
+                this.lastComputedBlock = await this.prover.prove(unsignedBlock, trial2, null)
                 try {
                   const obj = parsers.parseBlock.syncWrite(dos2unix(this.lastComputedBlock.getRawSigned()));
                   await this.server.writeBlock(obj)
-- 
GitLab