Consensus processing method in block chain system and computer equipment
By introducing master nodes and multi-round random sampling voting mechanisms into the chain consensus algorithm, the problem of low consensus efficiency in the DAG consensus protocol is solved, and fast consensus of proposed blocks is achieved in large-scale blockchain networks.
Patent Information
- Application Number
- CN202511235403.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-11-21
AI Technical Summary
DAG-based consensus protocols suffer from low consensus efficiency in large-scale blockchain networks, especially when multiple nodes propose new blocks simultaneously, leading to a large number of conflicting blocks and affecting consensus efficiency.
A chain-based consensus algorithm is introduced, which elects a unique master node to broadcast the proposed block in each round of consensus, and introduces a multi-round random sampling voting mechanism on other nodes to ensure that the proposed block spreads quickly and reaches consensus in the blockchain network.
It significantly improves consensus efficiency in large-scale blockchain networks, ensuring that proposed blocks can quickly reach consensus, and solves the problem of low efficiency in traditional DAG consensus protocols.
Smart Images

Figure CN121000731A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification belong to the field of blockchains, and particularly relate to a consensus processing method in a blockchain system and a computer device. BACKGROUND
[0002] In a large-scale blockchain network, in order to cope with the bottleneck of traditional blockchain networks in terms of scalability, throughput and latency, a consensus protocol based on DAG (Directed Acyclic Graph) is usually adopted. Unlike the traditional chain-based consensus protocol, this type of consensus protocol does not limit the out-degree and in-degree of each block, that is, each new block generated through consensus can refer to multiple blocks at the same time, and each block can be referred to by multiple new blocks, and in each round of consensus, multiple nodes are usually allowed to propose new blocks at the same time, so the topology structure of the blocks reaching consensus based on this type of consensus algorithm will no longer be a single chain structure, but a directed acyclic graph structure.
[0003] However, based on the above-described characteristics, although the DAG-based consensus protocol can naturally support high-concurrency writing, in actual application, this type of consensus protocol may have the problem of low consensus efficiency, especially in a large-scale blockchain network, this problem is particularly obvious. SUMMARY
[0004] The present specification proposes a consensus processing method in a blockchain system, wherein a consensus protocol running in the blockchain system supports electing a unique master node in each round of consensus, and the master node is used to propose a block corresponding to the current round of consensus to other consensus nodes participating in the consensus; the method is applied to any target consensus node in the consensus nodes participating in the consensus in the blockchain system, except for the master node; the method comprises:
[0005] receiving a proposed block corresponding to the current round of consensus broadcast by the master node; wherein the proposed block is broadcast by the master node to a plurality of consensus nodes randomly selected from the blockchain system;
[0006] in response to the received proposed block, iteratively performing a plurality of rounds of random sampling voting on the proposed block with other consensus nodes participating in the consensus;
[0007] after each round of random sampling voting ends, determining whether the number of rounds of random sampling voting with a voting result of passing reaches a preset threshold value; if the number of rounds reaches the preset threshold value, determining that the consensus on the proposed block passes; otherwise, the next round of random sampling voting is continued until the number of rounds of random sampling voting with a voting result of passing reaches the preset threshold value.
[0008] Optionally, performing a random sampling voting on the proposal block in each round with other consensus nodes participating in the consensus, comprising:
[0009] Randomly selecting a plurality of consensus nodes from other consensus nodes participating in the consensus;
[0010] Sending an inquiry message corresponding to the proposal block to each of the plurality of consensus nodes; wherein the inquiry message is used to inquire the voting result for the proposal block;
[0011] Collecting a response message corresponding to the inquiry message returned by the plurality of consensus nodes to complete a random sampling voting on the proposal block in each round; wherein the response message contains a voting result corresponding to the proposal block; the voting result contains a vote for and a vote against.
[0012] Optionally, after each round of random sampling voting ends, determining whether the number of rounds of random sampling voting with a voting result reaches a preset threshold, comprising:
[0013] After each round of random sampling voting ends, determining whether the number of votes for collected for the proposal block reaches Quorum;
[0014] If the number of votes for collected for the proposal block reaches Quorum, updating the number of rounds of random sampling voting with a voting result maintained for the proposal block, and further determining whether the number of rounds after the update reaches the preset threshold.
[0015] Optionally, the number of rounds of random sampling voting with a voting result maintained by the target consensus node for the proposal block, comprising: a first number representing the total number of rounds of random sampling voting with a voting result for the proposal block; and a second number representing the number of rounds of consecutive random sampling voting with a voting result for the proposal block;
[0016] If the number of votes for collected for the proposal block reaches Quorum, updating the number of rounds of random sampling voting with a voting result maintained for the proposal block, comprising:
[0017] If the number of the collected votes in favor of the proposed block reaches the Quorum, the first number maintained is updated, and it is determined whether the number of the collected votes in favor of the proposed block also reaches the Quorum in the last round of the random sampling voting; if the number of the collected votes in favor of the proposed block also reaches the Quorum in the last round of the random sampling voting, the first number maintained is further updated; otherwise, the first number maintained is restored to the initial value.
[0018] Optionally, it is determined whether the number of rounds of the random sampling voting with the voting result being a vote pass reaches a preset threshold; if the number of rounds reaches the preset threshold, it is determined that the consensus for the proposed block is passed; otherwise, the next round of the random sampling voting is continued until the number of rounds of the random sampling voting with the voting result being a vote pass reaches the preset threshold, including:
[0019] It is determined whether the second number after the update reaches a first threshold;
[0020] If the second number after the update reaches the first threshold, it is determined that the consensus for the proposed block is passed;
[0021] If the second number after the update does not reach the first threshold, it is further determined whether the first number after the update reaches a preset second threshold; wherein the first threshold is less than the second threshold;
[0022] If the first number after the update reaches the preset second threshold, it is determined that the consensus for the proposed block is passed;
[0023] If the first number after the update does not reach the preset second threshold, the next round of the random sampling voting is continued until the second number after the update reaches the first threshold; or the first number after the update reaches the second threshold.
[0024] Optionally, the target consensus node maintains a conflict block set corresponding to each round of consensus;
[0025] In response to the received proposed block, a plurality of rounds of random sampling voting for the proposed block are iteratively performed with other consensus nodes participating in the consensus, including:
[0026] In response to the received plurality of proposed blocks broadcast by the master node and corresponding to the current round of consensus, the plurality of proposed blocks are added to the conflict block set, and a target proposed block preferred by the target consensus node is determined from the conflict block set;
[0027] performing a plurality of rounds of random sampling voting for the proposed block against the target in iteration with other consensus nodes participating in the consensus.
[0028] Optionally, determining the target proposed block preferred by the target consensus node from the set of conflict blocks;
[0029] In the initial state, randomly selecting one proposed block from each proposed block in the set of conflict blocks as the target proposed block preferred by the target consensus node; and,
[0030] After the end of any round of random sampling voting, further switching the first highest number of proposed blocks maintained as the target proposed block preferred by the target consensus node.
[0031] Optionally, the method further comprises:
[0032] In any round of random sampling voting, if an inquiry message sent by other consensus nodes is received, determining whether the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node;
[0033] If the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node, returning a first response message corresponding to the inquiry message to the other consensus nodes; wherein the first response message contains an approval vote corresponding to the proposed block;
[0034] If the proposed block contained in the inquiry message is not the target proposed block preferred by the target consensus node, returning a second response message corresponding to the inquiry message to the other consensus nodes; wherein the second response message contains a disapproval vote corresponding to the proposed block.
[0035] In the above embodiment, a chain consensus algorithm that can run in a large-scale blockchain network is proposed. By introducing a random diffusion mechanism for proposed blocks on the master node in the chain consensus algorithm, and introducing a multi-round random sampling voting mechanism on other nodes except the master node, the consensus efficiency of the consensus algorithm can be significantly improved, and the proposed block can quickly reach consensus. BRIEF DESCRIPTION OF DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present specification, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments described in the present specification, and for those skilled in the art, other drawings can also be obtained from these drawings without creative labor.
[0037] Figure 1is a flow chart of a consensus processing method in a blockchain system according to an embodiment of the present specification;
[0038] Figure 2 is an interaction flow chart of a chain consensus protocol according to an embodiment of the present specification;
[0039] Figure 3 is a schematic structural diagram of an electronic device according to an embodiment of the present specification;
[0040] Figure 4 is a block diagram of a consensus processing device in a blockchain system according to an embodiment of the present specification. DETAILED DESCRIPTION
[0041] In order to enable those skilled in the art to better understand the technical solutions in the present specification, the technical solutions in the present specification will be clearly and completely described below in conjunction with the drawings in the embodiments of the present specification. Obviously, the described embodiments are only part of the embodiments of the present specification, not all. Based on the embodiments in the present specification, all other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present specification.
[0042] The DAG-based consensus protocol, although naturally suitable for running in a large-scale blockchain network, in each round of consensus, multiple nodes simultaneously propose new blocks, which may generate a large number of conflict blocks. For example, these conflict blocks can generally refer to blocks proposed by different nodes in the same round of consensus, which cannot be accepted at the same time due to contradictions in the topology structure or verification rules.
[0043] Once a large number of conflict blocks are generated in a round of consensus, it is necessary to introduce a processing mechanism for conflict blocks to determine the legal blocks from these conflict blocks. At this time, the additional processing mechanism for conflict blocks introduced obviously may cause the problem of reducing the consensus efficiency of the consensus algorithm.
[0044] Based on this, the present specification proposes a chain consensus algorithm that can run in a large-scale blockchain network.
[0045] On the one hand, in the chain consensus algorithm, multiple nodes will no longer be supported to simultaneously propose blocks in a round of consensus, but in each round of consensus, only the elected master node will propose blocks, and on the master node, a random diffusion mechanism for proposed blocks can be introduced, and the master node will randomly broadcast the proposed blocks corresponding to the current round of consensus to multiple consensus nodes selected from the blockchain system;
[0046] On the other hand, in this chain consensus algorithm, a multi-round random sampling voting mechanism can be introduced on other consensus nodes besides the master node. The consensus node that receives the proposed block broadcast by the master node and other consensus nodes participating in the consensus will iteratively conduct multiple rounds of random sampling voting on the proposed block to quickly reach a consensus on the proposed block.
[0047] Please see Figure 1 , Figure 1 This document presents a flowchart of a consensus processing method in a blockchain system. The consensus protocol of the blockchain system supports the election of a unique master node in each round of consensus. The master node proposes a block corresponding to the current round of consensus to the other consensus nodes participating in the consensus. The method is applied to any target consensus node among the consensus nodes participating in the consensus of the blockchain system, excluding the master node. The method includes the following execution process:
[0048] Step 102: Receive the proposal block corresponding to this round of consensus broadcast by the master node; wherein the proposal block is broadcast by the master node to multiple consensus nodes randomly selected from the blockchain system;
[0049] In this specification, the consensus protocol used by the aforementioned blockchain system may specifically include a chain-based consensus protocol.
[0050] Based on the chain consensus protocol, it will support the election of a unique master node (also known as the leader node) in each round of consensus. The master node will propose the block corresponding to the current round of consensus to the other consensus nodes participating in the consensus.
[0051] The specific method for electing the master node can be flexibly configured based on specific needs in practical applications, and will not be specifically limited in this manual.
[0052] In some embodiments, each round of consensus in a chain consensus protocol typically has a unique block height. Therefore, in practical applications, mathematical operations can be performed on the block height of each round of consensus to calculate the unique master node corresponding to this round of consensus.
[0053] For example, in one scenario, assuming the number of consensus nodes participating in the consensus process in the blockchain system is n, and all consensus nodes have unique and consecutive numbers (e.g., from 0 to n-1), and assuming the block height of this consensus round is h, then the master node for this round of consensus can be calculated using the following formula:
[0054] leader = hash(h) mod n
[0055] Wherein, the leader represents the calculated number of the leader node of the current round of consensus; h represents the block height of the current round of consensus; n is the number of consensus nodes participating in consensus in the blockchain system; hash(h) represents the hash calculation of h; mod represents the modulo operation, which is used to calculate the remainder after two integers are divided. Based on the above formula, the remainder after the hash value obtained by hashing h is divided by n can be calculated by the mod operation to represent the number of the leader node of the current round of consensus.
[0056] After the leader node of the current round of consensus is elected, the leader node can initiate a proposal block corresponding to the current round of consensus, and use a random diffusion mechanism to randomly select a plurality of consensus nodes from the blockchain system; wherein the specific number of consensus nodes randomly selected from the blockchain system can be flexibly set based on demand in actual application; and then broadcast the proposal block to the plurality of consensus nodes randomly selected from the blockchain system.
[0057] For example, please refer to Figure 2 , assuming that the blockchain system contains a total of 7 consensus nodes, P1-P7, P1 is elected as the leader node of the current round of consensus, at this time P1 can randomly select N consensus nodes from the blockchain system; for example, as Figure 2 shown, the value of N can be 2, P1 can randomly select P2 and P3 nodes from the blockchain system, and then broadcast the proposal block corresponding to the current round of consensus to P2 and P3.
[0058] The above target consensus node can receive the proposal block broadcasted by the leader node. At this time, if the target consensus node is one of the plurality of consensus nodes randomly selected by the leader node from the blockchain system, the target consensus node can receive the proposal block broadcasted by the target consensus node. In addition to the plurality of consensus nodes randomly selected by the leader node in the blockchain system, the proposal block broadcasted by the leader node cannot be received.
[0059] For example, please continue to refer to Figure 2 , taking the above target consensus node P2 as an example, since the above target consensus node is one of the N consensus nodes randomly selected by the leader node P1 from the blockchain system, at this time P2 can receive the proposal block broadcasted by the leader node.
[0060] Step 104: in response to the received proposal block, iteratively performing a plurality of rounds of random sampling voting on the proposal block with other consensus nodes participating in consensus;
[0061] After receiving the proposed block broadcasted by the master node, the target consensus node can respond to the proposed block and perform a multi-round random sampling voting mechanism with other consensus nodes participating in the consensus to iteratively perform multi-round random sampling voting on the proposed block to quickly reach a consensus on the proposed block.
[0062] It should be noted that the number of rounds of random sampling voting performed by the target consensus node and other consensus nodes depends on the consensus agreement preset condition for passing the consensus. In actual applications, the target consensus node can stop voting and no longer continue voting in the next round once the proposed block meets the consensus agreement passing condition during the multi-round random sampling voting process performed on the proposed block with other consensus nodes participating in the consensus. Otherwise, the above voting process needs to be iteratively performed until the voting process ends when the proposed block meets the consensus agreement passing condition.
[0063] In some embodiments, the target consensus node can randomly select a plurality of consensus nodes from other consensus nodes participating in the consensus when performing random sampling voting on the proposed block with other consensus nodes participating in the consensus, and then send an inquiry message corresponding to the proposed block to each of the plurality of consensus nodes. The inquiry message can be used to inquire about the voting result on the proposed block.
[0064] The message format of the inquiry message is not limited in the present specification.
[0065] For example, in actual applications, the inquiry message corresponding to the proposed block sent by the target consensus node to the plurality of consensus nodes can include the target proposal and the node identifier of the receiver of the inquiry message.
[0066] After the target consensus node sends the inquiry message corresponding to the proposed block to the plurality of consensus nodes, the target consensus node can further collect the response message corresponding to the inquiry message returned by the plurality of consensus nodes to complete a round of random sampling voting on the proposed block. The response message can include the voting result corresponding to the proposed block. The voting result includes a vote in favor and a vote against.
[0067] The message format of the response message is not limited in the present specification.
[0068] For example, in actual applications, the response message corresponding to the inquiry message returned by the plurality of consensus nodes to the target consensus node can include the voting result and the node identifier of the consensus node sending the response message.
[0069] It should be noted that in order to ensure the randomness of the voting, the above target consensus node can randomly select a plurality of consensus nodes from other consensus nodes participating in the consensus in each round of random sampling voting.
[0070] For example, please continue to see Figure 2 For example, please continue to see Figure 2 For example, please continue to see Figure 2 It is shown that the value of M can be 3; in the first round of random sampling voting, P2 can randomly select P3, P4 and P5 to participate in random sampling voting, and P3, P4 and P5 can return response messages to P2 respectively after receiving the inquiry message sent by P2. In the second round of random sampling voting, P2 can randomly select P5, P6 and P7 to participate in random sampling voting, and P5, P6 and P7 can return response messages to P2 respectively after receiving the inquiry message sent by P2. By analogy, in every N rounds of random sampling voting, P2 can randomly select P1 (the master node can also participate in voting), P5 and P7 to participate in random sampling voting, and P1, P5 and P7 can return response messages to P2 respectively after receiving the inquiry message sent by P2.
[0071] In this way, on the one hand, it can ensure that the voters of different rounds of random sampling voting can have a certain randomness; on the other hand, in each round of random sampling voting, a plurality of consensus nodes are randomly selected again, which can ensure that the proposal block broadcasted by the master node can be contained in the inquiry message and gradually spread to different consensus nodes in the entire blockchain network, and after the number of rounds of random sampling voting reaches a certain number, the proposal block is spread to the entire blockchain network, thereby playing the same diffusion effect as the rumor propagation mechanism adopted by the traditional DAG-based consensus protocol.
[0072] For example, taking the Hashgraph consensus protocol as an example based on the above DAG-based consensus protocol, based on the Hashgraph consensus protocol, each consensus node can exchange proposal blocks with other consensus nodes by running the gossip protocol. Different from the traditional communication mechanism, the gossip protocol adopts a special communication mechanism inspired by the characteristics of rumor spreading. Based on the gossip protocol, the consensus node can randomly select a consensus node as a communication partner, exchange the received proposal blocks between the consensus nodes, and repeat the above process. Through continuous two-to-two communication between consensus nodes, the proposal blocks published by all consensus nodes in a consensus round will eventually be gradually spread to each consensus node and recorded in the hash graph maintained locally by each consensus node, so that the hash graph maintained locally by all consensus nodes will record the same set of proposal blocks. And the above target consensus node adopts multiple rounds of random sampling voting, and randomly selects multiple consensus nodes in each round of random sampling voting, which can ensure that the proposal block broadcast by the master node can be gradually spread to different consensus nodes in the entire blockchain network through the inquiry message, and eventually spread to the entire blockchain network after a certain number of random sampling voting rounds.
[0073] Step 106, after each round of random sampling voting ends, determine whether the number of rounds of random sampling voting with a voting result of passing the vote reaches a preset threshold; if the number of rounds reaches the preset threshold, determine that the consensus for the proposal block is passed; otherwise, continue the next round of random sampling voting until the number of rounds of random sampling voting with a voting result of passing the vote reaches the preset threshold.
[0074] After each round of random sampling voting ends, the above target consensus node can also determine whether the above proposal block meets the consensus passing condition; if the above proposal block meets the consensus passing condition, the consensus for the proposal block can be directly determined to pass; otherwise, if the above proposal block does not meet the consensus passing condition, the next round of random sampling voting can be continued until the above proposal block meets the consensus passing condition.
[0075] It should be noted that in actual applications, the condition under which the above proposal block meets the consensus passing condition can be flexibly set based on requirements, and will not be particularly limited in this specification.
[0076] In some embodiments, to satisfy the condition of consensus passing for the proposed block, specifically, the number of rounds of random sampling voting with a voting pass result can reach a preset threshold in the above-mentioned multiple rounds of random sampling voting; that is, once the number of rounds reaches the threshold in the above-mentioned multiple rounds of random sampling voting with a voting pass result, it can be considered that the proposed block has passed the consensus.
[0077] In this case, the target consensus node can further determine whether the number of rounds of random sampling voting with a voting pass result reaches a preset threshold after each round of random sampling voting ends; if the number of rounds reaches the preset threshold, it can be determined that the consensus for the proposed block passes; otherwise, if the number of rounds has not reached the preset threshold, the next round of random sampling voting can be continued until the number of rounds of random sampling voting with a voting pass result reaches the preset threshold.
[0078] In some embodiments, during the above-mentioned multiple rounds of random sampling voting, the target consensus node can further maintain the number of rounds of random sampling voting with a voting pass result corresponding to the proposed block;
[0079] After each round of random sampling voting ends, the target consensus node can count the voting results of the proposed block from other consensus nodes based on the collected response messages, and determine whether the number of collected votes in favor of the proposed block reaches Quorum; it should be noted that Quorum generally refers to a threshold value of the number of consensus nodes that can represent the majority in the blockchain.
[0080] For example, in the case that the number of consensus nodes participating in the consensus in the blockchain is 3f+1, the value of Quorum can be n-f, i.e., 2f+1. In this way, for a distributed system including 4 nodes, any 3 nodes can form a Quorum. f refers to the number of Byzantine nodes (i.e., malicious nodes) that the blockchain can tolerate;
[0081] For another example, assuming that the total number of consensus nodes in the blockchain system is K, Quorum can be a threshold value a, and the value of a can satisfy
[0082] If the number of votes in favor of the proposed block collected by the target consensus node reaches Quorum, the number of rounds of random sampling voting with a voting pass result corresponding to the proposed block maintained by the target consensus node can be updated, and it can be further determined whether the number of rounds after the update reaches the preset threshold.
[0083] For example, the number of rounds of the voting-passed random sampling voting can be represented by chit. After one round of the voting-passed random sampling voting, if the number of votes obtained by a block for the proposal block reaches Quorum, the number of chit can be increased by 1, and it is further determined whether the number of chit after the increase by 1 reaches a preset threshold.
[0084] In some embodiments, the number of rounds of the voting-passed random sampling voting corresponding to the proposal block maintained by the target consensus node can specifically include: a first number representing the total number of rounds of the voting-passed random sampling voting corresponding to the proposal block; and a second number representing the number of rounds of the continuously voting-passed random sampling voting corresponding to the proposal block.
[0085] For example, still taking the number of rounds of the voting-passed random sampling voting represented by chit as an example, in one example, the total number of chit obtained by the proposal block T, that is, the first number, can be represented by The total number of chit obtained by the proposal block T, that is, the first number, can be represented by The number of times that the proposal block T obtains chit continuously, that is, the second number, can be represented by
[0086] It should be explained that the total number of rounds of the voting-passed random sampling voting refers to the total number of rounds in which the number of votes collected for the proposal block reaches Quorum in the multiple rounds of random sampling voting. The total number of rounds can be an accumulated value. The number of rounds of the continuously voting-passed random sampling voting is different from the total number of rounds of the voting-passed random sampling voting, and is not an accumulated value. If Quorum of votes for the proposal block are collected in the last round of random sampling voting, and Quorum of votes for the proposal block are collected in the current round of random sampling voting, that is, Quorum of votes for the proposal block are collected in two consecutive rounds, in this case, the number of rounds of the continuously voting-passed random sampling voting is 2. If Quorum of votes for the proposal block are collected in the current round of random sampling voting, but Quorum of votes for the proposal block are not collected in the last round of random sampling voting, in this case, the number of rounds of the continuously voting-passed random sampling voting is 1.
[0087] After each round of random sampling voting ends, if the number of votes collected by the target consensus node for the proposal block reaches Quorum, the first number maintained can be updated, for example, the first number is increased by 1.
[0088] In addition, the target consensus node can also determine whether the number of the collected votes in favor of the proposed block in the last round of the random sampling voting also reaches the Quorum. the block identifier of the block that represents the block that obtains the chit in the last round of the random sampling voting.
[0089] In this case, the target consensus node can determine, by using the maintained block identifier, whether the number of the collected votes in favor of the proposed block in the last round of the random sampling voting also reaches the Quorum. If the number of the collected votes in favor of the proposed block in the last round of the random sampling voting also reaches the Quorum, the maintained first number can be further updated. For example, the first number is increased by 1. Otherwise, the maintained first number can be restored to the initial value. For example, the initial value is 1, indicating that the number of the consecutive voting passes is 1.
[0090] In some embodiments, when determining whether the number of the updated rounds reaches the preset threshold, the target consensus node can first determine whether the second number after the update reaches a first threshold. If the second number after the update reaches the first threshold, that is, the number of the consecutive voting passes reaches the first threshold, the consensus for the proposed block can be directly determined to pass.
[0091] In this case, the number of the consecutive voting passes reaching the first threshold can be regarded as a condition for the fast consensus pass for the proposed block. As long as the number of the consecutive voting passes reaches the first threshold, the consensus for the proposed block can be directly determined to pass, and the consensus can be quickly reached.
[0092] If the second number after the update does not reach the first threshold, the target consensus node can further determine whether the first number after the update reaches a preset second threshold. The first threshold can be less than the second threshold. For example, in actual applications, the number of the consecutive voting passes is usually less than the number of the total voting passes, and thus the second number of the consecutive voting passes can be set to a smaller threshold.
[0093] If the first number after the update reaches the second threshold, that is, the number of the total voting passes reaches the second threshold, the consensus for the proposed block can be directly determined to pass.
[0094] If the first number after the update does not reach the second threshold, the target consensus node can continue the next round of random sampling voting until the second number after the update reaches the first threshold; or, the first number after the update reaches the second threshold.
[0095] For example, please continue to refer to Figure 2 , assuming that P2 iterates N rounds of random sampling voting, at this time the proposal block meets the consensus pass condition, at this time P2 can directly determine the consensus pass for the proposal block, and output the proposal block as at least part of the consensus result.
[0096] It should be noted that in actual application, the number of rounds of random sampling voting for the proposal block between the target consensus node and other consensus nodes participating in consensus is a dynamic value, and the number of rounds of random sampling voting is usually determined by the number of honest nodes in the blockchain system.
[0097] When the proportion of honest nodes in the blockchain system is large or the number of malicious nodes is small, it is usually easier to quickly reach consensus by running the consensus protocol. At this time, the number of rounds of random sampling voting between the target consensus node and other consensus nodes participating in consensus is usually small; on the contrary, the number of rounds of random sampling voting between the target consensus node and other consensus nodes participating in consensus is usually large.
[0098] For example, assuming that the first threshold is 3, in the case of completely ignoring the influence of malicious nodes (that is, all nodes are honest nodes), usually only 3 rounds of random sampling voting are needed, and the first number can reach 3, at this time the target proposal can quickly reach consensus. Conversely, if there are malicious nodes, usually after 3 rounds of random sampling voting, the first number usually cannot reach 3, at this time more rounds of random sampling voting may be needed before the target proposal can reach consensus.
[0099] In actual application, in the chain consensus protocol, although the simultaneous proposal of new blocks by multiple consensus nodes in the discussion consensus is no longer supported, if the master node has malicious behavior, the proposal blocks broadcast by the master node to the randomly selected consensus nodes in the blockchain system may still contain conflict blocks.
[0100] For example, in the same round of consensus, when the master node proposes multiple proposal blocks at the same block height, since the chain consensus protocol does not allow multiple blocks at the same block height, the multiple proposal blocks are conflict blocks in conflict.
[0101] In this case, in addition to the master node, other consensus nodes in the blockchain system can also locally maintain a set of conflict blocks corresponding to each round of consensus.
[0102] When the above target consensus node receives the multiple proposed blocks corresponding to the current round of consensus broadcast by the master node, at this time the target consensus node can first add the multiple proposed blocks to the maintained conflict block set in response to the received multiple proposed blocks, and determine the target proposed block preferred by the target consensus node from the conflict block set; Then, the above target consensus node only needs to initiate an inquiry for the preferred target proposed block, and iteratively perform multiple rounds of random sampling voting for the target proposed block with other consensus nodes participating in the consensus.
[0103] For example, in one example, the target consensus node can use to represent the target proposed block that the node is more preferred in the conflict block set, and in each round of random sampling voting, the above target consensus node only needs to initiate an inquiry for , and iteratively perform multiple rounds of random sampling voting for the target proposed block with other consensus nodes participating in the consensus.
[0104] Wherein, the strategy adopted when determining the target proposed block preferred by the consensus node from the conflict block set can be flexibly set in actual application, and will not be particularly limited in this specification.
[0105] For example, in some embodiments, when the above target consensus node determines the target proposed block preferred by the target consensus node from the maintained conflict block set, if the conflict block set only contains one proposed block, the unique proposed block can be determined as the preferred target proposed block;
[0106] If the conflict block set contains multiple proposed blocks, in the initial state (such as the multiple proposed blocks are all new proposed blocks added to the conflict block set, and have not been subjected to any inquiry), the above target consensus node can randomly select one proposed block from each proposed block in the conflict block set as the target proposed block preferred by the target consensus node; Of course, all proposed blocks in the conflict block set can also be regarded as the target proposed block preferred by the target consensus node.
[0107] And after the end of any round of random sampling voting, the above target consensus node can further switch the maintained second highest number of proposed blocks to the target proposed block preferred by the target consensus node according to the voting situation of other consensus nodes for each proposed block in the conflict block set.
[0108] For example, in one example, the total number of chits obtained by the proposed block T, i.e., the first number mentioned above, can be represented as is the total number of chits obtained by the proposed block T, i.e., the first number mentioned above, and represents the target proposed block to which the node is more inclined in the set of conflict blocks. At this time, if the of a new proposed block in the set of conflict blocks is more than the of all other blocks in the set of conflict blocks, then can be replaced by the new proposed block.
[0109] In some embodiments, in any round of random sampling voting, if the target consensus node receives an inquiry message sent by other consensus nodes, it can also determine whether the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node;
[0110] If the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node, a first response message corresponding to the inquiry message can be returned to other consensus nodes; wherein the first response message can contain an approval vote corresponding to the proposed block;
[0111] If the proposed block contained in the inquiry message is not the target proposed block preferred by the target consensus node, a second response message corresponding to the inquiry message can be returned to other consensus nodes; wherein the second response message contains a non-approval vote corresponding to the proposed block.
[0112] It should be emphasized that the above implementation is only described from the perspective of any target consensus node in the blockchain system except the master node. In actual application, multiple consensus nodes in the blockchain system that receive the proposed block broadcast by the master node will usually perform the same method process as the target consensus node and iteratively perform multiple rounds of random sampling voting on the proposed block with other consensus nodes; for example, please continue to refer to Figure 2 , Figure 2 The above multiple rounds of random sampling voting are described from the perspective of P2. In actual application, each consensus node in P3-P7 will actually perform the same interaction process as P2.
[0113] In this specification, the above embodiments will not be repeatedly described from the perspective of other consensus nodes in the above multiple consensus nodes except the target consensus node.
[0114] Corresponding to the above method embodiments, the present specification also provides device, electronic equipment and storage medium embodiments.
[0115] Figure 3 is a schematic structural diagram of a device provided by an exemplary embodiment. As shown inFigure 3 As shown, the device 300 is comprised of a communication interface 302, a user interface 304, a processor 306, and a data store 308, which are interconnected and communicate with each other through a system bus, network, or other connection mechanism 410. The communication interface 302 enables the device 300 to communicate with other devices, access networks, and transport networks through analog or digital modulation. For example, the communication interface 302 can include a chipset and antenna for wireless communication with a radio access network or access point. In addition, the communication interface 302 can be a wired interface such as an Ethernet, Token Ring, or USB port, or a wireless interface such as Wifi, Bluetooth, Global Positioning System (GPS), or a wide-area wireless interface (e.g., WiMAX or LTE). Of course, the communication interface 302 can support other forms of physical layer interface and standard or proprietary communication protocol. The communication interface 302 can also include multiple physical communication interfaces, such as a Wifi interface, a Bluetooth interface, and a wide-area wireless interface.
[0116] The user interface 304 includes receiving user input and providing output to the user. Thus, the user interface 304 can include input components such as a keyboard, a touch- sensitive or presence-sensitive panel, a computer mouse, a trackball, a joystick, a microphone, a still camera, and a video camera, and output components such as a display screen (which can be combined with a touch-sensitive panel), a CRT, an LCD, an LED, a display using DLP technology, a printer, other known or future- developed similar devices. The user interface 304 can also generate audible output through a speaker, a speaker jack, an audio output port, an audio output device, headphones, and other known or future- developed similar devices. In some embodiments, the user interface 304 can include software, circuitry, or other forms of logic that can transmit data to and receive data from external user input / output devices. Additionally or alternatively, the device 300 can support remote access from other devices through the communication interface 302 or another physical interface (not shown). The user interface 304 can be configured to receive user input, the location and movement of which can be indicated by an indicator or cursor described herein. The user interface 304 can also be configured as a display device for rendering or displaying a text segment.
[0117] The processor 306 can include one or more general processors and / or specialized processors.
[0118] The data store 308 can include one or more volatile and / or non-volatile storage components, and can be integrated in whole or in part with the processor 306. The data store 308 can include removable and / or non-removable components.
[0119] The processor 306 can execute program instructions 318 (e.g., compiled or interpreted program logic and / or machine code) stored in the data storage 308 to implement various functionality described herein. The data storage 308 can include a non-transitory computer- readable medium having stored thereon program instructions that, when executed by the device 300, can cause the device 300 to perform any of the methods, processes, or functions disclosed in the specification and / or drawings. Execution of the program instructions 318 by the processor 306 can cause the processor 306 to utilize data 312.
[0120] For example, the program instructions 318 can include an operating system 322 (e.g., an operating system kernel, device drivers, and / or other modules) installed on the device 300 as well as one or more application programs 320 (e.g., a browser, a social application, or a game application). Similarly, the data 312 can include operating system data 316 and application data 314. The operating system data 316 is primarily accessible to the operating system 322, while the application data 314 is primarily accessible to the one or more application programs 320. The application data 314 can be located in a file system that is visible or hidden to a user of the device 300.
[0121] The application programs 320 can communicate with the operating system 322 through one or more application programming interfaces (APIs). These APIs facilitate the application programs 320 in reading and / or writing application data 314, transmitting or receiving information via the communication interface 302, receiving or displaying information on the user interface 304, and so on.
[0122] In some terminology, the application programs 320 can be simply referred to as “apps.” Furthermore, the application programs 320 can be downloaded to the device 300 through one or more online application stores or application markets. However, the application programs can also be installed on the device 300 through other means, such as through a web browser or a physical interface (e.g., a USB port) on the device 300.
[0123] Reference is made to Figure 4 , Figure 4 is a block diagram of a consensus processing apparatus in a blockchain system according to an example embodiment, which can be applied to an electronic device as shown in Figure 3 to implement the technical solutions of the present specification. Among them, the consensus protocol running in the blockchain system supports electing a unique master node in each round of consensus, and the master node is used to propose a block corresponding to the current round of consensus to other consensus nodes participating in the consensus; the method is applied to any target consensus node in the blockchain system participating in the consensus except the master node; the apparatus comprises:
[0124] The receiving module 401 receives a proposal block corresponding to the current round of consensus broadcast by the master node; wherein the proposal block is broadcast by the master node to a plurality of consensus nodes randomly selected from the blockchain system;
[0125] The voting module 402, in response to the received proposal block, iteratively performs a plurality of rounds of random sampling voting on the proposal block with other consensus nodes participating in the consensus;
[0126] The determining module 403 determines whether the number of rounds of random sampling voting with a voting result of pass reaches a preset threshold after each round of random sampling voting ends; if the number of rounds reaches the preset threshold, it is determined that the consensus on the proposal block passes; otherwise, the next round of random sampling voting is continued until the number of rounds of random sampling voting with a voting result of pass reaches the preset threshold.
[0127] In the embodiment, the voting module 402:
[0128] randomly selects a plurality of consensus nodes from other consensus nodes participating in the consensus;
[0129] sends an inquiry message corresponding to the proposal block to the plurality of consensus nodes respectively; wherein the inquiry message is used to inquire the voting result on the proposal block;
[0130] collects the response message corresponding to the inquiry message returned by the plurality of consensus nodes to complete a round of random sampling voting on the proposal block; wherein the response message contains the voting result corresponding to the proposal block; the voting result contains the vote of approval and the vote of disapproval.
[0131] In the embodiment, the determining module 403:
[0132] determines whether the number of collected votes of approval corresponding to the proposal block reaches Quorum after each round of random sampling voting ends;
[0133] If the number of collected votes of approval corresponding to the proposal block reaches Quorum, the number of rounds of random sampling voting with a voting result of pass maintained corresponding to the proposal block is updated, and it is further determined whether the number of rounds after the update reaches the preset threshold.
[0134] In the embodiment, the target consensus node maintains a number of rounds of the random sampling voting of the passed voting corresponding to the proposed block, including: a first number representing a total number of rounds of the random sampling voting of the passed voting corresponding to the proposed block; and a second number representing a number of rounds of the consecutive random sampling voting of the passed voting corresponding to the proposed block.
[0135] The determination module 403 further:
[0136] If the number of the collected votes for the proposed block reaches the Quorum, the first number maintained is updated, and it is determined whether the number of the collected votes for the proposed block also reaches the Quorum in the last round of the random sampling voting; if the number of the collected votes for the proposed block also reaches the Quorum in the last round of the random sampling voting, the first number maintained is further updated; otherwise, the first number maintained is restored to the initial value.
[0137] In the embodiment, the determination module 403 further:
[0138] It is determined whether the second number after the update reaches a first threshold value;
[0139] If the second number after the update reaches the first threshold value, it is determined that the consensus for the proposed block is passed;
[0140] If the second number after the update does not reach the first threshold value, it is further determined whether the first number after the update reaches a preset second threshold value; wherein the first threshold value is less than the second threshold value;
[0141] If the first number after the update reaches the preset second threshold value, it is determined that the consensus for the proposed block is passed;
[0142] If the first number after the update does not reach the preset second threshold value, the next round of the random sampling voting is continued until the second number after the update reaches the first threshold value; or the first number after the update reaches the second threshold value.
[0143] In the embodiment, the target consensus node maintains a set of conflict blocks corresponding to each round of consensus;
[0144] The voting module 402:
[0145] in response to receiving the plurality of proposal blocks corresponding to the current round of consensus broadcasted by the primary node, adding the plurality of proposal blocks to the conflict block set, and determining a target proposal block preferred by the target consensus node from the conflict block set;
[0146] performing a plurality of rounds of random sampling voting for the target proposal block with other consensus nodes participating in the iteration of consensus.
[0147] In the embodiment, the voting module 402 further comprises:
[0148] In the initial state, randomly selecting one proposal block from each proposal block in the conflict block set as the target proposal block preferred by the target consensus node; and,
[0149] After the end of any round of random sampling voting, further switching the first highest number of proposal blocks maintained to the target proposal block preferred by the target consensus node.
[0150] In the embodiment, the device further comprises:
[0151] The returning module 404, Figure 4 If an inquiry message sent by other consensus nodes is received in any round of random sampling voting, determining whether the proposal block contained in the inquiry message is the target proposal block preferred by the target consensus node; if the proposal block contained in the inquiry message is the target proposal block preferred by the target consensus node, returning a first response message corresponding to the inquiry message to the other consensus nodes; wherein the first response message contains an approval vote corresponding to the proposal block; if the proposal block contained in the inquiry message is not the target proposal block preferred by the target consensus node, returning a second response message corresponding to the inquiry message to the other consensus nodes; wherein the second response message contains a disapproval vote corresponding to the proposal block.
[0152] For the convenience of description, the above device is described in various modules or units according to functions. Of course, the functions of each module or unit can be implemented in the same or more software and / or hardware when implementing one or more of the present specification, or the modules implementing the same function can be implemented by a combination of multiple sub-modules or sub-units. The above described device embodiment is only illustrative, for example, the division of the unit is only a logical function division, and actual implementation can have another division mode, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0153] Based on the same idea as the above method, the specification also provides an electronic device, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of the method according to any one of the above embodiments by running the executable instructions.
[0154] Based on the same idea as the above method, the specification also provides a computer-readable storage medium having stored thereon computer instructions which, when executed by a processor, implement the steps of the method according to any one of the above embodiments.
[0155] Based on the same idea as the above method, the specification also provides a computer program product comprising computer program / instructions which, when executed by a processor, implement the steps of the method according to any one of the above embodiments
[0156] Those skilled in the art can understand that:
[0157] In the specification, the term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, product or device that includes a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such a process, method, product or device. Without more limitations, it does not exclude the presence of other same or equivalent elements in the process, method, product or device that includes the elements.
[0158] In the specification, "one", "a" and "the" do not necessarily refer to the singular, but also include the plural.
[0159] In the specification, the first, second, etc. ordinal numbers do not necessarily indicate the order, and are often used for the purpose of distinguishing objects. For example, the first server and the second server usually refer to two servers. In order to distinguish the two servers, they are expressed as the first server and the second server. Of course, sometimes the two servers can also be the same server.
[0160] In the specification, unless specifically stated, "receiving and sending of data" is not necessarily direct receiving and sending, but can be indirect receiving and sending. For example, A receives data sent by B, which can be understood as A directly receiving data sent by B, or A indirectly receiving data sent by B through C and other subjects. Similarly, B sends data to A, which can be understood as B directly sending data to A, or B indirectly sending data to A through C and other subjects. Here C can be one subject, or two or more subjects.
[0161] In this specification, unless expressly stated otherwise, the association relationship between structures can be a direct association relationship or an indirect association relationship. For example, when describing "A is connected with B", unless it is expressly stated that A is directly connected with B, it should be understood that A can be directly connected with B or indirectly connected with B; for another example, when describing "A is on B", unless it is expressly stated that A is directly on B (AB is adjacent and A is on B), it should be understood that A can be directly on B or A can be indirectly on B (there is another element between AB and A is on B). By analogy.
[0162] The present specification uses specific terms to describe the embodiments of the present specification. As "one embodiment", "an embodiment", and / or "some embodiments" means a certain feature, structure, or characteristic in relation to at least one embodiment of the present specification. Therefore, it should be emphasized and noted that the "an embodiment" or "one embodiment" or "one alternative embodiment" mentioned in different positions in the present specification does not necessarily refer to the same embodiment. In addition, the skilled in the art can combine and combine the different embodiments or examples described in the present specification and the features of the different embodiments or examples without contradiction.
[0163] Although one or more embodiments of the present specification provide method steps as described in the embodiments or flowcharts, it can be understood that the order of steps listed in the embodiments or flowcharts is only one of the many execution orders, and does not represent the only execution order. Therefore, when the method steps are involved in the claims, the adjustment of the order of the steps or the parallelism between the steps is also within the protection scope of the claims.
Claims
1. A consensus processing method in a blockchain system, wherein the consensus protocol running the blockchain system supports the election of a unique master node in each round of consensus, and the master node is used to propose a block corresponding to the current round of consensus to other consensus nodes participating in the consensus. The method is applied to any target consensus node in the consensus nodes participating in consensus in the blockchain system except the master node; the method comprises: receiving a proposed block corresponding to the current round of consensus broadcast by the master node; wherein the proposed block is broadcast by the master node to a plurality of consensus nodes randomly selected from the blockchain system; in response to the received proposed block, iteratively performing a plurality of rounds of random sampling voting on the proposed block with other consensus nodes participating in consensus; after the end of each round of random sampling voting, determining whether the number of rounds of random sampling voting with a voting result of pass reaches a preset threshold; if the number of rounds reaches the preset threshold, determining that the consensus on the proposed block is passed; otherwise, continuing the next round of random sampling voting until the end when the number of rounds of random sampling voting with a voting result of pass reaches the preset threshold.
2. The method of claim 1, wherein performing any round of random sampling voting on the proposed block with other consensus nodes participating in consensus comprises: randomly selecting a plurality of consensus nodes from other consensus nodes participating in consensus; sending an inquiry message corresponding to the proposed block to the plurality of consensus nodes respectively; wherein the inquiry message is used to inquire the voting result on the proposed block; collecting the response message corresponding to the inquiry message returned by the plurality of consensus nodes to complete a round of random sampling voting on the proposed block; wherein the response message contains the voting result corresponding to the proposed block; the voting result contains the vote of approval and the vote of disapproval.
3. The method of claim 2, wherein after the end of each round of random sampling voting, determining whether the number of rounds of random sampling voting with a voting result of pass reaches a preset threshold comprises: after the end of each round of random sampling voting, determining whether the number of collected votes of approval corresponding to the proposed block reaches Quorum; if the number of collected votes of approval corresponding to the proposed block reaches Quorum, updating the number of rounds of random sampling voting with a voting result of pass maintained for the proposed block, and further determining whether the number of rounds after the update reaches the preset threshold.
4. The method of claim 3, wherein the number of rounds of the random sampling voting for the vote pass corresponding to the proposed block maintained by the target consensus node comprises: a first number representing the total number of rounds of random sampling voting with a voting result of pass corresponding to the proposed block; and a second number representing the number of rounds of consecutive random sampling voting with a voting result of pass corresponding to the proposed block; if the number of collected votes of approval corresponding to the proposed block reaches Quorum, updating the number of rounds of random sampling voting with a voting result of pass maintained for the proposed block comprises: If the number of collected votes in favor of the proposed block reaches the Quorum, update the first number maintained, and determine whether the number of collected votes in favor of the proposed block also reaches the Quorum in the last round of random sampling voting; if the number of collected votes in favor of the proposed block also reaches the Quorum in the last round of random sampling voting, further update the first number maintained; otherwise, restore the first number maintained to the initial value.
5. The method of claim 4, determining whether the number of rounds of random sampling voting with a voting result of pass reaches a preset threshold; if the number of rounds reaches the preset threshold, determining that the consensus for the proposed block is passed; otherwise, continuing the next round of random sampling voting until the number of rounds of random sampling voting with a voting result of pass reaches the preset threshold, including: determining whether the second number after the update reaches a first threshold; if the second number after the update reaches the first threshold, determining that the consensus for the proposed block is passed; if the second number after the update does not reach the first threshold, further determining whether the first number after the update reaches a preset second threshold; wherein the first threshold is less than the second threshold; if the first number after the update reaches the preset second threshold, determining that the consensus for the proposed block is passed; if the first number after the update does not reach the preset second threshold, continuing the next round of random sampling voting until the second number after the update reaches the first threshold; or, ending when the first number after the update reaches the second threshold.
6. The method of claim 4, the target consensus node maintains a set of conflict blocks corresponding to each round of consensus; in response to the received proposed block, iteratively performing multiple rounds of random sampling voting for the proposed block with other consensus nodes participating in the consensus, including: in response to receiving the multiple proposed blocks corresponding to the current round of consensus broadcast by the master node, adding the multiple proposed blocks to the set of conflict blocks, and determining a target proposed block preferred by the target consensus node from the set of conflict blocks; iteratively performing multiple rounds of random sampling voting for the target proposed block with other consensus nodes participating in the consensus.
7. The method of claim 6, determining the target proposed block preferred by the target consensus node from the set of conflict blocks; in the initial state, randomly selecting one proposed block from each proposed block in the set of conflict blocks as the target proposed block preferred by the target consensus node; and, after the end of any round of random sampling voting, further switching the proposed block with the highest maintained first number to the target proposed block preferred by the target consensus node.
8. The method of claim 7, further comprising: In any round of random sampling voting, if an inquiry message sent by another consensus node is received, it is determined whether the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node; If the proposed block contained in the inquiry message is the target proposed block preferred by the target consensus node, a first response message corresponding to the inquiry message is returned to the other consensus node; wherein the first response message contains an approval vote corresponding to the proposed block; If the proposed block contained in the inquiry message is not the target proposed block preferred by the target consensus node, a second response message corresponding to the inquiry message is returned to the other consensus node; wherein the second response message contains a non-approval vote corresponding to the proposed block.
9. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein, The processor executes the computer program to implement the steps of the method of any one of claims 1 to 8.
10. A computer program product comprising a computer program which, when executed by a processor, implements the steps of the method of any one of claims 1 to 8.