A blockchain consensus method and device based on Raft algorithm

By dividing blockchain nodes into management nodes and member nodes, and using periodic heartbeat notification broadcast and timer mechanisms, the problem that the existing Raft algorithm cannot meet the needs of management nodes is solved, and the correct management of management nodes and blocks are achieved. stable operation of the chain.

CN111813790BActive Publication Date: 2024-09-06SHANGHAI SHENTIE INFORMATION ENG
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010545769.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-16
Publication Date
2024-09-06
Estimated Expiration
2040-06-16

AI Technical Summary

Technical Problem

The existing blockchain consensus method based on the Raft algorithm cannot guarantee that the management node can manage the blockchain and each node when needed. Especially in alliance chain and private chain applications, the leader node is responsible for daily accounting but does not have the ability to do so. Highest administrative authority.

Method used

The nodes in the blockchain are divided into management nodes and member nodes. The management node takes over transaction events and blockchain status updates through periodic heartbeat notification broadcasts, ensuring that nodes with the highest management authority can manage when needed, and through scheduled The server and application layer software configuration implements state transition and conflict handling.

Benefits of technology

It realizes that while meeting the daily accounting requirements of the blockchain, the management node can effectively manage the blockchain and nodes, ensuring the correct application of management permissions and the stability of the blockchain system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111813790B
    Figure CN111813790B
Patent Text Reader

Abstract

The present invention relates to a blockchain consensus method based on the Raft algorithm, which specifically includes the following steps: step S1: dividing the nodes in the blockchain into management nodes and member nodes, the states of the member nodes and the management nodes include followers, candidates or leaders, and the state of the management nodes also includes managers; step S2: the management nodes and the member nodes are elected based on the conventional Raft algorithm, and the leader is elected to record transaction events and generate transaction blocks; step S3: when the management node is converted to a manager, a periodic heartbeat notification broadcast is sent, the member node is converted to a follower, and the management node takes over the work of the leader node; step S4: when the management node exits the manager, it is switched to a follower, stops sending periodic heartbeat notification broadcasts, the member node is converted to a candidate, and goes to step S2. Compared with the prior art, the present invention has the advantages that the management node can record transaction events and generate transaction blocks at the same time, and is convenient for unified management.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain, and in particular to a blockchain consensus method and device based on the Raft algorithm. Background Art

[0002] Currently, the most widely used consensus algorithms in blockchain technology are PoW algorithm, PBFT algorithm and Raft algorithm.

[0003] The Proof of Work algorithm PoW is used to confirm that a node has done a certain amount of work. It is a very successful consensus algorithm in the Bitcoin system. Based on the PoW algorithm, the PoS algorithm and the DPoS algorithm were derived.

[0004] The practical Byzantine fault-tolerant algorithm PBFT enables the Byzantine fault-tolerant algorithm to achieve an efficiency acceptable to engineering in practical applications, and the number of fault-tolerant nodes is N / 3-1.

[0005] The Raft algorithm is an engineering implementation of the Paxos algorithm, which reduces the complexity of the Paxos algorithm. The Raft algorithm mainly optimizes the Paxos algorithm in two aspects. First, the in-chain requests sent by the leader node of the Raft algorithm are continuous; second, Raft restricts the leader node election algorithm, and only the node with the latest log can become the leader. The number of fault-tolerant nodes of Raft is N / 2-1.

[0006] In the blockchain applications of alliance chains and private chains, PBFT and Raft are commonly used algorithms. The Raft algorithm has higher security requirements for nodes than the PBFT algorithm. The Raft algorithm requires that node errors cannot be Byzantine errors, which is not a high requirement in alliance chain and private chain applications. At the same time, the Raft algorithm is simpler and more efficient than the PBFT algorithm. Therefore, the Raft algorithm is widely used in alliance chain and private chain applications.

[0007] However, in many consortium chain and private chain application scenarios, the leader node elected by the Raft algorithm is the node responsible for daily continuous accounting, not the node with the highest management authority; the node with the highest management authority is generally not responsible for daily continuous accounting, but needs to change the status of each node when necessary. Therefore, a consensus algorithm that amends the Raft algorithm is needed to meet the above blockchain application requirements.

[0008] The prior art discloses a blockchain consensus method based on the RAFT algorithm applied to a distributed new energy system, which divides consensus nodes into candidate groups and follower groups according to reliability; and selects a consensus node in the leader state from the candidate group through an initial election process based on the RAFT algorithm. Directly classifying the candidate group and the follower group from the consensus nodes, and using the RAFT algorithm to elect the leader node under this classification, cannot guarantee that the management node can manage the blockchain and each node when needed. Summary of the invention

[0009] The purpose of the present invention is to provide a blockchain consensus method and device based on the Raft algorithm in order to overcome the defect of the above-mentioned prior art that the management node cannot ensure that the management node can manage the blockchain and each node when needed.

[0010] The purpose of the present invention can be achieved by the following technical solutions:

[0011] A blockchain consensus method based on the Raft algorithm specifically includes the following steps:

[0012] Step S1: Divide the nodes in the blockchain into management nodes and member nodes, the member node status includes follower, candidate or leader, and the management node status includes follower, candidate, leader or manager;

[0013] Step S2: The management node is not initially in the manager state. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node that is elected as the leader is responsible for recording transaction events and generating transaction blocks.

[0014] Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts;

[0015] Step S4: When the management node exits the manager state, the corresponding state switches to follower, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts is converted from follower to candidate, and the process goes to step S2.

[0016] The management nodes and member nodes are classified into management nodes and member nodes by identifying them according to the node type, node name, IP address and port number.

[0017] The management nodes and member nodes are classified into management nodes and member nodes by node name, IP address, port number and public key password.

[0018] The number of the management nodes is 1 or more.

[0019] Furthermore, at most one management node can be converted to a manager at the same time.

[0020] Furthermore, the transition of the management node from other states to the manager is determined by the application layer software configuration.

[0021] The status information of the blockchain updated by the periodic heartbeat broadcast in step S3 includes the setting of the management node, the addition and deletion of member nodes, the status of the member nodes in the Raft regular algorithm, and the designation of the next leader in the Raft regular algorithm.

[0022] Furthermore, the status information of the blockchain updated by the periodic heartbeat broadcast in step S3 also includes the update of the blockchain and the clearing of the blockchain.

[0023] The sending frequency of the periodic heartbeat broadcast is determined by the application layer software configuration.

[0024] The member node is provided with a timer. In step S4, each time the member node receives a periodic heartbeat notification broadcast, the timer is cleared and starts timing. When the recorded time of the timer is greater than the broadcast interval threshold, the state of the member node is converted from a follower to a candidate.

[0025] A device using a blockchain consensus method based on a Raft algorithm, comprising a memory and a processor, wherein the computer program is stored in the memory and executed by the processor, and the following steps are implemented during execution:

[0026] Step S1: Divide the nodes in the blockchain into management nodes and member nodes, the member node status includes follower, candidate or leader, and the management node status includes follower, candidate, leader or manager;

[0027] Step S2: The management node is not initially in the manager state. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node that is elected as the leader is responsible for recording transaction events and generating transaction blocks.

[0028] Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts;

[0029] Step S4: When the management node exits the manager state, the corresponding state switches to follower, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts is converted from follower to candidate, and the process goes to step S2.

[0030] Compared with the prior art, the present invention divides the nodes in the blockchain into management nodes and member nodes in advance, limits the management nodes with management authority, and takes over recording transaction events and generating transaction blocks after the status of the management node is converted to manager, so that the management node with the highest management authority has the functions of recording transaction events and generating transaction blocks at the same time. While meeting the daily accounting of the blockchain based on the conventional Raft algorithm, it also meets the needs of managing the blockchain and each node, and facilitates unified management of the nodes. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0032] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.

[0033] Embodiment 1

[0034] like Figure 1 As shown, a blockchain consensus method based on the Raft algorithm not only meets the daily accounting of the blockchain based on the conventional Raft algorithm, but also meets the needs of managing the blockchain and each node. Specifically, it includes the following steps:

[0035] Step S1: Divide the nodes in the blockchain into management nodes and member nodes. The states of member nodes include follower, candidate or leader. The states of manager nodes include follower, candidate, leader or manager.

[0036] Step S2: The initial status of the management node is not a manager. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node elected as the leader is responsible for recording transaction events and generating transaction blocks.

[0037] Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts;

[0038] Step S4: When the management node exits the manager state, the corresponding state switches to follower, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts switches from follower to candidate, and the process goes to step S2.

[0039] The management nodes and member nodes are classified according to the node type, node name, IP address and port number.

[0040] The number of management nodes is 1 or more, and at most one management node can be converted to manager at the same time.

[0041] The transition of a management node from other states to a manager is determined by the application layer software configuration.

[0042] The status information of the blockchain updated by the periodic heartbeat broadcast in step S3 includes the settings of the management node, the addition and deletion of member nodes, the status of the member nodes in the Raft regular algorithm, and the designation of the next leader in the Raft regular algorithm.

[0043] The status information of the blockchain updated by the periodic heartbeat broadcast in step S3 also includes the update of the blockchain and the clearing of the blockchain.

[0044] The frequency of sending periodic heartbeat broadcasts is determined by the application layer software configuration.

[0045] A timer is set in the member node. In step S4, each time the member node receives a periodic heartbeat notification broadcast, the timer is cleared and starts timing. When the recorded time of the timer is greater than the broadcast interval threshold, the state of the member node is converted from follower to candidate.

[0046] The content of the periodic heartbeat notification broadcast includes the information of the management node identification and the management node status. The member node knows that the broadcast is a periodic heartbeat notification broadcast based on the information of the management node identification and the management node status, and executes the instructions for updating the status information of the blockchain contained in the periodic heartbeat notification broadcast.

[0047] If the leader state node of the conventional Raft algorithm fails to receive the periodic heartbeat notification broadcast from the management node due to a fault, the system will have two nodes, the management node and the original leader state node, that record transaction events and generate transaction blocks. This conflict will be reported to the application layer software, and the application layer software will continue to configure the state of the management node as the manager state, and update various states of the blockchain through periodic heartbeat broadcasts until the conflict is eliminated, allowing the blockchain system to reach a new consensus state.

[0048] A device using a blockchain consensus method based on a Raft algorithm includes a memory and a processor, which is stored in the memory in the form of a computer program and executed by the processor, and implements the following steps during execution:

[0049] Step S1: Divide the nodes in the blockchain into management nodes and member nodes. The states of member nodes include follower, candidate or leader. The states of manager nodes include follower, candidate, leader or manager.

[0050] Step S2: The initial status of the management node is not a manager. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node elected as the leader is responsible for recording transaction events and generating transaction blocks.

[0051] Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts;

[0052] Step S4: When the management node exits the manager state, the corresponding state switches to follower, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts switches from follower to candidate, and the process goes to step S2.

[0053] Embodiment 2

[0054] The classification method of management nodes and member nodes is to identify them according to node type, node name, IP address, port number and public key password, and to classify them into management nodes and member nodes by node name, IP address, port number and signature based on private key. The rest is the same as the first embodiment.

[0055] In addition, it should be noted that the specific embodiments described in this specification may be named differently, and the above contents described in this specification are merely examples of the structure of the present invention. Any equivalent changes or simple changes made based on the structure, features and principles of the present invention are included in the protection scope of the present invention. Those skilled in the art of the present invention may make various modifications or supplements to the specific examples described or adopt similar methods, as long as they do not deviate from the structure of the present invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.

Claims

1. A blockchain consensus method based on the Raft algorithm, characterized in that: The specific steps include: Step S1: Divide the nodes in the blockchain into management nodes and member nodes, the member node status includes follower, candidate or leader, and the management node status includes follower, candidate, leader or manager; Step S2: The management node is not initially in the manager state. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node that is elected as the leader is responsible for recording transaction events and generating transaction blocks. Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts; Step S4: When the management node exits the manager state, the corresponding state is switched to the follower state, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts is switched from follower to candidate state, and the process goes to step S2; If the leader state node of the conventional Raft algorithm fails, the system has a management node and the original leader state node, a total of two nodes that record transaction events and generate transaction blocks, and report this conflict to the application layer software; The application layer software continuously configures the status of the management node to the manager status, and updates various states of the blockchain through periodic heartbeat broadcasts until the conflict is eliminated and the blockchain system reaches a new consensus state.

2. According to a blockchain consensus method based on the Raft algorithm according to claim 1, it is characterized in that: The management nodes and member nodes are classified into management nodes and member nodes by identifying them according to the node type, node name, IP address and port number.

3. According to a blockchain consensus method based on the Raft algorithm according to claim 1, it is characterized in that: The management nodes and member nodes are classified into management nodes and member nodes by node name, IP address, port number and public key password.

4. According to a blockchain consensus method based on the Raft algorithm according to claim 1, it is characterized in that: The number of the management nodes is 1 or more.

5. According to a blockchain consensus method based on the Raft algorithm according to claim 4, it is characterized in that: At most one management node can be changed to manager at the same time.

6. According to a blockchain consensus method based on the Raft algorithm according to claim 1, it is characterized in that: The status information of the blockchain updated by the periodic heartbeat broadcast in step S3 includes the setting of the management node, the addition and deletion of member nodes, the status of the member nodes in the Raft regular algorithm, and the designation of the next leader in the Raft regular algorithm.

7. A blockchain consensus method based on the Raft algorithm according to claim 6, characterized in that: The status information of the blockchain updated by the periodic heartbeat broadcast in step S3 also includes the update of the blockchain and the clearing of the blockchain.

8. The blockchain consensus method based on the Raft algorithm according to claim 1 is characterized in that: The member node is provided with a timer. In step S4, each time the member node receives a periodic heartbeat notification broadcast, the timer is cleared and starts timing. When the recorded time of the timer is greater than the broadcast interval threshold, the state of the member node is converted from a follower to a candidate.

9. A device using a blockchain consensus method based on the Raft algorithm, characterized in that: The method comprises a memory and a processor, wherein the method is stored in the memory in the form of a computer program and executed by the processor, and the following steps are implemented during execution: Step S1: Divide the nodes in the blockchain into management nodes and member nodes, the member node status includes follower, candidate or leader, and the management node status includes follower, candidate, leader or manager; Step S2: The management node is not initially in the manager state. All management nodes and member nodes elect a leader based on the conventional Raft algorithm. The node that is elected as the leader is responsible for recording transaction events and generating transaction blocks. Step S3: When the status of the management node changes from non-manager to manager, a periodic heartbeat notification broadcast is sent, and the member nodes that receive the periodic heartbeat notification broadcast change their status to follower. The management node in the manager status takes over the recording of transaction events and generates transaction blocks, and updates the status information of the blockchain through periodic heartbeat broadcasts; Step S4: When the management node exits the manager state, the corresponding state is switched to the follower state, the management node stops sending periodic heartbeat notification broadcasts, and the state of the member nodes that no longer receive periodic heartbeat notification broadcasts is switched from follower to candidate state, and the process goes to step S2; If the leader state node of the conventional Raft algorithm fails, the system has a management node and the original leader state node, a total of two nodes that record transaction events and generate transaction blocks, and report this conflict to the application layer software; The application layer software continuously configures the status of the management node to the manager status, and updates various states of the blockchain through periodic heartbeat broadcasts until the conflict is eliminated and the blockchain system reaches a new consensus state.

10. A device for a blockchain consensus method using a Raft algorithm according to claim 9, characterized in that: The number of the management nodes is one or more, and at most one management node can be converted to a manager at the same time.