WO2023045574A1 - Consensus in consortium blockchain - Google Patents

Consensus in consortium blockchain Download PDF

Info

Publication number
WO2023045574A1
WO2023045574A1 PCT/CN2022/109829 CN2022109829W WO2023045574A1 WO 2023045574 A1 WO2023045574 A1 WO 2023045574A1 CN 2022109829 W CN2022109829 W CN 2022109829W WO 2023045574 A1 WO2023045574 A1 WO 2023045574A1
Authority
WO
WIPO (PCT)
Prior art keywords
consensus node
consensus
checkpoint
chain
message
Prior art date
Application number
PCT/CN2022/109829
Other languages
French (fr)
Chinese (zh)
Inventor
陈盛龙
Original Assignee
蚂蚁区块链科技(上海)有限公司
支付宝(杭州)信息技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司, 支付宝(杭州)信息技术有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2023045574A1 publication Critical patent/WO2023045574A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Definitions

  • This document relates to the field of computer technology, especially to a consensus method and system in an alliance chain.
  • PBFT Practical Byzantine Fault Tolerance
  • the Normal Case Phase part includes request (request phase), pre-prepare (pre-preparation phase), prepare (preparation phase), commit (submission phase) and reply (response phase) to complete the consensus.
  • request and reply respectively correspond to the transaction request initiated by the client (client) and the transaction execution result returned to the client.
  • the consensus node usually starts the timer after receiving the request sent by the client. If the client does not receive f+1 replies to the request sent by it within the preset time period, the view switch can be triggered operate. However, since the request is sent by the client, it 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 on the request within the preset time period. The action in turn triggers a view switch action.
  • the embodiment of this specification provides a consensus method and system in the alliance chain to solve the problem that if the client sends a large number of requests to the consensus node in a short period of time in the existing alliance chain, it will also cause the consensus node to fail at the preset time. The problem of completing the consensus operation on the request within the segment and then triggering the view switching operation.
  • a consensus method in the alliance chain including: 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 for 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 is within the preset time If the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the segment, then the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; the second consensus node is based on the The stable checkpoint state of the second consensus node times out, and 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.
  • a consortium chain system including: a first consensus node, when generating a specified number of blocks, broadcasts a checkpoint message in the consortium chain, and the checkpoint message is used to indicate that the first consensus The node has generated the specified number of blocks; the second consensus node receives the checkpoint message sent by the first consensus node, if it does not receive the checkpoint message sent by other 2f consensus nodes in the alliance chain within the preset time checkpoint message, 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, and f is in the alliance chain The maximum number of abnormal consensus nodes allowed.
  • a consensus node in the consortium chain including: a broadcast module, when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number has been generated block; the receiving module receives checkpoint messages sent by other consensus nodes in the consortium chain; the status determination module, if the checkpoint message sent by other 2f consensus nodes in the consortium chain is not received within the preset time period message, then determine that the stable checkpoint state is overtime; the view switching module, based on the timeout of the stable checkpoint state, initiates a view switching operation in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
  • an electronic device comprising a processor and a memory arranged to store computer-executable instructions that, when executed, cause the processor to perform the following operations: block, broadcast a checkpoint message in the consortium chain, 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 consortium chain; if within a preset time period If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received, it is determined that the stable checkpoint state has timed out; based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the alliance The maximum number of abnormal consensus nodes allowed in the chain.
  • a computer-readable storage medium stores one or more programs, and when the one or more programs are executed by an electronic device including multiple application programs, the The electronic device performs the following operations: when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated; receiving other consensus in the consortium chain The checkpoint message sent by the node; 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; based on the timeout of the stable checkpoint state, in the A view switching operation is initiated in the consortium chain, and f is the maximum number of abnormal consensus nodes allowed in the consortium chain.
  • the embodiment of this specification uses the above technical solution to at least achieve the following technical effects: using the consensus method provided by the embodiment of this specification, the first consensus node in the consortium chain broadcasts a checkpoint message in the consortium chain when generating a specified number of blocks , the checkpoint message is used to indicate that the first consensus node has generated a 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 within the preset time period To the checkpoint message sent by other 2f consensus nodes in the alliance chain, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; and the second consensus node is based on the stable checkpoint state of the second consensus node.
  • f is the maximum number of abnormal consensus nodes allowed in the alliance chain. Since the consensus node counts the checkpoint messages received from other consensus nodes in the consortium chain, one thread can be used alone, which can avoid causing great pressure on the consensus node at a certain moment, and thus enable the consensus node to be more accurate in the consortium chain. Trigger a view switch operation.
  • Fig. 1 is a schematic diagram of the implementation flow of a consensus method in a consortium chain provided by an embodiment of this specification.
  • Fig. 2 is a schematic diagram of the implementation flow of an application of the consensus method in the consortium chain provided by an embodiment of this specification.
  • Fig. 3 is a schematic structural diagram of an alliance chain system provided by an embodiment of this specification.
  • Fig. 4 is a schematic structural diagram of a consensus node in a consortium chain provided by an embodiment of this specification.
  • Fig. 5 is a schematic structural diagram of an electronic device provided by an embodiment of this specification.
  • each Replica (copy, that is, all consensus nodes participating in the consensus in the alliance chain) sends a message or receives messages from other consensus nodes (including pre-prepare, prepare, commit messages) will be recorded in the message log (Message Log) of the memory of the consensus node.
  • Message Log message log
  • the Message Log of each consensus node in the alliance chain will take up 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 the proposal, the Message Log of each consensus node is cleared, and the memory space of each consensus node is released.
  • One way of garbage collection is that every time a consensus node in the consortium chain executes a proposal (that is, every time a block is generated), it can send a broadcast to other consensus nodes in the consortium chain, aiming at whether the consensus node can be cleared The message log of the consensus node is reached in the whole network. After receiving such broadcasts, each consensus node in the alliance chain can also send broadcasts to other consensus nodes in the alliance chain. unanimous. If the consensus nodes in the consortium chain receive confirmations from consensus nodes with different numbers of Quorum (2f+1), these consensus nodes can delete the proposal corresponding to one proposal (that is, the latest generated block) in the consensus node Message Log. message log.
  • Another way to deal with garbage is that every time a certain consensus node in the alliance chain executes k proposals (that is, each new k blocks are generated), it can send a broadcast to other consensus nodes in the alliance chain. Clearing the Message Log of this consensus node reaches a consensus in the entire network. After receiving such broadcasts, each consensus node in the alliance chain can also broadcast to other consensus nodes in the alliance chain. It is also aimed at whether the Message Log of this consensus node can be cleared. consensus across the network. If the consensus nodes in the consortium chain receive confirmations from consensus nodes with different numbers of Quorum (2f+1), these consensus nodes can delete the k proposals (that is, the latest generated k blocks) in the consensus node Message Log. message log.
  • k is the message record corresponding to the k proposals (that is, the newly generated k blocks) indicated by the checkpoint message in the embodiment of this specification
  • the Message Log that clears the consensus node above is the checkpoint message in the embodiment of this specification
  • the format is ⁇ CHECKPOINT, n, d, i>, where n is the sequence number of the smallest block that the consensus node currently expects to keep, d is the message digest that is expected to be kept, and i is the number of the consensus node that sent the checkpoint message .
  • the checkpoint message broadcast by the consensus node in the alliance chain and the summary of the checkpoint message received in the alliance chain are recorded in the Message Log of the consensus node. If the consensus node i in the consortium chain receives Quorum-1 legitimate checkpoint messages sent by other different consensus nodes, plus the checkpoint message sent by consensus node i itself, then the checkpoint message of consensus node i for ⁇ n, d> will be When the number of Quorum(2f+1) is reached, the consensus node i can clear the message records corresponding to all blocks before the block number n in the consensus node Message Log (including the corresponding pre-prepare, prepare, commit messages, and checkpoint messages).
  • the above block number n is the current stable checkpoint of the consensus node i, which means that the consensus node i has reached a consensus on the execution result of the block before the block number n, and the message record corresponding to the block with the block number n is still Retained in the Message Log of consensus node i. Since the processing of each consensus node in the consortium 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 first consensus node in the alliance chain broadcasts a checkpoint message in the alliance chain when generating a specified number of blocks.
  • the checkpoint message is used to indicate that the first consensus node has generated a specified number of blocks. block;
  • 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 other 2f consensus nodes in the alliance chain within the preset time period, Then 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 timeout of the stable checkpoint state of the second consensus node, and f is the maximum exception allowed in the alliance chain
  • the number of consensus nodes Since the consensus node in the alliance chain can trigger the view switching operation in time after the stable checkpoint state times out, to replace the consensus master node in the alliance chain and restart the consensus operation, thereby avoiding stagnation of each consensus node in the first
  • any request sent by the client to the consensus node in the consortium chain can successfully reach a consensus, it will eventually reach a consensus in the consortium chain and broadcast a commit message throughout the network, while the consensus node in the consortium chain targets a certain After the request reaches a consensus, it will send a checkpoint message to other nodes, so that 2f+1 nodes in the consortium chain can perform garbage collection operations after reaching a consensus on the same request, and change the state of the consensus node to a stable checkpoint state, so , if the stable checkpoint state of a certain consensus node in the alliance chain has timed out, it can also reflect that the request sent by the client to the consensus node has timed out.
  • the embodiment of this specification is based on this, and considering that each consensus node in the consortium chain can process the checkpoint message as a separate thread, it is proposed to trigger the view switching operation in the consortium chain based on the timeout of the stable checkpoint state of the consensus node.
  • FIG. 1 a schematic diagram of the implementation flow of a consensus method in a consortium chain provided by one or more embodiments of this specification is shown in Figure 1 , including the following steps.
  • Step 110 when the first consensus node in the consortium chain generates a specified number of blocks, it broadcasts a checkpoint message in the consortium chain, and the checkpoint message is used to indicate that the first consensus node has generated a specified number of blocks.
  • the purpose of broadcasting the checkpoint message in the alliance chain is to reach a consensus on whether the Message Log can be cleared in the entire network.
  • the first consensus node broadcasts a checkpoint message in the consortium chain, including: The block number n broadcasts the checkpoint message in the consortium chain, and the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.
  • 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 check whether the message corresponding to the block before the block number n in the Message Log can be cleared and recorded in the entire network agree.
  • the consensus node receives Quorum-1 legal checkpoint messages sent by different nodes, plus the checkpoint message sent by itself, it means that the consensus node has collected checkpoint messages of Quorum quantity, and a stable checkpoint can be achieved, and then It is possible to clean up the message records corresponding to the blocks before the block number n in the Message Log.
  • the method provided by the embodiment of this specification further includes: when the second consensus node generates a specified number of blocks, the second consensus node broadcasts the checkpoint message in the alliance chain to carry There is a checkpoint message of the block number n of the block with the largest serial number among the specified number of blocks, 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 the The checkpoint message sent by the second consensus node; when the first consensus node receives the checkpoint message of 2f consensus nodes in the alliance chain within the preset time period, the first consensus node clears the specified number of blocks in the first consensus node The message record corresponding to the block before the block with the largest sequence number; the first consensus node modifies the state of the first consensus node to stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.
  • the above specified number is a positive integer greater than or equal to 1.
  • a way of triggering the view switching operation is that when the specified number is 1, after the first consensus node modifies the state of the first consensus node to stable checkpoint, the method provided by the embodiment of this specification The method also includes: the first consensus node starts the timer; if the first consensus node does not receive the block numbers of n+ 1 checkpoint message, 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 the timeout of the stable checkpoint state of the first consensus node.
  • the first consensus node in the consortium chain Every time the first consensus node in the consortium chain executes a proposal (that is, every time a block is generated), it can broadcast checkpoint messages to other consensus nodes in the consortium chain to reach an agreement on whether the message log of this consensus node can be cleared in the entire network. Consistent, other consensus nodes in the consortium chain can also broadcast checkpoint messages to other consensus nodes in the consortium chain after receiving the checkpoint message, and also reach a consensus on whether the Message Log of this consensus node can be cleared in the entire network. If the first consensus node in the consortium chain receives confirmations from consensus nodes with different numbers of Quorum (2f+1) within the set preset time period, the first consensus node can modify the status of the consensus node to stable checkpoint.
  • the first consensus node in the consortium chain can restart the timer. If the first consensus node does not receive the zone data of other 2f consensus nodes in the consortium chain within the preset time period after starting the timer For the checkpoint message with block number n+1, the first consensus node determines that its stable checkpoint status has timed out, and can trigger a view switching operation in the consortium chain based on the stable checkpoint status timeout.
  • another way of triggering the view switching operation is that 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 stable checkpoint,
  • the method also includes: the first consensus node starts the timer; if the first consensus node does not receive the other 2f consensus nodes in the consortium chain within the preset time period after starting the timer, the block number is n+k checkpoint messages, 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 the timeout of the stable checkpoint state of the first consensus node.
  • the first consensus node in the alliance chain executes k proposals (that is, every time k blocks are generated), it can broadcast checkpoint messages to other consensus nodes in the alliance chain. After reaching a consensus on the network, other consensus nodes in the consortium chain can also broadcast checkpoint messages to other consensus nodes in the consortium chain after receiving the checkpoint message. It is also a consensus on whether the Message Log of this consensus node can be cleared in the entire network. If the first consensus node in the consortium chain receives confirmations from consensus nodes with different numbers of Quorum (2f+1) within the set preset time period, the first consensus node can modify the status of the consensus node to stable checkpoint. At this time, the first consensus node in the consortium chain can restart the timer.
  • the first consensus node determines that its stable checkpoint status has timed out, and can trigger a view switching operation in the consortium chain based on the stable checkpoint status timeout.
  • Step 120 the second consensus node in the consortium chain receives the checkpoint message sent by the first consensus node.
  • the second consensus node in the consortium chain When the second consensus node in the consortium chain generates a specified number of blocks, it can also broadcast a checkpoint message in the consortium chain.
  • the checkpoint message is used to indicate that the second consensus node has generated a specified number of blocks. While the second consensus node broadcasts the checkpoint message in the alliance chain, it will also receive the checkpoint message sent by other consensus nodes in the alliance chain such as the first consensus node.
  • Step 130 if the second consensus node does not receive checkpoint messages sent by other 2f consensus nodes in the consortium chain within the preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out.
  • the duration of the preset time period is the duration of the timer set locally by the second consensus node to trigger timeout. If the second consensus node does not receive the checkpoint messages sent by other 2f consensus nodes in the consortium chain within the preset time period, the second consensus node cannot collect the checkpoint messages of Quorum quantity, and cannot achieve stable checkpoint, and thus cannot Perform garbage cleaning operations on the Message Log in this consensus node. In the embodiment of this specification, the state that the consensus node cannot reach the stable checkpoint is simply referred to as the stable checkpoint state timeout.
  • Step 140 the second consensus node initiates a view switching operation in the consortium 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 consortium chain.
  • the second consensus node can initiate a view switching operation in the consortium chain based on the timeout of its local stable checkpoint state, in an attempt to replace the consensus master node in the consortium chain.
  • the consensus algorithm in the embodiment of this specification can also be applied to the RAFT algorithm, and other consensus algorithms that can distinguish between consensus master nodes and consensus backup nodes.
  • the embodiment of this specification does not impose specific restrictions on the adopted consensus algorithm, as long as there is a consensus master node in the adopted consensus algorithm.
  • C is the client
  • consensus node 0 is the consensus master node during this consensus operation
  • consensus nodes 1 to 3 are consensus backup nodes during this consensus operation.
  • the schematic diagram shown in Figure 2 includes the following situations: In the first case, the consensus node 0 is a malicious node, and the consensus node 0 deceives the consensus node 1 and the consensus node 2 to perform the consensus operation on the message m requesting consensus from the client ( Figure 2 shown in the solid line), while the consensus node 0 itself and the consensus node 3 do not perform the consensus operation on the message m requesting consensus from the client (the dotted line shown in Figure 2).
  • the local timer of the consensus node 3 will also time out, thereby initiating a view switching operation in the alliance chain; at the same time, due to the fact that in the first case , Consensus Node 1 and Consensus Node 2 have been unable to reach a stable checkpoint, that is, the stable checkpoint state has timed out. In this way, Consensus Node 1 and Consensus Node 2 will also trigger a view switching operation in the alliance chain, and then can achieve a Quorum number of view switching operations. Complete the master change.
  • every time a consensus node generates a block it can broadcast a block message to other consensus nodes through the P2P protocol, and receive the consensus node that broadcasts the block message, as shown in Figure 2 If the consensus node 3 finds that the block height in the block message is higher than its local maximum block height, it will synchronize the latest block from consensus node 1 or consensus node 2 (there are already 2f+1 signatures in the block , can be pushed or pulled from consensus node 1 or consensus node 2, regardless of the height of the block of consensus node 0), so as to maintain synchronization with consensus node 1 or consensus node 2.
  • the first consensus node in the consortium chain when the first consensus node in the consortium chain generates a specified number of blocks, it broadcasts a checkpoint message in the consortium chain.
  • the checkpoint message is used to indicate that the first consensus node has generated a 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 other 2f consensus nodes in the alliance chain within the preset time period, then 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 timeout of the stable checkpoint state of the second consensus node, f is the maximum abnormal consensus allowed in the alliance chain number of nodes.
  • the consensus node Since the consensus node counts the checkpoint messages received from other consensus nodes in the consortium chain, one thread can be used alone, which can avoid causing great pressure on the consensus node at a certain moment, and thus enable the consensus node to be more accurate in the consortium chain. Trigger a view switch operation.
  • Fig. 3 is a schematic structural diagram of the consortium chain system 300 provided by the embodiment of this specification.
  • the consortium chain system 300 may include a first consensus node 310 and a second consensus node 320, wherein: the first consensus node 310, when generating a specified number of blocks, A checkpoint message is broadcast in the consortium 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 320 receives the checkpoint message sent by the first consensus node, if If the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the 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 of the second consensus node When the state is timed out, a view switch operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
  • the first consensus node 310 is configured to: broadcast a checkpoint in the consortium chain based on the block number n of the block with the largest sequence number among the specified number of blocks message, the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.
  • the second consensus node broadcasts in the consortium chain a checkpoint message carrying the block number n of the block with the largest sequence number among the specified number of blocks, and the checkpoint message broadcast by the second consensus node is used to indicate that the second The consensus node has generated the specified number of blocks; the first consensus node receives the checkpoint message sent by the second consensus node; when the first consensus node receives the alliance within the preset time period When there are checkpoint messages from 2f consensus nodes in the chain, the first consensus node clears the message record corresponding to the block before the block with the largest sequence number in the specified number of blocks in the first consensus node; The first consensus node modifies the state of the first consensus node to stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.
  • the specified number is a positive integer greater than or equal to 1.
  • the method further includes: the first consensus node starts timer; if the first consensus node does not receive the block number n+1 carried by the other 2f consensus nodes in the consortium chain within the preset time period after starting the timer checkpoint message, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out; View switching operation.
  • the method further includes: the The first consensus node starts the timer; if the first consensus node does not receive the blocks carried by other 2f consensus nodes in the consortium chain within the preset time period after starting the timer n+k checkpoint message, the first consensus node determines that the stable checkpoint status of the first consensus node has timed out; the first consensus node is based on the stable checkpoint status of the first consensus node. Trigger the view switching operation in the alliance chain mentioned above.
  • the first consensus node is any consensus node in the consortium chain; the second consensus node is any consensus node in the consortium chain.
  • the consortium chain system 300 can implement the methods in the method embodiments in FIGS. 1-2 .
  • Fig. 4 is a schematic structural diagram of a consensus node 400 in a consortium chain provided by an embodiment of this specification, including: a broadcast module 410, which broadcasts a checkpoint message in the consortium chain when a specified number of blocks are generated, the checkpoint message It is used to indicate that the specified number of blocks has been generated; the receiving module 420 receives checkpoint messages sent by other consensus nodes in the alliance chain; the state determination module 430, if the alliance chain is not received within a preset time period The checkpoint message sent by other 2f consensus nodes in the chain determines that the stable checkpoint state is overtime; the view switching module 440 initiates a view switching operation in the alliance chain based on the timeout of the stable checkpoint state, and f is the alliance chain The maximum number of abnormal consensus nodes allowed in .
  • the broadcast module 410 is configured to: broadcast a checkpoint message in the consortium 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.
  • the status determination module 430 is further configured to: clear the designated node in this consensus node when receiving checkpoint messages from 2f consensus nodes in the consortium chain within the preset time period.
  • the specified number is a positive integer greater than or equal to 1.
  • the view switching module 440 is also used to: start the timer; if Within the preset time period after starting the timer, if no checkpoint message carrying block number n+1 from other 2f consensus nodes in the consortium chain is received, then the consensus node’s The stable checkpoint state timed out; based on the timeout of the stable checkpoint state of the consensus node, the view switching operation is triggered in the alliance chain.
  • the view switching module 440 is further configured to: Start the timer; if within the preset time period after starting the timer, the checkpoint message carrying the block number n+k of the other 2f consensus nodes in the consortium chain is not received, then Determine the timeout of the stable checkpoint state of the consensus node; based on the timeout of the stable checkpoint state of the consensus node, trigger the view switching operation in the alliance chain.
  • the consensus node 400 in the consortium chain is any consensus node in the consortium chain.
  • the consensus node 400 in the consortium chain can implement the method in the method embodiment in FIG. 1 .
  • Fig. 5 is a schematic structural diagram of an electronic device provided by an embodiment of this specification.
  • 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 (Random-Access Memory, RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
  • RAM random-Access Memory
  • non-volatile memory such as at least one disk memory.
  • the electronic device may also include hardware required by other services.
  • the processor, the network interface and the memory can be connected to each other through an internal bus, which can be an ISA (Industry Standard Architecture, industry standard architecture) bus, a PCI (Peripheral Component Interconnect, peripheral component interconnection standard) bus or an EISA (Extended Industry Standard Architecture, extended industry standard architecture) bus, etc.
  • the bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one double-headed arrow is used in FIG. 5 , but it does not mean that there is only one bus or one type of bus.
  • Memory for storing programs.
  • the program may include program code, and the program code includes computer operation instructions.
  • Storage which can include internal memory and nonvolatile storage, provides instructions and data to the processor.
  • 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 consensus nodes in the consortium chain on a logical level.
  • the processor executes the program stored in the memory, and is specifically used to perform the following operations: when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated block; receive checkpoint messages sent by other consensus nodes in the alliance chain; if the checkpoint messages sent by other 2f consensus nodes in the alliance chain are not received within the preset time period, then determine that the stable checkpoint state is overtime; 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.
  • a processor may be an integrated circuit chip with signal processing capabilities.
  • each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software.
  • the above-mentioned processor can be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; it can also be a digital signal processor (Digital Signal Processor, DSP), a dedicated integrated Circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • DSP Digital Signal Processor
  • ASIC Application Specific Integrated Circuit
  • FPGA Field-Programmable Gate Array
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the steps of the method disclosed in conjunction with one or more embodiments of this specification may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register.
  • 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.
  • the electronic device can also execute the consensus method in the consortium chain shown in FIG. 1 , which will not be repeated here in this specification.
  • the electronic equipment in this specification does not exclude other implementations, such as logic devices or the 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, It can also be a hardware or logic device.
  • the embodiment of this specification also proposes a computer-readable storage medium, the computer-readable storage medium stores one or more programs, and the one or more programs include instructions, and the instructions are used when a portable electronic device including multiple application programs During execution, the portable electronic device can be made to execute the method of the embodiment shown in FIG.
  • a typical implementing device is a computer.
  • 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 Combinations of any of these devices.
  • Computer-readable media including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information.
  • Information may be computer readable instructions, data structures, modules of a program, 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 Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic tape cartridge, tape magnetic disk storage or other magnetic storage device or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
  • computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.

Abstract

A consensus method in a consortium blockchain, and a system. The method comprises: a first consensus node in a consortium blockchain broadcasting a checkpoint message in the consortium blockchain when generating a specified number of blocks, wherein the checkpoint message is used for indicating that the first consensus node has generated the specified number of blocks (110); a second consensus node in the consortium blockchain receiving the checkpoint message sent by the first consensus node (120); if the second consensus node does not receive checkpoint messages sent by the other 2f consensus nodes in the consortium blockchain within a preset time period, the second consensus node determining that the stable checkpoint state of the second consensus node times out (130); and the second consensus node initiating a view switching operation in the consortium blockchain on the basis of the fact that the stable checkpoint state of the second consensus node times out, wherein f is the maximum number of abnormal consensus nodes that is allowed in the consortium blockchain (140).

Description

联盟链中的共识Consensus in Consortium Chain 技术领域technical field
本文件涉及计算机技术领域,尤其涉及一种联盟链中的共识方法和系统。This document relates to the field of computer technology, especially to a consensus method and system in an alliance chain.
背景技术Background technique
目前,实用拜占庭容错算法(Practical Byzantine Fault Tolerance,PBFT)主要包括两个部分,即包括Normal Case Phase和View Change Phase这两个部分。其中,Normal Case Phase部分包括request(请求阶段)、pre-prepare(预准备阶段)、prepare(准备阶段)、commit(提交阶段)和reply(响应阶段)这几个阶段来完成共识。其中,request和reply分别对应于client(客户端)发起的交易请求和返回给client的交易执行结果。At present, Practical Byzantine Fault Tolerance (PBFT) mainly includes two parts, including Normal Case Phase and View Change Phase. Among them, the Normal Case Phase part includes request (request phase), pre-prepare (pre-preparation phase), prepare (preparation phase), commit (submission phase) and reply (response phase) to complete the consensus. Among them, request and reply respectively correspond to the transaction request initiated by the client (client) and the transaction execution result returned to the client.
现有技术中,通常通过共识节点在接收到客户端发出request之后开启定时器,如果在预设时间段内客户端没有收到f+1个针对其发出的request的reply,则可触发视图切换操作。然而,由于request是由客户端发出的,是客户端的一种行为,如果客户端在短时间内给共识节点发送大量的request,也会导致共识节点无法在预设时间段内完成对request的共识操作进而触发视图切换操作。In the existing technology, the consensus node usually starts the timer after receiving the request sent by the client. If the client does not receive f+1 replies to the request sent by it within the preset time period, the view switch can be triggered operate. However, since the request is sent by the client, it 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 on the request within the preset time period. The action in turn triggers a view switch action.
发明内容Contents of the invention
本说明书实施例提供了一种联盟链中的共识方法和系统,以解决现有的联盟链中果客户端在短时间内给共识节点发送大量的request,也会导致共识节点无法在预设时间段内完成对request的共识操作进而触发视图切换操作的问题。The embodiment of this specification provides a consensus method and system in the alliance chain to solve the problem that if the client sends a large number of requests to the consensus node in a short period of time in the existing alliance chain, it will also cause the consensus node to fail at the preset time. The problem of completing the consensus operation on the request within the segment and then triggering the view switching operation.
为解决上述技术问题,本说明书实施例是这样实现的。第一方面,提出了一种联盟链中的共识方法,包括:联盟链中的第一共识节点在生成指定数量的区块时,在所述联盟链中广播checkpoint消息,所述checkpoint消息用于指示所述第一共识节点已经生成所述指定数量的区块;所述联盟链中的第二共识节点接收所述第一共识节点发送的checkpoint消息;如果所述第二共识节点在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则所述第二共识节点确定所述第二共识节点的stable checkpoint状态超时;所述第二共识节点基于所述第二共识节点的stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。In order to solve the above technical problems, the embodiments of this specification are implemented in the following way. In the first aspect, a consensus method in the alliance chain is proposed, including: 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 for 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 is within the preset time If the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the segment, then the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; the second consensus node is based on the The stable checkpoint state of the second consensus node times out, and 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.
第二方面,提出了一种联盟链系统,包括:第一共识节点,在生成指定数量的区块时,在所述联盟链中广播checkpoint消息,所述checkpoint消息用于指示所述第一共识 节点已经生成所述指定数量的区块;第二共识节点,接收所述第一共识节点发送的checkpoint消息,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定所述第二共识节点的stable checkpoint状态超时;以及基于所述第二共识节点的stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。In the second aspect, a consortium chain system is proposed, including: a first consensus node, when generating a specified number of blocks, broadcasts a checkpoint message in the consortium chain, and the checkpoint message is used to indicate that the first consensus The node has generated the specified number of blocks; the second consensus node receives the checkpoint message sent by the first consensus node, if it does not receive the checkpoint message sent by other 2f consensus nodes in the alliance chain within the preset time checkpoint message, 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, and f is in the alliance chain The maximum number of abnormal consensus nodes allowed.
第三方面,提出了一种联盟链中的共识节点,包括:广播模块,在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收模块,接收所述联盟链中的其它共识节点发送的checkpoint消息;状态确定模块,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;视图切换模块,基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。In the third aspect, a consensus node in the consortium chain is proposed, including: a broadcast module, when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number has been generated block; the receiving module receives checkpoint messages sent by other consensus nodes in the consortium chain; the status determination module, if the checkpoint message sent by other 2f consensus nodes in the consortium chain is not received within the preset time period message, then determine that the stable checkpoint state is overtime; the view switching module, based on the timeout of the stable checkpoint state, initiates a view switching operation in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
第四方面,提出了一种电子设备,包括处理器以及被安排成存储计算机可执行指令的存储器,所述可执行指令在被执行时使所述处理器执行以下操作:在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收所述联盟链中的其它共识节点发送的checkpoint消息;如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。In a fourth aspect, an electronic device is provided, comprising a processor and a memory arranged to store computer-executable instructions that, when executed, cause the processor to perform the following operations: block, broadcast a checkpoint message in the consortium chain, 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 consortium chain; if within a preset time period If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received, it is determined that the stable checkpoint state has timed out; based on the timeout of the stable checkpoint state, a view switching operation is initiated in the alliance chain, and f is the alliance The maximum number of abnormal consensus nodes allowed in the chain.
第五方面,提出了一种计算机可读存储介质,所述计算机可读存储介质存储一个或多个程序,所述一个或多个程序当被包括多个应用程序的电子设备执行时,使得所述电子设备执行以下操作:在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收所述联盟链中的其它共识节点发送的checkpoint消息;如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。In the fifth aspect, a computer-readable storage medium is proposed, the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by an electronic device including multiple application programs, the The electronic device performs the following operations: when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated; receiving other consensus in the consortium chain The checkpoint message sent by the node; 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; based on the timeout of the stable checkpoint state, in the A view switching operation is initiated in the consortium chain, and f is the maximum number of abnormal consensus nodes allowed in the consortium chain.
本说明书实施例采用上述技术方案至少可以达到下述技术效果:采用本说明书实施例提供的共识方法,联盟链中的第一共识节点在生成指定数量的区块时,在联盟链中广播checkpoint消息,该checkpoint消息用于指示第一共识节点已经生成指定数量的区块;联盟链中的第二共识节点接收第一共识节点发送的checkpoint消息;如果第二共识节点 在预设时间段内未接收到联盟链中的其它2f个共识节点发送的checkpoint消息,则第二共识节点确定第二共识节点的stable checkpoint状态超时;并且第二共识节点基于第二共识节点的stable checkpoint状态超时,在联盟链中发起视图切换操作,f为联盟链中允许的最大异常共识节点数量。由于共识节点统计从联盟链中的其它共识节点接收到的checkpoint消息可以单独使用一个线程,从而能够避免在某一瞬间给共识节点造成极大压力,进而使得共识节点能够更加准确地在联盟链中触发视图切换操作。The embodiment of this specification uses the above technical solution to at least achieve the following technical effects: using the consensus method provided by the embodiment of this specification, the first consensus node in the consortium chain broadcasts a checkpoint message in the consortium chain when generating a specified number of blocks , the checkpoint message is used to indicate that the first consensus node has generated a 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 within the preset time period To the checkpoint message sent by other 2f consensus nodes in the alliance chain, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out; and the second consensus node is based on the stable checkpoint state of the second consensus node. Initiate a view switching operation in , and f is the maximum number of abnormal consensus nodes allowed in the alliance chain. Since the consensus node counts the checkpoint messages received from other consensus nodes in the consortium chain, one thread can be used alone, which can avoid causing great pressure on the consensus node at a certain moment, and thus enable the consensus node to be more accurate in the consortium chain. Trigger a view switch operation.
附图说明Description of drawings
此处所说明的附图用来提供对本说明书的进一步理解,构成本说明书的一部分,本说明书的示意性实施例及其说明用于解释本说明书,并不构成对本说明书的不当限定。在附图中:The drawings described here are used to provide a further understanding of this specification and constitute a part of this specification. The schematic embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation of this specification. In the attached picture:
图1为本说明书一个实施例提供的一种联盟链中的共识方法的实现流程示意图。Fig. 1 is a schematic diagram of the implementation flow of a consensus method in a consortium chain provided by an embodiment of this specification.
图2为本说明书一个实施例提供的联盟链中的共识方法一种应用的实现流程示意图。Fig. 2 is a schematic diagram of the implementation flow of an application of the consensus method in the consortium chain provided by an embodiment of this specification.
图3为本说明书一个实施例提供的一种联盟链系统的结构示意图。Fig. 3 is a schematic structural diagram of an alliance chain system provided by an embodiment of this specification.
图4为本说明书一个实施例提供的一种联盟链中的共识节点的结构示意图。Fig. 4 is a schematic structural diagram of a consensus node in a consortium chain provided by an embodiment of this specification.
图5为本说明书一个实施例提供的一种电子设备的结构示意图。Fig. 5 is a schematic structural diagram of an electronic device provided by an embodiment of this specification.
具体实施方式Detailed ways
为使本文件的目的、技术方案和优点更加清楚,下面将结合本说明书具体实施例及相应的附图对本说明书技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本文件一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本文件保护的范围。In order to make the purpose, technical solution and advantages of this document clearer, the technical solution of this specification will be clearly and completely described below in conjunction with specific embodiments of this specification and corresponding drawings. Apparently, the described embodiments are only some of the embodiments in this document, not all of them. Based on the embodiments in this specification, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of this document.
以下结合附图,详细说明本说明书各实施例提供的技术方案。The technical solutions provided by each embodiment of this specification will be described in detail below in conjunction with the accompanying drawings.
在联盟链中使用PBFT算法进行共识的过程中,每个Replica(副本,即联盟链中所有参与共识的共识节点)在发出一个消息或者接收到其它共识节点发来的消息(包括pre-prepare、prepare、commit消息)时,都会在本共识节点的内存的消息日志(Message Log)中做记录。随着联盟链中共识操作的不断进行,联盟链中各共识节点的Message Log会占用越来越大的内存空间,因此,为了节省联盟链中各共识节点的内存空间,需要进行垃圾回收,即在各个共识节点执行完propose(提议)时,清空各共识节点的Message Log,释放各共识节点的内存空间。In the process of using the PBFT algorithm for consensus in the alliance chain, each Replica (copy, that is, all consensus nodes participating in the consensus in the alliance chain) sends a message or receives messages from other consensus nodes (including pre-prepare, prepare, commit messages) will be recorded in the message log (Message Log) of the memory of the consensus node. With the continuous progress of consensus operations in the alliance chain, the Message Log of each consensus node in the alliance chain will take up 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 the proposal, the Message Log of each consensus node is cleared, and the memory space of each consensus node is released.
一种垃圾回收的方式是,联盟链中某个共识节点每执行完一条propose(也就是每生成一个区块),就可以向联盟链中的其它共识节点发出广播,针对是否可以清除本共识 节点的Message Log在全网达成一致,联盟链中的各个共识节点接收到这类广播后也可以向联盟链中的其它共识节点发出广播,也是针对是否可以清除本共识节点的Message Log在全网达成一致。如果联盟链中的共识节点接收到Quorum(2f+1)数量不同共识节点的确认,这些共识节点就可以删除本共识节点Message Log中的1条propose(即最新生成的1个区块)对应的消息记录。One way of garbage collection is that every time a consensus node in the consortium chain executes a proposal (that is, every time a block is generated), it can send a broadcast to other consensus nodes in the consortium chain, aiming at whether the consensus node can be cleared The message log of the consensus node is reached in the whole network. After receiving such broadcasts, each consensus node in the alliance chain can also send broadcasts to other consensus nodes in the alliance chain. unanimous. If the consensus nodes in the consortium chain receive confirmations from consensus nodes with different numbers of Quorum (2f+1), these consensus nodes can delete the proposal corresponding to one proposal (that is, the latest generated block) in the consensus node Message Log. message log.
另一种垃圾处理的方式是,联盟链中某个共识节点每执行完k条propose(也就是每新生成k个区块),就可以向联盟链中的其它共识节点发出广播,针对是否可以清除本共识节点的Message Log在全网达成一致,联盟链中的各个共识节点接收到这类广播后也可以向联盟链中的其它共识节点发出广播,也是针对是否可以清除本共识节点的Message Log在全网达成一致。如果联盟链中的共识节点接收到Quorum(2f+1)数量不同共识节点的确认,这些共识节点就可以删除本共识节点Message Log中的k条propose(即最新生成的k个区块)对应的消息记录。Another way to deal with garbage is that every time a certain consensus node in the alliance chain executes k proposals (that is, each new k blocks are generated), it can send a broadcast to other consensus nodes in the alliance chain. Clearing the Message Log of this consensus node reaches a consensus in the entire network. After receiving such broadcasts, each consensus node in the alliance chain can also broadcast to other consensus nodes in the alliance chain. It is also aimed at whether the Message Log of this consensus node can be cleared. consensus across the network. If the consensus nodes in the consortium chain receive confirmations from consensus nodes with different numbers of Quorum (2f+1), these consensus nodes can delete the k proposals (that is, the latest generated k blocks) in the consensus node Message Log. message log.
其中,k即本说明书实施例中checkpoint消息指示删除的k条propose(即最新生成的k个区块)对应的消息记录,上面清除本共识节点的Message Log即为本说明书实施例中的checkpoint消息,格式为<CHECKPOINT,n,d,i>,其中,n是共识节点当前期望保留的最小的一个区块的序列编号,d是期望保留的消息摘要,i是发出checkpoint消息的共识节点的编号。Among them, k is the message record corresponding to the k proposals (that is, the newly generated k blocks) indicated by the checkpoint message in the embodiment of this specification, and the Message Log that clears the consensus node above is the checkpoint message in the embodiment of this specification , the format is <CHECKPOINT, n, d, i>, where n is the sequence number of the smallest block that the consensus node currently expects to keep, d is the message digest that is expected to be kept, and i is the number of the consensus node that sent the checkpoint message .
上述联盟链中的共识节点在联盟链中广播发出的checkpoint消息和接收到的checkpoint消息的摘要都被记录到本共识节点的Message Log中。如果联盟链中的共识节点i收到其他不同共识节点发送的Quorum-1个合法的checkpoint消息,加上共识节点i本身发出的checkpoint消息,那么共识节点i针对<n,d>的checkpoint消息便达到了Quorum(2f+1)数量,此时共识节点i可以清除本共识节点Message Log中区块号为n之前的所有区块对应的消息记录(包括区块号为n之前的区块对应的pre-prepare、prepare、commit消息以及checkpoint消息)。The checkpoint message broadcast by the consensus node in the alliance chain and the summary of the checkpoint message received in the alliance chain are recorded in the Message Log of the consensus node. If the consensus node i in the consortium chain receives Quorum-1 legitimate checkpoint messages sent by other different consensus nodes, plus the checkpoint message sent by consensus node i itself, then the checkpoint message of consensus node i for <n, d> will be When the number of Quorum(2f+1) is reached, the consensus node i can clear the message records corresponding to all blocks before the block number n in the consensus node Message Log (including the corresponding pre-prepare, prepare, commit messages, and checkpoint messages).
上述区块号n即为共识节点i当前的一个stable checkpoint,即表明共识节点i对区块号n之前的区块的执行结果已达成共识,区块号为n的区块对应的消息记录还保留在共识节点i的Message Log中。由于联盟链系统中每个共识节点的处理是不同步的,共识消息处理快的共识节点可能会逐步拉开与共识消息处理慢的共识节点的距离,通过设置高低水位可以限制消息处理的速度:H=h+L,其中,H是高水位,L是低水位,h是设定值,h一般取stable checkpoint的n值。这样可以控制处理快的共识节点的处理速度,当它处理的共识消息的n值达到高水位H后会等待,直到stable checkpoint发生变化, 才继续处理。The above block number n is the current stable checkpoint of the consensus node i, which means that the consensus node i has reached a consensus on the execution result of the block before the block number n, and the message record corresponding to the block with the block number n is still Retained in the Message Log of consensus node i. Since the processing of each consensus node in the consortium 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, h is the set value, h generally takes the n value of the stable checkpoint. This can control the processing speed of the fast-processing consensus node. When the n value of the consensus message it processes reaches the high water mark H, it will wait until the stable checkpoint changes before continuing to process.
因此,如果stable checkpoint一直不发生变化,联盟链中的各个共识节点就不能处理下一个propose,那么限制消息处理的速度的高低水位也就不会发生任何变化,进而就会导致联盟链中的各个共识节点都停滞不前了。Therefore, if the stable checkpoint has not changed, each consensus node in the consortium chain cannot process the next proposal, and the high and low water levels that limit the speed of message processing will not change, which in turn will cause all parties in the consortium chain to Consensus nodes have stagnated.
本说明书实施例为了解决这一问题,通过联盟链中的第一共识节点在生成指定数量的区块时,在联盟链中广播checkpoint消息,该checkpoint消息用于指示第一共识节点已经生成指定数量的区块;联盟链中的第二共识节点接收第一共识节点发送的checkpoint消息;如果第二共识节点在预设时间段内未接收到联盟链中的其它2f个共识节点发送的checkpoint消息,则第二共识节点确定第二共识节点的stable checkpoint状态超时;并且第二共识节点基于第二共识节点的stable checkpoint状态超时,在联盟链中发起视图切换操作,f为联盟链中允许的最大异常共识节点数量。由于联盟链中的共识节点能够在stable checkpoint状态超时之后及时触发视图切换操作,以更换联盟链中的共识主节点,并重新开始进行共识操作,进而避免联盟链中的各个共识节点都停滞不前的状况。In order to solve this problem, the first consensus node in the alliance chain broadcasts a checkpoint message in the alliance chain when generating a specified number of blocks. The checkpoint message is used to indicate that the first consensus node has generated a specified number of blocks. block; 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 other 2f consensus nodes in the alliance chain within the preset time period, Then 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 timeout of the stable checkpoint state of the second consensus node, and f is the maximum exception allowed in the alliance chain The number of consensus nodes. Since the consensus node in the alliance chain can trigger the view switching operation in time after the stable checkpoint state times out, to replace the consensus master node in the alliance chain and restart the consensus operation, thereby avoiding stagnation of each consensus node in the alliance chain status.
此外,由于客户端向联盟链中的共识节点发送的任意request如果能成功达成共识,最终都要在联盟链中达成共识,并在全网广播commit消息,而共识节点在联盟链中针对某一request达成共识之后,则会向其他节点发送checkpoint消息,以便在联盟链中的2f+1个节点针对同一request达成共识操作后进行垃圾回收操作,并将共识节点的状态更改为stable checkpoint状态,因此,如果联盟链中的某个共识节点的stable checkpoint状态出现了超时,也能够体现客户端向共识节点发送的request出现超时。In addition, if any request sent by the client to the consensus node in the consortium chain can successfully reach a consensus, it will eventually reach a consensus in the consortium chain and broadcast a commit message throughout the network, while the consensus node in the consortium chain targets a certain After the request reaches a consensus, it will send a checkpoint message to other nodes, so that 2f+1 nodes in the consortium chain can perform garbage collection operations after reaching a consensus on the same request, and change the state of the consensus node to a stable checkpoint state, so , if the stable checkpoint state of a certain consensus node in the alliance chain has timed out, it can also reflect that the request sent by the client to the consensus node has timed out.
本说明书实施例基于此,并且考虑到联盟链中各个共识节点处理checkpoint消息可以单独作为一个线程,提出基于共识节点的stable checkpoint状态超时,触发联盟链中的视图切换操作。The embodiment of this specification is based on this, and considering that each consensus node in the consortium chain can process the checkpoint message as a separate thread, it is proposed to trigger the view switching operation in the consortium chain based on the timeout of the stable checkpoint state of the consensus node.
具体地,本说明书一个或多个实施例提供的一种联盟链中的共识方法的实现流程示意图如图1所示,包括以下步骤。Specifically, a schematic diagram of the implementation flow of a consensus method in a consortium chain provided by one or more embodiments of this specification is shown in Figure 1 , including the following steps.
步骤110,联盟链中的第一共识节点在生成指定数量的区块时,在联盟链中广播checkpoint消息,checkpoint消息用于指示第一共识节点已经生成指定数量的区块。 Step 110, when the first consensus node in the consortium chain generates a specified number of blocks, it broadcasts a checkpoint message in the consortium chain, and the checkpoint message is used to indicate that the first consensus node has generated a specified number of blocks.
其中,第一共识节点在生成指定数量的区块时,在联盟链中广播checkpoint消息的目的在于就是否可以清除Message Log在全网中达成一致。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 on whether the Message Log can be cleared in the entire network.
可选地,为便于确定清除Message Log中哪些区块对应的消息记录,第一共识节点在联盟链中广播checkpoint消息,包括:第一共识节点基于指定数量的区块中序号最大 的区块的区块号n,在联盟链中广播checkpoint消息,checkpoint消息中携带有指定数量的区块中序号最大的区块的区块号n。Optionally, in order to facilitate the determination of clearing the message records corresponding to which blocks in the Message Log, the first consensus node broadcasts a checkpoint message in the consortium chain, including: The block number n broadcasts the checkpoint message in the consortium chain, and the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.
其中,checkpoint消息中携带有指定数量的区块中序号最大的区块的区块号n的目的在于,就是否可以清除Message Log中区块号n之前的区块对应的消息记录在全网中达成一致。Among them, 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 check whether the message corresponding to the block before the block number n in the Message Log can be cleared and recorded in the entire network agree.
应理解,如果共识节点收到不同节点发送来的Quorum-1个合法的checkpoint消息,加上自己发出的checkpoint消息,则表明共识节点收集到Quorum数量的checkpoint消息,也就能够达成stable checkpoint,进而能够对Message Log中区块号n之前的区块对应的消息记录进行垃圾清理。具体地,当第一共识节点在联盟链中广播checkpoint消息之后,本说明书实施例提供的方法还包括:当第二共识节点生成指定数量的区块时,第二共识节点在联盟链中广播携带有指定数量的区块中序号最大的区块的区块号n的checkpoint消息,第二共识节点广播的checkpoint消息用于指示第二共识节点已经生成指定数量的区块;第一共识节点接收第二共识节点发送的checkpoint消息;当第一共识节点在预设时间段内接收到联盟链中的2f个共识节点的checkpoint消息时,第一共识节点清除第一共识节点中指定数量的区块中序号最大的区块之前的区块对应的消息记录;第一共识节点基于指定数量的区块中序号最大的区块的区块号n,将第一共识节点的状态修改为stable checkpoint。It should be understood that if the consensus node receives Quorum-1 legal checkpoint messages sent by different nodes, plus the checkpoint message sent by itself, it means that the consensus node has collected checkpoint messages of Quorum quantity, and a stable checkpoint can be achieved, and then It is possible to clean up the message records corresponding to the blocks before the block number n in the Message Log. Specifically, after the first consensus node broadcasts the checkpoint message in the alliance chain, the method provided by the embodiment of this specification further includes: when the second consensus node generates a specified number of blocks, the second consensus node broadcasts the checkpoint message in the alliance chain to carry There is a checkpoint message of the block number n of the block with the largest serial number among the specified number of blocks, 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 the The checkpoint message sent by the second consensus node; when the first consensus node receives the checkpoint message of 2f consensus nodes in the alliance chain within the preset time period, the first consensus node clears the specified number of blocks in the first consensus node The message record corresponding to the block before the block with the largest sequence number; the first consensus node modifies the state of the first consensus node to stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.
可选地,上述指定数量为大于或等于1的正整数。Optionally, the above specified number is a positive integer greater than or equal to 1.
可选地,本说明书实施例提供的一种触发视图切换操作的方式为,当指定数量为1时,第一共识节点将第一共识节点的状态修改为stable checkpoint之后,本说明书实施例提供的方法还包括:第一共识节点启动定时器;如果第一共识节点在启动定时器之后的预设时间段内,未接收到联盟链中的其它2f个共识节点的携带有区块号为n+1的checkpoint消息,则第一共识节点确定第一共识节点的stable checkpoint状态超时;第一共识节点基于第一共识节点的stable checkpoint状态超时,在联盟链中触发视图切换操作。Optionally, a way of triggering the view switching operation provided by the embodiment of this specification is that when the specified number is 1, after the first consensus node modifies the state of the first consensus node to stable checkpoint, the method provided by the embodiment of this specification The method also includes: the first consensus node starts the timer; if the first consensus node does not receive the block numbers of n+ 1 checkpoint message, 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 the timeout of the stable checkpoint state of the first consensus node.
联盟链中第一共识节点每执行完一条propose(也就是每生成一个区块),就可以向联盟链中的其它共识节点广播checkpoint消息,针对是否可以清除本共识节点的Message Log在全网达成一致,联盟链中的其它共识节点接收到checkpoint消息后也可以向联盟链中的其它共识节点广播checkpoint消息,也是针对是否可以清除本共识节点的Message Log在全网达成一致。如果联盟链中的第一共识节点在设定的预设时间段内接收到Quorum(2f+1)数量不同共识节点的确认,第一共识节点就可以将共识节点的状态修改 为stable checkpoint。此时,联盟链中的第一共识节点可重新启动定时器,如果第一共识节点在启动定时器之后的预设时间段内,未接收到联盟链中的其它2f个共识节点的携带有区块号为n+1的checkpoint消息,则第一共识节点确定其stable checkpoint状态超时,并可以基于该stable checkpoint状态超时在联盟链中触发视图切换操作。Every time the first consensus node in the consortium chain executes a proposal (that is, every time a block is generated), it can broadcast checkpoint messages to other consensus nodes in the consortium chain to reach an agreement on whether the message log of this consensus node can be cleared in the entire network. Consistent, other consensus nodes in the consortium chain can also broadcast checkpoint messages to other consensus nodes in the consortium chain after receiving the checkpoint message, and also reach a consensus on whether the Message Log of this consensus node can be cleared in the entire network. If the first consensus node in the consortium chain receives confirmations from consensus nodes with different numbers of Quorum (2f+1) within the set preset time period, the first consensus node can modify the status of the consensus node to stable checkpoint. At this time, the first consensus node in the consortium chain can restart the timer. If the first consensus node does not receive the zone data of other 2f consensus nodes in the consortium chain within the preset time period after starting the timer For the checkpoint message with block number n+1, the first consensus node determines that its stable checkpoint status has timed out, and can trigger a view switching operation in the consortium chain based on the stable checkpoint status timeout.
可选地,本说明书实施例提供的另一种触发视图切换操作的方式为,当指定数量为大于1的正整数k时,第一共识节点将第一共识节点的状态修改为stable checkpoint之后,所述方法还包括:第一共识节点启动定时器;如果第一共识节点在启动定时器之后的预设时间段内,未接收到联盟链中的其它2f个共识节点的携带有区块号为n+k的checkpoint消息,则第一共识节点确定第一共识节点的stable checkpoint状态超时;第一共识节点基于第一共识节点的stable checkpoint状态超时,在联盟链中触发视图切换操作。Optionally, another way of triggering the view switching operation provided by the embodiment of this specification is that 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 stable checkpoint, The method also includes: the first consensus node starts the timer; if the first consensus node does not receive the other 2f consensus nodes in the consortium chain within the preset time period after starting the timer, the block number is n+k checkpoint messages, 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 the timeout of the stable checkpoint state of the first consensus node.
联盟链中第一共识节点每执行完k条propose(也就是每生成k个区块),就可以向联盟链中的其它共识节点广播checkpoint消息,针对是否可以清除本共识节点的Message Log在全网达成一致,联盟链中的其它共识节点接收到checkpoint消息后也可以向联盟链中的其它共识节点广播checkpoint消息,也是针对是否可以清除本共识节点的Message Log在全网达成一致。如果联盟链中的第一共识节点在设定的预设时间段内接收到Quorum(2f+1)数量不同共识节点的确认,第一共识节点就可以将共识节点的状态修改为stable checkpoint。此时,联盟链中的第一共识节点可重新启动定时器,如果第一共识节点在启动定时器之后的预设时间段内,未接收到联盟链中的其它2f个共识节点的携带有区块号为n+k的checkpoint消息,则第一共识节点确定其stable checkpoint状态超时,并可以基于该stable checkpoint状态超时在联盟链中触发视图切换操作。Every time the first consensus node in the alliance chain executes k proposals (that is, every time k blocks are generated), it can broadcast checkpoint messages to other consensus nodes in the alliance chain. After reaching a consensus on the network, other consensus nodes in the consortium chain can also broadcast checkpoint messages to other consensus nodes in the consortium chain after receiving the checkpoint message. It is also a consensus on whether the Message Log of this consensus node can be cleared in the entire network. If the first consensus node in the consortium chain receives confirmations from consensus nodes with different numbers of Quorum (2f+1) within the set preset time period, the first consensus node can modify the status of the consensus node to stable checkpoint. At this time, the first consensus node in the consortium chain can restart the timer. If the first consensus node does not receive the zone data of other 2f consensus nodes in the consortium chain within the preset time period after starting the timer For a checkpoint message with block number n+k, the first consensus node determines that its stable checkpoint status has timed out, and can trigger a view switching operation in the consortium chain based on the stable checkpoint status timeout.
步骤120,联盟链中的第二共识节点接收第一共识节点发送的checkpoint消息。 Step 120, the second consensus node in the consortium chain receives the checkpoint message sent by the first consensus node.
联盟链中的第二共识节点本身在生成指定数量的区块时,也可以在联盟链中广播checkpoint消息,checkpoint消息用于指示第二共识节点已经生成指定数量的区块。第二共识节点在联盟链中广播checkpoint消息的同时,也会接收到第一共识节点等联盟链中的其它共识节点发送的checkpoint消息。When the second consensus node in the consortium chain generates a specified number of blocks, it can also broadcast a checkpoint message in the consortium chain. The checkpoint message is used to indicate that the second consensus node has generated a specified number of blocks. While the second consensus node broadcasts the checkpoint message in the alliance chain, it will also receive the checkpoint message sent by other consensus nodes in the alliance chain such as the first consensus node.
步骤130,如果第二共识节点在预设时间段内未接收到联盟链中的其它2f个共识节点发送的checkpoint消息,则第二共识节点确定第二共识节点的stable checkpoint状态超时。 Step 130, if the second consensus node does not receive checkpoint messages sent by other 2f consensus nodes in the consortium chain within the preset time period, the second consensus node determines that the stable checkpoint state of the second consensus node has timed out.
其中,预设时间段的时长为第二共识节点本地设置的定时器触发超时的时长。如果第二共识节点在预设时间段内未接收到联盟链中的其它2f个共识节点发送的checkpoint 消息,则第二共识节点无法收集Quorum数量的checkpoint消息,也就无法达成stable checkpoint,进而无法对本共识节点中的Message Log进行垃圾清理操作。本说明书实施例将共识节点无法达成stable checkpoint的状态简称为stable checkpoint状态超时。Wherein, the duration of the preset time period is the duration of the timer set locally by the second consensus node to trigger timeout. If the second consensus node does not receive the checkpoint messages sent by other 2f consensus nodes in the consortium chain within the preset time period, the second consensus node cannot collect the checkpoint messages of Quorum quantity, and cannot achieve stable checkpoint, and thus cannot Perform garbage cleaning operations on the Message Log in this consensus node. In the embodiment of this specification, the state that the consensus node cannot reach the stable checkpoint is simply referred to as the stable checkpoint state timeout.
步骤140,第二共识节点基于第二共识节点的stable checkpoint状态超时,在联盟链中发起视图切换操作,f为联盟链中允许的最大异常共识节点数量。 Step 140, the second consensus node initiates a view switching operation in the consortium 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 consortium chain.
当第二共识节点的stable checkpoint状态超时,即表明第二共识节点的stable checkpoint无法进行更新,也就表明第二共识节点无法继续进行对propose的共识操作了,此时,为了改变这种状况,第二共识节点可基于其本地的stable checkpoint状态超时,在联盟链中发起视图切换操作,以试图更换联盟链中的共识主节点。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 consortium chain based on the timeout of its local stable checkpoint state, in an attempt to replace the consensus master node in the consortium chain.
需要说明的是,本说明书实施例中的共识算法除PBFT算法以外,还可适用于RAFT算法,等能够区分共识主节点和共识备份节点的共识算法。本说明书实施例对所采用的共识算法不做具体限制,只要所采用的共识算法存在共识主节点即可。It should be noted that, in addition to the PBFT algorithm, the consensus algorithm in the embodiment of this specification can also be applied to the RAFT algorithm, and other consensus algorithms that can distinguish between consensus master nodes and consensus backup nodes. The embodiment of this specification does not impose specific restrictions on the adopted consensus algorithm, as long as there is a consensus master node in the adopted consensus algorithm.
下面以图2所示采用PBFT算法进行共识操作的过程示意图,对本说明书实施例提供的共识方法进行详细说明。在图2中,C为客户端,共识节点0为本次共识操作过程中的共识主节点,共识节点1~共识节点3为本次共识操作过程中的共识备份节点。图2所示的示意图包括以下几种情况:第一种情况,共识节点0为作恶节点,共识节点0欺骗共识节点1和共识节点2执行对客户端请求共识的消息m的共识操作(图2所示的实线部分),而共识节点0本身和共识节点3不执行对客户端请求共识的消息m的共识操作(图2所示的虚线部分)。即使共识节点0持续作恶,但是,随着不断地处理消息m,一方面,共识节点3由于不执行任何共识操作,其本地的定时器在设定的时间段之后会超时,从而在联盟链中触发视图切换操作;另一方面,共识节点1和共识节点2虽然执行了对m的共识操作,但共识节点1和共识节点2在执行完m的共识操作后会达到checkpoint,从而在联盟链中广播checkpoint消息,但由于共识节点0和共识节点3并没有执行对m的共识操作,也就不会达到checkpoint,进而不会在联盟链中广播checkpoint消息,这就使得共识节点1和共识节点2无法收集到Quorum数量的checkpoint消息,无法达成stable checkpoint,进一步地,共识节点1和共识节点2达到高水位后不再继续执行,共识节点1和共识节点2在设定时间段后本地的定时器也会超时,进而触发视图切换操作。The consensus method provided by the embodiment of this specification will be described in detail below with the schematic diagram of the consensus operation process using the PBFT algorithm shown in FIG. 2 . In Figure 2, C is the client, consensus node 0 is the consensus master node during this consensus operation, and consensus nodes 1 to 3 are consensus backup nodes during this consensus operation. The schematic diagram shown in Figure 2 includes the following situations: In the first case, the consensus node 0 is a malicious node, and the consensus node 0 deceives the consensus node 1 and the consensus node 2 to perform the consensus operation on the message m requesting consensus from the client (Figure 2 shown in the solid line), while the consensus node 0 itself and the consensus node 3 do not perform the consensus operation on the message m requesting consensus from the client (the dotted line shown in Figure 2). Even if the consensus node 0 continues to do evil, but, as the message m is continuously processed, on the one hand, since the consensus node 3 does not perform any consensus operations, its local timer will time out after the set period of time, thus in the consortium chain Trigger the view switching operation; on the other hand, although the consensus node 1 and the consensus node 2 have executed the consensus operation on m, the consensus node 1 and the consensus node 2 will reach the checkpoint after executing the consensus operation of m, so that in the alliance chain Broadcast the checkpoint message, but because the consensus node 0 and the consensus node 3 did not perform the consensus operation on m, the checkpoint will not be reached, and the checkpoint message will not be broadcast in the alliance chain, which makes the consensus node 1 and the consensus node 2 Unable to collect checkpoint messages of the number of Quorum, unable to achieve stable checkpoint, further, consensus node 1 and consensus node 2 will not continue to execute after reaching the high water level, consensus node 1 and consensus node 2 will set the local timer after the set time period It will also time out, which will trigger the view switching operation.
第二种情况,如果共识节点0也是持续像第一种情况中那样作恶,则共识节点3本地的定时器也会超时,从而在联盟链中发起视图切换操作;同时,由于第一种情况中,共识节点1和共识节点2一直无法达成stable checkpoint,即stable checkpoint状态超时, 这样,共识节点1和共识节点2也会在联盟链中触发视图切换操作,进而能够达成Quorum数量的视图切换操作,完成换主。In the second case, if the consensus node 0 continues to do evil like in the first case, the local timer of the consensus node 3 will also time out, thereby initiating a view switching operation in the alliance chain; at the same time, due to the fact that in the first case , Consensus Node 1 and Consensus Node 2 have been unable to reach a stable checkpoint, that is, the stable checkpoint state has timed out. In this way, Consensus Node 1 and Consensus Node 2 will also trigger a view switching operation in the alliance chain, and then can achieve a Quorum number of view switching operations. Complete the master change.
第三种情况,在联盟链网络中,某个共识节点每生成一个区块,都可以通过P2P协议广播成块的消息给其它共识节点,接收到广播成块消息的共识节点,如图2中的共识节点3,发现成块消息中区块高度高于自己本地的最高区块高度,则会从共识节点1或共识节点2同步最新的区块(该区块中已经有2f+1个签名,可以从共识节点1或共识节点2推送或拉取,也不管共识节点0的区块的高度是多少),从而保持与共识节点1或共识节点2同步。In the third case, in the alliance chain network, every time a consensus node generates a block, it can broadcast a block message to other consensus nodes through the P2P protocol, and receive the consensus node that broadcasts the block message, as shown in Figure 2 If the consensus node 3 finds that the block height in the block message is higher than its local maximum block height, it will synchronize the latest block from consensus node 1 or consensus node 2 (there are already 2f+1 signatures in the block , can be pushed or pulled from consensus node 1 or consensus node 2, regardless of the height of the block of consensus node 0), so as to maintain synchronization with consensus node 1 or consensus node 2.
采用本说明书实施例提供的共识方法,联盟链中的第一共识节点在生成指定数量的区块时,在联盟链中广播checkpoint消息,该checkpoint消息用于指示第一共识节点已经生成指定数量的区块;联盟链中的第二共识节点接收第一共识节点发送的checkpoint消息;如果第二共识节点在预设时间段内未接收到联盟链中的其它2f个共识节点发送的checkpoint消息,则第二共识节点确定第二共识节点的stable checkpoint状态超时;并且第二共识节点基于第二共识节点的stable checkpoint状态超时,在联盟链中发起视图切换操作,f为联盟链中允许的最大异常共识节点数量。由于共识节点统计从联盟链中的其它共识节点接收到的checkpoint消息可以单独使用一个线程,从而能够避免在某一瞬间给共识节点造成极大压力,进而使得共识节点能够更加准确地在联盟链中触发视图切换操作。Using the consensus method provided by the embodiment of this specification, when the first consensus node in the consortium chain generates a specified number of blocks, it broadcasts a checkpoint message in the consortium chain. The checkpoint message is used to indicate that the first consensus node has generated a specified number of blocks. block; 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 other 2f consensus nodes in the alliance chain within the preset time period, then 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 timeout of the stable checkpoint state of the second consensus node, f is the maximum abnormal consensus allowed in the alliance chain number of nodes. Since the consensus node counts the checkpoint messages received from other consensus nodes in the consortium chain, one thread can be used alone, which can avoid causing great pressure on the consensus node at a certain moment, and thus enable the consensus node to be more accurate in the consortium chain. Trigger a view switch operation.
图3是本说明书实施例提供的联盟链系统300的结构示意图。请参考图3,在一种软件实施方式中,联盟链系统300可包括第一共识节点310和第二共识节点320,其中:第一共识节点310,在生成指定数量的区块时,在所述联盟链中广播checkpoint消息,所述checkpoint消息用于指示所述第一共识节点已经生成所述指定数量的区块;第二共识节点320,接收所述第一共识节点发送的checkpoint消息,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定所述第二共识节点的stable checkpoint状态超时;以及基于所述第二共识节点的stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。Fig. 3 is a schematic structural diagram of the consortium chain system 300 provided by the embodiment of this specification. Please refer to FIG. 3 , in a software implementation, the consortium chain system 300 may include a first consensus node 310 and a second consensus node 320, wherein: the first consensus node 310, when generating a specified number of blocks, A checkpoint message is broadcast in the consortium 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 320 receives the checkpoint message sent by the first consensus node, if If the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the 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 of the second consensus node When the state is timed out, a view switch operation is initiated in the alliance chain, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
可选地,在一种实施方式中,所述第一共识节点310,用于:基于所述指定数量的区块中序号最大的区块的区块号n,在所述联盟链中广播checkpoint消息,所述checkpoint消息中携带有所述指定数量的区块中序号最大的区块的区块号n。Optionally, in an implementation manner, the first consensus node 310 is configured to: broadcast a checkpoint in the consortium chain based on the block number n of the block with the largest sequence number among the specified number of blocks message, the checkpoint message carries the block number n of the block with the largest sequence number among the specified number of blocks.
可选地,在一种实施方式中,当所述第一共识节点在所述联盟链中广播checkpoint 消息之后,当所述第二共识节点生成所述指定数量的区块时,所述第二共识节点在所述联盟链中广播携带有所述指定数量的区块中序号最大的区块的区块号n的checkpoint消息,所述第二共识节点广播的checkpoint消息用于指示所述第二共识节点已经生成所述指定数量的区块;所述第一共识节点接收所述第二共识节点发送的checkpoint消息;当所述第一共识节点在所述预设时间段内接收到所述联盟链中的2f个共识节点的checkpoint消息时,所述第一共识节点清除所述第一共识节点中所述指定数量的区块中序号最大的区块之前的区块对应的消息记录;所述第一共识节点基于所述指定数量的区块中序号最大的区块的区块号n,将所述第一共识节点的状态修改为stable checkpoint。Optionally, in an implementation manner, after the first consensus node broadcasts a checkpoint message in the consortium chain, when the second consensus node generates the specified number of blocks, the second The consensus node broadcasts in the consortium chain a checkpoint message carrying the block number n of the block with the largest sequence number among the specified number of blocks, and the checkpoint message broadcast by the second consensus node is used to indicate that the second The consensus node has generated the specified number of blocks; the first consensus node receives the checkpoint message sent by the second consensus node; when the first consensus node receives the alliance within the preset time period When there are checkpoint messages from 2f consensus nodes in the chain, the first consensus node clears the message record corresponding to the block before the block with the largest sequence number in the specified number of blocks in the first consensus node; The first consensus node modifies the state of the first consensus node to stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.
在一种实施方式中,所述指定数量为大于或等于1的正整数。In one embodiment, the specified number is a positive integer greater than or equal to 1.
在一种实施方式中,当所述指定数量为1时,所述第一共识节点将所述第一共识节点的状态修改为stable checkpoint之后,所述方法还包括:所述第一共识节点启动定时器;如果所述第一共识节点在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+1的checkpoint消息,则所述第一共识节点确定所述第一共识节点的stable checkpoint状态超时;所述第一共识节点基于所述第一共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。In one embodiment, when the specified number is 1, after the first consensus node modifies the state of the first consensus node to stable checkpoint, the method further includes: the first consensus node starts timer; if the first consensus node does not receive the block number n+1 carried by the other 2f consensus nodes in the consortium chain within the preset time period after starting the timer checkpoint message, the first consensus node determines that the stable checkpoint state of the first consensus node has timed out; View switching operation.
在一种实施方式中,当所述指定数量为大于1的正整数k时,所述第一共识节点将所述第一共识节点的状态修改为stable checkpoint之后,所述方法还包括:所述第一共识节点启动定时器;如果所述第一共识节点在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+k的checkpoint消息,则所述第一共识节点确定所述第一共识节点的stable checkpoint状态超时;所述第一共识节点基于所述第一共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。In one embodiment, 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 stable checkpoint, the method further includes: the The first consensus node starts the timer; if the first consensus node does not receive the blocks carried by other 2f consensus nodes in the consortium chain within the preset time period after starting the timer n+k checkpoint message, the first consensus node determines that the stable checkpoint status of the first consensus node has timed out; the first consensus node is based on the stable checkpoint status of the first consensus node. Trigger the view switching operation in the alliance chain mentioned above.
在一种实施方式中,所述第一共识节点为所述联盟链中的任意一个共识节点;所述第二共识节点为所述联盟链中的任意一个共识节点。In one embodiment, the first consensus node is any consensus node in the consortium chain; the second consensus node is any consensus node in the consortium chain.
联盟链系统300能够实现图1~图2的方法实施例的方法,具体可参考图1~图2所示实施例的联盟链中的共识方法,不再赘述。The consortium chain system 300 can implement the methods in the method embodiments in FIGS. 1-2 . For details, please refer to the consensus method in the consortium chain in the embodiment shown in FIGS. 1-2 , and details will not be repeated here.
图4是本说明书一个实施例提供的一种联盟链中的共识节点400的结构示意图,包括:广播模块410,在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收模块420,接收所述联盟链中的其它共识节点发送的checkpoint消息;状态确定模块430,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable  checkpoint状态超时;视图切换模块440,基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。Fig. 4 is a schematic structural diagram of a consensus node 400 in a consortium chain provided by an embodiment of this specification, including: a broadcast module 410, which broadcasts a checkpoint message in the consortium chain when a specified number of blocks are generated, the checkpoint message It is used to indicate that the specified number of blocks has been generated; the receiving module 420 receives checkpoint messages sent by other consensus nodes in the alliance chain; the state determination module 430, if the alliance chain is not received within a preset time period The checkpoint message sent by other 2f consensus nodes in the chain determines that the stable checkpoint state is overtime; the view switching module 440 initiates a view switching operation in the alliance chain based on the timeout of the stable checkpoint state, and f is the alliance chain The maximum number of abnormal consensus nodes allowed in .
在一种实施方式中,所述广播模块410,用于:基于所述指定数量的区块中序号最大的区块的区块号n,在所述联盟链中广播checkpoint消息,所述checkpoint消息中携带有所述指定数量的区块中序号最大的区块的区块号n。In one embodiment, the broadcast module 410 is configured to: broadcast a checkpoint message in the consortium 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.
在一种实施方式中,状态确定模块430,还用于:当在所述预设时间段内接收到所述联盟链中的2f个共识节点的checkpoint消息时,清除本共识节点中所述指定数量的区块中序号最大的区块之前的区块对应的消息记录;基于所述指定数量的区块中序号最大的区块的区块号n,将本共识节点的状态修改为stable checkpoint。In one embodiment, the status determination module 430 is further configured to: clear the designated node in this consensus node when receiving checkpoint messages from 2f consensus nodes in the consortium chain within the preset time period. The message record corresponding to the block before the block with the largest serial number among the number of blocks; based on the block number n of the block with the largest serial number among the specified number of blocks, modify the status of the consensus node to stable checkpoint.
在一种实施方式中,所述指定数量为大于或等于1的正整数。In one embodiment, the specified number is a positive integer greater than or equal to 1.
在一种实施方式中,当所述指定数量为1时,所述状态确定模块430将本共识节点的状态修改为stable checkpoint之后,所述视图切换模块440,还用于:启动定时器;如果在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+1的checkpoint消息,则确定本共识节点的stable checkpoint状态超时;基于本共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。In one embodiment, when the specified number is 1, after the state determination module 430 modifies the state of this consensus node to stable checkpoint, the view switching module 440 is also used to: start the timer; if Within the preset time period after starting the timer, if no checkpoint message carrying block number n+1 from other 2f consensus nodes in the consortium chain is received, then the consensus node’s The stable checkpoint state timed out; based on the timeout of the stable checkpoint state of the consensus node, the view switching operation is triggered in the alliance chain.
在一种实施方式中,当所述指定数量为大于1的正整数k时,所述状态确定模块430将本共识节点的状态修改为stable checkpoint之后,所述视图切换模块440,还用于:启动定时器;如果在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+k的checkpoint消息,则确定本共识节点的stable checkpoint状态超时;基于本共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。In one embodiment, 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 stable checkpoint, the view switching module 440 is further configured to: Start the timer; if within the preset time period after starting the timer, the checkpoint message carrying the block number n+k of the other 2f consensus nodes in the consortium chain is not received, then Determine the timeout of the stable checkpoint state of the consensus node; based on the timeout of the stable checkpoint state of the consensus node, trigger the view switching operation in the alliance chain.
在一种实施方式中,所述联盟链中的共识节点400为所述联盟链中的任意一个共识节点。In one embodiment, the consensus node 400 in the consortium chain is any consensus node in the consortium chain.
联盟链中的共识节点400能够实现图1的方法实施例的方法,具体可参考图1所示实施例的联盟链中的共识方法,不再赘述。The consensus node 400 in the consortium chain can implement the method in the method embodiment in FIG. 1 . For details, please refer to the consensus method in the consortium chain in the embodiment shown in FIG. 1 , which will not be repeated here.
图5是本说明书的一个实施例提供的电子设备的结构示意图。请参考图5,在硬件层面,该电子设备包括处理器,可选地还包括内部总线、网络接口、存储器。其中,存储器可能包含内存,例如高速随机存取存储器(Random-Access Memory,RAM),也可能还包括非易失性存储器(non-volatile memory),例如至少1个磁盘存储器等。当然,该电子设备还可能包括其他业务所需要的硬件。Fig. 5 is a schematic structural diagram of an electronic device provided by an embodiment of this specification. Please refer to FIG. 5 , at the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. Wherein, the memory may include a memory, such as a high-speed random-access memory (Random-Access Memory, RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory. Of course, the electronic device may also include hardware required by other services.
处理器、网络接口和存储器可以通过内部总线相互连接,该内部总线可以是ISA(Industry Standard Architecture,工业标准体系结构)总线、PCI(Peripheral Component Interconnect,外设部件互连标准)总线或EISA(Extended Industry Standard Architecture,扩展工业标准结构)总线等。所述总线可以分为地址总线、数据总线、控制总线等。为便于表示,图5中仅用一个双向箭头表示,但并不表示仅有一根总线或一种类型的总线。The processor, the network interface and the memory can be connected to each other through an internal bus, which can be an ISA (Industry Standard Architecture, industry standard architecture) bus, a PCI (Peripheral Component Interconnect, peripheral component interconnection standard) bus or an EISA (Extended Industry Standard Architecture, extended industry standard architecture) bus, etc. The bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one double-headed arrow is used in FIG. 5 , but it does not mean that there is only one bus or one type of bus.
存储器,用于存放程序。具体地,程序可以包括程序代码,所述程序代码包括计算机操作指令。存储器可以包括内存和非易失性存储器,并向处理器提供指令和数据。Memory for storing programs. Specifically, the program may include program code, and the program code includes computer operation instructions. Storage, which can include internal memory and nonvolatile storage, provides instructions and data to the processor.
处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行,在逻辑层面上形成联盟链中的共识节点部署的区块链系统。处理器,执行存储器所存放的程序,并具体用于执行以下操作:在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收所述联盟链中的其它共识节点发送的checkpoint消息;如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。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 consensus nodes in the consortium chain on a logical level. The processor executes the program stored in the memory, and is specifically used to perform the following operations: when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated block; receive checkpoint messages sent by other consensus nodes in the alliance chain; if the checkpoint messages sent by other 2f consensus nodes in the alliance chain are not received within the preset time period, then determine that the stable checkpoint state is overtime; 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.
上述如本说明书图1所示实施例揭示的联盟链中的共识方法可以应用于处理器中,或者由处理器实现。处理器可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本说明书一个或多个实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本说明书一个或多个实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器,处理器读取存储器中的信息,结合其硬件完成上述方法的步骤。The above-mentioned consensus method in the consortium chain disclosed in the embodiment shown in FIG. 1 of this specification can be applied to the processor, or implemented by the processor. A 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 a processor or an instruction in the form of software. The above-mentioned processor can be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; it can also be a digital signal processor (Digital Signal Processor, DSP), a dedicated integrated Circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The various methods, steps and logic block diagrams disclosed in one or more embodiments of this specification can be realized or executed. A general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like. The steps of the method disclosed in conjunction with one or more embodiments of this specification may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register. 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.
该电子设备还可执行图1的联盟链中的共识方法,本说明书在此不再赘述。The electronic device can also execute the consensus method in the consortium chain shown in FIG. 1 , which will not be repeated here in this specification.
当然,除了软件实现方式之外,本说明书的电子设备并不排除其他实现方式,比如 逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。Of course, in addition to the software implementation, the electronic equipment in this specification does not exclude other implementations, such as logic devices or the 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, It can also be a hardware or logic device.
本说明书实施例还提出了一种计算机可读存储介质,该计算机可读存储介质存储一个或多个程序,该一个或多个程序包括指令,该指令当被包括多个应用程序的便携式电子设备执行时,能够使该便携式电子设备执行图5所示实施例的方法,并具体用于执行以下操作:在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;接收所述联盟链中的其它共识节点发送的checkpoint消息;如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。The embodiment of this specification also proposes a computer-readable storage medium, the computer-readable storage medium stores one or more programs, and the one or more programs include instructions, and the instructions are used when a portable electronic device including multiple application programs During execution, the portable electronic device can be made to execute the method of the embodiment shown in FIG. 5, and is specifically used to perform the following operations: when a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used for Indicate that the specified number of blocks has been generated; receive the checkpoint message sent by other consensus nodes in the alliance chain; if the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the preset time period message, it is determined that the stable checkpoint state has timed out; 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.
总之,以上所述仅为本说明书的较佳实施例而已,并非用于限定本说明书的保护范围。凡在本说明书一个或多个实施例的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例的保护范围之内。In a word, the above descriptions are only preferred embodiments of this specification, and are not intended to limit the scope of protection 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.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing 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 Combinations of any of these devices.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. Information may be computer readable instructions, data structures, modules of a program, 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 Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic tape cartridge, tape magnetic disk storage or other magnetic storage device or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有 的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus comprising a set of elements includes not only those elements, but also includes Other elements not expressly listed, or elements inherent in the process, method, commodity, or apparatus are also included. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this specification is described in a progressive manner, the same and similar parts of each embodiment 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 for relevant parts, refer to part of the description of the method embodiment.

Claims (11)

  1. 一种联盟链中的共识方法,包括:A consensus method in the alliance chain, including:
    联盟链中的第一共识节点在生成指定数量的区块时,在所述联盟链中广播checkpoint消息,所述checkpoint消息用于指示所述第一共识节点已经生成所述指定数量的区块;When the first consensus node in the consortium chain generates a specified number of blocks, it broadcasts a checkpoint message in the consortium chain, and the checkpoint message is used to indicate that the first consensus node has generated the specified number of blocks;
    所述联盟链中的第二共识节点接收所述第一共识节点发送的checkpoint消息;The second consensus node in the consortium chain receives the checkpoint message sent by the first consensus node;
    如果所述第二共识节点在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则所述第二共识节点确定所述第二共识节点的stable checkpoint状态超时;If the second consensus node does not receive the checkpoint message sent by other 2f consensus nodes in the alliance chain within the preset time period, the second consensus node determines the stable checkpoint status of the second consensus node time out;
    所述第二共识节点基于所述第二共识节点的stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。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. 如权利要求1所述的方法,第一共识节点在所述联盟链中广播checkpoint消息,包括:The method according to claim 1, wherein the first consensus node broadcasts a checkpoint message in the alliance chain, comprising:
    所述第一共识节点基于所述指定数量的区块中序号最大的区块的区块号n,在所述联盟链中广播checkpoint消息,所述checkpoint消息中携带有所述指定数量的区块中序号最大的区块的区块号n。The first consensus node broadcasts a checkpoint message in the consortium 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 specified number of blocks The block number n of the block with the largest sequence number.
  3. 如权利要求2所述的方法,当所述第一共识节点在所述联盟链中广播checkpoint消息之后,所述方法还包括:The method according to claim 2, after the first consensus node broadcasts a checkpoint message in the consortium chain, the method further comprises:
    当所述第二共识节点生成所述指定数量的区块时,所述第二共识节点在所述联盟链中广播携带有所述指定数量的区块中序号最大的区块的区块号n的checkpoint消息,所述第二共识节点广播的checkpoint消息用于指示所述第二共识节点已经生成所述指定数量的区块;When the second consensus node generates the specified number of blocks, the second consensus node broadcasts the block number n of the block with the largest sequence number among the specified number of blocks in the alliance chain checkpoint message, 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;
    所述第一共识节点接收所述第二共识节点发送的checkpoint消息;The first consensus node receives the checkpoint message sent by the second consensus node;
    当所述第一共识节点在所述预设时间段内接收到所述联盟链中的2f个共识节点的checkpoint消息时,所述第一共识节点清除所述第一共识节点中所述指定数量的区块中序号最大的区块之前的区块对应的消息记录;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 specified number of The message record corresponding to the block before the block with the largest sequence number in the block;
    所述第一共识节点基于所述指定数量的区块中序号最大的区块的区块号n,将所述第一共识节点的状态修改为stable checkpoint。The first consensus node modifies the state of the first consensus node to stable checkpoint based on the block number n of the block with the largest sequence number among the specified number of blocks.
  4. 如权利要求3所述的方法,所述指定数量为大于或等于1的正整数。The method according to claim 3, wherein the specified number is a positive integer greater than or equal to 1.
  5. 如权利要求4所述的方法,当所述指定数量为1时,所述第一共识节点将所述第一共识节点的状态修改为stable checkpoint之后,所述方法还包括:The method according to claim 4, when the specified number is 1, after the first consensus node modifies the state of the first consensus node to stable checkpoint, the method further includes:
    所述第一共识节点启动定时器;The first consensus node starts a timer;
    如果所述第一共识节点在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+1的checkpoint消息,则所述第一共识节点确定所述第一共识节点的stable checkpoint状态超时;If the first consensus node does not receive checkpoint messages carrying block number n+1 from other 2f consensus nodes in the consortium chain within the preset time period after starting the timer , then the first consensus node determines that the stable checkpoint state of the first consensus node times out;
    所述第一共识节点基于所述第一共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。The first consensus node triggers a view switching operation in the consortium chain based on the timeout of the stable checkpoint state of the first consensus node.
  6. 如权利要求4所述的方法,当所述指定数量为大于1的正整数k时,所述第一共识节点将所述第一共识节点的状态修改为stable checkpoint之后,所述方法还包括:The method according to 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 stable checkpoint, the method further includes:
    所述第一共识节点启动定时器;The first consensus node starts a timer;
    如果所述第一共识节点在启动所述定时器之后的所述预设时间段内,未接收到所述联盟链中的其它2f个共识节点的携带有区块号为n+k的checkpoint消息,则所述第一共识节点确定所述第一共识节点的stable checkpoint状态超时;If the first consensus node does not receive checkpoint messages with block number n+k from other 2f consensus nodes in the consortium chain within the preset time period after starting the timer , then the first consensus node determines that the stable checkpoint state of the first consensus node times out;
    所述第一共识节点基于所述第一共识节点的stable checkpoint状态超时,在所述联盟链中触发视图切换操作。The first consensus node triggers a view switching operation in the consortium chain based on the timeout of the stable checkpoint state of the first consensus node.
  7. 如权利要求1~6中任一所述的方法,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. 一种联盟链系统,包括:An alliance chain system, including:
    第一共识节点,在生成指定数量的区块时,在所述联盟链中广播checkpoint消息,所述checkpoint消息用于指示所述第一共识节点已经生成所述指定数量的区块;The first consensus node, when generating a specified number of blocks, 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;
    第二共识节点,接收所述第一共识节点发送的checkpoint消息,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定所述第二共识节点的stable checkpoint状态超时;以及基于所述第二共识节点的stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。The second consensus node receives the checkpoint message sent by the first consensus node, and if it does not receive the checkpoint message sent by other 2f consensus nodes in the alliance chain within the preset time period, then determine the second consensus node The stable checkpoint state of the node is 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, and f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
  9. 一种联盟链中的共识节点,包括:A consensus node in the alliance chain, including:
    广播模块,在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;The broadcast module broadcasts a checkpoint message in the consortium chain when generating a specified number of blocks, and the checkpoint message is used to indicate that the specified number of blocks has been generated;
    接收模块,接收所述联盟链中的其它共识节点发送的checkpoint消息;The receiving module receives checkpoint messages sent by other consensus nodes in the alliance chain;
    状态确定模块,如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;The state determination module, if the checkpoint message sent by other 2f consensus nodes in the alliance chain is not received within the preset time period, then determine that the stable checkpoint state is overtime;
    视图切换模块,基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。The view switching module, based on the timeout of the stable checkpoint state, initiates a view switching operation in the alliance chain, where f is the maximum number of abnormal consensus nodes allowed in the alliance chain.
  10. 一种电子设备,包括:An electronic device comprising:
    处理器;以及processor; and
    被安排成存储计算机可执行指令的存储器,所述可执行指令在被执行时使所述处理器执行以下操作:a memory arranged to store computer-executable instructions that, when executed, cause the processor to:
    在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;When a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated;
    接收所述联盟链中的其它共识节点发送的checkpoint消息;Receive checkpoint messages sent by other consensus nodes in the alliance chain;
    如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within the preset time period, the stable checkpoint state is determined to be timed out;
    基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。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 that stores one or more programs that, when executed by an electronic device including a plurality of application programs, cause the electronic device to perform the following operations :
    在生成指定数量的区块时,在联盟链中广播checkpoint消息,所述checkpoint消息用于指示已经生成所述指定数量的区块;When a specified number of blocks is generated, a checkpoint message is broadcast in the consortium chain, and the checkpoint message is used to indicate that the specified number of blocks has been generated;
    接收所述联盟链中的其它共识节点发送的checkpoint消息;Receive checkpoint messages sent by other consensus nodes in the alliance chain;
    如果在预设时间段内未接收到所述联盟链中的其它2f个共识节点发送的checkpoint消息,则确定stable checkpoint状态超时;If the checkpoint message sent by the other 2f consensus nodes in the alliance chain is not received within the preset time period, the stable checkpoint state is determined to be timed out;
    基于所述stable checkpoint状态超时,在所述联盟链中发起视图切换操作,f为所述联盟链中允许的最大异常共识节点数量。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.
PCT/CN2022/109829 2021-09-24 2022-08-03 Consensus in consortium blockchain WO2023045574A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111122765.9 2021-09-24
CN202111122765.9A CN113836232A (en) 2021-09-24 2021-09-24 Consensus method and system in alliance chain

Publications (1)

Publication Number Publication Date
WO2023045574A1 true WO2023045574A1 (en) 2023-03-30

Family

ID=78970015

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/109829 WO2023045574A1 (en) 2021-09-24 2022-08-03 Consensus in consortium blockchain

Country Status (2)

Country Link
CN (1) CN113836232A (en)
WO (1) WO2023045574A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113836232A (en) * 2021-09-24 2021-12-24 支付宝(杭州)信息技术有限公司 Consensus method and system in alliance chain
CN114529414A (en) * 2022-02-24 2022-05-24 蚂蚁区块链科技(上海)有限公司 Transaction processing method of block chain, block chain node and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180152289A1 (en) * 2016-11-30 2018-05-31 International Business Machines Corporation Checkpoints for permissionless blockchains
CN109784916A (en) * 2018-12-12 2019-05-21 广东工业大学 A method of ether mill common recognition mechanism that improving PBFT is applied to alliance's chain
CN111555858A (en) * 2020-03-20 2020-08-18 北京邮电大学 Practical Byzantine fault-tolerant consensus method based on block chain type storage
CN111612455A (en) * 2020-04-21 2020-09-01 国网江苏省电力有限公司电力科学研究院 Power consumption information protection-oriented Byzantine fault-tolerant alliance chain consensus method, system and storage medium
CN112988470A (en) * 2021-04-27 2021-06-18 支付宝(杭州)信息技术有限公司 Consensus method, consensus node and system in alliance chain
CN113360567A (en) * 2021-04-29 2021-09-07 广西电网有限责任公司 Safe storage method and application of electric power transaction distributed account book based on block chain
CN113836232A (en) * 2021-09-24 2021-12-24 支付宝(杭州)信息技术有限公司 Consensus method and system in alliance chain

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111865608B (en) * 2020-07-02 2022-08-26 南京邮电大学 Consensus mechanism operation method applied to alliance chain
CN111526216B (en) * 2020-07-03 2020-09-22 支付宝(杭州)信息技术有限公司 Consensus method and system in alliance chain
CN112929186B (en) * 2021-02-22 2022-02-22 北京航空航天大学 Alliance chain consensus optimization method based on communication mode structure

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180152289A1 (en) * 2016-11-30 2018-05-31 International Business Machines Corporation Checkpoints for permissionless blockchains
CN109784916A (en) * 2018-12-12 2019-05-21 广东工业大学 A method of ether mill common recognition mechanism that improving PBFT is applied to alliance's chain
CN111555858A (en) * 2020-03-20 2020-08-18 北京邮电大学 Practical Byzantine fault-tolerant consensus method based on block chain type storage
CN111612455A (en) * 2020-04-21 2020-09-01 国网江苏省电力有限公司电力科学研究院 Power consumption information protection-oriented Byzantine fault-tolerant alliance chain consensus method, system and storage medium
CN112988470A (en) * 2021-04-27 2021-06-18 支付宝(杭州)信息技术有限公司 Consensus method, consensus node and system in alliance chain
CN113360567A (en) * 2021-04-29 2021-09-07 广西电网有限责任公司 Safe storage method and application of electric power transaction distributed account book based on block chain
CN113836232A (en) * 2021-09-24 2021-12-24 支付宝(杭州)信息技术有限公司 Consensus method and system in alliance chain

Also Published As

Publication number Publication date
CN113836232A (en) 2021-12-24

Similar Documents

Publication Publication Date Title
WO2023045574A1 (en) Consensus in consortium blockchain
EP3547648B1 (en) Service processing and consensus method and device
JP6876806B2 (en) Blockchain Consensus Formation Methods and Devices
CN108648078B (en) Transaction preprocessing method and device and electronic equipment
WO2018161901A1 (en) Consensus method and device
RU2714098C1 (en) Data processing method and device
WO2019153490A1 (en) Method and device for real estate transaction, computer-readable storage medium, and terminal device
WO2018040589A1 (en) Distributed storage system based data processing method and storage device
CN108881120B (en) Data processing method and device based on block chain
CN111600965B (en) Consensus method and system in blockchain
EP3565219B1 (en) Service execution method and device
CN108846749B (en) Partitioned transaction execution system and method based on block chain technology
CN110162270B (en) Data storage method, storage node and medium based on distributed storage system
CN110648136B (en) Consensus and transaction synchronous parallel processing method and device and electronic equipment
WO2020063763A1 (en) Data storage method, apparatus and system, and server, control node and medium
WO2023016428A1 (en) Byzantine fault tolerance method and apparatus, and electronic device and storage medium
CN110020859B (en) Parallel execution block chain consensus method and device and electronic equipment
EP3816924B1 (en) Method for accepting blockchain evidence storage transaction and system
WO2019057193A1 (en) Data deletion method and distributed storage system
WO2023016429A1 (en) Binary consensus method and apparatus capable of revoting, electronic device, and storage medium
CN112988470B (en) Consensus method, consensus node and system in alliance chain
CN108829498B (en) Service data access method and device
CN113347174B (en) Consensus method and device in block chain and electronic equipment
CN109144403B (en) Method and equipment for switching cloud disk modes
CN113301173A (en) Domain name updating system and method, message forwarding method and server

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22871632

Country of ref document: EP

Kind code of ref document: A1