**6. Implementation**

In our experiment, we simulated each node by a process, where we implemented multi-process programming. In several tests, we created a different number of processes, each of them starting with the creation of a random number *blockID* ← *random*(), which is considered as the ID of the candidate block that the process is working on. After that, each process follows the execution of the proposed algorithm (Algorithm 1). Using five rounds and ten processes, the test took about 5 min, and we go<sup>t</sup> the result shown in Figure 2. The execution at University of El Oued was defined in Python using a mainframe made up of 32 dual-processor nodes of 10 cores each. The intensive computing unit has a managemen<sup>t</sup> node with the following specifications: Processor: Intel Xeon (R) E5-2660 v3 @ 2.60 GHz x 20, memory: 64 GB of RAM, disk: 2 TB HDD, OS: RedHat Enterprise Linux Server 7.2, OS type: 64 bit. The computing unit has 32 nodes. Each node has the following

characteristics: 10 physical cores, storage capacity: 500 GB HDD and available memory: 64 GB. The Proposed technique can be defined by the following algorithm:

**Algorithm 1** Consensus algorithm


**Figure 2.** Compute and wait example execution.

We repeated the experiment tens of times in each scenario (each input variation). For example, in Figure 3 with the first scenario where the number of processes is equal to 5 and the number of rounds equal to 5, the gain was 12.07. We repeated this test several times and we obtained different values (between 11 and 14), but we took the most frequent value which was 12.07. We did this at each input change (NbrR, NbrP = (5, 5); (5, 10); (5, 15); (5, 20). We did not take the average of measurements, but we considered the most frequent value.

**Figure 3.** The influence of NbrP for fixed NbrR.

The formal definition of gain: In each round, the process searches for a solution (compute time). Then the process will wait until it receives the latest solution. We will consider this wait time as a gain, and we can formulate the gain rate as follows: *gain rate = wait time/total execution time*. If the total execution time is the wait and compute time, we obtain:

$$\text{Again rate} = \text{wait time} / (\text{wait time} + \text{compute time}) \tag{4}$$

We let *Ci*,*<sup>x</sup>* (respectively, *Wi*,*<sup>x</sup>*) be the compute (respectively, wait) time of the process *i* in round *x*. The gain of the process *i* can be formulated as follows:

$$
gamma\_i = \sum\_{j=1}^{NbrR} \left( \mathcal{W}\_{i,j} / \left( \mathcal{W}\_{i,j} + \mathcal{C}\_{i,j} \right) \right) \tag{5}
$$

The average gain rate (network gain rate) is:

$$Gain = \sum\_{i=1}^{NbrP} \left(gain\_i / NbrP \right) \tag{6}$$

In the scenario shown in Figure 2, we have set the number of rounds *NbrR* = 5, *NbrP* = *NbrS* = 10, where NbrP (respectively, NbrS) is the number of processes (respectively, of solutions). We do not put different values between *NbrP* and *NbrS* in order to study the pure effect of the number of rounds. We notice that there is a real compute and wait in each round for most of the processes. Process 10 is the fastest because it has the minimum execution time and the maximum waiting time, that is why it has the highest gain rate (45.52%). On the other hand, process 1 (*p*<sup>1</sup>) is the heaviest process, because *p*1 has the highest execution and the lowest waiting time, and thus the lowest gain rate. For *p*1, the gain rate = wait/(wait + execution) = 0/(0 + 195) = 0. We explain that *p*1 is the last process to find the solution, it wakes up the others, and then starts directly the next round without making any wait. Even though *p*1 didn't wait, its computing time is less than the one of *p*8. We explain this by two possibilities. The first is given when *p*8 started, the second possibility when *p*1 quickly found the solution in the last round (there is no wait after the last round) and *p*8 took a long time in the last round. In general, the average gain of the network is 15.63%.

Compute and wait implementation: In the original PoW, each process will continue the calculation for 10 min (until one of the processes finds the hash). In the proposed protocol there are two types of processes, winning processes, which are processes that participate in all rounds (noting that the final winner is the process that has the minimum standard deviation of his solutions). The other type are those processes that leave the competition after such rounds (for example, when the number of solutions of the next round is equal to NbrS). In these two types, no process does the calculation during 10 min, there is a proof-wait (first type) or a proof-abandon (second type). So, there are two main factors that must be handled, the number of rounds *NbrR* and the number of solutions to be found in each round *NbrS*.

#### **Lemma 1.** *If NbrR* > 1 *then Gain* > 0

**Proof.** Based on the randomness of the hash function (Block + Nonce) < Target and on the arbitrary speed of each process, we have:

$$\mathbb{C}\_{i,\mathbf{x}} \neq \mathbb{C}\_{j,\mathbf{x}\prime} \,\forall i, j \in \{1, \dots, NbrP\}, \,\forall \mathbf{x} \in \{1, \dots, NbrR\} \tag{7}$$

where *NbrP* is the number of processes and 0 < *x* < *NbrR*. According to Equation (7), |*Ci*,*<sup>x</sup>* − *Cj*,*<sup>x</sup>*| > 0, so either *Wi*,*<sup>x</sup>* > 0 or *Wj*,*<sup>x</sup>* > 0, which implies that *Wi*,*<sup>x</sup>*/(*Wi*,*<sup>x</sup>* + *Ci*,*<sup>x</sup>*) > 0 or *Wi*,*<sup>x</sup>*/(*Wj*,*<sup>x</sup>* + *Cj*,*<sup>x</sup>*) > 0. We obtain *Gain* > 0.

#### **Lemma 2.** *If NbrP increases then Gain increases when NbrP* = *NbrS*

**Proof.** We let the probability of finding the solution by 5 (respectively, 10) processes be *P*5 (respectively, *P*10), we have *P*10 > *P*5. Let *Tp* be the compute time to find the solution with a probability *p*. So, *Tp*10 < *Tp*5 implies that the wait time *Wp*10 > *Wp*5 . According to Equation (4), *gain*10*processes* > *gain*5*processes*.

Discussion: In the first scenario shown by Figure 3, we fixed NbrR to 5, and we made several tests, during which we increased the number of processes (NbrP = 5, 10, 15, 20) to study the effect of this increase and its influence on the gain. These tests have shown that the more many processes do compute and wait, the more the gain increases. We explain this by the following example: in the round *x*, if first process *pi* finds a solution after 4 min, we suppose that *pi* will wait *t*1 = 1 minute to start the next round *x* + 1, so the gain is 1/(1 + 4) = 20%. With *NbrP* = 10, the first process *pj* will find a solution in 3 min, *pj* will wait for *t*2 > *t*1 (*t*2 = 2 min), so the gain is 2 / (2 + 4) = 30%.

In the second curve (curve on the right in Figure 3), where the NbrS is constant, we observe that the gain decreases, because the number of processes (which are waiting) decreases compared to the total number of processes. On the other hand, the number of processes that do not wait is increasing, which implies a decrease in the average gain in the network.

#### **Lemma 3.** *While NbrR* < *upper bound, if NbrR increases then Gain increases.*

**Proof.** Let *w* be the wait time, *c* the compute time, and *e* the execution time, so *e* = *w* + *c*. The gain *g* = *we* , and if a process does little computation and a lot of wait, then it will have a high gain rate. We know that there is no wait time in the last round, therefore, if *NbrR* = 2, then *g* = *w <sup>e</sup>*1+*e*2 where w is the wait time of round 1, *e*1 the compute time of round 1, and *e*2 the compute time of round 2. Let *e*1 + *e*2 = 2 × *e*. If *NbrR* = 3, then *g* = 2×*w* 3×*e* , if *NbrR* = 4, then *g* = 3×*w* 4×*e* ... , if *NbrR* = *α*, then *g* = *α*×*w* (*α*+<sup>1</sup>)×*e*. The effect of the wait time absence in the last round decreases if we increase *NbrR* and the gain *g* converges to *we* because *α* (*α*+<sup>1</sup>) converges to 1.

Discussion: In the second scenario illustrated by Figure 4, we fixed *NbrP* to 10, and we made several tests, in each of them increasing the number of rounds (*NbrR* = 5, 10, 15, 20) to study the effect of this increase and its influence on the gain. These tests have shown that the more *NbrR* increases, the more the gain increases but not absolutely. Rather, this increase converges to an upper bound related to the number of processes. Then the gain decreases because the difficulty is also reduced (NbrR increases then difficulty decreases).

Therefore, the processes will end almost at the same time because the solution is easy to find.

**Figure 4.** The influence of NbrR, case A.

#### **Lemma 4.** *If NbrR increases then Gain*(*Gnw*) *converges to a number G*

**Proof.** The average gain of the network (*Gnw*)=(*g*1 + *g*1 + ... *gNbrR*)/*NbrR* where *gi* is the gain of round *i*. We have *gNbrR* (gain of the last round) equal to 0 because there is a calculation and there is no wait. *gi* depends on moments *ti*,*j* at which solutions are found (*ti*,<sup>1</sup> is the instant where the first solution of round *i* is found, *ti*,*NbrR* is the instant at which the last solution of round *i* is found). In general, these times are random in each round, therefore, *g*1 ≈ *g*2 ≈ ... *gNbrR*−<sup>1</sup> and then *Gnw* = (*NbrR* − 1) × *g*1/*NbrR*

We obtain:

$$G\_{ww} = \mathcal{g}\_1 - (\mathcal{g}\_1 / NbrR) \tag{8}$$

We observe that if *NbrR* = 1 then *Gnw* = 0 and if *NbrR increases* then *Gnw* ≈ *g*1 = *G* Discussion: Figure 5 shows how the gain converges to a constant number G when the number of rounds increases (NbrR = 5, 10, 15, 20, 25). Usually, G depends on the number of processes and the number of solutions. In Figure 5, we have fixed the number of processes and the number of solutions. In Figure 5-right, (NbrP, NbrS) = (10, 5) and we have set up several scenarios (NbrR = 5, . . . until NbrR = 200). We noticed that starting from NbrR = 20 the gain remains greater than 8 and less than 9. In the similar way, in Figure 5-left, the gain remains close to 19.5 whenever NbrR > 20 (20 NbrR 200). This is why we said that the gain converges to a constant number G when the number of rounds increases. *G* ≈ 8.5 with (NbrP, NbrS) = (10, 5) and NbrR 20; *G* ≈ 19.5 with (NbrP, NbrS) = (10, 10) and NbrR 20.

The number of solutions is a very important factor because it designates the number of processes that will wait; therefore, it controls the gain. Figure 6 shows the increase in gain as NbrS increases. On the other hand, we cannot introduce a number of solutions without having a multi-round environment. The importance of NbrS directs us towards private blockchains; In which we can talk about NbrS compared to the total number of processes. In another philosophy, we may consider that the node leaves the competition if NbrS of the next round is saturated. In this case, we will increase the gain to the maximum (Table 1). The downside of this philosophy is that after a round *j* in which the number of processes is NbrS and one of these processes breaks down, the rest of the competitors (NbrS-1) cannot continue because NbrS (in round *j* + 1) will never be reached.

**Figure 5.** The influence of NbrR, case B.

**Figure 6.** The influence of NbrS.

**Table 1.** The gain rate with leaving competition.

