Consensus methods and systems in consortium chains

By introducing a checkpoint message mechanism into the alliance chain, the consensus node cannot complete the consensus caused by the client sending a large number of requests in a short time, and a more accurate view switching operation is achieved, avoiding system stagnation and improving the stability of the alliance chain.

CN113836232BActive Publication Date: 2024-11-29ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111122765.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-24
Publication Date
2024-11-29
Estimated Expiration
2041-09-24

AI Technical Summary

Technical Problem

In the alliance chain, the client sends a large number of requests in a short time, causing the consensus node to be unable to complete the consensus operation within the preset time period, which in turn triggers the view switching operation, causing the system to stagnate.

Method used

Introduce a checkpoint message mechanism. Consensus nodes broadcast checkpoint messages when generating a specified number of blocks. If checkpoint messages from other 2f consensus nodes are not received within the preset time period, it is determined that the stable checkpoint status timeout and triggers the view switching operation. , avoid extreme pressure and ensure accurate triggering of view switching.

Benefits of technology

Through the checkpoint message mechanism, consensus nodes can promptly trigger view switching operations to avoid system stagnation and improve the processing accuracy and stability of consensus nodes in the alliance chain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113836232B_ABST
    Figure CN113836232B_ABST
Patent Text Reader

Abstract

The present specification discloses a consensus method and system in a consortium chain, the method comprising: when a first consensus node in the consortium chain generates a specified number of blocks, the first consensus node broadcasts a checkpoint message in the consortium chain, the checkpoint message being used to indicate that the first consensus node has generated the specified number of blocks; the second consensus node in the consortium chain receives the checkpoint message sent by the first consensus node; if the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the consortium chain within a preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; the second consensus node initiates a view switching operation in the consortium chain based on the stable checkpoint state timeout of the second consensus node, where f is the maximum number of abnormal consensus nodes allowed in the consortium chain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This document relates to the field of computer technology, and in particular to a consensus method and system in a consortium chain. Background Art

[0002] At present, the Practical Byzantine Fault Tolerance (PBFT) algorithm mainly includes two parts, namely the Normal Case Phase and the View Change Phase. Among them, the Normal Case Phase includes request, pre-prepare, prepare, commit, and reply to complete the consensus. Among them, request and reply correspond to the transaction request initiated by the client and the transaction execution result returned to the client.

[0003] In the prior art, the consensus node usually starts a timer after receiving a request from the client. If the client does not receive f+1 replies to its requests within a preset time period, a view switching operation can be triggered. However, since the request is sent by the client and is a behavior of the client, if the client sends a large number of requests to the consensus node in a short period of time, the consensus node will not be able to complete the consensus operation on the request within the preset time period, thereby triggering a view switching operation. Summary of the invention

[0004] The embodiments of this specification provide a consensus method and system in a consortium chain to solve the problem in the existing consortium chain that if the client sends a large number of requests to the consensus node in a short period of time, the consensus node will not be able to complete the consensus operation of the request within a preset time period, thereby triggering a view switching operation.

[0005] To solve the above technical problems, the embodiments of this specification are implemented as follows:

[0006] First, a consensus method in the alliance chain is proposed, including:

[0007] When the first consensus node in the alliance chain generates a specified number of blocks, it broadcasts a checkpoint message in the alliance chain, where the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks;

[0008] The second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node;

[0009] If the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within the preset time period, the second consensus node determines that the stablecheckpoint state of the second consensus node has timed out;

[0010] The second consensus node initiates a view switching operation in the alliance chain based on the timeout of the stable checkpoint state of the second consensus node, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0011] Secondly, a consortium chain system is proposed, including:

[0012] The first consensus node, when generating a specified number of blocks, broadcasts a checkpoint message in the consortium chain, wherein the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks;

[0013] The second consensus node receives the checkpoint message sent by the first consensus node. If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within a preset time period, it is determined that the stable checkpoint state of the second consensus node has timed out; and based on the stable checkpoint state timeout of the second consensus node, a view switching operation is initiated in the alliance chain, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0014] Thirdly, a consensus node in the alliance chain is proposed, including:

[0015] A broadcast module, which broadcasts a checkpoint message in the consortium chain when a specified number of blocks are generated, wherein the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0016] A receiving module, receiving checkpoint messages sent by other consensus nodes in the alliance chain;

[0017] The state determination module determines that the stable checkpoint state has timed out if no checkpoint message is received from the other 2f consensus nodes in the alliance chain within a preset time period;

[0018] The view switching module initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0019] In a fourth aspect, an electronic device is provided, comprising:

[0020] Processor; and

[0021] a memory arranged to store computer executable instructions which, when executed, cause the processor to:

[0022] When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0023] Receive checkpoint messages sent by other consensus nodes in the alliance chain;

[0024] If no checkpoint message is received from the other 2f consensus nodes in the alliance chain within the preset time period, it is determined that the stable checkpoint state has timed out;

[0025] Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0026] In a fifth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by an electronic device including a plurality of application programs, the electronic device performs the following operations:

[0027] When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0028] Receive checkpoint messages sent by other consensus nodes in the alliance chain;

[0029] If no checkpoint message is received from the other 2f consensus nodes in the alliance chain within the preset time period, it is determined that the stable checkpoint state has timed out;

[0030] Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0031] The embodiments of this specification adopt the above technical solutions to achieve at least the following technical effects:

[0032] Using the consensus method provided in the embodiment of this specification, when the first consensus node in the alliance chain generates a specified number of blocks, the checkpoint message is broadcast in the alliance chain, and the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks; the second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node; if the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within the preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; and the second consensus node initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout of the second consensus node, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain. Since the consensus node can use a single thread to count the checkpoint messages received from other consensus nodes in the alliance chain, it can avoid causing great pressure on the consensus node at a certain moment, thereby enabling the consensus node to trigger the view switching operation in the alliance chain more accurately. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:

[0034] Figure 1 A schematic diagram of the implementation flow of a consensus method in a consortium chain provided in one embodiment of this specification.

[0035] Figure 2 A schematic diagram of an implementation flow of an application of a consensus method in a consortium chain provided in one embodiment of this specification.

[0036] Figure 3 A schematic diagram of the structure of a consortium chain system provided for one embodiment of this specification.

[0037] Figure 4 A schematic diagram of the structure of a consensus node in a consortium chain provided for one embodiment of this specification.

[0038] Figure 5 A schematic diagram of the structure of an electronic device provided in one embodiment of this specification. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solutions and advantages of this document clearer, the technical solutions of this specification will be clearly and completely described in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this document, not all of them. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this document.

[0040] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.

[0041] In the process of consensus using the PBFT algorithm in the alliance chain, each Replica (i.e., all consensus nodes participating in the consensus in the alliance chain) will record in the message log of the memory of the consensus node when sending a message or receiving a message from other consensus nodes (including pre-prepare, prepare, and commit messages). As the consensus operation in the alliance chain continues, the Message Log of each consensus node in the alliance chain will occupy more and more memory space. Therefore, in order to save the memory space of each consensus node in the alliance chain, garbage collection is required, that is, when each consensus node executes propose, the Message Log of each consensus node is cleared to release the memory space of each consensus node.

[0042] One way of garbage collection is that every time a consensus node in the alliance chain executes a propose (that is, every time a block is generated), it can broadcast to other consensus nodes in the alliance chain to reach a consensus on whether the Message Log of this consensus node can be cleared. After receiving such broadcasts, each consensus node in the alliance chain can also broadcast to other consensus nodes in the alliance chain to reach a consensus on whether the Message Log of this consensus node can be cleared. If a consensus node in the alliance chain receives confirmations from different consensus nodes in Quorum (2f+1), these consensus nodes can delete the message record corresponding to a propose (that is, the latest generated block) in the Message Log of this consensus node.

[0043] Another way to deal with garbage is that every time a consensus node in the alliance chain executes k proposals (that is, every time k new blocks are generated), it can broadcast to other consensus nodes in the alliance chain to reach a consensus on whether the Message Log of this consensus node can be cleared. After receiving such broadcasts, each consensus node in the alliance chain can also broadcast to other consensus nodes in the alliance chain to reach a consensus on whether the MessageLog of this consensus node can be cleared. If a consensus node in the alliance chain receives confirmations from different consensus nodes of Quorum (2f+1), these consensus nodes can delete the message records corresponding to the k proposals (that is, the latest k blocks generated) in the Message Log of this consensus node.

[0044] Wherein, k is the message record corresponding to the k proposals (i.e., the latest k generated blocks) deleted by the checkpoint message in the embodiment of this specification. The message log cleared from this consensus node is the checkpoint message in the embodiment of this specification, and the format is<CHECKPOINT,n,d,i> , where n is the sequence number of the smallest block that the consensus node currently expects to retain, d is the message digest that is expected to be retained, and i is the number of the consensus node that issued the checkpoint message.

[0045] The checkpoint messages broadcasted by the consensus nodes in the above alliance chain and the summaries of the checkpoint messages received are recorded in the Message Log of this consensus node. If consensus node i in the alliance chain receives Quorum-1 legal checkpoint messages sent by other different consensus nodes, plus the checkpoint message sent by consensus node i itself, then consensus node i will<n,d> The checkpoint messages have reached the Quorum (2f+1) number. At this time, consensus node i can clear the message records corresponding to all blocks before block number n in the Message Log of this consensus node (including pre-prepare, prepare, commit messages and checkpoint messages corresponding to blocks before block number n).

[0046] The block number n mentioned above is the current stable checkpoint of consensus node i, which means that consensus node i has reached a consensus on the execution results of the blocks before block number n, and the message records corresponding to the block number n are still retained in the Message Log of consensus node i. Since the processing of each consensus node in the alliance chain system is asynchronous, the consensus node with fast consensus message processing may gradually distance itself from the consensus node with slow consensus message processing. The speed of message processing can be limited by setting high and low water levels: H = h + L, where H is the high water level, L is the low water level, and h is the set value, which is generally the value of n of the stable checkpoint. In this way, the processing speed of the fast consensus node can be controlled. When the n value of the consensus message it processes reaches the high water level H, it will wait until the stable checkpoint changes before continuing to process.

[0047] Therefore, if the stable checkpoint does not change, the consensus nodes in the alliance chain will not be able to process the next propose, and the high and low water levels that limit the speed of message processing will not change, which will cause the consensus nodes in the alliance chain to stagnate.

[0048] In order to solve this problem, the embodiment of this specification is to broadcast a checkpoint message in the alliance chain when the first consensus node in the alliance chain generates a specified number of blocks, and the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks; the second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node; if the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within a preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; and the second consensus node initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout of the second consensus node, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain. Since the consensus nodes in the alliance chain can trigger the view switching operation in time after the stable checkpoint state times out, so as to replace the consensus master node in the alliance chain and restart the consensus operation, the situation where all consensus nodes in the alliance chain are stagnant can be avoided.

[0049] In addition, if any request sent by the client to the consensus node in the alliance chain can successfully reach a consensus, it will eventually reach a consensus in the alliance chain and broadcast a commit message to the entire network. After the consensus node reaches a consensus on a request in the alliance chain, it will send a checkpoint message to other nodes so that garbage collection can be performed after 2f+1 nodes in the alliance chain reach a consensus on the same request, and the state of the consensus node will be changed to a stable checkpoint state. Therefore, if the stable checkpoint state of a consensus node in the alliance chain times out, it can also reflect that the request sent by the client to the consensus node has timed out.

[0050] Based on this, and considering that each consensus node in the alliance chain can process checkpoint messages as a separate thread, the embodiments of this specification propose to trigger a view switching operation in the alliance chain based on the stable checkpoint state timeout of the consensus node.

[0051] Specifically, a schematic diagram of the implementation process of a consensus method in a consortium chain provided by one or more embodiments of this specification is as follows: Figure 1 As shown, including:

[0052] Step 110, when the first consensus node in the alliance chain generates a specified number of blocks, it broadcasts a checkpoint message in the alliance chain, and the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks.

[0053] Among them, when the first consensus node generates a specified number of blocks, the purpose of broadcasting the checkpoint message in the alliance chain is to reach a consensus in the entire network on whether the Message Log can be cleared.

[0054] Optionally, in order to facilitate determining which blocks in the Message Log correspond to the message records to be cleared, the first consensus node broadcasts a checkpoint message in the consortium chain, including:

[0055] The first consensus node broadcasts a checkpoint message in the alliance chain based on the block number n of the block with the largest sequence number among the specified number of blocks. The checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.

[0056] The purpose of carrying the block number n of the block with the largest sequence number among the specified number of blocks in the checkpoint message is to reach a consensus in the entire network on whether the message records corresponding to the blocks before block number n in the Message Log can be cleared.

[0057] It should be understood that if the consensus node receives a Quorum-1 legal checkpoint message sent by different nodes, plus the checkpoint message sent by itself, it means that the consensus node has collected a Quorum number of checkpoint messages, and can achieve a stable checkpoint, and then can perform garbage cleaning on the message records corresponding to the blocks before block number n in the Message Log. Specifically, after the first consensus node broadcasts the checkpoint message in the alliance chain, the method provided in the embodiment of this specification also includes:

[0058] When the second consensus node generates a specified number of blocks, the second consensus node broadcasts a checkpoint message carrying the block number n of the block with the largest sequence number among the specified number of blocks in the alliance chain. The checkpoint message broadcast by the second consensus node is used to indicate that the second consensus node has generated the specified number of blocks;

[0059] The first consensus node receives the checkpoint message sent by the second consensus node;

[0060] When the first consensus node receives checkpoint messages from 2f consensus nodes in the alliance chain within a preset time period, the first consensus node clears the message records corresponding to the blocks before the block with the largest sequence number among the specified number of blocks in the first consensus node;

[0061] The first consensus node changes the state of the first consensus node to a stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.

[0062] Optionally, the above specified number is a positive integer greater than or equal to 1.

[0063] Optionally, a method for triggering a view switching operation provided in an embodiment of this specification is that when the specified number is 1, after the first consensus node changes the state of the first consensus node to a stable checkpoint, the method provided in an embodiment of this specification further includes:

[0064] The first consensus node starts the timer;

[0065] If the first consensus node does not receive a checkpoint message carrying block number n+1 from the other 2f consensus nodes in the alliance chain within a preset time period after the timer is started, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out;

[0066] The first consensus node triggers a view switching operation in the alliance chain based on the timeout of the stable checkpoint state of the first consensus node.

[0067] After the first consensus node in the alliance chain executes a propose (that is, each time a block is generated), it can broadcast a checkpoint message to other consensus nodes in the alliance chain, and reach a consensus on whether the message log of this consensus node can be cleared in the whole network. After receiving the checkpoint message, other consensus nodes in the alliance chain can also broadcast the checkpoint message to other consensus nodes in the alliance chain, and reach a consensus on whether the message log of this consensus node can be cleared in the whole network. If the first consensus node in the alliance chain receives confirmations from different consensus nodes of Quorum (2f+1) within the preset time period, the first consensus node can modify the state of the consensus node to stable checkpoint. At this time, the first consensus node in the alliance chain can restart the timer. If the first consensus node does not receive the checkpoint message carrying the block number n+1 from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that its stable checkpoint state has timed out, and can trigger a view switching operation in the alliance chain based on the stable checkpoint state timeout.

[0068] Optionally, another method of triggering a view switching operation provided by an embodiment of this specification is that when the specified number is a positive integer k greater than 1, after the first consensus node changes the state of the first consensus node to a stable checkpoint, the method further includes:

[0069] The first consensus node starts the timer;

[0070] If the first consensus node does not receive a checkpoint message carrying a block number of n+k from the other 2f consensus nodes in the alliance chain within a preset time period after the timer is started, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out;

[0071] The first consensus node triggers a view switching operation in the alliance chain based on the timeout of the stable checkpoint state of the first consensus node.

[0072] After the first consensus node in the alliance chain executes k proposes (that is, every time k blocks are generated), it can broadcast a checkpoint message to other consensus nodes in the alliance chain, and reach a consensus on whether the MessageLog of this consensus node can be cleared in the whole network. After receiving the checkpoint message, other consensus nodes in the alliance chain can also broadcast a checkpoint message to other consensus nodes in the alliance chain, and reach a consensus on whether the MessageLog of this consensus node can be cleared in the whole network. If the first consensus node in the alliance chain receives confirmations from different consensus nodes of Quorum (2f+1) within a preset time period, the first consensus node can modify the state of the consensus node to stablecheckpoint. At this time, the first consensus node in the alliance chain can restart the timer. If the first consensus node does not receive a checkpoint message carrying a block number of n+k from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that its stable checkpoint state has timed out, and can trigger a view switching operation in the alliance chain based on the stable checkpoint state timeout.

[0073] Step 120: The second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node.

[0074] When the second consensus node in the alliance chain generates a specified number of blocks, it can also broadcast a checkpoint message in the alliance chain. The checkpoint message is used to indicate that the second consensus node has generated a specified number of blocks. When the second consensus node broadcasts the checkpoint message in the alliance chain, it will also receive the checkpoint messages sent by the first consensus node and other consensus nodes in the alliance chain.

[0075] Step 130: If the second consensus node does not receive a checkpoint message sent by the other 2f consensus nodes in the alliance chain within a preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out.

[0076] The duration of the preset time period is the duration of the timer set locally on the second consensus node to trigger the timeout. If the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within the preset time period, the second consensus node cannot collect the quorum number of checkpoint messages, and cannot reach a stable checkpoint, and thus cannot perform garbage cleaning operations on the Message Log in this consensus node. In this embodiment of the specification, the state in which the consensus node cannot reach a stable checkpoint is referred to as a stable checkpoint state timeout.

[0077] Step 140: The second consensus node initiates a view switching operation in the alliance chain based on the timeout of the stable checkpoint state of the second consensus node, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0078] When the stable checkpoint status of the second consensus node times out, it means that the stable checkpoint of the second consensus node cannot be updated, which means that the second consensus node cannot continue the consensus operation on propose. At this time, in order to change this situation, the second consensus node can initiate a view switching operation in the alliance chain based on the timeout of its local stable checkpoint status, in an attempt to replace the consensus master node in the alliance chain.

[0079] It should be noted that the consensus algorithm in the embodiments of this specification can be applied to the RAFT algorithm, in addition to the PBFT algorithm, and other consensus algorithms that can distinguish between the consensus master node and the consensus backup node. The embodiments of this specification do not specifically limit the consensus algorithm used, as long as the consensus algorithm used has a consensus master node.

[0080] Below Figure 2 The schematic diagram of the process of using the PBFT algorithm to perform consensus operations is shown in the figure, which describes in detail the consensus method provided in the embodiments of this specification. Figure 2 In the figure, C is the client, consensus node 0 is the consensus master node during this consensus operation, and consensus nodes 1 to 3 are the consensus backup nodes during this consensus operation. Figure 2 The schematic diagram shown includes the following cases:

[0081] In the first case, consensus node 0 is a malicious node. Consensus node 0 deceives consensus node 1 and consensus node 2 to perform the consensus operation on the client's consensus request message m ( Figure 2 The solid line part shown), while consensus node 0 itself and consensus node 3 do not perform the consensus operation on the client's consensus request message m ( Figure 2 The dashed part shown in the figure). Even if consensus node 0 continues to do evil, as it continuously processes message m, on the one hand, consensus node 3 does not perform any consensus operation, and its local timer will time out after the set time period, thereby triggering a view switching operation in the alliance chain; on the other hand, although consensus node 1 and consensus node 2 have performed the consensus operation on m, consensus node 1 and consensus node 2 will reach the checkpoint after completing the consensus operation on m, thereby broadcasting the checkpoint message in the alliance chain, but since consensus node 0 and consensus node 3 have not performed the consensus operation on m, they will not reach the checkpoint, and will not broadcast the checkpoint message in the alliance chain, which makes it impossible for consensus node 1 and consensus node 2 to collect the quorum number of checkpoint messages and reach a stable checkpoint. Furthermore, consensus node 1 and consensus node 2 will no longer continue to execute after reaching the high water mark, and the local timers of consensus node 1 and consensus node 2 will also time out after the set time period, thereby triggering a view switching operation.

[0082] In the second case, if consensus node 0 continues to act maliciously as in the first case, the local timer of consensus node 3 will also time out, thereby initiating a view switching operation in the alliance chain. At the same time, since consensus node 1 and consensus node 2 have not been able to reach a stable checkpoint in the first case, that is, the stable checkpoint state has timed out, consensus node 1 and consensus node 2 will also trigger a view switching operation in the alliance chain, and then the quorum number of view switching operations can be achieved, completing the master change.

[0083] In the third case, in the alliance chain network, every time a consensus node generates a block, it can broadcast the block message to other consensus nodes through the P2P protocol. The consensus nodes that receive the broadcast block message, such as Figure 2 Consensus node 3 in the block finds that the block height in the block message is higher than the highest block height in its local area, it will synchronize the latest block from consensus node 1 or consensus node 2 (the block already has 2f+1 signatures, which can be pushed or pulled from consensus node 1 or consensus node 2, regardless of the block height of consensus node 0), thereby maintaining synchronization with consensus node 1 or consensus node 2.

[0084] Using the consensus method provided in the embodiment of this specification, when the first consensus node in the alliance chain generates a specified number of blocks, the checkpoint message is broadcast in the alliance chain, and the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks; the second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node; if the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within the preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; and the second consensus node initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout of the second consensus node, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain. Since the consensus node can use a single thread to count the checkpoint messages received from other consensus nodes in the alliance chain, it can avoid causing great pressure on the consensus node at a certain moment, thereby enabling the consensus node to trigger the view switching operation in the alliance chain more accurately.

[0085] Figure 3 This is a schematic diagram of the structure of the alliance chain system 300 provided in the embodiment of this specification. Please refer to Figure 3 In a software implementation, the alliance chain system 300 may include a first consensus node 310 and a second consensus node 320, wherein:

[0086] The first consensus node 310, when generating a specified number of blocks, broadcasts a checkpoint message in the consortium chain, wherein the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks;

[0087] The second consensus node 320 receives the checkpoint message sent by the first consensus node. If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within a preset time period, it is determined that the stable checkpoint state of the second consensus node has timed out; and based on the stable checkpoint state timeout of the second consensus node, a view switching operation is initiated in the alliance chain, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0088] Optionally, in one implementation, the first consensus node 310 is used to:

[0089] Based on the block number n of the block with the largest sequence number among the specified number of blocks, a checkpoint message is broadcast in the alliance chain, and the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.

[0090] Optionally, in one embodiment, after the first consensus node broadcasts a checkpoint message in the alliance chain,

[0091] When the second consensus node generates the specified number of blocks, the second consensus node broadcasts a checkpoint message carrying the block number n of the block with the largest sequence number among the specified number of blocks in the alliance chain, and the checkpoint message broadcast by the second consensus node is used to indicate that the second consensus node has generated the specified number of blocks;

[0092] The first consensus node receives a checkpoint message sent by the second consensus node;

[0093] When the first consensus node receives checkpoint messages from 2f consensus nodes in the alliance chain within the preset time period, the first consensus node clears the message records corresponding to the blocks before the block with the largest sequence number among the specified number of blocks in the first consensus node;

[0094] The first consensus node modifies the state of the first consensus node to a stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.

[0095] Optionally, in one implementation, the specified number is a positive integer greater than or equal to 1.

[0096] Optionally, in one implementation, when the specified number is 1, after the first consensus node changes the state of the first consensus node to a stable checkpoint, the method further includes:

[0097] The first consensus node starts a timer;

[0098] If the first consensus node does not receive a checkpoint message carrying a block number of n+1 from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out;

[0099] The first consensus node triggers a view switching operation in the alliance chain based on a timeout of a stable checkpoint state of the first consensus node.

[0100] Optionally, in one implementation, when the specified number is a positive integer k greater than 1, after the first consensus node changes the state of the first consensus node to a stable checkpoint, the method further includes:

[0101] The first consensus node starts a timer;

[0102] If the first consensus node does not receive a checkpoint message carrying a block number of n+k from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out;

[0103] The first consensus node triggers a view switching operation in the alliance chain based on a timeout of a stable checkpoint state of the first consensus node.

[0104] Optionally, in one implementation, the first consensus node is any consensus node in the alliance chain;

[0105] The second consensus node is any consensus node in the alliance chain.

[0106] Alliance chain system 300 can achieve Figure 1-2 For details, please refer to Figure 1-2 The consensus method in the alliance chain of the illustrated embodiment will not be described in detail.

[0107] Figure 4 This is a schematic diagram of the structure of a consensus node 400 in a consortium chain provided by an embodiment of this specification, including:

[0108] A broadcast module 410, when generating a specified number of blocks, broadcasts a checkpoint message in the alliance chain, wherein the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0109] A receiving module 420 receives checkpoint messages sent by other consensus nodes in the alliance chain;

[0110] The state determination module 430 determines that the stable checkpoint state has timed out if no checkpoint message sent by the other 2f consensus nodes in the alliance chain is received within a preset time period;

[0111] The view switching module 440 initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0112] Optionally, in one implementation, the broadcast module 410 is used to:

[0113] Based on the block number n of the block with the largest sequence number among the specified number of blocks, a checkpoint message is broadcast in the alliance chain, and the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.

[0114] Optionally, in one implementation, the state determination module 430 is further configured to:

[0115] When checkpoint messages from 2f consensus nodes in the alliance chain are received within the preset time period, the message records corresponding to the blocks before the block with the largest sequence number among the specified number of blocks in the consensus node are cleared;

[0116] Based on the block number n of the block with the largest sequence number among the specified number of blocks, the state of this consensus node is changed to stable checkpoint.

[0117] Optionally, in one implementation, the specified number is a positive integer greater than or equal to 1.

[0118] Optionally, in one implementation, when the specified number is 1, after the state determination module 430 modifies the state of the consensus node to a stable checkpoint, the view switching module 440 is further configured to:

[0119] Start the timer;

[0120] If within the preset time period after starting the timer, no checkpoint message carrying the block number n+1 is received from the other 2f consensus nodes in the alliance chain, it is determined that the stablecheckpoint state of the consensus node has timed out;

[0121] Based on the timeout of the stable checkpoint state of this consensus node, a view switching operation is triggered in the alliance chain.

[0122] Optionally, in one implementation, when the specified number is a positive integer k greater than 1, after the state determination module 430 modifies the state of the consensus node to a stable checkpoint, the view switching module 440 is further configured to:

[0123] Start the timer;

[0124] If within the preset time period after starting the timer, no checkpoint message carrying the block number n+k is received from the other 2f consensus nodes in the alliance chain, it is determined that the stablecheckpoint state of the consensus node has timed out;

[0125] Based on the timeout of the stable checkpoint state of this consensus node, a view switching operation is triggered in the alliance chain.

[0126] Optionally, in one implementation, the consensus node 400 in the alliance chain is any consensus node in the alliance chain.

[0127] The consensus node 400 in the alliance chain can achieve Figure 1 For details, please refer to Figure 1 The consensus method in the alliance chain of the illustrated embodiment will not be described in detail.

[0128] Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of this specification. Figure 5 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.

[0129] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0130] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.

[0131] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a blockchain system deployed by the consensus node in the alliance chain at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations:

[0132] When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0133] Receive checkpoint messages sent by other consensus nodes in the alliance chain;

[0134] If no checkpoint message is received from the other 2f consensus nodes in the alliance chain within the preset time period, it is determined that the stable checkpoint state has timed out;

[0135] Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0136] The above is as in this manual Figure 1The consensus method in the alliance chain disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or instructions in software form. The above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in one or more embodiments of this specification can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in conjunction with one or more embodiments of this specification can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0137] The electronic device may also perform Figure 1 The consensus method in the alliance chain will not be described in detail in this manual.

[0138] Of course, in addition to software implementation, the electronic device of this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0139] The embodiment of the present specification also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 5 The method of the embodiment shown is specifically used to perform the following operations:

[0140] When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated;

[0141] Receive checkpoint messages sent by other consensus nodes in the alliance chain;

[0142] If no checkpoint message is received from the other 2f consensus nodes in the alliance chain within the preset time period, it is determined that the stable checkpoint state has timed out;

[0143] Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

[0144] In short, the above description is only a preferred embodiment of this specification and is not intended to limit the protection scope of this specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification shall be included in the protection scope of one or more embodiments of this specification.

[0145] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0146] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0147] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0148] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

Claims

1. A consensus method in a consortium chain, comprising: When the first consensus node in the alliance chain generates a specified number of blocks, it broadcasts a checkpoint message in the alliance chain, where the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks; The second consensus node in the alliance chain receives the checkpoint message sent by the first consensus node; If the second consensus node does not receive the checkpoint message sent by the other 2f consensus nodes in the alliance chain within a preset time period, the second consensus node determines that the stablecheckpoint state of the second consensus node has timed out; the checkpoint message of the other 2f consensus nodes is sent in response to the checkpoint message of the first consensus node; The second consensus node initiates a view switching operation in the alliance chain based on the timeout of the stable checkpoint state of the second consensus node, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

2. According to the method of claim 1, the first consensus node broadcasts a checkpoint message in the alliance chain, comprising: The first consensus node broadcasts a checkpoint message in the alliance chain based on the block number n of the block with the largest sequence number among the specified number of blocks, and the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.

3. The method according to claim 2, after the first consensus node broadcasts the checkpoint message in the alliance chain, the method further comprises: When the second consensus node generates the specified number of blocks, the second consensus node broadcasts a checkpoint message carrying the block number n of the block with the largest sequence number among the specified number of blocks in the alliance chain, and the checkpoint message broadcast by the second consensus node is used to indicate that the second consensus node has generated the specified number of blocks; The first consensus node receives a checkpoint message sent by the second consensus node; When the first consensus node receives checkpoint messages from 2f consensus nodes in the alliance chain within the preset time period, the first consensus node clears the message records corresponding to the blocks before the block with the largest sequence number among the specified number of blocks in the first consensus node; The first consensus node modifies the state of the first consensus node to a stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks. The method according to claim 3 , wherein the specified number is a positive integer greater than or equal to 1.

5. According to the method of claim 4, when the specified number is 1, after the first consensus node changes the state of the first consensus node to a stable checkpoint, the method further comprises: The first consensus node starts a timer; If the first consensus node does not receive a checkpoint message carrying a block number of n+1 from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out; The first consensus node triggers a view switching operation in the alliance chain based on a timeout of a stable checkpoint state of the first consensus node.

6. The method of claim 4, when the specified number is a positive integer k greater than 1, after the first consensus node modifies the state of the first consensus node to a stable checkpoint, the method further comprises: The first consensus node starts a timer; If the first consensus node does not receive a checkpoint message carrying a block number of n+k from the other 2f consensus nodes in the alliance chain within the preset time period after starting the timer, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out; The first consensus node triggers a view switching operation in the alliance chain based on a timeout of a stable checkpoint state of the first consensus node.

7. The method according to any one of claims 1 to 6, The first consensus node is any consensus node in the alliance chain; The second consensus node is any consensus node in the alliance chain.

8. A consortium chain system, comprising: The first consensus node, when generating a specified number of blocks, broadcasts a checkpoint message in the consortium chain, wherein the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks; The second consensus node receives the checkpoint message sent by the first consensus node, and if the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within a preset time period, it is determined that the stable checkpoint state of the second consensus node has timed out; and based on the timeout of the stable checkpoint state of the second consensus node, a view switching operation is initiated in the alliance chain, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain, and the checkpoint messages of the other 2f consensus nodes are sent in response to the checkpoint message of the first consensus node.

9. A consensus node in a consortium chain, comprising: A broadcast module, which broadcasts a checkpoint message in the consortium chain when a specified number of blocks are generated, wherein the checkpoint message is used to indicate that the specified number of blocks have been generated; A receiving module, receiving checkpoint messages sent by other consensus nodes in the alliance chain; A state determination module, which determines that the stable checkpoint state has timed out if no checkpoint message sent by the other 2f consensus nodes in the alliance chain is received within a preset time period, and the checkpoint message of the other 2f consensus nodes is sent in response to the checkpoint message of the first consensus node in the alliance chain; The view switching module initiates a view switching operation in the alliance chain based on the stable checkpoint state timeout, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

10. An electronic device, comprising: processor; as well as a memory arranged to store computer executable instructions which, when executed, cause the processor to: When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated; Receive checkpoint messages sent by other consensus nodes in the alliance chain; If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within the preset time period, it is determined that the stable checkpoint state has timed out, and the checkpoint message of the other 2f consensus nodes is sent in response to the checkpoint message of the first consensus node in the alliance chain; Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

11. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of application programs, causes the electronic device to perform the following operations: When a specified number of blocks are generated, a checkpoint message is broadcast in the consortium chain, where the checkpoint message is used to indicate that the specified number of blocks have been generated; Receive checkpoint messages sent by other consensus nodes in the alliance chain; If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within the preset time period, it is determined that the stable checkpoint state has timed out, and the checkpoint message of the other 2f consensus nodes is sent in response to the checkpoint message of the first consensus node in the alliance chain; Based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.

Citation Information

Patent Citations

  • A method for applying an Ethernet workshop consensus mechanism of improved PBFT to an alliance chain

    CN109784916A

  • Consensus method, consensus node and system in alliance chain

    CN112988470A