Disclosure of Invention
In view of the above, the present invention provides a fragmentation method and device based on an ordered balanced binary tree, which are used to solve the problem that in the prior art, as the number of nodes in a blockchain system increases, the time required for achieving global consensus also increases continuously, resulting in great challenges on the throughput of the whole blockchain system, and the specific scheme is as follows:
a fragmentation method based on an ordered balanced binary tree comprises the following steps:
when a request of a target node for joining a target network is received, judging whether the target node is a first node of the target network;
if not, sending the request to each node in a target block chain of the target network, and receiving the response of each node to the request, wherein each node in the target block chain forms a target balanced binary tree;
and determining a target subtree node of the target balanced binary tree according to the response, and adding the target node into the target subtree node.
The above method, optionally, further includes:
if the target node is the head node of the target network, constructing the target block chain according to the target node;
initializing the target block chain.
The above method, optionally, further includes:
judging whether the binary tree balanced with the target is unbalanced;
and if so, determining a minimum imbalance sub-tree in the target balanced binary tree, and adjusting the target balanced binary tree according to the minimum imbalance sub-tree.
Optionally, in the above method, determining a target subtree node of the target balanced binary tree according to the response, and adding the target node to the target subtree node includes:
determining the network distance between the target node and each subtree in the target balanced binary tree according to the response;
and selecting the shortest network distance from the network distances, wherein the subtree node corresponding to the shortest network distance is the target subtree node.
The above method, optionally, further includes:
when detecting that any node leaves the target block chain, judging whether the any node is a leaf node;
if yes, directly leaving, or;
if not, selecting the node with the highest height from the left sub-tree and the right sub-tree corresponding to the arbitrary node in sequence to replace the arbitrary node, or;
and if the heights of the left subtree and the right subtree corresponding to the arbitrary node are equal, selecting the left subtree corresponding to the arbitrary node by default.
The above method, optionally, further includes:
when the nodes of both trading parties in the target block chain trade, acquiring the positions of the nodes of both trading parties in the target balanced binary tree;
determining the minimum public father node of the nodes of the two transaction parties according to the position;
and after consensus is completed according to the minimum public father node, broadcasting the generated target block by the root node of the partition corresponding to the trading bilateral node.
The above method, optionally, further includes:
and distributing a weighting factor for each node in the target block chain.
A slicing device based on ordered balanced binary tree includes:
the first judgment module is used for judging whether a target node is a first node of a target network or not when a request of the target node for joining the target network is received;
a sending and receiving module, configured to send the request to each node in a target block chain of the target network if the node in the target block chain is not in the target network, and receive a response of each node to the request, where each node in the target block chain forms a target balanced binary tree;
and the determining and adding module is used for determining a target subtree node of the target balanced binary tree according to the response and adding the target node into the target subtree node.
The above apparatus, optionally, further comprises:
the second judgment module is used for judging whether the binary tree is unbalanced with the target balance;
and if so, determining a minimum imbalance sub-tree in the target balanced binary tree, and adjusting the target balanced binary tree according to the minimum imbalance sub-tree.
The above apparatus, optionally, the determining and joining module includes:
a first determining unit, configured to determine, according to the response, a network distance between the target node and each sub-tree in the target balanced binary tree;
and the second determining unit is used for selecting the shortest network distance from the network distances, and the subtree node corresponding to the shortest network distance is the target subtree node.
Compared with the prior art, the invention has the following advantages:
the invention discloses a fragmentation method based on an ordered balanced binary tree, which comprises the following steps: when a request of a target node for joining a target network is received, judging whether the target node is a first node of the target network; if not, sending the request to each node in a target block chain of the target network, and receiving the response of each node to the request, wherein each node in the target block chain forms a target balanced binary tree; and determining a target subtree node of the target balanced binary tree according to the response, and adding the target node into the target subtree node. The fragmentation method enables all nodes in the target block chain to form the target balanced binary tree, all the fragments can process transactions in parallel, and the fragmentation technology can improve the concurrency of transaction processing and confirmation, so that the throughput of the target block chain can be improved.
Of course, it is not necessary for any product in which the invention is practiced to achieve all of the above-described advantages at the same time.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The invention discloses a fragmentation method based on an ordered balanced binary tree, which is applied to the field of a block chain, wherein along with the increase of the number of nodes in the block chain, the time required for achieving consensus is also increased continuously, so that the throughput of a block chain system is influenced. The verifier only needs to verify one part of the network transaction, the workload is distributed on each sub-slice, and the slicing technology can improve the concurrency of transaction processing and confirmation, so that the throughput of the whole system is improved. The execution flow of the slicing method is shown in fig. 1, and includes the steps of:
s101, when a request of a target node for joining a target network is received, judging whether the target node is a first node of the target network;
in this embodiment of the present invention, the target node is a node currently requesting to join a target network, and whether the target node is a head node of the target network is determined by an identifier fed back by the target network, where the identifier may be an electrical signal, a number, or another identifier, for example, when the target network feeds back a high level, the target node is determined to be the head node of the target network, and when the target network feeds back a low level, the target node is determined not to be the head node of the target network, where a specific form of the identifier is not limited in this embodiment of the present invention.
S102, sending the request to each node in a target block chain of the target network, and receiving the response of each node to the request, wherein each node in the target block chain forms a target balanced binary tree;
in this embodiment of the present invention, when the target node is not the first node of the target network, a target block chain corresponding to the target network is obtained, where each node in the target block chain exists in a target balanced binary tree, and each node exists in a form of a root node, a subtree node, or a leaf node in the target balanced binary tree, where any subtree node may be used as an independent partition. Each node receives the request and then responds to the request, wherein the response may be a reply message.
S103, determining a target subtree node of the target balanced binary tree according to the response, and adding the target node into the target subtree node.
In the embodiment of the present invention, initially, the height difference of the target balanced binary tree needs to be set to 1, and the network distance between the target node and each node is determined according to the time for receiving the response. That is, the faster the reply message of a node is received, the closer the network distance to the node is, the shortest network distance is selected from the network distances, the subtree node corresponding to the shortest network distance is the target subtree node, and the target node is added to the target subtree node.
The invention discloses a fragmentation method based on an ordered balanced binary tree, which comprises the following steps: when a request of a target node for joining a target network is received, judging whether the target node is a first node of the target network; if not, sending the request to each node in a target block chain of the target network, and receiving the response of each node to the request, wherein each node in the target block chain forms a target balanced binary tree; and determining a target subtree node of the target balanced binary tree according to the response, and adding the target node into the target subtree node. The fragmentation method enables all nodes in the target block chain to form the target balanced binary tree, all the fragments can process transactions in parallel, and the fragmentation technology can improve the concurrency of transaction processing and confirmation, so that the throughput of the target block chain can be improved.
S104, initializing the target network.
In this embodiment of the present invention, when the target node is a head node of the target network, the target network needs to be initialized, including:
s11, creating a primary account, and initiating a transaction by the primary account;
and S12, creating a creating block. Starting a target block chain, a first block needs to be created, namely an ancestry block, and some basic settings need to be configured in the ancestry block:
and the independent block chain network id is used when other nodes are connected, and the nodes of different id networks cannot be connected with each other.
The mining difficulty degree determines the block-out efficiency according to the mining difficulty degree, the mining difficulty degree can be configured according to business requirements, the business requirements determine the data output efficiency, and the mining difficulty degree can be configured according to the data output efficiency required in business
Balance of primary account, initialization phase, balance of primary account
The generation of each block requires an upper limit on the resources consumed. The generation of each tile requires the consumption of a certain number of tokens.
S13, initializing the target block chain, making a local directory stored by the related data of the block chain, binding the initial account with the miners, and starting to dig the mine.
In this embodiment of the present invention, when the target node is added to the target balanced binary tree, it needs to determine whether the target balanced binary tree is unbalanced, and a flowchart of a determination process is as follows:
s201, judging whether the height of a left sub-tree and a right sub-tree in a path from the target node in the target balanced binary tree to a root node in the target balanced binary tree is greater than 2 sub-trees or not;
s202, determining a minimum unbalanced sub-tree in the target balanced binary tree;
in the embodiment of the present invention, if the minimum unbalanced sub-tree exists, the minimum unbalanced sub-tree is a sub-tree that uses the target node as a starting point, the minimum unbalanced sub-tree is searched upwards in the target balanced binary tree, and a sub-tree that uses a node whose absolute value of a first balancing factor exceeds 1 as a root is used as the minimum unbalanced sub-tree, where the balancing factor is a difference between a height of a left sub-tree and a height of a right sub-tree, values of the balancing factors are only 0, 1, -1, and correspond to the left and right sub-trees, respectively, which are equal in height, the left.
S203, adjusting the target balanced binary tree according to the minimum unbalanced subtree.
In the embodiment of the present invention, when the left sub-tree is high, the method includes:
a) LL type
In an LL-type unbalanced binary tree, the smallest unbalanced subtree is found first, then the root node of the subtree is rotated to the right, and after the tree height of the subtree on the right is increased by 1, and the tree height of the subtree on the left is decreased by 1, and the difference of the original tree heights is, then the balance factor of the root can be reduced to 0. After the rotation, the left child of the original root node is taken as a new root node.
Rotating the unbalanced binary tree to the right, centered on the root node, is shown in fig. 3-1. The rotating steps are as follows
i. Using 2 as a root node
ii. Right child with 3 as 2
iii, the right child of 2 is taken as the left child of 3 (maintain the order of the tree, just here NULL already)
b) LR type
For LR, the spinning is performed in two steps, as shown in FIG. 3-2. The rotation is followed by "the right child of the left child of the original root node is taken as the new root node".
The first rotates to the left centered on the root of the higher subtree, i.e. 1. The method comprises the following specific steps.
i. The left sub-tree of 2 is taken as the right sub-tree of 1 (maintain the ordering of the tree, only NULL here)
ii. Left subtree with 1 as 2
iii left subtree with 2 as 3
The second is to rotate to the right, centered on the root of the original tree, i.e. 3. After the rotation, the balance factor of 1,2,3 becomes 0.
When the right subtree is high, the method comprises the following steps:
a) RR type
A schematic view of the rotation is shown in fig. 3-3, with the following steps. After rotation, the new root node is the right child of the original root node.
i. Using 2 as a root node
ii. Left child with 1 as 2
iii, the left child of 2 is taken as the right child of 1 (maintain the order of the tree, just NULL here)
b) RL type
Similar to the LR type, we need to make two rotations, which are schematically shown in fig. 3-4, and the rotation is followed by "the left child of the right child of the original root node is taken as the new root node".
First, the right child of the root node, i.e., 3, is rotated to the right. The method comprises the following specific steps
i. Right child with 2 as 1
ii. Right child with 3 as 2
iii, the right child of 2 is taken as the left child of 3 (maintain the order of the tree, just here NULL already)
Second, the primitive root node, i.e., 1, is used as the center, rotating to the left. The method comprises the following specific steps
i. Using 2 as a root node
ii. Left child with 1 as 2
iii, the left child of 2 is taken as the right child of 1 (maintain the order of the tree, just NULL here)
In the embodiment of the present invention, a node may be added to the target block chain, and a node in the target block chain may also leave the target block chain, when it is detected that any node in the target block chain leaves the target block chain, it is determined whether the any node is a leaf node, if so, the node directly leaves, if not, a node with the highest height is selected from left and right subtrees corresponding to the any node in sequence to replace the any node, and if the heights of the left and right subtrees corresponding to the any node are equal, a left subtree corresponding to the any node is selected by default.
In the embodiment of the present invention, the target block chain is suitable for performing a transaction between nodes, and a transaction process is shown in fig. 4 and includes the steps of:
s301, when nodes of both trading parties in the target block chain carry out trading, acquiring positions of the nodes of both trading parties in the target balanced binary tree;
in the embodiment of the present invention, when nodes of both trading parties in the target block chain perform a trade, the nodes of both trading parties may be located in the same partition or in different partitions, and the position may be a root node, a sub-tree node, or a leaf node.
S302, determining a minimum public father node of the nodes of both parties of the transaction according to the position;
in the embodiment of the invention, the minimum public father node is that the left sub-tree and the right sub-tree of the node respectively comprise two nodes, and the two nodes are respectively positioned in different sub-trees, so that the sub-tree node to which the node belongs is determined according to the nodes of both transaction sides, and the minimum public father node is searched upwards layer by layer according to the sub-tree nodes.
And S303, completing consensus according to the minimum public father node, and broadcasting the generated target block by the root node of the partition corresponding to the trading bilateral node after the consensus is completed.
In the embodiment of the present invention, a partition where the minimum common parent node is located is determined, and consensus is completed in the partition, which is implemented by a POW consensus mechanism in the embodiment of the present invention, and a workload certification process of a POW includes:
and S21, generating a merkle root hash. That is, any node in the target block chain generates a transaction, and generates a Merkle root hash with all other transactions to be packed by a Merkle tree algorithm, and the process of generating the Merkle root hash is as follows:
at the lowest level of the target block chain, as with the hash list, the data is divided into small data blocks with corresponding hashes and their correspondences. But going up, instead of directly operating the root hash, two adjacent hashes are combined into a string, and then the hash of the string is operated, so that every two hashes are married to obtain a 'sub-hash'. If the total number of the hash at the bottom layer is singular, a single hash must be generated at last, and the situation is that the hash operation is directly carried out on the hash, so that the sub-hash can be obtained. Therefore, pushing up is still the same way, a smaller number of new first-level hashes can be obtained, and finally an inverted tree must be formed, and a Merkle root hash is left at the position of the tree root.
And S22, assembling a block head. The block head is used as an input parameter for calculating the workload certification output, so that the Merkle root hash calculated in the first step and other components of the block head are assembled into the block head
S23 output of calculation workload certification
Output of workload certification-SHA 256(SHA256 (block header))
if (output of workload proof < target value), prove workload completion
if (output of workload certification > is the target value), the random number is changed, the logic of i is recursed, and the comparison with the target value is continued. The target value may be defined empirically or in specific situations, and a value of the target value is not limited in the embodiment of the present invention.
S24, the node that completes the workload certification can submit the block to the target block chain and inform other nodes in the target network, and when more than half of the other nodes authenticate that the block is the block with the fastest generation efficiency, the block is authenticated as a formal block.
Furthermore, as the height of the node is higher, the consensus process that the node needs to participate in is more, and the excitation obtained by the node participating in the consensus needs to be weighted by a weighting factor positively correlated with the height of the node, that is, the excitation obtained by the node is the normal excitation (1+ the height of the node is 0.1).
In the embodiment of the invention, the network fragmentation technology can improve the concurrency of transaction processing and transaction confirmation, thereby improving the throughput of the whole block chain network. Based on the ordered balanced binary tree, the nodes with similar network distances can be ensured to be positioned in the same partition as much as possible, and the cost brought by the network is reduced, so that the efficiency of the consensus mechanism can be further improved; on the other hand, the characteristic that the balanced binary tree is automatically adjusted to be balanced can ensure that the balanced structure of the binary tree is stabilized at a certain level, thereby reducing the influence of the change of the number of nodes on the performance of the blockchain network and reducing the cost of manually maintaining the blockchain network.
Based on the above fragmentation method based on the ordered balanced binary tree, an embodiment of the present invention further provides a fragmentation device based on the ordered balanced binary tree, where a structural block diagram of the fragmentation device is shown in fig. 5, and the fragmentation device includes:
a first judgment module 401, a sending and receiving module 402 and a determining and joining module 403.
Wherein the content of the first and second substances,
the first determining module 401 is configured to determine, when a request for a target node to join a target network is received, whether the target node is a first node of the target network;
the sending and receiving module 402 is configured to send the request to each node in a target block chain of the target network if the target block chain is not the target block chain, and receive a response of each node to the request, where each node in the target block chain forms a target balanced binary tree;
the determining and adding module 403 is configured to determine a target subtree node of the target balanced binary tree according to the response, and add the target node to the target subtree node.
The invention discloses a slicing device based on an ordered balanced binary tree, which comprises: when a request of a target node for joining a target network is received, judging whether the target node is a first node of the target network; if not, sending the request to each node in a target block chain of the target network, and receiving the response of each node to the request, wherein each node in the target block chain forms a target balanced binary tree; and determining a target subtree node of the target balanced binary tree according to the response, and adding the target node into the target subtree node. The above-mentioned slicing device makes up every node in the said target block chain into the said target balanced binary tree, every slicing can process the trade in parallel, slicing technology can improve the concurrency of trade processing and confirming, and then can improve the throughput of the said target block chain.
In this embodiment of the present invention, the slicing apparatus further includes:
a second decision block 404 and a determination and adjustment block 405.
Wherein the content of the first and second substances,
the second judging module 404 is configured to judge whether the binary tree balanced with the target is unbalanced;
the determining and adjusting module 405 is configured to determine a minimum imbalance sub-tree in the target binary balanced tree and adjust the target binary balanced tree according to the minimum imbalance sub-tree if yes.
In this embodiment of the present invention, the determining and joining module 405 includes:
a first determination unit 406 and a second determination unit 407.
Wherein the content of the first and second substances,
the first determining unit 406 is configured to determine, according to the response, network distances between the target node and each sub-tree in the target balanced binary tree;
the second determining unit 407 is configured to select a shortest network distance from the network distances, where a sub-tree node corresponding to the shortest network distance is the target sub-tree node.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functions of the units may be implemented in the same software and/or hardware or in a plurality of software and/or hardware when implementing the invention.
From the above description of the embodiments, it is clear to those skilled in the art that the present invention can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
The fragmentation method and device based on the ordered balanced binary tree provided by the invention are introduced in detail, specific examples are applied in the text to explain the principle and the implementation mode of the invention, and the description of the above embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.