WO2021032138A1 - 一种基于区块链***的共识方法、装置及*** - Google Patents

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

Info

Publication number
WO2021032138A1
WO2021032138A1 PCT/CN2020/110108 CN2020110108W WO2021032138A1 WO 2021032138 A1 WO2021032138 A1 WO 2021032138A1 CN 2020110108 W CN2020110108 W CN 2020110108W WO 2021032138 A1 WO2021032138 A1 WO 2021032138A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
consensus
block
group
layer
Prior art date
Application number
PCT/CN2020/110108
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 WO2021032138A1 publication Critical patent/WO2021032138A1/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
    • H04L67/104Peer-to-peer [P2P] networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
    • 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), and in particular to a consensus method, device and system based on a blockchain system.
  • Blockchain technology is no exception, but due to the security and real-time requirements of the financial industry , Also put forward higher requirements for technology.
  • it is usually necessary to use multiple nodes to reach a consensus on the block. If the number of nodes reaching a consensus on the block exceeds the preset number, it means that most of the blockchain systems
  • the blocks obtained by the nodes processed by the transactions are consistent; in this way, the block can be successfully produced, and the node can also update the internal transaction database according to the block.
  • the PBFT consensus algorithm is a commonly used consensus algorithm.
  • the PBFT consensus algorithm after each round of block consensus (that is, successful block generation) performed by the blockchain system, the PBFT consensus algorithm can be used from the blockchain A master node is selected from multiple nodes in the system, and the master node is used for block packaging in the next round of block consensus.
  • the master node can obtain transaction data to be processed from the transaction pool, package the original block according to the transaction data to be processed, and send it to other nodes in the blockchain system;
  • each node (including the master node) in the blockchain system can process the transaction based on the original block packaged by the master node to obtain the target block, and then send the target block to other nodes in the blockchain system;
  • Each node can determine the consensus result of the node according to its own target block and the target block of other nodes, and send the consensus result of this node to other nodes, so that each node can compare with other nodes according to its own consensus result
  • the consensus result of determines whether the consensus of each node is successful, if it is, the node can update the block database inside the node, if not, the node may not process it.
  • the communication overhead of the PBFT consensus algorithm is O(n 2 ); where n is Number of nodes. If the number of nodes in the blockchain system is small, the PBFT consensus algorithm can have small communication overhead.
  • each node in the blockchain system may be in a waiting state for a long time, resulting in a low consensus efficiency of the blockchain system.
  • the embodiment of the present invention provides a consensus method based on a blockchain system, which is used to solve the technology of high communication pressure and low consensus efficiency caused by the use of the PBFT consensus algorithm to execute block consensus in a large-scale node blockchain system problem.
  • an embodiment of the present invention provides a consensus method based on a blockchain system.
  • the blockchain system includes an N-level node layer with a hierarchical relationship; wherein each node layer includes at least one node group, Each node group includes a master node and at least one slave node; any two node groups in the same node layer include different nodes; each node in the i-1th node layer is included in the i-th node layer
  • the master node in each node group; each node in the Nth node layer is all the consensus nodes in the blockchain system;
  • the master node of the node group determines the consensus result of the node group according to the consensus state of each node in the node group to the consensus block; if the i Is greater than 1, when the master node participates in the consensus of the i-1th level node layer, the consensus result of the node group is taken as the consensus state of the master node on the block to be agreed; if the If i is equal to 1, the consensus result of the node group in the i-th node layer is taken as the consensus result of the block to be agreed; where i and N are positive integers, and 1 ⁇ i ⁇ N.
  • the consensus process between large-scale nodes can be transformed into the consensus process in each node group. Consensus process between a small number of nodes, thereby greatly reducing communication consumption and communication pressure; and each node only needs to perform the consensus process in the node group to which the node belongs, so that it only needs to wait for other nodes in the node group
  • the sent consensus state can perform the subsequent consensus process, without the need to wait for the consensus state sent by all nodes in the blockchain system to perform the subsequent consensus process, which can greatly reduce the consensus process of each node.
  • the time required has greatly improved the consensus efficiency of the blockchain system.
  • the node group in the first-level node layer is the first node group; the master node in the node group determines the node according to the consensus state of each node in the node group to the consensus block Before the consensus result of the group, the master node of the first node group also generates the block for consensus, and sends the block for consensus to any consensus node in the blockchain system; accordingly, After the consensus result of the node group in the first-level node layer is used as the consensus result of the block to be agreed, the master node of the first node group also sends the consensus result of the block to be consensus to the Any consensus node in the blockchain system.
  • each consensus node by using the master node in the first node group to directly send the consensus results of the to-be-consensus block or the to-be-consensus block to each consensus node in the blockchain system, multiple calls to each of the intermediate node layers can be avoided. Node groups, thereby reducing the pressure on each node group in the middle layer; and, compared to forwarding the consensus results of the waiting block or the waiting block through each node group in the middle node layer, each consensus node can be earlier The consensus result of the block to be consensus or the block to be consensus is received, thereby further improving the consensus efficiency of the blockchain system.
  • the node group in the first-level node layer is the first node group; the master node in the node group determines the consensus state of each node in the node group according to the consensus state of the consensus block to be Before the consensus result of the node group, the master node of the first node group also generates the block to be agreed upon, and sends the block to be agreed upon according to the hierarchical relationship to the node in the Nth level Each node; accordingly, after the consensus result of the node group in the first-level node layer is used as the consensus result of the block to be agreed, the master node of the first node group also divides the The consensus result of the block to be consensus is sent to each node in the Nth node layer.
  • the sending the consensus result of the to-be-consensus block or the to-be-consensus block to each node in the Nth-level node layer according to the hierarchical relationship includes: for the i-1th level For each node group in the node layer, the master node of the node group sends the block to be agreed or the consensus result of the block to be agreed to any slave node in the node group; the node group Any node in sending the block to be agreed or the consensus result of the block to be agreed to any node in the node group where the node in the i-th level node layer is located.
  • the consensus result of the block to be consensus or the block to be consensus is sent to each consensus node in the blockchain system according to the hierarchical relationship, so that each master node only needs to be in the node group to which the master node belongs Synchronize the consensus result of the block to be consensus or the block to be consensus, thereby converting the synchronization process between the master node in the first node group and all consensus nodes in the blockchain system into each master node and its respective node group The synchronization process between the slave nodes, thereby reducing the communication pressure of the master node in the first node group.
  • any node of the node group also processes the block to be agreed upon to obtain the block information of the node for the block to be agreed upon, and compares the block information of the node to the block to be agreed upon.
  • the block information is sent to other nodes in the node group; the nodes of the node group compare the block information of the block to be agreed upon by the node and the other nodes in the node group to the area to be agreed upon.
  • the block information of the block determines the consensus state of the node on the block to be agreed; accordingly, the master node of the first node group sends the consensus result of the block to be agreed to the Nth level
  • any consensus node in the blockchain system also updates the internal preset database of the consensus node according to the consensus result of the block to be consensus.
  • the master node of each node group in the Nth node layer can determine the consensus state of the node group according to the consensus state of other nodes in the node group, and can synchronize it to the upper node layer to which the node group belongs In this way, block consensus is implemented for each node group in each node layer.
  • each node updates directly according to its own block information and the block information of other nodes.
  • the default database can improve the accuracy of consensus results.
  • the Nth level node From the nodes included in each node group in the layer, the master node of each node group in the next round of block consensus is elected; further, each node group in the i-th node layer is used in the next round of block consensus.
  • the master node in the consensus constitutes each node group in the i-1 level node layer, and each node group is elected from the nodes included in each node group in the i-1 level node layer The master node in the next round of block consensus.
  • the nodes included in each node group in the Nth node layer are set unchanged, and after a certain round of block consensus is over, it is reselected from each node group in the next node layer according to the reverse hierarchical relationship
  • the master node composes each node group in the upper node layer, which can ensure that the master node in each node group of each node layer in different rounds of block consensus is different, so that each node in the node group can be rotated as the master Nodes, to ensure the running sequence of the blockchain system.
  • an embodiment of the present invention provides a consensus device based on a blockchain system.
  • the blockchain system includes N-level node layers with hierarchical relationships; wherein each node layer includes at least one node group, Each node group includes a master node and at least one slave node; any two node groups in the same node layer include different nodes; each node in the i-1th node layer is included in the i-th node layer
  • the master node in each node group; each node in the Nth node layer is all the consensus nodes in the blockchain system; for each node group in the i-th node layer, the node group
  • the main nodes include:
  • the determining module is used to determine the consensus result of the node group according to the consensus state of each node in the node group to be a consensus block;
  • a processing module configured to, if the i is greater than 1, when the master node participates in the consensus of the i-1th level node layer, use the consensus result of the node group as the master node's agreement to the pending consensus The consensus state of the block; if the i is equal to 1, the consensus result of the node group in the i-th node layer is taken as the consensus result of the block to be agreed;
  • i and N are positive integers, and 1 ⁇ i ⁇ N.
  • the device when the i is equal to 1, the device further includes a generating module and a transceiver module; the generating module is used to: generate the block to be agreed upon; Before each node in the node group determines the consensus status of the consensus block for the consensus block, the transceiver module is used to: send the consensus block to any consensus in the blockchain system The node or according to the hierarchical relationship sends the block to be agreed to each node in the Nth node layer; accordingly, the processing module sends the consensus result of the node group in the i node layer As the consensus result of the to-be-consensus block, the transceiver module is also used to: send the consensus result of the to-be-consensus block to any consensus node in the blockchain system or send the consensus result according to the hierarchy relationship The block to be agreed is sent to each node in the Nth node layer.
  • the sending the consensus result of the to-be-consensus block or the to-be-consensus block to each node in the Nth-level node layer according to the hierarchical relationship includes: for the i-1th level For each node group in the node layer, the master node of the node group sends the block to be agreed or the consensus result of the block to be agreed to any slave node in the node group; the node group Any node in sending the block to be agreed or the consensus result of the block to be agreed to any node in the node group where the node is located in the i-th level node layer.
  • an embodiment of the present invention provides a blockchain system, which includes N-level node layers with hierarchical relationships; wherein each node layer includes at least one node group, and each node group Includes a master node and at least one slave node; any two node groups in the same node layer include different nodes; each node in the i-1th node layer is in each node group included in the i-th node layer Each node in the Nth node layer is all the consensus nodes in the blockchain system; the node group in the first node layer is the first node group;
  • the first node group is used to generate a consensus block, and send the consensus block to each node in the Nth node layer;
  • Any node group in the Nth level node layer is used to process the block to be agreed, and determine the consensus state of each node in the node group on the block to be agreed;
  • Any node group in the i-th node layer is used to determine the consensus result of the node group according to the consensus state of each node in the node group to the consensus block; if the i is greater than 1, then When the master node of the node group participates in the consensus of the i-1th level node layer, the consensus result of the node group is used as the consensus state of the master node on the block to be agreed; if the i is equal to 1 , The consensus result of the node group in the i-th node layer is taken as the consensus result of the block to be agreed;
  • i and N are positive integers, and 1 ⁇ i ⁇ N.
  • the first node group is also used to: send the consensus result of the block to be consensus to each node in the Nth node layer; accordingly, the Nth node
  • the nodes in the node layer are also used to update the internal preset database of the node according to the consensus result of the block to be agreed.
  • any node group in the i-th node layer is also used to: select the node group from among the nodes included in the node group.
  • the master node in one round of block consensus constitutes each node group in the i-1th level node layer according to the master node of each node group in the Nth level node layer in the next round of block consensus.
  • a computing device provided by an embodiment of the present invention includes at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, The processing unit executes the consensus method based on the blockchain system as described in any of the foregoing first aspect.
  • a computer-readable storage medium provided by an embodiment of the present invention stores a computer program executable by a computing device.
  • the computing device executes Any consensus method based on the blockchain system described in the first aspect.
  • 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
  • Figure 3 is a block consensus method based on a blockchain system provided by an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of the architecture of a blockchain system with a hierarchical structure provided by an embodiment of the present invention
  • FIG. 5 is another representation form of a blockchain system with a hierarchical structure provided by an embodiment of the present invention.
  • FIG. 6 is a schematic diagram of a process corresponding to a block consensus method provided by an embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of a consensus device based on a blockchain system provided by an embodiment of the present invention.
  • the field of financial 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, customers, etc. 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 top of the Transmission Control Protocol (TCP) protocol.
  • TCP Transmission Control Protocol
  • the nodes in the blockchain system can be equal to each other, and there is no central node in the system, so every node can Connect other nodes randomly.
  • each node can be equipped with a preset database, and each node 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 the block, the block height of the block, the timestamp and other information.
  • the block includes transaction data, such as transaction data to be processed in the process of consensus on the block by nodes in the blockchain system and transaction results obtained from processing the transaction data to be processed.
  • 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, etc.
  • 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 on the stack can be obtained from the internal transaction pool for subsequent processing and consensus processes.
  • Figure 2 is a schematic diagram of the corresponding process when using the PBFT consensus algorithm to process transactions.
  • the process of PBFT consensus algorithm processing transactions can be divided into three stages: pre-prepare Phase, prepare phase and commit phase. The following describes the specific implementation process of the three stages.
  • Block consensus can be determined in many ways. For example, if a new historical block is detected in 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 was 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 previous round of block consensus execution fails, the window value v inside each node is incremented (ie, 1). 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 main node
  • h is the current block height
  • 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 passed by consensus on a master node is greater than the preset number, it can 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, just waiting for the next round of block consensus.
  • 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 of 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;
  • 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;
  • the number of the master node determined by the node is 4, and the node 104 is taken as the master node of the next round of block consensus, and the nodes 101, 102, and 103 are taken as the slave nodes of the next round of block
  • the master node of the previous round of block consensus is node 101, 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 1; based on Table 1, it can be seen that the master node of the next round of block consensus can be node 102, and the master node 102 is used to execute Consensus of block 2. Correspondingly, if the node 101 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. In this way, the node 101 (or the node 102 ⁇ Node 104)
  • the number of the master node determined using the above formula is 1, that is, the master node of the next round of block consensus can be node 102, and the master node 102 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 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 prepare package according to the block header and block body of block 2.
  • the master node 101 can send the prepare packet to any node in the blockchain system, that is, node 102, node 103, and node 104. At this point, the pre-prepare phase is over.
  • the master node needs to send prepare packets to all nodes in the blockchain system except the master node. Therefore, the communication overhead corresponding to the pre-prepare phase is (n-1), that is, O(n ).
  • any node in the blockchain system receives the prepare packet sent by the master node 101, it can parse the prepare packet to obtain the transaction data to be processed by the block consensus; in this way, the node can execute the round The transaction data to be processed by the block consensus obtains the transaction result. Further, the node may generate a first hash value according to the transaction result, generate a second hash value according to the receipt information of each transaction, generate a third hash value according to the transaction request message, and then generate a third hash value according to the first hash value, The second hash value and the third hash value generate the hash value of block 2.
  • the node can assemble the hash value of block 2 into the block header of block 2, and assemble the transaction results of the transaction data to be processed in this round of block consensus into the block body of block 2, and use
  • the node’s private key, the block header of block 2 and the block body of block 2 generate the node’s signature package, which can then be sent to other nodes in the blockchain system. So far, the prepare phase End of execution.
  • each node needs to send signature packets to all nodes in the blockchain system except this node, so the communication overhead corresponding to the prepare phase is n*(n-1), that is, O(n 2 ).
  • 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 reaches 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 block 2 (including block header and block body) determined by each other node to process transactions. Further, any node can compare the block 2 determined by the transaction processing by itself with the block 2 determined by the transaction processing by any other node, and if they are the same, it can receive the signature package sent by the other node; if they are different, then The signed package sent by the other node can be rejected.
  • the node may not perform subsequent operations and wait for the operation and maintenance personnel to perform subsequent maintenance.
  • the preset threshold can be set by those skilled in the art based on experience, and is not limited.
  • the preset threshold can be set as
  • 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 block 2 (including block header and zone) determined by each other node to process the transaction. Block); in this way, the node can compare the block 2 determined by the transaction processing by itself with the block 2 determined by the transaction processing by any other node, and if they are the same, it can receive the commit packet sent by the other node, if different , The commit packet sent by the other node can be rejected.
  • the number of commit packets received by the node is less than the preset threshold, it means that the node is an abnormal node.
  • the node may not perform follow-up operations and wait for the operation and maintenance personnel to perform follow-up maintenance; accordingly, if the node receives The number of signature packages received is greater than or equal to the commit package, 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 processing the transaction. In this way, the node can get from the memory Obtain block 2 generated by the node for processing transactions, and write block 2 into the preset database inside the node, thereby completing the round of block consensus. At this point, the commit phase is over.
  • each node needs to send signature packets to all nodes in the blockchain system except this node, so the communication overhead corresponding to the commit phase is n*(n-1), that is, O(n 2 ).
  • the communication overhead required is (n-1)+2n*(n-1), which is O(n 2 ).
  • the system is a block chain block chains large number of nodes of the system, such as the number of nodes is 1000, the reached cost of the communication 106, the very large communication overhead, resulting in a communication system than the pressure block chain
  • each node needs to wait for the signature package or commit package sent by all other nodes in the blockchain system in the prepare phase and the commit phase to perform the subsequent consensus process, which causes the node to wait for a long time. During this time, the node is in a non-working state, resulting in lower processing efficiency of the node and lower consensus efficiency of the blockchain system.
  • the embodiment of the present invention provides a blockchain system to solve the technical problems of high communication pressure and low consensus efficiency caused by the use of the PBFT consensus algorithm to execute block consensus in a large-scale node blockchain system .
  • Fig. 3 is a block consensus method based on a block chain system provided by an embodiment of the present invention, and the method includes:
  • Step 301 before executing each round of block consensus, determine whether the number of nodes in the blockchain system is greater than the preset number, if yes, execute step 302, if not, execute step 304.
  • a monitor can be set in the blockchain system.
  • the monitor can monitor the current block consensus of the blockchain system. If it is monitored that a certain round of block consensus is over, or a new block is monitored A round of block consensus is about to begin, and the number of nodes in the current blockchain system can be obtained. Further, if the number of nodes in the current blockchain system is greater than the preset number, indicating that the blockchain system is a large-scale node blockchain system, step 302 can be performed; if the number of nodes is less than or equal to the preset number, it indicates If the blockchain system is a small-scale node blockchain system, step 304 can be executed.
  • the preset number can be set by those skilled in the art based on experience. Since the PBFT consensus algorithm can better handle the blockchain system with the number of nodes within 100, the preset number can be set to 100.
  • Step 302 Perform hierarchical grouping of nodes in the blockchain system to convert the blockchain system into a hierarchical structure.
  • the consensus nodes in the blockchain system can be divided into N-level (ie, two or more) node layers, and each node layer includes multiple node groups, each The node group includes a master node and multiple slave nodes. The nodes in any two node groups in each node layer are different.
  • the Nth node layer includes all consensus nodes in the blockchain system. The first node layer only The first node group is included; and, for any node group in any node layer, each node in the node group is the master node of the corresponding node group in the next node layer.
  • the master node in the node group may be determined in turn from multiple nodes in the node group by using the PBFT consensus algorithm.
  • the multiple master nodes selected by the second-level node layer are divided into multiple node groups, and multiple node groups are used to form the N-1th level node layer,..., the multiple master nodes selected by the second-level node layer form the first A node group, and use the first node group to form the first-level node layer.
  • multiple nodes can be divided according to a preset threshold to obtain multiple node groups. For example, when the preset threshold is 10, if there are 1000 consensus nodes in the blockchain system, they are consensus node 1 , Consensus node 2, consensus node 3, ..., consensus node 1000, 1000 consensus nodes can be divided into node group 1, node group 2, node group 3, ..., node group 100, and node group 1 includes consensus nodes 1. Consensus node 2, Consensus node 3,..., Consensus node 10.
  • Node group 2 includes consensus node 11, consensus node 12, consensus node 13,..., consensus node 20,..., node group 100 includes consensus node 991 , Consensus node 992, consensus node 993,..., consensus node 1000; node group 1, node group 2, node group 3,..., node group 100 constitute the Nth-level node layer.
  • consensus nodes in the blockchain system, namely, consensus node 1, consensus node 2, consensus node 3, ..., consensus node 995
  • the preset threshold is 10
  • 1000 consensus nodes can be Nodes are divided into node group 1, node group 2, node group 3,..., node group 100
  • node group 1 includes consensus node 1, consensus node 2, consensus node 3,...
  • consensus node 10 node group 2 includes consensus Node 11, consensus node 12, consensus node 13, ..., consensus node 20, ...
  • the node group 100 includes consensus node 991, consensus node 992, consensus node 993, consensus node 994, and consensus node 995.
  • the monitor can monitor the nodes in the blockchain system in real time.
  • the node group in the Nth node layer can always remain unchanged; if the node in the blockchain system is monitored If the node changes, the Nth node layer can be updated according to the change type.
  • the consensus node 1001 can be inserted into any node group from node group 1 to node group 100, or a node group 101 can also be added ,
  • the consensus node 1001 is set as the only node in the node group 101, so that the Nth level node layer includes node group 1 to node group 101; if it is monitored that the consensus node 50 in the blockchain system exits the blockchain, you can Delete the consensus node 50 from the node group 5; if it is monitored that more consensus nodes withdrawn from the blockchain system or more consensus nodes are newly added, so that the consensus node in the blockchain system changes greatly, then Re-divide the current consensus nodes of the blockchain system in the above manner to obtain multiple new node groups, and use multiple new node groups to form the Nth level node layer.
  • the PBFT consensus algorithm can be used to select a master node from each node group of node group 1 to node group 100 , And divide multiple master nodes according to a preset threshold to obtain multiple node groups, and use multiple node groups to form the N-1th level node layer.
  • the master node selected from node group 1 is consensus node 2
  • the master node selected from node group 2 is consensus node 12
  • the master node selected from node group 3 is selected
  • the master node of is the consensus node 22...
  • the master node selected from the node group 100 is the consensus node 992
  • the consensus node 2 the consensus node 12, the consensus node 22,...
  • the consensus node 992 can be divided into nodes Group 110, node group 120, node group 130,..., node group 200
  • node group 110 includes consensus node 2, consensus node 12, consensus node 22, ..., consensus node 92
  • node group 120 includes consensus node 102, consensus Node 112, consensus node 122, ..., consensus node 192, ...
  • node group 200 includes consensus node 902, consensus node 912, consensus node 922, ..., consensus node 992;
  • node group 110, node group 120, node group 130,..., the node group 200 constitutes the N
  • the greater the number of consensus nodes in the blockchain system the more levels of the node layer, constituting the N-2 level node layer, the N-3 level node layer,..., the second level node layer
  • the process of the first-level node layer can be implemented by referring to the process of forming the N-1th-level node layer, which will not be repeated here.
  • the number of node groups in the Nth level node layer and the nodes in each node group will not change; however, because the upper level node The layer is composed of the master node in the next node layer.
  • the PBFT consensus algorithm will change the master node of each node group in the Nth node layer before each round of block consensus. Therefore, each round of block consensus corresponds to The node groups in the N-1 level node layer to the first level node layer are different from the node groups in the N-1 level node layer to the first level node layer corresponding to the previous round of block consensus.
  • each level of node layer can be divided into multiple corresponding node groups using the same division method, or it can be divided into multiple corresponding node groups using different division methods, and the same preset can be used
  • Nodes are divided by threshold to obtain multiple node groups, or nodes may be divided by different preset thresholds to obtain multiple node groups, or nodes may be divided by random numbers to obtain multiple node groups, which is not specifically limited.
  • FIG. 4 is a schematic diagram of the architecture of a blockchain system with a hierarchical structure provided by an embodiment of the present invention.
  • the blockchain system may include a first-level node layer, a second-level node layer, and a third-level node layer.
  • Level node layer, the third level node layer includes all consensus nodes in the blockchain system, namely node 1, node 2, node 3, ..., node 1000.
  • nodes 1 to 1000 are divided according to a preset threshold of 10 to obtain node group a 3,1 , node group a 3,2 , node group a 3,3 ,..., node group a 3,100 ,
  • Node group a 3,1 includes node 1, node 2, node 3,..., node 10,
  • node group a 3,2 includes node 11, node 12, node 13,..., node 20,...
  • node group a 3,100 includes node 991, node 992, node 993, ..., node 1000.
  • the master node in node group a 3,1 (the node corresponding to the thick circle) is node 1, and the master node in node group a 3,2 is Node 11,..., the primary node in node group a 3,100 is node 991, then in the second-level node layer, node 1, node 11,..., node 991 are divided according to the preset threshold of 10, and node group a is obtained 2,1 , node group a 2,2 , node group a 2,3 ,..., node group a 2,10 , node group a 2,1 includes node 1, node 11, node 21,..., node 91,
  • the node group a 2,2 includes the node 101, the node 111, the node 121,..., the node 191,..., and the node group a 2,10 includes the node 901, the node 911, the node 921,..., the node 991.
  • a 2,1 node group of the node 11 is the master node
  • node group in a 2,2 master node is node 111, «, node group a 2
  • the master node in 10 is node 911, and in the first-level node layer, node 11, node 111, ..., node 911 constitute a node group a 1 .
  • the number of levels (or the number of layers) N of the node layer in the blockchain system can be:
  • n is the number of consensus nodes in the blockchain system.
  • the number of node groups g N in the Nth node layer can be:
  • the number g i of node groups in the i-th node layer can be:
  • g i+1 is the number of node groups in the i+1 level node layer.
  • Figure 5 is another representation of the hierarchical structure of the blockchain system.
  • Figure 5 only illustrates the second-level node layer And the composition of each node group in the first-level node layer.
  • each node in the first-level node layer is located in the node group of the first-level node layer and the second-level node layer at the same time.
  • node 1 in the first-level node layer is located in the node group a 1 at the same time.
  • the node 101 in the first-level node layer is located in the node group a 1 and the node group a 2,2 at the same time, ..., the node 901 in the first-level node layer is located in the node group a at the same time 1 and node group a 2 , 10.
  • each node in the first-level node layer is located in the node group of the first-level node layer, the second-level node layer, and the third-level node layer at the same time, Among the nodes of the second-level node layer, nodes other than the nodes in the first-level node layer are located in the node groups of the second-level node layer and the third-level node layer at the same time.
  • Step 303 Execute each round of block consensus according to the hierarchical structure of the blockchain system.
  • a master node different from the previous round of block consensus can be selected from each node group of the Nth level of node layer, and the selected master node from the Nth level of node layer Multiple master nodes form each node group of the N-1 level node layer; then the master node can be selected from each node group of the N-1 level node layer, and use to select from the N-1 level node layer A plurality of master nodes form each node group of the N-2th level node layer, and each node group in the upper level node layer is constructed in this way until the first node group in the first level node layer is constructed. In this way, the construction of the blockchain hierarchy corresponding to this round of block consensus is completed, and the subsequent round of block consensus can be executed based on the blockchain hierarchy.
  • Step 304 Use the PBFT consensus algorithm to execute this round of block consensus.
  • the number of consensus nodes in the blockchain system is less than the preset number, it means that the current blockchain system is a small-scale node blockchain system, that is, the communication pressure of using the PBFT consensus algorithm to process this round of block consensus is not great; therefore; , You can directly use the PBFT consensus algorithm to execute this round of block consensus, the specific implementation can be referred to as shown in Figure 2, and will not be repeated.
  • Fig. 6 is a schematic diagram of a process corresponding to a block consensus method provided by an embodiment of the present invention, and the method includes:
  • step 601 the master node of the first node group in the first-level node layer packs the block to obtain the block to be consensus, and synchronizes it to the slave node of the first node group in the first-level node layer.
  • each consensus node in the blockchain system can be the node where the consensus node is located.
  • the group, the level to which the node group belongs, and the identifiers of other nodes included in the node group are stored in the memory of the consensus node; so, if the consensus node needs to synchronize information in the node group where the consensus node is located, then The identities of other nodes included in the node group can be obtained from the memory of the consensus node, so as to synchronize the information to other nodes.
  • Table 2 is a schematic table of a possible correspondence table provided by an embodiment of the present invention.
  • Table 2 Schematic of a correspondence table
  • the correspondence table of node 111 can store the node group where node 111 is located in each node layer and other nodes in the node group where node 111 is located.
  • node 111 is a node in the first node layer.
  • group a 1 a node group a 1 in addition includes a node group 111, it also may include a node 11, node 211, node 311, node 411, node 511, node 611, node 711, node 811, node 911; accordingly, The node 111 is in the node group a 2,2 of the second-level node layer.
  • the node group a 2,2 may also include node 101, node 121, node 131, node 141, node 151, node 161. Node 171, node 181, node 191; node 111 is in the node group a 3,12 of the third-level node layer.
  • node group a 3,12 may also include node 112 and node 113 , Node 114, node 115, node 116, node 117, node 118, node 119, node 120.
  • the correspondence table of each node in the first-level node layer may include the node in the first-level node layer and the second-level node.
  • the node group in the third-level node layer and the other nodes included in the node group; the corresponding relationship table of each node in the second-level node layer except the node in the first-level node layer can contain this
  • the node is located in the second-level node layer and the third-level node layer in the node group and other nodes included in the node group; each node in the third-level node layer except the node in the second-level node layer
  • the correspondence table may include the node group where the node is located in the third-level node layer and other nodes included in the node group where it is located.
  • the embodiment of the present invention refers to the node group in the first-level node layer as the first node group.
  • the master node of the first node group can obtain the transaction data to be processed in the current round of block consensus from the internal transaction pool, and can follow Package block of transaction data to be processed. Based on FIG. 4, since the first node group is the node group a 1 , and the master node of the node group a 1 in the current round of block consensus is the node 111, the master node 111 can execute the process of packaging the block.
  • the master node of the first node group can package the block according to steps 1 to 3:
  • Step 1 Obtain the block height of the largest historical block and the hash value of the largest historical block from the historical blocks cached in the memory, and set the block height of the block to be consensus according to the block height of the largest historical block;
  • Step 2 Use the current timestamp, the block height of the block to be consensus and the hash value of the largest block in history to assemble the block header of the block to be consensus, and use the transaction data to be processed in the current round of block consensus to assemble the block to be consensus The block body.
  • Step 3 Write the block header of the block to be agreed and the block body of the block to be agreed into the corresponding positions of the prepare package respectively to generate the prepare package.
  • step 602 the master node of the node group in the first-level node layer transmits the block to be consensus to any node in the Nth-level node layer.
  • the master node of the first node group can transmit the prepare packet to any node in the Nth node layer in multiple ways. Two possible transmission methods are described below:
  • the master node of the first node group can transmit the prepare packet to any node in the Nth node layer according to the hierarchical structure corresponding to the current round of block consensus. Specifically, the first node group The master node can first send the prepare packet to any slave node in the first node group, and then any slave node sends the prepare packet to any slave node in the node group where the slave node is located in the next node layer Nodes until there is no next node level.
  • the master node 111 determines that the master node 111 is in the node group a 1 of the first-level node layer by querying the correspondence table shown in Table 2, so that the prepare package can be synchronized to the node group a 1 from any of a node, i.e.
  • node 11 determines that node 11 is in node group a 2,1 of the second-level node layer by querying the correspondence table stored inside, so that node 11 can synchronize the prepare packet to node group a 2,1 Any slave node of node 1, node 21, node 31, node 41, node 51, node 61, node 71, node 81, and node 91; further, for any node in node group a 2,1 (Such as node 1), node 1 determines that node 1 is in the node group a 3,1 of the third-level node layer by querying the internally stored correspondence table, so that node 1 can synchronize the prepare packet to any of node group a 31 One slave node, namely node 2, node 3, node 4,
  • the consensus result of the block to be consensus or the block to be consensus is sent to each consensus node in the blockchain system according to the hierarchical relationship, so that each master node only needs to be in the node group to which the master node belongs Synchronize the consensus result of the block to be consensus or the block to be consensus, thereby transforming the synchronization process between the master node in the first node group and all the consensus nodes in the blockchain system into each master node and its respective node group
  • the synchronization process between the slave nodes in the first node group reduces the communication pressure of the master node in the first node group.
  • the master node of the first node group can directly send the prepare package to the blockchain after generating the prepare package All the consensus nodes in the system, such as the master node 111, directly send the prepare packet to nodes 1 to 110 and nodes 112 to 1000.
  • the master node in the first node group to directly send the consensus block to each consensus node in the blockchain system, it is possible to avoid multiple calls to each node group in the intermediate node layer, thereby reducing intermediate nodes.
  • the pressure of each node group in the layer; and, compared to the forwarding of the consensus block through each node group in the intermediate node layer, each consensus node can receive the consensus block earlier, thereby further improving the blockchain system Consensus efficiency.
  • step 603 the master node of any node group in the Nth node layer determines the consensus result of the node group according to the consensus state of each node in the node group to the consensus block.
  • the node can first verify the legality of the prepare package after determining that the prepare package reaches the node. If it is determined that the prepare package is legal, then You can receive the prepare package; if it is determined that the prepare package is illegal, you can refuse to receive the prepare package, and you can send alarm information to the user, for example, you can push the alarm information to the user through WeChat, Dingding, email, etc.
  • the specific process of legality verification can be as follows: the node parses the prepare package to obtain the current timestamp corresponding to the current round of block consensus, the block height of the block to be consensus, the hash value of the largest historical block, and the current round of block consensus. Process the transaction data and query the historical block cached inside the node to determine the block height and hash value of the largest historical block corresponding to the node.
  • the prepare package is determined to be legal; correspondingly, if it is determined that the block height of the block to be consensus is greater than the block height of the largest historical block corresponding to the node plus one, it means that the block to be consensus is a historical block that has been agreed upon, or if Make sure that the block height of the block to be consensus is less than the block height of the largest historical block corresponding to the node plus one, indicating that the block cached inside the node lags behind other nodes, or the hash value of the largest historical block corresponding to the current round of block consensus If it is not equal to the hash value of the largest historical block corresponding to the node, the node can determine that the prepare package is illegal. By verifying the legality of the prepare package
  • the node can process the transaction data to be processed in the current round of block consensus to obtain the transaction result, and can determine the hash value of the block to be consensus based on the transaction data, transaction result, and receipt of each transaction; in this way, the node can Use transaction data and transaction results to assemble the block body of the block to be consensus, and use the hash value of the block to be consensus, the block height of the block to be consensus, the current timestamp and the hash value of the largest historical block to assemble the consensus
  • the block header of the block, and the node's private key, the updated block header of the block to be consensus and the block body of the block to be consensus can be used to generate the signature package corresponding to the node, and then the correspondence table within the node can be inquired Determine the node group where the node is in the Nth node layer, and send the signature packet corresponding to the node to any node in the node group where the node is in the Nth node layer.
  • the node can first use any node after determining that the signature package corresponding to any node in the node group reaches the node Parses the signature package corresponding to any node, and verifies the legality of the information obtained by analyzing the signature package corresponding to any node based on its own signature package. If it is determined that the signature package corresponding to any node If it is legal, the signature package corresponding to any node can be received; if it is determined that the signature package corresponding to any node is illegal, it can refuse to receive the signature package corresponding to any node.
  • the process of verifying the legality of the signed package can be implemented by referring to the process of verifying the legality of the prepare package. The difference is that when verifying the legality of the signed package, the transaction processing result and the hash value of the consensus block need to be verified. .
  • each node can only store the public keys of other nodes in the node group where the node is located, instead of storing the public keys of all consensus nodes in the blockchain system, thereby reducing the amount of public keys occupied by the nodes.
  • Resources for example, because node 1 is only in node group a 3,1 , node 1 can only store the public keys of nodes 2-10.
  • the public keys of other nodes can be sent by the monitor to each node according to the hierarchical grouping in each round of block consensus, or the nodes can also be sent from the blockchain according to the hierarchical grouping in each round of block consensus. It can be obtained from the public database of the system, and the details are not limited.
  • the node can count the number of successfully received signature packets. If the number of successfully received signature packets is less than the preset number, it means that The consensus block generated by the node is different from most nodes in the node group. The transaction result processed by the node is faulty, so the node does not need to do any processing; accordingly, if the number of successfully received signature packets is greater than or equal to the expected If the number is set, it means that the consensus block generated by the node is the same as most nodes in the node group, and the transaction result processed by the node is normal. Therefore, the node can generate the commit corresponding to the node according to the consensus block corresponding to the node.
  • Packet, and the commit packet corresponding to the node can be sent to any node in the node group where the node is in the Nth node layer.
  • the preset number can be set by those skilled in the art based on experience, for example, Among them, n is the number of nodes in the blockchain system.
  • the node can first use any node after determining that the commit packet corresponding to any node in the node group reaches the node
  • the process of verifying the legality of the commit package can be implemented with reference to the process of verifying the legality of the signature package, and will not be repeated.
  • the node can count the number of commit packets that have been successfully received. If the number of commit packets that have been successfully received is less than the preset number, it indicates that The consensus result of the node is different from the consensus result of most nodes in the node group. The consensus process of the node is faulty, so the node can do nothing; accordingly, if the number of successfully received commit packets is greater than or equal to the preset The number indicates that the consensus result of the node is the same as the consensus result of most nodes in the node group where it is located. The consensus process of the node is normal, so the node can update the state to the pending state.
  • the master node of the node group can determine the number of nodes in the node group that are in the pending state according to the state of each node in the node group. If the number of nodes is greater than or equal to the preset number, the master node of the node group can generate a commit_t packet based on the block to be agreed upon; where t is the identifier of the node group, and the commit_t packet is used to indicate that the node group treats the consensus area The consensus result of the block.
  • the master node 1 of the node group a 3,1 can generate the commit_a 3,1 package, and the commit_a 3,1 can be based on the private key of the master node 1, and the block header and pending consensus block generated by the master node 1.
  • the block body of the consensus block is generated.
  • the master node of the node group may not perform any processing. It should be noted that if the master node in a certain node group fails to receive the preset number of signature packets, or fails to receive the preset number of commit packets, it means that the consensus process of the master node is incorrect. Therefore, the master node No processing is required, that is, no commit_t package may be generated.
  • Step 604 When the j-th node layer is not the first-level node layer, the master node of any node group in the j-th node layer sends the consensus result of the node group to the master node in the j-1th node layer. Any node in the node group where the node is located.
  • the master node of the node group can query the internal correspondence table of the master node. Determine the node group where the master node is in the N-1 level node layer, and send the commit_t packet corresponding to the master node to any of the node groups where the master node is in the N-1 level node layer Slave node.
  • the master node 11 of the node group a 3, 2 in the third-level node layer can query the internal correspondence table of the master node 11 to determine that the master node 11 is in the node group a 2,1 of the second-level node layer.
  • commit_a 3,2 can be synchronized to any slave node in the node group a 2,1 , namely, node 1, node 21, node 31, node 41, node 51, node 61, node 71, node 81, and node 91.
  • step 605 the master node of any node group in the j-1 level node layer determines the consensus result of the node group according to the consensus state of each node in the node group to the consensus block.
  • the node can first use the other node after determining that the commit_t packet corresponding to any other node in the node group reaches the node.
  • the public key of any node parses the commit_t packet corresponding to any other node, and then uses the generated commit_t packet to verify the validity of the commit_t packet corresponding to any other node. If the verification is legal, the node can receive If the commit_t packet corresponding to any other node is not legally verified, the node may refuse to receive the commit_t packet corresponding to any other node.
  • node 31 of node group a 2, 1 in the second-level node layer determines any of node 1, node 11, node 21, node 41, node 51, node 61, node 71, node 81, and node 91.
  • a node (such as node 1) sends a commit_t packet (ie, commit_a 3,1 packet) to node 31, it can use the public key of node 1 to parse the commit_a 3,1 packet, and use the commit_a 3,2 packet generated by it to commit_a
  • the 3,1 packet is validated; if it is verified that the commit_a 3,1 packet is legal, the node 31 can receive the commit_a 3,1 packet sent by the node 1, and if the commit_a 3,1 packet is verified to be illegal, the node 31 can refuse to receive the node 1 commit_a 3,1 packet sent.
  • any node in any node group in the j-1th level node layer determines that the number of commit_t packets received is greater than the preset number, the status of the node can be updated to the pending submission state; accordingly, the After the master node in the node group determines that there are a preset number of nodes in the node group to be submitted, it can generate the commit_t packet corresponding to the node group according to its corresponding block to be agreed, and the commit_t packet corresponding to the node group is used To instruct the node group to treat the consensus result of the consensus block.
  • the node can update the status of the node according to the identity of the node group, that is, the state of the node can include both the pending state and the identity of the corresponding node group; for example, node 1 is in node group a 1, 1 and node group a at the same time In 2,1 , node 1 corresponds to a state corresponding to node group a 1,1 and a state corresponding to node group a 2,1 , thereby avoiding mutual interference between the states of the same node in different node groups.
  • Step 606 Determine whether the j-1th level node layer is the first level node layer, if not, execute step 604, and if yes, execute step 607.
  • the master node in the node group queries the internal correspondence table to determine that there is no upper-level node layer that contains the master node, then It can be determined that the j-1th level node layer is the first-level node layer; if the master node in the node group queries the internal correspondence table to determine that there is an upper-level node layer that contains the master node, then the j-1th level can be determined The node layer is not the first-level node layer.
  • step 607 the consensus result of the first node group for the consensus block is taken as the consensus result of the to-be-consensus block, and the consensus result of the to-be-consensus block is transmitted to any node in the Nth node layer.
  • the master node of the first node group can use the consensus result of the first node group to be the consensus result of the block to be consensus, and can take the consensus result of the block to be consensus
  • the consensus result of the block is transmitted to any node in the Nth node layer; among them, the master node of the first node group can transmit the consensus result of the block to be consensus in the two ways of transmitting the block to be agreed in step 602,
  • the consensus result of the block to be consensus can also be transmitted in other ways, which is not limited.
  • the consensus result of the block to be consensus is transmitted through the hierarchical result, it is for any node group in any node layer, and each node in the node group is receiving the consensus result of the block to be agreed.
  • the consensus result of the consensus block can be verified before. If the verification is legal, the consensus result of the consensus block can be synchronized to any node in the node layer where the node is located in the next node layer. If it is legal, the node can do nothing.
  • the master node of the first node group directly sends the consensus result of the block to be consensus to any node in the Nth level node layer, then any node in the Nth level node layer is receiving the consensus block
  • the consensus result of the consensus block can be verified before the consensus result of the consensus block. If the verification is legal, the consensus result of the block to be consensus can be received. If the verification is not legal, the node can do nothing.
  • step 608 after receiving the consensus result of the block to be agreed upon, the node in the Nth level of node layer updates the preset database with the consensus result of the block to be agreed upon, this round of consensus ends, and the next round of consensus is started.
  • any node in the Nth level node layer receives the consensus result of the block to be consensus, it can use the consensus result of the block to be consensus to update the internal preset database of the node, for example, first parse the consensus to be The consensus result of the block is the block to be consensus, then the block header and block body of the block to be consensus are added to the preset database, and finally the block header of the block to be consensus is added to the memory cache as the largest block in history .
  • each node directly updates the preset database according to its own block information and the block information of other nodes, which can improve the accuracy of the consensus result.
  • the consensus results of the blocks to be agreed in steps 606 to 608 may all exist in the form of commit packets.
  • the master node of each node group in the next round of block consensus can be selected from the nodes included in each node group in the Nth level node layer, and The master node of each node group in the N-1 level node layer in the next round of block consensus can be used to form each node group in the N-1 level node layer; if the N-1 level node layer is not the first level For the node layer, the master node of each node group in the next round of block consensus can be selected from the nodes included in each node group in the N-1th level node layer, and the N-1th level node layer can be used The master node of each node group in the next round of block consensus constitutes each node group in the N-2
  • the nodes included in each node group in the Nth-level node layer are set unchanged. After a certain round of block consensus ends, the nodes in the next-level node layer are re-created from each node group according to the reverse hierarchical relationship. Selecting the master node to form each node group in the upper node layer can ensure that the master node in each node group of each node layer in different rounds of block consensus is different, so that each node in the node group can be rotated.
  • the master node guarantees the running sequence of the blockchain system.
  • the blockchain system includes N-level node layers with hierarchical relationships, each node layer includes at least one node group, and each node group includes a master node and at least one slave node; the same level Any two node groups in the node layer include different nodes, each node in the i-1th level node layer is the master node in each node group included in the i-th level node layer, and each node in the Nth level node layer All consensus nodes in the blockchain system; for each node group in the i-th node layer, the master node of the node group determines the consensus of the node group according to the consensus state of each node in the node group to the consensus block As a result, if i is greater than 1, when the master node participates in the consensus of the i-1th level node layer, the consensus result of the node group is regarded as the consensus state of the master node for the consensus block; if i is equal to 1, then The consensus result of the node group
  • the consensus process between large-scale nodes can be transformed into each node group Consensus process between a small number of nodes, thereby greatly reducing communication consumption and communication pressure; and, each node only needs to perform the consensus process in the node group to which the node belongs, so that it only needs to wait for other nodes in the node group.
  • the consensus state sent by the node can perform the subsequent consensus process, without the need to wait for the consensus state sent by all nodes in the blockchain system to perform the subsequent consensus process, which can greatly reduce the consensus of each node.
  • the time required for the process has greatly improved the consensus efficiency of the blockchain system.
  • the step number shown in FIG. 6 is only an example of the execution process, and does not constitute a limitation on the order of execution of each step.
  • the embodiment of the present invention also provides a consensus device based on the blockchain system, and the specific content of the device can be implemented with reference to the foregoing method.
  • FIG. 7 is a schematic structural diagram of a consensus device based on a blockchain system provided by an embodiment of the present invention.
  • the blockchain system includes an N-level node layer with a hierarchical relationship; wherein each node layer includes at least one node Group, each node group includes a master node and at least one slave node; any two node groups in the same node layer include different nodes; each node in the i-1th node layer is the i-th node layer The master node in each node group included; each node in the Nth level node layer is all the consensus nodes in the blockchain system;
  • the master node in the node group includes:
  • the determining module 701 is configured to determine the consensus result of the node group according to the consensus state of each node in the node group to be a consensus block;
  • the processing module 702 is configured to, if the i is greater than 1, when the master node participates in the consensus of the i-1th level node layer, use the consensus result of the node group as the master node's response to the waiting The consensus state of the consensus block; if the i is equal to 1, the consensus result of the node group in the i-th node layer is taken as the consensus result of the block to be agreed;
  • i and N are positive integers, and 1 ⁇ i ⁇ N.
  • the device when the i is equal to 1, the device further includes a generating module 703 and a transceiver module 704;
  • the generating module 703 is used for generating the block to be agreed upon;
  • the transceiver module 704 is configured to: send the block to be consensus to the Any consensus node in the blockchain system or according to the hierarchical relationship sends the block to be agreed upon to each node in the Nth node layer;
  • the processing module 702 takes the consensus result of the node group in the i-th node layer as the consensus result of the block to be agreed, and the transceiver module 704 is also used to: Send to any consensus node in the blockchain system or send the block to be agreed to each node in the Nth node layer in accordance with the hierarchical relationship; wherein, according to the hierarchical relationship Sending the block to be agreed or the consensus result of the block to be agreed to each node in the Nth node layer includes:
  • the master node of the node group For each node group in the i-1th level node layer, the master node of the node group sends the block to be agreed or the consensus result of the block to be agreed to any of the node groups A slave node; any node in the node group sends the block to be agreed or the consensus result of the block to be agreed to any node in the node group in the i-th level node layer where the node is located .
  • the blockchain system includes N-level node layers with hierarchical relationships, each node layer includes at least one node group, and each node group includes a master node and At least one slave node; any two node groups in the same node layer include different nodes, each node in the i-1th node layer is the master node in each node group included in the i-th node layer, and the Nth node
  • Each node in the level node layer is all the consensus nodes in the blockchain system; for each node group in the i-th level node layer, the master node of the node group treats the consensus of the consensus block according to each node in the node group The state determines the consensus result of the node group.
  • the consensus result of the node group is regarded as the consensus state of the master node for the consensus block; If i is equal to 1, then the consensus result of the node group is regarded as the consensus result of the block to be agreed; where i and N are positive integers, and 1 ⁇ i ⁇ N.
  • the consensus process between large-scale nodes can be transformed into each node group Consensus process between a small number of nodes, thereby greatly reducing communication consumption and communication pressure; and, each node only needs to perform the consensus process in the node group to which the node belongs, so that it only needs to wait for other nodes in the node group.
  • the consensus state sent by the node can perform the subsequent consensus process, without the need to wait for the consensus state sent by all nodes in the blockchain system to perform the subsequent consensus process, which can greatly reduce the consensus of each node.
  • the time required for the process has greatly improved the consensus efficiency of the blockchain system.
  • embodiments of the present invention also provide a computing device, including at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, The processing unit is caused to execute the consensus method based on the blockchain system described in any of the above-mentioned FIGS.
  • embodiments of the present invention also provide a computer-readable storage medium that stores a computer program executable by a computing device, and when the program runs on the computing device, the computing device executes the foregoing The consensus method based on the blockchain system described in any of Figures 3 to 6.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • Development Economics (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)
  • Computer And Data Communications (AREA)

Abstract

本发明实施例公开了一种基于区块链***的共识方法、装置及***,方法包括:针对第i级节点层中的每个节点组,该节点组中的主节点根据该节点组中各节点的共识状态确定该节点组的共识结果,若i大于1,则在第i-1级节点层进行共识时,将该节点组的共识结果作为该主节点对待共识区块的共识状态;若i等于1,则将该节点组的共识结果作为待共识区块的共识结果。本发明实施例中,在大规模节点的区块链***中,通过对区块链***中的大规模节点进行分层分组,可以将大规模节点之间的共识过程转化为每个节点组内的少量节点之间的共识过程,从而减小通信压力,并可以减少每个节点的共识过程所需的时间,使得区块链***的共识效率得到提升。

Description

一种基于区块链***的共识方法、装置及***
相关申请的交叉引用
本申请要求在2019年08月20日提交中国专利局、申请号为201910770124.0、申请名称为“一种基于区块链***的共识方法、装置及***”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及金融科技(Fintech)技术领域,尤其涉及一种基于区块链***的共识方法、装置及***。
背景技术
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,区块链技术也不例外,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。在区块链***中,为了保证交易执行的准确性,通常需要使用多个节点对区块进行共识,若对区块达成共识的节点数量超过预设数量,则说明区块链***中大多数的节点处理交易所得到的区块是一致的;如此,该区块可以成功出块,且节点也可以根据该区块更新内部的交易数据库。
PBFT共识算法是现有较为常用的一种共识算法,在PBFT共识算法中,当区块链***每执行完一轮区块共识(即成功出块)后,PBFT共识算法均可以从区块链***的多个节点中选取出一个主节点,主节点用于在下一轮区块共识中进行区块打包。具体地说,在下一轮区块共识中,主节点可以从交易池中获取待处理的交易数据,并根据待处理的交易数据打包生成原始区块后发送给区块链***中的其它节点;相应地,区块链***中的每个节点(包括主节点)可以基于主节点打包的原始区块处理交易得到目标区块,进而将目标区块发送给区块链***中的其它节点;如此,每个节点可以根据自己的目标区块和其它节点的目标区块确定该节点的共识结果,并将该节点的共识结果发送给其它节点,以使每个节点根据自己的共识结果和其它节点的共识结果确定每个节点是否共识成功,若是,则节点可以更新节点内部的区块数据库,若否,则节点可以不作处理。
显然地,在PBFT共识算法中,由于每个节点均需要与区块链***中除该节点以外的全部节点进行通信共识,因此PBFT共识算法的通信开销为O(n 2);其中,n为节点数。若区块链***中的节点数量较少,则PBFT共识算法可以具有较小的通信开销,然而,若区块链***中的节点数量较大,比如数千个节点,则PBFT共识算法需要非常大的通信开销,导致区块链***的通信压力较大;且,每个节点只有在接收到除该节点以外的全部节点发送的目标区块(或共识结果)后方可执行后续的共识过程(比如确定共识结果,或更新预 设数据库),因此区块链***中的每个节点均可能在长时间内处于等待状态,导致区块链***的共识效率较低。
综上,目前亟需一种基于区块链***的共识方法,用以解决在大规模节点的区块链***中使用PBFT共识算法执行区块共识所导致的通信压力大、共识效率低的技术问题。
发明内容
本发明实施例提供的一种基于区块链***的共识方法,用以解决在大规模节点的区块链***中使用PBFT共识算法执行区块共识所导致的通信压力大、共识效率低的技术问题。
第一方面,本发明实施例提供的一种基于区块链***的共识方法,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;
针对所述第i级节点层中的每个节点组,所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;若所述i大于1,则在所述主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;其中,i、N为正整数,1≤i≤N。
在上述设计中,在大规模节点的区块链***中,通过对区块链***中的大规模节点进行分层分组,可以将大规模节点之间的共识过程转化为每个节点组内的少量节点之间的共识过程,从而极大地降低通信消耗,减小通信压力;且,每个节点只需在该节点所属的节点组中进行共识过程,从而只需等待本节点组中的其他节点发送的共识状态即可执行后续的共识过程,而无需像现有技术需要等待区块链***中的全部节点发送的共识状态方可执行后续的共识过程,从而可以大大减少每个节点的共识过程所需的时间,使得区块链***的共识效率得到较大提升。
在一种可能的设计中,第1级节点层中的节点组为第一节点组;在所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,所述第一节点组的主节点还生成所述待共识区块,并将所述待共识区块发送给所述区块链***中的任一共识节点;相应地,所述将第1级节点层中节点组的共识结果作为所述待共识区块的共识结果之后,所述第一节点组的主节点还将所述待共识区块的共识结果发送给所述区块链***中的任一共识节点。
在上述设计中,通过使用第一节点组中的主节点直接向区块链***中的各个共识节点发送待共识区块或待共识区块的共识结果,可以避免多次调用中间节点层的各个节点组,从而降低中间层的各个节点组的压力;且,相比于通过中间节点层的各个节点组转发待共识区块或待共识区块的共识结果来说,各个共识节点可以更早地接收到待共识区块或待共识区块的共识结果,从而进一步提高区块链***的共识效率。
在一种可能的设计中,所述第1级节点层中的节点组为第一节点组;在所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,所述第一节点组的主节点还生成所述待共识区块,并按所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;相应地,所述将第1级节点层中节点组的共识结果作为所述待共识区块的共识结果之后,所述第一节点组的主节点还按所述层级关系将所述待共识区块的共识结果发送给所述第N级节点层中的各节点。其中,所述按所述层级关系将所述待共识区块或所述待共识区块的共识结果发送给所述第N级节点层中的各节点,包括:针对所述第i-1级节点层中的每个节点组,所述节点组的主节点将所述待共识区块或所述待共识区块的共识结果发送给所述节点组中的任一从节点;所述节点组中的任一节点将所述待共识区块或所述待共识区块的共识结果发送给所述第i级节点层中所述节点所在的节点组中的任一节点。
在上述设计中,通过按照层级关系将待共识区块或待共识区块的共识结果发送给区块链***中的各个共识节点,使得每个主节点只需在该主节点所属的节点组中同步待共识区块或待共识区块的共识结果,从而将第一节点组中的主节点与区块链***中的全部共识节点之间的同步过程转化为每个主节点与各自节点组中的从节点之间的同步过程,从而降低第一节点组中的主节点的通信压力。
在一种可能的设计中,所述第一节点组的主节点将所述待共识区块发送给所述第N级节点层中的各节点后,针对于所述第N级节点层中的每个节点组,所述节点组的任一节点还处理所述待共识区块得到所述节点对所述待共识区块的区块信息,并将所述节点对所述待共识区块的区块信息发送给所述节点组中的其它节点;所述节点组的节点根据所述节点对所述待共识区块的区块信息与所述节点组中的其它节点对所述待共识区块的区块信息,确定所述节点对所述待共识区块的共识状态;相应地,所述第一节点组的主节点将所述待共识区块的共识结果发送给所述第N级节点层中的各节点之后,所述区块链***中的任一共识节点还根据所述待共识区块的共识结果更新所述共识节点内部的预设数据库。
在上述设计中,第N级节点层中每个节点组的主节点可以根据节点组中其它节点的共识状态确定节点组的共识状态,并可以同步给该节点组所属的上一级节点层中的任一节点,从而实现了对每级节点层中的每个节点组均执行区块共识,相比于现有技术中每个节点根据自己的区块信息和其它节点的区块信息直接更新预设数据库来说,可以提高共识结果的准确性。
在一种可能的设计中,在所述区块链***中的任一共识节点根据所述待共识区块的共识结果更新所述共识节点内部的预设数据库之后,从所述第N级节点层中每个节点组包括的各节点中选举出所述每个节点组在下一轮区块共识中的主节点;进一步地,使用所述第i级节点层中各节点组在下一轮区块共识中的主节点构成所述第i-1级节点层中的各节点组,并从所述第i-1级节点层中每个节点组包括的各节点中选举出所述每个节点组在下一轮区块共识中的主节点。
在上述设计中,设置第N级节点层中各节点组所包括的节点不变,在某一轮区块共识 结束后,根据反向层级关系从下一级节点层的各个节点组中重新选取主节点组成上一级节点层中的各个节点组,可以保证不同轮区块共识中每级节点层的每个节点组中的主节点均不同,从而可以实现节点组中的各个节点轮换作主节点,保证区块链***的运行顺序。
第二方面,本发明实施例提供的一种基于区块链***的共识装置,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;针对所述第i级节点层中的每个节点组,所述节点组中的主节点包括:
确定模块,用于根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;
处理模块,用于若所述i大于1,则在所述主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;
其中,i、N为正整数,1≤i≤N。
在一种可能的实现方式中,在所述i等于1时,所述装置还包括生成模块和收发模块;所述生成模块用于:生成所述待共识区块;在所述确定模块根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,所述收发模块用于:将所述待共识区块发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;相应地,在所述处理模块将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果,所述收发模块还用于:将所述待共识区块的共识结果发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点。其中,所述按所述层级关系将所述待共识区块或所述待共识区块的共识结果发送给所述第N级节点层中的各节点,包括:针对所述第i-1级节点层中的每个节点组,所述节点组的主节点将所述待共识区块或所述待共识区块的共识结果发送给所述节点组中的任一从节点;所述节点组中的任一节点将所述待共识区块或所述待共识区块的共识结果发送给第i级节点层中所述节点所在的节点组中的任一节点。
第三方面,本发明实施例提供的一种区块链***,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;第一级节点层中的节点组为第一节点组;
所述第一节点组,用于生成待共识区块,并将所述待共识区块发送给所述第N级节点层中的各节点;
所述第N级节点层中的任一节点组,用于处理所述待共识区块,确定所述节点组中的每个节点对所述待共识区块的共识状态;
所述第i级节点层中的任一节点组,用于根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;若所述i大于1,则在所述节点组的主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;
其中,i、N为正整数,1≤i≤N。
在一种可能的设计中,所述第一节点组还用于:将所述待共识区块的共识结果发送给所述第N级节点层中的各节点;相应地,所述第N级节点层中的节点还用于:根据所述待共识区块的共识结果更新所述节点内部的预设数据库。
在一种可能的设计中,在所述i大于1时,所述第i级节点层中的任一节点组还用于:从所述节点组包括的各节点中选举出所述节点组在下一轮区块共识中的主节点,以根据所述第N级节点层中各节点组在下一轮区块共识中的主节点构成所述第i-1级节点层中的各节点组。
第四方面,本发明实施例提供的一种计算设备,包括至少一个处理单元以及至少一个存储单元,其中,所述存储单元存储有计算机程序,当所述程序被所述处理单元执行时,使得所述处理单元执行如上述第一方面任意所述的基于区块链***的共识方法。
第五方面,本发明实施例提供的一种计算机可读存储介质,其存储有可由计算设备执行的计算机程序,当所述程序在所述计算设备上运行时,使得所述计算设备执行如上述第一方面任意所述的基于区块链***的共识方法。
本发明的这些方面或其他方面在以下实施例的描述中会更加简明易懂。
附图说明
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例提供的一种区块链***的架构示意图;
图2为本发明实施例提供的一种使用PBFT共识算法处理交易时对应的流程示意图;
图3为本发明实施例提供的一种基于区块链***的区块共识方法;
图4为本发明实施例提供的一种具有层级结构的区块链***的架构示意图;
图5为本发明实施例提供的一种层级结构的区块链***的另一种表示形式;
图6为本发明实施例提供的一种区块共识方法对应的流程示意图;
图7为本发明实施例提供的一种基于区块链***的共识装置的结构示意图。
具体实施方式
为了使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明作进一步地详细描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。
金融科技(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作为下一轮区块共识的从节点;若节点确定出的主节点的编号为4,则将节点104作为下一轮区块共识的主节点,将节点101、节点102和节点103作为下一轮区块共识的从节点。
比如,若上一轮区块共识的主节点为节点101,且节点101的内存中存储了一条新的历史区块1,则视窗数值v被置零,区块链***中的节点数量为4,因此,节点101(或节点102~节点104)使用上述公式确定出的主节点的编号为1;基于表1可知,下一轮区块共识的主节点可以为节点102,使用主节点102执行区块2的共识。相应地,若节点101长时间未响应,则节点的内存中最大的历史区块仍为0,由于上一轮区块共识失败,因此视窗数值v递增为1,如此,节点101(或节点102~节点104)使用上述公式确定出的主节点的编号为1,即下一轮区块共识的主节点可以为节点102,使用主节点102执行区块1的共识。
在pre-prepare阶段中,若某一轮区块共识的主节点为节点101,且节点101的内存中存储的最大区块为区块1,则主节点101可以从主节点101的交易池中获取该轮区块共识待处理的交易数据,并根据该轮区块共识待处理的交易数据打包区块2,生成prepare包。具体地说,主节点101可以使用区块1的哈希值、区块2的块高以及当前的时间戳组装区块2的区块头,并可以使用该轮区块共识待处理的交易数据组装区块2的区块体,进而可以根据区块2的区块头和区块体生成prepare包。进一步地,主节点101可以将prepare包发送给区块链***中的任一节点,即节点102、节点103和节点104。至此,pre-prepare阶段执行结束。
显然地,在pre-prepare阶段中,主节点需要向区块链***中除主节点以外的所有节点发送prepare包,因此pre-prepare阶段对应的通信开销为(n-1),即O(n)。
prepare阶段
在prepare阶段中,区块链***中的任一节点接收到主节点101发送的prepare包后,均可以解析prepare包得到该轮区块共识待处理的交易数据;如此,该节点可以执行该轮区块共识待处理的交易数据得到交易结果。进一步地,该节点可以根据交易结果生成第一哈希值,根据每一条交易的收据信息生成第二哈希值,根据交易的请求消息生成第三哈希值,进而根据第一哈希值、第二哈希值和第三哈希值生成区块2的哈希值。如此,该节点可以将区块2的哈希值组装到区块2的区块头中、将该轮区块共识待处理的交易数据的交 易结果组装到区块2的区块体中,并使用该节点的私钥、区块2的区块头和区块2的区块体生成该节点的签名包,进而可以将该节点的签名包发送给区块链***中的其它节点,至此,prepare阶段执行结束。
显然地,在prepare阶段中,每个节点均需要向区块链***中除该节点以外的所有节点发送签名包,因此prepare阶段对应的通信开销为n*(n-1),即O(n 2)。
commit阶段
在commit阶段中,区块链***中的任一节点内部均可以存储有区块链***中所有节点的公钥,如此,任一节点在确定其它节点发送的签名包到达该节点后,可以先从该节点内部获取其它节点的公钥,并使用其它节点的公钥对其它节点的签名包进行解密,得到其它每个节点处理交易确定的区块2(包括区块头和区块体)。进一步地,任一节点可以将自己处理交易确定的区块2与任一其它节点处理交易确定的区块2进行对比,若相同,则可以接收所述其它节点发送的签名包,若不同,则可以拒绝所述其它节点发送的签名包。
针对于区块链***中的任一节点,若该节点接收到的签名包的数量小于预设阈值,说明该节点为异常节点,因此该节点可以不作后续操作,等待运维人员进行后续维护即可;相应地,若该节点接收到的签名包的数量大于或等于预设阈值,则说明该节点处理交易得到的区块2与区块链***中其它大部分节点处理交易得到的区块2相同,即该节点生成的区块2处于待提交状态;如此,该节点可以根据该节点处理交易得到的区块2生成commit包,并可以将commit包发送给区块链***中的其它节点,commit包用于指示该节点处于待提交状态。其中,预设阈值可以由本领域技术人员根据经验进行设置,不作限定比如,预设阈值可以设置为
Figure PCTCN2020110108-appb-000001
进一步地,区块链***中的任一节点在确定其它节点发送的commit包到达该节点后,可以解析其它节点的commit包得到其它每个节点处理交易确定的区块2(包括区块头和区块体);如此,该节点可以将自己处理交易确定的区块2与任一其它节点处理交易确定的区块2进行对比,若相同,则可以接收所述其它节点发送的commit包,若不同,则可以拒绝所述其它节点发送的commit包。相应地,若该节点接收到的commit包的数量小于预设阈值,说明该节点为异常节点,因此该节点可以不作后续操作,等待运维人员进行后续维护即可;相应地,若该节点接收到的签名包的数量大于或等于commit包,则说明该节点处理交易得到的区块2与区块链***中其它大部分节点处理交易得到的区块2相同,如此,该节点可以从内存中获取该节点处理交易所生成的区块2,并可以将区块2写入该节点内部的预设数据库中,从而完成该轮区块共识。至此,commit阶段执行结束。
显然地,在commit阶段中,每个节点均需要向区块链***中除该节点以外的所有节点发送签名包,因此commit阶段对应的通信开销为n*(n-1),即O(n 2)。
根据上述三个阶段的内容可知,PBFT共识算法在处理交易时,所需的通信开销为(n-1)+2n*(n-1),即O(n 2)。采用该种方式,若区块链***为大规模节点的区块链***,比如节点数量为1000,则其通信开销达到了10 6,该通信开销非常巨大,导致区块链***的通信压力较大;相应地,每个节点在prepare阶段和commit阶段均需要等待区块链***中的 其它全部节点发送的签名包或commit包方可执行后续的共识过程,导致节点需要等待相当长的时间,在该时间内节点处于不工作状态,从而导致节点的处理效率较低,区块链***的共识效率较低。
基于此,本发明实施例提供了一种区块链***,用以解决在大规模节点的区块链***中使用PBFT共识算法执行区块共识所导致的通信压力大、共识效率低的技术问题。
图3为本发明实施例提供的一种基于区块链***的区块共识方法,该方法包括:
步骤301,在执行每轮区块共识之前,确定区块链***中的节点数量是否大于预设数量,若是,则执行步骤302,若否,则执行步骤304。
在一种可能的实现方式中,可以在区块链***中设置监控器,监控器可以监控区块链***当前的区块共识情况,若监测到某一轮区块共识结束,或者监测到新一轮区块共识即将开始,则可以获取当前区块链***中的节点数量。进一步地,若当前区块链***中的节点数量大于预设数量,说明区块链***为大规模节点的区块链***,则可以执行步骤302;若节点数量小于或等于预设数量,说明区块链***为小规模节点的区块链***,则可以执行步骤304。
其中,预设数量可以由本领域技术人员根据经验进行设置,由于PBFT共识算法可以较好地处理节点数量在100以内的区块链***,因此预设数量可以设置为100。
步骤302,对区块链***中的节点进行分层分组,将区块链***转化为层级结构。
在一种可能的分层分组方式中,可以将区块链***中的共识节点划分为N级(即两级或两级以上)节点层,每级节点层中包括多个节点组,每个节点组包括一个主节点和多个从节点,每级节点层中的任意两个节点组中的节点不同,第N级节点层包括区块链***中的全部共识节点,第一级节点层仅包含第一节点组;且,针对于任一级节点层中的任一节点组,该节点组中的每个节点均为下一级节点层中对应节点组的主节点。其中,节点组中的主节点可以为采用PBFT共识算法从该节点组的多个节点中轮流确定的。
具体实施中,可以先将区块链***中的全部共识节点划分为多个节点组,并使用多个节点组构成第N级节点层,然后在每轮区块共识之前,使用PBFT共识算法从第N级节点层的每个节点组中选取一个主节点(每个节点组在该轮区块共识中的主节点不同于在上一轮区块共识中的主节点),进而再将第N级节点层选取出的多个主节点划分为多个节点组,并使用多个节点组构成第N-1级节点层,……,将第二级节点层选取出的多个主节点构成第一节点组,并使用第一节点组构成第一级节点层。
在一种可能的划分方式中,可以按照预设阈值划分多个节点得到多个节点组,比如在预设阈值为10时,若区块链***中存在1000个共识节点,分别为共识节点1、共识节点2、共识节点3、……、共识节点1000,则可以将1000个共识节点划分为节点组1、节点组2、节点组3、……、节点组100,节点组1包括共识节点1、共识节点2、共识节点3、……、共识节点10,节点组2包括共识节点11、共识节点12、共识节点13、……、共识节点20,……,节点组100包括共识节点991、共识节点992、共识节点993、……、共识节点1000;节点组1、节点组2、节点组3、……、节点组100构成了第N级节点层。又比如,若区块链 ***中存在995个共识节点,分别为共识节点1、共识节点2、共识节点3、……、共识节点995,在预设阈值为10时,则可以将1000个共识节点划分为节点组1、节点组2、节点组3、……、节点组100,节点组1包括共识节点1、共识节点2、共识节点3,……、共识节点10,节点组2包括共识节点11、共识节点12、共识节点13、……、共识节点20,……,节点组100包括共识节点991、共识节点992、共识节点993、共识节点994、共识节点995。
本发明实施例中,监控器可以实时监控区块链***中的节点,在节点未发生变化时,第N级节点层中的节点组可以始终保持不变;若监控到区块链***中的节点发生变化,则可以根据变化类型更新第N级节点层。举例来说,若监控到区块链***中新增了一个共识节点1001,则可以将共识节点1001***节点组1~节点组100中的任一节点组,或者也可以新增一个节点组101,将共识节点1001设置为节点组101中唯一的节点,如此,第N级节点层中包括节点组1~节点组101;若监控到区块链***中共识节点50退出区块链,则可以将共识节点50从节点组5中删除;若监控到区块链***中退出较多的共识节点或新增较多的共识节点,使得区块链***中的共识节点变化情况较大,则可以重新按照上述方式划分区块链***的当前共识节点得到多个新的节点组,并使用多个新的节点组构成第N级节点层。
进一步地,在每轮区块共识之前,针对于第N级节点层的节点组1~节点组100,可以采用PBFT共识算法从节点组1~节点组100的每个节点组中选择一个主节点,并按照预设阈值划分多个主节点得到多个节点组,使用多个节点组构成第N-1级节点层。举例来说,若第一轮区块共识之前,从节点组1中选出的主节点为共识节点2,从节点组2中选出的主节点为共识节点12,从节点组3中选出的主节点为共识节点22,……,从节点组100中选出的主节点为共识节点992,则可以将共识节点2、共识节点12、共识节点22、……、共识节点992划分为节点组110、节点组120、节点组130、……、节点组200,节点组110包括共识节点2、共识节点12、共识节点22、……、共识节点92,节点组120包括共识节点102、共识节点112、共识节点122、……、共识节点192,……,节点组200包括共识节点902、共识节点912、共识节点922、……、共识节点992;节点组110、节点组120、节点组130、……、节点组200构成了第N-1级节点层。
需要说明的是,区块链***中的共识节点数量越多,则节点层的层级较多,构成第N-2级节点层、第N-3级节点层、……、第二级节点层、第一级节点层的过程均可以参照构成第N-1级节点层的过程进行实现,此处不再赘述。
本发明实施例中,当区块链***中的共识节点不发生变化时,第N级节点层中的节点组数量以及每个节点组中的节点均不会发生变化;但是由于上一级节点层是由下一级节点层中的主节点构成的,PBFT共识算法会在每轮区块共识之前改变第N级节点层中每个节点组的主节点,因此,每轮区块共识对应的第N-1级节点层~第一级节点层中的节点组均不同于上一轮区块共识对应的第N-1级节点层~第一级节点层中的节点组。
需要说明的是,上述仅是一种示例性的简单说明,并不构成对方案的限定,在具体实施中,可以由本领域技术人员根据经验设置划分节点的方式,或者可以根据实际场景设置 划分节点的方式;比如,每级节点层可以采用相同的划分方式划分得到各自对应的多个节点组,或者也可以采用不同的划分方式划分得到各自对应的多个节点组,且,可以采用同一预设阈值划分节点得到多个节点组,或者也可以采用不同的预设阈值划分节点得到多个节点组,或者还可以采用随机数划分节点得到多个节点组,具体不作限定。
图4为本发明实施例提供的一种具有层级结构的区块链***的架构示意图,如图4所示,该区块链***可以包括第一级节点层、第二级节点层和第三级节点层,第三级节点层中包括区块链***中的全部共识节点,即节点1、节点2、节点3、……、节点1000。在第三级节点层中,节点1~节点1000按照预设阈值10进行划分,得到节点组a 3,1、节点组a 3,2、节点组a 3,3、……、节点组a 3,100,节点组a 3,1包括节点1、节点2、节点3、……、节点10,节点组a 3,2包括节点11、节点12、节点13、……、节点20,……,节点组a 3,100包括节点991、节点992、节点993、……、节点1000。
如图4所示,设定在执行某一轮区块共识之前,节点组a 3,1中的主节点(粗线圈对应的节点)为节点1,节点组a 3,2中的主节点为节点11,……,节点组a 3,100中的主节点为节点991,则在第二级节点层中,节点1、节点11、……、节点991按照预设阈值10进行划分,得到节点组a 2,1、节点组a 2,2、节点组a 2,3、……、节点组a 2,10,节点组a 2,1包括节点1、节点11、节点21、……、节点91,节点组a 2,2包括节点101、节点111、节点121、……、节点191,……,节点组a 2,10包括节点901、节点911、节点921、……、节点991。相应地,设定在执行该轮区块共识之前,节点组a 2,1中的主节点为节点11,节点组a 2,2中的主节点为节点111,……,节点组a 2,10中的主节点为节点911,则在第一级节点层中,节点11、节点111、……、节点911构成节点组a 1
本发明实施例中,若采用同一预设阈值划分节点,则区块链***中节点层的级数(或层数)N可以为:
N=log mn
其中,m为预设阈值,n为区块链***中共识节点的数量。
相应地,第N级节点层中节点组的数量g N可以为:
g N=n/m
第i级节点层中节点组的数量g i可以为:
g i=g i+1/m
其中,g i+1为第i+1级节点层中节点组的数量。
为了便于清晰地理解图4所示意的层级结构的区块链***,图5为层级结构的区块链***的另一种表示形式,为了便于描述,图5仅示意出了第二级节点层和第一级节点层中各个节点组的构成。
如图5所示,第一级节点层中的各个节点同时位于第一级节点层和第二级节点层的节点组中,比如,第一级节点层中的节点1同时位于节点组a 1和节点组a 2,1中,第一级节点层中的节点101同时位于节点组a 1和节点组a 2,2中,……,第一级节点层中的节点901同时位于节点组a 1和节点组a 2,10中。可以理解地,若扩展至图4中的三级节点层,则第一级 节点层中的各节点同时位于第一级节点层、第二级节点层和第三级节点层的节点组中,第二级节点层的各节点中除第一级节点层中各节点以外的节点同时位于第二级节点层和第三级节点层的节点组中。
步骤303,按照区块链***的层级结构执行所述每轮区块共识。
具体实施中,在任一轮区块共识之前,可以从第N级节点层的每个节点组中选取不同于上一轮区块共识的主节点,并使用从第N级节点层中选取出的多个主节点构成第N-1级节点层的各个节点组;进而可以从第N-1级节点层的每个节点组中选取主节点,并使用从第N-1级节点层中选取出的多个主节点构成第N-2级节点层的各个节点组,依次按照该种方式构建上一级节点层中的各个节点组,直至构建第一级节点层中的第一节点组。如此,该轮区块共识对应的区块链层级结构构建完成,后续可以基于该区块链层级结构执行该轮区块共识。
步骤304,使用PBFT共识算法执行该轮区块共识。
若区块链***中的共识节点数量小于预设数量,说明当前区块链***为小规模节点的区块链***,即使用PBFT共识算法处理该轮区块共识的通信压力并不大;因此,可以直接使用PBFT共识算法执行该轮区块共识,具体实现可以参照图2所示,不再赘述。
基于图4和图5所示意的层级结构的区块链***,图6为本发明实施例提供的一种区块共识方法对应的流程示意图,该方法包括:
步骤601,第一级节点层中第一节点组的主节点打包区块,得到待共识区块,并同步给第一级节点层中第一节点组的从节点。
在一种可能的实现方式中,上一轮区块共识结束后,若成功构建了区块链***的层级结构,则区块链***中的每个共识节点均可以将该共识节点所在的节点组、所在的节点组所属的层级以及所在的节点组包括的其它节点的标识存储在该共识节点的内存中;如此,若后续该共识节点需要在该共识节点所在的节点组中同步信息,则可以从该共识节点的内存中获取所在节点组包括的其它节点的标识,从而将信息同步给其它节点。
其中,上述信息可以以对应关系表的形式进行存储,表2为本发明实施例提供的一种可能的对应关系表的示意表。
表2:一种对应关系表的示意
Figure PCTCN2020110108-appb-000002
Figure PCTCN2020110108-appb-000003
如表2所示,节点111的对应关系表中可以存储有节点111在每级节点层中所在的节点组和所在的节点组中的其它节点,比如,节点111在第一级节点层的节点组a 1中,节点组a 1中除了包括节点组111以外,还可以包括节点11、节点211、节点311、节点411、节点511、节点611、节点711、节点811、节点911;相应地,节点111在第二级节点层的节点组a 2,2中,节点组a 2,2中除了包括节点组111以外,还可以包括节点101、节点121、节点131、节点141、节点151、节点161、节点171、节点181、节点191;节点111在第三级节点层的节点组a 3,12中,节点组a 3,12中除了包括节点组111以外,还可以包括节点112、节点113、节点114、节点115、节点116、节点117、节点118、节点119、节点120。
需要说明的是,基于图4所示意的层级结构的区块链***,第一级节点层中的每个节点的对应关系表中可以包含该节点分别在第一级节点层、第二级节点层和第三级节点层中所在的节点组以及所在的节点组包括的其它节点;第二级节点层中除第一级节点层中的节点以外的每个节点的对应关系表中可以包含该节点分别在第二级节点层和第三级节点层中所在的节点组以及所在的节点组包括的其它节点;第三级节点层中除第二级节点层中的节点以外的每个节点的对应关系表中可以包含该节点在第三级节点层中所在的节点组以及所在的节点组包括的其它节点。
为了便于描述,本发明实施例将第一级节点层中的节点组称为第一节点组。
具体实施中,在上一轮区块共识结束、本轮区块共识启动后,第一节点组的主节点可以从内部的交易池中获取本轮区块共识待处理的交易数据,并可以根据待处理的交易数据打包区块。基于图4,由于第一节点组为节点组a 1,且本轮区块共识中节点组a 1的主节点为节点111,因此,主节点111可以执行打包区块的过程。
其中,第一节点组的主节点可以按照步骤1~步骤3打包区块:
步骤1,从内存缓存的历史区块中获取历史最大区块的块高和历史最大区块的哈希值,并根据历史最大区块的块高设置待共识区块的块高;
步骤2,使用当前时间戳、待共识区块的块高以及历史最大区块的哈希值组装待共识区块的区块头,并使用本轮区块共识待处理的交易数据组装待共识区块的区块体。
步骤3,将待共识区块的区块头和待共识区块的区块体分别写入prepare包的对应位置,生成prepare包。
步骤602,第一级节点层中节点组的主节点将待共识区块传送给第N级节点层中的任一节点。
本发明实施例中,第一节点组的主节点可以按照多种方式传送prepare包给第N级节点层中的任一节点,下面描述两种可能的传送方式:
在一种可能的传送方式中,第一节点组的主节点可以按照本轮区块共识对应的层级结构传送prepare包给第N级节点层中的任一节点,具体地说,第一节点组的主节点可以先将prepare包发送给第一节点组中的任一从节点,进而由任一从节点将prepare包发送给下一级 节点层中该从节点所在的节点组中的任一从节点,直至不存在下一节点层为止。
举例来说,主节点111在得到prepare包后,通过查询表2所示的对应关系表确定主节点111在第一级节点层的节点组a 1中,从而可以将prepare包同步给节点组a 1中的任一从节点,即节点11、节点211、节点311、节点411、节点511、节点611、节点711、节点811和节点911;相应地,针对于第一节点组中的任一节点(比如节点11),节点11通过查询内部存储的对应关系表确定节点11在第二级节点层的节点组a 2,1中,从而节点11可以将prepare包同步给节点组a 2,1中的任一从节点,即节点1、节点21、节点31、节点41、节点51、节点61、节点71、节点81和节点91;进一步地,针对于节点组a 2,1中的任一节点(比如节点1),节点1通过查询内部存储的对应关系表确定节点1在第三级节点层的节点组a 3,1中,从而节点1可以将prepare包同步给节点组a 31中的任一从节点,即节点2、节点3、节点4、节点5、节点6、节点7、节点8和节点9。如此,通过按照层级关系依次同步prepare包,区块链***中的任一共识节点均可以接收到prepare包。
在上述传送方式中,通过按照层级关系将待共识区块或待共识区块的共识结果发送给区块链***中的各个共识节点,使得每个主节点只需在该主节点所属的节点组中同步待共识区块或待共识区块的共识结果,从而将第一节点组中的主节点与区块链***中的全部共识节点之间的同步过程转化为每个主节点与各自节点组中的从节点之间的同步过程,从而降低第一节点组中的主节点的通信压力。
在另一种可能的传送方式中,由于区块链***中的任意两个节点可以相互通信,因此,第一节点组的主节点在生成prepare包后,可以直接将prepare包发送给区块链***中的所有共识节点,比如主节点111直接将prepare包发送给节点1~节点110以及节点112~节点1000。在该种传送方式中,通过使用第一节点组中的主节点直接向区块链***中的各个共识节点发送待共识区块,可以避免多次调用中间节点层的各个节点组,从而降低中间层的各个节点组的压力;且,相比于通过中间节点层的各个节点组转发待共识区块来说,各个共识节点可以更早地接收到待共识区块,从而进一步提高区块链***的共识效率。
步骤603,第N级节点层中任一节点组的主节点根据该节点组中各节点对待共识区块的共识状态确定该节点组的共识结果。
具体实施中,针对于第N级节点层中任一节点组中的任一节点,该节点在确定prepare包到达该节点后,可以先对prepare包进行合法性验证,若确定prepare包合法,则可以接收prepare包;若确定prepare包不合法,则可以拒绝接收prepare包,并可以向用户发送告警信息,比如可以通过微信、钉钉、邮件等将告警信息推送给用户。
其中,合法性验证的具体过程可以为:节点解析prepare包得到本轮区块共识对应的当前时间戳、待共识区块的块高、历史最大区块的哈希值以及本轮区块共识待处理的交易数据,并查询该节点内部缓存的历史区块确定节点对应的历史最大区块的块高和哈希值。若确定待共识区块的块高等于节点对应的历史最大区块的块高加一,且本轮区块共识对应的历史最大区块的哈希值等于节点对应的历史最大区块的哈希值,则确定prepare包合法;相应地,若确定待共识区块的块高大于节点对应的历史最大区块的块高加一,说明待共识 区块为已共识过的历史区块,或者若确定待共识区块的块高小于节点对应的历史最大区块的块高加一,说明节点内部缓存的区块落后于其它节点,或者本轮区块共识对应的历史最大区块的哈希值不等于节点对应的历史最大区块的哈希值,节点均可以确定prepare包不合法。通过对prepare包进行合法性验证,可以过滤已处理的区块,提高交易处理的准确性。
进一步地,节点可以处理本轮区块共识中待处理的交易数据,得到交易结果,并可以基于交易数据、交易结果和每条交易的收据确定待共识区块的哈希值;如此,节点可以使用交易数据和交易结果组装待共识区块的区块体,并使用待共识区块的哈希值、待共识区块的块高、当前时间戳和最大历史区块的哈希值组装待共识区块的区块头,并可以使用节点的私钥、更新后的待共识区块的区块头以及待共识区块的区块体生成节点对应的签名包,进而可以通过查询节点内部的对应关系表确定节点在第N级节点层中所在的节点组,并可以将节点对应的签名包发送给节点在第N级节点层中所在的节点组中的任一节点。
相应地,针对于第N级节点层的任一节点组中的任一节点,该节点在确定所在节点组中的任一节点对应的签名包到达该节点后,可以先使用所述任一节点的公钥解析所述任一节点对应的签名包,并基于自己的签名包对解析所述任一节点对应的签名包得到的信息进行合法性验证,若确定所述任一节点对应的签名包合法,则可以接收所述任一节点对应的签名包;若确定所述任一节点对应的签名包不合法,则可以拒绝接收所述任一节点对应的签名包。其中,对签名包进行合法性验证的过程可以参照对prepare包进行合法性验证的过程来实现,区别在于对签名包进行合法性验证时还需要验证交易处理结果以及待共识区块的哈希值。
在一个示例中,每个节点内部可以仅存储该节点所在的节点组中其它节点的公钥,而无需存储区块链***中全部共识节点的公钥,从而可以降低公钥在节点内部占用的资源;比如,由于节点1仅在节点组a 3,1中,因此节点1内部可以仅存储节点2~节点10的公钥。其中,其它节点的公钥可以由监控器根据每轮区块共识中的分层分组情况发送给每个节点,或者也可以由节点根据每轮区块共识中的分层分组情况从区块链***的公共数据库中获取,具体不作限定。
进一步地,针对于第N级节点层的任一节点组中的任一节点,该节点可以统计已成功接收的签名包的数量,若已成功接收的签名包的数量小于预设数量,说明该节点生成的待共识区块与所在节点组中的大部分节点不同,该节点处理的交易结果故障,因此该节点可以不作任何处理;相应地,若已成功接收的签名包的数量大于或等于预设数量,说明该节点生成的待共识区块与所在节点组中的大部分节点相同,该节点处理的交易结果正常,因此该节点可以根据该节点对应的待共识区块生成该节点对应的commit包,并可以将该节点对应的commit包发送给该节点在第N级节点层中所在的节点组中的任一节点。其中,预设数量可以由本领域技术人员根据经验进行设置,比如可以
Figure PCTCN2020110108-appb-000004
其中,n为区块链***中的节点数量。
相应地,针对于第N级节点层的任一节点组中的任一节点,该节点在确定所在节点组 中的任一节点对应的commit包到达该节点后,可以先使用所述任一节点的公钥解析所述任一节点对应的commit包,并基于自己的commit包对解析所述任一节点对应的commit包得到的信息进行合法性验证,若确定所述任一节点对应的commit包合法,则可以接收所述任一节点对应的commit包;若确定所述任一节点对应的commit包不合法,则可以拒绝接收所述任一节点对应的commit包。其中,对commit包进行合法性验证的过程可以参照对签名包进行合法性验证的过程来实现,不再赘述。
进一步地,针对于第N级节点层的任一节点组中的任一节点,该节点可以统计已成功接收的commit包的数量,若已成功接收的commit包的数量小于预设数量,说明该节点的共识结果与所在节点组中的大部分节点的共识结果不同,该节点的共识过程故障,因此该节点可以不作任何处理;相应地,若已成功接收的commit包的数量大于或等于预设数量,说明该节点的共识结果与所在节点组中的大部分节点的共识结果相同,该节点的共识过程正常,因此该节点可以将状态更新为待提交状态。
如此,针对于第N节点层中的任一节点组,该节点组的主节点可以根据该节点组中各节点的状态确定该节点组中处于待提交状态的节点数量,若处于待提交状态的节点数量大于或等于预设数量,则该节点组的主节点可以根据其得到的待共识区块生成commit_t包;其中,t为该节点组的标识,commit_t包用于指示该节点组对待共识区块的共识结果。举例来说,节点组a 3,1的主节点1可以生成commit_a 3,1包,commit_a 3,1可以为根据主节点1的私钥、主节点1生成的待共识区块的区块头和待共识区块的区块体生成的。相应地,若处于待提交状态的节点数量小于预设数量,则该节点组的主节点可以不作任何处理。需要说明的是,若某一节点组中的主节点未能接收到预设数量的签名包,或未能接收到预设数量的commit包,说明主节点的共识过程有误,因此,主节点可以不作任何处理,即可以不生成commit_t包。
步骤604,在第j级节点层不为第一级节点层时,第j级节点层中任一节点组的主节点将该节点组的共识结果发送给第j-1级节点层中该主节点所在的节点组中的任一节点。
以第j级节点层为第N级节点层为例,具体实施中,针对于第N级节点层中的任一节点组,该节点组的主节点可以查询该主节点内部的对应关系表,确定该主节点在第N-1级节点层中所在的节点组,并可以将该主节点对应的commit_t包发送给该主节点在第N-1级节点层中所在的节点组中的任一从节点。举例来说,第三级节点层中节点组a 3,2的主节点11可以查询主节点11内部的对应关系表,确定主节点11在第二级节点层的节点组a 2,1中,从而可以将commit_a 3,2同步给节点组a 2,1中的任一从节点,即节点1、节点21、节点31、节点41、节点51、节点61、节点71、节点81和节点91。
步骤605,第j-1级节点层中任一节点组的主节点根据该节点组中各节点对待共识区块的共识状态确定该节点组的共识结果。
具体实施中,针对于第j-1级节点层中任一节点组的任一节点,该节点在确定所在节点组中其它任一节点对应的commit_t包到达该节点后,可以先使用所述其它任一节点的公钥解析所述其它任一节点对应的commit_t包,再使用该生成的commit_t包对所述其它任 一节点对应的commit_t包进行合法性验证,若验证合法,则该节点可以接收所述其它任一节点对应的commit_t包,若验证不合法,则该节点可以拒绝接收所述其它任一节点对应的commit_t包。
举例来说,第二级节点层中节点组a 2,1的节点31在确定节点1、节点11、节点21、节点41、节点51、节点61、节点71、节点81和节点91中的任一节点(比如节点1)发送的commit_t包(即commit_a 3,1包)到达节点31后,可以使用节点1的公钥解析commit_a 3,1包,并使用其生成的commit_a 3,2包对commit_a 3,1包进行合法性验证;若验证commit_a 3,1包合法,则节点31可以接收节点1发送的commit_a 3,1包,若验证commit_a 3,1包不合法,则节点31可以拒绝接收节点1发送的commit_a 3,1包。
进一步地,第j-1级节点层中任一节点组的任一节点若确定接收到的commit_t包的数量大于预设数量,则可以将该节点的状态更新为待提交状态;相应地,该节点组中的主节点在确定该节点组中存在预设数量的节点达到待提交状态后,可以根据其对应的待共识区块生成该节点组对应的commit_t包,该节点组对应的commit_t包用于指示该节点组对待共识区块的共识结果。需要说明的是,节点可以按照节点组的标识更新节点的状态,即节点的状态可以同时包括待提交状态和对应节点组的标识;比如,节点1同时在节点组a 1,1和节点组a 2,1中,因此节点1对应存在节点组a 1,1对应的状态和节点组a 2,1对应的状态,从而避免不同节点组中同一节点的状态的互相干扰。
步骤606,确定第j-1级节点层是否为第一级节点层,若否,则执行步骤604,若是,则执行步骤607。
本发明实施例中,针对于第j-1级节点层中的任一节点组,若该节点组中的主节点查询内部的对应关系表确定不存在上一级节点层包含该主节点,则可以确定第j-1级节点层为第一级节点层;若该节点组中的主节点查询内部的对应关系表确定存在上一级节点层包含该主节点,则可以确定第j-1级节点层不为第一级节点层。
步骤607,将第一节点组对待共识区块的共识结果作为待共识区块的共识结果,并将待共识区块的共识结果传送给第N级节点层中的任一节点。
具体实施中,若确定当前节点组为第一节点组,则第一节点组的主节点可以将第一节点组对待共识区块的共识结果作为待共识区块的共识结果,并可以将待共识区块的共识结果传送给第N级节点层中的任一节点;其中,第一节点组的主节点可以按照步骤602中传送待共识区块的两种方式传送待共识区块的共识结果,也可以按照其它方式传送待共识区块的共识结果,不作限定。
需要说明的是,若通过层级结果传送待共识区块的共识结果,则针对于任一级节点层中的任一节点组,该节点组中的每个节点在接收待共识区块的共识结果之前可以先对待共识区块的共识结果进行验证,若验证合法,则可以将待共识区块的共识结果同步给该节点在下一级节点层中所在的节点层中的任一节点,若验证不合法,则该节点可以不作任何处理。
相应地,若通过第一节点组的主节点直接发送待共识区块的共识结果给第N级节点层 中的任一节点,则第N级节点层中的任一节点在接收待共识区块的共识结果之前可以先对待共识区块的共识结果进行验证,若验证合法,则可以接收待共识区块的共识结果,若验证不合法,则该节点可以不作任何处理。
步骤608,第N级节点层中的节点接收到待共识区块的共识结果后,使用待共识区块的共识结果更新预设数据库,该轮共识结束,启动下一轮共识。
本发明实施例中,第N级节点层中的任一节点接收到待共识区块的共识结果后,可以使用待共识区块的共识结果更新该节点内部的预设数据库,比如先解析待共识区块的共识结果得到待共识区块,再将待共识区块的区块头和区块体添加到预设数据库中,最后将待共识区块的区块头作为历史最大区块添加到内存缓存中。采用该种方式,相比于现有技术中每个节点根据自己的区块信息和其它节点的区块信息直接更新预设数据库来说,可以提高共识结果的准确性。需要说明的是,本发明实施例中,步骤606至步骤608中待共识区块的共识结果均可以以commit包的形式存在。
本发明实施例中,针对于区块链***中的任一共识节点,若该共识节点执行完步骤608,则确定本轮区块共识结束;如此,监控器若监控到本轮区块共识结束,且确定当前区块链***中的节点不变,则可以从第N级节点层中每个节点组包括的各节点中选举出每个节点组在下一轮区块共识中的主节点,并可以使用第N-1级节点层中各节点组在下一轮区块共识中的主节点构成第N-1级节点层中的各节点组;若第N-1级节点层不为第一级节点层,则可以从第N-1级节点层中每个节点组包括的各节点中选举出每个节点组在下一轮区块共识中的主节点,并可以使用第N-1级节点层中各节点组在下一轮区块共识中的主节点构成第N-2级节点层中的各节点组,一直执行至第一级节点层为止。
本发明实施例中,设置第N级节点层中各节点组所包括的节点不变,在某一轮区块共识结束后,根据反向层级关系从下一级节点层的各个节点组中重新选取主节点组成上一级节点层中的各个节点组,可以保证不同轮区块共识中每级节点层的每个节点组中的主节点均不同,从而可以实现节点组中的各个节点轮换作主节点,保证区块链***的运行顺序。
本发明的上述实施例中,区块链***包括存在层级关系的N级节点层,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同,第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点,第N级节点层中的各节点为区块链***中全部的共识节点;针对第i级节点层中的每个节点组,该节点组的主节点根据该节点组中各节点对待共识区块的共识状态确定该节点组的共识结果,若i大于1,则在该主节点参与第i-1级节点层的共识时,将该节点组的共识结果作为该主节点对待共识区块的共识状态;若i等于1,则将该节点组的共识结果作为待共识区块的共识结果;其中,i、N为正整数,1≤i≤N。本发明实施例中,在大规模节点的区块链***中,通过对区块链***中的大规模节点进行分层分组,可以将大规模节点之间的共识过程转化为每个节点组内的少量节点之间的共识过程,从而极大地降低通信消耗,减小通信压力;且,每个节点只需在该节点所属的节点组中进行共识过程,从而只需等待本节点组中的其他节点发送的共识状态即可执行后续的共识过程,而 无需像现有技术需要等待区块链***中的全部节点发送的共识状态方可执行后续的共识过程,从而可以大大减少每个节点的共识过程所需的时间,使得区块链***的共识效率得到较大提升。需要说明的是,图6所示意的步骤编号仅为执行流程的一种示例,并不构成对各个步骤的执行先后顺序的限定。
针对上述方法流程,本发明实施例还提供一种基于区块链***的共识装置,该装置的具体内容可以参照上述方法实施。
图7为本发明实施例提供的一种基于区块链***的共识装置的结构示意图,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;
针对所述第i级节点层中的每个节点组,所述节点组中的主节点包括:
确定模块701,用于根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;
处理模块702,用于若所述i大于1,则在所述主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;
其中,i、N为正整数,1≤i≤N。
可选地,在所述i等于1时,所述装置还包括生成模块703和收发模块704;
所述生成模块703用于:生成所述待共识区块;
在所述确定模块701根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,所述收发模块704用于:将所述待共识区块发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;
在所述处理模块702将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果,所述收发模块704还用于:将所述待共识区块的共识结果发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;其中,所述按所述层级关系将所述待共识区块或所述待共识区块的共识结果发送给所述第N级节点层中的各节点,包括:
针对所述第i-1级节点层中的每个节点组,所述节点组的主节点将所述待共识区块或所述待共识区块的共识结果发送给所述节点组中的任一从节点;所述节点组中的任一节点将所述待共识区块或所述待共识区块的共识结果发送给第i级节点层中所述节点所在的节点组中的任一节点。
从上述内容可以看出:本发明的上述实施例中,区块链***包括存在层级关系的N级节点层,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同,第i-1级节点层中的各节点为 第i级节点层包括的各节点组中的主节点,第N级节点层中的各节点为区块链***中全部的共识节点;针对第i级节点层中的每个节点组,该节点组的主节点根据该节点组中各节点对待共识区块的共识状态确定该节点组的共识结果,若i大于1,则在该主节点参与第i-1级节点层的共识时,将该节点组的共识结果作为该主节点对待共识区块的共识状态;若i等于1,则将该节点组的共识结果作为待共识区块的共识结果;其中,i、N为正整数,1≤i≤N。本发明实施例中,在大规模节点的区块链***中,通过对区块链***中的大规模节点进行分层分组,可以将大规模节点之间的共识过程转化为每个节点组内的少量节点之间的共识过程,从而极大地降低通信消耗,减小通信压力;且,每个节点只需在该节点所属的节点组中进行共识过程,从而只需等待本节点组中的其他节点发送的共识状态即可执行后续的共识过程,而无需像现有技术需要等待区块链***中的全部节点发送的共识状态方可执行后续的共识过程,从而可以大大减少每个节点的共识过程所需的时间,使得区块链***的共识效率得到较大提升。
基于同一发明构思,本发明实施例还提供一种计算设备,包括至少一个处理单元以及至少一个存储单元,其中,所述存储单元存储有计算机程序,当所述程序被所述处理单元执行时,使得所述处理单元执行上述图3至图6任意所述的基于区块链***的共识方法。
基于同一发明构思,本发明实施例还提供一种计算机可读存储介质,其存储有可由计算设备执行的计算机程序,当所述程序在所述计算设备上运行时,使得所述计算设备执行上述图3至图6任意所述的基于区块链***的共识方法。
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。

Claims (12)

  1. 一种基于区块链***的共识方法,其特征在于,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;
    针对所述第i级节点层中的每个节点组,所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;若所述i大于1,则在所述主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;其中,i、N为正整数,1≤i≤N。
  2. 根据权利要求1所述的方法,其特征在于,第1级节点层中的节点组为第一节点组;
    在所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,还包括:
    所述第一节点组的主节点生成所述待共识区块,并将所述待共识区块发送给所述区块链***中的任一共识节点;
    所述将第1级节点层中节点组的共识结果作为所述待共识区块的共识结果之后,还包括:
    所述第一节点组的主节点将所述待共识区块的共识结果发送给所述区块链***中的任一共识节点。
  3. 根据权利要求1所述的方法,其特征在于,所述第1级节点层中的节点组为第一节点组;
    在所述节点组的主节点根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,还包括:
    所述第一节点组的主节点生成所述待共识区块,并按所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;
    所述将第1级节点层中节点组的共识结果作为所述待共识区块的共识结果之后,还包括:
    所述第一节点组的主节点按所述层级关系将所述待共识区块的共识结果发送给所述第N级节点层中的各节点;
    其中,所述按所述层级关系将所述待共识区块或所述待共识区块的共识结果发送给所述第N级节点层中的各节点,包括:
    针对所述第i-1级节点层中的每个节点组,所述节点组的主节点将所述待共识区块或所述待共识区块的共识结果发送给所述节点组中的任一从节点;所述节点组中的任一节点将所述待共识区块或所述待共识区块的共识结果发送给所述第i级节点层中所述节点所在的 节点组中的任一节点。
  4. 根据权利要求2或3所述的方法,其特征在于,所述第一节点组的主节点将所述待共识区块发送给所述第N级节点层中的各节点后,还包括:
    针对于所述第N级节点层中的每个节点组,所述节点组的任一节点处理所述待共识区块得到所述节点对所述待共识区块的区块信息,并将所述节点对所述待共识区块的区块信息发送给所述节点组中的其它节点;所述节点组的节点根据所述节点对所述待共识区块的区块信息与所述节点组中的其它节点对所述待共识区块的区块信息,确定所述节点对所述待共识区块的共识状态;
    所述第一节点组的主节点将所述待共识区块的共识结果发送给所述第N级节点层中的各节点之后,还包括:
    所述区块链***中的任一共识节点根据所述待共识区块的共识结果更新所述共识节点内部的预设数据库。
  5. 根据权利要求4所述的方法,其特征在于,在所述区块链***中的任一共识节点根据所述待共识区块的共识结果更新所述共识节点内部的预设数据库之后,还包括:
    针对于所述第i级节点层中的每个节点组,从所述节点组包括的各节点中选举出所述节点组在下一轮区块共识中的主节点,以根据所述第N级节点层中各节点组在下一轮区块共识中的主节点构成所述第i-1级节点层中的各节点组。
  6. 一种基于区块链***的共识装置,其特征在于,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;针对所述第i级节点层中的每个节点组,所述节点组中的主节点包括:
    确定模块,用于根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;
    处理模块,用于若所述i大于1,则在所述主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;其中,i、N为正整数,1≤i≤N。
  7. 根据权利要求6所述的装置,其特征在于,在所述i等于1时,所述装置还包括生成模块和收发模块;
    所述生成模块用于:生成所述待共识区块;
    在所述确定模块根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果之前,所述收发模块用于:将所述待共识区块发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;
    在所述处理模块将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识 结果,所述收发模块还用于:将所述待共识区块的共识结果发送给所述区块链***中的任一共识节点或者按照所述层级关系将所述待共识区块发送给所述第N级节点层中的各节点;
    其中,所述按所述层级关系将所述待共识区块或所述待共识区块的共识结果发送给所述第N级节点层中的各节点,包括:
    针对所述第i-1级节点层中的每个节点组,所述节点组的主节点将所述待共识区块或所述待共识区块的共识结果发送给所述节点组中的任一从节点;所述节点组中的任一节点将所述待共识区块或所述待共识区块的共识结果发送给第i级节点层中所述节点所在的节点组中的任一节点。
  8. 一种区块链***,其特征在于,所述区块链***包括存在层级关系的N级节点层;其中,每级节点层中包括至少一个节点组,每个节点组中包括一个主节点和至少一个从节点;同一级节点层中的任意两个节点组包括的节点不同;第i-1级节点层中的各节点为第i级节点层包括的各节点组中的主节点;第N级节点层中的各节点为所述区块链***中全部的共识节点;第一级节点层中的节点组为第一节点组;
    所述第一节点组,用于生成待共识区块,并将所述待共识区块发送给所述第N级节点层中的各节点;
    所述第N级节点层中的任一节点组,用于处理所述待共识区块,确定所述节点组中的每个节点对所述待共识区块的共识状态;
    所述第i级节点层中的任一节点组,用于根据所述节点组中各节点对待共识区块的共识状态确定所述节点组的共识结果;若所述i大于1,则在所述节点组的主节点参与所述第i-1级节点层的共识时,将所述节点组的共识结果作为所述主节点对所述待共识区块的共识状态;若所述i等于1,则将所述第i级节点层中节点组的共识结果作为所述待共识区块的共识结果;
    其中,i、N为正整数,1≤i≤N。
  9. 根据权利要求8所述的***,其特征在于,所述第一节点组还用于:将所述待共识区块的共识结果发送给所述第N级节点层中的各节点;所述第N级节点层还用于:根据所述待共识区块的共识结果更新所述第N级节点层的各节点内部的预设数据库。
  10. 根据权利要求9所述的***,其特征在于,在所述i大于1时,所述第i级节点层中的任一节点组还用于:
    从所述节点组包括的各节点中选举出所述节点组在下一轮区块共识中的主节点,以根据所述第N级节点层中各节点组在下一轮区块共识中的主节点构成所述第i-1级节点层中的各节点组。
  11. 一种计算设备,其特征在于,包括至少一个处理单元以及至少一个存储单元,其中,所述存储单元存储有计算机程序,当所述程序被所述处理单元执行时,使得所述处理单元执行权利要求1~5任一权利要求所述的方法。
  12. 一种计算机可读存储介质,其特征在于,其存储有可由计算设备执行的计算机程序,当所述程序在所述计算设备上运行时,使得所述计算设备执行权利要求1~5任一权利 要求所述的方法。
PCT/CN2020/110108 2019-08-20 2020-08-19 一种基于区块链***的共识方法、装置及*** WO2021032138A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910770124.0A CN110474986B (zh) 2019-08-20 2019-08-20 一种基于区块链***的共识方法、装置及***
CN201910770124.0 2019-08-20

Publications (1)

Publication Number Publication Date
WO2021032138A1 true WO2021032138A1 (zh) 2021-02-25

Family

ID=68512928

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/110108 WO2021032138A1 (zh) 2019-08-20 2020-08-19 一种基于区块链***的共识方法、装置及***

Country Status (2)

Country Link
CN (1) CN110474986B (zh)
WO (1) WO2021032138A1 (zh)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113254272A (zh) * 2021-06-09 2021-08-13 腾讯科技(深圳)有限公司 区块链网络的数据处理方法、装置、计算机设备和介质
CN113676355A (zh) * 2021-08-27 2021-11-19 浙商银行股份有限公司 一种区块链多层级组网方法、设备及存储介质
CN114338040A (zh) * 2021-12-29 2022-04-12 大连理工江苏研究院有限公司 一种区块链节点的分组多链三次共识方法
CN114363084A (zh) * 2022-01-13 2022-04-15 西南林业大学 一种基于区块链的跨境贸易数据可信存储方法
CN115314369A (zh) * 2022-10-12 2022-11-08 中国信息通信研究院 区块链节点共识的方法和装置、设备和介质
CN115473908A (zh) * 2022-11-03 2022-12-13 山东区块链研究院 一种区块链节点故障恢复方法及区块链***
CN116015929A (zh) * 2022-12-30 2023-04-25 ***股份有限公司 一种联盟链准入管理方法及装置

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110474986B (zh) * 2019-08-20 2022-08-12 深圳前海微众银行股份有限公司 一种基于区块链***的共识方法、装置及***
CN110912994B (zh) * 2019-11-22 2022-02-11 中国联合网络通信集团有限公司 一种区块链共识方法及装置
CN111339187B (zh) * 2020-02-20 2023-05-09 百度在线网络技术(北京)有限公司 基于智能合约的数据处理方法、装置、设备和存储介质
CN111046110B (zh) * 2020-03-16 2020-06-26 支付宝(杭州)信息技术有限公司 用于区块链***的节点管理的方法、节点和计算设备
CN111524011B (zh) * 2020-05-06 2023-05-30 杭州复杂美科技有限公司 平行链共识确认方法、设备和存储介质
CN111711526B (zh) * 2020-06-16 2024-03-26 深圳前海微众银行股份有限公司 一种区块链节点的共识方法及***
CN111786818B (zh) * 2020-06-16 2023-04-18 杭州溪塔科技有限公司 一种区块链共识节点状态监控方法和装置
CN112434311B (zh) * 2020-11-05 2022-05-20 德州职业技术学院(德州市技师学院) 一种区块链数据加密共享方法和***
CN113347174B (zh) * 2021-05-31 2022-12-13 矩阵元技术(深圳)有限公司 区块链中的共识方法、装置和电子设备
CN113505155B (zh) * 2021-07-06 2023-05-12 中国联合网络通信集团有限公司 基于区块链网络的交易信息检索方法和检索装置
CN113837758A (zh) * 2021-09-27 2021-12-24 深圳前海微众银行股份有限公司 一种区块链***的共识方法及装置
CN114513525B (zh) * 2022-04-19 2022-07-05 北京易鲸捷信息技术有限公司 采用跨机房链式转发的数据一致性优化方法及***

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108182635A (zh) * 2017-12-18 2018-06-19 深圳前海微众银行股份有限公司 区块链共识方法、***和计算机可读存储介质
CN109819003A (zh) * 2017-11-22 2019-05-28 南京理工大学 一种区块链的分层共识方法和***
US20190173666A1 (en) * 2017-12-01 2019-06-06 International Business Machines Corporation Hierarchical blockchain consensus optimazation scheme
CN110113388A (zh) * 2019-04-17 2019-08-09 四川大学 一种基于改进型聚类算法的区块链***共识的方法和装置
CN110474986A (zh) * 2019-08-20 2019-11-19 深圳前海微众银行股份有限公司 一种基于区块链***的共识方法、装置及***

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10304143B2 (en) * 2016-05-05 2019-05-28 Lance Timothy Kasper Consensus system for manipulation resistant digital record keeping
CN107147735B (zh) * 2017-05-12 2020-08-11 北京博晨技术有限公司 一种基于分层结构的分布式账本***
CN109246194B (zh) * 2018-08-13 2021-06-08 佛山市顺德区中山大学研究院 基于多领导节点的实用拜占庭容错区块链共识方法及***
CN109547527B (zh) * 2018-10-12 2021-04-06 广西师范大学 区块链中基于信誉机制的分区快速共识方法
CN109462587B (zh) * 2018-11-09 2020-03-27 四川虹微技术有限公司 区块链分层共识方法、区块链网络***及区块链节点
CN109327548A (zh) * 2018-11-27 2019-02-12 北京瑞卓喜投科技发展有限公司 一种区块链更新方法及区块链更新***
CN109547211B (zh) * 2018-11-29 2020-06-30 浙江大学 应用数字签名技术的分级并发拜占庭共识方法及***

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109819003A (zh) * 2017-11-22 2019-05-28 南京理工大学 一种区块链的分层共识方法和***
US20190173666A1 (en) * 2017-12-01 2019-06-06 International Business Machines Corporation Hierarchical blockchain consensus optimazation scheme
CN108182635A (zh) * 2017-12-18 2018-06-19 深圳前海微众银行股份有限公司 区块链共识方法、***和计算机可读存储介质
CN110113388A (zh) * 2019-04-17 2019-08-09 四川大学 一种基于改进型聚类算法的区块链***共识的方法和装置
CN110474986A (zh) * 2019-08-20 2019-11-19 深圳前海微众银行股份有限公司 一种基于区块链***的共识方法、装置及***

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113254272A (zh) * 2021-06-09 2021-08-13 腾讯科技(深圳)有限公司 区块链网络的数据处理方法、装置、计算机设备和介质
CN113254272B (zh) * 2021-06-09 2022-09-13 腾讯科技(深圳)有限公司 区块链网络的数据处理方法、装置、计算机设备和介质
CN113676355A (zh) * 2021-08-27 2021-11-19 浙商银行股份有限公司 一种区块链多层级组网方法、设备及存储介质
CN113676355B (zh) * 2021-08-27 2024-04-23 浙商银行股份有限公司 一种区块链多层级组网方法、设备及存储介质
CN114338040A (zh) * 2021-12-29 2022-04-12 大连理工江苏研究院有限公司 一种区块链节点的分组多链三次共识方法
CN114338040B (zh) * 2021-12-29 2024-03-08 大连理工江苏研究院有限公司 一种区块链节点的分组多链三次共识方法
CN114363084A (zh) * 2022-01-13 2022-04-15 西南林业大学 一种基于区块链的跨境贸易数据可信存储方法
CN115314369A (zh) * 2022-10-12 2022-11-08 中国信息通信研究院 区块链节点共识的方法和装置、设备和介质
CN115473908A (zh) * 2022-11-03 2022-12-13 山东区块链研究院 一种区块链节点故障恢复方法及区块链***
CN116015929A (zh) * 2022-12-30 2023-04-25 ***股份有限公司 一种联盟链准入管理方法及装置
CN116015929B (zh) * 2022-12-30 2024-05-17 ***股份有限公司 一种联盟链准入管理方法及装置

Also Published As

Publication number Publication date
CN110474986B (zh) 2022-08-12
CN110474986A (zh) 2019-11-19

Similar Documents

Publication Publication Date Title
WO2021032138A1 (zh) 一种基于区块链***的共识方法、装置及***
JP7362654B2 (ja) 分割されたブロックチェーンネットワークにおけるブロックチェーンのブロックの維持管理
Xu et al. CUB, a consensus unit-based storage scheme for blockchain system
CN107657438B (zh) 一种区块链生成方法、数据验证方法、节点及***
CN110517141B (zh) 一种基于区块链***的共识方法及装置
US20200143366A1 (en) Methods for decentralized digital asset transfer and smart contract state transition
US11461310B2 (en) Distributed ledger technology
JP2020504927A (ja) イベントの削除を可能にする分散データベースのための方法および装置
CN111902817A (zh) 基于共享节点和纠错编码的区块链数据存储
CN111611315A (zh) 面向金融大数据的多叉树结构区块链集成优化存储方法
US11036760B2 (en) Method for parallel maintenance of data consistency
CN111698094B (zh) 一种基于区块链***的共识方法及区块链***
KR20190068799A (ko) 서비스 존 기반의 계층적 합의 방법 및 장치
CN111095210A (zh) 基于纠错编码存储共享的区块链数据
US11354335B2 (en) Method and apparatus for obtaining number for transaction-accessed variable in blockchain in parallel
CN114626547A (zh) 一种基于区块链的群组协同学习方法
US20230102617A1 (en) Repeat transaction verification method, apparatus, and device, and medium
CN113886501A (zh) 一种基于多链架构下的区块链业务模块扩展方法
CN110704438A (zh) 一种区块链中布隆过滤器的生成方法及装置
Qin et al. A secure and effective construction scheme for blockchain networks
WO2020073246A1 (zh) 基于区块链的交易数据处理方法、设备和存储介质
CN115544026B (zh) 数据存储方法、装置、电子设备和存储介质
Ren et al. Toward reducing cross-shard transaction overhead in sharded blockchains
Geng et al. Blockchain-inspired Framework for Runtime Verification of IoT Ecosystem Task Fulfillment
Ying et al. Gcfl: blockchain-based efficient federated learning for heterogeneous devices

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

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20854568

Country of ref document: EP

Kind code of ref document: A1

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 09/08/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20854568

Country of ref document: EP

Kind code of ref document: A1