A blockchain consensus method, device, equipment and storage medium
By determining the target block from multiple sub-blockchains and performing global sorting in the blockchain system, the scalability and transaction throughput problems of the traditional blockchain consensus protocol in a large-scale network environment are solved, and the system is improved. performance and security.
Patent Information
- Application Number
- CN202111277507.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-30
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-10-30
AI Technical Summary
Traditional blockchain consensus protocols show low scalability and transaction throughput in large-scale open network environments, and are difficult to adapt to the blockchain network environment where application nodes are constantly increasing.
By determining the target sub-blockchain to which the target block belongs from multiple sub-blockchains, and performing global sorting based on the logical clock of each valid block, the global blockchain is obtained, and multi-chain consensus is used to allocate high-concurrency block processing capabilities to improve the scalability and transaction throughput of the system.
It improves the scalability and transaction throughput of the blockchain system in a large-scale open network environment, and provides a more reliable timing relationship measurement through the logical clock, enhancing the security of the system.
Smart Images

Figure CN114281888B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of blockchain technology, and in particular to a blockchain consensus method, device, equipment and storage medium. Background Art
[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. The blockchain consensus protocol is the key technology of the underlying blockchain platform, which directly determines the security and system performance of the blockchain system.
[0003] Traditional consensus protocols (such as Raft protocol, Practical Byzantine Fault Tolerance (PBFT)) or their improved protocols are mostly based on the collaborative method of state machine replication to achieve consistency. However, traditional consensus schemes have high communication complexity, and the system transaction performance decreases significantly with the increase of network node scale. Therefore, they are mostly used in small-scale alliance chain networks and are difficult to adapt to the blockchain network environment with an increasing number of application nodes. Summary of the invention
[0004] The embodiments of the present application provide a blockchain consensus method, apparatus, device and storage medium for improving the scalability and transaction throughput of a blockchain system in a large-scale open network environment.
[0005] On the one hand, the embodiment of the present application provides a blockchain consensus method, which is applied to any node in a blockchain system, including:
[0006] Determine a target sub-blockchain to which a target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain, wherein the target block is generated based on transaction data or obtained synchronously from other nodes;
[0007] Obtaining respectively corresponding valid block sequences from the multiple sub-blockchains, each valid block sequence including at least one valid block;
[0008] Based on the logical clocks corresponding to the obtained valid blocks, the valid blocks are globally sorted to obtain a global blockchain.
[0009] On the one hand, an embodiment of the present application provides a blockchain consensus device, which is applied to any node in a blockchain system, including:
[0010] A matching module, used to determine a target sub-blockchain to which a target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain, wherein the target block is generated based on transaction data or obtained synchronously from other nodes;
[0011] A screening module, used to obtain respectively corresponding valid block sequences from the multiple sub-blockchains, each valid block sequence including at least one valid block;
[0012] The sorting module is used to globally sort the valid blocks based on the logical clocks corresponding to the obtained valid blocks to obtain a global blockchain.
[0013] Optionally, the logical clock of the valid block is: starting from the valid block, the number of blocks passed along the logical clock path corresponding to the valid block to the genesis block, wherein the logical clock path corresponding to the valid block is: starting from the valid block, the path extending to the genesis block along the direction pointing to the longest clock block.
[0014] Optionally, the matching module is specifically used for:
[0015] Merge the other field information in the block header of the target block except the auxiliary information field and perform a hash operation to obtain a packaged hash, wherein the other field information at least includes the global snapshot flags of the multiple sub-blockchains, the transaction root hash of the transaction data, and the block hash of the longest clock block pointed to by the target block, wherein the longest clock block pointed to by the target block is a legal block with the maximum logical clock monitored by the node when generating the target block;
[0016] Processing the packaged hash using a verifiable delay function to obtain a verifiable output result;
[0017] Based on the verifiable output result, determine the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof;
[0018] The target block is obtained based on the other field information, the verifiable output result, the parent block hash, the parent block proof and the transaction data.
[0019] Optionally, the matching module is further used for:
[0020] Merging the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation, and before obtaining the packaged hash, taking a global snapshot of the multiple sub-block chains to obtain the latest valid block in each valid block sequence;
[0021] Based on the block hashes of the latest valid blocks obtained, construct a first Merkle tree corresponding to the global snapshot;
[0022] The root hash of the first Merkle tree is used as a global snapshot mark of the multiple sub-blockchains.
[0023] Optionally, the matching module is further used for:
[0024] Merging the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation, and constructing a second Merkle tree based on the transaction data before obtaining the packaged hash;
[0025] The root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
[0026] Optionally, the matching module is further used for:
[0027] Before determining the target child blockchain to which the target block belongs, the corresponding parent block in the target child blockchain, and the corresponding parent block hash and parent block proof based on the verifiable output result, the verifiable output result is encrypted and hashed to obtain a verifiable output hash;
[0028] Determining that the verifiable output hash is less than the block generation difficulty.
[0029] Optionally, the matching module is specifically used for:
[0030] Using the verifiable output hash, taking a modulo of the total number of the plurality of sub-blockchains, to determine the target sub-blockchain to which the target block belongs;
[0031] The valid block corresponding to the target child blockchain in the global snapshot is used as the parent block of the target block in the target child blockchain, and the parent block hash and parent block proof of the parent block are obtained.
[0032] Optionally, the verifiable output result includes verifiable output content and verifiable output proof;
[0033] The matching module is also used for:
[0034] Based on the verifiable output result, after determining the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof, the target block hash of the target block is generated based on the block hash of the longest clock block pointed to by the target block, the global snapshot flag, the transaction root hash, the verifiable output content, and the parent block hash.
[0035] Optionally, the matching module is further used for:
[0036] Receive the target block sent by other nodes, and obtain the verifiable output result corresponding to the target block, the parent block hash of the parent block, the parent block proof of the parent block, and the global snapshot flag from the block header of the target block;
[0037] Based on the verifiable output result, the parent block hash, the parent block proof and the global snapshot flag, perform basic verification on the target block;
[0038] Based on the verifiable output result corresponding to the target block, perform a difficulty check on the target block;
[0039] Based on the logical clock of the target block and the logical clock of the parent block, the clock of the target block is checked.
[0040] Optionally, the screening module is specifically used for:
[0041] For the multiple sub-blockchains, perform the following steps respectively:
[0042] Starting from the genesis block of a sub-blockchain and extending in the direction of the sub-blocks, blocks corresponding to the maximum weight block subtree are selected in sequence as valid blocks until there are no extended blocks, and a valid block sequence consisting of the selected valid blocks is obtained, wherein the block subtree of a block includes the block and other block subtrees extending along the block, the weight of the block subtree is the sum of the block weights of each block in the block subtree, and the block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash.
[0043] Optionally, the screening module is specifically used for:
[0044] Each time a block corresponding to the maximum weight block subtree is selected as a valid block, the following steps are included:
[0045] For a first valid block most recently selected in the one sub-blockchain, determine, from the one sub-blockchain, at least one candidate sub-block connected to the first valid block, and a block sub-tree corresponding to each of the at least one candidate sub-block;
[0046] Determine the weight of the block subtree corresponding to each of the at least one candidate subblock, and determine a maximum weight block subtree from each block subtree based on the obtained weight;
[0047] A candidate subblock corresponding to the maximum weight block subtree among the at least one candidate subblock is used as a second valid block.
[0048] Optionally, the sorting module is specifically used to:
[0049] Obtain a target valid block from each valid block sequence respectively;
[0050] Based on the obtained logical clocks corresponding to the various target valid blocks, the various target valid blocks are globally sorted to obtain a global blockchain.
[0051] Optionally, the screening module is further used for:
[0052] For each valid block, the following steps are performed respectively:
[0053] If the weight of the block subtree corresponding to a block is greater than or equal to the stability threshold, the block is regarded as a stable block;
[0054] If the weight of the block subtree corresponding to the block is less than the stability threshold, the block is regarded as an unstable block.
[0055] Optionally, the sorting module is specifically used to:
[0056] Get the latest stable block from each valid block sequence respectively;
[0057] Obtain the minimum logical clock from the logical clocks corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary;
[0058] Filtering out, from each stable block, a target stable block whose logic clock is less than or equal to the block clock boundary;
[0059] Based on the logical clocks corresponding to the obtained target stable blocks, the target stable blocks are globally sorted to obtain a global blockchain.
[0060] Optionally, the sorting module is specifically used to:
[0061] According to the order of logical clocks from small to large, the target stable blocks are globally sorted to obtain a preliminary sorting result;
[0062] If there are target stable blocks with the same logical clock in the preliminary sorting result, the target stable blocks with the same logical clock are sorted based on the sub-blockchain number or block hash to obtain the global blockchain.
[0063] On the one hand, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned blockchain consensus method when executing the program.
[0064] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by a computer device. When the program is run on the computer device, the computer device executes the steps of the above-mentioned blockchain consensus method.
[0065] In the embodiment of the present application, multiple sub-blockchains can share the processing power of high-concurrency blocks in a large-scale network environment. Therefore, the global blockchain obtained by multi-chain consensus can improve the scalability and transaction throughput of the blockchain system in a large-scale open network environment. Secondly, the logical clock corresponding to each block provides a more reliable measurement of the timing relationship between blocks. Therefore, based on the logical clock corresponding to each valid block, when each valid block is globally sorted to obtain a global blockchain, the security of the multi-chain system can be better improved, and it is also convenient for the multi-chain system to be further optimized based on this. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0067] Figure 1 A schematic diagram of a system architecture applicable to an embodiment of the present application;
[0068] Figure 2 A flowchart of a blockchain consensus method provided in an embodiment of the present application;
[0069] Figure 3 A schematic diagram of a parallel multi-chain architecture provided in an embodiment of the present application;
[0070] Figure 4 A schematic diagram of a parallel multi-chain architecture provided in an embodiment of the present application;
[0071] Figure 5 A flowchart of a method for generating a target block provided in an embodiment of the present application;
[0072] Figure 6 A schematic diagram of a block structure provided in an embodiment of the present application;
[0073] Figure 7 A schematic diagram of the structure of a sub-blockchain provided in an embodiment of the present application;
[0074] Figure 8 A schematic diagram of a parallel multi-chain architecture provided in an embodiment of the present application;
[0075] Fig. 9 A schematic diagram of a parallel multi-chain architecture provided in an embodiment of the present application;
[0076] Fig.10 A flowchart of a blockchain consensus method provided in an embodiment of the present application;
[0077] Fig.11 A schematic diagram of the structure of a blockchain consensus device provided in an embodiment of the present application;
[0078] Fig.12 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0079] In order to make the purpose, technical solution and beneficial effects of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0080] For ease of understanding, the terms involved in the embodiments of the present invention are explained below.
[0081] Blockchain: A new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0082] VDF: Verifiable Delay Function. A new type of cryptographic primitive whose execution time is deterministic and has nothing to do with the number of cores of the node's central processing unit (CPU). For a given input, its execution result is unique and verifiable.
[0083] GHOST: Greedy Heaviest Observed Sub-Tree, Ghost Protocol or Heaviest Subchain Protocol. A consensus rule that improves the proof of work, that is, starting from the genesis block, the corresponding block of the heaviest subtree is taken as the current block in order.
[0084] Merkle Tree: A data structure organization method that outputs a unique value (usually a hash). The basic method is to sort the data set and perform hash operations in a step-by-step manner until a unique value is formed. The number of sequences is preferably a power of 2, and the insufficient part can be supplemented by repeating the leaf node value.
[0085] Gossip protocol: a message propagation protocol, that is, a node broadcasts to its surrounding nodes, relays the message, and eventually covers the entire network. It is currently a typical message propagation method in blockchain networks.
[0086] PoW: Proof of Work. A consensus mechanism where nodes submit blocks by competing for hash calculation results that meet specific conditions.
[0087] Figure 1 A schematic diagram of the architecture of a blockchain system provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the blockchain system may include N nodes, namely node 100-1, node 100-2, ..., node 100-N, where N is a positive integer. Any two nodes in the blockchain system can be connected to communicate, thereby jointly maintaining the blockchain system, wherein any two nodes can be connected by wire or by wireless, without specific limitation.
[0088] In the embodiment of the present invention, the nodes in the blockchain system may have multiple functions. For example, routing function, transaction function, consensus function, etc. Specifically, the nodes in the blockchain system may transmit information such as transaction data transmitted by other nodes to more nodes to realize communication between nodes; or, the nodes in the blockchain system may be used to record all transactions in history; or, the nodes in the blockchain system may generate new blocks in the blockchain by verifying and recording transactions.
[0089] It should be noted that a node in the blockchain system can be a physical machine (server) or a process or a series of processes running in the server. This application does not specifically limit this.
[0090] like Figure 1As shown, 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. In a specific implementation, the client device 200 may send transaction data to any node in the blockchain system, and after receiving the transaction data, a node in the blockchain system may synchronize the transaction data to other nodes in the blockchain system. After receiving the transaction data, a node may also store the transaction data in the transaction pool inside the node; accordingly, after receiving the transaction data synchronized by the node, other nodes may also store the transaction data in the transaction pool inside other nodes. In this way, if a node determines to process multiple transaction data, it may obtain multiple transaction data from the internal transaction pool, and then perform subsequent transaction processing and block consensus.
[0091] In the embodiment of the present application, Figure 1 Any node in the blockchain system shown in the figure generates a target block based on transaction data, or obtains the target block synchronously from other nodes. Then, the target sub-blockchain to which the target block belongs is determined from multiple sub-blockchains, and the target block is added to the target sub-blockchain. Then, the valid block sequences corresponding to each of the multiple sub-blockchains are obtained, and each valid block sequence includes at least one valid block. Then, based on the logical clocks corresponding to each of the valid blocks obtained, the valid blocks are globally sorted to obtain a global blockchain.
[0092] In the embodiment of the present application, since multiple sub-blockchains can share the processing power of high-concurrency blocks in a large-scale network environment, the global blockchain is obtained by adopting a multi-chain consensus method, which can improve the scalability and transaction throughput of the blockchain system in a large-scale open network environment. Secondly, the logical clock corresponding to each block provides a more reliable measurement of the timing relationship between blocks. Therefore, based on the logical clock corresponding to each valid block, when each valid block is globally sorted to obtain a global blockchain, the security of the multi-chain system can be better improved, and it is also convenient for the multi-chain system to be further optimized based on this.
[0093] based on Figure 1 The system architecture diagram shown in the figure, the embodiment of the present application provides a process of a blockchain consensus method, such as Figure 2 As shown, the process of this method can be Figure 1 Any node in the blockchain system shown in the figure executes the following steps:
[0094] Step S201, determine the target sub-blockchain to which the target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain.
[0095] Specifically, multiple sub-blockchains are multiple parallel single chains, and the number of multiple sub-blockchains can be set according to actual conditions. When setting, the number of multiple sub-blockchains depends on the estimation of the scale of nodes actually participating in the blockchain network and the local physical computing power of the nodes. The larger the scale of the blockchain network, the more sub-blockchains should be increased accordingly, but the number of sub-blockchains should not be over-expanded to prevent system performance degradation. The genesis blocks in multiple sub-blockchains can be the same or different. A sub-blockchain may or may not contain a forked block.
[0096] For example, see Figure 3 , is a parallel multi-chain architecture provided in an embodiment of the present application, the parallel multi-chain architecture includes sub-blockchain C0, sub-blockchain C1 and sub-blockchain C2, wherein sub-blockchain C0 includes genesis block G0, block C01, block C02, block C03, block C04, block C05, and block C06. Sub-blockchain C1 includes genesis block G1, block C11, block C12, block C13, block C14, block C15, and block C16. Sub-blockchain C2 includes genesis block G2, block C21, block C22, block C23, block C24, block C25, and block C26.
[0097] Before the blockchain consensus is reached, all nodes in the blockchain system start from the public genesis block and the same configuration file to initialize the protocol, and then start to package and generate new blocks or synchronize blocks generated by other nodes. The relevant initialization parameters include: block generation difficulty, VDF parameters, the number and number of each sub-blockchain, etc. The above target blocks are generated by nodes based on transaction data, or synchronized from other nodes. When setting the VDF parameters, the VDF execution time should be greater than the average block propagation time of the blockchain network, so that the nodes can fully interact and the network can converge quickly to avoid possible balance attacks on GHOST.
[0098] Step S202, obtaining the corresponding valid block sequences from the multiple sub-blockchains respectively.
[0099] Specifically, each valid block sequence includes at least one valid block, and there is no forked block in the at least one valid block. After obtaining the corresponding valid block sequence from the child blockchain, other blocks in the child blockchain can be removed, thereby updating the child blockchain to the corresponding valid block sequence.
[0100] Step S203: Based on the obtained logical clocks corresponding to the valid blocks, the valid blocks are globally sorted to obtain a global blockchain.
[0101] Specifically, the logical clock is used to characterize the timing relationship between blocks. The logical clock of a valid block is the number of blocks (including valid blocks, excluding the genesis block) that are passed along the logical clock path corresponding to the valid block from the valid block as the starting point to the genesis block, where the logical clock path corresponding to the valid block is: starting from the valid block, extending to the genesis block in the direction pointing to the longest clock block. The longest clock block pointed to by a block is the legal block with the largest logical clock detected by the node when generating the block. The block can be a block generated by the node or a block synchronized from other nodes. The initial longest clock block is the genesis block.
[0102] For example, see Figure 4 , is a parallel multi-chain architecture provided in an embodiment of the present application, the parallel multi-chain architecture includes sub-blockchain C0, sub-blockchain C1 and sub-blockchain C2, wherein sub-blockchain C0 includes genesis block G0, block C01, block C02, block C03, block C04, and block C05. Sub-blockchain C1 includes genesis block G1, block C11, block C12, block C13, block C14, and block C15. Sub-blockchain C2 includes genesis block G2, block C21, block C22, block C23, block C24, and block C25.
[0103] Set the valid block to block C15, the longest clock block pointed to by block C15 is block C04, the longest clock block pointed to by block C04 is block C13, the longest clock block pointed to by block C13 is block C23, the longest clock block pointed to by block C23 is block C12, the longest clock block pointed to by block C12 is block C02, the longest clock block pointed to by block C02 is block C11, and the longest clock block pointed to by block C11 is the genesis block G1.
[0104] Depend on Figure 4 It can be seen that the logical clock path corresponding to block C15 is: block C15→block C04→block C13→block C23→block C12→block C02→block C11→genesis block G1, so the logical clock corresponding to block C15 is 7.
[0105] After obtaining the logical clocks corresponding to each valid block, each valid block can be globally sorted in the order of logical clocks from small to large to obtain a global blockchain. It is also possible to use specific rules to screen each valid block, and then globally sort the retained valid blocks in the order of logical clocks from small to large to obtain a global blockchain. In addition, when there are multiple valid blocks with the same logical clock, the multiple valid blocks can be sorted according to the sub-blockchain numbers or block hashes corresponding to the multiple valid blocks, and finally output the global blockchain.
[0106] It should be noted that in the embodiments of the present application, the node may trigger global sorting to obtain the global blockchain each time the obtained block is added to the corresponding sub-blockchain; or it may trigger global sorting to obtain the global blockchain after a preset time interval or a preset number of blocks, wherein the preset time interval and the preset number of blocks may be set according to actual conditions; or it may trigger global sorting to obtain the global blockchain only when an external trigger instruction is received, and the present application does not make any specific limitation on this.
[0107] In the embodiment of the present application, since multiple sub-blockchains can share the processing power of high-concurrency blocks in a large-scale network environment, the global blockchain is obtained by adopting a multi-chain consensus method, which can improve the scalability and transaction throughput of the blockchain system in a large-scale open network environment. Secondly, the logical clock corresponding to each block provides a more reliable measurement of the timing relationship between blocks. Therefore, based on the logical clock corresponding to each valid block, when each valid block is globally sorted to obtain a global blockchain, the security of the multi-chain system can be better improved, and it is also convenient for the multi-chain system to be further optimized based on this.
[0108] Optionally, in the above step S201, the node adopts at least one of the following implementations to generate a target block based on the transaction data, such as Figure 5 As shown, the specific steps include:
[0109] Step S501, merging the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation to obtain a packaged hash.
[0110] Specifically, other field information includes at least the global snapshot flags of multiple sub-blockchains, the transaction root hash of the transaction data, and the block hash of the longest clock block pointed to by the target block, wherein the longest clock block pointed to by the target block is the legal block with the maximum logical clock monitored by the node when generating the target block. In addition, other field information may also include the block hash of at least one sampled block corresponding to the target block.
[0111] Specifically, the embodiment of the present application adopts at least one of the following implementation methods to obtain the global snapshot flags of multiple sub-blockchains:
[0112] First, a global snapshot is taken of multiple sub-blockchains to obtain the latest valid blocks in each valid block sequence. When taking a snapshot, the latest valid blocks are sorted, specifically by the number of the sub-blockchain to which the latest valid block belongs. Then, based on the block hash of each latest valid block, the first Merkle tree corresponding to the global snapshot is constructed. The root hash of the first Merkle tree is then used as the global snapshot mark of multiple sub-blockchains.
[0113] The embodiment of the present application adopts at least one of the following implementation methods to obtain the transaction root hash of the transaction data: based on the transaction data, a second Merkle tree is constructed, and then the root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
[0114] It should be noted that the embodiments of the present application may also adopt other hash algorithms to obtain the global snapshot flags of multiple sub-blockchains and the transaction root hash of transaction data. This application does not make any specific limitations on this.
[0115] After obtaining other field information except the auxiliary information field, each field information is merged in a determined order, and then the package hash corresponding to the merged data is calculated.
[0116] Step S502, using a verifiable delay function to process the packaged hash to obtain a verifiable output result.
[0117] One possible implementation method is that when the node is a multi-core CPU node, the verifiable delay function can be executed in parallel through multiple threads. At the same time, different threads correspond to different transaction contents, thereby realizing multi-threaded parallel participation in VDF and keeping the input matching the node processing capacity.
[0118] Step S503, based on the verifiable output result, determine the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof.
[0119] In a possible implementation, after obtaining the verifiable output result, the difficulty of the target block can be checked based on the verifiable output result.
[0120] Specifically, the verifiable output result is encrypted and hashed to obtain the verifiable output hash, and then it is determined whether the verifiable output hash is less than the block generation difficulty. If so, the target block is determined to be a legal block and the subsequent steps are performed. Otherwise, the target block is determined to be an illegal block and the target block is discarded. The above block generation difficulty can be a fixed value or can be adjusted regularly.
[0121] Using the verifiable output hash, modulo the total number of multiple sub-blockchains, determine the target sub-blockchain to which the target block belongs. Then use the valid block corresponding to the target sub-blockchain in the global snapshot as the parent block of the target block in the target sub-blockchain, and obtain the parent block hash and parent block proof of the parent block.
[0122] In a specific implementation, after determining the target sub-blockchain to which the target block belongs, based on the global snapshot described above, the latest valid block corresponding to the target sub-blockchain in the global snapshot can be obtained, and then the obtained latest valid block is used as the parent block of the target block in the target sub-blockchain, and the parent block hash and parent block proof of the parent block are obtained, wherein the parent block proof can be a Merkle tree proof.
[0123] Step S504, based on other field information, verifiable output results, parent block hash, parent block proof and transaction data, obtain the target block.
[0124] Specifically, the verifiable output result includes the verifiable output content and the verifiable output proof. The target block includes a block header and a block body. The block hash, global snapshot flag, transaction root hash, verifiable output result, parent block hash, and parent block proof of the longest clock block pointed to by the target block are added to the block header, and the transaction data is added to the block body. It should be noted that the data in the target block is not limited to the above-mentioned types, and may also include more development-related information fields, which are not specifically limited in this application.
[0125] For example, Figure 6 An exemplary block structure is shown, including a block header and a block body, wherein the block header includes a global snapshot flag, a block hash of the longest clock block, a transaction root hash, verifiable output content, a parent block hash, a verifiable output certificate, and a parent block certificate, etc. The block body includes the actual transaction data entered into the block.
[0126] In addition to obtaining the target block, in an embodiment of the present application, a target block hash of the target block is generated based on the block hash of the longest clock block pointed to by the target block, the global snapshot flag, the transaction root hash, the verifiable output content, and the parent block hash, wherein the target block hash is used to uniquely identify the target block.
[0127] Optionally, after obtaining the target block, the node can broadcast the target block to the network, and the blockchain network broadcast method can adopt the Gossip protocol, etc. After receiving the target block, other blocks can add the target block to the local target sub-blockchain.
[0128] In the embodiment of the present application, the node realizes block generation by completing a verifiable delay function of a specific difficulty, providing a more reliable measurement of the time relationship between blocks without having to adopt the traditional proof-of-work mechanism (PoW), thereby improving the scalability and transaction throughput of the blockchain system in a large-scale open network environment.
[0129] Optionally, in the above step S201, the target block may also be obtained synchronously from other nodes.
[0130] Specifically, the node receives the target block sent by other nodes, and obtains the verifiable output result corresponding to the target block, the parent block hash of the parent block, the parent block proof of the parent block and the global snapshot flag from the block header of the target block. The process of other nodes generating the target block refers to the above steps S501 to S505, which will not be repeated here.
[0131] Before adding the target block to the local sub-blockchain, the node needs to verify the target block. The verification process includes one or more of the following processes:
[0132] 1. Perform basic verification on the target block based on the verifiable output results, the parent block hash of the parent block, the parent block proof of the parent block and the global snapshot flag.
[0133] Specifically, the verification can verify whether the output result is correct, and the verification rules are defined by the verifiable delay function itself.
[0134] Based on the parent block hash and parent block proof obtained from the block header, the target sub-blockchain to which the target block belongs is determined. The verifiable output result obtained from the block header is encrypted and hashed to obtain the verifiable output hash, and the verifiable output hash is used to modulo the total number of sub-blockchains to determine the reference sub-blockchain to which the target block belongs.
[0135] Determine whether the target sub-blockchain and the reference sub-blockchain are consistent. If so, based on the parent block proof and global snapshot flag of the parent block obtained from the block header, determine whether the parent block is the block in the corresponding global snapshot. If so, determine that the target block is a legal block. Otherwise, determine that the target block is an illegal block and discard the target block.
[0136] 2. Based on the verifiable output result corresponding to the target block, the difficulty of the target block is checked.
[0137] Specifically, the verifiable output result obtained from the block header is encrypted and hashed to obtain the verifiable output hash, and then it is determined whether the verifiable output hash is less than the block generation difficulty. If so, the target block is determined to be a legal block, otherwise, the target block is determined to be an illegal block and is discarded.
[0138] 3. Based on the logical clock of the target block and the logical clock of the parent block, the clock of the target block is checked.
[0139] The method described above is used to calculate the logical clock of the target block and the logical clock of the parent block respectively, and then determine whether the logical clock of the target block is greater than or equal to the logical clock of the parent block. If so, the target block is determined to be a legal block, otherwise, the target block is determined to be an illegal block and discarded.
[0140] After verifying the target block using one or more of the above verification processes, if the target block is determined to be a legal block, the target block is added to the corresponding sub-blockchain; if the target block is determined to be an illegal block, the target block is discarded.
[0141] In the embodiment of the present application, after a node receives a target block sent by other nodes, it performs a multi-dimensional verification on the target block, and only adds the target block to the corresponding sub-blockchain when the verification passes, thereby ensuring the security of the blockchain system.
[0142] Optionally, in the above step S202, for multiple sub-blockchains, the corresponding valid block sequences are obtained respectively in the following manners:
[0143] Starting from the genesis block of a sub-blockchain, extending along the sub-block direction, the blocks corresponding to the maximum weight block subtree are selected as valid blocks in turn until there are no extended blocks, and a valid block sequence consisting of the selected valid blocks is obtained.
[0144] Specifically, the block subtree of a block includes the block and other block subtrees extending along the block. The weight of the block subtree is the sum of the block weights of each block in the block subtree. The block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash.
[0145] The block weight of each block is determined based on the verifiable output hash of each block, rather than simply setting the block weight of each block to the same value, thereby improving the convergence speed of the single chain.
[0146] For example, see Figure 7 , which is a schematic diagram of the structure of a sub-blockchain, which includes the genesis block G0, block C01, block C02, block C03, block C04, block C05, block C06, block C07, block C08, and block C09.
[0147] Taking block C01 as an example, the block subtree of block C01 includes block C01, block C02, block C03, block C04, block C07, block C08, and block C09. The weight of the block subtree is the sum of the block hashes corresponding to each of the above blocks.
[0148] In a possible implementation manner, each time a block corresponding to the maximum weight block subtree is selected as a valid block, the following steps are included:
[0149] For the first valid block newly selected in a sub-blockchain, at least one candidate sub-block connected to the first valid block and the block sub-tree corresponding to each of the at least one candidate sub-block are determined from the sub-blockchain. Then, the weight of the block sub-tree corresponding to each of the at least one candidate sub-block is determined, and the maximum weight block sub-tree is determined from each block sub-tree based on the obtained weight. Finally, the candidate sub-block corresponding to the maximum weight block sub-tree in the at least one candidate sub-block is used as the second valid block.
[0150] Specifically, in the initial state, the genesis block on the sub-blockchain is the first valid block, and then the second valid block is selected along the extension direction of the sub-blockchain.
[0151] For example, see Figure 7 In the sub-blockchain shown, in the process of selecting valid blocks for the first time, the genesis block G0 is used as the first valid block, and the blocks connected to the genesis block G0 include block C01 and block C05.
[0152] Block subtree 1 of block C01 includes block C01, block C02, block C03, block C04, block C07, block C08, and block C09. The sum of the block hashes corresponding to block C01, block C02, block C03, block C04, block C07, block C08, and block C09 is used as the weight of block subtree 1.
[0153] Block subtree 2 of block C05 includes block C05 and block C06, and the sum of the block hashes corresponding to block C05 and block C06 is used as the weight of block subtree 2. Since the weight of block subtree 1 is greater than the weight of block subtree 2, block subtree 1 is the maximum weight block subtree, and block C01 corresponding to block subtree 1 is the second valid block.
[0154] In the process of selecting valid blocks for the second time, block C01 is used as the first valid block, and the blocks connected to block C01 include block C02, block C03 and block C04.
[0155] The block subtree 3 of block C02 includes block C02, block C07 and block C08, and the sum of the block hashes corresponding to block C02, block C07 and block C08 is used as the weight of block subtree 3.
[0156] The block subtree 4 of block C03 includes block C03 and block C09, and the sum of the block hashes corresponding to block C03 and block C09 is used as the weight of block subtree 4.
[0157] The block subtree 5 of block C04 includes block C04, and the block hash corresponding to block C04 is used as the weight of block subtree 5.
[0158] Since the weight of block subtree 3 is greater than the weights corresponding to block subtree 4 and block subtree 5 respectively, block subtree 3 is the maximum weight block subtree, then block C02 corresponding to block subtree 3 is the second valid block.
[0159] In the process of selecting valid blocks for the third time, block C02 is used as the first valid block, and the blocks connected to block C02 include block C07 and block C08.
[0160] The block subtree 6 of block C07 includes block C07, and the block hash corresponding to block C07 is used as the weight of block subtree 6.
[0161] The block subtree 7 of block C08 includes block C08, and the block hash corresponding to block C08 is used as the weight of block subtree 7.
[0162] Since the weight of block subtree 6 is greater than the weight of block subtree 7, block subtree 6 is the maximum weight block subtree, and block C07 corresponding to block subtree 6 is the second valid block.
[0163] There are no extended blocks after block C07, so the selection of valid blocks is stopped, and the valid block sequence obtained is genesis block G0, block C01, block C02, and block C07.
[0164] In the embodiment of the present application, starting from the genesis block of the sub-blockchain, the blocks corresponding to the maximum weight block subtree are selected in sequence as valid blocks, and a valid block sequence consisting of the selected valid blocks is obtained. The VDF-based single-chain transformation based on the heaviest sub-chain idea can better improve the security of the multi-chain system, and the upper limit of system performance can be further improved within the scope of node processing capabilities.
[0165] Furthermore, after obtaining the valid block sequences corresponding to each sub-blockchain, the valid blocks in each valid block sequence can be divided into stable blocks and unstable blocks.
[0166] Specifically, for each valid block, perform the following steps respectively:
[0167] If the weight of the block subtree corresponding to a block is greater than or equal to the stability threshold, the block is regarded as a stable block. If the weight of the block subtree corresponding to a block is less than the stability threshold, the block is regarded as an unstable block, where the stability threshold is set according to the actual situation.
[0168] By dividing the obtained valid blocks into stable blocks and unstable blocks, it is convenient to monitor the status of the sub-blockchain in real time, and it is also convenient to sort all the valid blocks in the future to obtain a stable global blockchain.
[0169] Optionally, in the above step S203, the embodiment of the present application adopts at least the following implementation methods to globally sort the obtained valid blocks to obtain a global blockchain:
[0170] Implementation method 1: Obtain a target valid block from each valid block sequence respectively; based on the logical clock corresponding to each obtained target valid block, globally sort each target valid block to obtain a global blockchain.
[0171] Specifically, a target valid block is randomly obtained from each valid block sequence. The filtered target valid filtered blocks are globally sorted in the order of logical clock from small to large to obtain the global blockchain. When there are target valid blocks with the same logical clock, the target valid blocks with the same logical clock are sorted based on the sub-blockchain number or block hash to obtain the global blockchain.
[0172] For example, if Figure 8 As shown, a parallel multi-chain architecture provided by an embodiment of the present application, the parallel multi-chain architecture includes a sub-blockchain C0, a sub-blockchain C1 and a sub-blockchain C2, wherein the sub-blockchain C0 includes a genesis block G0 (logical clock: 0), a block C01 (logical clock: 1), a block C02 (logical clock: 2), a block C03 (logical clock: 3), and a block C04 (logical clock: 4). The sub-blockchain C1 includes a genesis block G1 (logical clock: 0), a block C11 (logical clock: 1), a block C12 (logical clock: 3), and a block C13 (logical clock: 5). The sub-blockchain C2 includes a genesis block G2 (logical clock: 0), a block C21 (logical clock: 1), a block C22 (logical clock: 4), a block C23 (logical clock: 5), and a block C24 (logical clock: 6).
[0173] Block C01 in sub-blockchain C0, block C11 in sub-blockchain C1, and block C22 in sub-blockchain C2 are selected as target valid blocks.
[0174] The selected target valid blocks are globally sorted in the order of logical clock from small to large. When there are target valid blocks with the same logical clock, the target valid blocks with the same logical clock are sorted in the order of sub-blockchain numbers from small to large. The obtained global blockchain is: block C01, block C11 and block C22.
[0175] Implementation method 2: Obtain the latest stable block from each valid block sequence, obtain the minimum logical clock from the logical clocks corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary. From each stable block, select the target stable block whose logical clock is less than or equal to the block clock boundary. Based on the obtained logical clocks corresponding to each target stable block, globally sort each target stable block to obtain a global blockchain.
[0176] Specifically, the target stable blocks are globally sorted in the order of logical clock from small to large to obtain a preliminary sorting result. If there are target stable blocks with the same logical clock in the preliminary sorting result, the target stable blocks with the same logical clock are sorted based on the sub-blockchain number or block hash to obtain a global blockchain.
[0177] When the target stable blocks with the same logical clock are sorted by sub-blockchain number or block hash, they can also be sorted in ascending order.
[0178] For example, if Fig. 9 As shown, a parallel multi-chain architecture provided by an embodiment of the present application, the parallel multi-chain architecture includes a sub-blockchain C0, a sub-blockchain C1 and a sub-blockchain C2, wherein the sub-blockchain C0 includes a genesis block G0 (logical clock: 0), a block C01 (logical clock: 1), a block C02 (logical clock: 2), a block C03 (logical clock: 3), and a block C04 (logical clock: 4). The sub-blockchain C1 includes a genesis block G1 (logical clock: 0), a block C11 (logical clock: 1), a block C12 (logical clock: 3), and a block C13 (logical clock: 5). The sub-blockchain C2 includes a genesis block G2 (logical clock: 0), a block C21 (logical clock: 1), a block C22 (logical clock: 4), a block C23 (logical clock: 5), and a block C24 (logical clock: 6).
[0179] It is assumed that the stable blocks in the sub-blockchain C0 include: the genesis block G0, block C01, and the latest stable block is block C01. The stable blocks in the sub-blockchain C1 include: the genesis block G1, block C11, and the latest stable block is block C11. The stable blocks in the sub-blockchain C2 include: the genesis block G2, block C21, and block C22, and the latest stable block is block C22.
[0180] Among the logical clocks corresponding to the above-mentioned latest stable blocks, the minimum logical clock is 1, and the block clock boundary is determined to be 1.
[0181] Among the stable blocks in the sub-blockchain C0, the target stable blocks whose logical clock is less than or equal to the block clock boundary include the genesis block G0 and block C01.
[0182] Among the stable blocks in the sub-blockchain C1, the target stable blocks whose logical clocks are less than or equal to the block clock boundaries include the genesis block G1 and the block C11.
[0183] Among the stable blocks in the sub-blockchain C2, the target stable blocks whose logical clocks are less than or equal to the block clock boundaries include the genesis block G2 and the block C21.
[0184] The selected target stable blocks are globally sorted in the order of logical clock from small to large. When there are target stable blocks with the same logical clock, they are sorted in the order of sub-blockchain numbers from small to large. The obtained global blockchain is: genesis block G0, genesis block G1, genesis block G2, block C01, block C11, and block C21.
[0185] In the embodiment of the present application, the heaviest subchain idea is adopted to carry out VDF-based single-chain transformation, and a global blockchain is constructed based on the block timing relationship corresponding to the block logical clock, introducing a more reliable time relationship measurement, thereby improving the security of the multi-chain system and further improving the system performance upper limit within the node processing capacity.
[0186] Furthermore, after obtaining the global blockchain, it is determined whether there are repeated or conflicting transactions between different blocks in the global blockchain (for example, the same transaction is packaged repeatedly). Specifically, the transactions in each block are executed in sequence according to the order of the blocks in the blockchain. If a transaction in the current block has been executed before, it is determined that the transaction is an illegal transaction and is not executed. Otherwise, the transaction is determined to be a legal transaction and is executed, and the system status is updated at the same time.
[0187] In order to better explain the embodiment of the present application, the following introduces a blockchain consensus method provided by the embodiment of the present application in combination with a specific implementation scenario. The process of the method can be as follows: Figure 1 Any node in the blockchain system shown in the figure executes the following steps: Fig.10 As shown:
[0188] Step S1001, system protocol initialization.
[0189] Specifically, the node first initializes protocol-related parameters, such as: block generation difficulty, VDF parameters, the number and number of each sub-blockchain, blockchain network identification, block size, local public and private key account configuration, etc.
[0190] Step S1002, VDF process.
[0191] Specifically, the transaction data is obtained from the transaction pool, and the legal block with the maximum logical clock monitored by the node when generating the target block is used as the longest clock block pointed to by the target block, and the block hash of the longest clock block is obtained.
[0192] Take a global snapshot of multiple sub-blockchains, obtain the latest valid block in each valid block sequence, and build the first Merkle tree corresponding to the global snapshot based on the block hash of each latest valid block. Then use the root hash of the first Merkle tree as the global snapshot mark of multiple sub-blockchains.
[0193] Based on the transaction data, a second Merkle tree is constructed, and then the root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
[0194] The block hash of the longest clock block, the global snapshot flags of multiple sub-blockchains, and the transaction root hash of the transaction data are merged, and then the package hash corresponding to the merged data is calculated. Then the package hash is processed using VDF to obtain a verifiable output result. The verifiable output result includes verifiable output content and verifiable output proof.
[0195] The verifiable output result is encrypted and hashed to obtain the verifiable output hash, and then it is determined whether the verifiable output hash is less than the block generation difficulty. If so, the target block is determined to be a legal block and subsequent steps are executed. Otherwise, the target block is determined to be an illegal block and the target block is discarded.
[0196] After the difficulty test is passed, the verifiable output hash is used to modulo the total number of multiple sub-blockchains to determine the target sub-blockchain to which the target block belongs. Then the valid block corresponding to the target sub-blockchain in the global snapshot is used as the parent block of the target block in the target sub-blockchain, and the parent block hash and parent block proof of the parent block are obtained.
[0197] Add the block hash of the longest clock block, the global snapshot flag, the transaction root hash, the verifiable output result, the parent block hash, and the parent block proof to the block header, and add the transaction data to the block body to obtain the target block.
[0198] Generate the target block hash of the target block based on the block hash of the longest clock block, the global snapshot flag, the transaction root hash, the verifiable output content, and the parent block hash.
[0199] Step S1003: message broadcast and synchronization.
[0200] The node broadcasts the target block to other nodes, synchronizes the blocks generated by other nodes, and adds the transaction data in the synchronized blocks to the transaction pool.
[0201] Step S1004: block legitimacy verification.
[0202] Specifically, after a node receives a block sent by other nodes, it performs basic verification, difficulty verification, and clock verification on the block. If the verification passes, the received block is determined to be a legal block, otherwise it is an illegal block.
[0203] Step S1005, adding the legal block to the corresponding sub-blockchain.
[0204] Step S1006, obtaining corresponding valid block sequences from multiple sub-block chains respectively.
[0205] Specifically, for each sub-blockchain, starting from the genesis block of the sub-blockchain and extending along the sub-block direction, blocks corresponding to the maximum weight block subtree are selected in sequence as valid blocks until there are no extended blocks, and a valid block sequence composed of the selected valid blocks is obtained.
[0206] The block subtree of a block includes the block and other block subtrees extending along the block. The weight of the block subtree is the sum of the block weights of each block in the block subtree. The block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash.
[0207] Step S1007, globally sort the obtained valid blocks to obtain a global blockchain.
[0208] Specifically, the valid blocks in each valid block sequence are divided into stable blocks and unstable blocks. The latest stable blocks are obtained from each valid block sequence. The minimum logical clock is obtained from the logical clocks corresponding to each latest stable block, and the minimum logical clock is used as the block clock boundary; from each stable block, the target stable block whose logical clock is less than or equal to the block clock boundary is screened out.
[0209] Step S1008, executing transactions in each block in the global blockchain.
[0210] Execute transactions in each block in block order.
[0211] Step S1009, the system status is updated, and step S1002 is executed.
[0212] In the embodiment of the present application, since multiple sub-blockchains can share the processing power of high-concurrency blocks in a large-scale network environment, the global blockchain is obtained by adopting a multi-chain consensus method, which can improve the scalability and transaction throughput of the blockchain system in a large-scale open network environment. Secondly, the logical clock corresponding to each block provides a more reliable measurement of the timing relationship between blocks. Therefore, based on the logical clock corresponding to each valid block, when each valid block is globally sorted to obtain a global blockchain, the security of the multi-chain system can be better improved, and it is also convenient for the multi-chain system to be further optimized based on this.
[0213] Based on the same technical concept, the embodiment of the present application provides a schematic diagram of the structure of a blockchain consensus device, which is applied to any node in a blockchain system, such as Fig.11 As shown, the device 1100 includes:
[0214] A matching module 1101 is used to determine a target sub-blockchain to which a target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain, where the target block is generated based on transaction data or obtained synchronously from other nodes;
[0215] A screening module 1102 is used to obtain respectively corresponding valid block sequences from the multiple sub-block chains, each valid block sequence including at least one valid block;
[0216] The sorting module 1103 is used to globally sort the valid blocks based on the logical clocks corresponding to the obtained valid blocks to obtain a global blockchain.
[0217] Optionally, the logical clock of the valid block is: starting from the valid block, the number of blocks passed along the logical clock path corresponding to the valid block to the genesis block, wherein the logical clock path corresponding to the valid block is: starting from the valid block, the path extending to the genesis block along the direction pointing to the longest clock block.
[0218] Optionally, the matching module 1101 is specifically configured to:
[0219] Merge the other field information in the block header of the target block except the auxiliary information field and perform a hash operation to obtain a packaged hash, wherein the other field information at least includes the global snapshot flags of the multiple sub-blockchains, the transaction root hash of the transaction data, and the block hash of the longest clock block pointed to by the target block, wherein the longest clock block pointed to by the target block is a legal block with the maximum logical clock monitored by the node when generating the target block;
[0220] Processing the packaged hash using a verifiable delay function to obtain a verifiable output result;
[0221] Based on the verifiable output result, determine the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof;
[0222] The target block is obtained based on the other field information, the verifiable output result, the parent block hash, the parent block proof and the transaction data.
[0223] Optionally, the matching module 1101 is further configured to:
[0224] Merging the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation, and before obtaining the packaged hash, taking a global snapshot of the multiple sub-block chains to obtain the latest valid block in each valid block sequence;
[0225] Based on the block hashes of the latest valid blocks obtained, construct a first Merkle tree corresponding to the global snapshot;
[0226] The root hash of the first Merkle tree is used as a global snapshot mark of the multiple sub-blockchains.
[0227] Optionally, the matching module 1101 is further configured to:
[0228] Merging the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation, and constructing a second Merkle tree based on the transaction data before obtaining the packaged hash;
[0229] The root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
[0230] Optionally, the matching module 1101 is further configured to:
[0231] Before determining the target child blockchain to which the target block belongs, the corresponding parent block in the target child blockchain, and the corresponding parent block hash and parent block proof based on the verifiable output result, the verifiable output result is encrypted and hashed to obtain a verifiable output hash;
[0232] Determining that the verifiable output hash is less than the block generation difficulty.
[0233] Optionally, the matching module 1101 is specifically configured to:
[0234] Using the verifiable output hash, taking a modulo of the total number of the plurality of sub-blockchains, to determine the target sub-blockchain to which the target block belongs;
[0235] The valid block corresponding to the target child blockchain in the global snapshot is used as the parent block of the target block in the target child blockchain, and the parent block hash and parent block proof of the parent block are obtained.
[0236] Optionally, the verifiable output result includes verifiable output content and verifiable output proof;
[0237] The matching module 1101 is also used for:
[0238] Based on the verifiable output result, after determining the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof, the target block hash of the target block is generated based on the block hash of the longest clock block pointed to by the target block, the global snapshot flag, the transaction root hash, the verifiable output content, and the parent block hash.
[0239] Optionally, the matching module 1101 is further configured to:
[0240] Receive the target block sent by other nodes, and obtain the verifiable output result corresponding to the target block, the parent block hash of the parent block, the parent block proof of the parent block, and the global snapshot flag from the block header of the target block;
[0241] Based on the verifiable output result, the parent block hash, the parent block proof and the global snapshot flag, perform basic verification on the target block;
[0242] Based on the verifiable output result corresponding to the target block, perform a difficulty check on the target block;
[0243] Based on the logical clock of the target block and the logical clock of the parent block, the clock of the target block is checked.
[0244] Optionally, the screening module 1102 is specifically used for:
[0245] For the multiple sub-blockchains, perform the following steps respectively:
[0246] Starting from the genesis block of a sub-blockchain and extending in the direction of the sub-blocks, blocks corresponding to the maximum weight block subtree are selected in sequence as valid blocks until there are no extended blocks, and a valid block sequence consisting of the selected valid blocks is obtained, wherein the block subtree of a block includes the block and other block subtrees extending along the block, the weight of the block subtree is the sum of the block weights of each block in the block subtree, and the block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash.
[0247] Optionally, the screening module 1102 is specifically used for:
[0248] Each time a block corresponding to the maximum weight block subtree is selected as a valid block, the following steps are included:
[0249] For a first valid block most recently selected in the one sub-blockchain, determine, from the one sub-blockchain, at least one candidate sub-block connected to the first valid block, and a block sub-tree corresponding to each of the at least one candidate sub-block;
[0250] Determine the weight of the block subtree corresponding to each of the at least one candidate subblock, and determine a maximum weight block subtree from each block subtree based on the obtained weight;
[0251] A candidate subblock corresponding to the maximum weight block subtree among the at least one candidate subblock is used as a second valid block.
[0252] Optionally, the sorting module 1103 is specifically used to:
[0253] Obtain a target valid block from each valid block sequence respectively;
[0254] Based on the obtained logical clocks corresponding to the various target valid blocks, the various target valid blocks are globally sorted to obtain a global blockchain.
[0255] Optionally, the screening module 1102 is further used for:
[0256] For each valid block, the following steps are performed respectively:
[0257] If the weight of the block subtree corresponding to a block is greater than or equal to the stability threshold, the block is regarded as a stable block;
[0258] If the weight of the block subtree corresponding to the block is less than the stability threshold, the block is regarded as an unstable block.
[0259] Optionally, the sorting module 1103 is specifically used to:
[0260] Get the latest stable block from each valid block sequence respectively;
[0261] Obtain the minimum logical clock from the logical clocks corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary;
[0262] Filtering out, from each stable block, a target stable block whose logic clock is less than or equal to the block clock boundary;
[0263] Based on the logical clocks corresponding to the obtained target stable blocks, the target stable blocks are globally sorted to obtain a global blockchain.
[0264] Optionally, the sorting module 1103 is specifically used to:
[0265] According to the order of logical clocks from small to large, the target stable blocks are globally sorted to obtain a preliminary sorting result;
[0266] If there are target stable blocks with the same logical clock in the preliminary sorting result, the target stable blocks with the same logical clock are sorted based on the sub-blockchain number or block hash to obtain the global blockchain.
[0267] In the embodiment of the present application, since multiple sub-blockchains can share the processing power of high-concurrency blocks in a large-scale network environment, the global blockchain is obtained by adopting a multi-chain consensus method, which can improve the scalability and transaction throughput of the blockchain system in a large-scale open network environment. Secondly, the logical clock corresponding to each block provides a more reliable measurement of the timing relationship between blocks. Therefore, based on the logical clock corresponding to each valid block, when each valid block is globally sorted to obtain a global blockchain, the security of the multi-chain system can be better improved, and it is also convenient for the multi-chain system to be further optimized based on this.
[0268] Based on the same technical concept, the embodiment of the present application provides a computer device, such as Fig.12 As shown, it includes at least one processor 1201 and a memory 1202 connected to the at least one processor. The specific connection medium between the processor 1201 and the memory 1202 is not limited in the embodiment of the present application. Fig.12 For example, the processor 1201 and the memory 1202 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0269] In an embodiment of the present application, the memory 1202 stores instructions that can be executed by at least one processor 1201, and the at least one processor 1201 can execute the steps of the above-mentioned blockchain consensus method by executing the instructions stored in the memory 1202.
[0270] Among them, the processor 1201 is the control center of the computer device, which can use various interfaces and lines to connect various parts of the computer device, and realize the blockchain consensus by running or executing instructions stored in the memory 1202 and calling the data stored in the memory 1202. Optionally, the processor 1201 may include one or more processing units, and the processor 1201 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1201. In some embodiments, the processor 1201 and the memory 1202 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0271] Processor 1201 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.
[0272] Memory 1202, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 1202 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic memory, disk, optical disk, etc. Memory 1202 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 1202 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0273] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned blockchain consensus method.
[0274] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0275] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0276] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0277] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0278] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0279] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A blockchain consensus method, applied to any node in a blockchain system, characterized in that: include: Determine a target sub-blockchain to which a target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain, wherein the target block is generated based on transaction data or obtained synchronously from other nodes; For the multiple sub-blockchains, the following steps are performed respectively: starting from the genesis block of a sub-blockchain, extending along the sub-block direction, sequentially selecting blocks corresponding to the maximum weight block subtree as valid blocks, until there are no extended blocks, and obtaining a valid block sequence composed of the selected valid blocks, wherein the block subtree of a block includes the block and other block subtrees extending along the block, the weight of the block subtree is the sum of the block weights of each block in the block subtree, and the block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash; Based on the obtained logical clocks corresponding to each valid block, the valid blocks are globally sorted to obtain a global blockchain; the logical clock of the valid block is: starting from the valid block, the number of blocks passed along the logical clock path corresponding to the valid block to the genesis block, wherein the logical clock path corresponding to the valid block is: starting from the valid block, the path extending to the genesis block along the direction pointing to the longest clock block.
2. The method according to claim 1, characterized in that The target block is generated based on transaction data, including: Merge the other field information in the block header of the target block except the auxiliary information field and perform a hash operation to obtain a packaged hash, wherein the other field information at least includes the global snapshot flags of the multiple sub-blockchains, the transaction root hash of the transaction data, and the block hash of the longest clock block pointed to by the target block, wherein the longest clock block pointed to by the target block is a legal block with the maximum logical clock monitored by the node when generating the target block; Processing the packaged hash using a verifiable delay function to obtain a verifiable output result; Based on the verifiable output result, determine the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof; The target block is obtained based on the other field information, the verifiable output result, the parent block hash, the parent block proof and the transaction data.
3. The method according to claim 2, characterized in that The step of combining the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation to obtain the packaged hash further includes: Taking a global snapshot of the multiple sub-blockchains to obtain the latest valid block in each valid block sequence; Based on the block hashes of the latest valid blocks obtained, construct a first Merkle tree corresponding to the global snapshot; The root hash of the first Merkle tree is used as a global snapshot mark of the multiple sub-blockchains.
4. The method according to claim 2, characterized in that The step of combining the information of other fields in the block header of the target block except the auxiliary information field and performing a hash operation to obtain the packaged hash further includes: Based on the transaction data, construct a second Merkle tree; The root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
5. The method according to claim 2, characterized in that Before determining the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof based on the verifiable output result, the method further includes: Performing cryptographic hash processing on the verifiable output result to obtain a verifiable output hash; Determining that the verifiable output hash is less than the block generation difficulty.
6. The method according to claim 5, characterized in that The determining, based on the verifiable output result, the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof includes: Using the verifiable output hash, taking a modulo of the total number of the plurality of sub-blockchains, to determine the target sub-blockchain to which the target block belongs; The valid block corresponding to the target child blockchain in the global snapshot is used as the parent block of the target block in the target child blockchain, and the parent block hash and parent block proof of the parent block are obtained.
7. The method according to claim 2, characterized in that The verifiable output result includes verifiable output content and verifiable output proof; After determining the target sub-blockchain to which the target block belongs, the corresponding parent block in the target sub-blockchain, and the corresponding parent block hash and parent block proof based on the verifiable output result, the method further includes: A target block hash of the target block is generated based on the block hash of the longest clock block pointed to by the target block, the global snapshot flag, the transaction root hash, the verifiable output content, and the parent block hash.
8. The method according to claim 1, characterized in that The target block is obtained synchronously from other nodes, including: Receive the target block sent by other nodes, and obtain the verifiable output result corresponding to the target block, the parent block hash of the parent block, the parent block proof of the parent block, and the global snapshot flag from the block header of the target block; Based on the verifiable output result, the parent block hash, the parent block proof and the global snapshot flag, perform basic verification on the target block; Based on the verifiable output result corresponding to the target block, perform a difficulty check on the target block; Based on the logical clock of the target block and the logical clock of the parent block, the clock of the target block is checked.
9. The method according to claim 1, characterized in that Each time a block corresponding to the maximum weight block subtree is selected as a valid block, the following steps are included: For a first valid block most recently selected in the one sub-blockchain, determine, from the one sub-blockchain, at least one candidate sub-block connected to the first valid block, and a block sub-tree corresponding to each of the at least one candidate sub-block; Determine the weight of the block subtree corresponding to each of the at least one candidate subblock, and determine a maximum weight block subtree from each block subtree based on the obtained weight; A candidate subblock corresponding to the maximum weight block subtree among the at least one candidate subblock is used as a second valid block.
10. The method according to claim 1, characterized in that The globally sorting each valid block based on the obtained logical clock corresponding to each valid block to obtain a global blockchain includes: Obtain a target valid block from each valid block sequence respectively; Based on the obtained logical clocks corresponding to the various target valid blocks, the various target valid blocks are globally sorted to obtain a global blockchain.
11. The method according to claim 1, characterized in that Also includes: For each valid block, the following steps are performed respectively: If the weight of the block subtree corresponding to a block is greater than or equal to the stability threshold, the block is regarded as a stable block; If the weight of the block subtree corresponding to the block is less than the stability threshold, the block is regarded as an unstable block.
12. The method according to claim 11, characterized in that The globally sorting each valid block based on the obtained logical clock corresponding to each valid block to obtain a global blockchain includes: Get the latest stable block from each valid block sequence respectively; Obtain the minimum logical clock from the logical clocks corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary; Filtering out, from each stable block, a target stable block whose logic clock is less than or equal to the block clock boundary; Based on the logical clocks corresponding to the obtained target stable blocks, the target stable blocks are globally sorted to obtain a global blockchain.
13. The method according to claim 12, characterized in that The method of globally sorting the target stable blocks based on the obtained logical clocks corresponding to the target stable blocks to obtain a global blockchain includes: According to the order of logical clocks from small to large, the target stable blocks are globally sorted to obtain a preliminary sorting result; If there are target stable blocks with the same logical clock in the preliminary sorting result, the target stable blocks with the same logical clock are sorted based on the sub-blockchain number or block hash to obtain the global blockchain.
14. A blockchain consensus device, applied to any node in a blockchain system, characterized in that: include: A matching module, used to determine a target sub-blockchain to which a target block belongs from multiple sub-blockchains, and add the target block to the target sub-blockchain, wherein the target block is generated based on transaction data or obtained synchronously from other nodes; A screening module is used to respectively perform the following steps for the multiple sub-block chains: starting from the genesis block of a sub-block chain, extending along the sub-block direction, sequentially selecting blocks corresponding to the maximum weight block subtree as valid blocks until there are no extended blocks, and obtaining a valid block sequence composed of the selected valid blocks, wherein the block subtree of a block includes the block and other block subtrees extending along the block, the weight of the block subtree is the sum of the block weights of each block in the block subtree, and the block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash; A sorting module is used to globally sort the valid blocks based on the logical clocks corresponding to the valid blocks to obtain a global blockchain; the logical clock of the valid block is: starting from the valid block, the number of blocks passed along the logical clock path corresponding to the valid block to the genesis block, wherein the logical clock path corresponding to the valid block is: starting from the valid block, the path extending to the genesis block along the direction pointing to the longest clock block.
15. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 13 are implemented.
16. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of any method described in claims 1 to 13.
