WO2023071373A1 - 一种区块链共识方法、装置、设备及存储介质 - Google Patents

一种区块链共识方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2023071373A1
WO2023071373A1 PCT/CN2022/110336 CN2022110336W WO2023071373A1 WO 2023071373 A1 WO2023071373 A1 WO 2023071373A1 CN 2022110336 W CN2022110336 W CN 2022110336W WO 2023071373 A1 WO2023071373 A1 WO 2023071373A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
target
sub
valid
hash
Prior art date
Application number
PCT/CN2022/110336
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 中国银联股份有限公司
Priority to US18/575,811 priority Critical patent/US20240163121A1/en
Publication of WO2023071373A1 publication Critical patent/WO2023071373A1/zh

Links

Images

Classifications

    • 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/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3236Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
    • H04L9/3239Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions involving non-keyed hash functions, e.g. modification detection codes [MDCs], MD5, SHA or RIPEMD
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • 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/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • 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/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3297Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving time stamps, e.g. generation of time stamps

Definitions

  • Embodiments of the present invention relate to the technical field of blockchain, and in particular, to a blockchain consensus method, device, equipment, and storage medium.
  • Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • 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.
  • the embodiment of the present application provides a block chain consensus method, device, device and storage medium, which are used to improve the scalability and transaction throughput of the block chain system in a large-scale open network environment.
  • the embodiment of this application provides a blockchain consensus method, which is applied to any node in the blockchain system, including:
  • each valid block sequence including at least one valid block
  • the respective valid blocks are globally sorted to obtain a global blockchain.
  • the embodiment of the present application provides a blockchain consensus device, which is applied to any node in the blockchain system, including:
  • a matching module configured to determine the target sub-block chain to which the target block belongs from a plurality of sub-block chains, and add the target block to the target sub-block chain, the target block is based on a transaction Data generated, or obtained synchronously from other nodes;
  • a screening module configured to obtain respective valid block sequences from the plurality of sub-block chains, each valid block sequence including at least one valid block;
  • the sorting module is configured to perform global sorting on the respective valid blocks based on the logical clocks corresponding to the obtained valid blocks to obtain the 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 The logical clock path corresponding to the valid block is: starting from the valid block, extending to the genesis block along the direction of the longest clock block.
  • the matching module is specifically used for:
  • the target block is obtained based on the other field information, the verifiable output result, the parent block hash, the parent block certificate, and the transaction data.
  • the matching module is also used for:
  • the root hash of the first Merkle tree is used as the global snapshot mark of the plurality of sub-blockchains.
  • the matching module is also used for:
  • the root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
  • the matching module is also used for:
  • the verifiable output result Based on the verifiable output result, determine the target sub-block chain to which the target block belongs, the corresponding parent block in the target sub-block chain, and the corresponding parent block hash and parent block Before the block certification, the verifiable output result is encrypted and hashed to obtain the verifiable output hash;
  • the matching module is specifically used for:
  • the verifiable output result includes verifiable output content and verifiable output certificate
  • the matching module is also used for:
  • the target sub-block chain to which the target block belongs, the corresponding parent block in the target sub-block chain, and the corresponding parent block hash and parent block certificate Afterwards, 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, generate The target block hash of the target block.
  • the matching module is also used for:
  • a clock check is performed on the target block based on the logical clock of the target block and the logical clock of the parent block.
  • the screening module is specifically used for:
  • the block subtree of a block includes the one block and other block subtrees extending along the one block, and the weight of the block subtree is the block The sum of the block weights of each block in the block subtree, where the block weight of each block is the verifiable output hash of each block, or a preset ratio of the verifiable output hash.
  • the screening module is specifically used for:
  • Selecting the block corresponding to the block subtree with the largest weight each time as a valid block includes the following steps:
  • For the latest selected first valid block in the one sub-block chain determine at least one candidate sub-block connected to the first valid block from the one sub-block chain, and the at least A block subtree corresponding to each candidate sub-block;
  • the sorting module is specifically used for:
  • the target valid blocks are globally sorted to obtain a global blockchain.
  • the screening module is also used for:
  • the block is regarded as a stable block
  • the one block is regarded as an unstable block.
  • the sorting module is specifically used for:
  • the target stable blocks are globally sorted to obtain the global blockchain.
  • the sorting module is specifically used for:
  • the embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored on the memory and operable on the processor, and the above-mentioned block chain consensus is realized when the processor executes the program. method steps.
  • 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, and when the program is run on the computer device, the computer device executes the aforementioned blockchain consensus method steps.
  • an embodiment of the present application provides a computer program product
  • the computer program product includes a computer program stored on a computer-readable storage medium
  • the computer program includes program instructions, and when the program instructions are executed by a computer device , making the computer device execute the steps of the above block chain consensus method.
  • multiple sub-blockchains can share the processing capacity of high-concurrency blocks in a large-scale network environment. Therefore, the use of multi-chain consensus to obtain the global Scalability and transaction throughput in network environment.
  • the logical clocks corresponding to each block provide a more reliable measurement of the timing relationship between the blocks. Therefore, based on the logical clocks corresponding to each valid block, when the global blockchain is obtained by globally sorting each valid block, It can better improve the security of the multi-chain system, and also facilitate the further optimization of the multi-chain system based on this.
  • FIG. 1 is a schematic diagram of a system architecture applicable to an embodiment of the present application
  • Fig. 2 is a schematic flow chart of a block chain consensus method provided by the embodiment of the present application.
  • FIG. 3 is a schematic diagram of a parallel multi-chain architecture provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of a parallel multi-chain architecture provided by an embodiment of the present application.
  • FIG. 5 is a schematic flowchart of a method for generating a target block provided by an embodiment of the present application
  • FIG. 6 is a schematic diagram of a block structure provided by an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a sub-blockchain provided by the embodiment of the present application.
  • FIG. 8 is a schematic diagram of a parallel multi-chain architecture provided by an embodiment of the present application.
  • FIG. 9 is a schematic diagram of a parallel multi-chain architecture provided by an embodiment of the present application.
  • FIG. 10 is a schematic flow diagram of a block chain consensus method provided by the embodiment of the present application.
  • FIG. 11 is a schematic structural diagram of a block chain consensus device provided by an embodiment of the present application.
  • FIG. 12 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • Blockchain A new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • Blockchain (Blockchain), essentially a decentralized database, is a series of data blocks associated with each other using cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify its Validity of information (anti-counterfeiting) and generation of the next block.
  • the blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.
  • VDF Verifiable Delay Function, verifiable delay function.
  • a new type of cryptographic primitive whose execution time is determined, independent of the number of cores of the central processing unit (CPU) of the node, and for a given input, its execution result is unique and verifiable.
  • GHOST Greedy Heaviest Observed Sub-Tree, ghost protocol or heaviest sub-chain protocol.
  • Merkle Tree Merkle tree, a data structure organization method, and outputs a unique value (usually a hash).
  • the basic method is to sort the data set, and perform hash operations in a level-by-level merge until a unique value is formed. .
  • the number of sequences should be a power of 2, and the insufficient part can be completed by repeating the value of the leaf node.
  • Gossip protocol A message dissemination protocol, that is, a node broadcasts to its surrounding nodes, relays the transmission, and finally makes the information cover the entire network. It is currently a typical message dissemination method in the blockchain network.
  • PoW Proof of Work
  • Proof of Work A consensus mechanism in which nodes submit blocks by competing for hash results that meet certain conditions.
  • Figure 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 N nodes, which are respectively nodes 100-1, nodes 100-2, ..., Nodes 100 ⁇ N, N is a positive integer, any two nodes in the blockchain system can communicate and connect to jointly maintain the blockchain system, wherein any two nodes can be connected by wire or wirelessly , without limitation.
  • the nodes in the blockchain system can have various functions. For example, routing function, transaction function, consensus function, etc. Specifically, nodes in the blockchain system can transmit information such as transaction data transmitted by other nodes to more nodes to achieve communication between nodes; or, nodes in the blockchain system can be used to record history All transactions on the blockchain; or, nodes in the blockchain system can generate new blocks in the blockchain by verifying and recording transactions.
  • routing function For example, routing function, transaction function, consensus function, etc.
  • nodes in the blockchain system can transmit information such as transaction data transmitted by other nodes to more nodes to achieve communication between nodes; or, nodes in the blockchain system can be used to record history All transactions on the blockchain; or, nodes in the blockchain system can generate new blocks in the blockchain by verifying and recording transactions.
  • a node in the blockchain system may be a physical machine (server), or a process or a series of processes running in the server, which is not specifically limited in this application.
  • 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 data to any node in the blockchain system, and a certain node in the blockchain system can synchronize the transaction data to the blockchain system after receiving the transaction data other nodes in the .
  • a node After a node receives the transaction data, it can also store the transaction data in the transaction pool inside the node; correspondingly, other nodes can also store the transaction data in other nodes after receiving the transaction data synchronized by the node in the transaction pool. In this way, if a node determines to process multiple transaction data, it can obtain multiple transaction data from the internal transaction pool, and then perform subsequent transaction processing and block consensus.
  • the node for any node in the blockchain system shown in Figure 1, the node generates the target block based on the transaction data, or obtains the target block synchronously from other nodes. Then, from the plurality of sub-block chains, determine the target sub-block chain to which the target block belongs, and add the target block to the target sub-block chain. Then respectively obtain corresponding valid block sequences from the plurality of sub-block chains, each valid block sequence including at least one valid block. Afterwards, based on the logical clocks corresponding to each valid block obtained, each valid block is globally sorted to obtain a global blockchain.
  • the use of multi-chain consensus to obtain the global blockchain can improve the performance of the blockchain system on a large scale. Scalability and transaction throughput in an open network environment.
  • the logical clocks corresponding to each block provide a more reliable measurement of the timing relationship between the blocks. Therefore, based on the logical clocks corresponding to each valid block, when the global blockchain is obtained by globally sorting each valid block, It can better improve the security of the multi-chain system, and also facilitate the further optimization of the multi-chain system based on this.
  • the embodiment of the present application provides a flow of a block chain consensus method, as shown in Figure 2, the flow of the method can be any of the block chain systems shown in Figure 1 A node executes, including the following steps:
  • Step S201 from a plurality of sub-blockchains, determine the target sub-blockchain to which the target block belongs, and add the target block to the target sub-blockchain.
  • multiple sub-blockchains are multiple parallel single chains, and the number of multiple sub-blockchains can be set according to actual conditions. Specifically, when setting up, 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 capabilities of the nodes. The larger the scale of the blockchain network, the number of sub-blockchains should also be Increase accordingly, but not excessively expand the number of sub-blockchains to prevent system performance degradation. Genesis blocks in multiple sub-blockchains may or may not be the same. The child blockchain may or may not contain forked blocks.
  • 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 Genesis Block G0, Block C01, Block C02, Block C03, Block C04, Block C05, and Block C06.
  • the sub-block chain C1 includes the genesis block G1, block C11, block C12, block C13, block C14, block C15, and block C16.
  • Sub-block chain C2 includes genesis block G2, block C21, block C22, block C23, block C24, block C25, and block C26.
  • all nodes in the blockchain system start from the public genesis block and the same configuration file, initialize the protocol, and then start packaging and generating new blocks or synchronizing blocks generated by other nodes , where the relevant initialization parameters include: block generation difficulty, VDF parameters, the number and number of each sub-block chain, etc.
  • the above target blocks are generated by nodes based on transaction data, or obtained synchronously from other nodes.
  • the VDF execution time should be greater than the average block propagation time of the blockchain network, so that nodes can fully interact, the network can converge quickly, and possible balance attacks on GHOST can be avoided.
  • Step S202 obtaining respective valid block sequences from multiple sub-block chains.
  • each valid block sequence includes at least one valid block, and there is no fork block in at least one valid block. From the sub-blockchain, after obtaining the corresponding valid block sequence, other blocks in the sub-blockchain can be removed, thereby updating the sub-blockchain to the corresponding valid block sequence.
  • Step S203 based on the obtained logical clocks corresponding to each valid block, perform global sorting on each valid block to obtain a global blockchain.
  • the logic clock is used to represent the timing relationship between the blocks.
  • the logical clock of the valid block is the number of blocks (including the valid block, excluding the genesis block) passed along the logical clock path corresponding to the valid block to the genesis block, starting from the valid block, where, The logical clock path corresponding to the valid block is: starting from the valid block, extending to the genesis block along the direction of the longest clock block.
  • the longest clock block pointed to by a block is the legal block with the largest logical clock monitored by the node when generating the block. This block can be the block generated by the node, or it can be synchronized from other nodes obtained block.
  • the initial longest clock block is the Genesis block.
  • 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 Genesis Block G0, Block C01, Block C02, Block C03, Block C04, and Block C05.
  • Sub-block chain C1 includes genesis block G1, block C11, block C12, block C13, block C14, and block C15.
  • Sub-block chain C2 includes genesis block G2, block C21, block C22, block C23, block C24, and block C25.
  • 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
  • the longest clock block pointed to by block C11 is Genesis block G1.
  • each valid block can be globally sorted according to 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 reserved valid blocks according to the order of the logical clock from small to large to obtain a global blockchain. In addition, when there are multiple valid blocks with the same logical clock, multiple valid blocks can be sorted according to the sub-block chain numbers or block hashes corresponding to multiple valid blocks, and finally the global blockchain is output .
  • each time a node adds the obtained block to the corresponding sub-blockchain it will trigger global sorting to obtain the global block chain; Or after a preset number of blocks, trigger the global sorting to obtain the global blockchain.
  • the preset duration and the preset number of blocks can be set according to the actual situation; it can also be when an external trigger command is received. Trigger the global sorting to obtain the global blockchain, which is not specifically limited in this application.
  • the use of multi-chain consensus to obtain the global blockchain can improve the performance of the blockchain system on a large scale. Scalability and transaction throughput in an open network environment.
  • the logical clocks corresponding to each block provide a more reliable measurement of the timing relationship between the blocks. Therefore, based on the logical clocks corresponding to each valid block, when the global blockchain is obtained by globally sorting each valid block, It can better improve the security of the multi-chain system, and also facilitate the further optimization of the multi-chain system based on this.
  • the node adopts at least one of the following implementation methods to generate the target block based on the transaction data, as shown in Figure 5, specifically including the following steps:
  • step S501 hash operation is performed on all field information except the auxiliary information field in the block header of the target block to obtain a packed hash.
  • other field information includes at least the global snapshot flags of multiple sub-blockchains, the transaction root hash of 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
  • the long clock block is the legal block with the largest logical clock monitored by the node when generating the target block.
  • other field information may also include a block hash of at least one sampling block corresponding to the target block.
  • the embodiment of this application adopts at least one of the following implementation methods to obtain the global snapshot flags of multiple sub-blockchains:
  • the obtained latest valid blocks are sorted, specifically, they can be sorted according to the number of the sub-block chain 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. Then use the root hash of the first Merkle tree as the global snapshot mark of multiple sub-blockchains.
  • 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, construct a second Merkle tree, and then use the root hash of the second Merkle tree as the transaction of the transaction data root hash.
  • hash algorithms may be used in the embodiment of the present application to obtain the global snapshot marks of multiple sub-blockchains and the transaction root hash of the transaction data, which is not specifically limited in this application.
  • the information of each field is combined in a determined order, and then the packed hash corresponding to the combined data is calculated.
  • step S502 a verifiable delay function is used to process the packed hash to obtain a verifiable output result.
  • the verifiable delay function can be executed in parallel through multiple threads.
  • different threads correspond to different transaction contents, so as to realize multi-thread parallel participation in VDF, and keep investment and node processing ability to match.
  • 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 certificate.
  • the difficulty verification of the target block may also be performed based on the verifiable output result.
  • the verifiable output result is encrypted and hashed to obtain the verifiable output hash, and then it is judged 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 Step, otherwise, determine that the target block is an illegal block and discard the target block.
  • the block generation difficulty mentioned above can be a fixed value, or it can be adjusted periodically.
  • the verifiable output hash is used to take the modulus of the total number of multiple sub-blockchains to 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 certificate of the parent block.
  • the latest valid block corresponding to the target sub-blockchain in the global snapshot can be obtained, and then the obtained latest valid block Act as the parent block of the target block in the target sub-block chain, and obtain the parent block hash and parent block certificate of the parent block, wherein the parent block certificate can be a Merkle tree certificate.
  • Step S504 obtain the target block based on other field information, verifiable output results, parent block hash, parent block certificate and transaction data.
  • the verifiable output results include verifiable output content and verifiable output certificates.
  • the target block includes block header and block body, block hash of the longest clock block pointing to the target block, global snapshot flag, transaction root hash, verifiable output result, parent block hash, parent zone
  • the block proof is added to the block header, and the transaction data is added to the block body.
  • the data in the target block is not limited to the ones described above, and may include more information fields related to development, which is not specifically limited in this application.
  • FIG. 6 exemplarily shows a block structure, 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, parent block hash, verifiable output proof and parent block proof, etc.
  • the block body includes the transaction data actually entered into the block.
  • a target block hash of the target block is generated, wherein the target block hash is used to uniquely identify the target block.
  • the node after the node obtains the target block, it can broadcast the target block to the network.
  • the blockchain network broadcasting method can use the Gossip protocol and the like. After other blocks receive the target block, they can add the target block to the local target sub-block chain.
  • the node realizes block generation by completing a verifiable delay function of a specific difficulty, and provides a more reliable time relationship measurement between blocks without using the traditional proof-of-work mechanism (PoW), thereby improving Scalability and transaction throughput of blockchain systems in a large-scale open network environment.
  • PoW proof-of-work mechanism
  • the target block may also be obtained synchronously from other nodes.
  • 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, and the parent block hash of the parent block from the block header of the target block.
  • the process of other nodes generating the target block refers to the above step S501 to step S505, and will not be repeated here.
  • the verification process includes one or more of the following processes:
  • the target block is basically verified.
  • the verification can verify whether the output result is correct, and the verification rule is defined by the verifiable delay function itself.
  • 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 take the modulus of the total number of multiple sub-block chains to determine the reference sub-area to which the target block belongs blockchain.
  • the verifiable output result obtained from the block header is encrypted and hashed to obtain the verifiable output hash, and then it is judged whether the verifiable output hash is less than the block generation difficulty, and if so, the target block is determined to be a legal area block, otherwise, determine that the target block is an illegal block and discard the target block.
  • the target block After the target block is verified using one or more of the above verification processes, if it is determined that the target block is a legal block, the target block will be added to the corresponding sub-block chain; if it is determined that the target block is If the block is illegal, the target block is discarded.
  • the node after the node receives the target block sent by other nodes, it performs multi-dimensional verification on the target block, and only adds the target block to the corresponding sub-block chain when the verification passes, thus ensuring Security of the blockchain system.
  • step S202 for multiple sub-blockchains, the corresponding valid block sequences are obtained in the following manner:
  • the block subtree of a block includes the block and other block subtrees extending along the block, and 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 proportion of the verifiable output hash.
  • the block weight of each block is determined based on the verifiable output hash of each block, instead of simply setting the block weight of each block to the same value, thereby improving the convergence speed of the single chain.
  • Figure 7 is a schematic structural diagram 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, Block C09.
  • the block subtree of block C01 includes block C01, block C02, block C03, block C04, block C07, block C08, and block C09.
  • the block subtree The weight of is the sum of the block hashes corresponding to each of the above blocks.
  • selecting a block corresponding to the block subtree with the largest weight each time as a valid block includes the following steps:
  • the candidate sub-block corresponding to the block subtree with the largest weight is used as the second valid block.
  • the genesis block on the sub-block chain is the first valid block, and then the second valid block is sequentially selected along the extension direction of the sub-block chain.
  • the genesis block G0 is used as the first valid block, and the block connected to the genesis block G0 Includes block C01 and block C05.
  • Block subtree 1 of block C01 includes block C01, block C02, block C03, block C04, block C07, block C08, and block C09, block C01, block C02, block C03 , block C04, block C07, block C08, and block C09 respectively correspond to the sum of block hashes as the weight of block subtree 1.
  • the block subtree 2 of block C05 includes block C05 and block C06, and the sum of block hashes corresponding to block C05 and block C06 is used as the weight of block subtree 2. Since the weight of the block subtree 1 is greater than the weight of the block subtree 2, the block subtree 1 is the largest weighted block subtree, and the block C01 corresponding to the block subtree 1 is the second valid block.
  • the block C01 is used as the first valid block, and the blocks connected to the block C01 include the block C02, the block C03 and the block C04.
  • the block subtree 3 of block C02 includes block C02, block C07, and block C08, and the sum of block hashes corresponding to block C02, block C07, and block C08 is used as the block subtree 3 Weights.
  • the block subtree 4 of the block C03 includes the block C03 and the block C09, and the sum of the corresponding block hashes of the block C03 and the block C09 is used as the weight of the block subtree 4 .
  • the block subtree 5 of the block C04 includes the block C04, and the block hash corresponding to the block C04 is used as the weight of the block subtree 5.
  • block subtree 3 Since the weight of block subtree 3 is greater than the corresponding weights of block subtree 4 and block subtree 5, then block subtree 3 is the maximum weight block subtree, then the block corresponding to block subtree 3 C02 is the second valid block.
  • the block C02 is used as the first valid block, and the blocks connected to the block C02 include the block C07 and the block C08.
  • the block subtree 6 of the block C07 includes the block C07, and the block hash corresponding to the block C07 is used as the weight of the block subtree 6.
  • the block subtree 7 of the block C08 includes the block C08, and the block hash corresponding to the block C08 is used as the weight of the block subtree 7.
  • the block subtree 6 Since the weight of the block subtree 6 is greater than that of the block subtree 7, the block subtree 6 is the largest weight block subtree, and the block C07 corresponding to the block subtree 6 is the second valid block.
  • the blocks corresponding to the block subtree with the largest weight are sequentially selected as valid blocks, and a valid block sequence composed of the selected valid blocks is obtained.
  • Using the most important sub-chain idea to carry out VDF-based single-chain transformation 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.
  • the valid blocks in each valid block sequence can be divided into stable blocks and unstable blocks.
  • the block will be regarded as a stable block; if the weight of the block subtree corresponding to a block is less than the stable threshold, the block will be regarded as a stable In the stable block, the stable value threshold is set according to the actual situation.
  • the embodiment of the present application adopts at least the following implementation methods to globally sort the obtained valid blocks to obtain the global blockchain:
  • Embodiment 1 Obtain a target valid block from each valid block sequence; based on the obtained logical clock corresponding to each target valid block, perform global sorting on each target valid block to obtain a global blockchain.
  • a target valid block is randomly obtained from each valid block sequence.
  • the selected target effective screening blocks are globally sorted to obtain the global blockchain.
  • the target valid blocks with the same logical clock are sorted based on sub-block chain numbers or block hashes to obtain the global blockchain.
  • the parallel multi-chain architecture includes a sub-block chain C0, a sub-block chain C1 and a sub-block chain C2, wherein the sub-block Block chain C0 includes genesis block G0 (logic clock: 0), block C01 (logic clock: 1), block C02 (logic clock: 2), block C03 (logic clock: 3), block C04 ( Logical Clock: 4).
  • Sub-block chain C1 includes genesis block G1 (logic clock: 0), block C11 (logic clock: 1), block C12 (logic clock: 3), and block C13 (logic clock: 5).
  • Sub-block chain C2 includes genesis block G2 (logic clock: 0), block C21 (logic clock: 1), block C22 (logic clock: 4), block C23 (logic clock: 5), block C24 (logical clocks: 6).
  • the selected target valid blocks are globally sorted.
  • the target with the same logical clock is sorted according to the order of the sub-block chain numbers from small to large.
  • Valid blocks are sorted, and the obtained global blockchain is: block C01, block C11 and block C22.
  • Embodiment 2 Obtain the latest stable block from each valid block sequence, obtain the minimum logical clock from the logical clock corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary. From each stable block, a target stable block whose logic clock is less than or equal to the block clock boundary is screened out. Based on the obtained logical clocks corresponding to each target stable block, each target stable block is globally sorted to obtain a global blockchain.
  • the global sorting of each target stable block is performed to obtain a preliminary sorting result. If there are target stable blocks with the same logical clock in the preliminary sorting result, then based on the sub-block chain number or block hash, sort the target stable blocks with the same logical clock to obtain the global blockchain.
  • the parallel multi-chain architecture includes a sub-block chain C0, a sub-block chain C1 and a sub-block chain C2, wherein the sub-block Block chain C0 includes genesis block G0 (logic clock: 0), block C01 (logic clock: 1), block C02 (logic clock: 2), block C03 (logic clock: 3), block C04 ( Logical Clock: 4).
  • Sub-block chain C1 includes genesis block G1 (logic clock: 0), block C11 (logic clock: 1), block C12 (logic clock: 3), and block C13 (logic clock: 5).
  • Sub-block chain C2 includes genesis block G2 (logic clock: 0), block C21 (logic clock: 1), block C22 (logic clock: 4), block C23 (logic clock: 5), block C24 (logical clocks: 6).
  • the stable blocks in the sub-block chain C0 are set to include: the genesis block G0 and the block C01, among which the latest stable block is the block C01.
  • the stable blocks in the sub-block chain C1 include: the genesis block G1 and the block C11, among which the latest stable block is the block C11.
  • Stable blocks in sub-blockchain C2 include: Genesis block G2, block C21, and block C22, among which the latest stable block is block C22.
  • the target stable blocks whose logical clock is less than or equal to the block clock boundary include the genesis block G0 and the block C01.
  • the target stable blocks whose logical clock is less than or equal to the block clock boundary include the genesis block G1 and the block C11.
  • the target stable blocks whose logical clock is less than or equal to the block clock boundary include the genesis block G2 and the block C21.
  • the selected target stable blocks are globally sorted.
  • they are sorted according to the order of the sub-block chain numbers from small to large.
  • the target stable blocks are sorted, and the obtained global blockchain is: Genesis Block G0, Genesis Block G1, Genesis Block G2, Block C01, Block C11, and Block C21.
  • the idea of the heaviest sub-chain is adopted to carry out VDF-based single-chain transformation, and the global blockchain is constructed based on the block timing relationship corresponding to the block logic clock, and a more reliable time relationship measurement is introduced, thereby improving multiple
  • the security of the chain system also enables the upper limit of system performance to be further improved within the scope of node processing capabilities.
  • the transactions in each block are executed sequentially 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 it is not executed; otherwise, it is determined The transaction is legal and executed, and the system status is updated at the same time.
  • Step S1001 system protocol initialization.
  • the node first initializes the parameters related to the protocol, 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.
  • the parameters related to the protocol 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.
  • Step S1002 VDF process.
  • the transaction data is obtained from the transaction pool, and the legal block with the largest logical clock detected by the node when generating the target block is used as the longest clock block pointed to by the target block, and the longest clock block is obtained. block hash.
  • 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.
  • Verifiable output results include verifiable output content and verifiable output proof.
  • the verifiable output hash is used to take the modulus of the total number of multiple sub-blockchains to 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 certificate of the parent block.
  • the target block hash of the target block is generated.
  • Step S1003 message broadcast and synchronization.
  • the node broadcasts the target block to other nodes, synchronizes the blocks generated by other nodes, and adds the transaction data in the synchronized block to the transaction pool.
  • Step S1004 block validity verification.
  • the node After the node receives the 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 .
  • Step S1005 adding legal blocks to corresponding sub-block chains.
  • Step S1006 obtain corresponding valid block sequences from multiple sub-block chains respectively.
  • each sub-blockchain starting from the genesis block of the sub-blockchain, extending along the sub-block direction, sequentially select the block corresponding to the subtree of the block with the largest weight as the valid block until there is no extension block, to obtain a valid block sequence composed of selected valid blocks.
  • 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.
  • Each block The block weight of a block is the verifiable output hash of each block, or a preset proportion of verifiable output hashes.
  • Step S1007 globally sort the obtained valid blocks to obtain a global blockchain.
  • valid blocks in each valid block sequence are divided into stable blocks and unstable blocks. Obtain the latest stable block from each valid block sequence respectively. Obtain the minimum logical clock from the logical clock corresponding to each latest stable block, and use the minimum logical clock as the block clock boundary; from each stable block, filter out the target stable block whose logical clock is less than or equal to the block clock boundary .
  • Step S1008 execute transactions in each block in the global blockchain.
  • Step S1009 update the system status, go to step S1002.
  • the use of multi-chain consensus to obtain the global blockchain can improve the performance of the blockchain system on a large scale. Scalability and transaction throughput in an open network environment.
  • the logical clocks corresponding to each block provide a more reliable measurement of the timing relationship between the blocks. Therefore, based on the logical clocks corresponding to each valid block, when the global blockchain is obtained by globally sorting each valid block, It can better improve the security of the multi-chain system, and also facilitate the further optimization of the multi-chain system based on this.
  • the embodiment of this application provides a schematic structural diagram of a blockchain consensus device, which is applied to any node in the blockchain system.
  • the device 1100 includes:
  • Matching module 1101 configured to determine the target sub-block chain to which the target block belongs from among multiple sub-block chains, and add the target block to the target sub-block chain, the target block is based on Generated by transaction data, or obtained synchronously from other nodes;
  • a screening module 1102 configured to obtain respective valid block sequences from the plurality of sub-block chains, each valid block sequence including at least one valid block;
  • the sorting module 1103 is configured to perform global sorting on each valid block based on the obtained logic clock corresponding to each valid block, and 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 The logical clock path corresponding to the valid block is: starting from the valid block, extending to the genesis block along the direction of the longest clock block.
  • the matching module 1101 is specifically configured to:
  • the target block is obtained based on the other field information, the verifiable output result, the parent block hash, the parent block certificate, and the transaction data.
  • the matching module 1101 is also used for:
  • the root hash of the first Merkle tree is used as the global snapshot mark of the plurality of sub-blockchains.
  • the matching module 1101 is also used for:
  • the root hash of the second Merkle tree is used as the transaction root hash of the transaction data.
  • the matching module 1101 is also used for:
  • the verifiable output result Based on the verifiable output result, determine the target sub-block chain to which the target block belongs, the corresponding parent block in the target sub-block chain, and the corresponding parent block hash and parent block Before the block certification, the verifiable output result is encrypted and hashed to obtain the verifiable output hash;
  • the matching module 1101 is specifically configured to:
  • the verifiable output result includes verifiable output content and verifiable output certificate
  • the matching module 1101 is also used for:
  • the target sub-block chain to which the target block belongs, the corresponding parent block in the target sub-block chain, and the corresponding parent block hash and parent block certificate Afterwards, 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, generate The target block hash of the target block.
  • the matching module 1101 is also used for:
  • a clock check is performed on the target block based on the logical clock of the target block and the logical clock of the parent block.
  • the screening module 1102 is specifically configured to:
  • the genesis block of a sub-block chain Starting from the genesis block of a sub-block chain, extending along the sub-block direction, sequentially select the block corresponding to the subtree of the block with the largest weight as a valid block until there is no extension block, and obtain the selected valid block
  • the screening module 1102 is specifically configured to:
  • Selecting the block corresponding to the block subtree with the largest weight each time as a valid block includes the following steps:
  • For the latest selected first valid block in the one sub-block chain determine at least one candidate sub-block connected to the first valid block from the one sub-block chain, and the at least A block subtree corresponding to each candidate sub-block;
  • the sorting module 1103 is specifically configured to:
  • the target valid blocks are globally sorted to obtain a global blockchain.
  • the screening module 1102 is also used for:
  • the block is regarded as a stable block
  • the one block is regarded as an unstable block.
  • the sorting module 1103 is specifically configured to:
  • the target stable blocks are globally sorted to obtain a global blockchain.
  • the sorting module 1103 is specifically configured to:
  • the use of multi-chain consensus to obtain the global blockchain can improve the performance of the blockchain system on a large scale. Scalability and transaction throughput in an open network environment.
  • the logical clocks corresponding to each block provide a more reliable measurement of the timing relationship between the blocks. Therefore, based on the logical clocks corresponding to each valid block, when the global blockchain is obtained by globally sorting each valid block, It can better improve the security of the multi-chain system, and also facilitate the further optimization of the multi-chain system based on this.
  • the embodiment of the present application provides a computer device, as shown in Figure 12, including at least one processor 1201, and a memory 1202 connected to the at least one processor, the processor is not limited in the embodiment of the present application
  • the specific connection medium between 1201 and memory 1202 is, for example, the bus connection between processor 1201 and memory 1202 in FIG. 12 .
  • the bus can be divided into address bus, data bus, control bus and so on.
  • the memory 1202 stores instructions executable by at least one processor 1201, and at least one processor 1201 can execute the steps of the blockchain consensus method above by executing the instructions stored in the memory 1202.
  • the processor 1201 is the control center of the computer equipment, which can use various interfaces and lines to connect various parts of the computer equipment, by running or executing the instructions stored in the memory 1202 and calling the data stored in the memory 1202, thereby realizing the district Blockchain consensus.
  • the processor 1201 may include one or more processing units, and the processor 1201 may integrate an application processor and a modem processor.
  • the tuner processor mainly handles wireless communication. It can be understood that the foregoing modem processor may not be integrated into the processor 1201 .
  • the processor 1201 and the memory 1202 can be implemented on the same chip, and in some embodiments, they can also be implemented on independent chips.
  • the processor 1201 can be a general processor, such as a central processing unit (CPU), a digital signal processor, an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array or other programmable logic devices, discrete gates or transistors Logic devices and discrete hardware components can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application.
  • a general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the methods disclosed in connection with the embodiments of the present application may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
  • the memory 1202 can be used to store non-volatile software programs, non-volatile computer-executable programs and modules.
  • the memory 1202 may include at least one type of storage medium, for example, may include flash memory, hard disk, multimedia card, card memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), Programmable Read Only Memory (PROM), Read Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Magnetic Memory, Disk , CD, etc.
  • Memory 1202 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
  • the memory 1202 in this embodiment of the present application may also be a circuit or any other device capable of implementing a storage function, and is used for storing program instructions and/or data.
  • 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.
  • the computer device executes the above-mentioned block chain consensus method. step.
  • an embodiment of the present application provides a computer program product, the computer program product includes a computer program stored on a computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by the computer When the device executes, the computer device is made to execute the steps of the above block chain consensus method.
  • the embodiments of the present invention may be provided as methods or computer program products. Accordingly, the present invention can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions
  • the device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例提供了一种区块链共识方法、装置、设备及存储介质,涉及区块链技术领域,该方法包括:节点基于交易数据和可验证延迟函数生成目标区块,或者从其他节点同步获得目标区块。从多个子区块链中,确定目标区块所属的目标子区块链,并将目标区块添加至目标子区块链。然后分别从多个子区块链中,获得各自对应的有效区块序列。再基于获得的各个有效区块各自对应的逻辑时钟,对各个有效区块进行全局排序,获得全局区块链。采用多链共识的方式获得全局区块链,提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升多链系统的安全性。

Description

一种区块链共识方法、装置、设备及存储介质
相关申请的交叉引用
本申请要求在2021年10月30日提交中国专利局、申请号为202111277507.8、申请名称为“一种区块链共识方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明实施例涉及区块链技术领域,尤其涉及一种区块链共识方法、装置、设备及存储介质。
背景技术
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链共识协议是底层区块链平台的关键技术,直接决定区块链系统的安全性和系统性能。
传统共识协议(如:Raft协议、实用拜占庭容错协议(Practical Byzantine Fault Tolerance,简称PBFT))或其改进协议多基于状态机复制的协同方法进行一致性达成。然而,传统共识方案具有较高的通讯复杂度,系统交易性能随着网络节点规模的上升而明显下降,因此多应用于小规模联盟链网络中,难以适应应用节点不断增多的区块链网络环境。
发明内容
本申请实施例提供了一种区块链共识方法、装置、设备及存储介质,用于提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。
一方面,本申请实施例提供了一种区块链共识方法,应用于区块链系统中的任意一个节点,包括:
从多个子区块链中,确定目标区块所属的目标子区块链,并将所述目标区块添加至所述目标子区块链,所述目标区块是基于交易数据生成的,或者从其他节点同步获得的;
分别从所述多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块;
基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链。
一方面,本申请实施例提供了一种区块链共识装置,应用于区块链系统中的任意一个节点,包括:
匹配模块,用于从多个子区块链中,确定目标区块所属的目标子区块链,并将所述目标区块添加至所述目标子区块链,所述目标区块是基于交易数据生成的,或者从其他节点同步获得的;
筛选模块,用于分别从所述多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块;
排序模块,用于基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链。
可选地,所述有效区块的逻辑时钟为:以所述有效区块为起点,沿所述有效区块对应的逻辑时钟路径至创世区块所经过的区块数量,其中,所述有效区块对应的逻辑时钟路径为:以所述有效区块为起点,沿指向最长时钟区块的方向延伸至创世区块的路径。
可选地,所述匹配模块具体用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希,其中,所述其他字段信息至少包括所述多个子区块链的全局快照标志、所述交易数据的交易根哈希和所述目标区块指向的最长时钟区块的区块哈希,其中,所述目标区块指向的最长时钟区块为节点在生成所述目标区块时监测到的具有最大逻辑时钟的合法区块;
采用可验证延迟函数对所述打包哈希进行处理,获得可验证输出结果;
基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明;
基于所述其他字段信息、所述可验证输出结果、所述父区块哈希、所述父区块证明以及所述交易数据,获得所述目标区块。
可选地,所述匹配模块还用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,对所述多个子区块链进行全局快照,获得所述各个有效区块序列中的最新有效区块;
基于获得的各个最新有效区块的区块哈希,构建所述全局快照对应的第一默克尔树;
将所述第一默克尔树的根哈希,作为所述多个子区块链的全局快照标志。
可选地,所述匹配模块还用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,基于所述交易数据,构建第二默克尔树;
将所述第二默克尔树的根哈希,作为所述交易数据的交易根哈希。
可选地,所述匹配模块还用于:
所述基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之前,对所述可验证输出结果进行加密哈希处理,获得可验证输出哈希;
确定所述可验证输出哈希小于区块生成难度。
可选地,所述匹配模块具体用于:
采用所述可验证输出哈希,对所述多个子区块链的总数取模,确定所述目标区块所属的目标子区块链;
将所述目标子区块链在全局快照中对应的有效区块,作为所述目标区块在所述目标子区块链中的父区块,并获取所述父区块的父区块哈希和父区块证明。
可选地,所述可验证输出结果包括可验证输出内容和可验证输出证明;
所述匹配模块还用于:
基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之后,基于所述目标区块指向的最长时钟区块的区块哈希、所述全局快照标志、所述交易根哈希、所述可验证输出内容、所述父区块哈希,生成所述目标区块的目标区块哈希。
可选地,所述匹配模块还用于:
接收其他节点发送的所述目标区块,并从所述目标区块的区块头中获取所述目标区块对应的可验证输出结果、父区块的父区块哈希、父区块的父区块证明和全局快照标志;
基于所述可验证输出结果、所述父区块哈希、所述父区块证明和所述全局快照标志,对所述目标区块进行基础校验;
基于所述目标区块对应的可验证输出结果,对所述目标区块进行难度校验;
基于所述目标区块的逻辑时钟和所述父区块的逻辑时钟,对所述目标区块进行时钟校验。
可选地,所述筛选模块具体用于:
针对所述多个子区块链,分别执行以下步骤:
从一个子区块链的创世区块开始,沿子区块方向延伸,依次选取对应最大权重区块子树的区块作为有效区块,直至无延伸区块,获得由选取的有效区块组成的有效区块序列,其中,一个区块的区块子树包括所述一个区块以及沿所述一个区块延伸的其他区块子树,所述区块子树的权重为所述区块子树中各个区块的区块权重之和,每个区块的区块权重是每个区块的可验证输出哈希,或者所述可验证输出哈希的预设比例。
可选地,所述筛选模块具体用于:
每次选取对应最大权重区块子树的区块作为有效区块,包括以下步骤:
针对所述一个子区块链中最新选取的第一有效区块,从所述一个子区块链中,确定与所述第一有效区块连接的至少一个候选子区块,以及所述至少一个候选子区块各自对应的区块子树;
确定所述至少一个候选子区块各自对应的区块子树的权重,并基于获得的权重从各个区块子树中,确定最大权重区块子树;
将所述至少一个候选子区块中,对应所述最大权重区块子树的候选子区块,作为第二有效区块。
可选地,所述排序模块具体用于:
分别从各个有效区块序列中获取一个目标有效区块;
基于获得的各个目标有效区块对应的逻辑时钟,对所述各个目标有效区块进行全局排序,获得全局区块链。
可选地,所述筛选模块还用于:
针对所述各个有效区块,分别执行以下步骤:
若一个区块对应的区块子树的权重大于等于稳定阈值,则将所述一个区块作为稳定区块;
若所述一个区块对应的区块子树的权重小于稳定阈值,则将所述一个区块作为不稳定区块。
可选地,所述排序模块具体用于:
分别从各个有效区块序列中获取最新稳定区块;
从各个最新稳定区块对应的逻辑时钟中获得最小逻辑时钟,并将所述最小逻辑时钟作为区块时钟边界;
从各个稳定区块中,筛选出逻辑时钟小于或等于所述区块时钟边界的目标稳定区块;
基于获得的各个目标稳定区块对应的逻辑时钟,对所述各个目标稳定区块进行全局排 序,获得全局区块链。
可选地,所述排序模块具体用于:
按照逻辑时钟从小到大的顺序,对所述各个目标稳定区块进行全局排序,获得初步排序结果;
若所述初步排序结果中存在逻辑时钟相同的目标稳定区块,则基于子区块链编号或区块哈希,对所述逻辑时钟相同的目标稳定区块进行排序,获得全局区块链。
一方面,本申请实施例提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述区块链共识方法的步骤。
一方面,本申请实施例提供了一种计算机可读存储介质,其存储有可由计算机设备执行的计算机程序,当所述程序在计算机设备上运行时,使得所述计算机设备执行上述区块链共识方法的步骤。
一方面,本申请实施例提供了一种计算机程序产品,所述计算机程序产品包括存储在计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机设备执行时,使所述计算机设备执行上述区块链共识方法的步骤。
本申请实施例中,多个子区块链可以分摊大规模网络环境下高并发区块的处理能力,因此,采用多链共识的方式获得全局区块链,可以提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。其次,各个区块对应的逻辑时钟,为区块之间提供了更加可靠的时序关系度量,故基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升了多链系统的安全性,也便于多链系统基于此做进一步的优化。
附图说明
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例适用的一种系统架构示意图;
图2为本申请实施例提供的一种区块链共识方法的流程示意图;
图3为本申请实施例提供的一种平行多链架构的示意图;
图4为本申请实施例提供的一种平行多链架构的示意图;
图5为本申请实施例提供的一种生成目标区块的方法的流程示意图;
图6为本申请实施例提供的一种区块结构的示意图;
图7为本申请实施例提供的一种子区块链的结构示意图;
图8为本申请实施例提供的一种平行多链架构的示意图;
图9为本申请实施例提供的一种平行多链架构的示意图;
图10为本申请实施例提供的一种区块链共识方法的流程示意图;
图11为本申请实施例提供的一种区块链共识装置的结构示意图;
图12为本申请实施例提供的一种计算机设备的结构示意图。
具体实施方式
为了使本发明的目的、技术方案及有益效果更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。
为了方便理解,下面对本发明实施例中涉及的名词进行解释。
区块链:一种分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层。
VDF:Verifiable Delay Function,可验证延迟函数。一种新型密码学原语,其执行过程时间确定,与节点中央处理器(central processing unit,简称CPU)核心数无关,且对于给定输入,其执行结果唯一且可验证。
GHOST:Greedy Heaviest Observed Sub-Tree,幽灵协议或最重子链协议。一种对工作量证明进行改进的共识规则,即从创世块开始按顺序逐级取最重子树对应区块作为当前区块。
Merkle Tree:默克尔树,一种数据结构组织方法,并输出唯一值(一般为哈希),基本方法是将数据集进行排序,采用逐级合并的方式做哈希运算直至形成一个唯一数值。序列数量以2的次方为佳,不足部分可通过重复叶子节点数值进行补全。
Gossip协议:一种消息传播协议,即某节点向其周围节点进行广播,接力传播,最终使信息覆盖整个网络,目前是区块链网络中典型消息传播方式。
PoW:Proof of Work,工作量证明。一种共识机制,节点通过竞争满足特定条件的哈希运算结果进行区块的提交。
图1为本发明实施例提供的一种区块链系统的架构示意图,如图1所示,区块链系统中可以包括N个节点,分别为节点100~1、节点100~2、…、节点100~N,N为正整数,区块链系统中任意两个节点可以通信连接,从而共同维护区块链系统,其中,任意两个节点可以通过有线方式连接,或者也可以通过无线方式连接,具体不作限定。
本发明实施例中,区块链系统中的节点可以具有多种功能。比如,路由功能、交易功能、共识功能等。具体地说,区块链系统中的节点可以把其他节点传送过来的交易数据等信息传送给更多的节点以实现节点之间的通信;或者,区块链系统中的节点可以用于记录历史上的所有交易;或者,区块链系统中的节点可以通过验证和记录交易从而生成区块链中的新区块。
需要说明的是,区块链系统中的一个节点可以是一台物理机(服务器),也可以是服务器中运行的一个进程或者一系列进程,对此,本申请具体不作限定。
如图1所示,该系统架构中还可以包括客户端设备200,客户端设备200可以通过接入区块链网络与区块链系统中的任一节点连接。具体实施中,客户端设备200可以将交易数据发送给区块链系统中的任一节点,区块链系统中的某一节点在接收到交易数据后,可以将交易数据同步给区块链系统中的其它节点。某一节点在接收到交易数据后,还可以将交易数据存储在节点内部的交易池中;相应地,其它节点在接收到该节点同步的交易数据后,也可以将交易数据存储在其它节点内部的交易池中。如此,若某一节点确定处理多条 交易数据,则可以从内部的交易池中获取多条交易数据,进而进行后续的交易处理及区块共识。
在本申请实施例中,针对图1所示的区块链系统中的任意一个节点,节点基于交易数据生成目标区块,或者从其他节点同步获得目标区块。然后从多个子区块链中,确定目标区块所属的目标子区块链,并将目标区块添加至目标子区块链。然后分别从多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块。之后再基于获得的各个有效区块各自对应的逻辑时钟,对各个有效区块进行全局排序,获得全局区块链。
本申请实施例中,由于多个子区块链可以分摊大规模网络环境下高并发区块的处理能力,因此,采用多链共识的方式获得全局区块链,可以提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。其次,各个区块对应的逻辑时钟,为区块之间提供了更加可靠的时序关系度量,故基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升了多链系统的安全性,也便于多链系统基于此做进一步的优化。
基于图1所示的系统架构图,本申请实施例提供了一种区块链共识方法的流程,如图2所示,该方法的流程可以由图1所示的区块链系统中的任意一个节点执行,包括以下步骤:
步骤S201,从多个子区块链中,确定目标区块所属的目标子区块链,并将目标区块添加至目标子区块链。
具体地,多个子区块链为多个平行的单链,多个子区块链的数量可以根据实际情况进行设置。具体在进行设置时,多个子区块链的数量取决于对实际参与区块链网络的节点规模和节点本地物理运算能力的估计,区块链网络规模越大,子区块链的数量也应相应提升,但不能过度扩展子区块链的数量以防止系统性能下降。多个子区块链中的创世区块可以相同,也可以不相同。子区块链中可能包含分叉区块,也可能不包含分叉区块。
举例来说,参见图3,为本申请实施例提供的一种平行多链架构,平行多链架构包括子区块链C0、子区块链C1和子区块链C2,其中,子区块链C0包括创世区块G0、区块C01、区块C02、区块C03、区块C04、区块C05、区块C06。子区块链C1包括创世区块G1、区块C11、区块C12、区块C13、区块C14、区块C15、区块C16。子区块链C2包括创世区块G2、区块C21、区块C22、区块C23、区块C24、区块C25、区块C26。
在进行区块链共识之前,区块链系统中的所有节点均从公共的创世区块和相同配置文件出发,进行协议的初始化,然后开始新区块的打包生成或者同步其他节点生成的区块,其中,相关初始化参数包括:区块生成难度、VDF参数、各子区块链的数量和编号等。上述目标区块是节点基于交易数据生成的,或者从其他节点同步获得的。在对VDF参数的设置,应使VDF执行时间大于区块链网络的平均区块传播时间,以使节点充分交互,网络快速收敛,避免可能的对GHOST的平衡攻击。
步骤S202,分别从多个子区块链中,获得各自对应的有效区块序列。
具体地,每个有效区块序列包括至少一个有效区块,至少一个有效区块中不存在分叉区块。从子区块链中,获得相应的有效区块序列之后,可以去除子区块链中的其他区块,从而将子区块链更新为相应的有效区块序列。
步骤S203,基于获得的各个有效区块各自对应的逻辑时钟,对各个有效区块进行全局 排序,获得全局区块链。
具体地,逻辑时钟用于表征区块之间的时序关系。有效区块的逻辑时钟为以有效区块为起点,沿有效区块对应的逻辑时钟路径至创世区块所经过的区块数量(包括有效区块,不包括创世区块),其中,有效区块对应的逻辑时钟路径为:以有效区块为起点,沿指向最长时钟区块的方向延伸至创世区块的路径。一个区块指向的最长时钟区块为节点在生成该区块时监测到的具有最大逻辑时钟的合法区块,该区块可以是该节点生成的区块,也可以是从其他节点中同步获得的区块。初始最长时钟区块为创世区块。
举例来说,参见图4,为本申请实施例提供的一种平行多链架构,平行多链架构包括子区块链C0、子区块链C1和子区块链C2,其中,子区块链C0包括创世区块G0、区块C01、区块C02、区块C03、区块C04、区块C05。子区块链C1包括创世区块G1、区块C11、区块C12、区块C13、区块C14、区块C15。子区块链C2包括创世区块G2、区块C21、区块C22、区块C23、区块C24、区块C25。
设定有效区块为区块C15,区块C15指向的最长时钟区块为区块C04,区块C04指向的最长时钟区块为区块C13,区块C13指向的最长时钟区块为区块C23,区块C23指向的最长时钟区块为区块C12,区块C12指向的最长时钟区块为区块C02,区块C02指向的最长时钟区块为区块C11,区块C11指向的最长时钟区块为创世区块G1。
由图4可知,区块C15对应的逻辑时钟路径为:区块C15→区块C04→区块C13→区块C23→区块C12→区块C02→区块C11→创世区块G1,则区块C15对应的逻辑时钟为7。
在获得各个有效区块各自对应的逻辑时钟之后,可以按照逻辑时钟从小到大的顺序对各个有效区块进行全局排序,获得全局区块链。也可以采用特定规则对各个有效区块进行筛选,然后将保留的有效区块按照逻辑时钟从小到大的顺序对各个有效区块进行全局排序,获得全局区块链。另外,当存在多个有效区块的逻辑时钟相同时,可以按照多个有效区块对应的子区块链编号或区块哈希,对多个有效区块进行排序,最终输出全局区块链。
需要说明的是,在本申请实施例中,节点可以是每次将获得的区块添加至相应的子区块链后,都触发全局排序获得全局区块链;也可以是在间隔预设时长或间隔预设数量的区块后,触发全局排序获得全局区块链,其中,预设时长和预设数量的区块可以根据实际情况进行设置;还可以是接收到外部的触发指令时,才触发全局排序获得全局区块链,对此,本申请不做具体限定。
本申请实施例中,由于多个子区块链可以分摊大规模网络环境下高并发区块的处理能力,因此,采用多链共识的方式获得全局区块链,可以提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。其次,各个区块对应的逻辑时钟,为区块之间提供了更加可靠的时序关系度量,故基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升了多链系统的安全性,也便于多链系统基于此做进一步的优化。
可选地,在上述步骤S201中,节点至少采用以下一种实施方式,基于交易数据生成目标区块,如图5所示,具体包括以下步骤:
步骤S501,对目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希。
具体地,其他字段信息至少包括多个子区块链的全局快照标志、交易数据的交易根哈希和目标区块指向的最长时钟区块的区块哈希,其中,目标区块指向的最长时钟区块为节 点在生成目标区块时监测到的具有最大逻辑时钟的合法区块。另外,其他字段信息还可以包括目标区块对应的至少一个采样区块的区块哈希。
具体地,本申请实施例采用以下至少一种实施方式获得多个子区块链的全局快照标志:
先对多个子区块链进行全局快照,获得各个有效区块序列中的最新有效区块。在进行快照时,将获得的各个最新有效区块进行排序,具体可以按照最新有效区块所属的子区块链的编号进行排序。然后基于各个最新有效区块的区块哈希,构建全局快照对应的第一默克尔树。再将第一默克尔树的根哈希,作为多个子区块链的全局快照标志。
本申请实施例采用以下至少一种实施方式获得交易数据的交易根哈希:基于交易数据,构建第二默克尔树,然后将第二默克尔树的根哈希,作为交易数据的交易根哈希。
需要说明的是,本申请实施例还可以采用其他的哈希算法,获得多个子区块链的全局快照标志和交易数据的交易根哈希,对此,本申请不做具体限定。
获得除辅助信息字段之外的其他字段信息之后,将各个字段信息按照确定顺序进行合并,然后计算合并后的数据对应的打包哈希。
步骤S502,采用可验证延迟函数对打包哈希进行处理,获得可验证输出结果。
一种可能的实施方式,当节点为多核CPU节点时,可以通过多线程并行执行可验证延迟函数,同时,不同的线程对应不同的交易内容,从而实现多线程并行参与VDF,保持投入与节点处理能力相匹配。
步骤S503,基于可验证输出结果,确定目标区块所属的目标子区块链、在目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明。
一种可能的实施方式,在获得可验证输出结果之后,还可以基于可验证输出结果对目标区块进行难度校验。
具体地,对可验证输出结果进行加密哈希处理,获得可验证输出哈希,然后判断可验证输出哈希是否小于区块生成难度,若是,则确定目标区块为合法区块,并执行后续步骤,否则,确定目标区块为非法区块并丢弃目标区块。上述区块生成难度可以是固定值,也可以定期调整。
采用可验证输出哈希,对多个子区块链的总数取模,确定目标区块所属的目标子区块链。然后将目标子区块链在全局快照中对应的有效区块,作为目标区块在目标子区块链中的父区块,并获取父区块的父区块哈希和父区块证明。
具体实施中,在确定目标区块所属的目标子区块链之后,基于前文描述全局快照,可以获得目标子区块链在全局快照中对应的最新有效区块,然后将获得的最新有效区块作为目标区块在目标子区块链中的父区块,并获得父区块的父区块哈希和父区块证明,其中,父区块证明可以是默克尔树证明。
步骤S504,基于其他字段信息、可验证输出结果、父区块哈希、父区块证明以及交易数据,获得目标区块。
具体地,可验证输出结果包括可验证输出内容和可验证输出证明。目标区块包括区块头和区块体,将目标区块指向的最长时钟区块的区块哈希、全局快照标志、交易根哈希、可验证输出结果、父区块哈希、父区块证明添加至区块头,将交易数据添加至区块体。需要说明的是,目标区块中的数据并不仅限于上述描述的几种,还可包含更多与开发相关的信息字段,对此,本申请不做具体限定。
举例来说,图6示例性示出了一种区块结构,包括区块头和区块体,其中,区块头包 括全局快照标志、最长时钟区块的区块哈希、交易根哈希、可验证输出内容、父区块哈希、可验证输出证明和父区块证明等。区块体包括实际入块的交易数据。
除了获得目标区块之外,本申请实施例中基于目标区块指向的最长时钟区块的区块哈希、全局快照标志、交易根哈希、可验证输出内容、父区块哈希,生成目标区块的目标区块哈希,其中,目标区块哈希用于唯一标识目标区块。
可选地,节点在获得目标区块之后,可以将目标区块广播至网络中,区块链网络广播方法可采用Gossip协议等。其他区块在接收到目标区块之后,可以将目标区块添加至本地的目标子区块链。
本申请实施例中,节点通过完成特定难度的可验证延迟函数,实现区块生成,为区块之间提供更加可靠的时间关系度量,而不必采用传统的工作量证明机制(PoW),从而提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。
可选地,在上述步骤S201中,目标区块也可以是从其他节点同步获得的。
具体地,节点接收其他节点发送的目标区块,并从目标区块的区块头中获取目标区块对应的可验证输出结果、父区块的父区块哈希、父区块的父区块证明和全局快照标志,其他节点生成目标区块的过程参见上述步骤S501至步骤S505,此处不再赘述。
节点在将目标区块添加至本地的子区块链之前,需要对目标区块进行校验,其中,校验过程包括以下一项或多项过程:
1、基于可验证输出结果、父区块的父区块哈希、父区块的父区块证明和全局快照标志,对目标区块进行基础校验。
具体地,校验可验证输出结果是否正确,校验规则由可验证延迟函数自身定义。
基于从区块头获得的父区块哈希和父区块证明,确定目标区块所属的目标子区块链。对从区块头获得的可验证输出结果进行加密哈希处理,获得可验证输出哈希,采用可验证输出哈希,对多个子区块链的总数取模,确定目标区块所属的参考子区块链。
判断目标子区块链和参考子区块链是否一致,若是,则基于从区块头获得的父区块的父区块证明和全局快照标志,并判断父区块是否为相应的全局快照中的区块,若是,则确定目标区块为合法区块,否则,确定目标区块为非法区块并丢弃目标区块。
2、基于目标区块对应的可验证输出结果,对目标区块进行难度校验。
具体地,对从区块头获得的可验证输出结果进行加密哈希处理,获得可验证输出哈希,然后判断可验证输出哈希是否小于区块生成难度,若是,则确定目标区块为合法区块,否则,确定目标区块为非法区块并丢弃目标区块。
3、基于目标区块的逻辑时钟和父区块的逻辑时钟,对目标区块进行时钟校验。
采用前文描述的方法分别计算目标区块的逻辑时钟和父区块的逻辑时钟,然后判断目标区块的逻辑时钟是否大于等于父区块的逻辑时钟,若是,则确定目标区块为合法区块,否则,确定目标区块为非法区块并丢弃目标区块。
采用上述一项或多项校验过程,对目标区块进行校验之后,若确定目标区块为合法区块,则将目标区块添加至相应的子区块链;若确定目标区块为非法区块,则丢弃目标区块。
本申请实施例中,节点接收其他节点发送的目标区块之后,对目标区块进行多维度的校验,在校验通过时才将目标区块添加至对应的子区块链,从而保证了区块链系统的安全性。
可选地,在上述步骤S202中,针对多个子区块链,分别采用以下方式获得对应的有 效区块序列:
从一个子区块链的创世区块开始,沿子区块方向延伸,依次选取对应最大权重区块子树的区块作为有效区块,直至无延伸区块,获得由选取的有效区块组成的有效区块序列。
具体地,一个区块的区块子树包括该区块以及沿该区块延伸的其他区块子树,区块子树的权重为区块子树中各个区块的区块权重之和,每个区块的区块权重是每个区块的可验证输出哈希,或者可验证输出哈希的预设比例。
基于每个区块的可验证输出哈希确定每个区块的区块权重,而不是简单地将每个区块的区块权重都设置为相同的值,从而提高单链的收敛速度。
举例来说,参见图7,为一个子区块链的结构示意图,该子区块链包括创世区块G0、区块C01、区块C02、区块C03、区块C04、区块C05、区块C06、区块C07、区块C08、区块C09。
以区块C01举例来说,区块C01的区块子树包括区块C01、区块C02、区块C03、区块C04、区块C07、区块C08、区块C09,该区块子树的权重为上述各个区块各自对应的区块哈希之和。
在一种可能的实施方式,每次选取对应最大权重区块子树的区块作为有效区块,包括以下步骤:
针对一个子区块链中最新选取的第一有效区块,从该子区块链中,确定与第一有效区块连接的至少一个候选子区块,以及至少一个候选子区块各自对应的区块子树。然后确定至少一个候选子区块各自对应的区块子树的权重,并基于获得的权重从各个区块子树中,确定最大权重区块子树。最后将至少一个候选子区块中,对应最大权重区块子树的候选子区块,作为第二有效区块。
具体地,在起始状态时,子区块链上的创世区块为第一有效区块,然后依次沿子区块链延伸方向选取第二有效区块。
举例来说,参见图7所示的子区块链,在第一次选取有效区块的过程中,以创世区块G0作为第一有效区块,与创世区块G0连接的区块包括区块C01和区块C05。
区块C01的区块子树1包括区块C01、区块C02、区块C03、区块C04、区块C07、区块C08、区块C09,将区块C01、区块C02、区块C03、区块C04、区块C07、区块C08、区块C09各自对应的区块哈希之和作为区块子树1的权重。
区块C05的区块子树2包括区块C05和区块C06,将区块C05和区块C06各自对应的区块哈希之和作为区块子树2的权重。由于区块子树1的权重大于区块子树2的权重,则区块子树1为最大权重区块子树,那么,区块子树1对应的区块C01为第二有效区块。
在第二次选取有效区块的过程中,以区块C01作为第一有效区块,与区块C01连接的区块包括区块C02、区块C03和区块C04。
区块C02的区块子树3包括区块C02、区块C07和区块C08,将区块C02、区块C07和区块C08各自对应的区块哈希之和作为区块子树3的权重。
区块C03的区块子树4包括区块C03和区块C09,则将区块C03和区块C09各自对应的区块哈希之和作为区块子树4的权重。
区块C04的区块子树5包括区块C04,将区块C04对应的区块哈希作为区块子树5的权重。
由于区块子树3的权重大于区块子树4和区块子树5各自对应的权重,则区块子树3 为最大权重区块子树,那么,区块子树3对应的区块C02为第二有效区块。
在第三次选取有效区块的过程中,以区块C02作为第一有效区块,与区块C02连接的区块包括区块C07和区块C08。
区块C07的区块子树6包括区块C07,则将区块C07对应的区块哈希作为区块子树6的权重。
区块C08的区块子树7包括区块C08,则将区块C08对应的区块哈希作为区块子树7的权重。
由于区块子树6的权重大于区块子树7的权重,则区块子树6为最大权重区块子树,那么,区块子树6对应的区块C07为第二有效区块。
区块C07之后没有延伸的区块,故停止选取有效区块,获得的有效区块序列为创世区块G0、区块C01、区块C02、区块C07。
本申请实施例中,从子区块链的创世区块开始,依次选取对应最大权重区块子树的区块作为有效区块,获得由选取的有效区块组成的有效区块序列。采用最重子链思想进行基于VDF的单链改造,可更好提升多链系统的安全性,系统性能上限可在节点处理能力范围内得到进一步提升。
进一步地,在获得各个子区块链各自对应的有效区块序列之后,可以将各个有效区块序列中的有效区块划分为稳定区块和不稳定区块。
具体地,针对各个有效区块,分别执行以下步骤:
若一个区块对应的区块子树的权重大于等于稳定阈值,则将该区块作为稳定区块,若一个区块对应的区块子树的权重小于稳定阈值,则将该区块作为不稳定区块,其中,稳值阈值根据实际情况进行设置。
通过将获得的各个有效区块划分为稳定区块和不稳定区块,便于实时监测子区块链的状态,同时便于后续对各个有效区块进行全部排序,获得稳定的全局区块链。
可选地,在上述步骤S203中,本申请实施例至少采用以下几种实施方式对获得的各个有效区块进行全局排序,获得全局区块链:
实施方式一、分别从各个有效区块序列中获取一个目标有效区块;基于获得的各个目标有效区块对应的逻辑时钟,对各个目标有效区块进行全局排序,获得全局区块链。
具体地,分别从各个有效区块序列中随机获取一个目标有效区块。按照逻辑时钟从小到大的顺序,对筛选出的目标有效筛选区块进行全局排序,获得全局区块链。在存在逻辑时钟相同的目标有效区块时,基于子区块链编号或区块哈希,对逻辑时钟相同的目标有效区块进行排序,获得全局区块链。
举例来说,如图8所示,为本申请实施例提供的一种平行多链架构,平行多链架构包括子区块链C0、子区块链C1和子区块链C2,其中,子区块链C0包括创世区块G0(逻辑时钟:0)、区块C01(逻辑时钟:1)、区块C02(逻辑时钟:2)、区块C03(逻辑时钟:3)、区块C04(逻辑时钟:4)。子区块链C1包括创世区块G1(逻辑时钟:0)、区块C11(逻辑时钟:1)、区块C12(逻辑时钟:3)、区块C13(逻辑时钟:5)。子区块链C2包括创世区块G2(逻辑时钟:0)、区块C21(逻辑时钟:1)、区块C22(逻辑时钟:4)、区块C23(逻辑时钟:5)、区块C24(逻辑时钟:6)。
选取子区块链C0中的区块C01、子区块链C1中的区块C11和子区块链C2中的区块C22作为目标有效区块。
按照逻辑时钟从小到大的顺序,对选取的目标有效区块进行全局排序,当存在逻辑时钟相同的目标有效区块时,按照子区块链编号从小到大的顺序,对逻辑时钟相同的目标有效区块进行排序,获得的全局区块链为:区块C01、区块C11和区块C22。
实施方式二、分别从各个有效区块序列中获取最新稳定区块,从各个最新稳定区块对应的逻辑时钟中获得最小逻辑时钟,并将最小逻辑时钟作为区块时钟边界。从各个稳定区块中,筛选出逻辑时钟小于或等于区块时钟边界的目标稳定区块。基于获得的各个目标稳定区块对应的逻辑时钟,对各个目标稳定区块进行全局排序,获得全局区块链。
具体地,按照逻辑时钟从小到大的顺序,对各个目标稳定区块进行全局排序,获得初步排序结果。若初步排序结果中存在逻辑时钟相同的目标稳定区块,则基于子区块链编号或区块哈希,对逻辑时钟相同的目标稳定区块进行排序,获得全局区块链。
采用子区块链编号或区块哈希对逻辑时钟相同的目标稳定区块进行排序时,也可以按照从小到大的顺序。
举例来说,如图9所示,为本申请实施例提供的一种平行多链架构,平行多链架构包括子区块链C0、子区块链C1和子区块链C2,其中,子区块链C0包括创世区块G0(逻辑时钟:0)、区块C01(逻辑时钟:1)、区块C02(逻辑时钟:2)、区块C03(逻辑时钟:3)、区块C04(逻辑时钟:4)。子区块链C1包括创世区块G1(逻辑时钟:0)、区块C11(逻辑时钟:1)、区块C12(逻辑时钟:3)、区块C13(逻辑时钟:5)。子区块链C2包括创世区块G2(逻辑时钟:0)、区块C21(逻辑时钟:1)、区块C22(逻辑时钟:4)、区块C23(逻辑时钟:5)、区块C24(逻辑时钟:6)。
设定子区块链C0中的稳定区块包括:创世区块G0、区块C01,其中,最新稳定区块为区块C01。子区块链C1中的稳定区块包括:创世区块G1、区块C11,其中,最新稳定区块为区块C11。子区块链C2中的稳定区块包括:创世区块G2、区块C21、区块C22,其中,最新稳定区块为区块C22。
上述各个最新稳定区块对应的逻辑时钟中,最小逻辑时钟为1,则确定区块时钟边界为1。
在子区块链C0中的各个稳定区块中,逻辑时钟小于或等于区块时钟边界的目标稳定区块包括创世区块G0和区块C01。
在子区块链C1中的各个稳定区块中,逻辑时钟小于或等于区块时钟边界的目标稳定区块包括创世区块G1和区块C11。
在子区块链C2中的各个稳定区块中,逻辑时钟小于或等于区块时钟边界的目标稳定区块包括创世区块G2、区块C21。
按照逻辑时钟从小到大的顺序,对筛选出的目标稳定区块进行全局排序,当存在逻辑时钟相同的目标稳定区块时,按照子区块链编号从小到大的顺序,对逻辑时钟相同的目标稳定区块进行排序,获得的全局区块链为:创世区块G0、创世区块G1、创世区块G2、区块C01、区块C11、区块C21。
本申请实施例中,采用最重子链思想进行基于VDF的单链改造,并基于区块逻辑时钟对应的区块时序关系构建全局区块链,引入了更加可靠的时间关系度量,从而提升了多链系统的安全性,也使系统性能上限可在节点处理能力范围内得到进一步提升。
进一步地,在获得全局区块链之后,判断全局区块链中不同区块之间是否存在重复或冲突交易(比如同一交易被重复打包)。具体地,按照区块链中区块的顺序依次执行各个 区块中的交易,若当前区块中的某个交易在之前已经被执行,则确定该交易为非法交易,则不执行,否则确定该交易为合法交易并执行,同时进行系统状态更新。
为了更好地解释本申请实施例,下面结合具体实施场景,介绍本申请实施例提供的一种区块链共识方法,该方法的流程可以由图1所示的区块链系统中的任意一个节点执行,包括以下步骤,如图10所示:
步骤S1001,系统协议初始化。
具体地,节点先进行协议相关参数的初始化,如:区块生成难度、VDF参数、各子区块链的数量和编号、区块链网络标识、区块大小、本地公私钥账户配置等。
步骤S1002,VDF过程。
具体地,从交易池中获取交易数据,将节点在生成目标区块时监测到的具有最大逻辑时钟的合法区块作为目标区块指向的最长时钟区块,并获得最长时钟区块的区块哈希。
对多个子区块链进行全局快照,获得各个有效区块序列中的最新有效区块,基于各个最新有效区块的区块哈希,构建全局快照对应的第一默克尔树。再将第一默克尔树的根哈希,作为多个子区块链的全局快照标志。
基于交易数据,构建第二默克尔树,然后将第二默克尔树的根哈希,作为交易数据的交易根哈希。
将最长时钟区块的区块哈希、多个子区块链的全局快照标志和交易数据的交易根哈希进行合并,然后计算合并后的数据对应的打包哈希。之后再采用VDF对打包哈希进行处理,获得可验证输出结果。可验证输出结果包括可验证输出内容和可验证输出证明。
对可验证输出结果进行加密哈希处理,获得可验证输出哈希,然后判断可验证输出哈希是否小于区块生成难度,若是,则确定目标区块为合法区块,并执行后续步骤,否则,确定目标区块为非法区块并丢弃目标区块。
难度检测通过后,采用可验证输出哈希,对多个子区块链的总数取模,确定目标区块所属的目标子区块链。然后将目标子区块链在全局快照中对应的有效区块,作为目标区块在目标子区块链中的父区块,并获取父区块的父区块哈希和父区块证明。
将最长时钟区块的区块哈希、全局快照标志、交易根哈希、可验证输出结果、父区块哈希、父区块证明添加至区块头,将交易数据添加至区块体,获得目标区块。
基于最长时钟区块的区块哈希、全局快照标志、交易根哈希、可验证输出内容、父区块哈希,生成目标区块的目标区块哈希。
步骤S1003,消息广播与同步。
节点将目标区块广播给其他节点,同时同步其他节点生成的区块,并将同步的区块中的交易数据添加至交易池中。
步骤S1004,区块合法性校验。
具体地,节点接收其他节点发送的区块之后,对区块进行基础校验、难度校验和时钟校验,若校验通过,则确定接收的区块为合法区块,否则为非法区块。
步骤S1005,将合法区块添加至相应的子区块链。
步骤S1006,分别从多条子区块链中获取相应的有效区块序列。
具体地,针对每个子区块链,从该子区块链的创世区块开始,沿子区块方向延伸,依次选取对应最大权重区块子树的区块作为有效区块,直至无延伸区块,获得由选取的有效区块组成的有效区块序列。
一个区块的区块子树包括该区块以及沿该区块延伸的其他区块子树,区块子树的权重为区块子树中各个区块的区块权重之和,每个区块的区块权重是每个区块的可验证输出哈希,或者可验证输出哈希的预设比例。
步骤S1007,对获得的有效区块进行全局排序,获得全局区块链。
具体地,将各个有效区块序列中的有效区块划分为稳定区块和不稳定区块。分别从各个有效区块序列中获取最新稳定区块。从各个最新稳定区块对应的逻辑时钟中获得最小逻辑时钟,并将最小逻辑时钟作为区块时钟边界;从各个稳定区块中,筛选出逻辑时钟小于或等于区块时钟边界的目标稳定区块。
步骤S1008,执行全局区块链中各个区块中的交易。
按照区块顺序,执行各个区块中的交易。
步骤S1009,系统状态更新,执行步骤S1002。
本申请实施例中,由于多个子区块链可以分摊大规模网络环境下高并发区块的处理能力,因此,采用多链共识的方式获得全局区块链,可以提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。其次,各个区块对应的逻辑时钟,为区块之间提供了更加可靠的时序关系度量,故基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升了多链系统的安全性,也便于多链系统基于此做进一步的优化。
基于相同的技术构思,本申请实施例提供了一种区块链共识装置的结构示意图,应用于区块链系统中的任意一个节点,如图11所示,该装置1100包括:
匹配模块1101,用于从多个子区块链中,确定目标区块所属的目标子区块链,并将所述目标区块添加至所述目标子区块链,所述目标区块是基于交易数据生成的,或者从其他节点同步获得的;
筛选模块1102,用于分别从所述多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块;
排序模块1103,用于基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链。
可选地,所述有效区块的逻辑时钟为:以所述有效区块为起点,沿所述有效区块对应的逻辑时钟路径至创世区块所经过的区块数量,其中,所述有效区块对应的逻辑时钟路径为:以所述有效区块为起点,沿指向最长时钟区块的方向延伸至创世区块的路径。
可选地,所述匹配模块1101具体用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希,其中,所述其他字段信息至少包括所述多个子区块链的全局快照标志、所述交易数据的交易根哈希和所述目标区块指向的最长时钟区块的区块哈希,其中,所述目标区块指向的最长时钟区块为节点在生成所述目标区块时监测到的具有最大逻辑时钟的合法区块;
采用可验证延迟函数对所述打包哈希进行处理,获得可验证输出结果;
基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明;
基于所述其他字段信息、所述可验证输出结果、所述父区块哈希、所述父区块证明以及所述交易数据,获得所述目标区块。
可选地,所述匹配模块1101还用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,对所述多个子区块链进行全局快照,获得所述各个有效区块序列中的最新有效区块;
基于获得的各个最新有效区块的区块哈希,构建所述全局快照对应的第一默克尔树;
将所述第一默克尔树的根哈希,作为所述多个子区块链的全局快照标志。
可选地,所述匹配模块1101还用于:
对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,基于所述交易数据,构建第二默克尔树;
将所述第二默克尔树的根哈希,作为所述交易数据的交易根哈希。
可选地,所述匹配模块1101还用于:
所述基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之前,对所述可验证输出结果进行加密哈希处理,获得可验证输出哈希;
确定所述可验证输出哈希小于区块生成难度。
可选地,所述匹配模块1101具体用于:
采用所述可验证输出哈希,对所述多个子区块链的总数取模,确定所述目标区块所属的目标子区块链;
将所述目标子区块链在全局快照中对应的有效区块,作为所述目标区块在所述目标子区块链中的父区块,并获取所述父区块的父区块哈希和父区块证明。
可选地,所述可验证输出结果包括可验证输出内容和可验证输出证明;
所述匹配模块1101还用于:
基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之后,基于所述目标区块指向的最长时钟区块的区块哈希、所述全局快照标志、所述交易根哈希、所述可验证输出内容、所述父区块哈希,生成所述目标区块的目标区块哈希。
可选地,所述匹配模块1101还用于:
接收其他节点发送的所述目标区块,并从所述目标区块的区块头中获取所述目标区块对应的可验证输出结果、父区块的父区块哈希、父区块的父区块证明和全局快照标志;
基于所述可验证输出结果、所述父区块哈希、所述父区块证明和所述全局快照标志,对所述目标区块进行基础校验;
基于所述目标区块对应的可验证输出结果,对所述目标区块进行难度校验;
基于所述目标区块的逻辑时钟和所述父区块的逻辑时钟,对所述目标区块进行时钟校验。
可选地,所述筛选模块1102具体用于:
针对所述多个子区块链,分别执行以下步骤:
从一个子区块链的创世区块开始,沿子区块方向延伸,依次选取对应最大权重区块子树的区块作为有效区块,直至无延伸区块,获得由选取的有效区块组成的有效区块序列,其中,一个区块的区块子树包括所述一个区块以及沿所述一个区块延伸的其他区块子树,所述区块子树的权重为所述区块子树中各个区块的区块权重之和,每个区块的区块权重是 每个区块的可验证输出哈希,或者所述可验证输出哈希的预设比例。
可选地,所述筛选模块1102具体用于:
每次选取对应最大权重区块子树的区块作为有效区块,包括以下步骤:
针对所述一个子区块链中最新选取的第一有效区块,从所述一个子区块链中,确定与所述第一有效区块连接的至少一个候选子区块,以及所述至少一个候选子区块各自对应的区块子树;
确定所述至少一个候选子区块各自对应的区块子树的权重,并基于获得的权重从各个区块子树中,确定最大权重区块子树;
将所述至少一个候选子区块中,对应所述最大权重区块子树的候选子区块,作为第二有效区块。
可选地,所述排序模块1103具体用于:
分别从各个有效区块序列中获取一个目标有效区块;
基于获得的各个目标有效区块对应的逻辑时钟,对所述各个目标有效区块进行全局排序,获得全局区块链。
可选地,所述筛选模块1102还用于:
针对所述各个有效区块,分别执行以下步骤:
若一个区块对应的区块子树的权重大于等于稳定阈值,则将所述一个区块作为稳定区块;
若所述一个区块对应的区块子树的权重小于稳定阈值,则将所述一个区块作为不稳定区块。
可选地,所述排序模块1103具体用于:
分别从各个有效区块序列中获取最新稳定区块;
从各个最新稳定区块对应的逻辑时钟中获得最小逻辑时钟,并将所述最小逻辑时钟作为区块时钟边界;
从各个稳定区块中,筛选出逻辑时钟小于或等于所述区块时钟边界的目标稳定区块;
基于获得的各个目标稳定区块对应的逻辑时钟,对所述各个目标稳定区块进行全局排序,获得全局区块链。
可选地,所述排序模块1103具体用于:
按照逻辑时钟从小到大的顺序,对所述各个目标稳定区块进行全局排序,获得初步排序结果;
若所述初步排序结果中存在逻辑时钟相同的目标稳定区块,则基于子区块链编号或区块哈希,对所述逻辑时钟相同的目标稳定区块进行排序,获得全局区块链。
本申请实施例中,由于多个子区块链可以分摊大规模网络环境下高并发区块的处理能力,因此,采用多链共识的方式获得全局区块链,可以提升区块链系统在大规模开放网络环境下的可扩展性和交易吞吐量。其次,各个区块对应的逻辑时钟,为区块之间提供了更加可靠的时序关系度量,故基于各个有效区块对应的逻辑时钟,对各个有效区块进行全局排序获得全局区块链时,可以更好地提升了多链系统的安全性,也便于多链系统基于此做进一步的优化。
基于相同的技术构思,本申请实施例提供了一种计算机设备,如图12所示,包括至少一个处理器1201,以及与至少一个处理器连接的存储器1202,本申请实施例中不限定 处理器1201与存储器1202之间的具体连接介质,图12中处理器1201和存储器1202之间通过总线连接为例。总线可以分为地址总线、数据总线、控制总线等。
在本申请实施例中,存储器1202存储有可被至少一个处理器1201执行的指令,至少一个处理器1201通过执行存储器1202存储的指令,可以执行上述区块链共识方法的步骤。
其中,处理器1201是计算机设备的控制中心,可以利用各种接口和线路连接计算机设备的各个部分,通过运行或执行存储在存储器1202内的指令以及调用存储在存储器1202内的数据,从而实现区块链共识。可选的,处理器1201可包括一个或多个处理单元,处理器1201可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器1201中。在一些实施例中,处理器1201和存储器1202可以在同一芯片上实现,在一些实施例中,它们也可以在独立的芯片上分别实现。
处理器1201可以是通用处理器,例如中央处理器(CPU)、数字信号处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件,可以实现或者执行本申请实施例中公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。
存储器1202作为一种非易失性计算机可读存储介质,可用于存储非易失性软件程序、非易失性计算机可执行程序以及模块。存储器1202可以包括至少一种类型的存储介质,例如可以包括闪存、硬盘、多媒体卡、卡型存储器、随机访问存储器(Random Access Memory,RAM)、静态随机访问存储器(Static Random Access Memory,SRAM)、可编程只读存储器(Programmable Read Only Memory,PROM)、只读存储器(Read Only Memory,ROM)、带电可擦除可编程只读存储器(Electrically Erasable Programmable Read-Only Memory,EEPROM)、磁性存储器、磁盘、光盘等等。存储器1202是能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。本申请实施例中的存储器1202还可以是电路或者其它任意能够实现存储功能的装置,用于存储程序指令和/或数据。
基于同一发明构思,本申请实施例提供了一种计算机可读存储介质,其存储有可由计算机设备执行的计算机程序,当程序在计算机设备上运行时,使得计算机设备执行上述区块链共识方法的步骤。
基于同一发明构思,本申请实施例提供了一种计算机程序产品,所述计算机程序产品包括存储在计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机设备执行时,使所述计算机设备执行上述区块链共识方法的步骤。
本领域内的技术人员应明白,本发明的实施例可提供为方法、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流 程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。

Claims (19)

  1. 一种区块链共识方法,应用于区块链系统中的任意一个节点,其特征在于,包括:
    从多个子区块链中,确定目标区块所属的目标子区块链,并将所述目标区块添加至所述目标子区块链,所述目标区块是基于交易数据生成的,或者从其他节点同步获得的;
    分别从所述多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块;
    基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链。
  2. 如权利要求1所述的方法,其特征在于,所述有效区块的逻辑时钟为:以所述有效区块为起点,沿所述有效区块对应的逻辑时钟路径至创世区块所经过的区块数量,其中,所述有效区块对应的逻辑时钟路径为:以所述有效区块为起点,沿指向最长时钟区块的方向延伸至创世区块的路径。
  3. 如权利要求1所述的方法,其特征在于,所述目标区块是基于交易数据生成的,包括:
    对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希,其中,所述其他字段信息至少包括所述多个子区块链的全局快照标志、所述交易数据的交易根哈希和所述目标区块指向的最长时钟区块的区块哈希,其中,所述目标区块指向的最长时钟区块为节点在生成所述目标区块时监测到的具有最大逻辑时钟的合法区块;
    采用可验证延迟函数对所述打包哈希进行处理,获得可验证输出结果;
    基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明;
    基于所述其他字段信息、所述可验证输出结果、所述父区块哈希、所述父区块证明以及所述交易数据,获得所述目标区块。
  4. 如权利要求3所述的方法,其特征在于,所述对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,还包括:
    对所述多个子区块链进行全局快照,获得所述各个有效区块序列中的最新有效区块;
    基于获得的各个最新有效区块的区块哈希,构建所述全局快照对应的第一默克尔树;
    将所述第一默克尔树的根哈希,作为所述多个子区块链的全局快照标志。
  5. 如权利要求3所述的方法,其特征在于,所述对所述目标区块的区块头中除辅助信息字段之外的其他字段信息合并后进行哈希运算,获得打包哈希之前,还包括:
    基于所述交易数据,构建第二默克尔树;
    将所述第二默克尔树的根哈希,作为所述交易数据的交易根哈希。
  6. 如权利要求3所述的方法,其特征在于,所述基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之前,还包括:
    对所述可验证输出结果进行加密哈希处理,获得可验证输出哈希;
    确定所述可验证输出哈希小于区块生成难度。
  7. 如权利要求6所述的方法,其特征在于,所述基于所述可验证输出结果,确定所 述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明,包括:
    采用所述可验证输出哈希,对所述多个子区块链的总数取模,确定所述目标区块所属的目标子区块链;
    将所述目标子区块链在全局快照中对应的有效区块,作为所述目标区块在所述目标子区块链中的父区块,并获取所述父区块的父区块哈希和父区块证明。
  8. 如权利要求3所述的方法,其特征在于,所述可验证输出结果包括可验证输出内容和可验证输出证明;
    所述基于所述可验证输出结果,确定所述目标区块所属的目标子区块链、在所述目标子区块链中对应的父区块,以及相应的父区块哈希和父区块证明之后,还包括:
    基于所述目标区块指向的最长时钟区块的区块哈希、所述全局快照标志、所述交易根哈希、所述可验证输出内容、所述父区块哈希,生成所述目标区块的目标区块哈希。
  9. 如权利要求1所述的方法,其特征在于,所述目标区块是从其他节点同步获得的,包括:
    接收其他节点发送的所述目标区块,并从所述目标区块的区块头中获取所述目标区块对应的可验证输出结果、父区块的父区块哈希、父区块的父区块证明和全局快照标志;
    基于所述可验证输出结果、所述父区块哈希、所述父区块证明和所述全局快照标志,对所述目标区块进行基础校验;
    基于所述目标区块对应的可验证输出结果,对所述目标区块进行难度校验;
    基于所述目标区块的逻辑时钟和所述父区块的逻辑时钟,对所述目标区块进行时钟校验。
  10. 如权利要求1所述的方法,其特征在于,所述分别从所述多个子区块链中,获得各自对应的有效区块序列,包括:
    针对所述多个子区块链,分别执行以下步骤:
    从一个子区块链的创世区块开始,沿子区块方向延伸,依次选取对应最大权重区块子树的区块作为有效区块,直至无延伸区块,获得由选取的有效区块组成的有效区块序列,其中,一个区块的区块子树包括所述一个区块以及沿所述一个区块延伸的其他区块子树,所述区块子树的权重为所述区块子树中各个区块的区块权重之和,每个区块的区块权重是每个区块的可验证输出哈希,或者所述可验证输出哈希的预设比例。
  11. 如权利要求10所述的方法,其特征在于,每次选取对应最大权重区块子树的区块作为有效区块,包括以下步骤:
    针对所述一个子区块链中最新选取的第一有效区块,从所述一个子区块链中,确定与所述第一有效区块连接的至少一个候选子区块,以及所述至少一个候选子区块各自对应的区块子树;
    确定所述至少一个候选子区块各自对应的区块子树的权重,并基于获得的权重从各个区块子树中,确定最大权重区块子树;
    将所述至少一个候选子区块中,对应所述最大权重区块子树的候选子区块,作为第二有效区块。
  12. 如权利要求1所述的方法,其特征在于,所述基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链,包括:
    分别从各个有效区块序列中获取一个目标有效区块;
    基于获得的各个目标有效区块对应的逻辑时钟,对所述各个目标有效区块进行全局排序,获得全局区块链。
  13. 如权利要求1所述的方法,其特征在于,还包括:
    针对所述各个有效区块,分别执行以下步骤:
    若一个区块对应的区块子树的权重大于等于稳定阈值,则将所述一个区块作为稳定区块;
    若所述一个区块对应的区块子树的权重小于稳定阈值,则将所述一个区块作为不稳定区块。
  14. 如权利要求13所述的方法,其特征在于,所述基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链,包括:
    分别从各个有效区块序列中获取最新稳定区块;
    从各个最新稳定区块对应的逻辑时钟中获得最小逻辑时钟,并将所述最小逻辑时钟作为区块时钟边界;
    从各个稳定区块中,筛选出逻辑时钟小于或等于所述区块时钟边界的目标稳定区块;
    基于获得的各个目标稳定区块对应的逻辑时钟,对所述各个目标稳定区块进行全局排序,获得全局区块链。
  15. 如权利要求14所述的方法,其特征在于,所述基于获得的各个目标稳定区块对应的逻辑时钟,对所述各个目标稳定区块进行全局排序,获得全局区块链,包括:
    按照逻辑时钟从小到大的顺序,对所述各个目标稳定区块进行全局排序,获得初步排序结果;
    若所述初步排序结果中存在逻辑时钟相同的目标稳定区块,则基于子区块链编号或区块哈希,对所述逻辑时钟相同的目标稳定区块进行排序,获得全局区块链。
  16. 一种区块链共识装置,应用于区块链系统中的任意一个节点,其特征在于,包括:
    匹配模块,用于从多个子区块链中,确定目标区块所属的目标子区块链,并将所述目标区块添加至所述目标子区块链,所述目标区块是基于交易数据生成的,或者从其他节点同步获得的;
    筛选模块,用于分别从所述多个子区块链中,获得各自对应的有效区块序列,每个有效区块序列包括至少一个有效区块;
    排序模块,用于基于获得的各个有效区块各自对应的逻辑时钟,对所述各个有效区块进行全局排序,获得全局区块链。
  17. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现权利要求1~15任一权利要求所述方法的步骤。
  18. 一种计算机可读存储介质,其特征在于,其存储有可由计算机设备执行的计算机程序,当所述程序在计算机设备上运行时,使得所述计算机设备执行权利要求1~15任一所述方法的步骤。
  19. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机设备执行时,使所述计算机设备执行权利要求1-15任一项所述的方法的步骤。
PCT/CN2022/110336 2021-10-30 2022-08-04 一种区块链共识方法、装置、设备及存储介质 WO2023071373A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US18/575,811 US20240163121A1 (en) 2021-10-30 2022-08-04 Blockchain consensus method, apparatus, and device, and storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111277507.8A CN114281888A (zh) 2021-10-30 2021-10-30 一种区块链共识方法、装置、设备及存储介质
CN202111277507.8 2021-10-30

Publications (1)

Publication Number Publication Date
WO2023071373A1 true WO2023071373A1 (zh) 2023-05-04

Family

ID=80868754

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/110336 WO2023071373A1 (zh) 2021-10-30 2022-08-04 一种区块链共识方法、装置、设备及存储介质

Country Status (3)

Country Link
US (1) US20240163121A1 (zh)
CN (1) CN114281888A (zh)
WO (1) WO2023071373A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114281888A (zh) * 2021-10-30 2022-04-05 中国银联股份有限公司 一种区块链共识方法、装置、设备及存储介质
CN114900497B (zh) * 2022-05-09 2023-09-26 上海极豆科技有限公司 一种标识序号生成方法、装置、电子设备及存储介质
CN114924617B (zh) * 2022-06-15 2024-04-26 深圳前海微众银行股份有限公司 一种去中心化系统中的时钟同步方法及装置
CN115086049B (zh) * 2022-06-21 2023-09-08 天津理工大学 基于可验证延迟函数的区块链医疗数据共享系统及方法
CN115730009A (zh) * 2022-11-18 2023-03-03 中国银联股份有限公司 一种区块链交易分配方法及装置
CN117610087B (zh) * 2024-01-23 2024-04-26 北京天润基业科技发展股份有限公司 区块处理方法及装置、电子设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111488202A (zh) * 2020-04-07 2020-08-04 百度国际科技(深圳)有限公司 多链系统的事务处理方法、装置、设备、系统和介质
US20200252221A1 (en) * 2019-02-05 2020-08-06 Visa International Service Association Optimizations for verification of interactions system and method
CN111786952A (zh) * 2020-05-29 2020-10-16 中国银联股份有限公司 区块链系统的共识方法、装置、设备及介质
CN112685796A (zh) * 2021-03-12 2021-04-20 腾讯科技(深圳)有限公司 一种基于区块链的区块共识方法以及相关设备
CN114281888A (zh) * 2021-10-30 2022-04-05 中国银联股份有限公司 一种区块链共识方法、装置、设备及存储介质

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10097344B2 (en) * 2016-07-15 2018-10-09 Mastercard International Incorporated Method and system for partitioned blockchains and enhanced privacy for permissioned blockchains
US11239999B1 (en) * 2018-04-25 2022-02-01 Tyson York Winarski Blockchain network communications system
CN108765151A (zh) * 2018-05-11 2018-11-06 深圳市恋上互联网技术有限公司 一种基于区块链的交易方法
CN109886681B (zh) * 2019-01-31 2021-06-18 北京瑞卓喜投科技发展有限公司 区块链共识方法及共识系统
CN110365768B (zh) * 2019-07-15 2021-07-06 腾讯科技(深圳)有限公司 分布式系统的数据同步方法、装置、介质、电子设备
CN110689345B (zh) * 2019-09-06 2022-03-18 北京清红微谷技术开发有限责任公司 调整区块权重的无许可区块链共识方法、系统、p2p网络
US11726773B2 (en) * 2021-05-19 2023-08-15 Micro Focus Llc Software supply chain quality control evaluation using blockchain
CN113886496A (zh) * 2021-09-30 2022-01-04 上海浦东发展银行股份有限公司 区块链的数据同步方法、装置、计算机设备和存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200252221A1 (en) * 2019-02-05 2020-08-06 Visa International Service Association Optimizations for verification of interactions system and method
CN111488202A (zh) * 2020-04-07 2020-08-04 百度国际科技(深圳)有限公司 多链系统的事务处理方法、装置、设备、系统和介质
CN111786952A (zh) * 2020-05-29 2020-10-16 中国银联股份有限公司 区块链系统的共识方法、装置、设备及介质
CN112685796A (zh) * 2021-03-12 2021-04-20 腾讯科技(深圳)有限公司 一种基于区块链的区块共识方法以及相关设备
CN114281888A (zh) * 2021-10-30 2022-04-05 中国银联股份有限公司 一种区块链共识方法、装置、设备及存储介质

Also Published As

Publication number Publication date
US20240163121A1 (en) 2024-05-16
CN114281888A (zh) 2022-04-05

Similar Documents

Publication Publication Date Title
WO2023071373A1 (zh) 一种区块链共识方法、装置、设备及存储介质
CN110869967B (zh) 用于并行处理区块链交易的系统和方法
Miller et al. The honey badger of BFT protocols
US11973869B2 (en) Maintaining blocks of a blockchain in a partitioned blockchain network
EP3698518B1 (en) Primary and secondary blockchain device
CN109472572B (zh) 基于区块链主链加并行多子链的合约系统
US20230037932A1 (en) Data processing method and apparatus based on blockchain network, and computer device
CN115152177B (zh) 提供机密知识的专门证明的系统和方法
CN109493052B (zh) 一种基于主链加并行多子链的跨链合约系统
JP2019536108A (ja) データをビザンチン障害耐性複製する方法及びシステム
CN110771127A (zh) 用于区块链网络中一致分布式内存池的方法和系统
Leal et al. Performance evaluation of private ethereum networks
CN112508573B (zh) 一种交易数据处理方法、装置以及计算机设备
JP2022551874A (ja) セキュアな共生(Symbiosis)マイニングのための方法および装置
US20230017790A1 (en) Graphic-blockchain-orientated hybrid consensus implementation apparatus and implementation method thereof
CN112613601A (zh) 神经网络模型更新方法、设备及计算机存储介质
CN111555860B (zh) 一种区块链节点共识方法、装置、电子设备及存储介质
Charapko et al. Bridging paxos and blockchain consensus
CN114884652A (zh) 一种区块链上产生随机数种子的方法、系统和共识节点
Ma et al. Stochastic performance modeling for practical byzantine fault tolerance consensus in the blockchain
CN117251889B (zh) 区块链共识方法、相关装置和介质
CN111147477B (zh) 一种基于区块链网络的验证方法及装置
Ma et al. Ripple+: An improved scheme of ripple consensus protocol in deployability liveness and timing assumption
Ozdayi et al. Instachain: Breaking the sharding limits via adjustable quorums
WO2023072955A1 (en) Methods and systems for distributed blockchain functionalities

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

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 18575811

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE