+ All Categories
Home > Documents > HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node...

HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node...

Date post: 31-Jul-2021
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
13
Research Article Hybrid Consensus Algorithm Optimization: A Mathematical MethodBasedonPOSandPBFTandItsApplicationinBlockchain Yaqin Wu , Pengxin Song, and Fuxin Wang School of Mechanical Electronic and Information Engineering, China University of Mining and Technology (Beijing), Beijing 100083, China Correspondence should be addressed to Yaqin Wu; [email protected] Received 11 December 2019; Accepted 6 March 2020; Published 13 April 2020 Academic Editor: Ricardo Aguilar-Lopez Copyright © 2020 Yaqin Wu et al. is is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. Blockchain is a new technology for processing complex and disordered information with respect to business and other industrial applications. is work is aimed at studying the consensus algorithm of blockchain to improve the performance of blockchain. Despite their advantages, the proof of stake (POS) algorithm and the practical Byzantine fault tolerance (PBFT) algorithm have high latency, low throughput, and poor scalability. In this paper, a blockchain hybrid consensus algorithm which combines advantages of the POS and PBFT algorithms is proposed, and the algorithm is divided into two stages: sortition and witness. e proposed algorithm reduces the number of consensus nodes to a constant value by verifiable pseudorandom sortition and performs transaction witness between nodes. e algorithm is improved and optimized from three dimensions: throughput, latency, and scalability. e experimental results show that the improved hybrid consensus algorithm is significantly superior to the previous single algorithms for its excellent scalability, high throughput, and low latency. 1. Introduction With the development of science and technology, block- chain technology has gradually emerged in people’s vision and become a focus of research by experts and scholars. It is receiving increasing attentions from industry and academia. People have been aware of the unique remarkable innova- tion that the blockchain technology can bring about and have invested in researches on business aspects such as fi- nance, insurance, and traceability, which further accelerates maturity and industry landing of the blockchain technology [1, 2]. Currently, the fledgling blockchain technology is developing in China; the market competition pattern and the independent intellectual property system are initially formed. Meanwhile, relevant technologies and applied ecology are forming in areas, such as energy, medicine, and libraries [3–5]. e blockchain technology is a new kind of distributed infrastructure and computing paradigm in which the chain data structure is used to verify the data structure and store data, the distributed node consensus algorithm is used to generate and update data, the cryptography way is used to ensure the security of data transmission and access, and the intelligent contracts composed of automated script code are used to program and manipulate data. Extensive researches have been conducted on the blockchain. Larimer et al. proposed the delegated proof of stack (DPOS) algorithm [6] that utilizes the entrusted voting of stakeholders to elect multiple super nodes and solves the consensus problem in a democratic and fair way. Wood et al. proposed the proof of authority (POA) algorithm [7] which is essentially an optimized equity proof model. Identity authentication is used as the form of equity to replace digital currency. Authentication is authorized by a preapproved set of nodes to authenticate transactions and blocks in their respective networks. To ensure network efficiency and ad- ministrative security, there are usually only a few (typically fewer than 25) validation nodes. Bowers et al. proposed the proof of retrievability (POR) algorithm [8] which is a form of proof from the file system to the client to prove the integrity of the file. Compared with other consensus algorithms, the POR algorithm is of lower communication complexity. Castro and Liskov proposed the practical Byzantine fault Hindawi Mathematical Problems in Engineering Volume 2020, Article ID 7270624, 13 pages https://doi.org/10.1155/2020/7270624
Transcript
Page 1: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

Research ArticleHybrid Consensus Algorithm Optimization A MathematicalMethodBasedonPOSandPBFTand ItsApplication inBlockchain

Yaqin Wu Pengxin Song and Fuxin Wang

School of Mechanical Electronic and Information Engineering China University of Mining and Technology (Beijing)Beijing 100083 China

Correspondence should be addressed to Yaqin Wu wyqcumtcumtbeducn

Received 11 December 2019 Accepted 6 March 2020 Published 13 April 2020

Academic Editor Ricardo Aguilar-Lopez

Copyright copy 2020 Yaqin Wu et al +is is an open access article distributed under the Creative Commons Attribution Licensewhich permits unrestricted use distribution and reproduction in any medium provided the original work is properly cited

Blockchain is a new technology for processing complex and disordered information with respect to business and other industrialapplications +is work is aimed at studying the consensus algorithm of blockchain to improve the performance of blockchainDespite their advantages the proof of stake (POS) algorithm and the practical Byzantine fault tolerance (PBFT) algorithm havehigh latency low throughput and poor scalability In this paper a blockchain hybrid consensus algorithm which combinesadvantages of the POS and PBFTalgorithms is proposed and the algorithm is divided into two stages sortition and witness +eproposed algorithm reduces the number of consensus nodes to a constant value by verifiable pseudorandom sortition andperforms transaction witness between nodes +e algorithm is improved and optimized from three dimensions throughputlatency and scalability +e experimental results show that the improved hybrid consensus algorithm is significantly superior tothe previous single algorithms for its excellent scalability high throughput and low latency

1 Introduction

With the development of science and technology block-chain technology has gradually emerged in peoplersquos visionand become a focus of research by experts and scholars It isreceiving increasing attentions from industry and academiaPeople have been aware of the unique remarkable innova-tion that the blockchain technology can bring about andhave invested in researches on business aspects such as fi-nance insurance and traceability which further acceleratesmaturity and industry landing of the blockchain technology[1 2] Currently the fledgling blockchain technology isdeveloping in China themarket competition pattern and theindependent intellectual property system are initiallyformed Meanwhile relevant technologies and appliedecology are forming in areas such as energy medicine andlibraries [3ndash5] +e blockchain technology is a new kind ofdistributed infrastructure and computing paradigm in whichthe chain data structure is used to verify the data structureand store data the distributed node consensus algorithm isused to generate and update data the cryptography way is

used to ensure the security of data transmission and accessand the intelligent contracts composed of automated scriptcode are used to program and manipulate data

Extensive researches have been conducted on theblockchain Larimer et al proposed the delegated proof ofstack (DPOS) algorithm [6] that utilizes the entrusted votingof stakeholders to elect multiple super nodes and solves theconsensus problem in a democratic and fair wayWood et alproposed the proof of authority (POA) algorithm [7] whichis essentially an optimized equity proof model Identityauthentication is used as the form of equity to replace digitalcurrency Authentication is authorized by a preapproved setof nodes to authenticate transactions and blocks in theirrespective networks To ensure network efficiency and ad-ministrative security there are usually only a few (typicallyfewer than 25) validation nodes Bowers et al proposed theproof of retrievability (POR) algorithm [8] which is a form ofproof from the file system to the client to prove the integrityof the file Compared with other consensus algorithms thePOR algorithm is of lower communication complexityCastro and Liskov proposed the practical Byzantine fault

HindawiMathematical Problems in EngineeringVolume 2020 Article ID 7270624 13 pageshttpsdoiorg10115520207270624

tolerance (PBFT) algorithm [9] As an algorithm based on astate machine copy replica the PBFT algorithm provides afault tolerance guarantee that the failure node does notexceed (n minus 1)3 under the premise of ensuring safety andactivity [10]

+is work is aimed at studying the blockchain consensusalgorithm and proposing an improved hybrid consensusalgorithm that combines advantages of the PBFT algorithmand the proof of stake (POS) algorithm +e proposedimproved consensus algorithm boasts both the low latencyand high throughput of the PBFT algorithm and the scal-ability and fairness of the POS algorithm +e main con-tributions of this work are as follows

(1) Mainstream blockchain consensus algorithms werestudied +eir advantages and disadvantages andspecific application scenarios were compared bymeans of data analysis +e POS algorithm features aconsensus time latency and low throughput whilethe PBFT algorithm needs to specify the number ofnodes in the whole network when running For a P2Pnetwork the number of nodes does not always re-main constant and nodes will continuously join orexit the network However the current number ofnodes is critical to a PBFTalgorithm and the numberof wrong nodes can lead to consensus failures or evendata inconsistencies

(2) Consensus algorithms were analyzed An improvedhybrid consensus algorithm was put forward bycombining advantages of the PBFT algorithm andthe POS algorithm It reduces the number of con-sensus nodes to a constant value by means of veri-fiable pseudorandom sortition and conductstransaction witness between nodes Finally theimproved algorithm was tested and verified fromthree dimensions namely throughput scalabilityand latency +e results reveal that the improvedhybrid consensus is pretty advantageous in the threedimensions

2 Theories

21 Overview of Consensus Algorithm A consensus algo-rithm is a set of rules that govern the proper functioning of adistributed system +ese rules define the basic functions ofdifferent parts the way they cooperate and the essentialconditions required for functioning properly A consensusalgorithm describes the rules to be followed to reach aconsensus and usually describes what operations should beperformed under what conditions in detail For example theproof of work (POW) algorithm defines the following ruleas long as a node can calculate the block that conforms to thetarget value it can be verified by the whole networkGenerally speaking a consensus algorithm is a process ofsolving data synchronization between the nodes which donot trust each other in a distributed system

211 POW Algorithm +e POW algorithm [11] was pro-posed before the appearance of cryptocurrencies and was

first used in antispam scenarios It usually consists ofhashing and validation functions +e input of a hashfunction is a character or a file with a variable length whileits output is a hash value with a constant length Since manyraw and intermediate data are abandoned in the hashprocess the hash function is irreversible +e results of hashfunctions are highly random to ensure fair competitionbetween nodes Validation functions are used for defining ahash value range that conforms to the rules so as to measurethe workload +e value ranges of validation functions aredynamically adjusted to avoid the problems caused by theincrease or decrease of network hashrate so that the POWalgorithm can run stably and smoothly

hash(T) hash value

verify(hash valuege target value)1113896 (1)

+e POW algorithm shown in Eq (1) relies on math-ematical problems that are easy to be verified but difficult tobe solved According to a hash function hash N⟶ N x

can be solved so that hash(T + x)ge target value and T arethe Merkel roots of the business lists Target value is adynamically adjusted value called the difficulty value x

represents variable parameters such as trading data andverification random number Each block in the blockchainwith workload proof will contain a solution to solve thisproblem +e total difficulty of the blockchain is the sum ofthe difficulties of all blockchains as shown in the followingequation

D(l) D 1113936i

li1113888 1113889 1113936i

D li( 1113857 (2)

In the process of forking the highest blockchain is theone with the greatest total difficulty as shown in the fol-lowing equation

Φ l1 l2 ln( 1113857 lm where m arg maxiisin1n

D li( 1113857( 1113857

(3)

In bitcoin [12] for example the hash function is SHA-256 and the validation function is to compare the hash valuewith the target value until the hash value becomes smallerthan the target value +e package equity of the block isobtained by solving the block that meets the requirementsEach node can merely carry out hash value collision byconstantly changing variable options such as the randomnumber until the value satisfying the condition is acquired

+e POW algorithm is a computation-intensive algo-rithm that consumes considerable energy and resourcesEvery year the bitcoin network consumes about 576 TWhof electricity equivalent to the annual electricity con-sumption of Colombia [13] In addition the competition forbitcoin mining is continuing which means more electricitywill be consumed In spite of its vast energy consumptionthis mechanism can guarantee the security and trust of dataIn fact the POW algorithm has some other inherent defects+e huge energy consumption leads to a low degree ofpersonal participation and turns the bitcoin network into anorganizational or operational mining pool As a result the

2 Mathematical Problems in Engineering

bitcoin network gradually tends to be centralized contraryto the original idea of decentralization

Excessive concentration of hashrate will bring the risk ofldquo51 hashrate attackrdquo +e so-called ldquo51 hashrate attackrdquodoes not mean a specific 51 hashrate Instead it refers tothe fact that if a node holds more than half of the networkhashrate it will pose the risk of attacking the network as it iscapable of tampering with the block data by virtue of its ownhashrate However due to the large number of nodes in thebitcoin network and their distribution all over the world it ishard to obtain more than half of the hashrate of the wholenetwork and it is extremely difficult and expensive forindividuals to tamper with the data

212 POS Algorithm Different from the POW algorithmthe POS algorithm need not obtain the rights and interests ofblock packaging through hashrate Instead it is conducted inthe form of mortgage tokens and the node with the mostsecurity interests will obtain the rights and interests of thenext block packaging [14] +e biggest advantage of the POSalgorithm is that it does not need an intensive operationCompared with the POW algorithm the POS algorithm notonly consumes less energy but also functions more effi-ciently Moreover lower energy consumption makes par-ticipation cheaper and allows more people to join thedecentralized network

+e POS algorithm has a collection of equity holdersEach time the algorithm selects an equity holder from thecollection as a witness through the pseudorandom algo-rithm +e witness is endowed with the right to produce ablock based on the greatest height of the current blockchainIf the witness fails to produce the block within the giventime the second witness will be chosen +e POS algorithmcan provide a relatively fair solution In the pseudorandomalgorithm the probability that an equity holder is selected asa witness increases linearly according to its weight of equitymortgage +at is an equity holder who owns more equitymortgage is more likely to be selected as a witness If onenode has 10 times the equity of the other it is going to get 10times the probability of being selected POS means thatblocks are all packaged by equity holders If an equity holderis verified to have violated the rules of double mining ordouble signature the mortgaged tokens and equity will beconfiscated

213 PBFT Algorithm +e PBFT algorithm provides thefault tolerance of |(n minus 1)3| It aims to solve the problem ofinefficiency of the original Byzantine algorithm and can beapplied in the actual scenario In equation (4) n is the totalnumber of nodes directly participating in the consensus inthe network and f is the maximum number of maliciousnodes allowed to be tolerated +e algorithm requires theparticipation of at least 3f + 1 nodes In the extreme case f

nodes can be faulty nodes (different from malicious nodes)To enable the number of normal nodes to be greater thanthat of malicious nodes n minus 2fgtf it is necessary to satisfyngt 3f and at least 3f + 1 nodes are needed Since at most fmalicious nodes exist in the network which contains 3f + 1

nodes the algorithm can still guarantee consistency andcorrectness of the data

n 3f + 1

f n minus 13

(4)

+e three phases of agreement among four nodes aredescribed in Figure 1 where Node 4 is the faulty node andNodes 1ndash3 are the normal nodes First the client initiates arequest and after receiving the request Node 1 sends apreprepared message to the other nodes If the other nodesagree to the request they will enter the prepare phaseotherwise they will send a rejection message back In theprepare phase if preprepared messages are received frommore than 2f nodes the preparation will be completed andthe commit phase will be entered In the commit phase thecommit information is broadcast to other nodes If com-mitted messages are received from more than 2f nodes thecommit phase will be completed and more than half of thenodes will reach an agreement Finally the information willbe replied to the client after being processed +e algorithmhas set a corresponding time specification for each proce-dure in the process of reaching an agreement If the task ofthis phase fails to be completed within the specified time thecurrent round of consensus terminates for timeout

Figure 1 shows that the network message transmissionbetween nodes is very frequent in the PBFT algorithm Asthe number of nodes increases a large number of con-sensus messages are transmitted through the networkleading to the congestion and even unavailability of thenetwork +e PBFT algorithm needs to specify the numberof nodes in the whole network when running For a P2Pnetwork the number of nodes does not always remainconstant and nodes will continuously join or exit thenetwork However the current number of nodes is criticalto a PBFT algorithm and the number of wrong nodes canresult in consensus failures or even data inconsistenciesDue to the uncertain number of network nodes and theconsumption of network message the PBFT algorithmcannot be used in P2P networks with many nodes

214 Raft Algorithm +e Raft algorithm a consistencyalgorithm proposed after the Paxos algorithm is easier to beunderstood and implemented than the Paxos algorithm [15]It is a voting-type consistency algorithm that guarantees dataconsistency through log synchronization In order to en-hance its comprehensibility the Raft algorithm separates theprocess of achieving consistency into four parts leadershipelection log synchronization member change and securityassurance

In the Raft algorithm nodes play different roles in-cluding leaders candidates and followers in distributedsystems on the basis of their different states +e nodes playswitched roles and undertake different tasks according to thechange of system status +e specific role transition is dis-closed in Figure 2

Mathematical Problems in Engineering 3

+e running process of the Raft algorithm resembles anelection Specifically each node can become a candidate whoneeds to convince most voters to vote for it Once more thanhalf of the voters support it it becomes the leader Each nodein the Raft algorithm can be a candidate to send requests toother followers If the candidate receives more than half ofthe followersrsquo responses the election is successful and thecandidate becomes a leader Meanwhile a log is copied to thefollowers If the leader node is lost or goes down the electionwill be reconducted in accordance with the previous stepsEach node is equipped with a timer for determining whetherthe leader node is normal according to the heartbeat delay Ifthe heartbeat times out it means that the leader node is lostand fails to provide services In this case the node willconvert its role into a candidate and participate in the leaderelection of a new term

215 Algorithm Comparison Common consensus algo-rithms in the blockchain include POW POS delegatedproof of stake (DPOS) and PBFT +ese proof algorithmshave large performance bottlenecks Both the early dis-tributed consistency algorithms and the current blockchainconsensus algorithms are used for solving the problem ofdata inconsistency Of the two types the former are mostlyapplied to private networks or controlled network

environments and most of them are only targeted at dealingwith node network latency or other hardware failureproblems without considering the problem of malicioushacking or attack to the node data

As shown in Table 1 the Raft algorithm does not supportByzantine fault tolerance Besides it strictly restricts theentry and exit of nodes and its network is of constant scaleand poor scalability On the contrary proof algorithms suchas POW and POS need not submit their own conclusions tothe other nodes in the network +ey reach a consensususing proof and other nodes can perform verification Inaddition proof algorithms which are public network-ori-ented possess relatively lower requirements for participantsallow participants to be anonymous support Byzantine faulttolerance and enable the entire network to reach a con-sensus within minutes Nevertheless the POW algorithmmining consumes considerable electricity and it has thedisadvantages of high latency and low throughput For all itslow electricity consumption the POS algorithm has a longrecognition period and low throughput and it is dependenton its own ldquodigital currencyrdquo Although the DPOS algorithmis also less electricity consuming it is more complicatedbecause the concept of entrusted equity is introduced in thealgorithm and the representative node is selected by meansof manual voting +e notes are a low participation degreeso the algorithm is not completely decentralized Although

Request Preprepare Prepare Commit ReplyClient

Note 1

Note 2

Note 3

Note 4

Figure 1 Flowchart of PBFT algorithm

Discover highertenure and leader

Follower Candidate Leader

ReceiveElection

Start

Timer triggerTimeout

retransmissionGreater than the

general vote

Figure 2 Schematic diagram of role transition character transformation in the Raft algorithm

4 Mathematical Problems in Engineering

PBFT supports Byzantine fault tolerance and boasts highthroughput and low latency the nodes in the whole networkare limited Meanwhile its scalability is poor and excessivenodes will lead to a large number of consensus messages andunavailability of the nodes

22 Algorithm Design and Improvement

221 Formal Definition and Analysis A blockchain is es-sentially a state machine driven by transactions and thesystem state (s isin S) is a collection of stored data states Anoperation to change a data state is called a transaction +eyare defined as follows

(i) Transaction state machine a transaction state ma-chine is a quad (T S g δ) in which T means acollection of transactions S means a collection ofstates g isin S means the initial state δ means a statetransition function δ S times T⟶ S +e semantics ofthis transaction state machine are a discrete mi-gration system (S g⟶ ) in which g⟶isin S times S

represents the migration relationship(ii) Transaction log a transaction log called a ledger in

the blockchain is a set of transactions with abstractdata types constructed recursively It is defined asfollows

l Γ Tt( 1113857

l l1 + l21113896 (5)

where Tt isin 2T represents a set of transactionsΓ isin 2T⟶ L is a function for constructing a set oftransaction construction logs L is a collection oflogs times L times L⟶ L represents the merging of twologs into one It is noteworthy that a log usuallyrepresents a set of transactions rather than a datastate In the blockchain all transaction operationsare orderly and dependent Modifying one of thetransactions requires reconstructing a transactionlog which increases the cost of data tamperingMultiple valid log sets can be constructed based onthe received transaction log set but the variation oftransaction order will result in the inconsistentsystem state which is often referred to as ldquodataforkingrdquo

(iii) Data bifurcation let Tt Ttprime1113864 1113865 isin 2T TtsubeTt

prime Ifl Γ(Tt) lprime Γ(Tt

prime) and lle lprime (le represents theprefix relationship) are not satisfied then data

forking occurs between l and lprime According to thesemantics of the transaction state machine if noforking occurs each node will eventually enter thesame state If forking occurs and each node stillenters the same state the case is called pseudo-forking When forking occurs each node needs tochoose one of the many forking chains in accor-dance with the established rule+is established ruleis the consensus algorithm

(iv) Consensus algorithms Φ 2T⟶ L is a functionthat receives a collection of transaction logs andreturns a unique collection of ordered logs thatconform to established rules A good consensusalgorithm should have a high convergence ratewhich can be achieved based on a reduction offorking probability and a strong ability to preventmalicious attacks

Assuming that there are c nodes in the system partici-pating in transaction log production M |L| N

|S| Mi |Li| where Li l|f(l) si si isin S1113864 1113865 then theprobability of pseudoforking occurrence is Pf as shown inthe following equation

Pf 1113936N

i1

Mi

M1113872 1113873

Cminus

1MCminus 1 (6)

As can be seen from equation (6) the optimization of aconsensus algorithm by reducing the probability of pseu-doforking can be achieved in two ways +e first is to changethe structure of transaction log that is to divide theequivalent class of transaction log and construct a logstructure with a low forking probability +e second is toreduce C that is to reduce the probability of forking andpromote the efficiency of consensus by reducing the numberof nodes participating in the consensus +e second way isadopted to improve the existing consensus algorithm in thispaper

222 Algorithm Improvement and Implementation

(1) Improvement of POS and PBFT Algorithm +e study onconsensus algorithms reveals that the POS algorithm notonly spends a long time in reaching an agreement but alsorequires mining operations Even after the transaction isprocessed it still needs a long time to confirm the data untilthe probability enters the acceptable range +e wholeprocess is too time consuming+erefore the POS algorithmis not suitable for scenarios requiring quick feedback ofresults such as distributed storage

Table 1 Comparisons of consensus algorithms

Algorithm Billing right Advantage Disadvantage Representative applicationPOW Competing competition Decentralization High consumption high latency BitcoinPOS Equity competition Low resource consumption Low participation NxtDPOS Equity election High throughput high latency Producer evil EOSPBFT Leader node High throughput high latency Poor scalability FabricRaft Leader node High throughput high latency No Byzantine fault tolerance Etcd

Mathematical Problems in Engineering 5

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 2: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

tolerance (PBFT) algorithm [9] As an algorithm based on astate machine copy replica the PBFT algorithm provides afault tolerance guarantee that the failure node does notexceed (n minus 1)3 under the premise of ensuring safety andactivity [10]

+is work is aimed at studying the blockchain consensusalgorithm and proposing an improved hybrid consensusalgorithm that combines advantages of the PBFT algorithmand the proof of stake (POS) algorithm +e proposedimproved consensus algorithm boasts both the low latencyand high throughput of the PBFT algorithm and the scal-ability and fairness of the POS algorithm +e main con-tributions of this work are as follows

(1) Mainstream blockchain consensus algorithms werestudied +eir advantages and disadvantages andspecific application scenarios were compared bymeans of data analysis +e POS algorithm features aconsensus time latency and low throughput whilethe PBFT algorithm needs to specify the number ofnodes in the whole network when running For a P2Pnetwork the number of nodes does not always re-main constant and nodes will continuously join orexit the network However the current number ofnodes is critical to a PBFTalgorithm and the numberof wrong nodes can lead to consensus failures or evendata inconsistencies

(2) Consensus algorithms were analyzed An improvedhybrid consensus algorithm was put forward bycombining advantages of the PBFT algorithm andthe POS algorithm It reduces the number of con-sensus nodes to a constant value by means of veri-fiable pseudorandom sortition and conductstransaction witness between nodes Finally theimproved algorithm was tested and verified fromthree dimensions namely throughput scalabilityand latency +e results reveal that the improvedhybrid consensus is pretty advantageous in the threedimensions

2 Theories

21 Overview of Consensus Algorithm A consensus algo-rithm is a set of rules that govern the proper functioning of adistributed system +ese rules define the basic functions ofdifferent parts the way they cooperate and the essentialconditions required for functioning properly A consensusalgorithm describes the rules to be followed to reach aconsensus and usually describes what operations should beperformed under what conditions in detail For example theproof of work (POW) algorithm defines the following ruleas long as a node can calculate the block that conforms to thetarget value it can be verified by the whole networkGenerally speaking a consensus algorithm is a process ofsolving data synchronization between the nodes which donot trust each other in a distributed system

211 POW Algorithm +e POW algorithm [11] was pro-posed before the appearance of cryptocurrencies and was

first used in antispam scenarios It usually consists ofhashing and validation functions +e input of a hashfunction is a character or a file with a variable length whileits output is a hash value with a constant length Since manyraw and intermediate data are abandoned in the hashprocess the hash function is irreversible +e results of hashfunctions are highly random to ensure fair competitionbetween nodes Validation functions are used for defining ahash value range that conforms to the rules so as to measurethe workload +e value ranges of validation functions aredynamically adjusted to avoid the problems caused by theincrease or decrease of network hashrate so that the POWalgorithm can run stably and smoothly

hash(T) hash value

verify(hash valuege target value)1113896 (1)

+e POW algorithm shown in Eq (1) relies on math-ematical problems that are easy to be verified but difficult tobe solved According to a hash function hash N⟶ N x

can be solved so that hash(T + x)ge target value and T arethe Merkel roots of the business lists Target value is adynamically adjusted value called the difficulty value x

represents variable parameters such as trading data andverification random number Each block in the blockchainwith workload proof will contain a solution to solve thisproblem +e total difficulty of the blockchain is the sum ofthe difficulties of all blockchains as shown in the followingequation

D(l) D 1113936i

li1113888 1113889 1113936i

D li( 1113857 (2)

In the process of forking the highest blockchain is theone with the greatest total difficulty as shown in the fol-lowing equation

Φ l1 l2 ln( 1113857 lm where m arg maxiisin1n

D li( 1113857( 1113857

(3)

In bitcoin [12] for example the hash function is SHA-256 and the validation function is to compare the hash valuewith the target value until the hash value becomes smallerthan the target value +e package equity of the block isobtained by solving the block that meets the requirementsEach node can merely carry out hash value collision byconstantly changing variable options such as the randomnumber until the value satisfying the condition is acquired

+e POW algorithm is a computation-intensive algo-rithm that consumes considerable energy and resourcesEvery year the bitcoin network consumes about 576 TWhof electricity equivalent to the annual electricity con-sumption of Colombia [13] In addition the competition forbitcoin mining is continuing which means more electricitywill be consumed In spite of its vast energy consumptionthis mechanism can guarantee the security and trust of dataIn fact the POW algorithm has some other inherent defects+e huge energy consumption leads to a low degree ofpersonal participation and turns the bitcoin network into anorganizational or operational mining pool As a result the

2 Mathematical Problems in Engineering

bitcoin network gradually tends to be centralized contraryto the original idea of decentralization

Excessive concentration of hashrate will bring the risk ofldquo51 hashrate attackrdquo +e so-called ldquo51 hashrate attackrdquodoes not mean a specific 51 hashrate Instead it refers tothe fact that if a node holds more than half of the networkhashrate it will pose the risk of attacking the network as it iscapable of tampering with the block data by virtue of its ownhashrate However due to the large number of nodes in thebitcoin network and their distribution all over the world it ishard to obtain more than half of the hashrate of the wholenetwork and it is extremely difficult and expensive forindividuals to tamper with the data

212 POS Algorithm Different from the POW algorithmthe POS algorithm need not obtain the rights and interests ofblock packaging through hashrate Instead it is conducted inthe form of mortgage tokens and the node with the mostsecurity interests will obtain the rights and interests of thenext block packaging [14] +e biggest advantage of the POSalgorithm is that it does not need an intensive operationCompared with the POW algorithm the POS algorithm notonly consumes less energy but also functions more effi-ciently Moreover lower energy consumption makes par-ticipation cheaper and allows more people to join thedecentralized network

+e POS algorithm has a collection of equity holdersEach time the algorithm selects an equity holder from thecollection as a witness through the pseudorandom algo-rithm +e witness is endowed with the right to produce ablock based on the greatest height of the current blockchainIf the witness fails to produce the block within the giventime the second witness will be chosen +e POS algorithmcan provide a relatively fair solution In the pseudorandomalgorithm the probability that an equity holder is selected asa witness increases linearly according to its weight of equitymortgage +at is an equity holder who owns more equitymortgage is more likely to be selected as a witness If onenode has 10 times the equity of the other it is going to get 10times the probability of being selected POS means thatblocks are all packaged by equity holders If an equity holderis verified to have violated the rules of double mining ordouble signature the mortgaged tokens and equity will beconfiscated

213 PBFT Algorithm +e PBFT algorithm provides thefault tolerance of |(n minus 1)3| It aims to solve the problem ofinefficiency of the original Byzantine algorithm and can beapplied in the actual scenario In equation (4) n is the totalnumber of nodes directly participating in the consensus inthe network and f is the maximum number of maliciousnodes allowed to be tolerated +e algorithm requires theparticipation of at least 3f + 1 nodes In the extreme case f

nodes can be faulty nodes (different from malicious nodes)To enable the number of normal nodes to be greater thanthat of malicious nodes n minus 2fgtf it is necessary to satisfyngt 3f and at least 3f + 1 nodes are needed Since at most fmalicious nodes exist in the network which contains 3f + 1

nodes the algorithm can still guarantee consistency andcorrectness of the data

n 3f + 1

f n minus 13

(4)

+e three phases of agreement among four nodes aredescribed in Figure 1 where Node 4 is the faulty node andNodes 1ndash3 are the normal nodes First the client initiates arequest and after receiving the request Node 1 sends apreprepared message to the other nodes If the other nodesagree to the request they will enter the prepare phaseotherwise they will send a rejection message back In theprepare phase if preprepared messages are received frommore than 2f nodes the preparation will be completed andthe commit phase will be entered In the commit phase thecommit information is broadcast to other nodes If com-mitted messages are received from more than 2f nodes thecommit phase will be completed and more than half of thenodes will reach an agreement Finally the information willbe replied to the client after being processed +e algorithmhas set a corresponding time specification for each proce-dure in the process of reaching an agreement If the task ofthis phase fails to be completed within the specified time thecurrent round of consensus terminates for timeout

Figure 1 shows that the network message transmissionbetween nodes is very frequent in the PBFT algorithm Asthe number of nodes increases a large number of con-sensus messages are transmitted through the networkleading to the congestion and even unavailability of thenetwork +e PBFT algorithm needs to specify the numberof nodes in the whole network when running For a P2Pnetwork the number of nodes does not always remainconstant and nodes will continuously join or exit thenetwork However the current number of nodes is criticalto a PBFT algorithm and the number of wrong nodes canresult in consensus failures or even data inconsistenciesDue to the uncertain number of network nodes and theconsumption of network message the PBFT algorithmcannot be used in P2P networks with many nodes

214 Raft Algorithm +e Raft algorithm a consistencyalgorithm proposed after the Paxos algorithm is easier to beunderstood and implemented than the Paxos algorithm [15]It is a voting-type consistency algorithm that guarantees dataconsistency through log synchronization In order to en-hance its comprehensibility the Raft algorithm separates theprocess of achieving consistency into four parts leadershipelection log synchronization member change and securityassurance

In the Raft algorithm nodes play different roles in-cluding leaders candidates and followers in distributedsystems on the basis of their different states +e nodes playswitched roles and undertake different tasks according to thechange of system status +e specific role transition is dis-closed in Figure 2

Mathematical Problems in Engineering 3

+e running process of the Raft algorithm resembles anelection Specifically each node can become a candidate whoneeds to convince most voters to vote for it Once more thanhalf of the voters support it it becomes the leader Each nodein the Raft algorithm can be a candidate to send requests toother followers If the candidate receives more than half ofthe followersrsquo responses the election is successful and thecandidate becomes a leader Meanwhile a log is copied to thefollowers If the leader node is lost or goes down the electionwill be reconducted in accordance with the previous stepsEach node is equipped with a timer for determining whetherthe leader node is normal according to the heartbeat delay Ifthe heartbeat times out it means that the leader node is lostand fails to provide services In this case the node willconvert its role into a candidate and participate in the leaderelection of a new term

215 Algorithm Comparison Common consensus algo-rithms in the blockchain include POW POS delegatedproof of stake (DPOS) and PBFT +ese proof algorithmshave large performance bottlenecks Both the early dis-tributed consistency algorithms and the current blockchainconsensus algorithms are used for solving the problem ofdata inconsistency Of the two types the former are mostlyapplied to private networks or controlled network

environments and most of them are only targeted at dealingwith node network latency or other hardware failureproblems without considering the problem of malicioushacking or attack to the node data

As shown in Table 1 the Raft algorithm does not supportByzantine fault tolerance Besides it strictly restricts theentry and exit of nodes and its network is of constant scaleand poor scalability On the contrary proof algorithms suchas POW and POS need not submit their own conclusions tothe other nodes in the network +ey reach a consensususing proof and other nodes can perform verification Inaddition proof algorithms which are public network-ori-ented possess relatively lower requirements for participantsallow participants to be anonymous support Byzantine faulttolerance and enable the entire network to reach a con-sensus within minutes Nevertheless the POW algorithmmining consumes considerable electricity and it has thedisadvantages of high latency and low throughput For all itslow electricity consumption the POS algorithm has a longrecognition period and low throughput and it is dependenton its own ldquodigital currencyrdquo Although the DPOS algorithmis also less electricity consuming it is more complicatedbecause the concept of entrusted equity is introduced in thealgorithm and the representative node is selected by meansof manual voting +e notes are a low participation degreeso the algorithm is not completely decentralized Although

Request Preprepare Prepare Commit ReplyClient

Note 1

Note 2

Note 3

Note 4

Figure 1 Flowchart of PBFT algorithm

Discover highertenure and leader

Follower Candidate Leader

ReceiveElection

Start

Timer triggerTimeout

retransmissionGreater than the

general vote

Figure 2 Schematic diagram of role transition character transformation in the Raft algorithm

4 Mathematical Problems in Engineering

PBFT supports Byzantine fault tolerance and boasts highthroughput and low latency the nodes in the whole networkare limited Meanwhile its scalability is poor and excessivenodes will lead to a large number of consensus messages andunavailability of the nodes

22 Algorithm Design and Improvement

221 Formal Definition and Analysis A blockchain is es-sentially a state machine driven by transactions and thesystem state (s isin S) is a collection of stored data states Anoperation to change a data state is called a transaction +eyare defined as follows

(i) Transaction state machine a transaction state ma-chine is a quad (T S g δ) in which T means acollection of transactions S means a collection ofstates g isin S means the initial state δ means a statetransition function δ S times T⟶ S +e semantics ofthis transaction state machine are a discrete mi-gration system (S g⟶ ) in which g⟶isin S times S

represents the migration relationship(ii) Transaction log a transaction log called a ledger in

the blockchain is a set of transactions with abstractdata types constructed recursively It is defined asfollows

l Γ Tt( 1113857

l l1 + l21113896 (5)

where Tt isin 2T represents a set of transactionsΓ isin 2T⟶ L is a function for constructing a set oftransaction construction logs L is a collection oflogs times L times L⟶ L represents the merging of twologs into one It is noteworthy that a log usuallyrepresents a set of transactions rather than a datastate In the blockchain all transaction operationsare orderly and dependent Modifying one of thetransactions requires reconstructing a transactionlog which increases the cost of data tamperingMultiple valid log sets can be constructed based onthe received transaction log set but the variation oftransaction order will result in the inconsistentsystem state which is often referred to as ldquodataforkingrdquo

(iii) Data bifurcation let Tt Ttprime1113864 1113865 isin 2T TtsubeTt

prime Ifl Γ(Tt) lprime Γ(Tt

prime) and lle lprime (le represents theprefix relationship) are not satisfied then data

forking occurs between l and lprime According to thesemantics of the transaction state machine if noforking occurs each node will eventually enter thesame state If forking occurs and each node stillenters the same state the case is called pseudo-forking When forking occurs each node needs tochoose one of the many forking chains in accor-dance with the established rule+is established ruleis the consensus algorithm

(iv) Consensus algorithms Φ 2T⟶ L is a functionthat receives a collection of transaction logs andreturns a unique collection of ordered logs thatconform to established rules A good consensusalgorithm should have a high convergence ratewhich can be achieved based on a reduction offorking probability and a strong ability to preventmalicious attacks

Assuming that there are c nodes in the system partici-pating in transaction log production M |L| N

|S| Mi |Li| where Li l|f(l) si si isin S1113864 1113865 then theprobability of pseudoforking occurrence is Pf as shown inthe following equation

Pf 1113936N

i1

Mi

M1113872 1113873

Cminus

1MCminus 1 (6)

As can be seen from equation (6) the optimization of aconsensus algorithm by reducing the probability of pseu-doforking can be achieved in two ways +e first is to changethe structure of transaction log that is to divide theequivalent class of transaction log and construct a logstructure with a low forking probability +e second is toreduce C that is to reduce the probability of forking andpromote the efficiency of consensus by reducing the numberof nodes participating in the consensus +e second way isadopted to improve the existing consensus algorithm in thispaper

222 Algorithm Improvement and Implementation

(1) Improvement of POS and PBFT Algorithm +e study onconsensus algorithms reveals that the POS algorithm notonly spends a long time in reaching an agreement but alsorequires mining operations Even after the transaction isprocessed it still needs a long time to confirm the data untilthe probability enters the acceptable range +e wholeprocess is too time consuming+erefore the POS algorithmis not suitable for scenarios requiring quick feedback ofresults such as distributed storage

Table 1 Comparisons of consensus algorithms

Algorithm Billing right Advantage Disadvantage Representative applicationPOW Competing competition Decentralization High consumption high latency BitcoinPOS Equity competition Low resource consumption Low participation NxtDPOS Equity election High throughput high latency Producer evil EOSPBFT Leader node High throughput high latency Poor scalability FabricRaft Leader node High throughput high latency No Byzantine fault tolerance Etcd

Mathematical Problems in Engineering 5

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 3: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

bitcoin network gradually tends to be centralized contraryto the original idea of decentralization

Excessive concentration of hashrate will bring the risk ofldquo51 hashrate attackrdquo +e so-called ldquo51 hashrate attackrdquodoes not mean a specific 51 hashrate Instead it refers tothe fact that if a node holds more than half of the networkhashrate it will pose the risk of attacking the network as it iscapable of tampering with the block data by virtue of its ownhashrate However due to the large number of nodes in thebitcoin network and their distribution all over the world it ishard to obtain more than half of the hashrate of the wholenetwork and it is extremely difficult and expensive forindividuals to tamper with the data

212 POS Algorithm Different from the POW algorithmthe POS algorithm need not obtain the rights and interests ofblock packaging through hashrate Instead it is conducted inthe form of mortgage tokens and the node with the mostsecurity interests will obtain the rights and interests of thenext block packaging [14] +e biggest advantage of the POSalgorithm is that it does not need an intensive operationCompared with the POW algorithm the POS algorithm notonly consumes less energy but also functions more effi-ciently Moreover lower energy consumption makes par-ticipation cheaper and allows more people to join thedecentralized network

+e POS algorithm has a collection of equity holdersEach time the algorithm selects an equity holder from thecollection as a witness through the pseudorandom algo-rithm +e witness is endowed with the right to produce ablock based on the greatest height of the current blockchainIf the witness fails to produce the block within the giventime the second witness will be chosen +e POS algorithmcan provide a relatively fair solution In the pseudorandomalgorithm the probability that an equity holder is selected asa witness increases linearly according to its weight of equitymortgage +at is an equity holder who owns more equitymortgage is more likely to be selected as a witness If onenode has 10 times the equity of the other it is going to get 10times the probability of being selected POS means thatblocks are all packaged by equity holders If an equity holderis verified to have violated the rules of double mining ordouble signature the mortgaged tokens and equity will beconfiscated

213 PBFT Algorithm +e PBFT algorithm provides thefault tolerance of |(n minus 1)3| It aims to solve the problem ofinefficiency of the original Byzantine algorithm and can beapplied in the actual scenario In equation (4) n is the totalnumber of nodes directly participating in the consensus inthe network and f is the maximum number of maliciousnodes allowed to be tolerated +e algorithm requires theparticipation of at least 3f + 1 nodes In the extreme case f

nodes can be faulty nodes (different from malicious nodes)To enable the number of normal nodes to be greater thanthat of malicious nodes n minus 2fgtf it is necessary to satisfyngt 3f and at least 3f + 1 nodes are needed Since at most fmalicious nodes exist in the network which contains 3f + 1

nodes the algorithm can still guarantee consistency andcorrectness of the data

n 3f + 1

f n minus 13

(4)

+e three phases of agreement among four nodes aredescribed in Figure 1 where Node 4 is the faulty node andNodes 1ndash3 are the normal nodes First the client initiates arequest and after receiving the request Node 1 sends apreprepared message to the other nodes If the other nodesagree to the request they will enter the prepare phaseotherwise they will send a rejection message back In theprepare phase if preprepared messages are received frommore than 2f nodes the preparation will be completed andthe commit phase will be entered In the commit phase thecommit information is broadcast to other nodes If com-mitted messages are received from more than 2f nodes thecommit phase will be completed and more than half of thenodes will reach an agreement Finally the information willbe replied to the client after being processed +e algorithmhas set a corresponding time specification for each proce-dure in the process of reaching an agreement If the task ofthis phase fails to be completed within the specified time thecurrent round of consensus terminates for timeout

Figure 1 shows that the network message transmissionbetween nodes is very frequent in the PBFT algorithm Asthe number of nodes increases a large number of con-sensus messages are transmitted through the networkleading to the congestion and even unavailability of thenetwork +e PBFT algorithm needs to specify the numberof nodes in the whole network when running For a P2Pnetwork the number of nodes does not always remainconstant and nodes will continuously join or exit thenetwork However the current number of nodes is criticalto a PBFT algorithm and the number of wrong nodes canresult in consensus failures or even data inconsistenciesDue to the uncertain number of network nodes and theconsumption of network message the PBFT algorithmcannot be used in P2P networks with many nodes

214 Raft Algorithm +e Raft algorithm a consistencyalgorithm proposed after the Paxos algorithm is easier to beunderstood and implemented than the Paxos algorithm [15]It is a voting-type consistency algorithm that guarantees dataconsistency through log synchronization In order to en-hance its comprehensibility the Raft algorithm separates theprocess of achieving consistency into four parts leadershipelection log synchronization member change and securityassurance

In the Raft algorithm nodes play different roles in-cluding leaders candidates and followers in distributedsystems on the basis of their different states +e nodes playswitched roles and undertake different tasks according to thechange of system status +e specific role transition is dis-closed in Figure 2

Mathematical Problems in Engineering 3

+e running process of the Raft algorithm resembles anelection Specifically each node can become a candidate whoneeds to convince most voters to vote for it Once more thanhalf of the voters support it it becomes the leader Each nodein the Raft algorithm can be a candidate to send requests toother followers If the candidate receives more than half ofthe followersrsquo responses the election is successful and thecandidate becomes a leader Meanwhile a log is copied to thefollowers If the leader node is lost or goes down the electionwill be reconducted in accordance with the previous stepsEach node is equipped with a timer for determining whetherthe leader node is normal according to the heartbeat delay Ifthe heartbeat times out it means that the leader node is lostand fails to provide services In this case the node willconvert its role into a candidate and participate in the leaderelection of a new term

215 Algorithm Comparison Common consensus algo-rithms in the blockchain include POW POS delegatedproof of stake (DPOS) and PBFT +ese proof algorithmshave large performance bottlenecks Both the early dis-tributed consistency algorithms and the current blockchainconsensus algorithms are used for solving the problem ofdata inconsistency Of the two types the former are mostlyapplied to private networks or controlled network

environments and most of them are only targeted at dealingwith node network latency or other hardware failureproblems without considering the problem of malicioushacking or attack to the node data

As shown in Table 1 the Raft algorithm does not supportByzantine fault tolerance Besides it strictly restricts theentry and exit of nodes and its network is of constant scaleand poor scalability On the contrary proof algorithms suchas POW and POS need not submit their own conclusions tothe other nodes in the network +ey reach a consensususing proof and other nodes can perform verification Inaddition proof algorithms which are public network-ori-ented possess relatively lower requirements for participantsallow participants to be anonymous support Byzantine faulttolerance and enable the entire network to reach a con-sensus within minutes Nevertheless the POW algorithmmining consumes considerable electricity and it has thedisadvantages of high latency and low throughput For all itslow electricity consumption the POS algorithm has a longrecognition period and low throughput and it is dependenton its own ldquodigital currencyrdquo Although the DPOS algorithmis also less electricity consuming it is more complicatedbecause the concept of entrusted equity is introduced in thealgorithm and the representative node is selected by meansof manual voting +e notes are a low participation degreeso the algorithm is not completely decentralized Although

Request Preprepare Prepare Commit ReplyClient

Note 1

Note 2

Note 3

Note 4

Figure 1 Flowchart of PBFT algorithm

Discover highertenure and leader

Follower Candidate Leader

ReceiveElection

Start

Timer triggerTimeout

retransmissionGreater than the

general vote

Figure 2 Schematic diagram of role transition character transformation in the Raft algorithm

4 Mathematical Problems in Engineering

PBFT supports Byzantine fault tolerance and boasts highthroughput and low latency the nodes in the whole networkare limited Meanwhile its scalability is poor and excessivenodes will lead to a large number of consensus messages andunavailability of the nodes

22 Algorithm Design and Improvement

221 Formal Definition and Analysis A blockchain is es-sentially a state machine driven by transactions and thesystem state (s isin S) is a collection of stored data states Anoperation to change a data state is called a transaction +eyare defined as follows

(i) Transaction state machine a transaction state ma-chine is a quad (T S g δ) in which T means acollection of transactions S means a collection ofstates g isin S means the initial state δ means a statetransition function δ S times T⟶ S +e semantics ofthis transaction state machine are a discrete mi-gration system (S g⟶ ) in which g⟶isin S times S

represents the migration relationship(ii) Transaction log a transaction log called a ledger in

the blockchain is a set of transactions with abstractdata types constructed recursively It is defined asfollows

l Γ Tt( 1113857

l l1 + l21113896 (5)

where Tt isin 2T represents a set of transactionsΓ isin 2T⟶ L is a function for constructing a set oftransaction construction logs L is a collection oflogs times L times L⟶ L represents the merging of twologs into one It is noteworthy that a log usuallyrepresents a set of transactions rather than a datastate In the blockchain all transaction operationsare orderly and dependent Modifying one of thetransactions requires reconstructing a transactionlog which increases the cost of data tamperingMultiple valid log sets can be constructed based onthe received transaction log set but the variation oftransaction order will result in the inconsistentsystem state which is often referred to as ldquodataforkingrdquo

(iii) Data bifurcation let Tt Ttprime1113864 1113865 isin 2T TtsubeTt

prime Ifl Γ(Tt) lprime Γ(Tt

prime) and lle lprime (le represents theprefix relationship) are not satisfied then data

forking occurs between l and lprime According to thesemantics of the transaction state machine if noforking occurs each node will eventually enter thesame state If forking occurs and each node stillenters the same state the case is called pseudo-forking When forking occurs each node needs tochoose one of the many forking chains in accor-dance with the established rule+is established ruleis the consensus algorithm

(iv) Consensus algorithms Φ 2T⟶ L is a functionthat receives a collection of transaction logs andreturns a unique collection of ordered logs thatconform to established rules A good consensusalgorithm should have a high convergence ratewhich can be achieved based on a reduction offorking probability and a strong ability to preventmalicious attacks

Assuming that there are c nodes in the system partici-pating in transaction log production M |L| N

|S| Mi |Li| where Li l|f(l) si si isin S1113864 1113865 then theprobability of pseudoforking occurrence is Pf as shown inthe following equation

Pf 1113936N

i1

Mi

M1113872 1113873

Cminus

1MCminus 1 (6)

As can be seen from equation (6) the optimization of aconsensus algorithm by reducing the probability of pseu-doforking can be achieved in two ways +e first is to changethe structure of transaction log that is to divide theequivalent class of transaction log and construct a logstructure with a low forking probability +e second is toreduce C that is to reduce the probability of forking andpromote the efficiency of consensus by reducing the numberof nodes participating in the consensus +e second way isadopted to improve the existing consensus algorithm in thispaper

222 Algorithm Improvement and Implementation

(1) Improvement of POS and PBFT Algorithm +e study onconsensus algorithms reveals that the POS algorithm notonly spends a long time in reaching an agreement but alsorequires mining operations Even after the transaction isprocessed it still needs a long time to confirm the data untilthe probability enters the acceptable range +e wholeprocess is too time consuming+erefore the POS algorithmis not suitable for scenarios requiring quick feedback ofresults such as distributed storage

Table 1 Comparisons of consensus algorithms

Algorithm Billing right Advantage Disadvantage Representative applicationPOW Competing competition Decentralization High consumption high latency BitcoinPOS Equity competition Low resource consumption Low participation NxtDPOS Equity election High throughput high latency Producer evil EOSPBFT Leader node High throughput high latency Poor scalability FabricRaft Leader node High throughput high latency No Byzantine fault tolerance Etcd

Mathematical Problems in Engineering 5

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 4: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

+e running process of the Raft algorithm resembles anelection Specifically each node can become a candidate whoneeds to convince most voters to vote for it Once more thanhalf of the voters support it it becomes the leader Each nodein the Raft algorithm can be a candidate to send requests toother followers If the candidate receives more than half ofthe followersrsquo responses the election is successful and thecandidate becomes a leader Meanwhile a log is copied to thefollowers If the leader node is lost or goes down the electionwill be reconducted in accordance with the previous stepsEach node is equipped with a timer for determining whetherthe leader node is normal according to the heartbeat delay Ifthe heartbeat times out it means that the leader node is lostand fails to provide services In this case the node willconvert its role into a candidate and participate in the leaderelection of a new term

215 Algorithm Comparison Common consensus algo-rithms in the blockchain include POW POS delegatedproof of stake (DPOS) and PBFT +ese proof algorithmshave large performance bottlenecks Both the early dis-tributed consistency algorithms and the current blockchainconsensus algorithms are used for solving the problem ofdata inconsistency Of the two types the former are mostlyapplied to private networks or controlled network

environments and most of them are only targeted at dealingwith node network latency or other hardware failureproblems without considering the problem of malicioushacking or attack to the node data

As shown in Table 1 the Raft algorithm does not supportByzantine fault tolerance Besides it strictly restricts theentry and exit of nodes and its network is of constant scaleand poor scalability On the contrary proof algorithms suchas POW and POS need not submit their own conclusions tothe other nodes in the network +ey reach a consensususing proof and other nodes can perform verification Inaddition proof algorithms which are public network-ori-ented possess relatively lower requirements for participantsallow participants to be anonymous support Byzantine faulttolerance and enable the entire network to reach a con-sensus within minutes Nevertheless the POW algorithmmining consumes considerable electricity and it has thedisadvantages of high latency and low throughput For all itslow electricity consumption the POS algorithm has a longrecognition period and low throughput and it is dependenton its own ldquodigital currencyrdquo Although the DPOS algorithmis also less electricity consuming it is more complicatedbecause the concept of entrusted equity is introduced in thealgorithm and the representative node is selected by meansof manual voting +e notes are a low participation degreeso the algorithm is not completely decentralized Although

Request Preprepare Prepare Commit ReplyClient

Note 1

Note 2

Note 3

Note 4

Figure 1 Flowchart of PBFT algorithm

Discover highertenure and leader

Follower Candidate Leader

ReceiveElection

Start

Timer triggerTimeout

retransmissionGreater than the

general vote

Figure 2 Schematic diagram of role transition character transformation in the Raft algorithm

4 Mathematical Problems in Engineering

PBFT supports Byzantine fault tolerance and boasts highthroughput and low latency the nodes in the whole networkare limited Meanwhile its scalability is poor and excessivenodes will lead to a large number of consensus messages andunavailability of the nodes

22 Algorithm Design and Improvement

221 Formal Definition and Analysis A blockchain is es-sentially a state machine driven by transactions and thesystem state (s isin S) is a collection of stored data states Anoperation to change a data state is called a transaction +eyare defined as follows

(i) Transaction state machine a transaction state ma-chine is a quad (T S g δ) in which T means acollection of transactions S means a collection ofstates g isin S means the initial state δ means a statetransition function δ S times T⟶ S +e semantics ofthis transaction state machine are a discrete mi-gration system (S g⟶ ) in which g⟶isin S times S

represents the migration relationship(ii) Transaction log a transaction log called a ledger in

the blockchain is a set of transactions with abstractdata types constructed recursively It is defined asfollows

l Γ Tt( 1113857

l l1 + l21113896 (5)

where Tt isin 2T represents a set of transactionsΓ isin 2T⟶ L is a function for constructing a set oftransaction construction logs L is a collection oflogs times L times L⟶ L represents the merging of twologs into one It is noteworthy that a log usuallyrepresents a set of transactions rather than a datastate In the blockchain all transaction operationsare orderly and dependent Modifying one of thetransactions requires reconstructing a transactionlog which increases the cost of data tamperingMultiple valid log sets can be constructed based onthe received transaction log set but the variation oftransaction order will result in the inconsistentsystem state which is often referred to as ldquodataforkingrdquo

(iii) Data bifurcation let Tt Ttprime1113864 1113865 isin 2T TtsubeTt

prime Ifl Γ(Tt) lprime Γ(Tt

prime) and lle lprime (le represents theprefix relationship) are not satisfied then data

forking occurs between l and lprime According to thesemantics of the transaction state machine if noforking occurs each node will eventually enter thesame state If forking occurs and each node stillenters the same state the case is called pseudo-forking When forking occurs each node needs tochoose one of the many forking chains in accor-dance with the established rule+is established ruleis the consensus algorithm

(iv) Consensus algorithms Φ 2T⟶ L is a functionthat receives a collection of transaction logs andreturns a unique collection of ordered logs thatconform to established rules A good consensusalgorithm should have a high convergence ratewhich can be achieved based on a reduction offorking probability and a strong ability to preventmalicious attacks

Assuming that there are c nodes in the system partici-pating in transaction log production M |L| N

|S| Mi |Li| where Li l|f(l) si si isin S1113864 1113865 then theprobability of pseudoforking occurrence is Pf as shown inthe following equation

Pf 1113936N

i1

Mi

M1113872 1113873

Cminus

1MCminus 1 (6)

As can be seen from equation (6) the optimization of aconsensus algorithm by reducing the probability of pseu-doforking can be achieved in two ways +e first is to changethe structure of transaction log that is to divide theequivalent class of transaction log and construct a logstructure with a low forking probability +e second is toreduce C that is to reduce the probability of forking andpromote the efficiency of consensus by reducing the numberof nodes participating in the consensus +e second way isadopted to improve the existing consensus algorithm in thispaper

222 Algorithm Improvement and Implementation

(1) Improvement of POS and PBFT Algorithm +e study onconsensus algorithms reveals that the POS algorithm notonly spends a long time in reaching an agreement but alsorequires mining operations Even after the transaction isprocessed it still needs a long time to confirm the data untilthe probability enters the acceptable range +e wholeprocess is too time consuming+erefore the POS algorithmis not suitable for scenarios requiring quick feedback ofresults such as distributed storage

Table 1 Comparisons of consensus algorithms

Algorithm Billing right Advantage Disadvantage Representative applicationPOW Competing competition Decentralization High consumption high latency BitcoinPOS Equity competition Low resource consumption Low participation NxtDPOS Equity election High throughput high latency Producer evil EOSPBFT Leader node High throughput high latency Poor scalability FabricRaft Leader node High throughput high latency No Byzantine fault tolerance Etcd

Mathematical Problems in Engineering 5

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 5: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

PBFT supports Byzantine fault tolerance and boasts highthroughput and low latency the nodes in the whole networkare limited Meanwhile its scalability is poor and excessivenodes will lead to a large number of consensus messages andunavailability of the nodes

22 Algorithm Design and Improvement

221 Formal Definition and Analysis A blockchain is es-sentially a state machine driven by transactions and thesystem state (s isin S) is a collection of stored data states Anoperation to change a data state is called a transaction +eyare defined as follows

(i) Transaction state machine a transaction state ma-chine is a quad (T S g δ) in which T means acollection of transactions S means a collection ofstates g isin S means the initial state δ means a statetransition function δ S times T⟶ S +e semantics ofthis transaction state machine are a discrete mi-gration system (S g⟶ ) in which g⟶isin S times S

represents the migration relationship(ii) Transaction log a transaction log called a ledger in

the blockchain is a set of transactions with abstractdata types constructed recursively It is defined asfollows

l Γ Tt( 1113857

l l1 + l21113896 (5)

where Tt isin 2T represents a set of transactionsΓ isin 2T⟶ L is a function for constructing a set oftransaction construction logs L is a collection oflogs times L times L⟶ L represents the merging of twologs into one It is noteworthy that a log usuallyrepresents a set of transactions rather than a datastate In the blockchain all transaction operationsare orderly and dependent Modifying one of thetransactions requires reconstructing a transactionlog which increases the cost of data tamperingMultiple valid log sets can be constructed based onthe received transaction log set but the variation oftransaction order will result in the inconsistentsystem state which is often referred to as ldquodataforkingrdquo

(iii) Data bifurcation let Tt Ttprime1113864 1113865 isin 2T TtsubeTt

prime Ifl Γ(Tt) lprime Γ(Tt

prime) and lle lprime (le represents theprefix relationship) are not satisfied then data

forking occurs between l and lprime According to thesemantics of the transaction state machine if noforking occurs each node will eventually enter thesame state If forking occurs and each node stillenters the same state the case is called pseudo-forking When forking occurs each node needs tochoose one of the many forking chains in accor-dance with the established rule+is established ruleis the consensus algorithm

(iv) Consensus algorithms Φ 2T⟶ L is a functionthat receives a collection of transaction logs andreturns a unique collection of ordered logs thatconform to established rules A good consensusalgorithm should have a high convergence ratewhich can be achieved based on a reduction offorking probability and a strong ability to preventmalicious attacks

Assuming that there are c nodes in the system partici-pating in transaction log production M |L| N

|S| Mi |Li| where Li l|f(l) si si isin S1113864 1113865 then theprobability of pseudoforking occurrence is Pf as shown inthe following equation

Pf 1113936N

i1

Mi

M1113872 1113873

Cminus

1MCminus 1 (6)

As can be seen from equation (6) the optimization of aconsensus algorithm by reducing the probability of pseu-doforking can be achieved in two ways +e first is to changethe structure of transaction log that is to divide theequivalent class of transaction log and construct a logstructure with a low forking probability +e second is toreduce C that is to reduce the probability of forking andpromote the efficiency of consensus by reducing the numberof nodes participating in the consensus +e second way isadopted to improve the existing consensus algorithm in thispaper

222 Algorithm Improvement and Implementation

(1) Improvement of POS and PBFT Algorithm +e study onconsensus algorithms reveals that the POS algorithm notonly spends a long time in reaching an agreement but alsorequires mining operations Even after the transaction isprocessed it still needs a long time to confirm the data untilthe probability enters the acceptable range +e wholeprocess is too time consuming+erefore the POS algorithmis not suitable for scenarios requiring quick feedback ofresults such as distributed storage

Table 1 Comparisons of consensus algorithms

Algorithm Billing right Advantage Disadvantage Representative applicationPOW Competing competition Decentralization High consumption high latency BitcoinPOS Equity competition Low resource consumption Low participation NxtDPOS Equity election High throughput high latency Producer evil EOSPBFT Leader node High throughput high latency Poor scalability FabricRaft Leader node High throughput high latency No Byzantine fault tolerance Etcd

Mathematical Problems in Engineering 5

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 6: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

+e complexity of practical Byzantine messages is O(n2)In a large-scale network consensus messages will occupy alarge number of system resources Meanwhile affected bythe transaction processing speed of nodes and the networklatency the time consumed in the process of reaching aconsensus will be significantly delayed [16] +e time re-quired to reach a consensus under different transactiondelays whenf 1 2 3 33 and n 4 7 10 100 isexhibited in Figure 3 where the ordinate is the time requiredto reach a consensus and the abscissa is the number of nodesparticipating in the consensus It can be seen from Figure 3that the time required to reach a consensus increases withthe growth of the number of nodes

In the PBFT algorithm the greater the number of nodesparticipating in the consensus is the safer the system is butthe longer the delay is [17 18] Although the POS algorithmis strongly expansible without restrictions on network nodesits operation confirmation relies on the confirmation ofsubsequent nodes and there exists a risk of rollback [19 20]+erefore the POS algorithm is improved by integratingadvantages of the PBFT algorithm Specifically the nodesdirectly participating in the Byzantine agreement are con-trolled in a small fixed range +e improvement can not onlyensure low latency and high throughput of the PBFT al-gorithm but also enable fair participation of vast networknodes into the consensus so that the network scale is notlimited by the PBFT algorithm

Equity refers to the proportion of value provided by asingle node in the blockchain network +e specific algo-rithm for calculating the value can be selected in accordancewith the actual scenario and the value can be compre-hensively evaluated from multiple perspectives such aswhether the node is trustable network latency hard disk freespace CPU utilization rate and response latency In theexisting blockchain applications the concept of digitalcurrency is usually introduced to represent the equity for theconvenience of calculation transfer and exchange

ldquoDynamicrdquo is mainly reflected in the following two as-pects (1) all nodes in the whole network can freely join orexit the network that is the number of network nodes can bedynamically expanded or reduced without affecting thesystem consensus dynamic (2) the witness node changesdynamically and is dynamically designated by the POS al-gorithm according to its security interest and whether it is amalicious node

In light of the above ideas the algorithm is optimized+e network nodes are divided into witness nodes andordinary nodes Among them witness nodes are selectedfrom ordinary nodes by the pseudorandom algorithm ofPOS at intervals and are granted the right of witness toinitiate the Byzantine consensus and package the blockOrdinary nodes are responsible for synchronizing andverifying block data and providing storage space but they donot participate in the Byzantine consensus Witness nodesare selected asynchronously +e next round of witnessnodes is selected in advance In other words the switch ofwitness nodes can be completed in a short time withoutwaiting for the asynchronous result of POS +e process ispresented in Figure 4

(2) Implementation of Decentralized Verifiable CryptographicSortition

(1) Selection and witness stages in algorithm based onthe previous planning the algorithm can be dividedinto two stages +e first stage is the ldquosortition stagerdquoin which the POS algorithm selects a group of nodesas witness nodes through the pseudorandom algo-rithm based on node equity +e second stage is theldquowitness stagerdquo (Figure 5) in which the witnessnodes begin to process the received operational datainitiate the consensus and reach an agreement withother witness nodes in accordance with the currentstatus Finally the witness nodes package the blockand synchronize the data to other nodes If a witnessnode fails to reach a consensus due to repeateddowntime timeout inconsistent data etc it will beswitched in advance

(2) Recognition of consensus nodes the algorithmmanages the network nodes through dynamic se-lection so that the number of nodes participating inthe Byzantine consensus remains constant and eachnode owns a fair chance to participate in datapackaging +e improved algorithm still maintainsthe advantages such as low latency and highthroughput of the PBFT algorithm +e result of therequest is returned synchronously but it needs towait for the block confirmation of subsequent nodes

+e key to the algorithm is how to select consensus nodesaccurately and efficiently +e decentralized verifiablecryptographic sortition is used to process this selectionConsensus nodes are randomly selected from many nodesaccording to their weight and the cryptographic sortitionalgorithm [21] randomly selects a subset of nodes accordingto their weight +e nodes participating in the sortition needto have a pair of public-private keys (PK and SK) for provingto other nodes that they have been selected Supposing thatthere is a set of nodes with a weight of wi and the weight ofall nodes in the whole network is W 1113936iwi then theprobability that the node i can be selected is P P wiW

31 33 4245

68

88

115

143165

161168 173

184193

208217 223

229

15

17

19

21

23

25

3

5

7

9

11

13

15

17

4 7 10 16 34 49 54 82 100

Tim

e req

uire

d to

reac

h co

nsen

sus (

ms)

Number of nodes

Delay 075msDelay 5ms

Figure 3 +e time required to reach consensus and the number ofnodes

6 Mathematical Problems in Engineering

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 7: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

+at is to say the weight of a node is proportional to theprobability of its being selected

+e implementation of the cryptographic sortitionalgorithm depends on the verifiable random function[22] Given a value x the holder of the key needs tocalculate the value of the function y Fsk(x) and verifyPsk(x) Each node can be verified by the public keyPK gsk +e algorithm is implemented in the followingsteps

First a pair of public-private keys (PK and SK) isgenerated to calculate random numbers as shown in thefollowing equation

(PK SK) generatekey 1113857( (7)

Next the hashing operation is performed with theprivate key and the result is obtained +e input and outputvalues are represented by x and r respectively For the sameinput value the output result is determined +e proof valuewith the private key is calculated and expressed with pi

r hashVRF(SK x)

pi proveVRF(SK x)1113896 (8)

For verifiable random functions (VRF) anyone candirectly use the proof pi to verify the result and the equationis as follows

r proofVRF(pi) (9)

Common sense node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Ordinary node

Common sense node

Common sense node

Common sense node

POS

Low latency

Strong expansibility

PBHT

Figure 4 Node sortition for participating in the consensus

Initial 1 3 X X2 4 5 M M + 1 N

Block Redraw and start a new phase when consensus fails

Redraw regularly to start the next phase

Round 1 Round 2 Round 3

hellip hellip

Figure 5 Witness the node switching

Mathematical Problems in Engineering 7

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 8: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

Taking r as the condition pi is substituted into equation(9) to obtain

hashVRF(SK x) proofVRF pi proveVRF(SK x)( 1113857

(10)

+e conclusion isTrueFalse

VerifyVRF(PK x pi) (11)

For the sortition algorithm each round of sortitionrequires a random number seed which can be repeatedly andpublicly calculated and can be verified +e seed of randomnumber is obtained according to the random number of theprevious round +at is the random number seed of the rround is determined based on that of the rminus 1 round +eequation of random number seed transfer is shown in thefollowing

langseedr πrang⟵VRFskuseedrminus1 r( 1113857 (12)

In equation (12) π which is selected by u duringrandom number calculation is used for VRF proof Evenif u may be a malicious node the generated seed is still arandom value For r 0 the initial participants use thedistributed random function to generate distributedrandom numbers

(3) Improved Algorithm Flowchart +e process of theimproved algorithm is displayed in Figure 6 At the be-ginning of the program it is initialized into Round 1 andnode sortition is conducted A distributed verifiablerandom function is used to draw lots among ordinarynodes after which the selected nodes are endowed withthe power of witness nodes +en the witness nodes reacha Byzantine consensus and package the transaction into ablock Other witness nodes and ordinary nodes are re-sponsible for verifying the block including transactiondata block data public-private key signature and sorti-tion random number If the block succeeds in passing theverification it will be broadcast to the whole network andthe next block will be verified otherwise it will be sub-jected to timeout detection A fixed timeout limit is set foreach round of consensus If the timeout limit is exceededthe witness node will be reselected through drawing lotsotherwise the witness nodes will try to reach a consensusagain

3 Results and Discussion

In order to verify the improved algorithm the length of eachtransaction is set to 50 bytes after serialization and atransaction is filled with characters if its length is smallerthan 50 bytes When the number of test nodes is large theCPU and network consumption of the computer are rela-tively high and most computer resources are spent onsignature verification To solve this problem the systemadopts a sleep mode testing and verifying the consensusalgorithm from three dimensions throughput latency andscalability

31 8roughput Test Transaction throughput is an impor-tant performance metric for measuring distributed systems[23] +e throughput of a system is usually determined bythe number of concurrent transactions and the number oftransactions per second (TPS) +e time spent on a trans-action is the time consumed from the client request to theresult returned by the server +e overall performance of thesystem depends on the module with the weakest transactionprocessing ability in the system In a distributed system TPSrefers to the number of transactions that the system canhandle in a period

TPSΔtSumΔt

(Transactions)Δt

(13)

where Δt is the time spent on transaction processingSumΔt(Transactions) refers to the total number of trans-actions processed in the Δt period and TPSΔt

refers to thevalue of TPS in the Δt period

Bitcoin and Ethereum are representative projects of thePOW algorithm +erefore in this test the TPS value of thePOW algorithm was obtained by counting block data ofBitcoin and Ethereum Bitcoin and Ethereum nodes were setup to synchronize block data Detailed blockchain infor-mation was obtained and transaction data were countedthrough the RPC interface+e data were counted every dayOn each day the number of newly generated blocks and thenumber of transactions included in each block were cal-culated so was the TPS average +e TPS data in the pastthree months (2019122ndash2019421) are listed in Figure 7where the TPS value of Bitcoin was smaller than 5 andfluctuated between 22 and 465 while that of Ethereumfluctuated between 5 and 9

Nxt is the representative application of the POS algo-rithm [24] +e Nxt node test network was built for ac-quiring the number of transactions in the block and in eachblockchain every day based on which TPS was calculated+e TPS data in the past three months (2019122ndash2019421)are listed in Figure 8 where the TPS value of Nxt fluctuatedbetween 30 and 70

Due to the differences among the consensus algorithmsthe intervals between blocks differ notably To acquire moreaccurate test data the total number of transactions and theTPS value were counted with 1 minute taken as the testinterval and 60 minutes taken as a cycle +e transactionconstruction client was implemented in which eachtransaction was filled with 50 bytes and sent to the servicenode at the speed of 3000 TPS During the test the clientneed not pay attention to whether the transaction wassuccessful After the test the TPS value was uniformlycounted and calculated based on the block data +e Raftalgorithm the PBFTalgorithm and the improved algorithmwere subjected to the test +e test results are disclosed inFigure 9

As shown in Figure 9 the TPS of the Raft algorithmfluctuated between 1500 and 2000 that of the PBFT algo-rithm oscillated with large amplitudes between 700 and1500 and that of the improved algorithm oscillated withsmall amplitudes between 1100 and 1400 +e comparison

8 Mathematical Problems in Engineering

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 9: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

among the three algorithms reveals that the Raft algorithmhas larger TPS values than the other two as it is notcharacterized by Byzantine fault tolerance Nevertheless itcan achieve higher performance because leader nodes existwhile other nodes synchronize data as redundant nodeswithout causing network consensus costs in its runningprocess +e comparison between the PBFT algorithm andthe improved algorithm suggests that the average TPS valuesof the two just differ slightly but the TPS oscillation am-plitude of the latter is much smaller than that of the formerIt can be known through analysis that during the running ofthe PBFT algorithm the online or downline of nodes sig-nificantly affects the consensus which is likely to lead tonetwork latency or consensus failure

+e TPS values of various algorithms are presented inFigure 10 for comparison +e Raft algorithm has high

performance but it does not support Byzantine fault tol-erance +e PBFT algorithm and the improved algorithmare comparable in terms of performance but the latterboasts a smaller TPS fluctuation range and is more stable

32 Scalability Test Scalability divided into horizontal ex-pansion and vertical expansion is critical to a distributedsystem [25] Horizontal expansion refers to promoting theoverall performance of the system by adding the number ofmachines Its bottleneck lies in the limitation of multi-machine management Vertical expansion refers to en-hancing the overall performance of the system by improvingthe performance of a single machine Its bottleneck is thatthere is an upper limit on the performance of a singlemachine Since distributed systems are usually composed of

Start

Round 1T = 1

Next round drawT++

TimeoutDraw lots to select

witness nodes

Not timed outTimeoutverification

Byzantine consensus

Packingblock

Verification failed Blockverification

Success

Link and broadcsatblocks

Node data verification

Figure 6 Algorithm flowchart

Mathematical Problems in Engineering 9

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 10: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

2

3

4

5

6

7

8

9

10

TPS

Date

BitcoinEthereum

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 7 TPS comparison between Ethereum and Bitcoin

700

900

1100

1300

1500

1700

1900

2100

1 6 11 16 21 26 31 36 41 46 51 56

TPS

Number of nodes

Improved algorithmPBFTRaft

Figure 9 PBFT Raft and improved algorithm TPS comparison

25

35

45

55

65

75

TPS

122

201

9

129

201

9

25

2019

212

201

9

219

201

9

226

201

9

35

2019

312

201

9

319

201

9

326

201

9

42

2019

49

2019

416

201

9

Figure 8 TPS value of Nxt

10 Mathematical Problems in Engineering

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 11: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

inexpensive and efficient nodes horizontal expansion isgenerally adopted to promote system performance

Excellent scalability enables a system to make dynamicadjustment according to the current task status When thesystem is under a high load it can raise the processingcapacity by increasing the number of nodes When thesystem is under a low load it can improve the utilization byreducing the number of nodesWhether a distributed systempossesses strong scalability depends on whether the con-sensus algorithm supports the dynamic joining or exiting ofnodes

In the scalability test the influence of the increase ordecrease in node dynamics during the operation of theconsensus algorithm was evaluated by measuring TPS Justas the throughput test the client still sent the transactionfilled with 50 bytes at the speed of 3000 TPS +e differencelies in that during this test the number of network nodescontinuously increased by the timed script and the TPSunder the current number of nodes was counted and cal-culated in the unit of 1 minute Meanwhile the transactionprocessing performance of the system under differentnumbers of nodes was analyzed +e POW algorithm thePBFT algorithm the POS algorithm and the improved al-gorithm were subjected to this test

As shown in Figure 11 the performance of the PBFTalgorithm decreases significantly as the number of nodesincreases +e TPS values of the PBFT algorithm are about1200 and 218 when there are 4 nodes and 100 nodes in thesystem respectively which means that the performanceunder 100 nodes is nearly 7 times as high as that under 4nodes +e performances of the POW algorithm the POSalgorithm and the improved algorithm are relatively stable+e increase in the number of nodes does not greatly affectthe performances of the consensus algorithms It is con-cluded that the PBFT algorithm has poor scalability whilethe other three algorithms have strong scalability

33 Latency Test Latency is an important indicator forevaluating the performance of a distributed system andmeasuring communication delays and algorithm delaysbetween nodes in a distributed system [26 27] A systemwith low latency is able to quickly send back the transactionprocessing result and achieve good user experience while

one with high latency is unable to send back the transactionresult processing in time (the result can only be obtainedasynchronously) or achieve good user experience As shownin equation (14) latency of a distributed system usuallyconsists of three parts the time required for the transactionrequest data to be transmitted in the network (TRequest) thetime required for the witness nodes to reach a consensus(TConsensus) and the time required for the processing result toreturn (TResponse)

DelayTransaction TRequest + TConsensus + TResponse (14)

For the purpose of accurately measuring the consensustime transaction requests are randomly sent to differentnodes and broadcast over the whole network +e client endrecords the timestamp at two moments when it receives arequest and after receiving the feedback +e latency forprocessing a transaction can be obtained by calculating thedifference between the two timestamps

For the POW algorithm and the POS algorithm thelatency is limited by the program rules For example theblock-producing times of bitcoin Ethereum and Nxt pro-gram are regulated to be about 10 minutes 2 minutes and 1minute which means that it takes an average waiting time of5 minutes 1 minute and 30 seconds for a transaction to besuccessfully written to the blockchain respectively It can beseen that the two algorithms both have long and uncertainlatencies ranging from seconds to minutes

In this test the latencies of the PBFT algorithm and theimproved algorithm were calculated and counted in the unitof 1000 transactions +e client end constructs 50 byte-longtransactions which were then sent to the service nodes atrandom time intervals Finally the average transactionprocessing latencies were obtained according to the resultsas exhibited in Figure 12

It can be observed from Figure 12 that the PBFT algo-rithm has a low transaction processing latency when there

6 5076

112256 118527

169459

0

300

600

900

1200

1500

1800

PoW PoS PBFT Improvedalgorithm

Raft

TPS

Figure 10 TPS under different consensus algorithms 1

10

100

1000

10000

4 7 10 16 34 49 54 100

TPS

Number of nodes

PoW (Ethereum)PBFTImproved algorithmPoS

Figure 11 Influence of the number of nodes on the TPS

Mathematical Problems in Engineering 11

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 12: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

are 4 nodes in the system but its latency increases as thenumber of nodes grows In contrast the transaction pro-cessing latency of the improved algorithm is more stablewithout varying greatly as the number of nodes grows be-cause its number of witness nodes remains constant at 4 inthis test

In short the POW algorithm and the POS algorithmhave long and uncertain latencies while the PBFTalgorithmand the improved algorithm have shorter latencies Besidescompared with the PBFT algorithm the transaction pro-cessing latency of the improved algorithm is less affected bythe number of nodes

4 Conclusions

With the continuous development of blockchain technologyconsensus algorithms have gradually become a new researchhotspot +e pros and cons of a consensus algorithm directlyaffect the performance and function of the blockchain A goodconsensus algorithm should feature good scalability low la-tency high throughput and decentralization Based on theexisting consensus algorithm an improved hybrid consensusalgorithm based on the PBFTalgorithm and the POS algorithmis proposed in this work It dynamically selects the consensusnode in the form of verifiable cryptographic sortition which notonly allows a large number of nodes to participate in theconsensus fairly but also ensures the low latency and highthroughput of the consensus algorithm In the future we willcontinue to study the blockchain consensus algorithm andimprove the consensus algorithm in light of the idea of reducingblock forking +rough the improvement and optimization ofthe blockchain ledger structure the ledger will be reconstructedin the form of a directed acyclic graph to avoid the performanceloss caused by the ledger forking In this way the performanceof the blockchain consensus algorithm can be improved

Data Availability

+e coding data used to support the findings of this study areavailable from the corresponding author upon request

Conflicts of Interest

+e authors declare that there are no conflicts of interestregarding the publication of this paper

Acknowledgments

+anks are due to Dr Wei Zhao in China University ofMining and Technology (Beijing) for the useful commentson the manuscript preparation +is research was funded bythe National Natural Science Foundation of China (Grantno 51874314) and Fundamental Research Funds for theCentral Universities (Grant no 2011YJ15)

References

[1] C Pop T Cioara M Antal I Anghel I Salomie andM Bertoncini ldquoBlockchain based decentralized managementof demand response programs in smart energy gridsrdquo Sensorsvol 18 no 2 p 162 2018

[2] Z Zheng S Xie H N Dai X Chen and H WangldquoBlockchain challenges and opportunities a surveyrdquo Inter-national Journal of Web and Grid Services vol 14 no 4pp 352ndash375 2018

[3] M Andoni V Robu D Flynn et al ldquoBlockchain technologyin the energy sector a systematic review of challenges andopportunitiesrdquo Renewable and Sustainable Energy Reviewsvol 100 pp 143ndash174 2019

[4] M B Hoy ldquoAn introduction to the blockchain and its im-plications for libraries and medicinerdquo Medical ReferenceServices Quarterly vol 36 no 3 pp 273ndash279 2017

[5] W Zhao Y Cheng Z Pan K Wang and S Liu ldquoGas dif-fusion in coal particles a review of mathematical models andtheir applicationsrdquo Fuel vol 252 pp 77ndash100 2019

[6] D Larimer ldquoDelegated proof-of-stake (Dpos)rdquo 2014 httpsbitcointalkorgindexphptopic=5583160

[7] G Wood ldquoPolkadot vision for a heterogeneous multi-chainframeworkrdquo 2016 httpspolkadotnetworkPolkaDotPaperpdf

[8] A Juels and B S Kaliski Jr ldquoPORs proofs of retrievability forlarge filesrdquo in Proceedings of the 14th ACM Conference onComputer and Communications Security pp 584ndash597Alexandria VA USA November 2007

[9] M Castro and B Liskov ldquoPractical Byzantine fault tolerancerdquoOSDI vol 99 pp 173ndash186 1999

[10] G Bracha and S Toueg ldquoAsynchronous consensus andbroadcast protocolsrdquo Journal of the ACM (JACM) vol 32no 4 pp 824ndash840 1985

[11] M Jakobsson and A Juels ldquoProofs of work and bread puddingprotocols (extended abstract)rdquo in Secure Information Net-works IFIP-8e International Federation for InformationProcessing Preneel B ed vol 23 pp 258ndash272 SpringerBoston MA USA 1999

[12] R Bohme N Christin B Edelman and T Moore ldquoBitcoineconomics technology and governancerdquo Journal of EconomicPerspectives vol 29 no 2 pp 213ndash238 2015

[13] WorldDatainfo Energy Consumption in Colombia httpswwwworlddatainfoamericacolombiaenergy-consumptionphp

[14] S King and S Nadal ldquoPpcoin peer-to-peer crypto-currencywith proof-of-stakerdquo 2012 httpsdecredorgresearchking2012pdf

[15] J Chiefari Y K Chong F Ercole et al ldquoLiving Free-RadicalPolymerization by Reversible AdditionminusFragmentation Chain

27

3342 45

68

88

115

143

165

3332 33 34 36 33 32 33 312

4

6

8

10

12

14

16

4 7 10 16 34 49 54 82 100

Tran

sact

ion

laten

cy (m

s)

Number of nodes

PBFTImproved algorithm

Figure 12 Impact of different number of nodes on transactionlatency

12 Mathematical Problems in Engineering

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13

Page 13: HybridConsensusAlgorithmOptimization:AMathematical ...same state. If forking occurs and each node still enters the same state, the case is called pseudo-forking.Whenforkingoccurs,eachnodeneedsto

Transfer +e RAFT ProcessrdquoMacromolecules vol 31 no 16pp 5559ndash5562 1998

[16] H Sukhwani J M Martınez X Chang et al ldquoPerformancemodeling of Pbft consensus process for permissionedblockchain network (hyperledger fabric)rdquo in Proceedings ofthe 2017 IEEE 36th Symposium on Reliable Distributed Systems(SRDS) pp 253ndash255 Hong Kong China September 2017

[17] Y Yuan X Ni S Zeng and F Wang ldquoBlochchain consensusalgorithms the State of the art and future trendsrdquo ActaAutomatica Sinica vol 44 no 11 pp 2011ndash2022 2018

[18] C Cachin S Schubert andM Vukolic ldquoNon-determinism inbyzantine fault-tolerant replicationrdquo 2016 httpsarxivorgabs160307351

[19] Y Gilad R Hemo S Micali et al ldquoAlgorand scaling byz-antine agreements for cryptocurrenciesrdquo in Proceedings of the26th Symposium on Operating Systems Principles pp 51ndash68ACM Shanghai China October 2017

[20] J Kwon ldquoTendermint consensus without mining draft V03rdquo 2014 httpdigitalslabbuaaeducn__localC8D68C0A97F7766C07EBAE618D8CF318_304F91EF_AAD6Fpdf

[21] S Micali M Rabin and S Vadhan ldquoVerifiable randomfunctionsrdquo in Proceedings of the 40th Annual Symposium onFoundations of Computer Science pp 120ndash130 IEEE NewYork City NY USA October 1999

[22] Y Dodis ldquoEfficient construction of (distributed) verifiablerandom functionsrdquo in Proceedings of the InternationalWorkshop on 8eory amp Practice in Public Key CryptographyMiami FL USA January 2003

[23] G F Coulouri D Jean and K Tim Distributed SystemConcept and Design Pearson Education London UK 2004

[24] S Popov ldquoA probabilistic analysis of the nxt forging algo-rithmrdquo Ledger vol 1 pp 69ndash83 2016

[25] F Xu G Yang and D Ju ldquoDsign of distributed storage systemon peer-to-peer structurerdquo Journal of Software vol 15 no 2pp 268ndash277 2004

[26] X Qin Z Han and L Pang ldquoReal-Time scheduling withfault-tolerance in heterogeneous distributed systemsrdquo Chi-nese Journal of Computers vol 1 pp 49ndash56 2002

[27] A Panarello N Tapas G Merlino F Longo and A PuliafitoldquoBlockchain and iot integration a systematic surveyrdquo Sensorsvol 18 no 8 p 2575 2018

Mathematical Problems in Engineering 13


Recommended