Weight-incentive-based alliance chain consensus method and system for main node election
Technical Field
The invention relates to the technical field of block chain consensus, in particular to a method and a system for block chain consensus based on weight incentive main node election.
Background
In the block chain technique, the consensus algorithm is an integral part of one of the cores. A federation chain refers to a blockchain in which several enterprises are jointly involved in management, each enterprise operating one or more nodes, wherein data only allows different enterprises in the system to read, write, and send transactions, and jointly records transaction data. Also referred to as "shared authenticated blockchains," in conventional federation chain blockchains, a PBFT (pragmatine fault tolerant) consensus algorithm or a variant PBFT consensus algorithm is typically employed to achieve consistent storage of data on the blockchain.
The traditional PBFT consensus algorithm operates by a state machine, including node states and message states, a main node leads other nodes to process messages in a unified and synchronous mode, whether the messages continuously migrate to the next state or not is judged, the nodes reach the same agreement, and finally the messages reach the processed state, which is totally divided into 5 stages: the method comprises the following steps that firstly, in a Request stage, a client sends a transaction uplink Request to a main node, the Request comprises transaction content, a transaction summary and a message signature, then the Pre-preamble stage is entered, the main node receives the transaction uplink Request of the client, the main node verifies whether the signature of the client Request message is correct, when no problem is verified, the Pre-preamble message is broadcasted to other auxiliary nodes, then the Pre-preamble stage is entered, the auxiliary nodes receive the Pre-preamble message of the main node, and the following verification is carried out: if the master node and the slave node receive the Commit message and check that 2f +1 Premate messages (f represents the number of malicious nodes) successfully, broadcasting the Commit message to other common node, and finally entering a Reply stage, if the master node and the slave node receive the Commit message and check that the Commit message signature is correct, operating the request operation of the client and returning the Commit message to the client.
Compared with the conventional PBFT consensus algorithm, on 18 th 6 th 2021, chinese patent publication No. CN112991066A discloses a consensus method, apparatus, and electronic device in a federation chain, which improves the conventional PBFT consensus algorithm, and proposes to add a broadcast stage between Request and Pre-prefix, so that a client can send a transaction uplink Request to any block chain consensus node, and then broadcast the transaction to all consensus nodes in the block chain by the node receiving the Request, and after receiving the broadcast message, the master node executes subsequent Pre-prefix, Commit, and Reply stages to avoid the occurrence of a situation where block chain consensus cannot be completed when the client and the master node have no network connection or the master node is a malicious node, and other stages are consistent with the conventional PBFT consensus algorithm, but the highest TPS (system throughput capacity) of the block chain system of the PBFT consensus algorithm is reached, the number of system processing per second) is generally more than 10000TPS, and as the number of consensus nodes increases, the highest TPS is attenuated in polynomial level, and at this time, the scheme may cause a problem that the block chain consensus efficiency is low and it is difficult to support normal operation of a service requiring high TPS. In the stage of Prepare and Commit, each consensus node performs summary calculation and message broadcasting, and the message complexity is O (n)2). When the number of the consensus nodes in the network increases, all the consensus nodes need to perform two-stage summary calculation and message broadcasting operation, so that the performance of the traditional PBFT consensus algorithm is rapidly reduced along with the increase of the number of the consensus nodes. When the federation chain performance degrades to a certain degree, it may cause the service running on that federation chain to be interrupted.
In addition, conventional PBFT consensus algorithms require periodic master node replacement, or replacement of the master node in the event of master node corruption. The master node replacement operation is calculated by a formula p ═ v MOD R (p is the master node number, v is the view number, R is the total number of the consensus nodes, and MOD is remainder operation), that is, when no consensus node is added or withdrawn in the federation chain, all the consensus nodes alternately act as master nodes according to the self-numbering sequence. All the consensus nodes are fair to all the nodes by taking the consensus nodes as the master nodes in turn, but the method has the defect that the probability that the election process fails and the election needs to be carried out again due to the fact that malicious nodes cannot be elected as the master nodes by the method.
Disclosure of Invention
In order to solve the problem that in the conventional PBFT consensus method of the alliance chain, the consensus performance is reduced along with the increase of the number of consensus nodes, the invention provides the alliance chain consensus method and system based on weight excitation main node election, so that the probability of electing a malicious node as a main node is reduced, and the consensus performance of the alliance chain is improved.
In order to achieve the technical effects, the technical scheme of the invention is as follows:
a federation chain consensus method based on weight incentive master node election comprises the following steps:
s1, calculating the number f of tolerable malicious nodes of a alliance chain, and determining an initial consensus main node and a consensus auxiliary node in the alliance chain nodes;
s2, a common identification main node and a common identification auxiliary node in the alliance chain receive a transaction uplink request message sent by a client side, and common identification main node verification and common identification auxiliary node verification are carried out;
s3, each consensus auxiliary node verifies the consistency of the consensus main node verification result and the node verification result to obtain verification result information, wherein the verification result information comprises reply content rACKOr reply to the content rnon-ACKEach consensus auxiliary node replies the verification result information to the consensus main node;
s4, setting reply content r in verification result informationACKOf alpha or reply contents rnon-ACKThe number of the common node is beta, when alpha is more than or equal to 2f or beta is less than or equal to f, if the common node verification is successful,allowing the transaction to be written into the latest block of the consensus main node, and the consensus main node replies a 'transaction success' message to the client; if the check of the consensus master node fails, transaction writing is refused, and the consensus master node replies a 'transaction failure' message of the client;
when f is less than or equal to alpha < 2f or f < beta < 2f, the consensus master node broadcasts to inform all consensus slave nodes to enter a PBFT consensus protocol, and performs consensus again on the transaction by using the PBFT consensus protocol;
and when the alpha is less than or equal to 0 and less than or equal to f or beta is more than or equal to 2f, the common identification master node informs all the common identification auxiliary nodes to trigger the view change protocol, all the common identification auxiliary nodes calculate the election weight of the node according to the record of the check of the common identification auxiliary nodes, elects the node with the highest weight to be a new common identification master node, and returns to the step S2 to perform the common identification again.
In the technical scheme, a traditional PBFT consensus algorithm is taken as a basic starting point, the nodes of the alliance chain are subjected to 'three-step walking' consensus, and for the trade uplink request of the client, a 'simple consensus protocol' is adopted: all nodes in the alliance chain receive requests and carry out consensus main node verification and consensus auxiliary node verification, then each consensus auxiliary node verifies the consistency of verification results, whether transactions are written into blocks is determined according to the comparison of the feedback quantity of reply contents in verification result information and the quantity of malicious nodes, the consensus main node verification result is combined, the algorithm complexity of a simple consensus protocol is O (n), the operation speed is high, the efficiency is high, the consensus performance of the alliance chain can be improved, when the malicious nodes appear, the feedback quantity of the reply contents in the verification result information and the quantity of the malicious nodes do not meet the simple consensus protocol, the security and the reliability of the alliance chain cannot be guaranteed, the PBFT consensus protocol is used for consensus, the robustness of the alliance chain is improved, but the number of the malicious nodes which can be tolerated by the PBFT consensus protocol has a limit, therefore, and by combining a view replacement protocol and adopting a weight incentive mechanism to reselect the main consensus node, the appropriate election of the main consensus node is ensured, the probability of malicious nodes is reduced, and the consensus performance of the alliance chain is further improved.
Preferably, the expression for calculating the number f of tolerable malicious nodes of the federation chain in step S1 is as follows:
wherein N represents the total number of the identified nodes in the federation chain;
indicating a rounding down.
Preferably, the message for requesting uplink transaction sent by the receiving client of the consensus primary node and the consensus secondary node in the alliance chain is set to msgrequest,msgrequestIncludes a transaction content m, a transaction summary D (m) and a client signature Signc;
The checking of the consensus master node in step S2 includes:
the consensus main node calculates a summary D '(m) of the transaction content m, and the summary D' (m) is associated with a transaction uplink request message msg sent by the clientrequestThe transaction summary D (m) in (1) is checked, whether the two are equal is checked, and the check result is marked as rverificationForming a consensus master node check result message msgverificationVerification result message msgverificationComprises the following steps: check result flag rverificationTransaction content m, transaction summary D (m) and node signature Signnode k;
The checking of the common recognition auxiliary node comprises the following steps: each consensus sub-node calculates a summary D '(m) of the transaction content m, and the summary D' (m) is associated with a transaction uplink request message msg sent by the clientrequestThe transaction summary D (m) in the node is checked, whether the transaction summary D (m) is equal to the transaction summary m is checked, and a node checking result message is formed.
Preferably, the consensus master node will check the result message msgverificationSending the result to each consensus secondary node, and each consensus secondary node receiving a check result message msgverificationVerifying the consistency of the checking result of the consensus master node and the checking result of the node to obtain verification result information;
if the verification result is consistent, the reply is carried outVolume rACKPackaging the verification result information, otherwise, replying the content rnon-ACKPackaging the verification result information; the verification result information also comprises transaction content m, transaction abstract D (m) and node signature Signnode k。
Preferably, if the check result flag r is greater than or equal to 2f or β is less than or equal to f as stated in step S4verificationComprises the following steps:
D′(m)=D(m)
the consensus host node checks successfully and encapsulates the 'execute transaction' message msgsbft-commitAnd sent to all the consensus secondary nodes which receive the message msg of executing transactionsbft-commitDetermining to execute the transaction, writing the transaction into the latest block of the node, and replying a 'transaction success' message to the client by the consensus main node; if the verification result marks rverificationComprises the following steps:
D′(m)≠D(m)
the consensus master node fails the check and the consensus master node encapsulates a "do not execute transaction" message msgsbft-commitSent to all the consensus secondary nodes, and the consensus secondary nodes receive a 'do not execute transaction' message msgsbft-commitIf the transaction is not executed and the block is not written, the consensus master node replies to the client with a transaction failure message.
Here, after the consensus master node replies the "transaction success" message to the client or the consensus master node replies the "transaction failure" message to the client, the process still returns to step S2 to continue to execute the next round of consensus for the next uplink transaction request sent by the client.
Preferably, in step S4, when f ≦ α < 2f or f ≦ β ≦ 2f, the consensus master node broadcasts to notify all consensus secondary nodes to enter the PBFT consensus protocol, and the process of re-performing consensus on the transaction using the PBFT consensus protocol is as follows:
the client sends a transaction uplink request message to the consensus master node;
the consensus master node verifies the message sent by the client, and broadcasts a transaction Pre-prepare message to all consensus slave nodes after the verification is passed;
each consensus auxiliary node checks the received transaction Pre-Prepare message, and broadcasts the transaction Pre-Prepare message to other consensus auxiliary nodes and consensus main nodes except the consensus auxiliary node after the check is passed;
the consensus main node and the consensus auxiliary node verify the received trade prefix message, and when the verification is passed and the number of the passed consensus is more than or equal to 2f +1, the trade Commit message is broadcast to other consensus auxiliary nodes and the consensus main node except the consensus main node;
the common identification main node and the common identification auxiliary node verify the received transaction Commit message, when the correct number of Commit message verification results is more than or equal to 2f +1, the transaction is written into the latest block of the node, and a Reply message msg is returnedreplyAnd giving the client the result of the transaction success.
When f is more than or equal to alpha and less than 2f (or f is more than or equal to beta and less than or equal to 2f), malicious nodes appear, the feedback quantity of the reply content in the verification result information and the quantity of the malicious nodes do not meet basic consensus, the security and reliability of the alliance chain cannot be guaranteed, the PBFT consensus protocol is used for consensus, and the robustness of the alliance chain consensus is improved. In the return of Reply message msgreplyAfter "the transaction is successful" is sent to the ue, for the next uplink transaction request sent by the ue, the step S2 is still returned to continue to execute the next round of consensus; when the number Commit message check result is correct and the number of Commit message check results is correct and is less than 2f +1, returning a Reply message msgreplyIf the ue sends the next uplink transaction request, it returns to step S2 to continue executing the next round of consensus.
Preferably, when 0 ≦ α < f or β > 2f as described in step S4, the consensus master node broadcasts the message msgvcInforming all cognizant secondary nodes to trigger execution of a View Change protocol, message msgvcThe method comprises the following steps: view number v +1, last block number BS and node signature Signnode k(ii) a All the consensus secondary nodes receive the message msgvcThen, all the consensus auxiliary nodes calculate the election weight distribution P of the node k according to the record of the check of the consensus auxiliary nodesnode kThe process comprises the following steps:
1) calculating the accuracy, wherein the expression is as follows:
wherein, TkLThe latest transaction serial number verified for the k number consensus secondary node; tkOThe first transaction serial number verified for the k number consensus secondary node; tkEThe transaction sequence number set for checking errors of the k number consensus secondary node is represented as: tkE={Tk1,Tk2,Tk3,…,Tkn},E=1,2,3,…,n,Tk1For the first wrong checking transaction number, Tk, of the k-number consensus secondary nodenIdentifying the transaction serial number of the nth check error of the secondary node for the number k; when Correctness is more than 99 percent, the consensus auxiliary node is qualified to be elected as the consensus main node;
2) compute node base score PBThe expression is:
PB=A×Correctness
wherein A represents a modifiable weight-divided reference coefficient;
3) calculating continuously corrected prize PSCThe expression is:
4) calculating a check error history penalty PEHThe expression is:
5) calculating a continuous check error penalty PECThe expression is:
a=0.05×(TkL-TkO+1),C=1.57×A×a,x=Tkn-Tkn-1
wherein a and C both represent intermediate parameters;
6) calculating election weight distribution P of the node knode kThe expression is:
Pnode k=PB+PSC+PEH-PEC
wherein, Pnode kAnd showing the election weight distribution of the k-number consensus secondary node.
Preferably, the consensus secondary node calculates the election weight distribution P of the node k according to the record checked by the consensus secondary node in the step S2node kThen, P is addednode kEncapsulating into a reply message msgPre-voteBroadcast view switch-back message msgPre-voteTo the alliance chain, the message msgPre-voteIncluding the view number v +1, the last block number BS, and the election weight P of the nodenode kAnd node signature Signnode k;
All the common identification nodes in the alliance chain receive the message msgPre-voteComparing each election weight score Pnode 1~Pnode NMaking an election, wherein N represents the total number of the common nodes in the alliance chain; each node in the alliance chain encapsulates the election result into an election message msgvoteBroadcasting election message msgvoteTo the alliance chain, election message msgvoteComprises the following steps: view number v +1, last block number BS that stably achieves consensus, election result voteresult, and node signature Signnode k;
Each consensus node in the alliance chain receives election messages of other consensus nodes, the consensus node with the most votes is selected to become a new consensus main node, and the other consensus nodes send confirmation result messages msgpost-voteTo the new master node, message msgpost-voteComprises the following steps: view number v +1, last block number BS which stably achieves consensus, new consensus master node number node k and node signature Signnode k;
In the new consensus main sectionMessage msg received by pointpost-voteWhen the number is more than or equal to 2f +1, replying a message msg confirming to become the new consensus main node to all the auxiliary consensus nodesvc-commitAll nodes are notified to synchronize the block to the last stable consensus block BS.
The main consensus node is reselected by adopting a weight excitation mechanism, the election weight score is calculated through a series of excitation and penalty formulas by combining the node verification accuracy, the verification success, the error history, the continuous verification success and the error record, the node with the highest weight score is selected as the main node, the election fitness of the main consensus node is ensured, the probability of occurrence of malicious nodes is reduced, and the consensus performance of the alliance chain is further improved.
Preferably, if the new co-recognizing master node receives the message msgpost-voteIf the quantity is less than 2f +1, the election fails, and the original consensus primary node informs all the consensus secondary nodes to re-trigger and execute the view change protocol.
The invention also provides a alliance chain consensus system based on weight incentive main node election, which comprises:
the malicious node calculation module is used for determining an initial consensus main node in the nodes of the alliance chain and calculating the number f of the tolerable malicious nodes of the alliance chain;
the request receiving and checking module is used for receiving the transaction uplink request message sent by the client by the common main node and the common auxiliary node in the alliance chain, and checking the common main node and the common auxiliary node;
and each consensus auxiliary node verifies the consistency of the consensus main node verification result and the node verification result to obtain verification result information, wherein the verification result information comprises reply content rACKOr reply to the content rnon-ACKEach consensus auxiliary node replies verification result information to the consensus main node;
a request response processing module for setting the reply content r in the verification result informationACKOf alpha or reply contents rnon-ACKThe number of the common identification master node is beta, when alpha is more than or equal to 2f or beta is less than or equal to f, if the common identification master node is successfully verified, the transaction is allowed to be written into the most common identification master nodeA new block, wherein the consensus master node replies a 'transaction success' message to the client; if the checking of the consensus main node fails, refusing the transaction writing, and replying a 'transaction failure' message of the client by the consensus main node;
when the f is more than or equal to alpha and less than 2f or the f is more than or equal to beta and less than or equal to 2f, the consensus main node broadcasts to inform all consensus auxiliary nodes to enter a PBFT consensus protocol, and the PBFT consensus protocol is used for carrying out consensus again on the transaction;
and when alpha is less than or equal to 0 and less than or equal to f or beta is more than or equal to 2f, the common identification master node informs all the common identification auxiliary nodes to trigger the execution of the view change protocol, all the common identification auxiliary nodes calculate the election weight division of the node according to the record of the verification of the common identification auxiliary nodes, the node with the highest weight division is elected as a new common identification master node, and the new common identification master node inputs a request receiving and verifying module and restarts common identification.
Compared with the prior art, the invention has the beneficial effects that:
the invention provides a coalition chain consensus method and a coalition chain consensus system based on weight incentive main node election, for a transaction uplink request of a client, all nodes in a coalition chain receive the request and perform consensus main node verification and consensus auxiliary node verification, then each consensus auxiliary node verifies the consistency of the verification result, according to the comparison of the feedback quantity of the reply content in the verification result information and the quantity of malicious nodes, and in combination with the verification result of the consensus main node, whether the transaction is written into a block is determined, when no malicious node appears, the method has low complexity, high operation speed and high efficiency, can improve the consensus performance of the coalition chain, provide higher TPS and support the service operation with high TPS requirements, but when the malicious node appears, the comparison result of the feedback quantity of the reply content in the verification result information and the quantity of the malicious nodes does not meet the original consensus requirements, and the security and reliability of the coalition chain cannot be ensured, the PBFT consensus protocol is used for consensus, the safety and the robustness of the alliance chain are improved, the number of malicious nodes which can be tolerated by the PBFT consensus protocol is limited, the view change protocol is combined, the main consensus node is reselected by adopting a weight incentive mechanism, the suitability of the main consensus node is ensured, the possibility that the malicious node becomes a main node is reduced, and the consensus performance of the alliance chain is further improved.
Drawings
Fig. 1 is a schematic flowchart of a federation chain consensus method based on weight-driven master node election according to embodiment 1 of the present invention;
fig. 2 is a diagram showing an entire structure of a federation chain consensus system based on weight-driven master node election proposed in embodiment 2 of the present invention.
Detailed Description
The drawings are for illustrative purposes only and are not to be construed as limiting the patent;
for better illustration of the present embodiment, certain parts of the drawings may be omitted, enlarged or reduced, and do not represent actual dimensions;
it will be understood by those skilled in the art that certain well-known descriptions of the figures may be omitted.
The positional relationships depicted in the drawings are for illustrative purposes only and are not to be construed as limiting the present patent;
the technical solution of the present invention is further described below with reference to the accompanying drawings and examples.
Example 1
Considering that the highest TPS (system throughput, which is the number of systems processed per second) of a block chain system of a federation chain by using a conventional PBFT consensus algorithm is generally over 10000TPS, and as the number of consensus nodes increases, the highest TPS is attenuated in a polynomial level, at this time, the block chain consensus efficiency is low, and it is difficult to support the problem that services with high TPS requirements are normally operated, that is, sometimes the PBFT consensus algorithm is not necessarily used immediately, and in the stage of Prepare and Commit, each consensus node needs to perform summary calculation and perform message broadcasting, and the message complexity is O (n) (n is the number of common nodes in the federation and the stage of Commit)2). When the number of the consensus nodes in the network increases, all the consensus nodes need to perform two-stage summary calculation and message broadcasting operation, which causes the performance of the traditional PBFT consensus algorithm to rapidly decrease with the increase of the number of the consensus nodes. In addition to the interruption of service running on the federation chain which may result when the performance of the federation chain degrades to a certain extent, conventional PBFT consensus algorithms require periodic replacement of the host node, or in the event of corruption by the host nodeThe master node will also be replaced. When the common node joining or quitting does not occur in the alliance chain, all the common nodes can take the main nodes in turn according to the self numbering sequence. All consensus nodes are fair to all nodes by taking the consensus nodes as master nodes in turn, but the method has the disadvantage that the method cannot avoid the possibility that malicious nodes are elected as the master nodes, which causes the election process to fail, and election needs to be performed again, and affects the efficiency and the overall performance of the alliance chain consensus, so that embodiment 1 of the present invention provides an alliance chain consensus method based on weight excitation master node election, a flow diagram of which is shown in fig. 1, and the method includes:
s1, calculating the number f of tolerable malicious nodes of a alliance chain, and determining an initial consensus main node and a consensus auxiliary node in the alliance chain nodes;
the expression for calculating the number f of tolerable malicious nodes of the alliance chain is as follows:
wherein N represents the total number of the identified nodes in the federation chain;
indicating a rounding down. In addition, in specific implementation, the selection of the initial consensus master node in the federation chain nodes is usually a node that is initially considered to be high reliability, and is not a tamper message.
S2, a common identification main node and a common identification auxiliary node in the alliance chain receive a transaction uplink request message sent by a client side, and common identification main node verification and common identification auxiliary node verification are carried out;
setting a message of transaction uplink request sent by a receiving client of a common-identity main node and a common-identity auxiliary node in a alliance chain as msgrequest,msgrequestIncludes a transaction content m, a transaction summary D (m) and a client signature Signc(ii) a Wherein, the consensus master node verification comprises:
the consensus main node calculates a summary D '(m) of the transaction content m and sends the summary D' (m) to the clientTransaction uplink request message msgrequestThe transaction summary D (m) in (1) is checked, whether the two are equal is checked, and the check result is marked as rverificationForming a consensus master node check result message msgverificationVerification result message msgverificationComprises the following steps: check result flag rverificationTransaction content m, transaction summary D (m) and node signature Signnode k;
The checking of the common recognition auxiliary node comprises the following steps: each consensus sub-node calculates a summary D '(m) of the transaction content m, and the summary D' (m) is associated with a transaction uplink request message msg sent by the clientrequestThe transaction summary D (m) in the node is checked, whether the transaction summary D (m) is equal to the transaction summary m is checked, and a node checking result message is formed.
S3, each consensus auxiliary node verifies the consistency of the consensus main node verification result and the node verification result to obtain verification result information, wherein the verification result information comprises reply content rACKOr reply to the content rnon-ACKEach consensus auxiliary node replies the verification result information to the consensus main node;
the consensus master node sends a check result message msgverificationSending the message to each common identification secondary node, and each common identification secondary node receiving a verification result message msgverificationVerifying the consistency of the checking result of the consensus master node and the checking result of the node to obtain verification result information;
if the verification result is consistent, the content r is repliedACKPackaging the verification result information, otherwise, replying the content rnon-ACKPackaging the verification result information; the verification result information also comprises transaction content m, transaction abstract D (m) and node signature Signnode k。
The steps from S1 to S3 are a simple consensus protocol, when no malicious node appears, the high efficiency of the consensus process is ensured, a higher TPS is provided, the service operation with high TPS requirements is supported, and then the reply content r in the verification result information is used as the basisACKOr rnon-ACKThe number of the malicious nodes is compared with the number of the malicious nodes, and whether the transaction is written into the block or not is determined by combining the checking result of the common identification main nodeStep S4 is executed, and with reference to fig. 1, in consideration of the fact that when a malicious node occurs, the security reliability of the federation chain cannot be guaranteed, the PBFT consensus protocol is used for consensus, so as to improve the robustness of federation chain consensus, but the number of malicious nodes that can be tolerated by the PBFT consensus protocol has a limit, so that, with reference to the view replacement protocol, a weight excitation mechanism is used to reselect the main consensus node, so as to ensure the suitability of election of the main consensus node, reduce the probability of occurrence of the malicious node, further improve the consensus performance of the federation chain, and execute step S4:
s4, setting reply content r in verification result informationACKOf alpha or reply contents rnon-ACKWhen alpha is more than or equal to 2f or beta is less than or equal to f, if the consensus master node is verified successfully, the transaction is allowed to be written into the latest block of the consensus master node, and the consensus master node replies a 'transaction success' message to the client; if the check of the consensus master node fails, transaction writing is refused, and the consensus master node replies a 'transaction failure' message of the client;
when the f is more than or equal to alpha and less than 2f or the f is more than or equal to beta and less than or equal to 2f, the consensus main node broadcasts to inform all consensus auxiliary nodes to enter a PBFT consensus protocol, and the PBFT consensus protocol is used for carrying out consensus again on the transaction;
and when alpha is more than or equal to 0 and less than f or beta is more than 2f, the consensus master node informs all the consensus auxiliary nodes to trigger the execution of the view change protocol, all the consensus auxiliary nodes calculate the election weight of the node according to the record of the check of the consensus auxiliary nodes, the node with the highest weight is elected as a new consensus master node, and the step S2 is returned to carry out consensus again.
At this time, three cases are divided:
(one) when alpha is more than or equal to 2f or beta is less than or equal to f, if the check result marks rverificationComprises the following steps:
D′(m)=D(m)
the consensus host node checks successfully and encapsulates the 'execute transaction' message msgsbft-commitAnd sent to all the consensus secondary nodes which receive the message msg of executing transactionsbft-commitDetermining to execute the transaction, writing the transaction into the latest block of the node, and the consensus master node replies 'transaction success' to the clientInformation; if the verification result marks rverificationComprises the following steps:
D′(m)≠D(m)
the consensus master node fails the check and the consensus master node encapsulates a "do not execute transaction" message msgsbft-commitSent to all the consensus secondary nodes, and the consensus secondary nodes receive a 'do not execute transaction' message msgsbft-commitIf the transaction is not executed and the block is not written, the consensus master node replies to the client with a transaction failure message. After the consensus master node replies the "successful transaction" message to the client or the consensus master node replies the "failed transaction" message to the client, the process returns to step S2 to continue to execute the next round of consensus for the next uplink transaction request sent by the client.
(II) when the f is more than or equal to alpha and less than 2f or the f is more than or equal to beta and less than or equal to 2f, the consensus master node broadcasts to inform all consensus secondary nodes to enter the PBFT consensus protocol, and the process of carrying out consensus again on the transaction by using the PBFT consensus protocol comprises the following steps:
the client sends a transaction uplink request message to the consensus master node;
the consensus master node verifies the message sent by the client, and broadcasts a transaction Pre-prepare message to all consensus slave nodes after the verification is passed;
each consensus auxiliary node checks the received transaction Pre-Prepare message, and broadcasts the transaction Pre-Prepare message to other consensus auxiliary nodes and consensus main nodes except the consensus auxiliary node after the check is passed;
the consensus main node and the consensus auxiliary node verify the received trade prefix message, and when the verification is passed and the number of the passed consensus is more than or equal to 2f +1, the trade Commit message is broadcast to other consensus auxiliary nodes and the consensus main node except the consensus main node;
the common identification main node and the common identification auxiliary node verify the received transaction Commit message, when the correct number of Commit message verification results is more than or equal to 2f +1, the transaction is written into the latest block of the node, and a Reply message msg is returnedreplyAnd giving the client the result of the transaction success.
The above-mentioned process of using the PBFT consensus protocol to perform consensus again specifically is:
a Request stage: client sends transaction uplink request message msg to consensus master noderequestMessage msgrequestComprises the following steps: transaction content m, transaction summary D (m) and client signature Signc;
Pre-prepare stage: message msg of client received by consensus main noderequestConsensus master node verification message msgrequestClient-side signature Sign insidecWhether it is correct;
if the signature result of the client is verified to be correct, broadcasting a Pre-preamble message msg to other common identification nodespre-preparePre-preamble message msgpre-prepareComprises the following steps: transaction content m, transaction digest D (m), and consensus master signature Signnode k(ii) a If the signature result of the client is not correct, the common identification is marked as failure, and the transaction failure is sent to the client.
Stage Prepare: the consensus secondary node receives the message msg of the consensus primary nodepre-prepareAnd performing Prepare stage check: message msgpre-prepareConsensus master node signature Sign innode kWhether the summary D' (m) and msg of the transaction content m are correct or not is calculatedpre-prepareTransaction digests within D (m) are consistent.
If the verification result is consistent rprepareIf the node is consistent, i.e. D' (m) is consistent, a Prepare message msg is broadcast to other nodesprepareMessage msgprepareComprises the following steps: transaction content m, transaction digest D (m) and signature Sign of the common nodenode k(ii) a If the verification result is inconsistent r'prepareIf "disagreement", i.e. D' (m) ≠ D (m), it broadcasts a Prepare message msg to other consensus nodesprepare= <Transaction content m, transaction summary D (m), r'prepareThe signature Sign of the slave nodenode k>。
And a Commit stage: the consensus main node and the consensus auxiliary node receive the message msgprepareAnd carrying out Commit stage check:
checking msgprepareSecondary node signature Sign in (1)node kCorrect or not, msgprepareTransaction digests D (m) and msg in (1)pre-prepareIs consistent with the transaction summary d (m).
If the node Commit stage check result is consistent, and the received r isprepareIf the number is equal to or larger than 2f +1, broadcasting Commit message msg to other consensus nodescommitMessage msgcommitComprises the following steps: transaction content m, transaction summary D (m) and local node signature Signnode k(ii) a If the check result of the Commit stage of the node is consistent, and the received r is consistentprepareIf the number is consistent and less than 2f +1, the result is marked as consensus failure, and the result is sent to the client side.
A Reply stage: msg received by the consensus main node and the consensus auxiliary nodecommitChecking at Reply stage, and verifying msgcommitOwn node signature Sign in (1)node kWhether the signature is correct, if: msg received by node and verified by Reply stage to be correct in resultcommitIf the number is more than or equal to 2f +1, the transaction is written into the latest block of the node, and a Reply message msg is returnedreplyGiving the client the result of the transaction success; if the node receives the msg with correct result verified by the Reply stagecommitIf the quantity is less than 2f +1, the result is marked as consensus failure, and the transaction failure is sent to the client. And then returns a simple consensus protocol.
When f is more than or equal to alpha and less than 2f (or f is more than or equal to beta and less than or equal to 2f), malicious nodes appear, the feedback quantity of the reply content in the verification result information and the quantity of the malicious nodes do not meet basic consensus, the security and reliability of the alliance chain cannot be guaranteed, the PBFT consensus protocol is used for consensus, and the robustness of the alliance chain consensus is improved. In the return of Reply message msgreplyAfter "the transaction is successful" is sent to the ue, for the next uplink transaction request sent by the ue, the step S2 is still returned to continue to execute the next round of consensus; when the number Commit message check result is correct and the number of Commit message check results is correct and is less than 2f +1, returning a Reply message msgreplyIf the ue sends the next uplink transaction request, it returns to step S2 to continue executing the next round of consensus.
(III) inWhen alpha is more than or equal to 0 and less than f or beta is more than 2f, the consensus master node broadcasts message msgvcInforming all cognizant secondary nodes to trigger execution of a view Change protocol, message msgvcThe method comprises the following steps: view number v +1, last block number BS and node signature Signnode k(ii) a All the consensus secondary nodes receive the message msgvcThen, all the consensus auxiliary nodes calculate the election weight distribution P of the node k according to the record of the check of the consensus auxiliary nodesnode kThe process comprises the following steps:
1) calculating the accuracy, wherein the expression is as follows:
wherein, TkLThe latest transaction serial number verified for the k number consensus secondary node; tkOThe first transaction serial number verified for the k number consensus secondary node; tkEThe transaction sequence number set for checking errors of the k number consensus secondary node is represented as: tkE={Tk1,Tk2,Tk3,…,Tkn},E=1,2,3,…,n,Tk1For the first wrong checking transaction number, Tk, of the k-number consensus secondary nodenIdentifying the transaction serial number of the nth check error of the secondary node for the number k; when Correctness is more than 99 percent, the consensus auxiliary node is qualified to be elected as the consensus main node;
2) calculating a node basis score PB, wherein the expression is as follows:
PB=A×Correctness
wherein A represents a modifiable weight-divided reference coefficient;
3) calculating continuously corrected prize PSCThe expression is:
4) calculating a check error history penalty PEHThe expression is:
5) calculating a continuous check error penalty PECThe expression is:
wherein a and C both represent intermediate parameters;
6) calculating election weight distribution P of the node knode kThe expression is:
Pnode k=PB+PSC+PEH-PEC
wherein, Pnode kAnd showing the election weight distribution of the k-number consensus secondary node. The consensus secondary node calculates the election weight distribution P of the node k according to the record checked by the consensus secondary node in the step S2node kThen, P is addednode kEncapsulating in reply message msgPre-voteBroadcast View switch reply message msgPre-voteTo the alliance chain, the message msgPre-voteIncluding the view number v +1, the last stable consensus block number BS, the node election weight Pnode kAnd node signature Signnode k;
All the common identification nodes in the alliance chain receive the message msgPre-voteComparing each election weight score Pnode 1~Pnode NMaking an election, wherein N represents the total number of the common nodes in the alliance chain; each node in the alliance chain encapsulates the election result into an election message msgvoteBroadcasting election message msgvoteTo the alliance chain, election message msgvoteComprises the following steps: view number v +1, last block number BS that stably achieves consensus, election result voteresult, and node signature Signnode k;
Each consensus node in the alliance chain receives election messages of other consensus nodes, the consensus node with the most votes is selected to become a new consensus main node, and the other consensus nodes send confirmation result messages msgpost-voteTo the new master node, message msgpost-voteComprises the following steps: view number v +1, last block number BS which stably achieves consensus, new consensus master node number node k and node signature Signnode k;
Message msg received at new co-recognizing master nodepost-voteWhen the number is more than or equal to 2f +1, replying a message msg confirming to become the new consensus main node to all the auxiliary consensus nodesvc-commitAll nodes are informed to synchronize the block to the last stable consensus block BS if the new consensus master receives message msgpost-voteIf the quantity is less than 2f +1, the election fails, and the original consensus primary node informs all the consensus secondary nodes to re-trigger and execute the view replacement protocol.
And re-electing the main consensus nodes by adopting a weight excitation mechanism, calculating election weight scores through a series of excitation and penalty formulas by combining node verification accuracy, verification success, error history, continuous verification success and error records, selecting the node with the highest weight score as a main node, ensuring the appropriate election of the main consensus nodes, reducing the occurrence probability of malicious nodes and further improving the consensus performance of the alliance chain.
Example 2
As shown in fig. 2, the present invention further provides a federation chain consensus system for master node election based on weight incentive, the system being used to implement the method described in embodiment 1, and referring to fig. 2, the system includes:
the malicious node calculation module 101 is configured to clarify an initial consensus master node in the alliance chain nodes and calculate the number f of the tolerable malicious nodes of the alliance chain;
a request receiving and checking module 102, wherein a common main node and a common auxiliary node in a alliance chain receive a transaction uplink request message sent by a client to perform common main node checking and common auxiliary node checking;
the verification result verification sending module 103 verifies the consistency of the verification result of the consensus primary node and the verification result of the node by each consensus secondary node to obtain verification result information, wherein the verification result information comprises reply content rACKOr reply to the content rnon-ACKEach of which is totallyThe identification auxiliary node replies the verification result information to the consensus main node;
the request/response processing module 104 sets the reply content r in the verification result informationACKOf alpha or reply contents rnon-ACKWhen alpha is more than or equal to 2f or beta is less than or equal to f, if the consensus master node is verified successfully, the transaction is allowed to be written into the latest block of the consensus master node, and the consensus master node replies a 'transaction success' message to the client; if the checking of the consensus main node fails, refusing the transaction writing, and replying a 'transaction failure' message of the client by the consensus main node;
when f is less than or equal to alpha < 2f or f < beta < 2f, the consensus master node broadcasts to inform all consensus slave nodes to enter a PBFT consensus protocol, and performs consensus again on the transaction by using the PBFT consensus protocol;
and when alpha is less than or equal to 0 and less than or equal to f or beta is more than or equal to 2f, the common identification master node informs all the common identification auxiliary nodes to trigger the execution of the view change protocol, all the common identification auxiliary nodes calculate the election weight division of the node according to the record of the verification of the common identification auxiliary nodes, the node with the highest weight division is elected as a new common identification master node, and the new common identification master node inputs a request receiving and verifying module and restarts common identification.
The positional relationships depicted in the drawings are for illustrative purposes only and are not to be construed as limiting the present patent;
it should be understood that the above-described embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are not intended to be exhaustive of all embodiments. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the claims of the present invention.