An improved PBFT method and terminal
By updating the node reputation value and storing transaction information in the memory pool, combined with the PBFT consensus method of hashing and confirming messages, the problems of high bandwidth consumption and vulnerability of the master node in the PBFT consensus method are solved, and efficient blockchain data consistency and stability are achieved.
Patent Information
- Application Number
- CN202411814948.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-12-11
AI Technical Summary
The existing PBFT consensus method consumes high bandwidth and occupies large block space when the number of nodes increases, which affects the blockchain throughput. In addition, the master node is vulnerable to malicious attacks and has a high probability of view switching.
The first PBFT consensus algorithm is used to update node reputation values, select honest master nodes, store transaction information through the memory pool, use transaction hashes and confirmation messages to reduce bandwidth consumption, and the second PBFT consensus algorithm is used to construct candidate blocks to increase transparency and traceability.
Effectively reduce masternode bandwidth consumption, increase block throughput, reduce the possibility of masternode malicious behavior, ensure data consistency and integrity, and improve system stability.
Smart Images

Figure CN119583565B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to an improved PBFT consensus method and terminal. Background Art
[0002] Consensus is a core technology in blockchain, ensuring data consistency within the network. Blockchain technology uses this mechanism to allow participants to reach consensus, replacing the traditional reliance on centralized entities. The PBFT (Practical Byzantine Fault Tolerance) algorithm is one such consensus algorithm. Its key feature is that it guarantees data consistency as long as the number of malicious nodes does not exceed one-third of the total number of consensus nodes. However, it has certain limitations. In PBFT, clients send messages to the master node, which packages the messages into blocks and broadcasts them to other consensus nodes. This consumes the master node's bandwidth, especially when the number of nodes is large. As the number of nodes increases, the bandwidth required also increases. Furthermore, the inclusion of the original message text within the block results in a large block size, limiting the number of transactions that can be included, which in turn affects the blockchain's throughput. Furthermore, the sequential selection mechanism for selecting the master node can lead to malicious attacks against the master node or the selection of a malicious node as the master node, increasing the probability of view switches and increasing system instability. Therefore, an improved PBFT consensus method and terminal that can address these issues is urgently needed. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide an improved PBFT consensus method and terminal, which can reduce the bandwidth consumption of the master node for sending messages, effectively improve the block throughput, and reduce the possibility and predictability of malicious behavior of the master node, thereby reducing the probability of view switching.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] An improved PBFT consensus method includes the following steps:
[0006] S1. Use the first PBFT consensus algorithm to update the initial reputation value of each node and select the master node;
[0007] S2. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client, and store the transaction information in the node memory pool corresponding to each node;
[0008] S3. The consensus node sends a transaction receipt notification to the master node, where the transaction receipt notification includes a transaction hash. When the master node receives a first preset number of transaction receipt notifications, the master node sends a transaction confirmation message to the consensus node. If the consensus node does not receive the transaction confirmation message, the master node sends a request to obtain transaction confirmation information to the master node. Otherwise, the consensus node determines whether its own node memory pool contains the transaction information corresponding to the transaction confirmation message based on the transaction confirmation message. If not, the master node broadcasts a transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus.
[0009] In order to solve the above technical problems, another technical solution adopted by the present invention is:
[0010] An improved PBFT consensus terminal includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the processor implements the steps of the improved PBFT consensus method described above.
[0011] The beneficial effects of the present invention are as follows: an improved PBFT consensus method and terminal provided by the present invention updates the initial reputation value of each node by adopting a first PBFT consensus algorithm, selects a master node, and ensures that the nodes in the candidate master node set are honest nodes; the master node and all consensus nodes participating in the consensus process receive transaction information sent by the client and store the transaction information in the node memory pool corresponding to each node, avoiding dependence on the central node, reducing the bandwidth consumption of the master node sending messages in the subsequent consensus process, and effectively improving the block throughput; the consensus node sends a transaction reception notification to the master node. When the master node receives a first preset number of transaction reception notifications, the master node sends a transaction confirmation message to the consensus node. The transaction reception notification includes a transaction hash. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and adopts a second PBFT consensus algorithm for consensus, thereby increasing the transparency and traceability of the transaction process. Corresponding processing is performed based on the transaction confirmation information received by the consensus node and the data status of the node memory pool, providing integrity protection, and ensuring the data consistency of the consensus node. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 This is a flowchart of an improved PBFT consensus method according to an embodiment of the present invention;
[0013] Figure 2 Schematic diagram of an improved PBFT consensus terminal according to an embodiment of the present invention;
[0014] Figure 3 This is a flow chart of the consensus phase of an improved PBFT consensus method according to an embodiment of the present invention;
[0015] Description of labels:
[0016] 1. An improved PBFT consensus terminal; 2. Memory; 3. Processor. DETAILED DESCRIPTION
[0017] To illustrate the technical content, achieved objectives and effects of the present invention in detail, the following description is given in conjunction with the embodiments and accompanying drawings.
[0018] Please refer to Figure 1 , an embodiment of the present invention provides an improved PBFT consensus method, comprising the steps of:
[0019] S1. Use the first PBFT consensus algorithm to update the initial reputation value of each node and select the master node;
[0020] S2. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client, and store the transaction information in the node memory pool corresponding to each node;
[0021] S3. The consensus node sends a transaction receipt notification to the master node, where the transaction receipt notification includes a transaction hash. When the master node receives a first preset number of transaction receipt notifications, the master node sends a transaction confirmation message to the consensus node. If the consensus node does not receive the transaction confirmation message, the master node sends a request to obtain transaction confirmation information to the master node. Otherwise, the consensus node determines whether its own node memory pool contains the transaction information corresponding to the transaction confirmation message based on the transaction confirmation message. If not, the master node broadcasts a transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus.
[0022] As can be seen from the above description, the beneficial effects of the present invention are as follows: by adopting the first PBFT consensus algorithm to update the initial reputation value of each node, a master node is selected, and the nodes in the candidate master node set are ensured to be honest nodes; the master node and all consensus nodes participating in the consensus process receive transaction information sent by the client and store the transaction information in the node memory pool corresponding to each node, avoiding dependence on the central node, reducing the bandwidth consumption of the master node sending messages in the subsequent consensus process, and effectively improving the block throughput; the consensus node sends a transaction reception notification to the master node. When the master node receives a first preset number of transaction reception notifications, the master node sends a transaction confirmation message to the consensus node. The transaction reception notification includes a transaction hash. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and adopts the second PBFT consensus algorithm for consensus, thereby increasing the transparency and traceability of the transaction process. Corresponding processing is performed according to the transaction confirmation information received by the consensus node and the data status of the node memory pool, providing integrity protection, and ensuring the data consistency of the consensus node.
[0023] Furthermore, the step S1 specifically includes:
[0024] Assigning an initial reputation value to each node, using the first PBFT consensus algorithm to conduct a preset number of rounds of consensus, and calculating and updating the initial reputation value of each node after each round of consensus according to the reputation evaluation mechanism;
[0025] A set of candidate master nodes is obtained according to the reputation value of each node, and a master node is selected from the set of candidate master nodes using a random number node selection mechanism.
[0026] As can be seen from the above description, by adopting the first PBFT consensus algorithm to perform preset rounds of consensus, the reputation value of each node is calculated and updated after each round of consensus according to the reputation evaluation mechanism, and a set of candidate master nodes is obtained based on the reputation value of each node. The nodes in the candidate master node set are guaranteed to be honest nodes. The master node is selected from the candidate master node set using a random number node selection mechanism to avoid the possibility and predictability of malicious behavior of the master node, thereby reducing the probability of view switching.
[0027] Furthermore, selecting a master node from the set of candidate master nodes using a random number node selection mechanism includes:
[0028] The nodes in the candidate master node set are sorted based on the public keys to obtain a node sorting array, and a trusted third party generates a random number. The trusted third party performs a hash operation on the random number to obtain a first hash value, and broadcasts the first hash value to all candidate master nodes in the candidate master node set;
[0029] When the candidate master node receives the first hash value, it queries the public key of the node in the middle position in the node sorting array, calculates a second hash value based on the first hash value and the public key, and performs a modulo operation on the second hash value to obtain a node value. The corresponding node in the node sorting array whose sequence number is consistent with the node value is used as the master node.
[0030] As can be seen from the above description, by sorting the nodes in the candidate master node set based on the public key, it is ensured that each node has an equal chance to become the master node, and a random number is generated by a trusted third party, and the random number is hashed to obtain a first hash value. The second hash value is calculated by combining the first hash value and the public key of the intermediate node, and the corresponding node whose serial number in the node sorting array is consistent with the node value is used as the master node, avoiding the predictability of the master node while also ensuring the uniqueness of the master node.
[0031] Furthermore, step S3 includes:
[0032] The master node sends a pre-prepare message to the consensus nodes participating in the consensus process. If a consensus node receives the pre-prepare message, it checks the transaction information in the corresponding node memory pool and verifies the pre-prepare message. If the verification is successful, it broadcasts the pre-prepare message to other consensus nodes.
[0033] If a consensus node receives a first preset number of prepare messages, it verifies the prepare messages, and if the verification passes, broadcasts the commit message to other consensus nodes;
[0034] If a consensus node receives the submission message, it verifies the submission message, and when a first preset number of correct submission messages are received, it broadcasts a reply message to the client;
[0035] When the client receives reply messages sent by the second preset number of consensus nodes, the round of consensus is completed.
[0036] From the above description, it can be seen that through the exchange of pre-prepare messages, prepare messages and commit messages between the master node and multiple consensus nodes participating in the consensus process, as well as message verification at each stage of the consensus process, an efficient and secure consensus process is achieved, the fault tolerance and scalability of the system are improved, and the consistency and integrity of the data of each node in the blockchain are ensured.
[0037] Furthermore, the step S3 further includes:
[0038] If the master node does not have any errors, the consensus round is completed, the node updates its reputation value, and enters the next consensus round;
[0039] If an error occurs in the master node, the master node will be reselected based on a random selection mechanism and consensus will be re-performed until no error occurs in the master node.
[0040] From the above description, we can see that by detecting errors in the master node, quickly responding to the failure of the master node, providing a fault repair method, and reselecting the master node for consensus, the overall fault tolerance is improved, ensuring that the consensus process can be executed stably, thereby ensuring data consistency of all nodes.
[0041] Please refer to Figure 2 Another embodiment of the present invention provides an improved PBFT consensus terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, each step of the above-mentioned improved PBFT consensus method is implemented.
[0042] The improved PBFT consensus method and terminal described above are suitable for consensus in blockchains, can effectively improve block throughput, and reduce the possibility and predictability of malicious masternodes. The following specific implementation methods are used to illustrate the method:
[0043] Please refer to Figure 1 , Embodiment 1 of the present invention is: an improved PBFT consensus method, comprising the steps of:
[0044] S1. Use the first PBFT consensus algorithm to update the initial reputation value of each node and select the master node.
[0045] In this embodiment, the first PBFT consensus algorithm is used to update the initial reputation value of each node, select the master node, ensure that the nodes in the candidate master node set are honest nodes, reduce the possibility of the master node doing evil, and thus reduce the probability of view switching.
[0046] Furthermore, in this embodiment, step S1 specifically includes: assigning an initial reputation value to each node, using the first PBFT consensus algorithm to perform a preset round of consensus, and calculating and updating the initial reputation value of each node after each round of consensus according to the reputation evaluation mechanism; obtaining a set of candidate master nodes based on the reputation value of each node, and selecting a master node from the set of candidate master nodes using a random number node selection mechanism, further ensuring that the nodes in the set of candidate master nodes are honest nodes, while also avoiding the possibility and predictability of malicious behavior of the master node.
[0047] Furthermore, in this embodiment, the reputation value of each node is calculated and updated according to the reputation evaluation mechanism after each round of consensus, specifically: different reputation formulas are selected based on the node status to calculate the node reputation value, including: if the node does not engage in malicious behavior during the consensus process and correctly broadcasts and verifies the message, that is, the node is an honest node, then the overall reputation value of the node is calculated based on the node's voting enthusiasm, node transaction timeliness, and node historical performance; if the node engages in malicious behavior during the consensus process and tampers with the message, that is, the node is a malicious node, then the reputation value is reduced and the node is permanently prohibited from entering the candidate master node set. By reducing the reputation value of the malicious node and increasing the reputation value of the honest node, because the system can only tolerate no more than one-third of the total consensus node data as malicious nodes, after multiple rounds of consensus, the reputation mechanism can further ensure that the nodes in the candidate master node set are honest nodes, wherein the reputation value calculation formula of the honest node is: , , ,in, Score the node's enthusiasm, Score the timeliness of node transactions, are influencing factors, representing the weight of the node's enthusiasm score and the node's transaction timeliness score in the node's reputation value. ; The number of nodes voting in the preparation phase, The number of nodes voting for the submission phase, The total number of votes required by nodes in the preparation phase is: The total number of votes that nodes need to submit in the submission phase is: are influencing factors, representing the weights of the number of node votes in the preparation phase and the number of node votes in the submission phase in the node enthusiasm score, ; is the response time of node i in the consensus. The response time is preferably the sum of the time from receiving the first transaction message to sending the next stage message in the preparation and submission stages. If the node is offline or the response time exceeds a certain threshold, the node transaction timeliness score is 0. The reputation value of a malicious node is calculated as follows: ,in, .
[0048] Furthermore, in this embodiment, the selection of a master node from the candidate master node set using a random number node selection mechanism includes: sorting the nodes in the candidate master node set based on public keys to obtain a node sorting array, generating a random number by a trusted third party, performing a hash operation on the random number to obtain a first hash value, and broadcasting the first hash value to all candidate master nodes in the candidate master node set; when the candidate master node receives the first hash value, querying the public key of the node located in the middle position in the node sorting array, calculating a second hash value based on the first hash value and the public key, performing a modulus operation on the second hash value to obtain a node value, and selecting the node in the node sorting array whose sequence number is consistent with the node value as the master node. The specific selection process is as follows:
[0049] 1. Sort the candidate master nodes based on the public key to get the node sorting array [a1, a2, ..., a k ], k is the total number of candidate master nodes;
[0050] 2. The trusted third party generates a random number Randnum, which is known only to the trusted third party. The trusted third party performs a hash operation on the random number, i.e., H1 = hash(Randnum), to obtain the first hash value H1, and broadcasts it to all candidate masternodes;
[0051] 3. After receiving H1, the candidate master node queries the public key of the node in the middle position in the node sorting array and calculates the second hash value. The calculation formula is: H = hash(H1||pk), where pk is the public key of the consensus node (if the number of nodes is even, the node on the left of the middle is selected);
[0052] 4. Perform a modulo operation on the second hash value to obtain a node value P2 = H mod k, and use the node in the node sorting array whose sequence number is consistent with the node value as the master node.
[0053] By sorting the nodes in the candidate master node set based on the public key, it is ensured that each node has an equal chance to become the master node, and a random number is generated by a trusted third party, and the random number is hashed to obtain a first hash value. The second hash value is calculated by combining the first hash value and the public key of the intermediate node, and the corresponding node with the same sequence number as the node value in the node sorting array is used as the master node. The cryptographic properties of the hash function are used to ensure the randomness and confidentiality of the master node selection process. At the same time, a trusted third party is used to coordinate some key steps so that before the master node is selected, the malicious node cannot predict the final result of the master node selection, avoiding the predictability of the master node and ensuring the security of the master node.
[0054] S2. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client and store the transaction information in the node memory pool corresponding to each node.
[0055] In this embodiment, the client sends a message request to the master node and the consensus node. The message request is , where request is the request, o is the client operation, t is the timestamp, and c is the client identifier. For client signature, the master node and consensus node receive transaction information and store the transaction information in their respective node memory pools, avoiding dependence on central nodes, reducing the bandwidth consumption of the master node in sending messages in subsequent consensus processes, and effectively improving block throughput.
[0056] S3. The consensus node sends a transaction receipt notification to the master node, where the transaction receipt notification includes a transaction hash. When the master node receives a first preset number of transaction receipt notifications, the master node sends a transaction confirmation message to the consensus node. If the consensus node does not receive the transaction confirmation message, the master node sends a request to obtain transaction confirmation information to the master node. Otherwise, the consensus node determines whether its own node memory pool contains the transaction information corresponding to the transaction confirmation message based on the transaction confirmation message. If not, the master node broadcasts a transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus.
[0057] In this embodiment, the consensus node sends a transaction receipt notification to the master node, and the master node receives the transaction receipt notification and verifies it. The transaction receipt notification is , where id is the consensus node number, m is the transaction information initiated by the client, hash(m) is the hash value of the transaction collected by the node, and c is the client identifier. The master node signs the transaction receipt notification sent by the consensus node to ensure that the master node can obtain the information of all relevant transactions in a timely manner. The master node verifies the transaction receipt notification to ensure the legitimacy and validity of the transaction. If the master node receives a first preset number of transaction receipt notifications, the master node aggregates the received transaction receipt notifications to obtain an aggregate signature, sends the aggregate signature, participant list and transaction confirmation information to the consensus node, and puts the transaction hash into the candidate block. The first preset number is preferably 2f+1 (f is the number of malicious consensus nodes). The transaction confirmation message sent by the master node to the consensus node is , where confirm indicates transaction confirmation, hash(m) is the hash value of the transaction collected by the node, c is the client identifier, and number is the position number corresponding to the transaction hash placed in the candidate block in order. The master node signs, and the master node aggregates the signatures of the nodes that receive notifications of the broadcast transaction. The master node only broadcasts the transaction hash for consensus. If there is a consensus node that has not received the transaction confirmation information, the consensus node sends a request to the master node to obtain the transaction confirmation information, that is, number and the previous transaction confirmation message are not increasing in sequence. The consensus node will determine the number of missing transaction confirmation information based on the difference in number, and then initiate a request to the master node to broadcast the missing transaction confirmation information. If there is a consensus node that receives the transaction confirmation information and the transaction hash corresponding to the transaction confirmation information is not included in the node memory pool of the consensus node, the transaction request is broadcast to the node containing the transaction information to obtain the transaction information. Corresponding processing is performed according to the situation of the consensus node receiving the transaction confirmation information and the data situation of the node memory pool to provide integrity protection and ensure the data consistency of the consensus node.
[0058] Furthermore, in this embodiment, step S3 includes: the master node sends a pre-prepare message to the consensus nodes participating in the consensus process; if a consensus node receives the pre-prepare message, it checks the transaction information in the corresponding node memory pool and verifies the pre-prepare message, including whether the master node signature is correct, whether the block summary is correct, whether there are duplicate view messages, whether the block transaction hash is correct, etc. If the verification is successful, the prepare message is broadcast to other consensus nodes; if a consensus node receives a first preset number of prepare messages, the prepare message is verified; if the verification is successful, the commit message is broadcast to other consensus nodes; if a consensus node receives the commit message, the commit message is verified, and when the first preset number of correct commit messages is received, a reply message is broadcast to the client; when the client receives a reply message sent by a second preset number of consensus nodes, the consensus round is completed, wherein the first preset number is preferably 2f+1 and the second preset number is preferably f+1, and the pre-prepare message is , the preparation message is , the commit message is , the reply message is , where f is the number of malicious consensus nodes, pre-prepare is the pre-prepare message identifier, prepare is the prepare message identifier, commit is the commit message identifier, reply is the reply message identifier, v is the current view of the message being sent, n is the sequence number assigned by the master node to the request, and num is the total number of transactions contained in the block. is the block information, is the block hash value, The signature of the master node is i, and the consensus node number is i. The master node and multiple consensus nodes participating in the consensus process exchange pre-prepare messages, prepare messages, and commit messages, as well as message verification at each stage of the consensus process, to achieve an efficient and secure consensus process, improve the system's fault tolerance and scalability, and ensure the consistency and integrity of the data of each node in the blockchain.
[0059] Furthermore, in this embodiment, there is a situation where a malicious node disguises itself as an honest node to conduct consensus in order to increase its reputation and enter the high reputation list before committing malicious acts. The following verification behavior can ensure that even if the malicious node commits malicious acts after being elected as the master node, it can be detected to ensure that the consensus can proceed smoothly, including: if the master node continues to fail to respond to transaction reception notifications or broadcasts inconsistent confirmation information to different nodes, it will be determined to be a malicious node based on the timeout mechanism and the verification in the consensus process. The consensus node will initiate a view switch to replace the master node and reduce the reputation value of the malicious master node; if the master node sends an incorrect transaction confirmation message, after the consensus node receives the transaction confirmation message, the nodes in the aggregate signature will verify the transaction confirmation message. If it is found that the transaction hash value does not match the transaction hash value in its own node memory pool, the master node is considered to have committed malicious acts. The consensus node will initiate a view switch to replace the master node and reduce the reputation value of the malicious master node.
[0060] For further information, please refer to Figure 3 , Figure 3 This is a flow chart of the consensus phase of an improved PBFT consensus method according to an embodiment of the present invention. In this embodiment, step S3 further includes: if the master node has no errors, the consensus round is completed, the node updates its reputation value, and enters the next round of consensus; if the master node has an error, the master node is reselected based on a random selection mechanism and consensus is re-performed until the master node has no errors. By detecting errors in the master node, a rapid response to the failure of the master node is provided, a fault repair method is provided, and the master node is reselected for consensus, thereby improving the overall fault tolerance and ensuring that the consensus process can be stably executed, thereby ensuring data consistency of all nodes.
[0061] Please refer to Figure 2 , a second embodiment of the present invention is: an improved PBFT consensus terminal 1, comprising a memory 2, a processor 3, and a computer program stored in the memory 2 and executable on the processor 3, wherein the processor 3 implements each step of an improved PBFT consensus method of the first embodiment when executing the computer program.
[0062] In summary, the present invention provides an improved PBFT consensus method and terminal, which updates the initial reputation value of each node by adopting the first PBFT consensus algorithm to select a master node, including: assigning an initial reputation value to each node, adopting the first PBFT consensus algorithm to perform a preset round of consensus, and calculating and updating the initial reputation value of each node after each round of consensus according to the reputation evaluation mechanism; obtaining a set of candidate master nodes according to the reputation value of each node, and selecting a master node from the candidate master node set using a random number node selection mechanism to further ensure that the nodes in the candidate master node set are honest nodes, while also avoiding the possibility and predictability of the master node doing evil; and selecting a master node from the candidate master node set using a random number node selection mechanism. The node selection mechanism selects a master node, including: sorting the nodes in the candidate master node set based on the public key to obtain a node sorting array, and generating a random number by a trusted third party, performing a hash operation on the random number to obtain a first hash value, and broadcasting the first hash value to all candidate master nodes in the candidate master node set; when the candidate master node receives the first hash value, it queries the public key of the node in the middle position in the node sorting array, calculates a second hash value based on the first hash value and the public key, and performs a modulo operation on the second hash value to obtain a node value, and selects the node in the node sorting array whose sequence number is consistent with the node value as the master node, and uses The cryptographic properties of the hash function are used to ensure the randomness and confidentiality of the master node selection process. At the same time, a trusted third party is used to coordinate some key steps to avoid the predictability of the master node and ensure the security of the master node. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client, and store the transaction information in the node memory pool corresponding to each node, avoiding dependence on the central node, reducing the bandwidth consumption of the master node sending messages in the subsequent consensus process, and effectively improving the block throughput. The consensus node sends a transaction reception notification to the master node, and the transaction reception notification includes a transaction hash. When the master node receives a first preset number of transaction reception notifications, the master node sends a transaction The confirmation message is sent to the consensus node. If the consensus node does not receive the transaction confirmation message, it sends a request for obtaining transaction confirmation information to the master node. Otherwise, it determines whether the transaction information corresponding to the transaction confirmation message exists in its own node memory pool based on the transaction confirmation message. If not, it broadcasts the transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus. It performs corresponding processing based on the transaction confirmation information received by the consensus node and the data status of the node memory pool, providing integrity protection and ensuring the data consistency of the consensus node.The master node sends a pre-prepare message to the consensus nodes participating in the consensus process. If a consensus node receives the pre-prepare message, it checks the transaction information in the corresponding node memory pool and verifies the pre-prepare message, including whether the master node signature is correct, whether the block summary is correct, whether there are duplicate view messages, whether the block transaction hash is correct, etc. If the verification is successful, the prepare message is broadcast to other consensus nodes; if a consensus node receives a first preset number of prepare messages, it verifies the prepare message. If the verification is successful, it broadcasts a commit message to other consensus nodes; if a consensus node receives the commit message, it verifies the commit message. When the first preset number of correct commit messages are received, a reply message is broadcast to the client; when the client receives a reply message sent by a second preset number of consensus nodes, When a message is received, the consensus round is complete. The master node and multiple consensus nodes participating in the consensus process exchange pre-prepare messages, prepare messages, and commit messages, as well as verify messages at each stage of the consensus process. This allows for an efficient and secure consensus process, improving the system's fault tolerance and scalability, and ensuring the consistency and integrity of data across all nodes in the blockchain. If the master node does not fail, the consensus round is complete, the nodes update their reputations, and the next round of consensus begins. If the master node fails, a new master node is selected based on a random selection mechanism and consensus is re-run until the master node fails. This allows for rapid response to master node failures, provides a fault recovery method, and re-selects a new master node for consensus, improving overall fault tolerance and ensuring stable execution of the consensus process, thereby ensuring data consistency across all nodes.
[0063] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's description and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. An improved PBFT consensus method, characterized in that: Including steps: S1. Use the first PBFT consensus algorithm to update the initial reputation value of each node and select the master node, specifically including: Assigning an initial reputation value to each node, using the first PBFT consensus algorithm to conduct a preset number of rounds of consensus, and calculating and updating the initial reputation value of each node after each round of consensus according to the reputation evaluation mechanism; A set of candidate master nodes is obtained based on the reputation of each node, and a master node is selected from the candidate master node set using a random number node selection mechanism; S2. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client, and store the transaction information in the node memory pool corresponding to each node; S3. The consensus node sends a transaction receipt notification to the master node, where the transaction receipt notification includes a transaction hash. When the master node receives a first preset number of transaction receipt notifications, the master node sends a transaction confirmation message to the consensus node. If the consensus node does not receive the transaction confirmation message, the master node sends a request to obtain transaction confirmation information to the master node. Otherwise, the consensus node determines whether its own node memory pool contains the transaction information corresponding to the transaction confirmation message based on the transaction confirmation message. If not, the master node broadcasts a transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus.
2. An improved PBFT consensus method according to claim 1, characterized in that: The selecting a master node from the set of candidate master nodes using a random number node selection mechanism includes: The nodes in the candidate master node set are sorted based on the public keys to obtain a node sorting array, and a trusted third party generates a random number. The trusted third party performs a hash operation on the random number to obtain a first hash value, and broadcasts the first hash value to all candidate master nodes in the candidate master node set; When the candidate master node receives the first hash value, it queries the public key of the node in the middle position in the node sorting array, calculates a second hash value based on the first hash value and the public key, and performs a modulo operation on the second hash value to obtain a node value. The corresponding node in the node sorting array whose sequence number is consistent with the node value is used as the master node.
3. The improved PBFT consensus method according to claim 1, characterized in that: The step S3 comprises: The master node sends a pre-prepare message to the consensus nodes participating in the consensus process. If a consensus node receives the pre-prepare message, it checks the transaction information in the corresponding node memory pool and verifies the pre-prepare message. If the verification is successful, it broadcasts the pre-prepare message to other consensus nodes. If a consensus node receives a first preset number of prepare messages, it verifies the prepare messages, and if the verification passes, broadcasts the commit message to other consensus nodes; If a consensus node receives the submission message, it verifies the submission message, and when a first preset number of correct submission messages are received, it broadcasts a reply message to the client; When the client receives reply messages sent by the second preset number of consensus nodes, the round of consensus is completed.
4. The improved PBFT consensus method according to claim 3, characterized in that: The step S3 further includes: If the master node does not have any errors, the consensus round is completed, the node updates its reputation value, and enters the next round of consensus; If an error occurs in the master node, the master node will be reselected based on a random selection mechanism and consensus will be re-performed until no error occurs in the master node.
5. An improved PBFT consensus terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: S1. Use the first PBFT consensus algorithm to update the initial reputation value of each node and select the master node, specifically including: Assigning an initial reputation value to each node, using the first PBFT consensus algorithm to conduct a preset number of rounds of consensus, and calculating and updating the initial reputation value of each node after each round of consensus according to the reputation evaluation mechanism; A set of candidate master nodes is obtained based on the reputation of each node, and a master node is selected from the candidate master node set using a random number node selection mechanism; S2. The master node and all consensus nodes participating in the consensus process receive the transaction information sent by the client, and store the transaction information in the node memory pool corresponding to each node; S3. The consensus node sends a transaction receipt notification to the master node, where the transaction receipt notification includes a transaction hash. When the master node receives a first preset number of transaction receipt notifications, the master node sends a transaction confirmation message to the consensus node. If the consensus node does not receive the transaction confirmation message, the master node sends a request to obtain transaction confirmation information to the master node. Otherwise, the consensus node determines whether its own node memory pool contains the transaction information corresponding to the transaction confirmation message based on the transaction confirmation message. If not, the master node broadcasts a transaction request to the node containing the transaction information to obtain the transaction information. The master node constructs a candidate block and puts the transaction hash into the candidate block. The master node broadcasts the candidate block and uses the second PBFT consensus algorithm for consensus.
6. An improved PBFT consensus terminal according to claim 5, characterized in that: The selecting a master node from the set of candidate master nodes using a random number node selection mechanism includes: The nodes in the candidate master node set are sorted based on the public keys to obtain a node sorting array, and a trusted third party generates a random number. The trusted third party performs a hash operation on the random number to obtain a first hash value, and broadcasts the first hash value to all candidate master nodes in the candidate master node set; When the candidate master node receives the first hash value, it queries the public key of the node in the middle position in the node sorting array, calculates a second hash value based on the first hash value and the public key, and performs a modulo operation on the second hash value to obtain a node value. The corresponding node in the node sorting array whose sequence number is consistent with the node value is used as the master node.
7. An improved PBFT consensus terminal according to claim 5, characterized in that: The step S3 comprises: The master node sends a pre-prepare message to the consensus nodes participating in the consensus process. If a consensus node receives the pre-prepare message, it checks the transaction information in the corresponding node memory pool and verifies the pre-prepare message. If the verification is successful, it broadcasts the pre-prepare message to other consensus nodes. If a consensus node receives a first preset number of prepare messages, it verifies the prepare messages, and if the verification passes, broadcasts the commit message to other consensus nodes; If a consensus node receives the submission message, it verifies the submission message, and when a first preset number of correct submission messages are received, it broadcasts a reply message to the client; When the client receives reply messages sent by the second preset number of consensus nodes, the round of consensus is completed.
8. An improved PBFT consensus terminal according to claim 7, characterized in that: The step S3 further includes: If the master node does not have any errors, the consensus round is completed, the node updates its reputation value, and enters the next round of consensus; If an error occurs in the master node, the master node will be reselected based on a random selection mechanism and consensus will be re-performed until no error occurs in the master node.