WO2021036702A1 - 一种基于区块链系统的共识方法及装置 - Google Patents

一种基于区块链系统的共识方法及装置 Download PDF

Info

Publication number
WO2021036702A1
WO2021036702A1 PCT/CN2020/106623 CN2020106623W WO2021036702A1 WO 2021036702 A1 WO2021036702 A1 WO 2021036702A1 CN 2020106623 W CN2020106623 W CN 2020106623W WO 2021036702 A1 WO2021036702 A1 WO 2021036702A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
consensus
node
round
transaction data
Prior art date
Application number
PCT/CN2020/106623
Other languages
English (en)
French (fr)
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 WO2021036702A1 publication Critical patent/WO2021036702A1/zh

Links

Images

Classifications

    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present invention relates to the technical field of financial technology (Fintech), in particular to a consensus method and device based on a blockchain system.
  • PBFT Practical Byzantine Fault Tolerance
  • each node in the blockchain system can process transactions based on the original block packaged by the master node to obtain the target block, and then interact with other nodes in the blockchain system.
  • the node consensus target block If the target block consensus is successful, the block is successfully produced and the current round of block consensus is completed.
  • the PBFT consensus algorithm can re-select the master node of the next round of block consensus from multiple nodes and execute the following A round of block consensus process. It can be seen that using the PBFT consensus algorithm, each round of block consensus is executed separately, that is, the next round of block consensus needs to wait for the completion of the current round of block consensus before it can be executed, which leads to the consensus efficiency of the blockchain system Lower.
  • the embodiment of the present invention provides a consensus method based on a blockchain system to solve the technical problem of low consensus efficiency of the blockchain system caused by the prior blockchain system sequentially executing each round of block consensus.
  • an embodiment of the present invention provides a consensus method based on a blockchain system, including:
  • the first node receives the consensus information of the M-th block to be agreed upon sent by the second node, and the consensus information of the M-th block includes the to-be-processed in the first round of block consensus
  • the second node is the master node of the first round of block consensus; further, if the first node determines that the first node is the master of the I+1 round of block consensus
  • the node when consensus is made on the M-th block according to the consensus information of the M-th block, the consensus information of the M+1-th block to be agreed upon is generated in parallel; the consensus of the M+1-th block
  • the information includes the second transaction data to be processed in the I+1 round of block consensus; the second transaction data is different from the first transaction data; wherein, I and M are positive integers.
  • the master node of the I+1 round of block consensus can automatically package the block, so that it can be
  • the consensus process of the first round of block consensus and the block packaging process of the I+1 round of block consensus are executed in parallel to reduce the operation time of the I+1 round of block consensus and improve the consensus efficiency of the blockchain system.
  • the first node to generate consensus information of the M+1 th block to be agreed in parallel includes: the first node obtains from the transaction pool of the first node except for the first node.
  • a second transaction data other than the transaction data the block height of the M+1th block is set according to the block height of the Mth block, and the block height of the M+1th block is set according to the second transaction data, the M+1th block
  • the block height and current timestamp of the block generate the consensus information of the M+1th block.
  • the second transaction data except the first transaction data to be processed in the first round of block consensus is obtained from the transaction pool, and the second transaction data is taken as the block body of the M+1th block. It can avoid the repeated processing of the transaction data processed by the I+1 round of block consensus in the I+1 round of block consensus, and ensure the accuracy of transaction processing when the I+1 round of block consensus and the I+1 round of block consensus are executed in parallel; Moreover, when the first round of block consensus and the I+1 round of block consensus are executed in parallel, although the largest historical block of the second node is the M-1th block, it is determined according to the pending consensus in the first round of block consensus The block height of the M-th block is set to the block height of the M+1-th block to be agreed in the I+1 round of block consensus, so that the second node can accurately generate the area corresponding to the I+1 round of the block consensus process Block header, so that the first round of block consensus and the I+1 round of block consensus are executed in parallel.
  • the first node After the first node generates the consensus information of the M+1th block to be agreed in parallel, if it is determined that the consensus result of the first round of block consensus is the consensus success, then the The hash value of the Mth block is added to the consensus information of the M+1th block, and the consensus information of the M+1th block is sent to other nodes in the blockchain system.
  • the hash value of the M-th block to be agreed in the first round of block consensus is added to the first to be agreed in the I+1 round of block consensus.
  • a complete M+1th block can be assembled in the I+1 round of block consensus, so as to accurately establish the relationship between the Mth block and the M+1th block to ensure the block consensus.
  • the first node after the first node generates the consensus information of the M+1th block to be agreed in parallel, if it is determined that the consensus result of the first round of block consensus is consensus failure, then Obtain the first transaction data from the transaction pool of the first node, and set the block height of the M-th block according to the block height of the largest historical block; further, the first node according to the first transaction data , The block height of the M-th block, the hash value of the largest historical block and the current timestamp, generate the consensus information of the M-th block, and send the consensus information of the M-th block to Other nodes in the blockchain system.
  • the first node determines that the first node is the master node of the I+1 round of block consensus in the following manner: The block height and the number of nodes in the blockchain system determine the number of the master node of the I+1 round of block consensus. If the identity of the first node is the same as the master node of the I+1 round of block consensus If the numbers of the nodes match, it is determined that the first node is the master node of the I+1 round of block consensus.
  • the master node of the block consensus can call the node to automatically package the M+1 block to be agreed in the I+1 round of block consensus when a certain node is successfully matched, so as to ensure that the I+1 round of block consensus and
  • the automatic parallel execution of the first round of block consensus improves the accuracy of the consensus of the blockchain system.
  • an embodiment of the present invention provides a consensus device based on a blockchain system, and the device includes:
  • the transceiver module is used to receive the consensus information of the M-th block to be agreed upon by the second node in the first round of block consensus.
  • the consensus information of the M-th block includes the first round of block consensus.
  • the second node is the master node of the first round of block consensus; where I and M are positive integers;
  • the generation module is used to generate the pending consensus in parallel when it is determined that the first node is the master node of the I+1 round of block consensus, when the M-th block is agreed upon according to the consensus information of the M-th block
  • the consensus information of the M+1th block; the consensus information of the M+1th block includes the second transaction data to be processed in the I+1th round of block consensus; the second transaction data is related to the The first transaction data is different.
  • the generating module is specifically configured to: obtain second transaction data other than the first transaction data from the transaction pool of the first node, according to the Mth block Set the block height of the M+1th block, and generate the block height of the M+1th block according to the second transaction data, the block height of the M+1th block, and the current timestamp. Consensus information.
  • the transceiver module is also used to: if the consensus result of the first round of block consensus is determined For the consensus to succeed, the hash value of the M-th block is added to the consensus information of the M+1-th block, and the consensus information of the M+1-th block is sent to the block Other nodes in the chain system.
  • the generating module is further configured to: if it is determined that the consensus result of the first round of block consensus is consensus failure, obtain the first transaction from the transaction pool of the first node Data, and set the block height of the M-th block according to the block height of the largest historical block; further, according to the first transaction data, the block height of the M-th block, and the block height of the largest historical block
  • the hash value and the current timestamp are used to generate the consensus information of the M-th block, and send the consensus information of the M-th block to other nodes in the blockchain system.
  • the generating module is specifically configured to: determine the master node of the I+1 round of block consensus according to the block height of the Mth block and the number of nodes in the blockchain system If the identification of the first node matches the number of the master node of the I+1 round of block consensus, it is determined that the first node is the master node of the I+1 round of block consensus .
  • an embodiment of the present invention also provides a computing device, including:
  • processor, memory, and communication interface among them, the processor, memory and communication interface are connected by a bus;
  • the processor is configured to read the program in the memory and execute the above-mentioned consensus method based on the blockchain system;
  • the memory is used to store one or more executable programs, and can store data used by the processor when performing operations.
  • the embodiments of the present invention also provide a non-transitory computer-readable storage medium.
  • the non-transitory computer-readable storage medium stores computer instructions. When it runs on a computer, the computer executes the block-based The consensus method of the chain system.
  • an embodiment of the present invention also provides a computer program product containing instructions.
  • the computer program product includes a calculation program stored on a non-transitory computer-readable storage medium.
  • the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the consensus method based on the blockchain system.
  • FIG. 1 is a schematic diagram of the architecture of a blockchain system provided by an embodiment of the present invention
  • FIG. 2 is a schematic diagram of a corresponding process when using the PBFT consensus algorithm to process transactions according to an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a process corresponding to a consensus method based on a blockchain system provided by an embodiment of the present invention
  • FIG. 4 is a schematic diagram of a process for executing block consensus according to an embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a consensus device based on a blockchain system provided by an embodiment of the present invention.
  • FIG. 6 is a schematic structural diagram of a computing device provided by this application.
  • the field of financial technology (Fintech) technology usually involves a variety of transactions.
  • bank transactions can include card sales, deposit transactions, loan transactions, insurance transactions, wealth management transactions, etc.
  • the daily transaction volume of banks can reach thousands or even several. Thousands of pens.
  • the financial technology field can also use blockchain technology to process transactions. For example, if multiple banks are involved in related transactions, you can set up a consortium chain to synchronize related transactions. , Or you can put the courts and customers on the chain at the same time to jointly maintain the security and stability of the alliance chain.
  • the blockchain system can be a peer-to-peer (Peer To Peer, P2P) network composed of multiple nodes.
  • P2P is an application layer protocol that runs on the Transmission Control Protocol (TCP) protocol.
  • TCP Transmission Control Protocol
  • Nodes in the blockchain system can be equal to each other. There is no central node in the system, so each node can Randomly connect other nodes.
  • each node can be set up with a preset database, and each node jointly maintains the public ledger in the blockchain system through the preset database.
  • the preset database inside the node can store the data in the blockchain system.
  • Block data among them, the block data includes the block header and the block body.
  • the block header includes the hash value of the previous block, the hash value of this block, the block height of this block, the timestamp and other information.
  • the block includes transaction data.
  • the node in the blockchain system processes transaction data generated by the transaction to be processed during the process of consensus on the block.
  • FIG 1 is a schematic diagram of the architecture of a blockchain system provided by an embodiment of the present invention.
  • the blockchain system may include one or more nodes, such as node 101, node 102, node 103, and node 104 , Any two nodes of node 101 to node 104 can be connected in communication, so as to jointly maintain the blockchain system. Wherein, any two nodes may be connected in a wired manner, or may also be connected in a wireless manner, which is not specifically limited.
  • the nodes in the blockchain system may have multiple functions, such as routing function, transaction function, blockchain function, consensus function, and so on.
  • the nodes in the blockchain system can transmit transaction data and other information sent by other nodes to more nodes to achieve communication between nodes; or, the nodes in the blockchain system can be used to support users Perform transactions; or, nodes in the blockchain system can be used to record all transactions in history; or, nodes in the blockchain system can generate new blocks in the blockchain by verifying and recording transactions.
  • the routing function is a function that each node in the blockchain system must have, and other functions can be set by those skilled in the art according to actual needs.
  • a node in the blockchain system can be on a physical machine (server), and a node can specifically refer to a process or a series of processes running in the server.
  • the node 101 in the blockchain network may be a process running on a server, or may also refer to a server, which is not specifically limited.
  • the system architecture may also include a client device 200, and the client device 200 may be connected to any node in the blockchain system by accessing the blockchain network.
  • the client device 200 can send the transaction to any node in the blockchain system. After a certain node in the blockchain system receives the transaction, it can synchronize the transaction to other nodes in the blockchain system. node. After the node synchronizes the transaction, it can also store the transaction in the internal transaction pool of the node; accordingly, other nodes can also store the transaction in the internal transaction pool of other nodes after receiving the transaction synchronized by the node. In this way, if a certain node determines to process multiple transactions, it can obtain multiple transactions from the internal transaction pool, and then perform subsequent transaction processing and block consensus.
  • the transaction can be stored in the transaction pool in the form of a stack; in this way, if a node determines to process multiple transactions, the earliest multiple transactions into the stack can be obtained from the internal transaction pool for subsequent processing and consensus processes.
  • Fig. 2 is a schematic diagram of the corresponding process when using the PBFT consensus algorithm to process transactions according to an embodiment of the present invention.
  • the process of PBFT consensus algorithm processing transactions can be divided into three Stages: pre-prepare (pre-preparation) stage, prepare (preparation) stage and commit (submit) stage. The following describes the specific implementation process of the three stages.
  • Block consensus can be determined in many ways. For example, if it is detected that a new historical block is added to the memory of the node, it can be considered that a round of block consensus has been successfully executed, or if it is detected that the node has updated the internal default database , It can be considered that a round of block consensus has been successfully executed, and so on.
  • the PBFT consensus algorithm can take turns to select different nodes as the master node from multiple nodes in the blockchain system; specifically, a window value v can be set inside each node. If the previous round of block consensus is successfully executed, then The window value v inside each node can be set to zero. If the last round of block consensus execution fails, the window value v inside each node is incremented (that is, 1 is added). Correspondingly, if each node detects that a new historical block has been added to the memory of the node, or detects that the node has updated the internal preset database, it can determine the master node of the next round of block consensus according to the following formula Number:
  • leader is the number of the master node of the next round of block consensus
  • h is the block height of the block to be agreed
  • v is the window value
  • n is the number of nodes in the blockchain system.
  • each node can send the number of its own determined master node to other nodes in the blockchain system. If the number of nodes that have passed the consensus on a master node number is greater than the preset number, the number can be changed. The node corresponding to the number serves as the master node for the next round of block consensus. In another example, after each node determines the number of the master node, if its own node ID matches the number of the master node, the node will automatically be the master node for the next round of block consensus; if its own node ID matches the master node number If the number of the node does not match, it can be used as a slave node without any processing, and just wait for the next round of block consensus to be executed.
  • Table 1 is a schematic table of a correspondence relationship between a node identifier and a serial number of a master node provided by an embodiment of the present invention.
  • Table 1 A schematic diagram of the corresponding relationship between the node identifier and the number of the master node
  • node 101 can be used as the master node for the next round of block consensus, and nodes 102, 103, and 104 can be used as the next round of block consensus.
  • node 102 can be used as the master node of the next round of block consensus, and node 101, node 103, and node 104 can be used as the slave of the next round of block consensus Node; if the number of the master node determined by the node is 2, then node 103 will be the master node of the next round of block consensus, and node 101, node 102, and node 104 will be the slave nodes of the next round of block consensus; if The number of the master node determined by the node is 3, and then node 104 is taken as the master node for the next round of block consensus, and nodes 101, 102, and 103 are taken as the slave nodes for the next round of block consensus.
  • the master node of the previous round of block consensus is node 102, and a new historical block 1 is stored in the memory of node 101, the window value v is set to zero, and the number of nodes in the blockchain system is 4 Therefore, the number of the master node determined by node 101 (or node 102 ⁇ node 104) using the above formula is 2; based on Table 1, it can be seen that the master node of the next round of block consensus can be node 103, and the master node 103 is used to execute Consensus of block 2. Correspondingly, if the node 102 does not respond for a long time, the largest historical block in the memory of the node is still 0.
  • the window value v is incremented to 1.
  • the node 101 (or the node 102 ⁇ Node 104)
  • the number of the master node determined using the above formula is 2, that is, the master node of the next round of block consensus can be node 103, and the master node 103 is used to execute the consensus of block 1; further, if node 103 is long If the time does not respond, the largest historical block in the memory of node 103 is still 0. Because the previous round of block consensus failed, the window value v is incremented to 2.
  • node 101 (or node 102 ⁇ node 104) uses the above
  • the number of the master node determined by the formula is 3, that is, the master node of the next round of block consensus can be node 104, and the master node 104 is used to execute the consensus of block 1.
  • the master node 101 can get from the transaction pool of master node 101 Obtain the transaction data to be processed in this round of block consensus, and package block 2 according to the transaction data to be processed in this round of block consensus to generate a pre-prepare package.
  • the master node 101 can use the hash value of block 1, the block height of block 2, and the current timestamp to assemble the block header of block 2, and can use the transaction data to be processed in this round of block consensus.
  • the block body of block 2 can then generate a pre-prepare package according to the block header and block body of block 2. Further, the master node 101 can send the pre-prepare packet to any node in the blockchain system, that is, node 102, node 103, and node 104.
  • any node in the blockchain system receives the pre-prepare packet sent by the master node 101, it can parse the pre-prepare packet to obtain the transaction data to be processed by the block consensus; in this way, the node The transaction data to be processed in this round of block consensus can be executed to obtain the transaction result. Further, the node can generate the first hash value according to the transaction result, generate the second hash value according to the receipt information of each transaction, generate the third hash value according to the transaction request message, and then combine the first hash value, The second hash value and the third hash value are assembled into the block header of block 2, and the hash value of block 2 can be generated according to the data in the block header of block 2.
  • the node can assemble the hash value of block 2 and the transaction data processed by this round of block consensus into the block body of block 2, and use the private key of the node, the hash value of block 2, and Information such as the block height and the node's identification generates the signature packet of the node to block 2, and then the signature packet of the node can be sent to other nodes in the blockchain system.
  • any node in the blockchain system can store the public keys of all nodes in the blockchain system. In this way, any node can first determine that the signature package sent by other nodes arrives at the node. Obtain the public keys of other nodes from the inside of the node, and use the public keys of other nodes to decrypt the signature packets of other nodes to obtain the hash value of block 2 determined by each other node processing transaction. Further, any node can compare the hash value of block 2 determined by its processing transaction with the hash value of block 2 determined by any other node processing transaction, and if they are the same, it can receive the other node's sending If the signature package is different, the signature package sent by the other node can be rejected.
  • the node For any node in the blockchain system, if the number of signature packets received by the node within the timeout period is less than the preset threshold, the node considers that the current round of block consensus has failed, and the node can initiate a view switch, that is Increment the internal window value v (for example, if the original window value is 1, then the incremented window value is 2).
  • the number of signature packets received by the node within the timeout period is greater than or equal to the preset threshold, it means that the block 2 obtained by the node processing the transaction is the same as the block obtained by most other nodes in the blockchain system processing the transaction.
  • Block 2 is the same, the block 2 generated by the node is in the pending state; in this way, the node can use the node's private key, the hash value of block 2, the block height, the node's identification and other information to generate the node pair block 2’s commit package, and can send the commit package to other nodes in the blockchain system.
  • the commit package is used to indicate that the node is in a pending commit state.
  • the preset threshold is calculated based on the total number of consensus nodes n in the blockchain system, and the calculation formula is For example, when n is 8, the preset threshold is 5.
  • the node receives 4 signature packets in the prepare phase, it means that the node has failed in the current round of block consensus, so the node can initiate a view switch; If the node receives 6 signature packets in the prepare phase, it means that the block 2 obtained by the node processing the transaction is the same as the block 2 obtained by most other consensus nodes in the blockchain system, so the node can generate a commit packet .
  • any node in the blockchain system determines that the commit packet sent by other nodes arrives at the node, it can parse the commit packets of other nodes to obtain the hash value of block 2 determined by each other node to process the transaction; , The node can compare the hash value of block 2 determined by its processing transaction with the hash value of block 2 determined by any other node processing transaction, and if they are the same, it can receive the commit packet sent by the other node If they are different, the commit packet sent by the other node can be rejected.
  • the node if the number of commit packets received by the node within the timeout period is less than the preset threshold, the node considers that the current round of block consensus has failed, and the node can initiate a view switch; accordingly, if the node is within the timeout period
  • the number of commit packets received is greater than or equal to the preset threshold, which means that the block 2 obtained by the node processing the transaction is the same as the block 2 obtained by most other nodes in the blockchain system.
  • the block 2 generated by the node processing the transaction is obtained in the memory, and the block 2 can be written into the preset database inside the node to complete the round of block consensus.
  • the PBFT consensus algorithm determines the master node of the current round of block consensus from multiple nodes in the blockchain system, and then uses the master node of the current round of block consensus to execute the current round
  • the block of the block consensus is packaged, and after each node in the block chain system has executed the pre-prepare phase, prepare phase, and commit node, it is determined that the current round of block consensus is over; further, the PBFT consensus algorithm will start from the district.
  • the master node of the next round of block consensus is determined among the multiple nodes of the block chain system, and the master node of the next round of block consensus is used to perform the block packaging of the next round of block consensus, and in the block chain system After each node executes the pre-prepare phase, prepare phase, and commit node, it determines the end of the next round of block consensus; repeats the above process until there is no transaction data to be processed in the transaction pool.
  • the PBFT consensus algorithm can execute each round of block consensus in turn, that is, start the next round of block consensus after the end of the previous round of block consensus. In this way, it can better work in small transactions.
  • Transaction processing in the blockchain system In the financial technology field, thousands or even tens of thousands of transactions may be generated every second, resulting in a lot of transaction data to be processed in the blockchain system of the financial technology field. If the PBFT consensus algorithm is used to execute each round in turn Block consensus may require a lot of time, resulting in very low transaction processing efficiency, and may even block transactions, thereby causing huge losses in the financial field.
  • the embodiment of the present invention provides a consensus method based on the blockchain system to solve the consensus efficiency and transaction processing of the blockchain system caused by the existing blockchain system sequentially executing each round of block consensus.
  • Technical problems with low efficiency are due to the embodiment of the present invention.
  • FIG. 3 is a schematic diagram of a process corresponding to a consensus method based on a blockchain system provided by an embodiment of the present invention, and the method includes:
  • Step 301 In the first round of block consensus, the first node receives the consensus information of the M-th block to be agreed upon sent by the second node; the consensus information of the M-th block includes the to-be-processed block consensus information in the first round of block consensus.
  • the first transaction data, the second node is the master node of the first round of block consensus.
  • the I-1 round of block consensus can be determined Success; so, if the master node of the first round of block consensus is the second node, the second node can send the consensus information of the M-th block to be agreed in the first round of block consensus to the blockchain system Other nodes.
  • the consensus information of the Mth block can be generated in multiple ways. Two possible implementation methods are described below:
  • the consensus information of the M-th block can be generated by the second node after the success of the I-1 round of block consensus; specifically, after determining that the I-1 round of block consensus is successful
  • the second node can obtain the first transaction data to be processed in the first round of block consensus from the memory pool of the second node, and can use the first transaction data to assemble the block body of the Mth block.
  • -1 block height sets the block height of the Mth block, and uses the block height of the Mth block, the hash value of the M-1th block and the current timestamp to assemble the block header of the Mth block, and then According to the block header of the M-th block and the block body of the M-th block, the consensus information of the M-th block is generated.
  • the first round of The block to be agreed in the block consensus is block 2.
  • the master node of the block consensus is node 103; in this way, node 103 can obtain the first transaction data to be processed in the first round of block consensus from the internal transaction pool, and can use the block height of block 2 and block 1.
  • Assemble the block header of block 2 with the hash value of and the current timestamp use the first transaction data to assemble the block body of block 2, and then use the block header of block 2 and the block body of block 2 to generate pre-prepare package.
  • the consensus information of the M-th block can be generated by the second node during the I-1 round of block consensus. For example, when the second node receives the M-1 block’s consensus information After the consensus information, if the second node is determined to be the master node of the first round of block consensus, the first node can be generated in parallel based on the consensus information of the M-1th block in the process of participating in the I-1 round of block consensus. Consensus information of block M. It should be noted that this implementation can be specifically implemented with reference to the process of generating consensus information of the M+1th block in step 301 and step 302, and will not be repeated here.
  • the consensus information of the Mth block may include the block height of the Mth block, the hash value of the M-1th block, the generation timestamp of the Mth block, and the first transaction data.
  • the first transaction data may include transaction data of one transaction, or may also include transaction data of multiple (ie, two or more) transactions, which is not specifically limited.
  • step 302 if the first node determines that the first node is the master node of the I+1 round of block consensus, it will generate the M-th block to be agreed in parallel when the M-th block is agreed upon according to the consensus information of the M-th block.
  • each node in the blockchain system can analyze the consensus information of the Mth block to obtain the block height of the Mth block. , The hash value of the M-1th block, the generation timestamp of the Mth block and the first transaction data. Further, for each node in the blockchain system, the node can determine whether the node is the master of the I+1 round of block consensus based on the block height of the Mth block and the node data in the blockchain system. If it is not, then the node can directly participate in the first round of block consensus process. If it is, then the node can generate the first consensus to be reached in the I+1 round of block consensus in parallel when participating in the first round of block consensus. Consensus information of the M+1 block.
  • a node can determine whether the node is the master node of the I+1 round of block consensus based on the following formula and Table 1:
  • leader I+1 is the number of the master node of the I+1 round of block consensus
  • h M is the block height of the M-th block
  • n is the total number of consensus nodes in the blockchain system.
  • the M-th block is block 2
  • the master node of the first round of block consensus is node 103
  • node 101, node 102, and node 104 will receive the pre-prepare of block 2 sent by node 103.
  • the above formula can be used to determine the number of the master node of the I+1 round of block consensus.
  • node 101, node 102, and node 103 since the number of the master node determined by the above formula is 3, the node corresponding to the master node with number 3 is determined as node 104 according to Table 1, so node 101, node 102, and Node 103 can continue to perform the first round of block consensus process; correspondingly, for node 104, since the number of the master node determined by the above formula is 3, the node corresponding to the master node numbered 3 is determined according to Table 1.
  • the node 104 therefore, the node 104 can generate the pre-prepare package of block 3 in parallel during the execution of the first round of block consensus.
  • the master node of the block consensus can call the node to automatically package the M+1 block to be agreed in the I+1 round of block consensus when a node is successfully matched, so as to ensure the I+1 round of block consensus
  • the automatic parallel execution with the first round of block consensus improves the accuracy of the consensus of the blockchain system.
  • node 101 after determining that it is not the master node of the I+1 round of block consensus, node 101 can process the first transaction data to obtain the processing result of the first transaction data, and can generate it according to the processing result of the first transaction data
  • the first hash value, the second hash value is generated according to the first transaction data
  • the third hash value is generated according to the receipt of each transaction executed in the first transaction data
  • the preset hash algorithm can be used to hash the first hash value.
  • Value, the second hash value, and the third hash value are calculated to obtain the hash value of block 2.
  • the node 101 can assemble the first hash value, the second hash value, the third hash value, and the hash value of block 2 into the block header of block 2, and can combine the hash value of block 2
  • the hope value and the first transaction data are assembled into the block body of block 2, using the private key of node 101, the hash value of block 2, the height of block 2, the identification of node 101 and other information to generate the node 101 pair
  • the signature packet of block 2 is further sent to node 102, node 103, and node 104; node 101 can wait for the signature packet sent by node 102, node 103, and node 104, and can Continue to execute the commit phase in the first round of block consensus according to the number of received signature packets.
  • the node 104 can generate the pre-prepare package of block 3 in parallel in the process of executing the first round of block consensus.
  • the node 104 can perform the prepare phase first to obtain the signature of the node 104 on the block 2 Package and send the signature package of block 2 from node 104 to node 101, node 102, and node 103, and then while waiting for the signature package sent by node 101, node 102, and node 103, according to the pre-prepare package of block 2 Generate the pre-prepare package of block 3; or after receiving the consensus information of block 2 sent by node 103, first generate the pre-prepare package of block 3 according to the pre-prepare package of block 2
  • the pre-prepare package of block 2 sent by node 103 generates the signature package of node 104 for block 2; or the prepare phase and commit phase can be executed first to obtain the commit package of block 2 by node 104, and the node 104 is assigned to the zone.
  • the commit packet of block 2 is sent to node 101, node 102 and node 103, and then while waiting for the commit packet sent by node 101, node 102 and node 103, the pre-prepare packet of block 3 is generated according to the pre-prepare packet of block 2 Package; etc., the specific is not limited.
  • the node 104 can generate the pre-prepare package of block 3 in the following manner: the node 104 can first parse the pre-prepare package of block 2 to obtain the block height of block 2 and the first transaction data , Then the block height of block 3 can be set according to the block height of block 2, and the second transaction data except the first transaction data can be obtained from the transaction pool of node 104; further, node 104 can use block The block height of 3 and the current timestamp are assembled to obtain the block header of block 3, and the second transaction data can be used to assemble the block body of block 3, which can then be based on the block header of block 3 and the block of block 3. The body generates a pre-prepare package for block 3.
  • the pre-prepare package may be a data package with a preset format, and the pre-prepare package may be composed of multiple storage areas, and each storage area is used to store setting data.
  • the pre-prepare package of block 3 may consist of a first storage field, a second storage field, a third storage field, and a fourth storage field, where the first storage field is used to store the block height, The second storage field is used to store the generation timestamp of block 3, the third storage field is used to store the hash value of block 2, and the fourth storage field can store the transaction data to be processed in block 3 (ie, the second transaction). data).
  • the amount of data that can be stored in the first to fourth storage fields can be set by those skilled in the art based on experience, and is not limited.
  • the node 104 after the node 104 assembles the block header of block 3 and the block body of block 3, it can first store the block header of block 3 and the block body of block 3 in the memory of node 104. Then generate the initial pre-prepare package of block 3 (which can be an empty data package); further, the node 104 can convert the block height of block 3 into a preset format (such as binary) and place it in the initial pre-prepare package. In the first storage field, the generation timestamp of block 3 is converted into a preset format and then placed in the second storage field of the initial pre-prepare package, and the second transaction data is converted into a preset format and placed in the initial pre-prepare package.
  • a preset format such as binary
  • the third storage field of the initial pre-prepare packet can be made free; in this way, the node 104 can obtain the pre-prepare packet of block 3, and can Store the pre-prepare package of block 3 in the memory.
  • the second transaction data except the first transaction data to be processed in the first round of block consensus is obtained from the transaction pool, and the second transaction data is taken as the block body of the M+1th block It can avoid the repeated processing of the transaction data processed by the I+1 round of block consensus in the I+1 round of block consensus, and ensure the accuracy of transaction processing when the I+1 round of block consensus and the I+1 round of block consensus are executed in parallel ; And, when the first round of block consensus and the I+1 round of block consensus are executed in parallel, although the largest historical block of the second node is the M-1th block, it is determined by waiting in accordance with the first round of block consensus.
  • the block height of the M-th block of the consensus is set to the block height of the M+1-th block to be agreed in the I+1 round of block consensus, so that the second node can accurately generate the corresponding to the I+1 round of the block consensus process Block header, so that the I round of block consensus and the I+1 round of block consensus are executed in parallel.
  • the node 104 can continue to execute the consensus process of block 2, for example, execute the prepare phase and the commit phase in sequence, and determine whether the consensus of block 2 is successful after the execution of the commit phase is completed, if the node 104 successfully transfers the consensus result of block 2 Stored in the default database, it is determined that the consensus of block 2 is successful, so node 104 can send the pre-prepare packet of block 3 to node 101, node 102, and node 103; if node 104 fails to successfully transfer the consensus of block 2 If the result is stored in the preset database, it is determined that the consensus of block 2 has failed, so the node 104 can perform the consensus process of block 2 again.
  • the node 104 can also obtain the hash value of block 2 from the consensus result of block 2, and can convert the hash value of block 2 into a preset format Then add it to the third storage field of the pre-prepare packet of block 3 to obtain the target pre-prepare packet of block 3, and then send the target pre-prepare packet of block 3 to nodes 101, 102 and Node 103.
  • the hash value of the M-th block to be agreed in the first round of block consensus is added to the to-be-consensused block in the I+1 round of block consensus.
  • a complete M+1th block can be assembled in the I+1 round of block consensus, so as to accurately establish the association relationship between the Mth block and the M+1th block to ensure the block The sequence of the consensus process and the integrity of the blockchain.
  • the node 104 can repeat the consensus process for block 2 as follows: the node 104 can determine the block height of the largest historical block (ie, block 1) from the memory, and The first transaction data can be obtained from the transaction pool of node 104. In this way, node 104 can set the block height of block 2 according to the block height of block 1, and can also set the block height of block 2 according to the block height of block 2 and the hash of block 1.
  • the parallel processing of two rounds of block consensus can be avoided.
  • the problem of missing the block to be consensus in the previous round of block consensus is to ensure the accuracy of the consensus of the blockchain system.
  • Fig. 4 is a schematic diagram of a process for executing block consensus provided by an embodiment of the present invention, and the method includes:
  • step 401 in the first round of block consensus, the master node 101 packs block 0.
  • the block to be agreed upon is block 0; accordingly, since the number of blocks in the blockchain system is 4.
  • the master node 101 can obtain the transaction data to be processed in the first round of block consensus from the transaction pool of the master node 101, and can assemble the block header of block 0 according to the block height of block 0 and the current timestamp.
  • the transaction data to be processed in a round of block consensus assembles the block body of block 0, and then the pre-prepare package of block 0 can be generated according to the block header of block 0 and the block body of block 0, and block 0
  • the pre-prepare packet of is sent to node 102 to node 104.
  • Step 402 nodes 102 to 104 receive the pre-prepare packet of block 0 sent by node 101; in the first round of block consensus, node 101, node 103, and node 104 are determined not to be the second round of block consensus
  • the master node directly participates in the consensus process of block 0, that is, the prepare phase and the commit phase are executed in sequence; accordingly, node 102 determines that node 102 is the master node of the second round of block consensus, so node 102 can participate in block 0
  • the pre-prepare package of block 1 is generated in parallel.
  • the node 102 can set the block height of block 1 according to the block height of block 0, and can obtain the transaction data to be processed in the second round of block consensus from the transaction pool, where the second round of block consensus is to be processed
  • the transaction data of is different from the transaction data to be processed in the first round of block consensus; the node 102 can generate the pre- of block 1 based on the block height of block 1, the current timestamp, and the transaction data to be processed in the second round of block consensus.
  • Step 403 After the first round of block consensus is over, because the block 0 consensus is successful, the node 102 can update the pre-prepare package of block 1 with the hash value of block 0, and update the updated block 1’s pre-prepare package.
  • the pre-prepare packet is sent to node 101, node 103, and node 104 to start the second round of block consensus.
  • node 101, node 103, and node 104 receive the pre-prepare packet of block 1 sent by node 102.
  • node 101, node 102, and node 104 are not determined to be the third-round zone
  • the master node of the block consensus directly participates in the consensus process of block 1, that is, the prepare phase and the commit phase are executed in sequence.
  • node 103 determines that node 103 is the master node of the third round of block consensus. Therefore, node 103 can participate in the consensus process of block 1 according to the block height of block 2, the current timestamp and the third round of block
  • the pre-prepare package of block 2 is generated in parallel with the transaction data to be processed by consensus.
  • step 404 after the second round of block consensus is over, since the consensus of block 1 is successful, node 103 can use the hash value of block 1 to update the pre-prepare package of block 2 and update the updated block 2’s pre-prepare package.
  • the pre-prepare packet is sent to node 101, node 102, and node 104 to start the third round of block consensus.
  • node 101, node 102, and node 104 receive the pre-prepare packet of block 2 sent by node 103.
  • node 101, node 102, and node 103 are not determined to be the fourth round of zone
  • the master node of the block consensus directly participates in the consensus process of block 2, that is, the prepare phase and the commit phase are executed in sequence.
  • the node 104 determines that the node 104 is the master node of the fourth round of block consensus, so the node 104 can participate in the consensus process of block 2 according to the block height of block 3, the current timestamp and the fourth round of block
  • the pre-prepare package of block 3 is generated in parallel with the transaction data to be processed by consensus.
  • the node 104 can delete the block 3 stored in the memory, and can repackage the block 2.
  • the master node 104 can obtain the transaction data to be processed in the third round of block consensus from the transaction pool of the master node 104. And can assemble the block header of block 2 according to the block height of block 2, the hash value of block 1 and the current timestamp, and assemble the block body of block 2 according to the transaction data to be processed in the third round of block consensus.
  • the pre-prepare packet of block 2 can be generated according to the block header of block 2 and the block body of block 2, and the pre-prepare packet of block 2 can be sent to nodes 101 to 103.
  • Step 406 node 101, node 102, and node 103 receive the pre-prepare packet of block 2 sent by node 104.
  • node 102, node 103, and node 104 are determined not to be the fifth-round zone
  • the master node of the block consensus can directly participate in the consensus process of block 2, that is, execute the prepare phase and the commit phase in sequence.
  • node 101 determines that node 101 is the master node of the fifth round of block consensus, so node 101 can participate in the consensus process of block 2, according to the block height of block 2, current timestamp and fifth round of block
  • the pre-prepare package of block 3 is generated in parallel with the transaction data to be processed by consensus.
  • step 407 after the fourth round of block consensus is over, since the consensus of block 2 is successful, node 101 can update the pre-prepare package of block 3 with the hash value of block 2, and update the updated block 3’s pre-prepare package.
  • the pre-prepare packet is sent to node 102, node 103, and node 104 to start the fifth round of block consensus.
  • node 102, node 103, and node 104 receive the pre-prepare packet of block 3 sent by node 101.
  • node 101, node 103, and node 104 are not determined to be the sixth-round zone
  • the master node of the block consensus directly participates in the consensus process of block 3, that is, the prepare phase and the commit phase are executed in sequence.
  • the node 102 determines that the node 102 is the master node of the sixth round of block consensus, so the node 102 can participate in the consensus process of block 3 according to the block height of block 4, the current timestamp and the sixth round of block
  • the pre-prepare package of block 4 is generated in parallel with the transaction data to be processed by consensus.
  • the block consensus method in the embodiment of the present invention can greatly Shorten the consensus time and improve the consensus efficiency of the blockchain system.
  • the first node receives the consensus information of the M-th block to be agreed upon sent by the second node, and the consensus information of the M-th block includes the consensus information of the M-th block.
  • the second node is the master node of the first round of block consensus; further, if the first node determines that the first node is the first
  • the master node of the +1 round of block consensus will generate the consensus information of the M+1th block to be agreed in parallel when making a consensus on the Mth block according to the consensus information of the Mth block;
  • the consensus information of the M+1th block includes the second transaction data to be processed in the I+1th round of block consensus; the second transaction data is different from the first transaction data.
  • the master node of the I+1 round of block consensus automatically packs the blocks, and the realization
  • the consensus process of the first round of block consensus and the block packaging process of the I+1 round of block consensus are executed in parallel, which reduces the operation time of the I+1 round of block consensus, thereby improving the blockchain system Consensus efficiency.
  • an embodiment of the present invention also provides a consensus device based on a blockchain system, and the specific content of the device can be implemented with reference to the foregoing method.
  • Fig. 5 is a schematic structural diagram of a consensus device based on a blockchain system provided by an embodiment of the present invention, including:
  • the transceiver module 501 is configured to receive the consensus information of the M-th block to be agreed upon by the second node in the first round of block consensus, where the consensus information of the M-th block includes the first round of block consensus
  • the second node is the master node of the first round of block consensus; where I and M are positive integers;
  • the generating module 502 is configured to generate a waiting node in parallel when the M-th block is agreed upon according to the consensus information of the M-th block if it is determined that the first node is the master node of the I+1-th round of block consensus.
  • the consensus information of the M+1th block of the consensus; the consensus information of the M+1th block includes the second transaction data to be processed in the I+1 round of block consensus; the second transaction data and The first transaction data is different.
  • the generating module 502 is specifically configured to:
  • the block height of the M+1th block and the current timestamp the consensus information of the M+1th block is generated.
  • the transceiver module 501 is further configured to:
  • the hash value of the Mth block is added to the consensus information of the M+1th block, and the Mth block is added to the consensus information of the M+1th block.
  • the consensus information of the +1 block is sent to other nodes in the blockchain system.
  • the generating module 502 is further configured to:
  • the first transaction data is obtained from the transaction pool of the first node, and the M-th block is set according to the block height of the largest historical block. Block height;
  • the generating module 502 is specifically configured to:
  • the number of the master node of the I+1 round of block consensus is determined. If the numbers of the master nodes of the +1 round of block consensus match, it is determined that the first node is the master node of the (I+1) round of block consensus.
  • the first node receives the consensus information of the Mth block to be agreed upon sent by the second node, and the Mth block
  • the consensus information includes the first transaction data to be processed in the first round of block consensus, and the second node is the master node of the first round of block consensus; further, if the first node determines The first node is the master node of the I+1 round of block consensus, and when the M-th block is agreed upon according to the consensus information of the M-th block, the M+1-th area to be agreed upon is generated in parallel Block consensus information; the consensus information of the M+1th block includes the second transaction data to be processed in the I+1 round of block consensus; the second transaction data is different from the first transaction data .
  • the master node of the I+1 round of block consensus automatically packs the blocks, and the realization
  • the consensus process of the first round of block consensus and the block packaging process of the I+1 round of block consensus are executed in parallel, which reduces the operation time of the I+1 round of block consensus, thereby improving the blockchain system Consensus efficiency.
  • the present application also provides a computing device.
  • the computing device includes at least one processor 620 for implementing the method in FIG. 3 provided by the embodiment of the present application. Either method.
  • the computing device 600 may also include at least one memory 630 for storing program instructions and/or data.
  • the memory 630 and the processor 620 are coupled.
  • the coupling in the embodiments of the present application is an indirect coupling or communication connection between devices, units or modules, and may be in electrical, mechanical or other forms, and is used for information exchange between devices, units or modules.
  • the processor 620 may cooperate with the memory 630 to operate.
  • the processor 620 may execute program instructions stored in the memory 630. At least one of the at least one memory may be included in the processor.
  • each step of the above method can be completed by an integrated logic circuit of hardware in the processor or instructions in the form of software.
  • the steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed and completed by a hardware processor, or executed and completed by a combination of hardware and software modules in the 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, registers.
  • 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. In order to avoid repetition, detailed description is omitted here.
  • the processor in the embodiment of the present application may be an integrated circuit chip with signal processing capability.
  • the steps of the foregoing method embodiments can be completed by hardware integrated logic circuits in the processor or instructions in the form of software.
  • the above-mentioned processor may be a general-purpose processor, a digital signal processing circuit (digital signal processor, DSP), a dedicated integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (field programmable gate array, FPGA) or other Programming logic devices, discrete gates or transistor logic devices, discrete hardware components.
  • DSP digital signal processing circuit
  • ASIC application specific integrated circuit
  • FPGA field programmable gate array
  • Programming logic devices discrete gates or transistor logic devices, discrete hardware components.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like.
  • the steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed 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, registers.
  • 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 memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory.
  • the non-volatile memory can be read-only memory (ROM), programmable read-only memory (programmable ROM, PROM), erasable programmable read-only memory (erasable PROM, EPROM), and electrically available Erase programmable read-only memory (electrically EPROM, EEPROM) or flash memory.
  • the volatile memory may be random access memory (RAM), which is used as an external cache.
  • RAM random access memory
  • static random access memory static random access memory
  • dynamic RAM dynamic RAM
  • DRAM dynamic random access memory
  • synchronous dynamic random access memory synchronous DRAM, SDRAM
  • double data rate synchronous dynamic random access memory double data rate SDRAM, DDR SDRAM
  • enhanced synchronous dynamic random access memory enhanced SDRAM, ESDRAM
  • synchronous connection dynamic random access memory serial DRAM, SLDRAM
  • direct rambus RAM direct rambus RAM
  • the computing device 600 may further include a communication interface 610 for communicating with other devices through a transmission medium, so that the device used in the computing device 600 can communicate with other devices.
  • the communication interface may be a transceiver, circuit, bus, module, or other type of communication interface.
  • the transceiver when the communication interface is a transceiver, the transceiver may include an independent receiver and an independent transmitter; it may also be a transceiver with integrated transceiver functions, or an interface circuit.
  • the computing device 600 may also include a communication line 640.
  • the communication interface 610, the processor 620, and the memory 630 may be connected to each other through a communication line 640;
  • the communication line 640 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (extended industry standard architecture). , Referred to as EISA) bus and so on.
  • the communication line 640 can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is used in FIG. 6, but it does not mean that there is only one bus or one type of bus.
  • embodiments of the present invention also provide a non-transitory computer-readable storage medium.
  • the non-transitory computer-readable storage medium stores computer instructions.
  • the consensus method of the blockchain system is not limited to:
  • inventions of the present application provide a computer program product.
  • the computer program product includes a calculation program stored on a non-transitory computer-readable storage medium.
  • the computer program includes program instructions. When executed by a computer, the computer is caused to execute the above-mentioned consensus method based on the blockchain system.
  • the embodiments of the present invention can be provided as methods or computer program products. Therefore, the present invention may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Marketing (AREA)
  • Signal Processing (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明实施例公开了一种基于区块链系统的共识方法及装置,其中方法包括:在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息,若确定所述第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息。本发明实施例中,通过在第I轮区块共识的执行过程中启动第I+1轮区块共识的主节点,使第I+1轮区块共识过的主节点自动打包第M+1区块,实现了对第I轮区块共识的共识过程与第I+1轮区块共识的区块打包过程的并行执行,减少了第I+1轮区块共识的操作时间,从而可以提高区块链系统的共识效率。

Description

一种基于区块链系统的共识方法及装置
相关申请的交叉引用
本申请要求在2019年08月27日提交中国专利局、申请号为201910798196.6、申请名称为“一种基于区块链系统的共识方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及金融科技(Fintech)技术领域,尤其涉及一种基于区块链系统的共识方法及装置。
背景技术
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,区块链(Blockchain)技术也不例外,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。在区块链系统中,为了保证交易执行的准确性,通常需要使用多个节点对区块进行共识,若对区块达成共识的节点数量超过预设数量,则说明区块链系统中大多数的节点处理交易所得到的区块是一致的;如此,该区块可以成功出块,且节点也可以根据该区块更新内部的交易数据库。
实用拜占庭容错算法(practical byzantine fault tolerance,PBFT)是现有较为常用的一种共识算法,在PBFT共识算法中,当区块链系统每执行完一轮区块共识(即上一轮区块共识成功出块)后,PBFT共识算法可以从区块链系统的多个节点中选取出一个主节点,主节点用于获取本轮区块共识中待处理的交易数据,并根据本轮区块共识中待处理的交易数据打包原始区块后发送给区块链系统中的其它节点。相应地,在本轮区块共识中,区块链系统中的每个节点(包括主节点)可以基于主节点打包的原始区块处理交易得到目标区块,进而与区块链系统中的其它节点共识目标区块,若目标区块共识成功,则成功出块,完成本轮区块共识,如此,PBFT共识算法可以重新从多个节点中选取下一轮区块共识的主节点,执行下一轮区块共识过程。由此可知,采用PBFT共识算法,每轮区块共识均是单独执行的,即下一轮区块共识需要等待本轮区块共识执行完成后方可开始执行,从而导致区块链系统的共识效率较低。
综上,目前亟需一种基于区块链系统的共识方法,用以解决现有的区块链系统依次执行每轮区块共识所导致的区块链系统的共识效率较低的技术问题。
发明内容
本发明实施例提供一种基于区块链系统的共识方法,用以解决现有的区块链系统依次执行每轮区块共识所导致的区块链系统的共识效率较低的技术问题。
第一方面,本发明实施例提供的一种基于区块链系统的共识方法,包括:
在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;进一步地,所述第一节点若确定所述第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生 成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同;其中,I、M为正整数。
在上述设计中,通过在第I轮区块共识的执行过程中启动第I+1轮区块共识的主节点,使第I+1轮区块共识过的主节点自动打包区块,从而可以并行地执行第I轮区块共识的共识过程与第I+1轮区块共识的区块打包过程,减少第I+1轮区块共识的操作时间,提高区块链系统的共识效率。
在一种可能的设计中,所述第一节点并行生成待共识的第M+1区块的共识信息,包括:所述第一节点从所述第一节点的交易池中获取除所述第一交易数据之外的第二交易数据,根据所述第M区块的块高设置所述第M+1区块的块高,并根据所述第二交易数据、所述第M+1区块的块高和当前时间戳,生成所述第M+1区块的共识信息。
在上述设计中,通过从交易池中获取除第I轮区块共识中待处理的第一交易数据以外的第二交易数据,将第二交易数据作为第M+1区块的区块体,可以避免第I+1轮区块共识重复处理第I轮区块共识所处理的交易数据,保证在并行执行第I轮区块共识和第I+1轮区块共识时交易处理的准确性;且,并行执行第I轮区块共识和第I+1轮区块共识时,虽然第二节点的历史最大区块为第M-1区块,但是通过根据第I轮区块共识中待共识的第M区块的块高设置第I+1轮区块共识中待共识的第M+1区块的块高,可以使得第二节点准确生成第I+1轮区块共识过程对应的区块头,从而使得并行执行第I轮区块共识和第I+1轮区块共识。
在一种可能的设计中,所述第一节点并行生成待共识的第M+1区块的共识信息之后,若确定所述第I轮区块共识的共识结果为共识成功,则将所述第M区块的哈希值添加在所述第M+1区块的共识信息中,并将所述第M+1区块的共识信息发送给所述区块链系统中的其它节点。
在上述设计中,在第I轮区块共识成功后,通过将第I轮区块共识中待共识的第M区块的哈希值添加在第I+1轮区块共识中待共识的第M+1区块中,可以在第I+1轮区块共识中组装完整的第M+1区块,从而准确建立第M区块与第M+1区块的关联关系,保证区块共识过程的顺序进行以及区块链的完整性。
在一种可能的设计中,所述第一节点并行生成待共识的第M+1区块的共识信息之后,若确定所述第I轮区块共识的共识结果为共识失败,则从所述第一节点的交易池中获取所述第一交易数据,并根据历史最大区块的块高设置所述第M区块的块高;进一步地,所述第一节点根据所述第一交易数据、所述第M区块的块高、所述历史最大区块的哈希值和当前时间戳,生成所述第M区块的共识信息,并将所述第M区块的共识信息发送给所述区块链系统中的其它节点。
在上述设计中,在第I轮区块共识失败后,通过使用第一节点重新组装待共识的第M区块并对第M区块执行共识过程,可以避免并行处理两轮区块共识的过程时由于上一轮区块共识失败导致的遗漏上一轮区块共识中待共识区块的问题,保证区块链系统共识的准确性。
在一种可能的设计中,所述第一节点通过如下方式确定所述第一节点为所述第I+1轮区块共识的主节点:所述第一节点根据所述第M区块的块高和所述区块链系统的节点数量确定所述第I+1轮区块共识的主节点的编号,若所述第一节点的标识与所述第I+1轮区块共识的主节点的编号匹配,则确定所述第一节点为所述第I+1轮区块共识的主节点。
在上述设计中,针对于区块链系统中的任一节点,通过使用该节点的标识自动匹配第 I+1轮区块共识的主节点的编号,确定该节点是否为第I+1轮区块共识的主节点,可以在某一节点匹配成功时调用该节点自动打包第I+1轮区块共识中待共识的第M+1区块,从而可以保证第I+1轮区块共识与第I轮区块共识的自动并行执行,提高区块链系统共识的准确性。
第二方面,本发明实施例提供一种基于区块链系统的共识装置,所述装置包括:
收发模块,用于在第I轮区块共识中,接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;其中,I、M为正整数;
生成模块,用于若确定第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同。
在一种可能的设计中,所述生成模块具体用于:从所述第一节点的交易池中获取除所述第一交易数据之外的第二交易数据,根据所述第M区块的块高设置所述第M+1区块的块高,并根据所述第二交易数据、所述第M+1区块的块高和当前时间戳,生成所述第M+1区块的共识信息。
在一种可能的设计中,在所述生成模块并行生成待共识的第M+1区块的共识信息之后,所述收发模块还用于:若确定所述第I轮区块共识的共识结果为共识成功,则将所述第M区块的哈希值添加在所述第M+1区块的共识信息中,并将所述第M+1区块的共识信息发送给所述区块链系统中的其它节点。
在一种可能的设计中,所述生成模块还用于:若确定所述第I轮区块共识的共识结果为共识失败,则从所述第一节点的交易池中获取所述第一交易数据,并根据历史最大区块的块高设置所述第M区块的块高;进一步地,根据所述第一交易数据、所述第M区块的块高、所述历史最大区块的哈希值和当前时间戳,生成所述第M区块的共识信息,并将所述第M区块的共识信息发送给所述区块链系统中的其它节点。
在一种可能的设计中,所述生成模块具体用于:根据所述第M区块的块高和所述区块链系统的节点数量确定所述第I+1轮区块共识的主节点的编号,若所述第一节点的标识与所述第I+1轮区块共识的主节点的编号匹配,则确定所述第一节点为所述第I+1轮区块共识的主节点。
第三方面,本发明实施例还提供了一种计算设备,包括:
处理器、存储器、通信接口;其中,处理器、存储器与通信接口之间通过总线连接;
所述处理器,用于读取所述存储器中的程序,执行上述基于区块链系统的共识方法;
所述存储器,用于存储一个或多个可执行程序,可以存储所述处理器在执行操作时所使用的数据。
第四方面,本发明实施例还提供了一种非暂态计算机可读存储介质,非暂态计算机可读存储介质中存储计算机指令,当其在计算机上运行时,使得计算机执行上述基于区块链系统的共识方法。
第五方面,本发明实施例还提供一种包含指令的计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行上述基于区块链系统的共识方法。
附图说明
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例提供的一种区块链系统的架构示意图;
图2为本发明实施例提供的一种使用PBFT共识算法处理交易时对应的流程示意图;
图3为本发明实施例提供的一种基于区块链系统的共识方法对应的流程示意图;
图4为本发明实施例提供的一种执行区块共识的流程示意图;
图5为本发明实施例提供的一种基于区块链系统的共识装置的结构示意图;
图6为本申请提供的一种计算设备的结构示意图。
具体实施方式
为了使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明作进一步地详细描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。
金融科技(Fintech)技术领域通常涉及到多种交易,比如,银行的交易可以包括售卡交易、存款交易、贷款交易、保险交易、理财交易等,银行每天的交易量可以达到数千笔甚至数万笔。随着区块链技术的逐步发展,金融科技领域也可以使用区块链技术来处理交易,举例来说,若多家银行之间涉及到相关交易,则可以通过设置联盟链来同步处理相关交易,或者还可以将法院、客户等同时上链,共同维护联盟链的安全和稳定。
区块链系统可以是由多个节点组成的点对点(Peer To Peer,P2P)网络。P2P是一种运行在传输控制协议(Transmission Control Protocol,TCP)协议之上的应用层协议,在区块链系统中的节点可以彼此对等,系统中不存在中心节点,因此每个节点都可以随机地连接其它节点。在区块链系统中,每个节点内部都可以设置有预设数据库,各个节点通过预设数据库共同维护区块链系统中的公共账本,节点内部的预设数据库可以存储区块链系统中的区块数据;其中,区块数据包括区块头和区块体,区块头包括上一区块的哈希值、本区块的哈希值、本区块的块高、时间戳等信息,区块体包括交易数据,比如区块链系统中的节点对该区块进行共识的过程中处理待处理交易所生成的交易数据。
图1为本发明实施例提供的一种区块链系统的架构示意图,如图1所示,区块链系统中可以包括一个或多个节点,比如节点101、节点102、节点103与节点104,节点101~节点104中的任意两个节点可以通信连接,从而共同维护区块链系统。其中,任意两个节点可以通过有线方式连接,或者也可以通过无线方式连接,具体不作限定。
本发明实施例中,区块链系统中的节点可以具有多种功能,比如,路由功能、交易功能、区块链功能和共识功能等。具体地说,区块链系统中的节点可以把其他节点传送过来的交易数据等信息传送给更多的节点以实现节点之间的通信;或者,区块链系统中的节点可以用于支持用户进行交易;或者,区块链系统中的节点可以用于记录历史上的所有交易;或者,区块链系统中的节点可以通过验证和记录交易生成区块链中的新区块。实际应用中,路由功能是区块链系统中的每个节点必须具有的功能,而其它功能可由本领域技术人员根 据实际需要进行设置。
需要说明的是,区块链系统中的一个节点可以在一台物理机(服务器)上,且一个节点具体可以是指服务器中运行的一个进程或者一系列进程。比如,区块链网络中的节点101可以为一个服务器上运行的一个进程,或者也可以为是指服务器,具体不作限定。
如图1所示,该系统架构中还可以包括客户端设备200,客户端设备200可以通过接入区块链网络与区块链系统中的任一节点连接。具体实施中,客户端设备200可以将交易发送给区块链系统中的任一节点,区块链系统中的某一节点在接收到交易后,可以将交易同步给区块链系统中的其它节点。该节点在同步交易后,还可以将交易存储在节点内部的交易池中;相应地,其它节点在接收到该节点同步的交易后,也可以将交易存储在其它节点内部的交易池中。如此,若某一节点确定处理多条交易,则可以从内部的交易池中获取多条交易,进而进行后续的交易处理及区块共识。
其中,交易可以以栈的形式存储在交易池中;如此,若某一节点确定处理多条交易,则可以从内部的交易池中获取最早入栈的多条交易进行后续的处理及共识过程。
基于图1所示意的系统架构,图2为本发明实施例提供的一种使用PBFT共识算法处理交易时对应的流程示意图,如图2所示,PBFT共识算法处理交易的过程可以分为三个阶段:pre-prepare(预准备)阶段、prepare(准备)阶段和commit(提交)阶段。下面分别描述着三个阶段的具体实现过程。
一、pre-prepare阶段
采用PBFT共识算法,在每次成功执行一轮区块共识后,均可以从区块链系统的多个节点中选取一个节点作为主节点,将其它节点作为从节点;其中,成功执行一轮区块共识可以通过多种方式来确定,比如若检测到节点的内存中新增加了一个历史区块,则可以认为成功执行了一轮区块共识,或者若检测到节点更新了内部的预设数据库,则可以认为成功执行了一轮区块共识,等等。
PBFT共识算法可以从区块链系统的多个节点中轮流选取不同的节点作为主节点;具体地说,每个节点内部均可以设置一个视窗数值v,若上一轮区块共识执行成功,则每个节点内部的视窗数值v可以被置零,若上一轮区块共识执行失败,则每个节点内部的视窗数值v递增(即加1)。相应地,每个节点若检测到该节点的内存中新增加了一个历史区块,或者检测到该节点更新了内部的预设数据库,则可以按照如下公式确定下一轮区块共识的主节点的编号:
leader=(h+v)%n
其中,leader为下一轮区块共识的主节点的编号,h为待共识的区块的块高,v为视窗数值,n为区块链系统中的节点数量。
在一个示例中,每个节点可以将各自确定的主节点的编号发送给区块链系统中的其它节点,若对某一主节点的编号共识通过的节点数量大于预设数量,则可以将该编号对应的节点作为下一轮区块共识的主节点。在另一个示例中,每个节点确定主节点的编号后,若自己的节点标识与主节点的编号匹配,则该节点自动作为下一轮区块共识的主节点;若自己的节点标识与主节点的编号不匹配,则可以作为从节点,并不作任何处理,等待执行下一轮区块共识即可。
举例来说,表1为本发明实施例提供的一种节点标识与主节点的编号的对应关系的示意表。
表1:一种节点标识与主节点的编号的对应关系的示意
主节点的编号 节点标识
0 节点101
1 节点102
2 节点103
3 节点104
如表1所示,若节点确定出的主节点的编号为0,则可以将节点101作为下一轮区块共识的主节点,将节点102、节点103和节点104作为下一轮区块共识的从节点;若节点确定出的主节点的编号为1,则可以将节点102作为下一轮区块共识的主节点,将节点101、节点103和节点104作为下一轮区块共识的从节点;若节点确定出的主节点的编号为2,则将节点103作为下一轮区块共识的主节点,将节点101、节点102和节点104作为下一轮区块共识的从节点;若节点确定出的主节点的编号为3,则将节点104作为下一轮区块共识的主节点,将节点101、节点102和节点103作为下一轮区块共识的从节点。
比如,若上一轮区块共识的主节点为节点102,且节点101的内存中存储了一条新的历史区块1,则视窗数值v被置零,区块链系统中的节点数量为4,因此,节点101(或节点102~节点104)使用上述公式确定出的主节点的编号为2;基于表1可知,下一轮区块共识的主节点可以为节点103,使用主节点103执行区块2的共识。相应地,若节点102长时间未响应,则节点的内存中最大的历史区块仍为0,由于上一轮区块共识失败,因此视窗数值v递增为1,如此,节点101(或节点102~节点104)使用上述公式确定出的主节点的编号为2,即下一轮区块共识的主节点可以为节点103,使用主节点103执行区块1的共识;进一步地,若节点103长时间未响应,则节点103的内存中最大的历史区块仍为0,由于上一轮区块共识失败,因此视窗数值v递增为2,如此,节点101(或节点102~节点104)使用上述公式确定出的主节点的编号为3,即下一轮区块共识的主节点可以为节点104,使用主节点104执行区块1的共识。
在pre-prepare阶段中,若某一轮区块共识的主节点为节点101,且节点101的内存中存储的最大区块为区块1,则主节点101可以从主节点101的交易池中获取该轮区块共识待处理的交易数据,并根据该轮区块共识待处理的交易数据打包区块2,生成pre-prepare包。具体地说,主节点101可以使用区块1的哈希值、区块2的块高以及当前的时间戳组装区块2的区块头,并可以使用该轮区块共识待处理的交易数据组装区块2的区块体,进而可以根据区块2的区块头和区块体生成pre-prepare包。进一步地,主节点101可以将pre-prepare包发送给区块链系统中的任一节点,即节点102、节点103和节点104。
至此,pre-prepare阶段执行结束。
二、prepare阶段
在prepare阶段中,区块链系统中的任一节点接收到主节点101发送的pre-prepare包后,均可以解析pre-prepare包得到该轮区块共识待处理的交易数据;如此,该节点可以执行该轮区块共识待处理的交易数据得到交易结果。进一步地,该节点可以根据交易结果生成第一哈希值,根据每一条交易的收据信息生成第二哈希值,根据交易的请求消息生成第三哈希值,进而将第一哈希值、第二哈希值和第三哈希值组装到区块2的区块头中,并可以根据区块2的区块头中的数据生成区块2的哈希值。如此,该节点可以将区块2的哈希 值以及该轮区块共识处理的交易数据组装到区块2的区块体中,并使用该节点的私钥、区块2的哈希值、块高、节点的标识等信息生成该节点对区块2的签名包,进而可以将该节点的签名包发送给区块链系统中的其它节点。
至此,prepare阶段执行结束。
三、commit阶段
在commit阶段中,区块链系统中的任一节点内部均可以存储有区块链系统中所有节点的公钥,如此,任一节点在确定其它节点发送的签名包到达该节点后,可以先从该节点内部获取其它节点的公钥,并使用其它节点的公钥对其它节点的签名包进行解密,得到其它每个节点处理交易确定的区块2的哈希值。进一步地,任一节点可以将自己处理交易确定的区块2的哈希值与任一其它节点处理交易确定的区块2的哈希值进行对比,若相同,则可以接收所述其它节点发送的签名包,若不同,则可以拒绝所述其它节点发送的签名包。
针对于区块链系统中的任一节点,若该节点在超时时间内接收到的签名包的数量小于预设阈值,则该节点认为本轮区块共识失败,该节点可以发起视图切换,即递增内部的视窗数值v(比如若原视窗数值为1,则递增后的视窗数值为2)。相应地,若该节点在超时时间内接收到的签名包的数量大于或等于预设阈值,则说明该节点处理交易得到的区块2与区块链系统中其它大部分节点处理交易得到的区块2相同,该节点生成的区块2处于待提交状态;如此,该节点可以使用该节点的私钥、区块2的哈希值、块高、节点的标识等信息生成该节点对区块2的commit包,并可以将commit包发送给区块链系统中的其它节点,commit包用于指示该节点处于待提交状态。其中,预设阈值根据区块链系统中的总共识节点数n计算得出,计算公式为
Figure PCTCN2020106623-appb-000001
举例来说,在n为8时,预设阈值为5,则若该节点在prepare阶段收到4个签名包,说明该节点在本轮区块共识中失败,因此该节点可以发起视图切换;若该节点在prepare阶段接收到6个签名包,说明该节点处理交易得到的区块2与区块链系统中其它大部分共识节点处理交易得到的区块2相同,因此该节点可以生成commit包。
进一步地,区块链系统中的任一节点在确定其它节点发送的commit包到达该节点后,可以解析其它节点的commit包得到其它每个节点处理交易确定的区块2的哈希值;如此,该节点可以将自己处理交易确定的区块2的哈希值与任一其它节点处理交易确定的区块2的哈希值进行对比,若相同,则可以接收所述其它节点发送的commit包,若不同,则可以拒绝所述其它节点发送的commit包。相应地,若该节点在超时时间内接收到的commit包的数量小于预设阈值,则该节点认为本轮区块共识失败,该节点可以发起视图切换;相应地,若该节点在超时时间内接收到的commit包的数量大于或等于预设阈值,则说明该节点处理交易得到的区块2与区块链系统中其它大部分节点处理交易得到的区块2相同,如此,该节点可以从内存中获取该节点处理交易所生成的区块2,并可以将区块2写入该节点内部的预设数据库中,从而完成该轮区块共识。
至此,commit阶段执行结束。
综上,在执行多轮区块共识的过程中,PBFT共识算法从区块链系统的多个节点中确定本轮区块共识的主节点后,使用本轮区块共识的主节点执行本轮区块共识的区块打包,并在区块链系统中的每个节点执行完pre-prepare阶段、prepare阶段、commit节点后,确 定本轮区块共识结束;进一步地,PBFT共识算法再从区块链系统的多个节点中确定出下一轮区块共识的主节点,使用下一轮区块共识的主节点执行下一轮区块共识的区块打包,并在区块链系统中的每个节点执行完pre-prepare阶段、prepare阶段、commit节点后,确定下一轮区块共识结束;重复执行上述过程,直至交易池中不存在待处理的交易数据为止。
由此可知,PBFT共识算法可以依次执行每轮区块共识,即在上一轮区块共识结束后启动下一轮区块共识,采用该种方式,其可以较好地在交易量较小的区块链系统中进行交易处理。然而,在金融科技领域中,每秒钟可能会产生数千甚至数万笔交易,导致金融科技领域的区块链系统中待处理的交易数据非常多,若使用PBFT共识算法依次执行每轮区块共识,则可能会需要大量的时间,导致交易处理的效率非常低,甚至可能使得交易堵塞,从而为金融领域带来巨大的损失。
基于此,本发明实施例提供了一种基于区块链系统的共识方法,用以解决现有的区块链系统依次执行每轮区块共识所导致的区块链系统的共识效率和交易处理效率均较低的技术问题。
基于图1所示的区块链系统和图2所述的PBFT共识算法,图3为本发明实施例提供的一种基于区块链系统的共识方法对应的流程示意图,该方法包括:
步骤301,在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息;第M区块的共识信息包括第I轮区块共识中待处理的第一交易数据,第二节点为第I轮区块共识的主节点。
本发明实施例中,若第I-1轮区块共识中待共识的第M-1区块成功写入区块链系统中节点的预设数据库,则可以确定第I-1轮区块共识成功;如此,若第I轮区块共识的主节点为第二节点,则第二节点可以将第I轮区块共识中待共识的第M区块的共识信息发送给区块链系统中的其它节点。其中,第M区块的共识信息的生成方式可以有多种,下面分别描述两种可能的实现方式:
在一种可能的实现方式中,第M区块的共识信息可以为第二节点在第I-1轮区块共识成功后生成的;具体地说,在确定第I-1轮区块共识成功后,第二节点可以从第二节点的内存池中获取第I轮区块共识中待处理的第一交易数据,并可以使用第一交易数据组装第M区块的区块体,根据第M-1区块的块高设置第M区块的块高,并使用第M区块的块高、第M-1区块的哈希值和当前时间戳组装第M区块的区块头,进而根据第M区块的区块头和第M区块的区块体生成第M区块的共识信息。
举例来说,基于图1所示意的区块链系统,若第I-1轮区块共识成功,且区块链系统在当前时刻历史最大区块的块高为1,因此,第I轮区块共识中待共识的区块为区块2,在第I轮区块共识启动时,视窗数值v=0,节点数n=4,块高h=2,且基于表1可知第I轮区块共识的主节点为节点103;如此,节点103可以从内部设置的交易池中获取第I轮区块共识中待处理的第一交易数据,并可以使用区块2的块高、区块1的哈希值和当前时间戳组装区块2的区块头,使用第一交易数据组装区块2的区块体,进而使用区块2的区块头和区块2的区块体生成pre-prepare包。
在另一种可能的实现方式中,第M区块的共识信息可以为第二节点在第I-1轮区块共识过程中生成的,比如第二节点在接收到第M-1区块的共识信息后,若确定第二节点为第I轮区块共识的主节点,则可以在参与第I-1轮区块共识的过程中,并行地根据第M-1区块的共识信息生成第M区块的共识信息。需要说明的是,该种实现方式可以参照步骤301和步骤302 中生成第M+1区块的共识信息的过程进行具体实施,此处不再赘述。
在一个示例中,第M区块的共识信息可以包括第M区块的块高、第M-1区块的哈希值、第M区块的生成时间戳和第一交易数据。其中,第一交易数据可以包括一个交易的交易数据,或者也可以包括多个(即两个或两个以上)交易的交易数据,具体不作限定。
步骤302,第一节点若确定第一节点为第I+1轮区块共识的主节点,则在根据第M区块的共识信息对第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;其中,第M+1区块的共识信息包括第I+1轮区块共识中待处理的第二交易数据;第二交易数据与第一交易数据不同。
本发明实施例中,区块链系统中的每个节点在接收到第二节点发送的第M区块的共识信息后,均可以解析第M区块的共识信息得到第M区块的块高、第M-1区块的哈希值、第M区块的生成时间戳和第一交易数据。进一步地,针对于区块链系统中的每个节点,该节点可以根据第M区块的块高和区块链系统中的节点数据确定该节点是否为第I+1轮区块共识的主节点,若不是,则该节点可以直接参与第I轮区块共识过程,若是,则该节点可以在参与第I轮区块共识时并行地生成第I+1轮区块共识中待共识的第M+1区块的共识信息。
作为一种示例,节点可以基于如下公式和表1确定该节点是否为第I+1轮区块共识的主节点:
leader I+1=(h M+1)%n
其中,leader I+1为第I+1轮区块共识的主节点的编号,h M为第M区块的块高,n为区块链系统中总共识节点的数量。
举例来说,若第M区块为区块2,第I轮区块共识的主节点为节点103,则节点101、节点102和节点104在接收到节点103发送的区块2的pre-prepare包后,可以分别使用上述公式确定第I+1轮区块共识的主节点的编号。针对于节点101、节点102和节点103来说,由于上述公式确定出的主节点的编号为3,根据表1确定编号为3的主节点对应的节点为节点104,因此节点101、节点102和节点103可以继续执行第I轮区块共识过程;相应地,针对于节点104来说,由于上述公式确定出的主节点的编号为3,根据表1确定编号为3的主节点对应的节点为节点104,因此节点104可以在执行第I轮区块共识的过程中并行地生成区块3的pre-prepare包。
本发明实施例中,针对于区块链系统中的任一节点,通过使用该节点的标识自动匹配第I+1轮区块共识的主节点的编号,确定该节点是否为第I+1轮区块共识的主节点,可以在某一节点匹配成功时调用该节点自动打包第I+1轮区块共识中待共识的第M+1区块,从而可以保证第I+1轮区块共识与第I轮区块共识的自动并行执行,提高区块链系统共识的准确性。
以节点101为例,在确定不是第I+1轮区块共识的主节点后,节点101可以处理第一交易数据得到第一交易数据的处理结果,并可以根据第一交易数据的处理结果生成第一哈希值,根据第一交易数据生成第二哈希值,根据第一交易数据中执行每笔交易的收据生成第三哈希值,进而可以使用预设哈希算法对第一哈希值、第二哈希值和第三哈希值进行计算得到区块2的哈希值。进一步地,节点101可以将第一哈希值、第二哈希值、第三哈希值和区块2的哈希值组装到区块2的区块头中,并可以将区块2的哈希值以及第一交易数据组装到区块2的区块体中,使用节点101的私钥、区块2的哈希值、区块2的高度、节点101的标识等信息生成节点101对区块2的签名包,进而将节点101对区块2的签名包发送给节点102、节点103和节点104;且,节点101可以等待节点102、节点103和节点104分别发送的签名包, 并可以根据接收到的签名包的数量继续执行第I轮区块共识中commit阶段。
相应地,节点104在执行第I轮区块共识的过程中并行生成区块3的pre-prepare包的方式可以有多种,比如节点104可以先执行prepare阶段得到节点104对区块2的签名包,并将节点104对区块2的签名包发送给节点101、节点102和节点103,然后在等待节点101、节点102和节点103发送的签名包时,根据区块2的pre-prepare包生成区块3的pre-prepare包;或者也可以在接收到节点103发送的区块2的共识信息后,先根据区块2的pre-prepare包生成区块3的pre-prepare包,再根据节点103发送的区块2的pre-prepare包生成节点104对区块2的签名包;或者还可以先执行prepare阶段和commit阶段得到节点104对区块2的commit包,并将节点104对区块2的commit包发送给节点101、节点102和节点103,然后在等待节点101、节点102和节点103发送的commit包时,根据区块2的pre-prepare包生成区块3的pre-prepare包;等等,具体不作限定。
在一种可能的实现方式中,节点104可以采用如下方式生成区块3的pre-prepare包:节点104可以先解析区块2的pre-prepare包得到区块2的块高和第一交易数据,然后可以根据区块2的块高设置区块3的块高,并可以从节点104的交易池中获取除第一交易数据之外的第二交易数据;进一步地,节点104可以使用区块3的块高和当前时间戳组装得到区块3的区块头,并可以使用第二交易数据组装得到区块3的区块体,进而可以根据区块3的区块头和区块3的区块体生成区块3的pre-prepare包。
其中,pre-prepare包可以为具有预设格式的数据包,pre-prepare包可以由多个存储区域构成,每个存储区域用于存储设定数据。举例来说,区块3的pre-prepare包可以由第一存储字段、第二存储字段、第三存储字段和第四存储字段,其中,第一存储字段用于存储区块3的块高、第二存储字段用于存储区块3的生成时间戳,第三存储字段用于存储区块2的哈希值,第四存储字段可以存储区块3中待处理的交易数据(即第二交易数据)。此处,第一~第四存储字段可存储的数据量可以由本领域技术人员根据经验进行设置,不作限定。
具体实施中,节点104在组装得到区块3的区块头和区块3的区块体后,可以先将区块3的区块头和区块3的区块体存储在节点104的内存中,然后生成区块3的初始pre-prepare包(可以为空数据包);进一步地,节点104可以将区块3的块高转化为预设格式(比如二进制)后放置在初始pre-prepare包的第一存储字段中,将区块3的生成时间戳转化为预设格式后放置在初始pre-prepare包的第二存储字段中,将第二交易数据转化为预设格式后放置在初始pre-prepare包的第四存储字段中,由于区块2还未完成共识,因此可以使初始pre-prepare包的第三存储字段空闲;如此,节点104可以得到区块3的pre-prepare包,并可以将区块3的pre-prepare包存储在内存中。
本发明实施例中,通过从交易池中获取除第I轮区块共识中待处理的第一交易数据以外的第二交易数据,将第二交易数据作为第M+1区块的区块体,可以避免第I+1轮区块共识重复处理第I轮区块共识所处理的交易数据,保证在并行执行第I轮区块共识和第I+1轮区块共识时交易处理的准确性;且,并行执行第I轮区块共识和第I+1轮区块共识时,虽然第二节点的历史最大区块为第M-1区块,但是通过根据第I轮区块共识中待共识的第M区块的块高设置第I+1轮区块共识中待共识的第M+1区块的块高,可以使得第二节点准确生成第I+1轮区块共识过程对应的区块头,从而使得并行执行第I轮区块共识和第I+1轮区块共识。
进一步地,节点104可以继续执行区块2的共识过程,比如依次执行prepare阶段和commit阶段,并在commit阶段执行完成后确定区块2是否共识成功,若节点104成功将区块 2的共识结果存储在预设数据库中,则确定区块2共识成功,因此节点104可以向节点101、节点102和节点103发送区块3的pre-prepare包;若节点104未能成功将区块2的共识结果存储在预设数据库中,则确定区块2共识失败,因此节点104可以重新执行区块2的共识过程。
在一个示例中,节点104在确定区块2共识成功后,还可以从区块2的共识结果中获取区块2的哈希值,并可以将区块2的哈希值转化为预设格式后添加至区块3的pre-prepare包的第三存储字段中,从而得到区块3的目标pre-prepare包,进而可以将区块3的目标pre-prepare包发送给节点101、节点102和节点103。
本发明实施例中,在第I轮区块共识成功后,通过将第I轮区块共识中待共识的第M区块的哈希值添加在第I+1轮区块共识中待共识的第M+1区块中,可以在第I+1轮区块共识中组装完整的第M+1区块,从而准确建立第M区块与第M+1区块的关联关系,保证区块共识过程的顺序进行以及区块链的完整性。
相应地,节点104若确定区块2共识失败,则可以按照如下方式重复执行对区块2的共识过程:节点104可以从内存中确定最大历史区块(即区块1)的块高,并可以从节点104的交易池中获取第一交易数据,如此,节点104可以根据区块1的块高设置区块2的块高,并可以根据区块2的块高、区块1的哈希值和当前时间戳组装区块2的区块头,根据第一交易数据组装区块2的区块体,进而可以根据区块2的区块头和区块2的区块体生成区块2的pre-prepare包,并可以将区块2的pre-prepare包发送给节点101、节点102和节点103,以使区块链系统中的每个节点执行prepare阶段和commit阶段完成对区块2的共识。
本发明实施例中,在第I轮区块共识失败后,通过使用第一节点重新组装待共识的第M区块并对第M区块执行共识过程,可以避免并行处理两轮区块共识的过程时由于上一轮区块共识失败导致的遗漏上一轮区块共识中待共识区块的问题,保证区块链系统共识的准确性。
基于图1所示意的区块链系统和图3所示意的共识方法,图4为本发明实施例提供的一种执行区块共识的流程示意图,该方法包括:
步骤401,在第一轮区块共识中,主节点101打包区块0。
具体实施中,在第一轮区块共识中,由于区块链系统中不存在历史区块,因此待共识的区块为区块0;相应地,由于区块链系统中的区块数量为4,视窗数值v为0,因此使用公式leader=(h+v)/n确定主节点的编号为0;基于表1确定编号为0的主节点对应的节点为节点101,即节点101为第一轮区块共识的主节点。
如此,主节点101可以从主节点101的交易池中获取第一轮区块共识待处理的交易数据,并可以根据区块0的块高和当前时间戳组装区块0的区块头,根据第一轮区块共识待处理的交易数据组装区块0的区块体,进而可以根据区块0的区块头和区块0的区块体生成区块0的pre-prepare包,将区块0的pre-prepare包发送给节点102~节点104。
步骤402,节点102~节点104接收到节点101发送的区块0的pre-prepare包;在第一轮区块共识中,节点101、节点103和节点104确定不为第二轮区块共识的主节点,则直接参与区块0的共识过程,即依次执行prepare阶段和commit阶段;相应地,节点102确定节点102为第二轮区块共识的主节点,因此节点102可以在参与区块0的共识过程时,并行生成区块1的pre-prepare包。
以节点102为例,由于第一轮区块共识中区块0的块高为0,区块链系统中的区块数量为4,因此节点102使用公式leader I+1=(h M+1)/n确定主节点的编号为1;基于表1确 定编号为1的主节点对应的节点为节点102,即节点102为第二轮区块共识的主节点。
进一步地,节点102可以根据区块0的块高设置区块1的块高,并可以从交易池中获取第二轮区块共识待处理的交易数据,其中,第二轮区块共识待处理的交易数据不同于第一轮区块共识待处理的交易数据;节点102可以根据区块1的块高、当前时间戳和第二轮区块共识待处理的交易数据生成区块1的pre-prepare包。
步骤403,第一轮区块共识结束后,由于区块0共识成功,因此节点102可以使用区块0的哈希值更新区块1的pre-prepare包,并将更新后的区块1的pre-prepare包发送给节点101、节点103和节点104,启动第二轮区块共识。
相应地,节点101、节点103和节点104接收到节点102发送的区块1的pre-prepare包,在第二轮区块共识中,节点101、节点102和节点104确定不为第三轮区块共识的主节点,则直接参与区块1的共识过程,即依次执行prepare阶段和commit阶段。相应地,节点103确定节点103为第三轮区块共识的主节点,因此节点103可以在参与区块1的共识过程时,根据区块2的块高、当前时间戳和第三轮区块共识待处理的交易数据并行生成区块2的pre-prepare包。
步骤404,第二轮区块共识结束后,由于区块1共识成功,因此节点103可以使用区块1的哈希值更新区块2的pre-prepare包,并将更新后的区块2的pre-prepare包发送给节点101、节点102和节点104,启动第三轮区块共识。
相应地,节点101、节点102和节点104接收到节点103发送的区块2的pre-prepare包,在第三轮区块共识中,节点101、节点102和节点103确定不为第四轮区块共识的主节点,则直接参与区块2的共识过程,即依次执行prepare阶段和commit阶段。相应地,节点104确定节点104为第四轮区块共识的主节点,因此节点104可以在参与区块2的共识过程时,根据区块3的块高、当前时间戳和第四轮区块共识待处理的交易数据并行生成区块3的pre-prepare包。
步骤405,第三轮区块共识结束后,由于区块2共识失败,因此节点101~节点104中视窗数值v的值递增为1,历史最大区块为1,根据公式leader=(h+v)/n确定主节点的编号为3;基于表1确定编号为3的主节点对应的节点为节点104,即节点104为第四轮区块共识的主节点。
具体实施中,节点104可以删除内存中存储的区块3,并可以重新打包区块2,比如主节点104可以从主节点104的交易池中获取第三轮区块共识待处理的交易数据,并可以根据区块2的块高、区块1的哈希值和当前时间戳组装区块2的区块头,根据第三轮区块共识待处理的交易数据组装区块2的区块体,进而可以根据区块2的区块头和区块2的区块体生成区块2的pre-prepare包,将区块2的pre-prepare包发送给节点101~节点103。
步骤406,节点101、节点102和节点103接收到节点104发送的区块2的pre-prepare包,在第四轮区块共识中,节点102、节点103和节点104确定不为第五轮区块共识的主节点,则可以直接参与区块2的共识过程,即依次执行prepare阶段和commit阶段。相应地,节点101确定节点101为第五轮区块共识的主节点,因此节点101可以在参与区块2的共识过程时,根据区块2的块高、当前时间戳和第五轮区块共识待处理的交易数据并行生成区块3的pre-prepare包。
步骤407,第四轮区块共识结束后,由于区块2共识成功,因此节点101可以使用区块2的哈希值更新区块3的pre-prepare包,并将更新后的区块3的pre-prepare包发送给节 点102、节点103和节点104,启动第五轮区块共识。
相应地,节点102、节点103和节点104接收到节点101发送的区块3的pre-prepare包,在第五轮区块共识中,节点101、节点103和节点104确定不为第六轮区块共识的主节点,则直接参与区块3的共识过程,即依次执行prepare阶段和commit阶段。相应地,节点102确定节点102为第六轮区块共识的主节点,因此节点102可以在参与区块3的共识过程时,根据区块4的块高、当前时间戳和第六轮区块共识待处理的交易数据并行生成区块4的pre-prepare包。
基于图4所示意的流程可以确定,相比于现有的区块链系统直接使用PBFT共识算法依次执行每一轮区块共识过程来说,本发明实施例中的区块共识方法可以极大地缩短共识时间,提高区块链系统的共识效率。
本发明的上述实施例中,在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;进一步地,所述第一节点若确定所述第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同。本发明实施例中,通过在第I轮区块共识的执行过程中启动第I+1轮区块共识的主节点,使第I+1轮区块共识过的主节点自动打包区块,实现了对第I轮区块共识的共识过程与第I+1轮区块共识的区块打包过程的并行执行,减少了第I+1轮区块共识的操作时间,从而可以提高区块链系统的共识效率。
针对上述方法流程,本发明实施例还提供一种基于区块链系统的共识装置,该装置的具体内容可以参照上述方法实施。
图5为本发明实施例提供的一种基于区块链系统的共识装置的结构示意图,包括:
收发模块501,用于在第I轮区块共识中,接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;其中,I、M为正整数;
生成模块502,用于若确定第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同。
可选地,所述生成模块502具体用于:
从所述第一节点的交易池中获取除所述第一交易数据之外的第二交易数据,并根据所述第M区块的块高设置所述第M+1区块的块高;
根据所述第二交易数据、所述第M+1区块的块高和当前时间戳,生成所述第M+1区块的共识信息。
可选地,在所述生成模块502并行生成待共识的第M+1区块的共识信息之后,所述收发模块501还用于:
若确定所述第I轮区块共识的共识结果为共识成功,则将所述第M区块的哈希值添加在所述第M+1区块的共识信息中,并将所述第M+1区块的共识信息发送给所述区块链系统中的其它节点。
可选地,所述生成模块502还用于:
若确定所述第I轮区块共识的共识结果为共识失败,则从所述第一节点的交易池中获取所述第一交易数据,并根据历史最大区块的块高设置所述第M区块的块高;
根据所述第一交易数据、所述第M区块的块高、所述历史最大区块的哈希值和当前时间戳,生成所述第M区块的共识信息;
将所述第M区块的共识信息发送给所述区块链系统中的其它节点。
可选地,所述生成模块502具体用于:
根据所述第M区块的块高和所述区块链系统的节点数量确定所述第I+1轮区块共识的主节点的编号,若所述第一节点的标识与所述第I+1轮区块共识的主节点的编号匹配,则确定所述第一节点为所述第I+1轮区块共识的主节点。
从上述内容可以看出:本发明的上述实施例中,在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;进一步地,所述第一节点若确定所述第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同。本发明实施例中,通过在第I轮区块共识的执行过程中启动第I+1轮区块共识的主节点,使第I+1轮区块共识过的主节点自动打包区块,实现了对第I轮区块共识的共识过程与第I+1轮区块共识的区块打包过程的并行执行,减少了第I+1轮区块共识的操作时间,从而可以提高区块链系统的共识效率。
基于与上述图3所示的方法相同的构思,本申请还提供一种计算设备,如图6所示,该计算设备包括至少一个处理器620,用于实现本申请实施例提供的图3中任一方法。
计算设备600还可以包括至少一个存储器630,用于存储程序指令和/或数据。存储器630和处理器620耦合。本申请实施例中的耦合是装置、单元或模块之间的间接耦合或通信连接,可以是电性,机械或其它的形式,用于装置、单元或模块之间的信息交互。处理器620可能和存储器630协同操作。处理器620可能执行存储器630中存储的程序指令。所述至少一个存储器中的至少一个可以包括于处理器中。
在实现过程中,上述方法的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。结合本申请实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器,处理器读取存储器中的信息,结合其硬件完成上述方法的步骤。为避免重复,这里不再详细描述。
应注意,本申请实施例中的处理器可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法实施例的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器可以是通用处理器、数字信号处理电路(digital signal processor,DSP)、专用集成芯片(application specific integrated circuit,ASIC)、现场可编程门阵列(field programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。 结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器,处理器读取存储器中的信息,结合其硬件完成上述方法的步骤。
可以理解,本申请实施例中的存储器可以是易失性存储器或非易失性存储器,或可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(read-only memory,ROM)、可编程只读存储器(programmable ROM,PROM)、可擦除可编程只读存储器(erasable PROM,EPROM)、电可擦除可编程只读存储器(electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(random access memory,RAM),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(static RAM,SRAM)、动态随机存取存储器(dynamic RAM,DRAM)、同步动态随机存取存储器(synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(double data rate SDRAM,DDR SDRAM)、增强型同步动态随机存取存储器(enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(synchlink DRAM,SLDRAM)和直接内存总线随机存取存储器(direct rambus RAM,DR RAM)。应注意,本文描述的系统和方法的存储器旨在包括但不限于这些和任意其它适合类型的存储器。
计算设备600还可以包括通信接口610,用于通过传输介质和其它设备进行通信,从而用于计算设备600中的装置可以和其它设备进行通信。在本申请实施例中,通信接口可以是收发器、电路、总线、模块或其它类型的通信接口。在本申请实施例中,通信接口为收发器时,收发器可以包括独立的接收器、独立的发射器;也可以集成收发功能的收发器、或者是接口电路。
计算设备600还可以包括通信线路640。其中,通信接口610、处理器620以及存储器630可以通过通信线路640相互连接;通信线路640可以是外设部件互连标准(peripheral component interconnect,简称PCI)总线或扩展工业标准结构(extended industry standard architecture,简称EISA)总线等。所述通信线路640可以分为地址总线、数据总线、控制总线等。为便于表示,图6中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
基于同一发明构思,本发明实施例还提供了一种非暂态计算机可读存储介质,非暂态计算机可读存储介质中存储计算机指令,当其在计算机上运行时,使得计算机执行上述基于区块链系统的共识方法。
基于同一发明构思,本申请实施例提供一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行上述基于区块链系统的共识方法。
本领域内的技术人员应明白,本发明的实施例可提供为方法、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图 和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。

Claims (13)

  1. 一种基于区块链系统的共识方法,其特征在于,所述方法包括:
    在第I轮区块共识中,第一节点接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;
    所述第一节点若确定所述第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易数据与所述第一交易数据不同;
    其中,I、M为正整数。
  2. 根据权利要求1所述的方法,其特征在于,所述第一节点并行生成待共识的第M+1区块的共识信息,包括:
    所述第一节点从所述第一节点的交易池中获取除所述第一交易数据之外的第二交易数据,并根据所述第M区块的块高设置所述第M+1区块的块高;
    所述第一节点根据所述第二交易数据、所述第M+1区块的块高和当前时间戳,生成所述第M+1区块的共识信息。
  3. 根据权利要求2所述的方法,其特征在于,所述第一节点并行生成待共识的第M+1区块的共识信息之后,还包括:
    所述第一节点若确定所述第I轮区块共识的共识结果为共识成功,则将所述第M区块的哈希值添加在所述第M+1区块的共识信息中,并将所述第M+1区块的共识信息发送给所述区块链系统中的其它节点。
  4. 根据权利要求3所述的方法,其特征在于,所述方法还包括:
    所述第一节点若确定所述第I轮区块共识的共识结果为共识失败,则从所述第一节点的交易池中获取所述第一交易数据,并根据历史最大区块的块高设置所述第M区块的块高;
    所述第一节点根据所述第一交易数据、所述第M区块的块高、所述历史最大区块的哈希值和当前时间戳,生成所述第M区块的共识信息;
    所述第一节点将所述第M区块的共识信息发送给所述区块链系统中的其它节点。
  5. 根据权利要求1至4中任一项所述的方法,其特征在于,所述第一节点通过如下方式确定所述第一节点为所述第I+1轮区块共识的主节点:
    所述第一节点根据所述第M区块的块高和所述区块链系统的节点数量确定所述第I+1轮区块共识的主节点的编号,若所述第一节点的标识与所述第I+1轮区块共识的主节点的编号匹配,则确定所述第一节点为所述第I+1轮区块共识的主节点。
  6. 一种基于区块链系统的共识装置,其特征在于,所述装置包括:
    收发模块,用于在第I轮区块共识中,接收第二节点发送的待共识的第M区块的共识信息,所述第M区块的共识信息包括所述第I轮区块共识中待处理的第一交易数据,所述第二节点为所述第I轮区块共识的主节点;其中,I、M为正整数;
    生成模块,用于若确定第一节点为第I+1轮区块共识的主节点,则在根据所述第M区块的共识信息对所述第M区块进行共识时,并行生成待共识的第M+1区块的共识信息;所述第M+1区块的共识信息包括所述第I+1轮区块共识中待处理的第二交易数据;所述第二交易 数据与所述第一交易数据不同。
  7. 根据权利要求6所述的装置,其特征在于,所述生成模块具体用于:
    从所述第一节点的交易池中获取除所述第一交易数据之外的第二交易数据,并根据所述第M区块的块高设置所述第M+1区块的块高;
    根据所述第二交易数据、所述第M+1区块的块高和当前时间戳,生成所述第M+1区块的共识信息。
  8. 根据权利要求7所述的装置,其特征在于,在所述生成模块并行生成待共识的第M+1区块的共识信息之后,所述收发模块还用于:
    若确定所述第I轮区块共识的共识结果为共识成功,则将所述第M区块的哈希值添加在所述第M+1区块的共识信息中,并将所述第M+1区块的共识信息发送给所述区块链系统中的其它节点。
  9. 根据权利要求8所述的装置,其特征在于,所述生成模块还用于:
    若确定所述第I轮区块共识的共识结果为共识失败,则从所述第一节点的交易池中获取所述第一交易数据,并根据历史最大区块的块高设置所述第M区块的块高;
    根据所述第一交易数据、所述第M区块的块高、所述历史最大区块的哈希值和当前时间戳,生成所述第M区块的共识信息;
    将所述第M区块的共识信息发送给所述区块链系统中的其它节点。
  10. 根据权利要求6至9中任一项所述的装置,其特征在于,所述生成模块具体用于:
    根据所述第M区块的块高和所述区块链系统的节点数量确定所述第I+1轮区块共识的主节点的编号,若所述第一节点的标识与所述第I+1轮区块共识的主节点的编号匹配,则确定所述第一节点为所述第I+1轮区块共识的主节点。
  11. 一种计算设备,其特征在于,包括处理器、存储器、通信接口,其中处理器、存储器与通信接口之间通过总线连接;
    所述处理器,用于读取所述存储器中的程序,执行权利要求1至5任一所述方法;
    所述存储器,用于存储一个或多个可执行程序,以及存储所述处理器在执行操作时所使用的数据。
  12. 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令用于使所述计算机执行权利要求1至5任一所述方法。
  13. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行权利要求1至5任一所述方法。
PCT/CN2020/106623 2019-08-27 2020-08-03 一种基于区块链系统的共识方法及装置 WO2021036702A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910798196.6 2019-08-27
CN201910798196.6A CN110517141B (zh) 2019-08-27 2019-08-27 一种基于区块链系统的共识方法及装置

Publications (1)

Publication Number Publication Date
WO2021036702A1 true WO2021036702A1 (zh) 2021-03-04

Family

ID=68628154

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/106623 WO2021036702A1 (zh) 2019-08-27 2020-08-03 一种基于区块链系统的共识方法及装置

Country Status (2)

Country Link
CN (1) CN110517141B (zh)
WO (1) WO2021036702A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113379542A (zh) * 2021-05-28 2021-09-10 中邮信息科技(北京)有限公司 一种区块链交易的查询方法、装置、介质及电子设备
CN113486118A (zh) * 2021-07-21 2021-10-08 银清科技有限公司 共识节点选取方法及装置

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110517141B (zh) * 2019-08-27 2023-06-13 深圳前海微众银行股份有限公司 一种基于区块链系统的共识方法及装置
CN110708171B (zh) * 2019-12-13 2020-06-12 腾讯科技(深圳)有限公司 区块链共识投票方法、装置、设备以及存储介质
CN111369358B (zh) * 2020-02-10 2023-09-12 杭州溪塔科技有限公司 一种区块链共识方法、装置和电子设备
CN111556120B (zh) * 2020-04-23 2023-04-07 财付通支付科技有限公司 基于区块链的数据处理方法、装置、存储介质及设备
CN111768288B (zh) * 2020-06-02 2023-12-08 北京同邦卓益科技有限公司 业务处理方法、装置、电子设备及存储介质
CN111698094B (zh) * 2020-06-12 2023-06-09 深圳前海微众银行股份有限公司 一种基于区块链系统的共识方法及区块链系统
CN111711526B (zh) * 2020-06-16 2024-03-26 深圳前海微众银行股份有限公司 一种区块链节点的共识方法及系统
CN111522648B (zh) 2020-07-03 2020-10-09 支付宝(杭州)信息技术有限公司 一种区块链的交易处理方法、装置及电子设备
CN112256476B (zh) * 2020-09-27 2024-04-16 陕西医链区块链集团有限公司 基于区块链的数据操作方法、装置、设备及介质
CN112511312B (zh) * 2020-11-23 2023-10-17 北京微芯区块链与边缘计算研究院 一种可组装的共识方法及系统
CN113204432A (zh) * 2021-02-03 2021-08-03 支付宝(杭州)信息技术有限公司 区块链中的交易处理方法、装置及电子设备
CN116737810A (zh) * 2023-05-06 2023-09-12 清华大学 一种用于分布式时序数据库的共识服务接口

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190028276A1 (en) * 2017-07-20 2019-01-24 Chicago Mercantile Exchange Inc. Blockchain including linked digital assets
US20190182029A1 (en) * 2017-12-08 2019-06-13 Electronics And Telecommunications Research Institute Method of generating block chain and apparatus and method for generating blocks
CN109889397A (zh) * 2019-03-31 2019-06-14 杭州复杂美科技有限公司 抽签方法、区块生成方法、设备及存储介质
CN109978516A (zh) * 2019-03-06 2019-07-05 西安电子科技大学 区块链网络中区块的制造和同步方法、信息数据处理终端
CN109993647A (zh) * 2019-03-08 2019-07-09 西安电子科技大学 一种基于区块链的纳税征信系统及处理方法
CN110517141A (zh) * 2019-08-27 2019-11-29 深圳前海微众银行股份有限公司 一种基于区块链系统的共识方法及装置

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109064328B (zh) * 2018-07-09 2022-04-15 夸克链科技(深圳)有限公司 一种区块链的共识方法
CN109831425B (zh) * 2019-01-25 2022-02-15 中国联合网络通信集团有限公司 区块链共识方法、装置、设备及计算机可读存储介质

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190028276A1 (en) * 2017-07-20 2019-01-24 Chicago Mercantile Exchange Inc. Blockchain including linked digital assets
US20190182029A1 (en) * 2017-12-08 2019-06-13 Electronics And Telecommunications Research Institute Method of generating block chain and apparatus and method for generating blocks
CN109978516A (zh) * 2019-03-06 2019-07-05 西安电子科技大学 区块链网络中区块的制造和同步方法、信息数据处理终端
CN109993647A (zh) * 2019-03-08 2019-07-09 西安电子科技大学 一种基于区块链的纳税征信系统及处理方法
CN109889397A (zh) * 2019-03-31 2019-06-14 杭州复杂美科技有限公司 抽签方法、区块生成方法、设备及存储介质
CN110517141A (zh) * 2019-08-27 2019-11-29 深圳前海微众银行股份有限公司 一种基于区块链系统的共识方法及装置

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113379542A (zh) * 2021-05-28 2021-09-10 中邮信息科技(北京)有限公司 一种区块链交易的查询方法、装置、介质及电子设备
CN113379542B (zh) * 2021-05-28 2024-01-09 中邮信息科技(北京)有限公司 一种区块链交易的查询方法、装置、介质及电子设备
CN113486118A (zh) * 2021-07-21 2021-10-08 银清科技有限公司 共识节点选取方法及装置
CN113486118B (zh) * 2021-07-21 2023-09-22 银清科技有限公司 共识节点选取方法及装置

Also Published As

Publication number Publication date
CN110517141B (zh) 2023-06-13
CN110517141A (zh) 2019-11-29

Similar Documents

Publication Publication Date Title
WO2021036702A1 (zh) 一种基于区块链系统的共识方法及装置
CN110503558B (zh) 一种基于区块链系统的处理方法及装置
CN113329031B (zh) 一种区块的状态树的生成方法及装置
WO2021077962A1 (zh) 一种区块链节点同步的方法及装置
JP7154234B2 (ja) ブロックチェーン・ネットワークにおける高速伝搬のための方法及び特殊ネットワーク・ノード
CN112685796B (zh) 一种基于区块链的区块共识方法以及相关设备
CN111475576B (zh) 基于区块链的分布式数据库存储方法及系统
US20230273912A1 (en) Data processing method and apparatus for blockchain network, computer device, and computer-readable storage medium
WO2021120925A1 (zh) 一种区块同步的方法及装置
TW202016817A (zh) 基於區塊鏈的交易處理方法及裝置、電子設備
US20240163121A1 (en) Blockchain consensus method, apparatus, and device, and storage medium
WO2019019056A1 (zh) 前置机参与区块链共识的方法
CN111698094B (zh) 一种基于区块链系统的共识方法及区块链系统
WO2020248982A1 (zh) 一种区块链中交易处理的方法及装置
CN111163148B (zh) 一种区块链系统的共识状态的同步方法及相关设备
CN113064764B (zh) 在区块链系统中执行区块的方法及装置
US20230102617A1 (en) Repeat transaction verification method, apparatus, and device, and medium
WO2021244581A1 (zh) 联盟链中的共识方法和系统
WO2023011019A1 (zh) 基于区块链的数据处理方法、装置、设备、可读存储介质及计算机程序产品
WO2019153660A1 (zh) 交易处理方法、装置、计算机设备和存储介质
WO2021184873A1 (zh) 用于区块链网络中的数据同步的方法、装置和计算设备
WO2021196463A1 (zh) 一种区块链数据的同步方法、装置及电子设备、存储介质
CN113157450B (zh) 在区块链系统中执行区块的方法及装置
CN111309809A (zh) 一种区块头保存方法及其设备
CN116977067A (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质

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: 20856602

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 30/06/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20856602

Country of ref document: EP

Kind code of ref document: A1