Improved PBFT consensus method based on consensus participation and transaction activity
Technical Field
The invention belongs to the technical field of block chains, consensus mechanisms and PBFT (basic packet data transfer) application, and particularly relates to an improved PBFT consensus method based on consensus participation and transaction activity.
Background
The block chain technology concept is put forward for the first time in 2008, the block chain adopts various technologies in the fields of cryptography, computers and communication, and asymmetric encryption, time stamps, a common recognition mechanism and point-to-point communication are used, so that the problems of low efficiency, high cost and monopoly of data ownership of the existing centralized credit organization are solved, and the block chain is essentially a distributed system and has the characteristics of decentralization and safe credibility. The blockchain technology is considered as a new information technology development direction after the mobile internet, and the establishment of a credit society is promoted, so that the current information internet is converted into a value internet.
As blockchain technology continues to develop, consensus algorithms are also increasingly highlighted by researchers, where how to select consensus algorithms is a core part of blockchain design. The consensus algorithm is the most core technology of the block chain, which affects the performance of the block chain system, and the current consensus algorithm can be divided into three categories, namely public chain consensus, private chain consensus and alliance chain consensus according to the type of the block chain. Research on consensus algorithms has been started for a long time, such as Proof of Work (POW), Proof of rights of interest (POS), the practical byzantine fault-tolerant algorithm PBFT, which is the most widely applied league chain consensus mechanism, and the Raft algorithm.
The PBFT algorithm aims at solving the problem of how to ensure the consistency and the correctness of final decision under the condition that malicious nodes exist in the whole system, the algorithm is based on state machine copy replication, each state machine copy can store service states, legal requests of users are met, not only can transactions be completed, but also different types of operations can be realized, and the algorithm can carry out consensus on transmitted messages to obtain a global sequence. In the case that the malicious nodes are not higher than the total number 1/3, the algorithm can simultaneously guarantee the safety and the activity, and the algorithm reduces the complexity of the Byzantine fault-tolerant algorithm from an exponential level to a polynomial level O (N) for the first time2). All nodes in the PBFT algorithm are divided into three types, namely a client, a main node and a replica node, the process is divided into a consistency protocol, a view change protocol and a checkpoint protocol, wherein the consistency protocol is divided into three stages: a PRE-preparation phase (PRE-PREPARE), a preparation phase (PREPARE), and an acknowledgement phase (COMMIT).
The election mode of the main nodes in the PBFT algorithm is that the main nodes are sequentially taken as the main nodes in turn according to numbers, the election mode of the main nodes is random, the authenticity of the main nodes is not verified after the main nodes are successfully elected, the elected main nodes are probably malicious nodes and have certain potential safety hazards, although the maliciousness of the main nodes is possibly identified by the slave nodes and overturned through view change in the subsequent consensus process, certain loss can still be caused, if the continuously selected main nodes are all malicious nodes, frequent view change can also increase system overhead, system efficiency is reduced, and great waste of system resources can be caused and system safety is reduced. The PBFT has no penalty mechanism for the malicious master node, only the view is switched to change the master node, and the Byzantine node still stays in the network, so the improvement is needed in the practical application of the block chain, and in addition, the high-intensity network communication and network transmission overhead in the three-stage negotiation of the PBFT consistency protocol also needs to be further improved and optimized.
Accordingly, in view of the above problems, the present invention provides an improved PBFT consensus method based on consensus participation and transaction liveness.
Disclosure of Invention
The purpose of the invention is as follows: the invention aims to provide an improved PBFT consensus method based on consensus participation and transaction activity, which optimizes a view switching mechanism of a PBFT algorithm and enhances the randomness and the safety of master node election so as to enhance the capability of resisting malicious node attacks, and optimizes message transmission in the running process of a consistency protocol based on the credibility value of the master node election so as to reduce message complexity and network overhead.
The technical scheme is as follows: the invention provides an improved PBFT consensus method based on consensus participation and transaction activity, which comprises the following steps of 1, initializing nodes, numbering the nodes in a network by N integers of { 0, 1, 2, …, | N | -1}, and initializing the credibility values of the nodes to 0 point. And 2, the client sends a transaction request to the main node, the main node numbers the request message after receiving the request, and the traditional PBFT protocol is operated at the starting stage of the block chain network until the main node is switched for the first time. And 3, running the optimized view switching protocol to select the main node. And 4, processing the client request based on the optimized view switching protocol and the optimized consistency consensus protocol.
In the technical scheme, the step 3 includes a view switching time point, a view switching reference window W and a master node selection mechanism, wherein an algorithm of the view switching time point triggers view switching except for exception of the master node, and in the context of application that a node can dynamically join a quitted block chain, in order to avoid excessive centralization of blocks and maintain certain random security, an attempt switching protocol is run once every time period T; the method comprises the steps that a reference window W is switched in a view, the reliability value is a result obtained by accumulation after a plurality of rounds of consensus processes, in order to give consideration to new nodes, fairness is enhanced, meanwhile, the node reliability should reflect the latest state of the nodes, the influence of historical liveness on the current state is reduced, a window period W is set, W = nT, n is an integer, and the reliability is calculated according to the behavior of the nodes in the window period W; the main node selection mechanism has the advantages that the credibility is an important index for measuring the integrity of the nodes, when the view switching and the main node selection are carried out, a cryptographic lottery algorithm with weighted probability is adopted, the rights and interests of the nodes are the credibility of the nodes, the higher the credibility is, the higher the probability of selection is, so that the occurrence of malicious nodes and fault nodes selection can be reduced, and the occurrence of failure in the consensus process is reduced.
In the technical scheme, the consensus participation degree, the transaction activity, the reliability of the nodes and the two-layer block link structure in the step 3 are calculated by the following method, wherein the duplicate nodes participate in the primary block in the system to generate the consensus plus 1 point, and when the duplicate nodes generate the byzantine errors such as downtime and inconsistency with the final consensus result, the missed-recording blocks, the voting errors, the abnormal-recording blocks and the like, the total mark participation value is 1 point; the node serving as a main node successfully packs the blocks and completes one-time block generation consensus, and the consensus takes part in the score of 3; when the block cannot be generated successfully, if the copied node suspects to be a malicious node, the view conversion is triggered to be deducted for 5 points, and other situations, such as node downtime, communication unsmooth, long delay, block failure and the like, are deducted for 3 points; transaction activity, wherein the transaction activity value A is the number of transactions participated by the node; the credibility value R is obtained by weighted addition calculation according to the consensus participation value and the transaction active value, and the calculation method of the credibility value R is as follows: r = k a + (1-k) P (0< k < 1); the PBFT three-stage communication consensus process is required to be executed to ensure that the block chain network forms a consistent result when the credibility calculation is executed each time; the main Block (Key Block) is used for recording the identity and the credibility value of the nodes participating in consensus, and the result of the nodes trying to switch protocols when the consensus nodes operate to obtain the main node, and the Micro Block (Micro Block) is a Block for recording the consensus nodes operating the consensus protocol packaging transaction.
In step 4, the optimized consistency protocol execution process is as follows: (1) client send request (request): the customer service end sends a REQUEST message to the main node in the format of REQUEST, o, t, c, as in the REQUEST phase of the PBFT algorithm, wherein o is a REQUEST execution state machine, t is a time stamp, and c represents the number of the client; (2) a PRE-preparation stage (PRE-preparation) of an optimized consistency protocol, wherein a main node generates a PRE-preparation message after receiving a request sent by a client and broadcasts the PRE-preparation message to all consensus nodes, and the message format is as follows < < PRE-PREPARE, v, n, d, g, >, r, m >, wherein r is the credibility value of the nodes and g is the result of hash calculation performed on r; (3) optimized coherence protocol preparation phase (prepare): the replica node will generate a preparation message for the feedback, and sends the message to the master node, the message format is < PREPARE, v, n, d, i >, i is the node number, meanwhile, the nodes write the pre-preparation message and the preparation message into the log file, the main node receives the messages of all the replica nodes, and finds out the PRE-preparation message < < PRE-PREPARE, v, n, d, g >, r, m > stored locally according to the v and n values of the prefix message for comparison, judges whether the values corresponding to the field d are the same or not, once the transaction information is tampered, if the Hash value d of the node is changed, the master node ends the execution of the consensus and sends a termination message to each node, wherein the message comprises the inconsistent node number of the message, and a PBFT traditional consistency protocol is restarted once to finish the consensus; (4) and a consistency protocol optimization confirmation phase (COMMIT), wherein the master node receives feedback information of the preparation phase sent by all the consensus copy nodes, and under the condition that all the feedback information are completely the same, the master node generates a confirmation message and broadcasts the confirmation message to all nodes in the network, the message format is < COMMIT, v, n, d, a >, wherein a is determined addition information and indicates that the master node confirms addition, after all the nodes receive the confirmation message, the secondary transaction information is added into a local memory, the messages of all the copy nodes receive submission (COMMIT) information of the master node, and find out locally stored PRE-preparation messages < < PRE-PARE, v, n, d, g >, r, m > according to the v and n values of the COMMIT message, compare, judge whether the value corresponding to the field d is the same, and once the transaction information is tampered, its Hash value d must change, the replica node will attempt to initiate a view switch.
In the technical scheme, after a new master node election protocol is executed in the step 4, the running consensus protocol is determined according to the reliability value of the master node in election, a threshold value TV is preset by the system, and if the master node reliability value R > = TV, the optimized consistency consensus protocol is run; if the master node trustworthiness value R < TV, the conventional three-stage PBFT consensus process is still running.
In the technical solution, the consistency protocol of the consensus algorithm in step 4 needs to complete two times of node communication with complexity o (n) in the operation process.
Compared with the prior art, the improved PBFT consensus method based on the consensus participation degree and the transaction activity degree has the beneficial effects that: 1. the randomness safety of the master node election is enhanced, and the attack of malicious nodes is effectively resisted; 2. the complexity of node communication is simplified according to the credibility of the main node, and the communication responsibility is simplified; 3. the window period is set, so that the fairness of the honest nodes participating in the consensus process is improved; 4. and taking the node transaction activity as the node rights and interests, and exciting the active nodes to maintain the safety and stability of the block chain network.
Drawings
FIG. 1 is a schematic diagram of a workflow structure of an improved PBFT consensus method based on consensus participation and transaction activity according to the present invention;
FIG. 2 is a block chain structure diagram of an improved PBFT consensus method based on consensus participation and transaction activity according to the present invention;
FIG. 3 is a schematic diagram of an optimized consensus protocol execution process for an improved PBFT consensus method based on consensus participation and transaction activity.
Detailed Description
The invention is further elucidated with reference to the drawings and the embodiments.
Examples
The improved PBFT consensus method based on the consensus participation degree and the transaction activity degree as shown in the figure 1, the figure 2 and the figure 3 comprises the following steps of 1, carrying out initialization work on nodes, numbering the nodes in the network by N integers of { 0, 1, 2, …, | N | -1}, and initializing the credibility value of the nodes to 0 point. And 2, the client sends a transaction request to the main node, the main node numbers the request message after receiving the request, and the traditional PBFT protocol is operated at the starting stage of the block chain network until the main node is switched for the first time. And 3, running the optimized view switching protocol to select the main node. And 4, processing the client request based on the optimized view switching protocol and the optimized consistency consensus protocol.
Further preferably, the step 3 includes a view switching time point, a view switching reference window W, and a master node selection mechanism, where an algorithm of the view switching time point triggers view switching except that the master node is abnormal, and in the context of a blockchain application that a node may dynamically join in to exit, in order to avoid generating excessive centralization of a block and maintaining a certain random security, a protocol trying to switch is run once every time period T; the method comprises the steps that a reference window W is switched in a view, the reliability value is a result obtained by accumulation after a plurality of rounds of consensus processes, in order to give consideration to new nodes, fairness is enhanced, meanwhile, the node reliability should reflect the latest state of the nodes, the influence of historical liveness on the current state is reduced, a window period W is set, W = nT, n is an integer, and the reliability is calculated according to the behavior of the nodes in the window period W; the main node selection mechanism has the advantages that the credibility is an important index for measuring the integrity of the nodes, when the view switching and the main node selection are carried out, a cryptographic lottery algorithm with weighted probability is adopted, the rights and interests of the nodes are the credibility of the nodes, the higher the credibility is, the higher the probability of selection is, so that the occurrence of malicious nodes and fault nodes selection can be reduced, and the occurrence of failure in the consensus process is reduced.
Further preferably, in the step 3, the common recognition participation, the transaction activity, the credibility, and the block chain structure of two layers are: the method for calculating the consensus participation value P comprises the following steps that the copy node participates in a primary block in the system to generate consensus plus 1 point, and when a Byzantine error such as downtime occurs in the copy node and is inconsistent with a final consensus result, the 1 point is deducted by a missed-recording block, a voting error, an abnormal-recording block and the like; the node serving as a main node successfully packs the blocks and completes one-time block generation consensus, and the activity integral is added for 3 minutes in the cycle of consensus; when the block cannot be generated successfully, if the copied node suspects to be a malicious node, the view conversion is triggered to be deducted for 5 points, and other situations, such as node downtime, communication unsmooth, long delay, block failure and the like, are deducted for 3 points; transaction activity, wherein the transaction activity value A is the number of transactions participated by the node; the credibility of the node is calculated by weighted addition of the consensus participation value and the transaction active value, and the calculation method of the credibility value R is as follows: r = k a + (1-k) P (0< k < 1); the PBFT three-stage communication consensus process is required to be executed to ensure that the block chain network forms a consistent result when the credibility calculation is executed each time; as shown in fig. 2, a new Block chain structure is shown, where a main Block (Key Block) is used to record identities and reliability values of nodes participating in consensus, results of nodes trying to switch protocols when the consensus nodes operate to obtain the main node, and a Micro Block (Micro Block) is used to record a Block where the consensus nodes operate a consensus protocol packed transaction.
Further preferably, in step 4, the optimized consistency protocol is executed as follows: (1) client send request (request): the customer service end sends a REQUEST message to the main node in the format of REQUEST, o, t, c, as in the REQUEST phase of the PBFT algorithm, wherein o is a REQUEST execution state machine, t is a time stamp, and c represents the number of the client; (2) a PRE-preparation stage (PRE-preparation) of an optimized consistency protocol, wherein a main node generates a PRE-preparation message after receiving a request sent by a client and broadcasts the PRE-preparation message to all consensus nodes, and the message format is as follows < < PRE-PREPARE, v, n, d, g, >, r, m >, wherein r is the credibility value of the nodes and g is the result of hash calculation performed on r; (3) optimized coherence protocol preparation phase (prepare): the replica node will generate a preparation message for the feedback, and sends the message to the master node, the message format is < PREPARE, v, n, d, i >, i is the node number, meanwhile, the nodes write the pre-preparation message and the preparation message into the log file, the main node receives the messages of all the replica nodes, and finds out the PRE-preparation message < < PRE-PREPARE, v, n, d, g >, r, m > stored locally according to the v and n values of the prefix message for comparison, judges whether the values corresponding to the field d are the same or not, once the transaction information is tampered, if the Hash value d of the node is changed, the master node ends the execution of the consensus and sends a termination message to each node, wherein the message comprises the inconsistent node number of the message, and a PBFT traditional consistency protocol is restarted once to finish the consensus; (4) and a consistency protocol optimization confirmation phase (COMMIT), wherein the master node receives feedback information of the preparation phase sent by all the consensus copy nodes, and under the condition that all the feedback information are completely the same, the master node generates a confirmation message and broadcasts the confirmation message to all nodes in the network, the message format is < COMMIT, v, n, d, a >, wherein a is determined addition information and indicates that the master node confirms addition, after all the nodes receive the confirmation message, the secondary transaction information is added into a local memory, the messages of all the copy nodes receive submission (COMMIT) information of the master node, and find out locally stored PRE-preparation messages < < PRE-PARE, v, n, d, g >, r, m > according to the v and n values of the COMMIT message, compare, judge whether the value corresponding to the field d is the same, and once the transaction information is tampered, its Hash value d must change, the replica node will attempt to initiate a view switch.
Further preferably, in step 4, after the new master node election protocol is executed, the operated consensus protocol is determined according to the reliability value of the master node in the election, the system presets a threshold value TV, and if the master node reliability value R > = TV, the optimized consensus protocol is operated; if the master node trustworthiness value R < TV, the conventional three-stage PBFT consensus process is still running.
Further preferably, the consistency protocol of the consensus algorithm in step 4 needs to complete two times of node communication with complexity o (n) during the operation process. The design of the algorithm ensures that the algorithm can still finish consensus under the condition that Byzantine nodes exist in the network; the reliability of the nodes is quantized and applied to view switching, if the reliability of the nodes selected to be the main node in the view switching is high, the copy nodes do not need to broadcast messages to other copy nodes in the period of prefix and commit, a PBFT consistency protocol is optimized, and an algorithm can achieve consensus after the communication of the nodes with the complexity of O (n) is completed.
The invention discloses an improved PBFT consensus method based on consensus participation and transaction activity, which applies credibility to a view switching process as a method for randomly generating a main node by node interest weighting, and selects different consistency protocols to operate according to the credibility of the main node, thereby further reducing the message complexity of the consensus process.
The invention discloses an improved PBFT consensus method based on consensus participation and transaction activity, which is an open PBFT consensus protocol based on which nodes can join and quit.
The difference between the improved PBFT consensus method based on the consensus participation degree and the transaction activity degree and the traditional technology is as follows: 1. adding the transaction activity of the node into the evaluation of the node credit, and further exciting the node to improve the stability to participate in the block chain consensus process in an honest way; 2. the grouping method according to the node credibility value or the credibility value is not adopted, so that the complicated operation of the grouping method is avoided, the nodes can participate in the processes of main node election and consensus, and certain node participation and decentralization are ensured; 3. the probability of the node becoming a main node is determined according to the reliability of the node, so that the node with high honesty and reliability can be ensured to play a larger role in consensus to maintain the stability of the block chain network; 4. and the consistency process is optimized according to the credibility value of the main node, so that the safety is ensured, and the network overhead and pressure are reduced.
The foregoing is only a preferred embodiment of this invention and it should be noted that modifications can be made by those skilled in the art without departing from the principle of the invention and these modifications should also be considered as the protection scope of the invention.