Block chain consensus method, related device and medium
By adopting the method of using multiple master nodes in the blockchain in parallel to package and rolling the chain, and using multiple transaction storage space and mapping rules, the problems of waste of resources and reduction in throughput during the blockchain transaction are solved, and more efficient blockchain throughput and transaction rolling efficiency are achieved.
Patent Information
- Application Number
- CN202410078321.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-18
- Publication Date
- 2025-07-18
AI Technical Summary
During the blockchain transaction on the process of blockchain transactions, the existing technology has problems of resource waste and throughput decline caused by multiple rounds of block consensus, resulting in inefficient transaction on the chain.
The method of packing and rolling on multiple master nodes in parallel is adopted. Each consensus node has multiple transaction storage spaces. The transactions to be rolled on are distributed to their respective storage spaces through mapping rules, and are packaged by the target master node in the consensus round and sent to the slave node consensus to ensure that multiple blocks can be consensus on rolling on multiple blocks in one consensus round.
It improves the throughput and transaction on-chain efficiency of blockchain, reduces resource waste, and ensures the accuracy and efficiency of the consensus process.
Smart Images

Figure CN120336312A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of blockchain technology, and in particular, to a blockchain consensus method, related apparatus, and medium. Background Art
[0002] Currently, during the process of blockchain transactions being committed to the chain, there are often multiple rounds of block consensus. In each block consensus round, usually a consensus node (the primary node) packs multiple transactions to be committed to the chain into a block, and broadcasts the block containing multiple transactions to other consensus nodes (secondary nodes). Only after receiving the consensus confirmations from other consensus nodes can the block be committed to the chain. This method often causes significant resource waste during stages such as block broadcasting and consensus, leading to a decrease in the throughput of the blockchain and low efficiency in transaction commitment to the chain. Summary of the Invention
[0003] Embodiments of the present disclosure provide a blockchain consensus method, related apparatus, and medium, which can improve the throughput and speed of the blockchain, and thus improve the efficiency of transaction commitment to the chain.
[0004] According to one aspect of the present disclosure, there is provided a blockchain consensus method. The blockchain consensus method has multiple consensus rounds, and in each of the consensus rounds, it is applied to a target primary node among the second number of primary nodes in the first number of consensus nodes. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has a second number of transaction storage spaces respectively corresponding to the second number of primary nodes. The blockchain consensus method includes:
[0005] Obtain transactions to be committed to the chain;
[0006] Based on the mapping rule of the transactions to be committed to the chain in the second number of the transaction storage spaces, map the transactions to be committed to the chain to one of the transaction storage spaces;
[0007] Determine the target transaction storage space corresponding to the target primary node in the second number of the transaction storage spaces;
[0008] Pack the transactions to be committed to the chain stored in the target transaction storage space into a block to be consensus, and send the block to be consensus to the secondary nodes, so that the secondary nodes perform consensus on the transactions to be committed to the chain in the block to be consensus based on the target transaction storage space corresponding to the target primary node in the secondary nodes, where the secondary nodes are the consensus nodes other than the target primary node.
[0009] According to one aspect of the present disclosure, there is provided a blockchain consensus device, which has a plurality of consensus rounds and is applied to a target primary node among the second number of primary nodes in the first number of consensus nodes in each consensus round. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has a second number of transaction storage spaces respectively corresponding to the second number of primary nodes. The blockchain consensus device includes:
[0010] An acquisition unit, configured to acquire a transaction to be chained;
[0011] A mapping unit, configured to map the transaction to be chained to one of the transaction storage spaces based on the mapping rule of the transaction to be chained in the second number of transaction storage spaces;
[0012] A determination unit, configured to determine a target transaction storage space corresponding to the target primary node in the second number of transaction storage spaces;
[0013] A packaging unit, configured to package the transaction to be chained stored in the target transaction storage space into a block to be consensus and send the block to be consensus to a slave node, so that the slave node performs consensus on the transaction to be chained in the block to be consensus based on the target transaction storage space corresponding to the target primary node in the slave node, where the slave node is a consensus node other than the target primary node.
[0014] Optionally, the blockchain consensus device further includes a chaining unit, and the chaining unit is specifically configured to:
[0015] Obtain a consensus result based on the consensus feedback of each slave node;
[0016] If the consensus result is consensus success, determine the block to be consensus as the target block and determine the predetermined block height of the block to be consensus as the block height of the target block, so as to perform chaining processing on a plurality of consecutive target blocks based on the plurality of block heights;
[0017] If the consensus result is consensus failure, mark the predetermined block height of the block to be consensus, so as to allocate the marked predetermined block height to the block to be consensus generated in the next consensus round.
[0018] Optionally, the performing chaining processing on a plurality of consecutive target blocks based on the plurality of block heights includes:
[0019] Determine the chaining order of each target block based on the plurality of block heights;
[0020] Based on the above-chain order, perform the above-chain processing on multiple consecutive target blocks, and delay the above-chain of the discontinuous target blocks.
[0021] Optionally, the discontinuous target blocks include at least one first target block;
[0022] The delaying the above-chain of the discontinuous target blocks includes:
[0023] Among the multiple target blocks generated in multiple consensus rounds after the current consensus round, determine a second target block whose block height is less than that of the first target block;
[0024] Based on the block height, perform the above-chain on the consecutive second target blocks and the first target block together.
[0025] Optionally, the predetermined block height is determined in the following manner:
[0026] Obtain the block above-chain log of the blockchain network, where the block above-chain log includes multiple candidate segment numbers and the corresponding relationship between each assigned candidate segment number and each block on the blockchain;
[0027] Screen out a target segment number from the multiple unassigned candidate segment numbers, and determine the target segment number as the predetermined block height.
[0028] Optionally, the second number of transaction storage spaces is determined in the following manner:
[0029] Determine the number of nodes of the primary node in the current consensus round;
[0030] Based on the number of nodes, equally divide the transaction pool of the consensus nodes to obtain the second number of transaction storage spaces.
[0031] Optionally, each transaction storage space has a storage space index; each transaction to be above-chained has a transaction digest value;
[0032] The mapping unit is specifically used for:
[0033] Determine the round number of the current consensus round of the blockchain network;
[0034] Sum the round number of the current consensus round and the transaction digest value to obtain a sum result;
[0035] Perform a remainder operation based on the sum result and the second number to obtain a remainder result;
[0036] Store the transaction to be above-chained in the transaction storage space whose storage space index is the same as the remainder result.
[0037] Optionally, each of the transactions to be chained has a transaction digest value;
[0038] Specifically, the mapping unit is configured to:
[0039] For each of the transaction storage spaces, determine the digest range of the transaction storage space;
[0040] Based on the transaction digest value, determine the digest range where the transaction digest value is located as the target digest range;
[0041] Store the transaction to be chained in the transaction storage space whose digest range is the target digest range.
[0042] Optionally, the packaging unit is specifically configured to:
[0043] For each of the transactions to be chained in the target transaction storage space, obtain the transaction timestamp of the transaction to be chained;
[0044] Based on the order of the transaction timestamps, sequentially take out multiple transactions to be chained from the target transaction storage space and package them into the block to be consensus, until the size of the block to be consensus reaches a preset threshold.
[0045] Optionally, the packaging unit is specifically configured to:
[0046] For each of the transactions to be chained in the target transaction storage space, obtain the associated resource information of the transaction to be chained;
[0047] Determine the transaction packaging order based on the associated resource information;
[0048] Based on the transaction packaging order, sequentially take out multiple transactions to be chained from the target transaction storage space and package them into the block to be consensus, until the size of the block to be consensus reaches a preset threshold.
[0049] Optionally, the associated resource information includes an associated resource type and an associated resource quantity;
[0050] The determining the transaction packaging order based on the associated resource information includes:
[0051] For each of the transactions to be chained, based on the associated resource type, determine the first transaction score of the transaction to be chained;
[0052] For each of the transactions to be chained, based on the associated resource quantity, determine the second transaction score of the transaction to be chained;
[0053] Determine the total transaction score of the transaction to be chained based on the first transaction score and the second transaction score;
[0054] Sort the multiple transactions to be chained based on the magnitude of the total transaction score to obtain the transaction packaging order.
[0055] Optionally, the determining unit is specifically configured to:
[0056] Determine the node number of each master node and the storage space number of each transaction storage space;
[0057] Based on the node number and the storage space number, determine the target transaction storage space corresponding to the target master node.
[0058] Optionally, the blockchain consensus device further includes an updating unit, and the updating unit is used to update the target transaction storage space corresponding to the target master node;
[0059] The updating unit is specifically configured to:
[0060] Determine the node processing speed of each master node and the number of transactions of the current transactions to be chained in each transaction storage space;
[0061] Based on the node processing speed and the number of transactions, re-determine the target transaction storage space corresponding to the target master node.
[0062] Optionally, each transaction storage space has a storage space index;
[0063] The blockchain consensus device further includes a storage unit, and the storage unit is specifically configured to:
[0064] Determine the unchained transactions in each transaction storage space;
[0065] Update the current consensus round of the blockchain network to obtain the updated consensus round;
[0066] For each unchained transaction, perform a remainder operation on the sum of the round number of the updated consensus round and the transaction digest value of the unchained transaction and the second number of the transaction storage space to obtain a remainder;
[0067] Based on the remainder, re-store the unchained transaction to the transaction storage space with the same storage space index as the remainder to update each transaction storage space.
[0068] Optionally, the second number of master nodes is determined by the following method:
[0069] Determine the node credibility and node processing capabilities of each of the consensus nodes;
[0070] Based on the node credibility and the node processing capabilities, determine the second number of primary nodes among the first number of consensus nodes.
[0071] Optionally, the determining the second number of primary nodes among the first number of consensus nodes based on the node credibility and the node processing capabilities includes:
[0072] For each of the consensus nodes, determine a first score based on the node credibility;
[0073] For each of the consensus nodes, determine a second score based on the node processing capabilities;
[0074] Based on the first score and the second score, determine the total score of the consensus node;
[0075] Determine the consensus nodes with the top second number of total scores as the primary nodes.
[0076] Optionally, the second number is determined by the following method:
[0077] Obtain the total number of nodes in the blockchain network and the network operation information;
[0078] Based on the total number of nodes and the network operation information, determine the second number.
[0079] Optionally, the determining the second number based on the total number of nodes and the network operation information includes:
[0080] Based on the total number of nodes, determine a third score;
[0081] Based on the network operation information, determine a fourth score;
[0082] Based on the third score and the fourth score, determine the second number.
[0083] According to one aspect of the present disclosure, there is provided an electronic device including a memory and a processor, the memory storing a computer program, and the processor implementing the blockchain consensus method as described above when executing the computer program.
[0084] According to one aspect of the present disclosure, there is provided a computer-readable storage medium storing a computer program, and the computer program implements the blockchain consensus method as described above when executed by a processor.
[0085] According to one aspect of the present disclosure, there is provided a computer program product including a computer program, which is read and executed by a processor of a computer device, so that the computer device executes the blockchain consensus method as described above.
[0086] In the embodiments of the present disclosure, in each consensus round, not only one primary node performs packaging and uploading to the chain, but multiple primary nodes can perform parallel packaging and uploading to the chain. Multiple packages can be uploaded to the chain in one consensus round, improving the block generation efficiency. To prevent chaos in the consensus of multiple packages in one consensus round, multiple transaction storage spaces are placed in each consensus node, and each transaction storage space corresponds to one primary node. When each consensus node receives a transaction to be uploaded to the chain, according to a mapping rule, the transaction to be uploaded to the chain is mapped to one of its own transaction storage spaces. Since the mapping rules of different consensus nodes are the same, when the same transaction to be uploaded to the chain enters each consensus node, it is stored in the transaction storage space corresponding to the same primary node. When a target primary node in a certain consensus round wants to package and upload to the chain, it packages and uploads the transactions to be uploaded to the chain in the transaction storage space corresponding to the target primary node inside it, and sends them to the slave nodes for consensus. When the slave nodes perform consensus, they compare the transactions to be uploaded to the chain in the received block to be consensus with the transactions to be uploaded to the chain in the transaction storage space corresponding to the target primary node stored by themselves, thereby completing the consensus, achieving the effect of consensus on the uploading of multiple blocks in one consensus round without affecting the accuracy.
[0087] Other features and advantages of the present disclosure will be described in the following specification, and some of them will become obvious from the specification, or be understood by implementing the present disclosure. The objectives and other advantages of the present disclosure can be realized and obtained through the structures specifically pointed out in the specification, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] The drawings are used to provide a further understanding of the technical solutions of the present disclosure, and constitute a part of the specification. They are used together with the embodiments of the present disclosure to explain the technical solutions of the present disclosure, and do not constitute a limitation to the technical solutions of the present disclosure.
[0089] Figure 1 is a system architecture diagram of the application of the blockchain consensus method according to an embodiment of the present disclosure;
[0090] Figures 2A - 2E shows a schematic diagram of the application of the blockchain consensus method according to an embodiment of the present disclosure in the scenario of transaction uploading to the chain;
[0091] Figure 3 is a flowchart of the blockchain consensus method according to an embodiment of the present disclosure;
[0092] Figure 4Flowchart for determining the second number of transaction storage spaces according to an embodiment of the present disclosure;
[0093] Figure 5 Schematic diagram of the implementation process for determining the second number of transaction storage spaces according to an embodiment of the present disclosure;
[0094] Figure 6 Flowchart for mapping a transaction to be chained to a transaction storage space according to an embodiment of the present disclosure;
[0095] Figure 7 Flowchart for mapping a transaction to be chained to a transaction storage space according to another embodiment of the present disclosure;
[0096] Figure 8 Flowchart for determining the target transaction storage space corresponding to the target master node according to an embodiment of the present disclosure;
[0097] Figure 9 Flowchart for updating the target transaction storage space corresponding to the target master node according to an embodiment of the present disclosure;
[0098] Figures 10A - 10E Schematic diagram of the implementation process for updating the target transaction storage space corresponding to the target master node according to an embodiment of the present disclosure;
[0099] Figure 11 Flowchart for packaging a transaction to be chained into a block to be consensus according to an embodiment of the present disclosure;
[0100] Figure 12 Schematic diagram of the implementation process for packaging a transaction to be chained into a block to be consensus according to an embodiment of the present disclosure;
[0101] Figure 13 Flowchart for packaging a transaction to be chained into a block to be consensus according to another embodiment of the present disclosure;
[0102] Figure 14 Flowchart for determining the transaction packaging order according to an embodiment of the present disclosure;
[0103] Figure 15 Schematic diagram of the implementation process for packaging a transaction to be chained into a block to be consensus according to another embodiment of the present disclosure;
[0104] Figure 16 Flowchart for performing consensus on a block to be consensus according to an embodiment of the present disclosure;
[0105] Figure 17 Flowchart for performing consensus on a block to be consensus according to another embodiment of the present disclosure;
[0106] Figure 18 It is a schematic diagram of the implementation process for consensus on a consensus block according to an embodiment of the present disclosure;
[0107] Figure 19 It is a schematic diagram of the implementation process for consensus on a consensus block according to another embodiment of the present disclosure;
[0108] Figure 20 It is a flowchart of the process for uploading multiple consecutive target blocks based on multiple block heights according to an embodiment of the present disclosure;
[0109] Figure 21 It is a flowchart of determining a predetermined block height according to an embodiment of the present disclosure;
[0110] Figure 22 It is a schematic diagram of the implementation process for determining a predetermined block height according to an embodiment of the present disclosure;
[0111] Figure 23 It is a flowchart of updating each transaction storage space according to an embodiment of the present disclosure;
[0112] Figures 24A - 24C It is a schematic diagram of the implementation process for updating each transaction storage space according to an embodiment of the present disclosure;
[0113] Figure 25 It is a flowchart of determining a second number of primary nodes among the first number of consensus nodes according to an embodiment of the present disclosure;
[0114] Figure 26 It is a flowchart of determining primary nodes based on node credibility and node processing capabilities according to an embodiment of the present disclosure;
[0115] Figure 27 It is a flowchart of determining the second number according to an embodiment of the present disclosure;
[0116] Figures 28A - 28B It is a schematic diagram of the implementation process for determining primary nodes according to an embodiment of the present disclosure;
[0117] Figure 29 It is a module diagram of a blockchain consensus device according to an embodiment of the present disclosure;
[0118] Figure 30 It is a terminal structure diagram of a blockchain consensus method according to an embodiment of the present disclosure;
[0119] Figure 31 It is a server structure diagram of a blockchain consensus method according to an embodiment of the present disclosure. Detailed implementation manners
[0120] In order to make the objectives, technical solutions, and advantages of the present disclosure more clear and understandable, the present disclosure will be 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 disclosure and are not used to limit the present disclosure.
[0121] Before further elaborating on the embodiments of the present disclosure, the nouns and terms involved in the embodiments of the present disclosure are described. The nouns and terms involved in the embodiments of the present disclosure are applicable to the following explanations:
[0122] Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a way similar to human intelligence. Artificial intelligence also studies the design principles and implementation methods of various intelligent machines to enable the machines to have the functions of perception, reasoning, and decision-making. Artificial intelligence technology is an interdisciplinary subject involving a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, pre-trained model technology, operation / interaction systems, mechatronics, etc. Among them, pre-trained models, also known as large models or foundation models, can be widely applied to downstream tasks in various directions of artificial intelligence after fine-tuning. The software technologies of artificial intelligence mainly include several major directions such as computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning. With the research and progress of artificial intelligence technology, artificial intelligence technology has been studied and applied in multiple fields. For example, common ones include smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, driverless, autonomous driving, drones, robots, smart healthcare, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.
[0123] Blockchain: Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. In essence, it is a decentralized database, a string of data blocks generated by using cryptographic methods. Each data block contains information about a batch of transactions, which is used to verify the validity (anti-counterfeiting) of the information and link to the previous block.
[0124] Currently, during the process of uploading transactions to the blockchain, there are often multiple rounds of block consensus. In each round of block consensus, usually a consensus node (master node) packs multiple transactions to be uploaded into a block and broadcasts the block containing multiple transactions to other consensus nodes (slave nodes). Only after receiving the consensus confirmations from other consensus nodes can the block be uploaded to the blockchain. This method often causes significant resource waste in stages such as block broadcasting and consensus, leading to a decrease in the throughput of the blockchain and low efficiency in transaction uploading to the blockchain.
[0125] System Architecture and Scenario Description Applied in Embodiments of the Present Disclosure
[0126] Figure 1 It is a system architecture diagram to which the blockchain consensus method according to an embodiment of the present disclosure is applied. It includes an object terminal 140, the Internet 130, a gateway 120, a blockchain server 110, etc.
[0127] The object terminal 140 includes various forms such as a desktop computer, a laptop, a PDA (Personal Digital Assistant), a mobile phone, a vehicle-mounted terminal, a home theater terminal, a dedicated terminal, etc. Additionally, it can be a single device or a collection of multiple devices. The object terminal 140 can communicate with the Internet 130 in a wired or wireless manner to exchange data. Among them, the object terminal 140 includes a transaction processing system, and the transaction processing system is used for the object to send the transactions that need to be recorded on the blockchain to the blockchain server 110 according to actual needs.
[0128] See Figure 1 The blockchain server 110 shown. It includes a consensus network. The consensus network refers to a network that conducts consensus on transactions to be uploaded and then uploads them to the blockchain. It includes multiple consensus nodes. The consensus nodes are the blockchain nodes. The consensus nodes or blockchain nodes can be servers in the blockchain network or object terminals accessing the blockchain network. Here, the specific forms of the consensus nodes or blockchain nodes are not limited.
[0129] The gateway 120 is also called an inter-network connector and a protocol converter. The gateway realizes network interconnection at the transport layer and is a computer system or device that acts as a converter. Between two systems using different communication protocols, data formats, or languages, and even with completely different architectures, the gateway is a translator. At the same time, the gateway can also provide filtering and security functions. The messages sent by the object terminal 140 to the blockchain server 110 need to be sent to the corresponding blockchain server 110 through the gateway 120. The messages sent by the blockchain server 110 to the object terminal 140 also need to be sent to the corresponding object terminal 140 through the gateway 120.
[0130] The embodiments of the present disclosure can be applied in various scenarios, such as Figures 2A - 2E The transaction uploading scenario shown, etc.
[0131] As Figure 2A shown, the blockchain server 110 contains a consensus network, and in the consensus network, there are consensus nodes 1, 2, 3, 4, 5, 6, 7, and 8.
[0132] As Figure 2B shown, in each consensus round, all 8 consensus nodes in the consensus network are regarded as the primary nodes. Among them, when the primary node is consensus node 1, the secondary nodes are consensus nodes 2, 3, 4, 5, 6, 7, and 8. When the primary node is consensus node 2, the secondary nodes are consensus nodes 1, 3, 4, 5, 6, 7, and 8. When the primary node is consensus node 3, the secondary nodes are consensus nodes 2, 1, 4, 5, 6, 7, and 8. And so on, to determine the secondary nodes corresponding to each primary node.
[0133] As Figure 2C shown, in a consensus round, when the primary node is consensus node 1, consensus node 1 packs transactions 1, 2, 3, and 4 into block 1. When the primary node is consensus node 2, consensus node 2 packs transactions 5, 6, and 7 into block 2. When the primary node is consensus node 3, consensus node 3 packs transactions 8, 9, 10, and 11 into block 3. And so on, each primary node packs a part of the transactions to be chained into a block, where the transactions to be chained packed by each primary node are different to avoid duplicate packing of the same transaction to be chained. Based on this, each consensus node corresponds to a block.
[0134] As Figure 2D shown, in a consensus round, consensus node 1 packs and generates block 1 with a block height of 101; consensus node 2 packs and generates block 2 with a block height of 102; consensus node 3 packs and generates block 3 with a block height of 103; consensus node 4 packs and generates block 4 with a block height of 105; consensus node 5 packs and generates block 5 with a block height of 99; consensus node 6 packs and generates block 6 with a block height of 100; consensus node 7 packs and generates block 7 with a block height of 104; consensus node 8 packs and generates block 8 with a block height of 106.
[0135] As Figure 2EAs shown, according to the block heights of each block, each block is recorded on the blockchain in ascending order of block height, so as to implement the on-chain processing of multiple to-be-on-chain transactions of multiple blocks in one consensus round. Specifically, during the on-chain process, the on-chain order of each block is [Block 5, Block 6, Block 1, Block 2, Block 3, Block 7, Block 4, Block 8].
[0136] General Description of Embodiments of the Present Disclosure
[0137] According to an embodiment of the present disclosure, a blockchain consensus method is provided.
[0138] This blockchain consensus method is generally applied to business scenarios with a large number of to-be-on-chain transactions in a short period of time, such as Figures 2A - 2E the shown transaction on-chain scenario. The embodiment of the present disclosure provides a solution for setting multiple primary nodes in the same consensus round, enabling the multiple primary nodes to generate blocks and conduct consensus in parallel, and being able to consensus multiple blocks for on-chain in one consensus round, improving the throughput speed of the blockchain network and the transaction on-chain efficiency.
[0139] The blockchain consensus method of the embodiment of the present disclosure has multiple consensus rounds, and in each consensus round, it is applied to the target primary nodes among the second number of primary nodes in the first number of consensus nodes. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has the second number of transaction storage spaces respectively corresponding to the second number of primary nodes.
[0140] The second number is the total number of primary nodes in each consensus round.
[0141] The transaction storage space refers to the virtual space in the consensus node for storing to-be-on-chain transactions. Among them, the transaction storage space is a part of the transaction pool of the consensus node.
[0142] As Figure 3 shown, the blockchain consensus method according to an embodiment of the present disclosure may include:
[0143] Step 310: Obtain to-be-on-chain transactions;
[0144] Step 320: Based on the mapping rule of the to-be-on-chain transactions in the second number of transaction storage spaces, map the to-be-on-chain transactions to a transaction storage space;
[0145] Step 330: Determine the target transaction storage space corresponding to the target primary node in the second number of transaction storage spaces;
[0146] Step 340: For each primary node, pack the multiple to-be-on-chain transactions in the target transaction storage space corresponding to the primary node into a preliminary block;
[0147] Step 350: For each primary node, perform consensus processing on the preliminary block based on the slave nodes corresponding to the primary node to obtain a target block, so as to perform the on-chain processing on multiple consecutive target blocks.
[0148] The following will describe steps 310 - 350 in detail.
[0149] In step 310, obtain the transaction to be put on the chain.
[0150] The transaction to be put on the chain is a transaction sent by the object terminal and intended to be recorded on the blockchain. The transaction to be put on the chain can be some resource interaction transactions, object verification transactions, or other transactions that meet the requirements for being recorded on the blockchain. There is no limitation.
[0151] In the specific implementation of this embodiment, when an object wants to record a certain transaction on the blockchain, it will send a transaction on-chain request to the blockchain network. Based on this, the transaction information can be extracted from the transaction indicated by the received transaction on-chain request, so as to obtain the transaction to be put on the chain.
[0152] In another embodiment, since each consensus node in the blockchain network will broadcast the received transaction to be put on the chain to other consensus nodes after receiving it from the object terminal. Based on this, the target primary node can also receive the transaction to be put on the chain based on the broadcast of other consensus nodes.
[0153] In step 320, map the transaction to be put on the chain to a transaction storage space based on the mapping rule in the second number of transaction storage spaces.
[0154] The mapping rule is used to indicate which transaction storage space in the second number of transaction storage spaces the transaction to be put on the chain is mapped to.
[0155] In the blockchain network, each transaction to be put on the chain has a transaction digest value, and the transaction digest values of each transaction to be put on the chain are different. Based on this, the mapping rule of the embodiments of the present disclosure can be defined to divide the transaction storage space to which each transaction to be put on the chain is mapped and stored according to the transaction digest value of the transaction to be put on the chain.
[0156] In the embodiments of the present disclosure, the specific implementation process of step 320 will be described in detail below. It will not be elaborated here.
[0157] In step 330, determine the target transaction storage space corresponding to the target primary node in the second number of transaction storage spaces.
[0158] The target transaction storage space is the transaction storage space among the multiple transaction storage spaces that allows the target primary node to take out and package the transaction to be put on the chain.
[0159] In the embodiments of the present disclosure, the target storage transaction storage spaces corresponding to different master nodes are different.
[0160] In the embodiments of the present disclosure, the specific implementation process of step 330 will be described in detail below. It will not be elaborated here.
[0161] In step 340, the to-be-chained transactions stored in the target transaction storage space are packaged into a to-be-consensus block, and the to-be-consensus block is sent to the slave nodes.
[0162] The slave nodes are consensus nodes other than the target master node. For example, when the blockchain network includes consensus node 1, consensus node 2, consensus node 3, and consensus node 4, if consensus node 1 and consensus node 2 are used as the master nodes, then the slave nodes corresponding to consensus node 1 are consensus node 2, consensus node 3, and consensus node 4; the slave nodes corresponding to consensus node 2 are consensus node 1, consensus node 3, and consensus node 4.
[0163] The to-be-consensus block is generated by the target master node but has not been consensus by the slave nodes corresponding to the target master node.
[0164] After sending the to-be-consensus block to the slave nodes, each slave node conducts consensus on the to-be-chained transactions in the to-be-consensus block based on the target transaction storage space corresponding to the target master node in the slave node.
[0165] When the slave nodes conduct consensus on the to-be-consensus block, the slave nodes will verify whether all the to-be-chained transactions in the to-be-consensus block originate from the target transaction storage space and whether the transaction association information of the to-be-chained transactions in each to-be-consensus block is the same as that of the to-be-chained transactions in the target transaction storage space corresponding to its own target master node, according to the multiple to-be-chained transactions in the target transaction storage space corresponding to its own target master node. After the verification passes, the slave nodes will vote and broadcast on whether to allow the to-be-consensus block to be chained, so as to achieve the effect of consensus on the to-be-consensus block based on the voting, broadcasting and other node interactions of multiple slave nodes.
[0166] It should be noted that the transaction association information verified by the slave nodes may include the transaction digest value, transaction type, etc. of the to-be-chained transactions. In addition to verifying the transaction association information of each to-be-chained transaction, the slave nodes can also verify information such as the block header and block height of the to-be-consensus block, without limitation.
[0167] In the embodiments of the present disclosure, the specific implementation process of step 340 will be described in detail below. It will not be elaborated here.
[0168] Through the above steps 310-340, in the embodiments of the present disclosure, in each consensus round, there is not only one primary node for packaging and uploading to the chain, but multiple primary nodes can package and upload to the chain in parallel. Multiple packages can be uploaded to the chain in one consensus round, improving the block generation efficiency. To prevent chaos in the consensus of multiple packages in one consensus round, multiple transaction storage spaces are placed in each consensus node, and each transaction storage space corresponds to one primary node. When each consensus node receives a transaction to be uploaded to the chain, according to a mapping rule, the transaction to be uploaded to the chain is mapped to one of its transaction storage spaces. Since the mapping rules of different consensus nodes are the same, after the same transaction to be uploaded to the chain enters each consensus node, it is stored in the transaction storage space corresponding to the same primary node. When a target primary node in a certain consensus round wants to package and upload to the chain, it packages and uploads the transaction to be uploaded to the chain in the transaction storage space corresponding to the target primary node inside it, and sends it to the slave node for consensus. When the slave node conducts consensus, it compares the transaction to be uploaded to the chain in the received block to be consensus with the transaction to be uploaded to the chain in the transaction storage space corresponding to the target primary node stored by itself, thereby completing the consensus, achieving the effect of consensus on the upload of multiple blocks in one consensus round without affecting the accuracy.
[0169] The above is the overall description of steps 310-340. Since step 310 has been described in detail in the above overall description, the following will elaborate on the specific implementations of steps 320, 330, and 340.
[0170] Detailed Description of Step 320
[0171] In step 320, based on the mapping rule of the transaction to be uploaded to the chain in the second number of transaction storage spaces, the transaction to be uploaded to the chain is mapped to one transaction storage space.
[0172] Please refer to Figure 4 , in one embodiment, the second number of transaction storage spaces is determined in the following manner:
[0173] Step 410: Determine the number of nodes of the primary node in the current consensus round;
[0174] Step 420: Based on the number of nodes, equally divide the transaction pool of the consensus node in terms of space to obtain the second number of transaction storage spaces.
[0175] The following will elaborate on steps 410-420 in detail.
[0176] In step 410, determine the number of nodes of the primary node in the current consensus round.
[0177] In the specific implementation of this embodiment, in the current consensus round, after determining the primary node among multiple consensus nodes in the blockchain network, various methods such as the sum summation function can be used to perform node statistics on the primary node to obtain the total number of primary nodes in the blockchain network, and then determine the obtained total number as the number of primary nodes.
[0178] In step 420, the transaction pool of the consensus nodes is equally divided in space based on the number of nodes to obtain the second number of transaction storage spaces.
[0179] In order to ensure that each primary node corresponds to at least one transaction storage space and that the transaction storage spaces corresponding to different primary nodes are different from each other to reduce the risk of duplicate transaction packaging, the number of nodes can be used as the second number of transaction storage spaces.
[0180] For example, when there are 10 consensus nodes in the blockchain network and 4 of them are used as primary nodes, the primary nodes of the blockchain network are primary node 1, primary node 2, primary node 3, and primary node 4. Further, the second number of transaction storage spaces is determined to be 4, so that each primary node corresponds to one transaction storage space.
[0181] In the specific implementation of this embodiment, first, according to the number of nodes (the second number), the transaction pool of the consensus nodes is equally divided in space to obtain the second number of equal division regions. Then, each equal division region of the transaction pool is used as a transaction storage space to obtain the second number of transaction storage spaces.
[0182] As Figure 5 shown, it is the transaction pool of a consensus node, and the transaction pool is represented in the form of a digest ring. There are multiple digest slots on the transaction pool (digest ring), and the digest values corresponding to each digest slot are different. The transactions to be chained received by the consensus node will be stored in the respective digest slots of the transaction pool. Among them, the digest value of the digest slot where the transaction to be chained is stored is the same as the transaction digest value of the transaction to be chained. Based on this, when there are 4 primary nodes in the blockchain network, the transaction pool of the consensus node is equally divided into 4 parts, and each corresponding arc region is used as a transaction storage space. Specifically, the upper left 1 / 4 arc region is transaction storage space 4, which can also be called bucket 4; the upper right 1 / 4 arc region is transaction storage space 1, which can also be called bucket 1; the lower left 1 / 4 arc region is transaction storage space 3, which can also be called bucket 3; the upper right 1 / 4 arc region is transaction storage space 2, which can also be called bucket 2. Based on this, when the transaction digest value of a certain transaction to be chained falls in the upper left 1 / 4 arc region, the transaction to be chained is stored in the transaction storage space 4 of the consensus node.
[0183] The advantage of this embodiment is that, according to the number of master nodes in the blockchain network, the second number of transaction storage spaces is determined to be a value not less than the number of nodes, so that each master node corresponds to at least one transaction storage space, and the transaction storage spaces corresponding to different master nodes are different from each other, which can effectively reduce the risk of duplicate transaction uploading caused by multiple master nodes packing the same transaction to be uploaded to the chain. Further, after determining the number of transaction storage spaces, the transaction pools of the consensus nodes are equally divided, and each divided area becomes a transaction storage space, which can make multiple transaction storage spaces have relatively consistent storage capacities, improve the balance of transaction storage, avoid too large a difference in the number of transactions to be uploaded stored in each transaction storage space, and improve the rationality of transaction storage.
[0184] In the embodiments of the present disclosure, each transaction to be uploaded to the chain has a transaction digest value, which is obtained by concatenating the transaction name, transaction type, etc. of each transaction to be uploaded to the chain and performing a digest operation on the concatenation result.
[0185] Please refer to Figure 6 , in one embodiment, step 320 includes but is not limited to the following steps 610-630:
[0186] Step 610: For each transaction storage space, determine the digest interval of the transaction storage space;
[0187] Step 620: Based on the transaction digest value, determine the digest interval where the transaction digest value is located as the target digest interval;
[0188] Step 630: Store the transaction to be uploaded to the chain in the transaction storage space whose digest interval is the target digest interval.
[0189] The following describes steps 610-630 in detail.
[0190] In step 610, for each transaction storage space, determine the digest interval of the transaction storage space.
[0191] The digest interval is used to indicate the value range of the digest values of the digest slots for storing transactions to be uploaded to the chain in the transaction storage space.
[0192] In the specific implementation of this embodiment, since when dividing the transaction pool into multiple transaction storage spaces for each consensus node, the digest slots of each transaction storage space are determined, therefore, the multiple digest values corresponding to each transaction storage space are also determined. Based on this, for each transaction storage space, first determine the maximum digest value and the minimum digest value among the digest values of the digest slots in this transaction storage space; then, use the range determined by the maximum digest value and the minimum digest value as the digest interval of the transaction storage space.
[0193] In step 620, based on the transaction digest value, the digest interval where the transaction digest value is located is determined as the target digest interval.
[0194] The target digest interval is used to indicate the range where the transaction digest value of the transaction to be chained lies.
[0195] In the specific implementation of this embodiment, first, the transaction digest value is compared with each digest value in the digest intervals of each transaction storage space. Then, if there is a digest value in the digest interval of a certain transaction storage space that is the same as the transaction digest value, the digest interval is determined as the digest interval where the transaction digest value is located, and this digest interval is used as the target digest interval.
[0196] In step 630, the transaction to be chained is stored in the transaction storage space whose digest interval is the target digest interval.
[0197] In the specific implementation of this embodiment, first, the transaction storage space corresponding to the target digest interval is determined. Then, the transaction to be chained is stored in the transaction storage space whose digest interval is the target digest interval to implement the storage of the transaction to be chained.
[0198] The advantage of this embodiment is that, by comparing the transaction digest value of the transaction to be chained with the digest values of the digest slots in each transaction storage space, different transactions to be chained can be quickly stored in different transaction storage spaces, which can effectively improve the transaction storage efficiency.
[0199] Although the above comparison of the transaction digest value of the transaction to be chained with the digest values of the digest slots in each transaction storage space can achieve the effect of storing different transactions to be chained in different transaction storage spaces, this method will make the transaction storage space where the transaction to be chained is stored fixed. When the correspondence between the master node and the transaction storage space remains unchanged, if a certain master node is a Byzantine node or a dishonest node, it often leads to the situation that multiple transactions to be chained in the transaction storage space corresponding to the master node cannot be normally packaged and chained, resulting in the transaction being delayed or not chained, which is not conducive to the normal processing of transactions. Based on this, the embodiments of the present disclosure provide a solution for transaction storage based on the current consensus round and the transaction digest value of the transaction to be chained, which can improve the flexibility and rationality of transaction storage and reduce the risk that transactions cannot be normally chained due to the abnormality of a certain node.
[0200] In the embodiments of the present disclosure, each transaction storage space has a storage space index. The storage space index is used to identify different transaction storage spaces, and the storage space indexes of different transaction storage spaces are different. Among them, the storage space index can be a number, a letter, or a combination of numbers and letters.
[0201] To improve the index matching speed, the storage space index of each transaction storage space is represented by a number. For example, for a transaction storage space 001, its storage space index is 1.
[0202] Please refer to Figure 7 , in another embodiment, step 320 includes but is not limited to the following steps 710-740:
[0203] Step 710, determine the round number of the current consensus round of the blockchain network;
[0204] Step 720, sum the round number of the current consensus round and the transaction digest value to obtain a sum result;
[0205] Step 730, perform a modulo operation based on the sum result and the second number to obtain a modulo result;
[0206] Step 740, store the transaction to be chained to the transaction storage space whose storage space index is the same as the modulo result.
[0207] The following is a detailed description of steps 710-740.
[0208] In step 710, determine the round number of the current consensus round of the blockchain network.
[0209] The current consensus round refers to the consensus round in which the primary node and the secondary nodes of the blockchain network are at the current time.
[0210] The round number is used to identify which round of consensus the current consensus round is in the blockchain network.
[0211] In the specific implementation of this embodiment, since the background of the server to which the blockchain network belongs often records the network operation information of the blockchain network and generates corresponding log data. Based on this, with authorization, obtain the log data of the blockchain network from the server background, and determine the consensus round in which the primary node and the secondary nodes of the blockchain network are at the current time according to the blockchain consensus information recorded in the log data, and obtain the round number of the current consensus round.
[0212] For example, when it is the first consensus stage of the blockchain network currently, then the round number of the current consensus round is 1.
[0213] In step 720, sum the round number of the current consensus round and the transaction digest value to obtain a sum result.
[0214] In the specific implementation of this embodiment, for each transaction to be chained, add the transaction digest value and the round number of the transaction to be chained to obtain a sum result. Specifically, the transaction digest value of the i-th transaction to be chained can be expressed as hash(ti ), the round number can be represented as r. At this time, the summation result can be expressed as hash(t i ) + r.
[0215] In step 730, a modulo operation is performed based on the summation result and the second number to obtain a modulo result.
[0216] In the specific implementation of this embodiment, first, the modulo function (mod) is called; then, the called mod function is used to perform a modulo operation on the summation result and the second number. Specifically, the summation result is used as the dividend, the storage space number is used as the divisor, the summation result is divided by the storage space number, and the obtained remainder is used as the modulo result. Among them, the second number can be represented as n, where n is an integer not greater than 2 and not greater than the first number; the modulo result can be expressed as (hash(t i ) + r) mod n.
[0217] In step 740, the transaction to be chained is stored in the transaction storage space where the storage space index is the same as the modulo result.
[0218] In the specific implementation of this embodiment, first, the modulo result is compared with the storage space index of each transaction storage space. If there is a transaction storage space whose storage space index is the same as the modulo result, the transaction to be chained is stored in this transaction storage space where the storage space index is the same as the modulo result.
[0219] It should be noted that in different consensus rounds, the above-mentioned round numbers are different. Even if the transaction digest value of the same transaction to be chained remains unchanged, based on the above method, there will be certain differences in the modulo results calculated for the same transaction to be chained in different consensus rounds. Therefore, it is possible to make the same transaction to be chained fall into different transaction storage spaces with a certain probability in different consensus rounds.
[0220] For example, in the first consensus round, the modulo result of the transaction A to be chained is 4, and the transaction A to be chained is stored in transaction storage space 4. When the primary node 4 packs the transactions to be chained in transaction storage space 4, but the primary node is a Byzantine node, the transaction A to be chained will not be packed and chained in the first consensus round. At this time, in the second consensus round, the transaction A to be chained still exists in the transaction pool, but the modulo result of the transaction A to be chained becomes 2. The transaction A to be chained is re-stored in transaction storage space 2, and the primary node 2 packs the transactions to be chained in transaction storage space 2. When the primary node 2 is a normal node, the transaction A to be chained will be taken out and packed by the primary node 2 from transaction storage space 2, so that the transaction A to be chained can still be recorded on the blockchain.
[0221] The advantage of this embodiment is that the transaction storage is performed based on the current consensus round and the transaction digest value of the transaction to be chained. This makes the transaction storage space for the transaction to be chained jointly determined by the transaction digest value and the consensus round, such that the same transaction to be chained has a probability of being stored in different transaction storage spaces in different consensus rounds. This enables the same transaction to be chained to be packaged into a block and chained by different primary nodes in different consensus rounds, improving the flexibility and rationality of transaction storage and reducing the risk that transactions cannot be normally chained due to an abnormality of a certain node.
[0222] Detailed Description of Step 330
[0223] In step 330, determine the target transaction storage space corresponding to the target primary node among the second number of transaction storage spaces.
[0224] When this embodiment is specifically implemented, when determining the target transaction storage space corresponding to the target primary node among the second number of transaction storage spaces, a random matching method can be adopted, randomly selecting a transaction storage space as the target transaction storage space, which can improve the determination efficiency of the target transaction storage space. However, the random matching method has a problem of relatively large uncertainty. If the target primary node is a consensus node with a poor node processing speed, and the target transaction storage space is a transaction storage space storing a relatively large number of transactions to be chained, it will cause the problem of low efficiency in transaction packaging and chaining. Based on this, the embodiments of the present disclosure provide a solution for determining the target transaction storage space according to the number matching method or according to the node processing speed and the number of transactions to be chained in the transaction storage space, which can improve the rationality of the determined target transaction storage space.
[0225] Please refer to Figure 8 , in one embodiment, the process of determining the target transaction storage space corresponding to the target primary node includes but is not limited to the following steps 810-820:
[0226] Step 810: Determine the node number of each primary node and the storage space number of each transaction storage space;
[0227] Step 820: Based on the node number and the storage space number, determine the target transaction storage space corresponding to the target primary node.
[0228] The following will describe steps 810-820 in detail.
[0229] In step 810, determine the node number of each primary node and the storage space number of each transaction storage space.
[0230] The node number is used to identify each primary node to distinguish different primary nodes.
[0231] The storage space number is used to identify each transaction storage space to distinguish different transaction storage spaces.
[0232] In the embodiments of the present disclosure, both the node number and the storage space number start from 1 and increase gradually. For example, the node number of the first consensus node joining the blockchain network is A001, and the node number of the second consensus node joining the blockchain network is A002. The storage space numbers of multiple transaction storage spaces are K1, K2, ... in sequence.
[0233] In the specific implementation of this embodiment, since each consensus node will be assigned a number when joining the blockchain network. Based on this, after determining multiple primary nodes from multiple consensus nodes, the number of the consensus node determined as the primary node is used as the node number.
[0234] Furthermore, the storage space number of the transaction storage space is equivalent to the storage space index of the transaction storage space, and its determination process is similar to the process of determining the storage space index described above. For the sake of brevity, it will not be elaborated here.
[0235] In step 820, based on the node number and the storage space number, determine the target transaction storage space corresponding to the target primary node.
[0236] In the specific implementation of this embodiment, first, arrange each primary node in ascending order of the node number to obtain the first sequence. Then, arrange each transaction storage space in ascending order of the storage space number to obtain the second sequence. Further, use the first transaction storage space in the second sequence as the target transaction storage space of the first primary node in the first sequence; use the second transaction storage space in the second sequence as the target transaction storage space of the second primary node in the first sequence, and so on, to construct the mapping relationship of each element in the first sequence and the second sequence, so as to achieve the purpose of determining the target transaction storage space corresponding to the target primary node.
[0237] For example, the first sequence of primary nodes is [A001, A002, ..., An]; the second sequence of transaction storage spaces is [K1, K2, ..., Kn]. Based on this, the target storage space of primary node A001 is K1; the target storage space of primary node A002 is K2; ...; the target storage space of primary node An is Kn.
[0238] The advantage of this embodiment is that according to the node numbers of each primary node and the storage space numbers of each transaction storage space, in a pairwise comparison manner, determine the target transaction storage space corresponding to each primary node in multiple transaction storage spaces, which can reduce the risk of using the same transaction storage space as the target transaction storage space of multiple primary nodes, and improve the matching efficiency and matching accuracy.
[0239] After determining the target transaction storage space corresponding to the target master node, if the target transaction storage space corresponding to the target master node is updated in each consensus round, the same transaction to be chained will always be stored in the same transaction storage space. When the transaction storage space where the transaction to be chained is always stored is the target transaction storage space of a faulty node, it will cause the transaction to be chained to fail to be chained normally, affecting the security of transaction processing in the blockchain. Based on this, the embodiments of the present disclosure provide a solution for updating the target transaction storage space corresponding to the target master node after multiple blocks are consensus-chained in each round, which can enable the same transaction to be chained to have the opportunity to be stored in different transaction storage spaces, improving the security and stability of transaction chaining.
[0240] Please refer to Figure 9 , in one embodiment, for each consensus round, after processing multiple consecutive target blocks for chaining, the process of updating the target transaction storage space corresponding to the target master node includes but is not limited to the following steps 910-920:
[0241] Step 910: Determine the node processing speed of each master node and the number of transactions of the current transactions to be chained in each transaction storage space;
[0242] Step 920: Based on the node processing speed and the number of transactions, re-determine the target transaction storage space corresponding to the target master node.
[0243] The following is a detailed description of steps 910-920.
[0244] In step 910, determine the node processing speed of each master node and the number of transactions of the current transactions to be chained in each transaction storage space.
[0245] The node processing speed is used to indicate the time required for each master node to complete one round of consensus.
[0246] The number of transactions of the current transactions to be chained is used to indicate the total number of transactions to be chained still stored in the transaction storage space after one round of consensus is completed.
[0247] In the specific implementation of this embodiment, after one consensus round is executed, first, the time taken for each master node from block generation to completion of consensus is counted to obtain the node processing speed of each master node. Further, the number of transactions to be chained still stored in each transaction storage space is counted to obtain the number of transactions of the current transactions to be chained in each transaction storage space.
[0248] In step 920, based on the node processing speed and the number of transactions, re-determine the target transaction storage space corresponding to the target master node.
[0249] In the specific implementation of this embodiment, first, arrange each master node in descending order of node processing speed to obtain the first sorting. Then, arrange each transaction storage space in descending order of the number of transactions to be chained currently to obtain the second sorting. Further, use the first transaction storage space in the second sorting as the target transaction storage space of the first master node in the first sorting; use the second transaction storage space in the second sorting as the target transaction storage space of the second master node in the first sorting, and so on, to construct the mapping relationship of each element in the first sorting and the second sorting, thereby achieving the effect of re-determining the target transaction storage space corresponding to the target master node.
[0250] As Figure 10A shown, in the current consensus round, the 4 consensus nodes (Node 1, Node 2, Node 3, and Node 4) in the blockchain network all contain 4 transaction storage spaces, and the 4 consensus nodes are all master nodes. Among them, when the master node is Node 1, Node 2, Node 3, and Node 4 are all slave nodes. When the master node is Node 2, Node 1, Node 3, and Node 4 are all slave nodes. When the master node is Node 3, Node 2, Node 1, and Node 4 are all slave nodes. When the master node is Node 4, Node 2, Node 3, and Node 1 are all slave nodes. Specifically, in the current consensus round, the target transaction storage space corresponding to Node 1 is Transaction Storage Space 1, the target transaction storage space corresponding to Node 2 is Transaction Storage Space 2, the target transaction storage space corresponding to Node 3 is Transaction Storage Space 3, and the target transaction storage space corresponding to Node 4 is Transaction Storage Space 4.
[0251] As Figure 10B shown, the transactions to be chained in Transaction Storage Space 1 corresponding to Master Node 1 include Transaction 1, Transaction 5, Transaction 9, and Transaction 13; the transactions to be chained in Transaction Storage Space 2 corresponding to Master Node 2 include Transaction 2, Transaction 6, Transaction 10, and Transaction 14; the transactions to be chained in Transaction Storage Space 3 corresponding to Master Node 3 include Transaction 3, Transaction 7, Transaction 11, and Transaction 15; the transactions to be chained in Transaction Storage Space 4 corresponding to Master Node 4 include Transaction 4, Transaction 8, Transaction 12, and Transaction 16. Master Node 1 packs Transaction 1, Transaction 5, Transaction 9, and Transaction 13 all into a block to be consensus. Master Node 2 packs Transaction 10 and Transaction 14 into a block to be consensus. Master Node 3 packs Transaction 3, Transaction 7, Transaction 11, and Transaction 15 all into a block to be consensus. Master Node 4 is a Byzantine node, and Transaction 4, Transaction 8, Transaction 12, and Transaction 16 in Transaction Storage Space 4 are not packed. Based on this, there are no remaining transactions in Transaction Storage Space 1 and Transaction Storage Space 3; there are remaining transactions 2 and 6 in Transaction Storage Space 2, and remaining transactions 4, Transaction 8, Transaction 12, and Transaction 16 in Transaction Storage Space 4.
[0252] As Figure 10CAs shown, the correspondence between the primary node and the transaction storage space for the current consensus round (the k-th round of consensus) is updated. In the next consensus round (the (k + 1)-th round of consensus), the target transaction storage space corresponding to Node 1 is Transaction Storage Space 2, the target transaction storage space corresponding to Node 2 is Transaction Storage Space 3, the target transaction storage space corresponding to Node 3 is Transaction Storage Space 4, and the target transaction storage space corresponding to Node 4 is Transaction Storage Space 1.
[0253] As Figure 10D shown, in the next consensus round (the (k + 1)-th round of consensus), the 4 consensus nodes (Node 1, Node 2, Node 3, and Node 4) in the blockchain network also include 4 transaction storage spaces, and all 4 consensus nodes are primary nodes. However, the target transaction storage spaces corresponding to each primary node have changed.
[0254] As Figure 10E shown, in the next consensus round (the (k + 1)-th round of consensus), the transactions to be chained on Transaction Storage Space 2 corresponding to Primary Node 1 include Transaction 2, Transaction 6, Transaction 17, and Transaction 18; the transactions to be chained on Transaction Storage Space 3 corresponding to Primary Node 2 include Transaction 19, Transaction 20, Transaction 21, and Transaction 22; the transactions to be chained on Transaction Storage Space 4 corresponding to Primary Node 3 include Transaction 4, Transaction 8, Transaction 12, and Transaction 16; the transactions to be chained on Transaction Storage Space 1 corresponding to Primary Node 4 include Transaction 23, Transaction 24, and Transaction 25. Based on this, it can be determined that in different consensus rounds, although the same transaction to be chained is stored in the same transaction storage space, the transaction storage space storing the transaction to be chained corresponds to different primary nodes. Therefore, in different consensus rounds, different primary nodes package and chain the transaction to be chained.
[0255] The advantage of this embodiment is that after multiple blocks are consensus-chained in each round, the scheme of updating the target transaction storage space corresponding to the target primary node according to the node processing speed of each primary node and the number of transactions to be chained in each transaction storage space can enable the same transaction to be chained to have the opportunity to be stored in different transaction storage spaces, improving the security and stability of transaction chaining.
[0256] Detailed Description of Step 340
[0257] In step 340, the transactions to be chained stored in the target transaction storage space are packaged into a block to be consensus and the block to be consensus is sent to the slave nodes.
[0258] In the specific implementation of this embodiment, in each consensus round, each primary node has a separate consensus instance and executes a consensus process respectively. Based on this, in a consensus round, the target primary node packs the transactions to be chained stored in the target transaction storage space according to its own consensus instance, and jointly performs consensus on the packed block with multiple secondary nodes of its own consensus instance and chains it. Among them, packing the transactions to be chained stored in the target transaction storage space can be randomly selecting a certain number of transactions to be chained for packing, or packing multiple transactions to be chained according to a predetermined extraction order.
[0259] Please refer to Figure 11 , in one embodiment, the specific process of step 340 includes but is not limited to the following steps 1110-1120:
[0260] Step 1110, for each transaction to be chained in the target transaction storage space, obtain the transaction timestamp of the transaction to be chained;
[0261] Step 1120, based on the order of the transaction timestamps from early to late, sequentially extract multiple transactions to be chained from the target transaction storage space and pack them into the block to be consensus, until the size of the block to be consensus reaches a preset threshold.
[0262] The following describes steps 1110-1120 in detail.
[0263] In step 1110, for each transaction to be chained in the target transaction storage space, obtain the transaction timestamp of the transaction to be chained.
[0264] The transaction timestamp is used to indicate the time point when each transaction to be chained is generated.
[0265] In the specific implementation of this embodiment, since when each object terminal sends a transaction to be chained to the blockchain network, the blockchain network will record the associated information of the received transaction to be chained, where the associated information includes the terminal address of the object terminal that sends the transaction to be chained, and the transaction timestamp of the transaction to be chained, etc. Based on this, with authorization, extract the transaction timestamp of each transaction to be chained from the background log of the blockchain network.
[0266] In step 1120, based on the order of the transaction timestamps from early to late, sequentially extract multiple transactions to be chained from the target transaction storage space and pack them into the block to be consensus, until the size of the block to be consensus reaches a preset threshold.
[0267] The preset threshold is used to indicate the maximum number of transactions to be chained that the block to be consensus can accommodate. The preset threshold can be determined according to actual business requirements without limitation.
[0268] In the specific implementation of this embodiment, first, according to the transaction timestamps of each transaction to be chained, the transactions to be chained are sorted in ascending order of the transaction timestamps. Among them, the transactions to be chained with earlier transaction timestamps are arranged in the front positions, and the transactions to be chained with later transaction timestamps are arranged in the rear positions. Then, during the sorting, multiple transactions to be chained are sequentially taken out and packed into the block to be consensus, and the number of the transactions to be chained taken out is recorded. And so on, until the number of the transactions to be chained taken out and packed into the block to be consensus is equal to the preset threshold. At this time, the number of the transactions to be chained that the block to be consensus can accommodate reaches the maximum value, and the extraction of the transactions to be chained stops. Finally, after all the taken-out transactions to be chained are packed into the block to be consensus, the target master node broadcasts the block to be consensus to each slave node.
[0269] As Figure 12 shown, there are 8 transactions to be chained stored in the target transaction storage space corresponding to the target master node, which are transaction 1 with a transaction timestamp of 14:00:05, transaction 2 with a transaction timestamp of 11:30:12, transaction 3 with a transaction timestamp of 11:22:11, transaction 4 with a transaction timestamp of 13:33:12, transaction 5 with a transaction timestamp of 10:07:55, transaction 6 with a transaction timestamp of 16:25:05, transaction 7 with a transaction timestamp of 10:47:35, and transaction 8 with a transaction timestamp of 15:05:17. The transactions to be chained are sorted according to the transaction timestamps, and the sorting is [transaction 5, transaction 7, transaction 3, transaction 2, transaction 4, transaction 1, transaction 8, transaction 6]. When the maximum number of the transactions to be chained that the block to be consensus can accommodate is 4, 4 transactions to be chained with earlier transaction timestamps are taken out from the target transaction storage space in ascending order of the transaction timestamps for packing. Based on this, the transactions to be chained packed into the block to be consensus are transaction 2, transaction 3, transaction 5, and transaction 7.
[0270] The advantage of this embodiment is that when packing the transactions to be chained stored in the target transaction storage space into the block to be consensus, according to the ascending order of the transaction timestamps of each transaction to be chained, the earlier-generated transactions to be chained are preferentially taken out and packed into the block to be consensus, which can enable the earlier-generated transactions to be chained first, improving the timeliness of transaction chaining.
[0271] Since there will be certain differences in the importance of the resources associated with each transaction to be chained, and there will also be differences in the types and numbers of the associated resources. When the resources associated with the transaction to be chained are relatively important or the number of resources is large, it is often necessary to chain them as soon as possible to improve the security of resource interaction. Based on this, the embodiments of the present disclosure provide a solution for transaction packing based on the resource situation associated with each transaction to be chained, which can enable the transactions to be chained with relatively important associated resources or a large number of resources to be preferentially packed and chained, so as to improve the rationality of transaction chaining.
[0272] Please refer to Figure 13 , in another embodiment, the specific process of step 340 includes but is not limited to the following steps 1310-1330:
[0273] Step 1310: For each transaction to be chained in the target transaction storage space, obtain the associated resource information of the transaction to be chained;
[0274] Step 1320: Determine the transaction packaging order based on the associated resource information;
[0275] Step 1330: Based on the transaction packaging order, sequentially take out multiple transactions to be chained from the target transaction storage space and package them into the block to be consensus until the size of the block to be consensus reaches a preset threshold.
[0276] The following is a detailed description of steps 1310-1330.
[0277] In step 1310, for each transaction to be chained in the target transaction storage space, obtain the associated resource information of the transaction to be chained.
[0278] The associated resource information is used to indicate the specific situation of the resources associated with the transaction to be chained.
[0279] In the specific implementation of this embodiment, since each object terminal sends the transaction to be chained to the blockchain network, the blockchain network will record the associated information of the received transaction to be chained, where the associated information includes the terminal address of the object terminal that sends the transaction to be chained, the transaction timestamp of the transaction to be chained, and the associated resource information, etc. Based on this, with authorization, extract the associated resource information of each transaction to be chained from the background log of the blockchain network.
[0280] In step 1320, determine the transaction packaging order based on the associated resource information.
[0281] The transaction packaging order is used to define the order of taking out each transaction to be chained in the target transaction storage space.
[0282] To save space, the specific implementation process of determining the transaction packaging order based on the associated resource information in the embodiments of the present disclosure will be described in detail below and will not be elaborated here.
[0283] In step 1330, based on the transaction packaging order, sequentially take out multiple transactions to be chained from the target transaction storage space and package them into the block to be consensus until the size of the block to be consensus reaches a preset threshold.
[0284] In the specific implementation of this embodiment, the specific implementation process of step 1330 is similar to that of the above-mentioned step 1120. The difference is that in step 1120, multiple transactions to be chained are packaged in the order of the transaction timestamps from early to late, while in step 1330, multiple transactions to be chained are packaged in the determined transaction packaging order, and the transaction packaging orders of the two are different. For the sake of brevity, it will not be elaborated here.
[0285] In the embodiments of the present disclosure, the associated resource information of the transaction to be chained includes the associated resource type and the associated resource quantity.
[0286] The associated resource type is used to indicate the actual type of the resource associated with the transaction to be chained, and the associated resource type includes but is not limited to virtual resources, physical resources, etc.
[0287] The associated resource quantity is used to indicate the number of resources associated with the transaction to be chained.
[0288] Please refer to Figure 14 , in one embodiment, the specific process of determining the transaction packaging order based on the associated resource information includes but is not limited to the following steps 1410-1440:
[0289] Step 1410: For each transaction to be chained, based on the associated resource type, determine the first transaction score of the transaction to be chained;
[0290] Step 1420: For each transaction to be chained, based on the associated resource quantity, determine the second transaction score of the transaction to be chained;
[0291] Step 1430: Based on the first transaction score and the second transaction score, determine the total transaction score of the transaction to be chained;
[0292] Step 1440: Based on the magnitudes of the total transaction scores, sort the multiple transactions to be chained to obtain the transaction packaging order.
[0293] The following will describe steps 1410-1440 in detail.
[0294] In step 1410, for each transaction to be chained, based on the associated resource type, determine the first transaction score of the transaction to be chained.
[0295] The first transaction score is used to indicate the scoring situation of the associated resource type of each transaction to be chained in the transaction packaging order.
[0296] In the specific implementation of this embodiment, first, a preset relationship comparison table is obtained. The preset relationship comparison table is used to indicate multiple candidate resource types and the preset scores corresponding to each candidate resource type, where the preset scores are used to indicate the importance of the resources indicated by each candidate resource type. Then, for each transaction to be chained, a candidate resource type with the same associated resource type is searched for in the preset relationship comparison table. Finally, the preset score corresponding to the candidate resource type with the same associated resource type is determined as the first transaction score of the transaction to be chained.
[0297] In step 1420, for each transaction to be chained, based on the associated resource quantity, the second transaction score of the transaction to be chained is determined.
[0298] The second transaction score is used to indicate the scoring situation of the associated resource quantity of each transaction to be chained in the transaction packaging order.
[0299] In the specific implementation of this embodiment, the specific implementation process of step 1420 is similar to the specific implementation process of the above-mentioned step 1410. For the sake of brevity, it will not be elaborated here.
[0300] In step 1430, based on the first transaction score and the second transaction score, the total transaction score of the transaction to be chained is determined.
[0301] The total transaction score is used to indicate the overall scoring situation of each transaction to be chained in the transaction packaging order.
[0302] In the specific implementation of this embodiment, first, the first transaction weight and the second transaction weight are determined. The first transaction weight is used to indicate the importance of the associated resource type of the transaction to be chained in determining the transaction packaging order, and the second transaction weight is used to indicate the importance of the associated resource quantity of the transaction to be chained in determining the transaction packaging order. The sum of the first transaction weight and the second transaction weight is 1. Then, for each transaction to be chained, the product of the first transaction weight and the first transaction score is added to the product of the second transaction weight and the second transaction score to obtain the total transaction score of the transaction to be chained.
[0303] In step 1440, based on the magnitude of the total transaction score, multiple transactions to be chained are sorted to obtain the transaction packaging order.
[0304] In the specific implementation of this embodiment, based on the magnitude of the total transaction score, multiple transactions to be chained are arranged in descending order of the total transaction score to obtain the transaction packaging order. In the transaction packaging order, the transaction to be chained with a larger total transaction score is ranked in a more forward position, and the transaction to be chained with a smaller total transaction score is ranked in a more backward position.
[0305] Such as Figure 15As shown in the figure, there are 8 transactions to be chained stored in the target transaction storage space corresponding to the target master node, which are Transaction 1 with a total transaction score of 88, Transaction 2 with a total transaction score of 76, Transaction 3 with a total transaction score of 85, Transaction 4 with a total transaction score of 68, Transaction 5 with a total transaction score of 93, Transaction 6 with a total transaction score of 90, Transaction 7 with a total transaction score of 82, and Transaction 8 with a total transaction score of 77. Sort the transactions to be chained according to the total transaction score to obtain the transaction packaging order, and the transaction packaging order is [Transaction 5, Transaction 6, Transaction 1, Transaction 3, Transaction 7, Transaction 8, Transaction 2, Transaction 4]. When the maximum number of transactions to be chained that the block to be consensus can accommodate is 4, according to the transaction packaging order, Transaction 5, Transaction 6, Transaction 1, and Transaction 3 are taken out from the target transaction storage space and packaged into the block to be consensus.
[0306] The advantage of this embodiment is that based on the resource conditions associated with each transaction to be chained, the transaction packaging order of each transaction to be chained is determined, and the transactions to be chained are packaged and chained according to the transaction packaging order, which can make the transactions to be chained with relatively important associated resources or a large number of resources be preferentially packaged and chained, thereby improving the rationality of transaction chaining.
[0307] Please refer to Figure 16 , in some embodiments, after each slave node conducts consensus on the transactions to be chained in the block to be consensus, the blockchain consensus method further includes but is not limited to the following steps 1610-1630:
[0308] Step 1610, obtain a consensus result based on the consensus feedback of each slave node;
[0309] Step 1620, if the consensus result is consensus success, determine the block to be consensus as the target block, and determine the predetermined block height of the block to be consensus as the block height of the target block, so as to perform chaining processing on multiple consecutive target blocks based on multiple block heights;
[0310] Step 1630, if the consensus result is consensus failure, mark the predetermined block height of the block to be consensus, so as to allocate the marked predetermined block height to the block to be consensus generated in the next consensus round.
[0311] The following will describe steps 1610-1630 in detail.
[0312] In step 1610, a consensus result is obtained based on the consensus feedback of each slave node.
[0313] The consensus feedback is used to indicate whether each slave node agrees to chain the block to be consensus.
[0314] The consensus result is used to indicate whether the blockchain network will finally determine whether to put the consensus block on the chain based on multiple consensus feedbacks.
[0315] In the specific implementation of this embodiment, first determine the consensus feedback of each slave node; then, count the slave nodes whose consensus feedback is that they disagree to put the block to be agreed on the chain, and obtain the first node number; count the slave nodes whose consensus feedback is that they agree to put the block to be agreed on the chain, and obtain the second node number. Further, compare the first node number and the second node number. If it is determined that the first node number is greater than or equal to the second node number, it means that there are more slave nodes that oppose putting the block to be agreed on the chain, and if the block to be agreed on the chain, there will be a greater risk. Based on this, the consensus result is determined to be a consensus failure, and multiple transactions to be put on the chain of the block to be agreed on is not allowed to be put on the chain. If it is determined that the first node number is less than or equal to the second node number, it means that there are more slave nodes that agree to put the block to be agreed on the chain, and if the block to be agreed on the chain, there will be a smaller risk. Based on this, the consensus result is determined to be a consensus success, and multiple transactions to be put on the chain in the block to be agreed on the chain are put on the chain.
[0316] In step 1620, if the consensus result is a consensus success, the block to be agreed upon is determined as the target block, and the predetermined block height of the block to be agreed upon is determined as the block height of the target block, so as to perform on-chain processing on multiple consecutive target blocks based on multiple block heights.
[0317] The predetermined block height is used to indicate the location of the block to be agreed upon in the blockchain.
[0318] In the specific implementation of this embodiment, if the consensus result is a consensus success, the target master node will first assemble multiple transactions to be chained of the consensus block and the block information of the chained blocks on the blockchain into a target block, and then obtain the predetermined block height pre-set for the consensus block, and determine the predetermined block height of the consensus block as the block height of the target block. Further, according to the block heights of multiple target blocks generated in this consensus round, multiple target blocks with continuous block heights are chained in sequence according to the size of the block height.
[0319] Furthermore, for each slave node of the target master node, the slave node will also assemble the to-be-uploaded transactions of its own target transaction storage space corresponding to the target master node and the block information of the chained blocks on the blockchain into a target block according to the received blocks to be agreed upon, thereby obtaining multiple target blocks in the current consensus round, and chaining multiple consecutive target blocks based on the block height of each target block.
[0320] In step 1630, if the consensus result is a consensus failure, mark the predetermined block height of the block to be consensus, so as to allocate the marked predetermined block height to the block to be consensus generated in the next consensus round.
[0321] In the specific implementation of this embodiment, if the consensus result is a consensus success, the transactions to be chained in the block to be consensus will not be recorded on the blockchain in the current consensus round, and will still be stored in a transaction storage space of the transaction pool of each consensus node. Further, since the transactions to be chained in the block to be consensus will not be recorded on the blockchain in the current consensus round, the predetermined block height will not be used as the block height of the target block either, and the predetermined block height still has no corresponding relationship with the target block on the blockchain. Therefore, mark the predetermined block height of the block to be consensus, so as to allocate the marked predetermined block height to the block to be consensus generated in the next consensus round.
[0322] The advantage of this embodiment is that, according to the consensus feedback of each slave node, determine the final consensus result, and according to the consensus result, when the consensus is successful, according to whether the block heights of each target block are continuous, uniformly chain multiple target blocks with continuous block heights, and delay the chaining of target blocks with discontinuous block heights, which can make the blocks of the blockchain have a normal order. Further, when the consensus fails, use the unused predetermined block height for subsequent consensus rounds, so that multiple target blocks generated in multiple consensus rounds can be continuous, improving the security and correctness of block chaining.
[0323] Please refer to Figure 17 In a specific embodiment, the consensus process in a consensus round includes but is not limited to the following steps 1710-1730:
[0324] Step 1710: Broadcast the block to be consensus to each slave node, and receive the broadcast messages of each slave node for the block to be consensus;
[0325] Step 1720: Generate a submission message based on the received broadcast messages;
[0326] Step 1730: Determine the consensus result based on the broadcast of the submission message.
[0327] The following will describe steps 1710-1730 in detail.
[0328] In step 1710, after the target master node generates the block to be consensus, the target master node first broadcasts the block to be consensus to each slave node. Further, after each slave node receives the broadcast block to be consensus, each slave node verifies the transactions to be chained of the block to be consensus according to the transactions to be chained in the target transaction storage space corresponding to the target master node that it has, and generates a broadcast message according to the verification result.
[0329] In step 1720, after the target master node receives the broadcast messages broadcast by each slave node, it generates a commit message. The commit message summarizes the voting results of all slave nodes.
[0330] In step 1730, after the target master node aggregates the broadcast messages into a commit message, it sends the commit message to other slave nodes, so that other slave nodes determine whether to modify their own voting results according to the voting situations of the slave nodes other than themselves in the commit message, and perform the next round of voting. After multiple rounds of voting consensus, a consensus result is obtained.
[0331] As Figure 18 shown, it is the block consensus process based on the Byzantine fault tolerance consensus algorithm. The block consensus process includes stages of proposal, pre-prepare, prepare, commit, and reply. In the blockchain network, the master node is node 0. The slave nodes are node 1, node 2, and node 3, where node 3 is a faulty node. First, in the proposal stage, the object terminal C sends a transaction chaining request to node 0. Then, in the pre-prepare stage, node 0 generates a block to be consensus as a proposal according to the transaction chaining request, and broadcasts the proposal to node 1, node 2, and node 3. Further, in the prepare stage, after node 1 and node 2 receive the proposal, they will respectively conduct consensus on the block to be consensus corresponding to the transaction chaining request, vote and broadcast the voting results, so that node 0 receives the voting results broadcast by node 1 and node 2, and node 1 and node 2 receive the voting results broadcast by the other party. Then, in the commit stage, node 0, node 1, and node 2 will each generate a commit message according to the voting results and broadcast the commit message to the other three nodes. Finally, in the reply stage, node 1, node 2, and node 3 will all receive the commit messages from other nodes. Node 1, node 2, and node 3 respectively generate a reply message according to the multiple commit messages received, and send the reply message to the object terminal C.
[0332] As Figure 19As shown, it is a block consensus process based on HotStuff. The block consensus process includes a preparation stage, a prepare-to-commit stage, a commit stage, and a decision stage. In the blockchain network, the primary node is node N1, and the secondary nodes are node N2, node N3, and node N4. First, in the preparation stage, node N2, node N3, and node N4 each send the transactions to be chained received from their respective object terminals as new messages to the primary node N1. The primary node N1 merges and forwards the transactions to be chained to each node, so that node N2 receives the transactions to be chained sent by node N3 and node N4, node N3 receives the transactions to be chained sent by node N4 and node N2, and node N4 receives the transactions to be chained sent by node N2 and node N3. At the same time, the primary node N1 will merge the proposal messages into the forwarded transactions to be chained and send them to each node. In the prepare-to-commit stage, node N2, node N3, and node N4 send the voting results for the proposal to the primary node N1. The primary node N1 merges and sends the voting results prepared for submission by each node (including node N2, node N3, and node N4) to each node (including node N2, node N3, and node N4). After receiving the voting results of other nodes, node N2, node N3, and node N4 submit their latest voting results to the primary node N1. In the commit stage, the primary node N1 generates a commit message based on the final voting results of node N2, node N3, and node N4, and sends the commit message to node N2, node N3, and node N4. Further, in the decision stage, node N2, node N3, and node N4 send the voting results for the commit message to the primary node N1. After merging the votes of all nodes for the commit message, the primary node N1 forms a final decision and sends the final decision to node N2, node N3, and node N4. The above process is a method of aggregated voting based on the primary node. Multiple votes in the consensus process will generate a unified certificate, which is broadcast by the primary node. This can reduce the number of messages in the blockchain network, but will cause excessive node processing pressure on the primary node.
[0333] The advantage of this embodiment is that in one consensus round, each primary node and the secondary nodes corresponding to the primary node complete a consensus process, achieving multiple block consensuses in the same consensus round. The transaction packaging and block consensus of each primary node are independent of each other and do not affect each other, which can better improve the stability and security of parallel consensus of multiple primary nodes in the same consensus round.
[0334] Please refer to Figure 20 , in a specific embodiment, the specific process of step 1620 includes but is not limited to the following steps 2010-2020:
[0335] Step 2010: Based on multiple block heights, determine the chaining order of each target block;
[0336] Step 2020: Based on the chain - up order, perform chain - up processing on multiple consecutive target blocks, and delay the chain - up of discontinuous target blocks.
[0337] The following describes steps 2010 - 2020 in detail.
[0338] In step 2010, based on multiple block heights, determine the chain - up order of each target block.
[0339] The chain - up order is used to define the order of chain - up of multiple target blocks generated in a consensus round.
[0340] In the specific implementation of this embodiment, for the block heights of each target block, according to the size of the block heights, arrange multiple target blocks to obtain the chain - up order. In the chain - up order, the target block with a smaller block height is arranged in the front, and the target block with a larger block height is arranged in the back, so that the target block with a smaller block height is chain - up first, and the target block with a larger block height is chain - up later.
[0341] In step 2020, based on the chain - up order, perform chain - up processing on multiple consecutive target blocks, and delay the chain - up of discontinuous target blocks.
[0342] In the specific implementation of this embodiment, first, according to the chain - up order and the block heights of each target block, determine multiple target blocks with consecutive block heights, and determine target blocks with discontinuous block heights. Then, record multiple target blocks with consecutive block heights onto the blockchain in sequence, and delay the chain - up of target blocks with discontinuous block heights. Wait until in the next consensus round or subsequent consensus rounds, when the block height of the target block is continuous with the block heights of other target blocks, then chain - up multiple target blocks together.
[0343] In the embodiment of the present disclosure, the discontinuous target blocks include at least one first target block, where the first target block is a target block whose block height cannot form a continuous value with the block heights of other target blocks in the current consensus round.
[0344] In some embodiments, the specific process of delaying the chain - up of discontinuous target blocks includes the following steps:
[0345] Among the multiple target blocks generated in multiple consensus rounds after the current consensus round, determine the second target blocks whose block heights are less than that of the first target block;
[0346] Based on the block height, chain - up the consecutive second target blocks and the first target block together.
[0347] In the specific implementation of this embodiment, first, in the next consensus round, the marked predetermined block height is assigned to a to-be-consensus block generated in the next consensus round. When the to-be-consensus block is successfully consensus, the marked predetermined block height is used as the block height of the target block corresponding to the to-be-consensus block, and the target block with the block height of the marked predetermined block height is used as the second target block. Further, according to the block height, the first target block and the second target block are chained together. If, in the next consensus round, the to-be-consensus block assigned with the marked predetermined block height fails to be successfully consensus, then according to the process of step 2020, the marked predetermined block height is assigned to a to-be-consensus block in the next next consensus round, and the foregoing process is executed until the to-be-consensus block assigned with the marked predetermined block height is successfully consensus.
[0348] For example, for a certain consensus round, the target blocks include target block A with a block height of 4, target block B with a block height of 5, target block C with a block height of 6, target block D with a block height of 8, and target block E with a block height of 9. Among them, the block heights of target block A, target block B, and target block C are consecutive, and the block heights of target block D and target block E are consecutive. However, target block C and target block D are not consecutive, and there is a gap between target block C and target block D. According to the normal sorting, there should be a block with a block height of 7 between target block C and target block D. However, because a certain primary node is a Byzantine node or a non-goodwill node, the target block with a block height of 7 fails to be generated. Therefore, target block E and target block D are the first target blocks. At this time, first chain target block A, target block B, and target block C, and delay target block D and target block E until after a block with a block height of 7 (the second target block) is generated in a subsequent consensus round, and then chain target block D, target block E, and the newly generated block with a block height of 7 (the second target block) together.
[0349] The advantage of this embodiment is that according to the chaining order and the block heights of each target block, multiple target blocks with related block heights are sequentially recorded on the blockchain, and the target blocks with discontinuous block heights are chained later, which can avoid the chaos of the block heights of multiple target blocks recorded on the blockchain and enable the normal sorting of each block on the blockchain.
[0350] Please refer to Figure 21 , in an embodiment, the specific process of determining the predetermined block height includes but is not limited to the following steps 2110-2120:
[0351] Step 2110, obtain the block chaining log of the blockchain network;
[0352] Step 2120: Screen out a target segment number from multiple unallocated candidate segment numbers, and determine the target segment number as the predetermined block height.
[0353] The following will describe steps 2110 - 2120 in detail.
[0354] In step 2110, obtain the block chain - on - chain log of the blockchain network.
[0355] The block chain - on - chain log is used to record a serial number segment with a certain length, and the corresponding relationship between a certain segment of the serial number segment and each block on the blockchain.
[0356] In the embodiment of the present disclosure, the block chain - on - chain log includes multiple candidate segment numbers, and the corresponding relationship between each allocated candidate segment number and each block on the blockchain.
[0357] The candidate segment number is used to identify a certain segment in the serial number segment, and the candidate segment number can be used to indicate the block height of the block. Each allocated candidate segment number corresponds to a block on the blockchain and is used to indicate the block height of the corresponding block.
[0358] In the specific implementation of this embodiment, the block chain - on - chain log of the blockchain network is generally stored in the background server of the blockchain network. Based on this, with authorization, obtain the block chain - on - chain log of the blockchain network from the background server of the blockchain network.
[0359] In step 2120, screen out a target segment number from multiple unallocated candidate segment numbers, and determine the target segment number as the predetermined block height.
[0360] The target segment number is the candidate segment number corresponding to the block to be consensus - formed generated by the target primary node.
[0361] In the specific implementation of this embodiment, first, among multiple unallocated candidate segment numbers, determine the candidate segment numbers with marks. Further, when there are candidate segment numbers with marks among multiple unallocated candidate segment numbers, randomly select one of the candidate segment numbers with marks as the target segment number; when there are no candidate segment numbers with marks among multiple unallocated candidate segment numbers, randomly select one from the second number of candidate segment numbers sorted continuously after the last allocated candidate segment number according to the second number of the primary node as the target segment number. Finally, determine the target segment number as the predetermined block height.
[0362] Such as Figure 22As shown, the blockchain on-chain log has multiple candidate serial number segments, and each candidate serial number segment can be expressed as logindex k, where k is the serial number of the candidate serial number segment, and k is an integer greater than 0. In the current consensus round, the blockchain network includes 4 nodes, namely node 1, node 2, node 3, and node 4 in sequence, and these 4 nodes are all primary nodes. Among them, the candidate serial number segment (block height) of the target block corresponding to node 2 is log index100; the candidate serial number segment (block height) of the target block corresponding to node 2 is log index100; the candidate serial number segment (block height) of the target block corresponding to node 4 is logindex101; the candidate serial number segment (block height) of the target block corresponding to node 1 is log index103. Node 3 is a Byzantine node, so the candidate serial number segment (predetermined block height) assigned in advance to the block to be consensus corresponding to node 3 is not used, and the candidate serial number segment (predetermined block height) log index102 is marked as nil, and the candidate serial number segment (predetermined block height) log index102 will be assigned to the newly generated block to be consensus in the next consensus round. In addition, in the current consensus round, block 103 with the candidate serial number segment (block height) of log index103 is not consecutive with the other two blocks, so first chain block 100 and block 101, delay block 103 to the next consensus round, and after the target block with the block height of log index102 is generated, chain the target block with the block height of log index102 and block 103 together, so that the blocks on the blockchain can be sorted normally.
[0363] Furthermore, in the next consensus round, there is a marked candidate serial number log index10 among the multiple unallocated candidate segment serial numbers. Therefore, the candidate segment serial number log index10 is used as the target segment serial number of the target primary node. However, when there is no marked candidate serial number among the multiple unallocated candidate segment serial numbers, any one of the 4 candidate serial numbers (log index104, log index1035, log index106, logindex107) after the candidate serial number segment logindex103 is used as the target segment serial number of the target primary node.
[0364] The advantage of this embodiment is that the candidate serial number segments corresponding to each block in the blockchain network are recorded in the blockchain log of the block, so that the earlier segments of the serial number segments corresponding to the earlier-blocked blocks are in the front, and there is a clear chain correspondence between each segment of the serial number segment and the block on the blockchain. According to the chain correspondence, in each consensus round, the corresponding candidate serial number segments (predetermined block heights) are assigned to each block to be consensus, improving the accuracy and rationality of determining the predetermined block height, and effectively avoiding assigning the same predetermined block height to multiple blocks to be consensus. In addition, it is also possible to determine whether each target block is continuous according to the sorting order of each candidate serial number segment in the blockchain log, thereby improving the orderliness of blockchain logging.
[0365] Detailed Description of Transactions to be Uploaded to the Chain for Updating Each Transaction Storage Space in an Embodiment of the Present Disclosure
[0366] In actual blockchain logging, in each consensus round, in order to improve the efficiency of transaction logging, the transaction storage space where the transactions to be logged are stored is fixed; however, if a certain master node is a Byzantine node or a dishonest node, it often causes multiple transactions to be logged that are stored in the transaction storage space corresponding to the master node to fail to be normally packaged and logged, resulting in situations such as transactions being logged late or not logged, which is not conducive to the normal processing of transactions. Based on this, the embodiments of the present disclosure provide a solution for re-storing the transactions to be logged that were not packaged and logged in the previous round in different consensus rounds, so that the transactions to be logged that were not packaged and logged in the previous consensus round can be stored in different transaction storage spaces, improving the flexibility of transaction storage.
[0367] Please refer to Figure 23 , in one embodiment, the specific process of updating the transactions to be logged in each transaction storage space includes but is not limited to the following steps 2310-2340:
[0368] Step 2310, determine the transactions to be logged in each transaction storage space;
[0369] Step 2320, update the current consensus round of the blockchain network to obtain the updated consensus round;
[0370] Step 2330, for each transaction to be logged, perform a remainder operation on the sum of the round number of the updated consensus round and the transaction digest value of the transaction to be logged and the second number of the transaction storage space to obtain the remainder;
[0371] Step 2340, based on the remainder, re-store the transaction to be logged into the transaction storage space with the same storage space index as the remainder to update each transaction storage space.
[0372] The following is a detailed description of steps 2310-2340.
[0373] In step 2310, unchained transactions in each transaction storage space are determined.
[0374] The unchained transactions refer to the remaining transactions to be chained in each transaction storage space after generating multiple target blocks in the current consensus round.
[0375] In the specific implementation of this embodiment, after generating multiple target blocks in the current consensus round, the target master node performs transaction statistics on multiple transaction storage spaces maintained by itself, so as to determine the unchained transactions in each transaction storage space.
[0376] In step 2320, the current consensus round of the blockchain network is updated to obtain the updated consensus round.
[0377] The updated consensus round refers to the next consensus round after the current consensus round.
[0378] In the specific implementation of this embodiment, when updating the current consensus round of the blockchain network, first determine the round number of the current consensus round; then, add 1 to the round number of the current consensus round to obtain the round number of the updated consensus round, and after multiple consecutive target blocks of the current consensus round are chained, execute the updated consensus round to perform a new round of blockchain consensus.
[0379] In step 2330, for each unchained transaction, perform a remainder operation on the sum of the round number of the updated consensus round and the transaction digest value of the unchained transaction, and the second number of the transaction storage space, to obtain the remainder.
[0380] In the specific implementation of this embodiment, the specific implementation process of step 2330 is similar to the specific implementation process of the above steps 720-730. The difference is that the round numbers for summing with the transaction digest value are different for the two, and for the sake of brevity, it will not be elaborated.
[0381] In step 2340, based on the remainder, the unchained transactions are re-stored in the transaction storage space with the same storage space index as the remainder to update each transaction storage space.
[0382] In the specific implementation of this embodiment, the specific implementation process of step 2340 is similar to the specific implementation process of the above step 740. For the sake of brevity, it will not be elaborated.
[0383] Such as Figure 24AAs shown, in the current consensus round, the 4 consensus nodes (Node 1, Node 2, Node 3, and Node 4) in the blockchain network all contain 4 transaction storage spaces, and all 4 consensus nodes are primary nodes. Among them, when the primary node is Node 1, Node 2, Node 3, and Node 4 are all secondary nodes. When the primary node is Node 2, Node 1, Node 3, and Node 4 are all secondary nodes. When the primary node is Node 3, Node 2, Node 1, and Node 4 are all secondary nodes. When the primary node is Node 4, Node 2, Node 3, and Node 1 are all secondary nodes. Specifically, in each consensus round, the target transaction storage space corresponding to Node 1 is Transaction Storage Space 1, the target transaction storage space corresponding to Node 2 is Transaction Storage Space 2, the target transaction storage space corresponding to Node 3 is Transaction Storage Space 3, and the target transaction storage space corresponding to Node 4 is Transaction Storage Space 4.
[0384] As Figure 24B shown, the transactions to be chained in Transaction Storage Space 1 corresponding to primary node 1 include Transaction 1, Transaction 5, Transaction 9, and Transaction 13; the transactions to be chained in Transaction Storage Space 2 corresponding to primary node 2 include Transaction 2, Transaction 6, Transaction 10, and Transaction 14; the transactions to be chained in Transaction Storage Space 3 corresponding to primary node 3 include Transaction 3, Transaction 7, Transaction 11, and Transaction 15; the transactions to be chained in Transaction Storage Space 4 corresponding to primary node 4 include Transaction 4, Transaction 8, Transaction 12, and Transaction 16. Further, in the current consensus round, primary node 1 packs Transaction 1, Transaction 13, and Transaction 9 into block 103; primary node 2 packs Transaction 2 and Transaction 6 into block 100; primary node 4 packs Transaction 4, Transaction 8, Transaction 16, and Transaction 12 into block 101, and primary node 3 is a Byzantine node and does not pack any transactions. Based on this, in the current consensus round, the remaining unchained transactions in Transaction Storage Space 1 are Transaction 5; the remaining unchained transactions in Transaction Storage Space 2 are Transaction 10 and Transaction 14; the remaining unchained transactions in Transaction Storage Space 3 are Transaction 3, Transaction 7, Transaction 11, and Transaction 15; and there are no remaining transactions to be chained in Transaction Storage Space 4.
[0385] As Figure 24C shown, in the next consensus round, Transaction 3, Transaction 11, and Transaction 14 are re-stored in Transaction Storage Space 1; Transaction 5 and Transaction 15 are re-stored in Transaction Storage Space 12; Transaction 10 is re-stored in Transaction Storage Space 1; and Transaction 7 is re-stored in Transaction Storage Space 1.
[0386] The advantage of this embodiment is that the new storage location of the unchained transaction is determined based on the transaction summary value and the consensus round of the transaction to be chained, so that the same transaction to be chained has a probability of being stored in different transaction storage spaces in different consensus rounds. This can enable the same transaction to be chained to be packaged into a block and chained by different primary nodes in different consensus rounds, improving the flexibility and rationality of transaction storage and reducing the risk that transactions cannot be normally chained due to an abnormality of a certain node.
[0387] Detailed Description of Determining Multiple Primary Nodes among Multiple Consensus Nodes in an Embodiment of the Present Disclosure
[0388] In a blockchain network, the transaction processing capabilities and reputation status of each consensus node are different. When selecting a consensus node with poor transaction processing capabilities, it will also affect the block packaging and block consensus efficiency of the entire blockchain network, resulting in a still poor throughput speed of the blockchain network. Based on this, the embodiments of the present disclosure provide a solution for jointly screening primary nodes based on the node reputation and node processing capabilities of each consensus node, which can improve the accuracy of primary node screening.
[0389] Please refer to Figure 25 In one embodiment, the specific process of determining the second number of primary nodes among the first number of consensus nodes includes but is not limited to the following steps 2510-2520:
[0390] Step 2510: Determine the node reputation and node processing capabilities of each consensus node;
[0391] Step 2520: Based on the node reputation and node processing capabilities, determine the second number of primary nodes among the first number of consensus nodes.
[0392] The following details steps 2510-2520.
[0393] In step 2510, the node reputation and node processing capabilities of each consensus node are determined.
[0394] The node reputation is used to indicate the integrity of the node in consensus and broadcasting.
[0395] The node processing capability is used to indicate the block generation delay of the consensus node.
[0396] In the specific implementation of this embodiment, since the block generation, consensus, and broadcasting situations of each consensus node in the past multiple consensus rounds are recorded in the server background by the blockchain network. Based on this, with authorized permission, first extract the block generation, consensus, and broadcasting log contents of each consensus node in the past multiple consensus rounds from the server background, and then, according to the multiple log contents, determine the node reputation and node processing capabilities of each consensus node.
[0397] In step 2520, based on the node credibility and the node processing capacity, determine the second number of primary nodes from among the first number of consensus nodes.
[0398] Please refer to Figure 26 , in one embodiment, the process of determining the primary nodes based on the node credibility and the node processing capacity includes but is not limited to the following steps 2610-2640:
[0399] Step 2610: For each consensus node, determine a first score based on the node credibility.
[0400] Step 2620: For each consensus node, determine a second score based on the node processing capacity.
[0401] Step 2630: Based on the first score and the second score, determine the total score of the consensus node.
[0402] Step 2640: Determine the consensus nodes with the top second number of total scores as the primary nodes.
[0403] The following is a detailed description of steps 2610-2640.
[0404] In step 2610, first, for each consensus node, substitute the node credibility into a preset function, and use the output result of the preset function as the first score. Among them, the preset function is an increasing function with the node credibility as the independent variable and the first score as the dependent variable.
[0405] The specific implementation process of step 2620 is similar to the specific implementation process of the above step 2610. To save space, it will not be elaborated.
[0406] The specific implementation process of step 2630 is similar to the specific implementation process of the above step 1430. To save space, it will not be elaborated.
[0407] In step 2640, first, sort the consensus nodes in descending order according to the total scores of each consensus node to obtain a sorting. In the sorting, the consensus node with a larger total score is ranked in a more forward position. Then, in the sorting, determine the consensus nodes with the top second number as the primary nodes.
[0408] The advantage of this embodiment is that by jointly screening the primary nodes based on the node credibility and the node processing capacity of each consensus node, and introducing the methods of node scoring and score weighting for node screening, the accuracy of primary node screening can be improved. Furthermore, consensus nodes with better node processing capacity and better node credibility can be screened out as the primary nodes, improving the efficiency of block packaging and block consensus in the entire blockchain network, and thus improving the throughput speed of the blockchain network.
[0409] Please refer to Figure 27 , in one embodiment, the process of determining the second number includes but is not limited to the following steps 2710-2720:
[0410] Step 2710, obtain the total number of nodes in the blockchain network and network operation information;
[0411] Step 2720, based on the total number of nodes and network operation information, determine the second number.
[0412] The following is a detailed description of steps 2710-2720.
[0413] In step 2710, obtain the total number of nodes in the blockchain network and network operation information.
[0414] The total number of nodes is used to indicate the total number of consensus nodes in the blockchain network.
[0415] The network operation information is used to indicate the network operation status of the blockchain network. The network operation information includes network latency, throughput rate, and so on.
[0416] In the specific implementation of this embodiment, the specific implementation process of step 2710 is similar to the specific implementation process of the above step 2510. For the sake of brevity, it will not be elaborated here.
[0417] In step 2720, based on the total number of nodes and network operation information, determine the second number.
[0418] In the specific implementation of this embodiment, the process of determining the second number may include the following steps:
[0419] Based on the total number of nodes, determine the third fraction;
[0420] Based on the network operation information, determine the fourth fraction;
[0421] Based on the third fraction and the fourth fraction, determine the second number.
[0422] In the specific implementation of this embodiment, the methods of determining the third fraction and the fourth fraction are similar to the specific implementation process of the above step 2610. For the sake of brevity, it will not be elaborated here.
[0423] When determining the second number based on the third fraction and the fourth fraction, first, perform a weighted sum calculation on the third fraction and the fourth fraction according to a preset weight ratio to obtain a comprehensive score. Then, according to the correspondence between the preset proportion of the primary nodes among all consensus nodes and the comprehensive score, determine the proportion value corresponding to this comprehensive score. Finally, multiply the proportion value by the total number of nodes to obtain the second number.
[0424] Such as Figure 28AAs shown, it is the comparison relationship between the proportion of the primary node among all consensus nodes and the comprehensive score determined based on the third score and the fourth score. Among them, when the comprehensive score is 0 - 20, the proportion of the primary node among all consensus nodes is 20%; when the comprehensive score is 21 - 40, the proportion of the primary node among all consensus nodes is 40%; when the comprehensive score is 41 - 60, the proportion of the primary node among all consensus nodes is 60%; when the comprehensive score is 61 - 80, the proportion of the primary node among all consensus nodes is 80%; when the comprehensive score is 81 - 100, the proportion of the primary node among all consensus nodes is 100%.
[0425] As Figure 28B shown, when the total number of nodes is 10 and the comprehensive score is 55, the second number is 60% × 10 = 6. Among the 10 consensus nodes, select the 6 consensus nodes with the highest total scores as the primary nodes. Based on this, the primary nodes are node 8 with a total score of 93, node 5 with a total score of 90, node 1 with a total score of 88, node 10 with a total score of 85, node 4 with a total score of 84, and node 2 with a total score of 76.
[0426] The advantage of this embodiment is that when the total number of nodes in the blockchain network is large and the network operation state is good, setting a larger number of primary nodes enables more target blocks to be generated and chained in the same consensus round, thereby improving the overall transaction chaining efficiency of the blockchain network.
[0427] Device and Equipment Description of Embodiments of the Present Disclosure
[0428] It can be understood that although the steps in each of the above flowcharts are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this embodiment, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above flowcharts may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0429] It should be noted that in each specific embodiment of the present application, when it comes to performing relevant processing based on data related to the characteristics of the target object, such as target object attribute information or a set of attribute information, the permission or consent of the target object will be obtained first. Moreover, the collection, use, and processing of such data will comply with relevant laws, regulations, and standards. In addition, when the embodiments of the present application need to obtain the target object attribute information, the separate permission or separate consent of the target object will be obtained through methods such as popping up a window or jumping to a confirmation page. After clearly obtaining the separate permission or separate consent of the target object, the necessary target object-related data for the normal operation of the embodiments of the present application will be obtained.
[0430] Figure 29 FIG. 2900 is a schematic structural diagram of a blockchain consensus device 2900 provided by an embodiment of the present disclosure. The blockchain consensus device 2900 has multiple consensus rounds and is applied to a target primary node among the second number of primary nodes in the first number of consensus nodes in each consensus round. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has a second number of transaction storage spaces respectively corresponding to the second number of primary nodes. The blockchain consensus device 2900 includes:
[0431] An acquisition unit 2910, configured to acquire a transaction to be chained;
[0432] A mapping unit 2920, configured to map the transaction to be chained to a transaction storage space based on the mapping rule of the transaction to be chained in the second number of transaction storage spaces;
[0433] A determination unit 2930, configured to determine a target transaction storage space corresponding to the target primary node in the second number of transaction storage spaces;
[0434] A packaging unit 2940, configured to package the transaction to be chained stored in the target transaction storage space into a block to be consensus, and send the block to be consensus to a slave node, so that the slave node performs consensus on the transaction to be chained in the block to be consensus based on the target transaction storage space corresponding to the target primary node in the slave node, where the slave node is a consensus node other than the target primary node.
[0435] Optionally, the blockchain consensus device 2900 further includes a chaining unit (not shown). The chaining unit (not shown) is specifically configured to:
[0436] Obtain a consensus result based on the consensus feedback of each slave node;
[0437] If the consensus result is successful consensus, determine the block to be consensus as a target block, and determine the predetermined block height of the block to be consensus as the block height of the target block, so as to perform chaining processing on multiple consecutive target blocks based on multiple block heights;
[0438] If the consensus result is a consensus failure, mark the scheduled block height of the block to be consensus, so as to allocate the marked scheduled block height to the block to be consensus generated in the next consensus round.
[0439] Optionally, perform on-chain processing on multiple consecutive target blocks based on multiple block heights, including:
[0440] Determine the on-chain order of each target block based on multiple block heights;
[0441] Based on the on-chain order, perform on-chain processing on multiple consecutive target blocks, and delay the on-chain processing of discontinuous target blocks.
[0442] Optionally, the discontinuous target blocks include at least one first target block;
[0443] Delaying the on-chain processing of discontinuous target blocks includes:
[0444] Among multiple target blocks generated in multiple consensus rounds after the current consensus round, determine second target blocks with block heights less than the first target block;
[0445] Based on the block heights, perform on-chain processing on consecutive second target blocks and the first target block together.
[0446] Optionally, the scheduled block height is determined by the following method:
[0447] Obtain the on-chain log of the blockchain network, where the on-chain log of the block includes multiple candidate segment numbers, and the corresponding relationship between each allocated candidate segment number and each block on the blockchain;
[0448] Screen out the target segment number from multiple unallocated candidate segment numbers, and determine the target segment number as the scheduled block height.
[0449] Optionally, the second number of transaction storage spaces is determined by the following method:
[0450] Determine the number of nodes of the primary node in the current consensus round;
[0451] Based on the number of nodes, equally divide the transaction pool of the consensus nodes in terms of space to obtain the second number of transaction storage spaces.
[0452] Optionally, each transaction storage space has a storage space index; each transaction to be on-chain has a transaction digest value;
[0453] The mapping unit 2920 is specifically configured to:
[0454] Determine the round number of the current consensus round of the blockchain network;
[0455] Sum the round number of the current consensus round and the transaction digest value to obtain a sum result;
[0456] Perform a modulo operation based on the sum result and the second number to obtain a modulo result;
[0457] Store the transaction to be chained into the transaction storage space with the same storage space index as the modulo result.
[0458] Optionally, each transaction to be chained has a transaction digest value;
[0459] The mapping unit 2920 is specifically configured to:
[0460] For each transaction storage space, determine the digest interval of the transaction storage space;
[0461] Based on the transaction digest value, determine the digest interval where the transaction digest value is located as the target digest interval;
[0462] Store the transaction to be chained into the transaction storage space with the target digest interval as the digest interval.
[0463] Optionally, the packing unit 2940 is specifically configured to:
[0464] For each transaction to be chained in the target transaction storage space, obtain the transaction timestamp of the transaction to be chained;
[0465] Based on the order of the transaction timestamps from earliest to latest, sequentially take out multiple transactions to be chained from the target transaction storage space and pack them into the block to be consensus until the size of the block to be consensus reaches a preset threshold.
[0466] Optionally, the packing unit 2940 is specifically configured to:
[0467] For each transaction to be chained in the target transaction storage space, obtain the associated resource information of the transaction to be chained;
[0468] Determine the transaction packing order based on the associated resource information;
[0469] Based on the transaction packing order, sequentially take out multiple transactions to be chained from the target transaction storage space and pack them into the block to be consensus until the size of the block to be consensus reaches a preset threshold.
[0470] Optionally, the associated resource information includes the associated resource type and the associated resource quantity;
[0471] Determining the transaction packing order based on the associated resource information includes:
[0472] For each transaction to be chained, based on the associated resource type, determine the first transaction score of the transaction to be chained;
[0473] For each transaction to be chained, based on the associated resource quantity, determine the second transaction score of the transaction to be chained;
[0474] Based on the first transaction score and the second transaction score, determine the total transaction score of the transaction to be chained;
[0475] Based on the magnitude of the total transaction score, sort multiple transactions to be chained to obtain the transaction packaging order.
[0476] Optionally, the determination unit 2930 is specifically configured to:
[0477] Determine the node number of each master node and the storage space number of each transaction storage space;
[0478] Based on the node number and the storage space number, determine the target transaction storage space corresponding to the target master node.
[0479] Optionally, the blockchain consensus device 2900 further includes an update unit (not shown), and the update unit (not shown) is used to update the target transaction storage space corresponding to the target master node;
[0480] The update unit (not shown) is specifically configured to:
[0481] Determine the node processing speed of each master node and the number of transactions of the current transactions to be chained in each transaction storage space;
[0482] Based on the node processing speed and the number of transactions, re-determine the target transaction storage space corresponding to the target master node.
[0483] Optionally, each transaction storage space has a storage space index;
[0484] The blockchain consensus device 2900 further includes a storage unit (not shown), and the storage unit (not shown) is specifically configured to:
[0485] Determine the unchained transactions in each transaction storage space;
[0486] Update the current consensus round of the blockchain network to obtain the updated consensus round;
[0487] For each unchained transaction, perform a remainder operation on the sum of the round number of the updated consensus round and the transaction digest value of the unchained transaction and the second number of the transaction storage space to obtain a remainder;
[0488] Based on the remainder, re-store the unchained transaction to the transaction storage space with the same storage space index as the remainder to update each transaction storage space.
[0489] Optionally, the second number of master nodes is determined by the following method:
[0490] Determine the node credibility and node processing capabilities of each consensus node;
[0491] Based on the node credibility and node processing capabilities, determine a second number of primary nodes among the first number of consensus nodes.
[0492] Optionally, determining a second number of primary nodes among the first number of consensus nodes based on the node credibility and node processing capabilities includes:
[0493] For each consensus node, determine a first score based on the node credibility;
[0494] For each consensus node, determine a second score based on the node processing capabilities;
[0495] Based on the first score and the second score, determine the total score of the consensus node;
[0496] Determine the consensus nodes with the top second number of total scores as the primary nodes.
[0497] Optionally, the second number is determined by the following method:
[0498] Obtain the total number of nodes in the blockchain network and the network operation information;
[0499] Based on the total number of nodes and the network operation information, determine the second number.
[0500] Optionally, determining the second number based on the total number of nodes and the network operation information includes:
[0501] Based on the total number of nodes, determine a third score;
[0502] Based on the network operation information, determine a fourth score;
[0503] Based on the third score and the fourth score, determine the second number.
[0504] Refer to Figure 30 , Figure 30 is a structural block diagram of a part of a terminal for implementing the blockchain consensus method of the embodiments of the present disclosure. The terminal includes components such as a Radio Frequency (RF) circuit 3010, a memory 3015, an input unit 3030, a display unit 3040, a sensor 3050, an audio circuit 3060, a wireless fidelity (WiFi) module 3070, a processor 3080, and a power supply 3090. Those skilled in the art can understand that Figure 30 The shown terminal structure does not limit the mobile phone or computer, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0505] The RF circuit 3010 can be used for receiving and transmitting information or signals during communication. Specifically, after receiving the downlink information from the base station, it is processed by the processor 3080. Additionally, it transmits the uplink data to the base station.
[0506] The memory 3015 can be used to store software programs and modules. The processor 3080 executes various functional applications and data processing of the target terminal by running the software programs and modules stored in the memory 3015.
[0507] The input unit 3030 can be used to receive input numerical or character information, and generate key signal inputs related to the settings and function controls of the target terminal. Specifically, the input unit 3030 can include a touch panel 2531 and other input devices 3032.
[0508] The display unit 3040 can be used to display input information or provided information, as well as various menus of the target terminal. The display unit 3040 can include a display panel 3041.
[0509] The audio circuit 3060, speaker 3061, and microphone 3062 can provide an audio interface.
[0510] In this embodiment, the processor 3080 included in the terminal can execute the blockchain consensus method of the previous embodiment.
[0511] The terminals of the embodiments of the present disclosure include, but are not limited to, mobile phones, computers, intelligent voice interaction devices, intelligent home appliances, vehicle-mounted terminals, aircraft, etc. The embodiments of the present invention can be applied to various scenarios, including but not limited to data security, blockchain, data storage, information technology, etc.
[0512] Figure 31 It is a block diagram of a part of a server for implementing the blockchain consensus method of the embodiments of the present disclosure. The server may vary significantly due to configuration or performance differences, and may include one or more central processing units (CPUs) 3122 (for example, one or more processors) and a memory 3132, and one or more storage media 3130 (for example, one or more mass storage devices) for storing application programs 3142 or data 3144. Among them, the memory 3132 and the storage media 3130 can be transient storage or persistent storage. The programs stored in the storage media 3130 can include one or more modules (not shown in the figure), and each module can include a series of instruction operations on the server. Further, the central processor 3122 can be configured to communicate with the storage media 3130 and execute a series of instruction operations in the storage media 3130 on the server.
[0513] The server may also include one or more power supplies 3126, one or more wired or wireless network interfaces 3150, one or more input / output interfaces 3158, and / or one or more operating systems 3141, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0514] The central processing unit 3122 in the server can be used to execute the blockchain consensus method of the embodiments of the present disclosure.
[0515] The embodiments of the present disclosure also provide a computer-readable storage medium for storing program codes for executing the blockchain consensus method of the foregoing various embodiments.
[0516] The embodiments of the present disclosure also provide a computer program product including a computer program. The processor of the computer device reads and executes the computer program, so that the computer device executes to implement the above-mentioned blockchain consensus method.
[0517] Terms such as "first", "second", "third", "fourth", etc. (if any) in the specification of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "comprise" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily limit to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these process, method, product or device.
[0518] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects and indicates that three relationships may exist. For example, "A and / or B" may mean: only A exists, only B exists, and both A and B exist at the same time. Among them, A and B can be singular or plural. The character " / " generally means that the associated objects before and after are in an "or" relationship. "At least one (one) of the following" or similar expressions refer to any combination of these items, including any combination of single item (one) or plural items (ones). For example, at least one (one) of a, b or c may mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0519] It should be understood that in the description of the embodiments of the present disclosure, the meaning of "a plurality of (or multiple)" is more than two. Understandings such as "greater than", "less than", "exceeding", etc. do not include the corresponding number, and understandings such as "above", "below", "within", etc. include the corresponding number.
[0520] In several embodiments provided by the present disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The displayed or discussed couplings, direct couplings, or communication connections to each other can be indirect couplings or communication connections through some interfaces, devices, or units, and can be in electrical, mechanical, or other forms.
[0521] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the function of the module or unit.
[0522] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they can be located in one place, or can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0523] In addition, the functional units in the various embodiments of the present disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0524] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks, or optical discs.
[0525] It should also be understood that the various embodiments provided by the present disclosure can be combined arbitrarily to achieve different technical effects.
[0526] The above is a specific description of the embodiments of the present disclosure. However, the present disclosure is not limited to the above embodiments. Those skilled in the art can also make various equivalent deformations or substitutions without departing from the spirit of the present disclosure, and these equivalent deformations or substitutions are all included within the scope defined by the claims of the present disclosure.
Claims
1. A blockchain consensus method, characterized in that, The blockchain consensus method has multiple consensus rounds and is applied to a target primary node among the second number of primary nodes in the first number of consensus nodes in each consensus round. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has a second number of transaction storage spaces respectively corresponding to the second number of primary nodes. The blockchain consensus method includes: Obtain the transaction to be chained; Based on the mapping rule of the transaction to be chained in the second number of transaction storage spaces, map the transaction to be chained to one of the transaction storage spaces; Determine the target transaction storage space corresponding to the target primary node in the second number of transaction storage spaces; Package the transaction to be chained stored in the target transaction storage space into a block to be consensus, and send the block to be consensus to the slave nodes, so that the slave nodes perform consensus on the transaction to be chained in the block to be consensus based on the target transaction storage space corresponding to the target primary node in the slave nodes, where the slave nodes are the consensus nodes other than the target primary node.
2. The method according to claim 1, wherein After performing consensus on the transaction to be chained in the block to be consensus, the blockchain consensus method further includes: Obtain the consensus result based on the consensus feedback of each slave node; If the consensus result is successful consensus, determine the block to be consensus as the target block, and determine the predetermined block height of the block to be consensus as the block height of the target block, so as to perform chaining processing on multiple consecutive target blocks based on the multiple block heights; If the consensus result is failed consensus, mark the predetermined block height of the block to be consensus, so as to allocate the marked predetermined block height to the block to be consensus generated in the next consensus round.
3. The method according to claim 2, wherein The performing chaining processing on multiple consecutive target blocks based on the multiple block heights includes: Determine the chaining order of each target block based on the multiple block heights; Based on the chaining order, perform chaining processing on multiple consecutive target blocks, and delay the chaining of the discontinuous target blocks.
4. The method according to claim 2, wherein The predetermined block height is determined by the following method: Obtain the block chaining log of the blockchain network, where the block chaining log includes multiple candidate segment numbers and the corresponding relationship between each allocated candidate segment number and each block on the blockchain; Screen out the target segment number from multiple unallocated candidate segment numbers, and determine the target segment number as the predetermined block height.
5. The method according to claim 1, wherein The second number of transaction storage spaces is determined by the following method: Determine the number of nodes of the primary nodes in the current consensus round; Based on the number of nodes, equally divide the transaction pool of the consensus nodes in space to obtain the second number of transaction storage spaces.
6. The method according to claim 5, characterized in that, Each transaction storage space has a storage space index, and each transaction to be chained has a transaction digest value; Mapping the to-be-chained transaction to one of the transaction storage spaces based on the mapping rule of the to-be-chained transaction in the second number of the transaction storage spaces, includes: Determining the round number of the current consensus round of the blockchain network; Adding the round number of the current consensus round and the transaction digest value to obtain a sum result; Performing a modulo operation on the sum result and the second number to obtain a modulo result; Storing the to-be-chained transaction in the transaction storage space whose storage space index is the same as the modulo result.
7. The method according to claim 1, wherein Each to-be-chained transaction has a transaction digest value; Mapping the to-be-chained transaction to one of the transaction storage spaces based on the mapping rule of the to-be-chained transaction in the second number of the transaction storage spaces, includes: For each of the transaction storage spaces, determining the digest interval of the transaction storage space; Based on the transaction digest value, determining the target digest interval where the transaction digest value is located; Storing the to-be-chained transaction in the transaction storage space whose digest interval is the target digest interval.
8. The method according to claim 1, wherein Packing the to-be-chained transactions stored in the target transaction storage space into a to-be-consensus block, includes: For each to-be-chained transaction in the target transaction storage space, obtaining the transaction timestamp of the to-be-chained transaction; Based on the chronological order of the transaction timestamps, sequentially taking out multiple to-be-chained transactions from the target transaction storage space and packing them into the to-be-consensus block until the size of the to-be-consensus block reaches a preset threshold.
9. The method according to claim 1, characterized in that Packing the to-be-chained transactions stored in the target transaction storage space into a to-be-consensus block, includes: For each to-be-chained transaction in the target transaction storage space, obtaining the associated resource information of the to-be-chained transaction; Determining the transaction packing order based on the associated resource information; Based on the transaction packing order, sequentially taking out multiple to-be-chained transactions from the target transaction storage space and packing them into the to-be-consensus block until the size of the to-be-consensus block reaches a preset threshold.
10. The method according to claim 1, characterized in that, Determining the target transaction storage space corresponding to the target main node in the second number of the transaction storage spaces, includes: Determining the node number of each main node and the storage space number of each transaction storage space; Based on the node number and the storage space number, determining the target transaction storage space corresponding to the target main node.
11. The method according to claim 2, wherein After performing the blockchain processing on multiple consecutive target blocks based on multiple block heights, the blockchain consensus method further includes updating the target transaction storage space corresponding to the target main node, specifically including: Determining the node processing speed of each main node and the number of transactions of the current to-be-chained transactions in each transaction storage space; Based on the node processing speed and the number of transactions, re-determining the target transaction storage space corresponding to the target main node.
12. The method according to claim 2, wherein Each transaction storage space has a storage space index; After performing the blockchain processing on multiple consecutive target blocks based on multiple block heights, the blockchain consensus method further includes: Determine the unchained transactions in each of the transaction storage spaces; Update the current consensus round of the blockchain network to obtain the updated consensus round; For each of the unchained transactions, perform a modulo operation on the sum of the round number of the updated consensus round and the transaction digest value of the unchained transaction, and the second number of the transaction storage space, to obtain a remainder; Based on the remainder, re-store the unchained transaction to the transaction storage space with the same storage space index as the remainder to update each of the transaction storage spaces.
13. The method according to claim 1, wherein The second number of master nodes is determined by the following method: Determine the node reputation and node processing capabilities of each of the consensus nodes; Based on the node reputation and the node processing capabilities, determine the second number of master nodes among the first number of consensus nodes.
14. The method according to claim 13, wherein The determining the second number of master nodes among the first number of consensus nodes based on the node reputation and the node processing capabilities includes: For each of the consensus nodes, determine a first score based on the node reputation; For each of the consensus nodes, determine a second score based on the node processing capabilities; Based on the first score and the second score, determine the total score of the consensus node; Determine the consensus nodes with the top second number of total scores as the master nodes.
15. The method according to claim 14, wherein The second number is determined by the following method: Obtain the total number of nodes in the blockchain network and the network operation information; Based on the total number of nodes and the network operation information, determine the second number.
16. The method according to claim 15, wherein The determining the second number based on the total number of nodes and the network operation information includes: Based on the total number of nodes, determine a third score; Based on the network operation information, determine a fourth score; Based on the third score and the fourth score, determine the second number.
17. A blockchain consensus device, characterized in that, The blockchain consensus device has multiple consensus rounds, and in each consensus round, it is applied to the target master node among the second number of master nodes in the first number of consensus nodes. The second number is greater than or equal to 2 and less than or equal to the first number. Each consensus node has a second number of transaction storage spaces respectively corresponding to the second number of master nodes. The blockchain consensus device includes: An acquisition unit for acquiring the transaction to be chained; A mapping unit for mapping the transaction to be chained to one of the transaction storage spaces based on the mapping rule of the transaction to be chained in the second number of transaction storage spaces; A determination unit for determining the target transaction storage space corresponding to the target master node in the second number of transaction storage spaces; A packaging unit for packaging the transaction to be chained stored in the target transaction storage space into a block to be consensus and sending the block to be consensus to the slave nodes, so that the slave nodes perform consensus on the transaction to be chained in the block to be consensus based on the target transaction storage space corresponding to the target master node in the slave nodes, where the slave nodes are the consensus nodes other than the target master node.
18. An electronic device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the blockchain consensus method described in any one of claims 1 to 16.
19. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the blockchain consensus method described in any one of claims 1 to 16.
20. A computer program product, which includes a computer program that is read and executed by a processor of a computer device, so that the computer device executes the blockchain consensus method described in any one of claims 1 to 16.