Disclosure of Invention
The invention aims to provide a method and a system for processing blockchain transactions, which can increase the transaction amount per second of a blockchain network and improve the transaction throughput of the blockchain network.
To solve the above technical problem, according to an aspect of the present invention, there is provided a blockchain transaction processing method applied to a node on a blockchain network, wherein the node has a main fragment and m sub-fragments; the method comprises the following steps: the main fragment divides a plurality of transactions to be processed into A transaction sets, and distributes the A transaction sets to m sub-fragments for processing; wherein, A and m are natural numbers larger than 0; the main fragment acquires a new sub-block generated by each sub-fragment, and blocks are packed according to each sub-block; the main fragment broadcasts the new block generated by packaging; and if the new block passes the verification in the block chain network, recording the new block as a valid block in each node of the block chain network.
An embodiment of the present invention further provides a blockchain transaction processing system, including: a main fragment and m sub-fragments; the main fragment is used for dividing a plurality of transactions to be processed into A transaction sets and distributing the A transaction sets to m sub-fragments for processing; wherein A and m are natural numbers greater than 0; the main fragment is used for acquiring the new sub-blocks generated by each sub-fragment and carrying out block packing according to each sub-block; the main fragment is used for broadcasting the new blocks generated by packaging; and if the new block passes the verification in the block chain network, recording the new block as a valid block in each node of the block chain network.
Compared with the prior art, the node in the block chain network comprises a main fragment and a plurality of sub-fragments, wherein the main fragment divides each transaction to be processed into A transaction sets, distributes the A divided transaction sets to the sub-fragments for processing, and then packs the blocks by the main fragment according to the new sub-blocks generated by the sub-fragments so as to facilitate the broadcasting and uplink of the subsequent new blocks. Therefore, the transaction to be processed is distributed by the aid of the main fragments, the transaction is processed by the aid of the sub fragments, the main fragments are used for overall planning of information and main network communication, parallel processing of the transaction is achieved, processing efficiency is improved, transaction amount per second of the block chain network is increased under the condition that consistency and reliability of the block chain are guaranteed, and transaction throughput of the block chain network is improved.
Optionally, a is equal to m, and a transaction sets are allocated to m subfragments for processing, specifically including: and distributing A transaction sets to m sub-fragments for processing. Therefore, the full utilization of the sub-fragments is realized, and the parallel processing efficiency of the transaction is high.
Optionally, after allocating a transaction sets to m sub-shards for processing, the method further includes: and if all the sub-blocks generated within the first preset time length do not correspond to all the transactions to be processed, the main fragment gives up all the transactions to be processed and generates an error log. Therefore, the condition that the node does not respond for a long time to cause resource waste is avoided, and technicians can be helped to perform troubleshooting in time.
Optionally, if the number of times that a sub-fragment generation sub-block exceeds the second preset duration exceeds a preset number of times, determining that the sub-fragment is faulty.
Optionally, the blockchain transaction processing method further includes: and if the main fragment is in fault, removing the main fragment, and selecting one sub fragment from the m sub fragments as a new main fragment. Therefore, a new sub-fragment is selected in time to replace the fault main fragment, the normal operation of the node can be ensured, and the condition of the node paralysis caused by the fault of the main fragment is avoided.
Optionally, if a subfragment fails, the subfragment is removed.
Optionally, the consensus algorithm of the main fragment and the m sub-fragments is the same, so that the consistency of the main fragment and each sub-fragment can be realized, and the stability of the node is effectively ensured.
Optionally, if a node is newly added in the blockchain network, the newly added node acquires and synchronizes the longest blockchain in the blockchain network.
According to another aspect of the present invention, there is provided a blockchain transaction processing apparatus, the apparatus including: a main fragmentation unit and m sub-fragmentation units; the main fragment unit is used for dividing a plurality of transactions to be processed into A transaction sets and distributing the A transaction sets to the m sub-fragment units for processing; wherein A and m are natural numbers greater than 0; the main fragment unit is used for acquiring the new sub-blocks generated by each sub-fragment unit and carrying out block packaging according to each sub-block; the main fragment unit is used for broadcasting the new blocks generated by packaging; and if the new block passes the verification in the block chain network, recording the new block as a valid block in each node of the block chain network.
Detailed Description
In order to make the technical solutions in the present specification better understood, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in one or more embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present description without inventive step, shall fall within the scope of protection of the claims of the present application.
First embodiment
A first embodiment of the invention relates to a method for processing blockchain transactions, and a specific flow is shown in fig. 1. The transaction processing method in this embodiment is applied to a node on a blockchain network, where the node has a main fragment and m sub-fragments, and m is a natural number greater than 0. The following describes a specific implementation of the blockchain transaction processing method in this embodiment, including the following steps:
step 101, the main fragment divides a plurality of transactions to be processed into A transaction sets, and allocates the A transaction sets to m sub-fragments for processing.
Specifically, the value of a may be preset by a technician and stored in the node. For example, a may be 3. As shown in fig. 2, n transactions to be processed are given, and the main fragment divides the n transactions to be processed into 3 shares, which are transaction sets from the 1 st transaction to the ith transaction [ the 1 st transaction to be processed, the ith transaction ], transaction sets from the i +1 th transaction to the jth transaction [ the i +1 th transaction to be processed, the jth transaction to be processed ], and transaction sets from the j +1 th transaction to the nth transaction [ the j +1 th transaction to be processed, the nth transaction to be processed ]. The i and j are natural numbers larger than 0, and the numerical values of the i and j can be preset by technicians, namely the numerical values of the i and j are fixed, and the main fragments can also be selected according to the number of the transactions to be processed divided according to actual needs. For example, assuming that the number of transactions to be processed is n, the master shard may set i to c according to a remainder algorithm n mod 3 to c; j is 2 c.
In this embodiment, the main shard may perform the partition of the transaction set according to the number of the sub-shards, i.e. let a be equal to m. Therefore, the main fragment can averagely distribute the A divided transaction sets to the m sub-fragments, so that the sub-fragments are fully utilized, and the parallel processing efficiency of subsequent transactions is improved. The value of m may be preset by a technician and stored in the node, or may be selected by the master fragment according to the number n of actual transactions to be processed. For example, the node prestores the corresponding relationship between the number interval of the to-be-processed transactions and the numerical value of m, so that the main fragment can set the corresponding number of sub-fragments according to the numerical value interval where the number n of the current to-be-processed transactions is located.
And 102, the main fragment acquires the new sub-blocks generated by each sub-fragment, and performs block packing according to each sub-block.
Specifically, each sub-fragment processes each transaction to be processed in the assigned transaction set, one or more sub-blocks are generated by packaging, the main fragment periodically acquires the hash value of each sub-block newly generated by each sub-fragment, and records the hash value in the newly generated block, thereby realizing packaging of one or more new blocks.
For example, taking the above n transactions to be processed divided into 3 parts, wherein one sub-fragment generates the sub-block 0, one sub-fragment generates thesub-block 1, and one sub-fragment generates the sub-block 3, the main fragment generates the new block 0 including the information of the sub-block 0, thesub-block 1, and thesub-block 2. For example, the hash values of sub-block 0,sub-block 1, andsub-block 2 may be recorded in block 0, as shown in fig. 3.
And 103, broadcasting the new block generated by packaging by the main fragment.
Specifically, the master fragment broadcasts the latest block formed by the packing, each node in the block chain network receives a new block, the new block is verified, if the verification is passed, the new block is recorded by each node as a valid block and is added into the block chain, and the block chain is continuously lengthened.
Compared with the prior art, the node in the block chain network comprises a main fragment and a plurality of sub-fragments, wherein the main fragment divides each transaction to be processed into A transaction sets, distributes the A divided transaction sets to the sub-fragments for processing, and then packs the blocks by the main fragment according to the new sub-blocks generated by the sub-fragments so as to facilitate the broadcasting and uplink of the subsequent new blocks. Therefore, the transaction to be processed is distributed by the aid of the main fragments, the transaction is processed by the aid of the sub fragments, the main fragments are used for overall planning of information and main network communication, parallel processing of the transaction is achieved, processing efficiency is improved, transaction amount per second of the block chain network is increased under the condition that consistency and reliability of the block chain are guaranteed, and transaction throughput of the block chain network is improved.
It should be noted that, because the blockchain network is a distributed network (as shown in fig. 4) composed of a plurality of nodes, each transaction can reach any node through the main network after being input and initiated by a certain node, that is, each node in the blockchain network can know the transaction for processing and calculation. Therefore, the node having the main shard and the m sub shards mentioned in this embodiment may be any node on the blockchain network (as shown in fig. 5). That is, each node on the blockchain network may have a master shard and m sub-shards.
If all nodes in the blockchain network include the child shards and the master shards, and all transactions in the nodes can be processed through theabove steps 101 to 103, the blockchain shown in fig. 6 occurs. That is, each block includes information of sub-blocks generated by sub-fragments in the node that packs the block, and each newly generated block includes information of the previous block. Therefore, even if a node is newly added in the block chain, the newly added node acquires and synchronizes the longest block chain, and information synchronization can be realized, so that the consistency of the block chain is ensured.
It is worth mentioning that the consensus algorithm of the main shard and each associated sub-shard in each node is the same, and the consensus algorithm of each main shard is the same, so that the main shards can communicate with each other, and the main shard can communicate with each associated sub-shard, thereby realizing parallel processing of transactions on the nodes and record synchronization of transactions on the block chain.
Second embodiment
The second embodiment of the invention relates to a block chain transaction processing method. The second embodiment of the invention is improved on the basis of the first embodiment, and the main improvement is that: in the second embodiment of the present invention, if all the sub-blocks generated within the first preset time length do not correspond to all the pending transactions, the master fragment abandons each pending transaction and generates an error log. Therefore, the condition that the node does not respond for a long time to cause resource waste is avoided, and technicians can be helped to perform troubleshooting in time. The following is specifically described:
specifically, the main fragment packs the new block after acquiring the sub-blocks generated by all the sub-fragments, so as to avoid the omission of transactions and ensure the consistency of the block chain. However, if a sub-fragment fails, the sub-fragment cannot generate sub-blocks periodically, which results in the situation that the main fragment does not pack new blocks and the node does not respond for a long time. Therefore, in order to improve the resource rate of the node and avoid the occurrence of the above situations, when all the sub-blocks generated within the first preset time length do not correspond to all the transactions to be processed, the main fragment gives up each transaction to be processed and generates an error log, so that a technician can perform troubleshooting in time. The first preset time duration may be equal to or longer than the time duration for the sub-fragment to generate the sub-block periodically.
More specifically, if the number of times that a sub-fragment generation sub-block exceeds the second preset time length exceeds a preset number of times, the sub-fragment is determined to be faulty. At this time, the main fragment may reflect the information of the subfragment in the error log so as to facilitate a technician to repair in time, or the main fragment may directly remove the subfragment so as to ensure normal operation of the node. The preset times may be preset by a technician, and the second preset time period may be equal to or slightly longer than the time period for the sub-fragment to generate the sub-block periodically. In addition, during actual operation, the second preset time duration may be set to be less than or equal to the first preset time duration.
It should be noted that if the main fragment fails, the main fragment may be removed, and one of the m sub-fragments may be selected as a new main fragment. Therefore, a new sub-fragment is selected in time to replace the fault main fragment, the normal operation of the node can be ensured, and the condition of the node paralysis caused by the fault of the main fragment is avoided.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
Third embodiment
A third embodiment of the present invention relates to a blockchain transaction processing system, including: a main fragment and m sub-fragments; wherein m is a natural number greater than 0. The main fragment is used for dividing a plurality of transactions to be processed into A transaction sets and distributing the A transaction sets to m sub-fragments for processing; wherein n is a natural number greater than 0. The main fragment is used for obtaining the sub-blocks newly generated by each sub-fragment and carrying out block packing according to each sub-block. The master shard is used to broadcast the new tiles generated by the packetization. And if the new block passes the verification in the block chain network, recording the new block as a valid block in each node of the block chain network.
Specifically, the value of a may be preset by a technician and stored in the node. For example, a may be 3. As shown in fig. 2, n transactions to be processed are given, and the main fragment divides the n transactions to be processed into 3 shares, which are transaction sets from the 1 st transaction to the ith transaction [ the 1 st transaction to be processed, the ith transaction ], transaction sets from the i +1 th transaction to the jth transaction [ the i +1 th transaction to be processed, the jth transaction to be processed ], and transaction sets from the j +1 th transaction to the nth transaction [ the j +1 th transaction to be processed, the nth transaction to be processed ]. The i and j are natural numbers larger than 0, and the numerical values of the i and j can be preset by technicians, namely the numerical values of the i and j are fixed, and the main fragments can also be selected according to the number of the transactions to be processed divided according to actual needs. For example, assuming that the number of transactions to be processed is n, the master shard may set i to c according to a remainder algorithm n mod 3 to c; j is 2 c.
In this embodiment, the main shard may perform the partition of the transaction set according to the number of the sub-shards, i.e. let a be equal to m. Therefore, the main fragment can averagely distribute the A divided transaction sets to the m sub-fragments, so that the sub-fragments are fully utilized, and the parallel processing efficiency of subsequent transactions is improved. The value of m may be preset by a technician and stored in the node, or may be selected by the master fragment according to the number n of actual transactions to be processed. For example, the node prestores the corresponding relationship between the number interval of the to-be-processed transactions and the numerical value of m, so that the main fragment can set the corresponding number of sub-fragments according to the numerical value interval where the number n of the current to-be-processed transactions is located.
Specifically, each sub-fragment processes each transaction to be processed in the assigned transaction set, one or more sub-blocks are generated by packaging, the main fragment periodically acquires the hash value of each sub-block newly generated by each sub-fragment, and records the hash value in the newly generated block, thereby realizing packaging of one or more new blocks.
For example, taking the above n transactions to be processed divided into 3 parts, wherein one sub-fragment generates the sub-block 0, one sub-fragment generates thesub-block 1, and one sub-fragment generates the sub-block 3, the main fragment generates the new block 0 including the information of the sub-block 0, thesub-block 1, and thesub-block 2. For example, the hash values of sub-block 0,sub-block 1, andsub-block 2 may be recorded in block 0.
Specifically, the master fragment broadcasts the latest block formed by the packing, each node in the block chain network receives a new block, the new block is verified, if the verification is passed, the new block is recorded by each node as a valid block and is added into the block chain, and the block chain is continuously lengthened.
More specifically, since the blockchain network is a distributed network composed of a plurality of nodes, each transaction can reach any node through the main network after being input and initiated through a certain node, that is, each node in the blockchain network can acquire the transaction for processing and calculation. Therefore, the blockchain transaction processing system mentioned in this embodiment can be understood as any node on the blockchain network. That is, each node on the blockchain network may have a master shard and m sub-shards.
It should be understood that the present embodiment is a system embodiment corresponding to the first embodiment, and the present embodiment can be implemented in cooperation with the first embodiment. The related technical details mentioned in the first embodiment are still valid in this embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the first embodiment.
Fourth embodiment
A fourth embodiment of the invention is directed to a blockchain transaction processing system. The fourth embodiment is improved on the basis of the third embodiment, and the main improvement lies in that: in the fourth embodiment of the present invention, if all the sub-blocks generated within the first preset time period do not correspond to all the transactions to be processed, the master fragment is further configured to abandon each transaction to be processed and generate an error log. Therefore, the condition that the node does not respond for a long time to cause resource waste is avoided, and technicians can be helped to perform troubleshooting in time.
It should be understood that the present embodiment is a system embodiment corresponding to the second embodiment, and the present embodiment and the second embodiment can be implemented in cooperation. The related technical details mentioned in the second embodiment are still valid in this embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the second embodiment.
Fifth embodiment
A fifth embodiment of the present invention provides a blockchain transaction processing apparatus, including: a main fragmentation unit and m sub-fragmentation units. The main fragment unit is used for dividing a plurality of transactions to be processed into A transaction sets and distributing the A transaction sets to the m sub-fragment units for processing; wherein A and m are natural numbers greater than 0; the main fragment unit is used for acquiring the new sub-blocks generated by each sub-fragment unit and carrying out block packaging according to each sub-block; the main fragment unit is used for broadcasting the new blocks generated by packaging; and if the new block passes the verification in the block chain network, recording the new block as a valid block in each node of the block chain network.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.