Disclosure of Invention
The present invention provides a method, an apparatus, a device and a readable storage medium for performing a blockchain transaction, and aims to solve the technical problem that the performance of the conventional method for improving the performance of blockchain transaction simply by improving the parallelism may be reduced due to excessive parallelism.
In order to achieve the above object, the present invention provides a method for performing a blockchain service transaction, where the method is applied to a consensus node in a federation chain, and the method includes the following steps:
collecting first equipment information of a node and reporting the first equipment information as first information to a transaction and submitting the first equipment information;
recording the first equipment information in an intelligent contract according to the submitted first information reporting transaction, and broadcasting the first information reporting transaction to other consensus nodes in the alliance chain;
receiving second information reporting transactions broadcasted by other common identification nodes, and recording second equipment information of other common identification nodes in the second information reporting transactions in the intelligent contract;
calculating to obtain parallelism according to the equipment information of each consensus node recorded in the intelligent contract, and recording the parallelism in the intelligent contract;
and when the business transaction in the target block is executed, starting a plurality of threads according to the parallelism degree recorded in the intelligent contract to execute all the business transactions in the target block in parallel.
Optionally, the step of calculating the parallelism according to the device information of each consensus node recorded in the intelligent contract includes:
calculating to obtain a performance index value of the ith consensus node according to the equipment information of the ith consensus node recorded in the intelligent contract;
sorting the performance index values of all the consensus nodes in a descending order, and selecting the minimum performance index value in the front n-f individual performance index values, wherein n is the number of the consensus nodes in the alliance chain, and 3f +1 is n;
and calculating to obtain the parallelism according to the minimum performance index value.
Optionally, the device information of the ith consensus node includes the number of CPUs and the CPU frequency of the ith consensus node;
the step of calculating the performance index value of the ith consensus node according to the device information of the ith consensus node recorded in the intelligent contract comprises the following steps:
multiplying the number of CPUs of the ith consensus node recorded in the intelligent contract by the CPU frequency to obtain a first performance index value of the ith consensus node;
taking the number of CPUs of the ith consensus node recorded in the intelligent contract as a second performance index value of the ith consensus node;
the step of selecting the minimum performance index value in the front n-f individual performance index values after sorting the performance index values of all the consensus nodes from big to small comprises the following steps:
sorting the first performance index values of all the consensus nodes according to a descending order, and selecting the minimum first performance index value of the first n-f first performance index values;
sorting the second performance index values of all the consensus nodes according to a descending order, and selecting the minimum second performance index value of the first n-f second performance index values;
the step of calculating the parallelism according to the minimum performance index value comprises the following steps:
and dividing the minimum first performance index value by the minimum second performance index value, and rounding to obtain the parallelism.
Optionally, the step of starting multiple threads according to the parallelism recorded in the intelligent contract to execute the business transactions in the target block in parallel includes:
dividing each business transaction in the target block to obtain a plurality of transaction sets, wherein one transaction set comprises at least one business transaction, and the number of the transaction sets is the same as the parallelism degree recorded in the intelligent contract;
and respectively starting a thread aiming at each transaction set, and executing the corresponding transaction sets in parallel through each thread, wherein each thread executes each service transaction in the corresponding transaction set respectively according to a serial mode.
Optionally, the step of dividing each service transaction in the target block into a plurality of transaction sets includes:
for any target business transaction in the target block, performing modulus operation on the index of the target business transaction in the target block according to the parallelism degree recorded in the intelligent contract to obtain a modulus operation result;
determining a target sub-account number corresponding to the target business transaction according to the modulus taking result, and taking a transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction when the target business transaction is executed;
and constructing each business transaction corresponding to the same sub-account number into a transaction set.
Optionally, the step of performing the target business transaction comprises:
detecting whether a transfer sub-account number corresponding to the target sub-account number exists or not through the intelligent contract;
if the transaction number exists, the transfer sub-account number corresponding to the target sub-account number is used as a collection account number of the target business transaction for transaction execution;
and if the target business transaction does not exist, establishing a transfer sub-account number as the transfer sub-account number corresponding to the target sub-account number through the intelligent contract, and performing transaction execution by taking the transfer sub-account number corresponding to the target sub-account number as a receiving account number of the target business transaction.
Optionally, the step of broadcasting the first information reporting transaction to other respective consensus nodes in the federation chain includes:
signing the first information reporting transaction by adopting a private key of the node, and broadcasting the signed first information reporting transaction to other consensus nodes in the alliance chain;
the step of recording the second information reported to the second device information of other common nodes in the transaction in the intelligent contract includes:
and performing signature verification on the signed second information reporting transaction by adopting the public keys of other common identification nodes, and recording the second equipment information of other common identification nodes in the second information reporting transaction in the intelligent contract when the signature verification is passed.
In order to achieve the above object, the present invention further provides a device for performing blockchain business transaction, where the device is deployed at a consensus node in a federation chain, and the device includes:
the information collection module is used for collecting first equipment information of the node and reporting the first equipment information as first information to a transaction and submitting the first equipment information;
the contract module is used for recording the first equipment information in an intelligent contract according to the submitted first information reporting transaction and broadcasting the first information reporting transaction to other common nodes in the alliance chain;
the contract module is further configured to receive second information report transactions broadcast by other respective consensus nodes, and record second device information of the other respective consensus nodes in the second information report transactions in the intelligent contract;
the contract module is also used for calculating the parallelism according to the equipment information of each consensus node recorded in the intelligent contract and recording the parallelism in the intelligent contract;
and the parallel execution module is used for starting a plurality of threads to execute all the business transactions in the target block in parallel according to the parallelism degree recorded in the intelligent contract when the business transactions in the target block are executed.
In order to achieve the above object, the present invention further provides a device for performing blockchain service transaction, where the device for performing blockchain service transaction includes: the system comprises a memory, a processor and a blockchain business transaction execution program stored on the memory and capable of running on the processor, wherein the blockchain business transaction execution program realizes the steps of the blockchain business transaction execution method when being executed by the processor.
In addition, to achieve the above object, the present invention further provides a computer readable storage medium, which stores a blockchain business transaction execution program, and when the blockchain business transaction execution program is executed by a processor, the blockchain business transaction execution program implements the steps of the blockchain business transaction execution method as described above.
In the invention, the device information of the node is collected by the consensus nodes and submitted as the information reporting transaction, the device information is recorded in the intelligent contract according to the submitted information reporting transaction, and the information reporting transaction is broadcasted to other consensus nodes in the alliance chain; receiving information reporting transactions broadcasted by other consensus nodes, and recording the equipment information of other consensus nodes in the information reporting transactions in the intelligent contract; calculating to obtain parallelism according to the equipment information of each consensus node recorded in the intelligent contract, and recording the parallelism in the intelligent contract; and when the business transaction in the target block is executed, starting a plurality of threads to execute each business transaction in the target block in parallel according to the parallelism degree recorded in the intelligent contract. The invention calculates the parallelism according to the equipment information of each consensus node, and executes each service transaction in parallel according to the calculated parallelism, thereby comprehensively considering the overall calculation resource condition of each consensus node in the alliance chain and avoiding the condition of performance reduction caused by excessive parallelism due to simple improvement of the parallelism.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Abbreviations and key term definitions:
intelligent contract: and the system is deployed on a block chain to complete a section of program with a specific function. The program is executed by all nodes on the blockchain, and consistency of program execution results is ensured through a consensus algorithm. Such as transfer contracts, enable the user's account balance to be recorded on the blockchain, and provide a relevant transfer and query interface.
Trading: and the operation request initiated by the user calls the intelligent contract. The transaction is sent to the blockchain for invoking an interface on the intelligent contract to trigger execution of the intelligent contract code.
Block: in the unit of batch processing of transaction, a plurality of transactions are packed into a block to form a batch and are executed by nodes, and the nodes agree execution results by taking the block execution as rhythm.
API: an Application Programming Interface (also known as an Application Programming Interface, a foreign language name) is called API for short, and is a convention for linking different components of a software system.
PBFT is an abbreviation for Practical Byzantine Fault Tolerance, namely: a practical byzantine fault-tolerant algorithm.
And (3) executing in parallel: on a multi-core machine, a plurality of tasks are processed in the same time period, and the execution performance can be improved.
As shown in fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
It should be noted that, in the embodiment of the present invention, the blockchain service transaction execution device may be a consensus node in a federation chain, and is not limited herein.
As shown in fig. 1, the blockchain business transaction executing apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the device shown in fig. 1 does not constitute a limitation of a blockchain business transaction execution device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, the memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a blockchain service transaction execution program. The operating system is a program that manages and controls the hardware and software resources of the device, supporting the execution of the blockchain business transaction execution program, as well as other software or programs. In the device shown in fig. 1, the user interface 1003 is mainly used for data communication with a client; the network interface 1004 is mainly used for establishing communication connection with a server; and the processor 1001 may be configured to call the blockchain business transaction execution program stored in the memory 1005, and perform the following operations:
collecting first equipment information of a node and reporting the first equipment information as first information to a transaction and submitting the first equipment information;
recording the first equipment information in an intelligent contract according to the submitted first information reporting transaction, and broadcasting the first information reporting transaction to other consensus nodes in the alliance chain;
receiving second information reporting transactions broadcasted by other common identification nodes, and recording second equipment information of other common identification nodes in the second information reporting transactions in the intelligent contract;
calculating to obtain parallelism according to the equipment information of each consensus node recorded in the intelligent contract, and recording the parallelism in the intelligent contract;
and when the business transaction in the target block is executed, starting a plurality of threads according to the parallelism degree recorded in the intelligent contract to execute all the business transactions in the target block in parallel.
Further, the operation of calculating the parallelism according to the device information of each consensus node recorded in the intelligent contract includes:
calculating to obtain a performance index value of the ith consensus node according to the equipment information of the ith consensus node recorded in the intelligent contract;
sorting the performance index values of all the consensus nodes in a descending order, and selecting the minimum performance index value in the front n-f individual performance index values, wherein n is the number of the consensus nodes in the alliance chain, and 3f +1 is n;
and calculating to obtain the parallelism according to the minimum performance index value.
Further, the device information of the ith consensus node includes the number of CPUs and the CPU frequency of the ith consensus node;
the operation of calculating the performance index value of the ith consensus node according to the device information of the ith consensus node recorded in the intelligent contract comprises:
multiplying the number of CPUs of the ith consensus node recorded in the intelligent contract by the CPU frequency to obtain a first performance index value of the ith consensus node;
taking the number of CPUs of the ith consensus node recorded in the intelligent contract as a second performance index value of the ith consensus node;
the operation of selecting the minimum performance index value in the front n-f individual performance index values after the performance index values of the common identification nodes are sorted from big to small comprises the following steps:
sorting the first performance index values of all the consensus nodes according to a descending order, and selecting the minimum first performance index value of the first n-f first performance index values;
sorting the second performance index values of all the consensus nodes according to a descending order, and selecting the minimum second performance index value of the first n-f second performance index values;
the operation of calculating the parallelism according to the minimum performance index value comprises the following steps:
and dividing the minimum first performance index value by the minimum second performance index value, and rounding to obtain the parallelism.
Further, the operation of starting a plurality of threads to execute the business transactions in the target block in parallel according to the parallelism recorded in the intelligent contract comprises:
dividing each business transaction in the target block to obtain a plurality of transaction sets, wherein one transaction set comprises at least one business transaction, and the number of the transaction sets is the same as the parallelism degree recorded in the intelligent contract;
and respectively starting a thread aiming at each transaction set, and executing the corresponding transaction sets in parallel through each thread, wherein each thread executes each service transaction in the corresponding transaction set respectively according to a serial mode.
Further, the operation of dividing each service transaction in the target block into a plurality of transaction sets includes:
for any target business transaction in the target block, performing modulus operation on the index of the target business transaction in the target block according to the parallelism degree recorded in the intelligent contract to obtain a modulus operation result;
determining a target sub-account number corresponding to the target business transaction according to the modulus taking result, and taking a transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction when the target business transaction is executed;
and constructing each business transaction corresponding to the same sub-account number into a transaction set.
Further, the operation of executing the target business transaction comprises:
detecting whether a transfer sub-account number corresponding to the target sub-account number exists or not through the intelligent contract;
if the transaction number exists, the transfer sub-account number corresponding to the target sub-account number is used as a collection account number of the target business transaction for transaction execution;
and if the target business transaction does not exist, establishing a transfer sub-account number as the transfer sub-account number corresponding to the target sub-account number through the intelligent contract, and performing transaction execution by taking the transfer sub-account number corresponding to the target sub-account number as a receiving account number of the target business transaction.
Further, the operation of broadcasting the first information reporting transaction to other respective consensus nodes in the federation chain includes:
signing the first information reporting transaction by adopting a private key of the node, and broadcasting the signed first information reporting transaction to other consensus nodes in the alliance chain;
the operation of recording the second information reported to the second device information of other common nodes in the transaction in the intelligent contract includes:
and performing signature verification on the signed second information reporting transaction by adopting the public keys of other common identification nodes, and recording the second equipment information of other common identification nodes in the second information reporting transaction in the intelligent contract when the signature verification is passed.
Based on the above structure, various embodiments of a block chain service transaction execution method are provided.
Referring to fig. 2, fig. 2 is a flowchart illustrating a method for performing a blockchain transaction according to a first embodiment of the present invention.
While a logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in an order different than that shown or described herein. In this embodiment, the execution subject of the blockchain service transaction execution method may be a consensus node in a federation chain, and each of the consensus nodes respectively executes the blockchain service transaction execution method according to this embodiment. The method comprises the following steps:
step S10, collecting the first device information of the node and reporting the first device information as the first information to the transaction submission;
in this embodiment, considering that the consensus like PBFT is generally adopted in the federation chain, the consensus range is determined, the performance of the chain is determined by the participating nodes, and the performance improvement of a single node does not necessarily bring the overall performance improvement, but needs to consider the performance of all the consensus nodes to determine the parallelism together. Therefore, in order to solve the technical problem that the performance of the existing method for improving the performance of block chain transaction execution by simply improving the parallelism may be reduced due to excessive parallelism, the embodiment provides a method for performing transaction execution by cooperating the full-chain consensus nodes of the alliance chain with the calculated parallelism, and reasonably allocates the parallel rows, so as to achieve the purposes of reasonably using the resources of each node in the chain and improving the performance of chain transaction execution.
The common node collects device information of the node (hereinafter, the device information of the node is referred to as first device information to distinguish it from device information of other common nodes). The device information may include information related to hardware computing resources of the node, for example, the number of CPUs, the CPU frequency, and the like, which is not limited in this embodiment.
The consensus node submits the first device information of the node as a transaction, the transaction is specially used for reporting the device information and is different from the service transaction submitted by a client in a service scene, so that the transaction is called an information reporting transaction for distinguishing, and the information reporting transaction submitted by the node is called the first information reporting transaction to distinguish the information reporting transactions of other consensus nodes. The first information is submitted to the node. The first device information collected from the node may be collected through an API provided by the operating system, which is not limited herein.
It can be understood that other common nodes also perform the method for performing the blockchain service transaction according to the embodiment, so that the device information of each common node is collected and submitted as an information reporting transaction, and the device information and the information reporting transaction of the other common nodes are hereinafter referred to as a second device information and a second information reporting transaction respectively for distinguishing.
Step S20, recording the first device information in an intelligent contract according to the submitted first information reporting transaction, and broadcasting the first information reporting transaction to other consensus nodes in the alliance chain;
in this embodiment, by using this characteristic, the first device information of the node is submitted to the node as the first information reporting transaction by the consensus node, and after receiving the first information reporting transaction, the node broadcasts the first information reporting transaction to each of the other consensus nodes in the alliance chain. It can be understood that other common nodes also perform the method for performing the blockchain service transaction of the embodiment, so that other nodes also report respective second information to the transaction for broadcasting.
After receiving the submitted first information reporting transaction, the consensus node also records the first equipment information in the first information reporting transaction in the intelligent contract for subsequent use.
Step S30, receiving second information report transactions broadcast by each other consensus node, and recording second device information of each other consensus node in the second information report transactions in the intelligent contract;
the consensus nodes respectively receive second information reporting transactions broadcasted by other consensus nodes, respectively extract second equipment information of other consensus nodes from each second information reporting transaction, and record each second equipment information in the intelligent contract. For example, if the federation chain has four consensus nodes, each consensus node records its first device information and second device information of three other consensus nodes in the intelligent contract of the node, that is, each consensus node records four device information in the intelligent contract of the node, and the device information in the intelligent contract of each consensus node is consistent.
Step S40, calculating the parallelism according to the device information of each consensus node recorded in the intelligent contract, and recording the parallelism in the intelligent contract;
after the consensus nodes record the equipment information of each consensus node in the intelligent contract, the parallelism can be calculated according to the equipment information of each consensus node. Specifically, the device computing resource condition of each node can be considered according to the device information computing parallelism of each consensus node, and the reasonable parallelism is determined, so that resource occupation competition caused by excessive parallelism and performance reduction caused by high resource switching cost are avoided.
In an embodiment, the parallelism that can be supported by the device of each consensus node under the condition of reasonably utilizing hardware resources can be determined according to the device information of each consensus node, and the minimum parallelism can be selected from the parallelism as the calculated parallelism.
After the consensus node calculates the parallelism, the parallelism can be recorded in the intelligent contract, so that the business transaction can be executed in parallel according to the parallelism extracted from the intelligent contract subsequently.
It should be noted that, since the methods for calculating the parallelism by the respective consensus nodes according to the respective device information are the same, the parallelism calculated by the respective consensus nodes is the same, and the parallelism recorded in the respective intelligent contracts is also the same.
Step S50, when executing the business transaction in the target block, starting multiple threads according to the parallelism recorded in the intelligent contract to execute each business transaction in the target block in parallel.
One consensus node in the alliance chain is used as a packing node, a plurality of service transactions are packed in a transaction pool to obtain a block, the block is broadcasted to other consensus nodes, and each consensus node executes each service transaction in the block. When the consensus node executes the business transaction in a certain block (hereinafter referred to as a target block for distinction), a plurality of threads can be started to execute each business transaction in parallel according to the parallelism degree recorded in the intelligent contract. The number of the started threads is the same as the parallelism, so that the parallel execution of each service transaction according to the parallelism is realized. It should be noted that conflict-free transactions in each service transaction may be executed in parallel by using different threads, so as to avoid conflicts when executing each service transaction in parallel. And the threads can sequentially execute the business transactions according to a serial mode.
In an embodiment, when the device information of the consensus node is updated, the device information of the consensus node may be collected and reported again to update the device information of the consensus node in the intelligent contract, and the new parallelism is recalculated according to the updated device information in the intelligent contract, and the parallel execution of the service transaction is performed according to the new parallelism.
In an embodiment, as shown in fig. 3, the consensus node may include an information collection module, a contract module, and a parallel execution module, where the consensus node collects the first device information of the node through the information collection module, and submits the first device information as the first information reporting transaction to the contract module. The information collection module can use the first device information as a parameter to construct a calling transaction of an information collection function of the contract module, so that the first device information is reported as first information and the transaction is submitted to the contract module. After the consensus node submits the first information reporting transaction to the contract module through the information collection module, the contract module broadcasts the first information reporting transaction to other consensus nodes, the contract module receives second information reporting transactions broadcasted by other consensus nodes, and second equipment information in the second information reporting transaction is recorded in the intelligent contract. The consensus nodes can calculate the parallelism according to the equipment information of each consensus node recorded in the intelligent contract through the contract module, and the parallelism is recorded in the intelligent contract. The consensus node can read the parallelism degree recorded in the intelligent contract through the parallel execution module and execute the business transaction according to the parallelism degree.
In this embodiment, the consensus node collects the device information of the node and submits the device information as an information reporting transaction, records the device information in the intelligent contract according to the submitted information reporting transaction, and broadcasts the information reporting transaction to other consensus nodes in the alliance chain; receiving information reporting transactions broadcasted by other consensus nodes, and recording the equipment information of other consensus nodes in the information reporting transactions in the intelligent contract; calculating to obtain parallelism according to the equipment information of each consensus node recorded in the intelligent contract, and recording the parallelism in the intelligent contract; and when the business transaction in the target block is executed, starting a plurality of threads to execute each business transaction in the target block in parallel according to the parallelism degree recorded in the intelligent contract. In the embodiment, the parallelism is calculated according to the equipment information of each consensus node, and each service transaction is executed in parallel according to the calculated parallelism, so that the overall calculation resource condition of each consensus node in the alliance chain is comprehensively considered, the condition that the performance is reduced due to excessive parallelism caused by simply improving the parallelism is avoided, and the storage consumption is also prevented from being increased by times due to simply improving the parallelism. And the collected equipment information is submitted as an information reporting transaction to broadcast the information reporting transaction to other consensus nodes, the equipment information is recorded in an intelligent contract, and the consistency of the parallelism calculation of each consensus node is realized by utilizing the characteristics of the intelligent contract, so that the consistency of the transaction execution performance improvement of each consensus node is ensured.
Further, in an embodiment, the step of broadcasting the first information reporting transaction to other respective consensus nodes in the federation chain in the step S20 includes:
step S201, signing the first information reporting transaction by using a private key of the node, and broadcasting the signed first information reporting transaction to other common nodes in the alliance chain;
after receiving the first information reporting transaction submitted by the node, the consensus node may first sign the first information reporting transaction by using the private key of the node, and then broadcast the signed first information reporting transaction to other consensus nodes. The method for signing the first information reporting transaction by adopting the private key specifically comprises the steps of calculating a summary of the first information reporting transaction by adopting a summary algorithm, and encrypting the summary by adopting the private key to obtain a digital signature; the step of broadcasting the signed first information reporting transaction to other consensus nodes is to broadcast the digital signature and the first information reporting transaction to each consensus node.
The common identification node can send the public key of the node to each other common identification node in advance, so that after each other common identification node receives the signed first information report transaction, the public key is adopted to perform signature verification on the signed first information report transaction, and after the signature verification is passed, the first device information in the first information report transaction is recorded in each intelligent contract.
The step of recording the second information reported by the step S30 to the second device information of each other consensus node in the transaction in the intelligent contract includes:
step S301, performing signature verification on the signed second information report transaction by using the public keys of other common identification nodes, and recording the second device information of other common identification nodes in the second information report transaction in the intelligent contract when the signature verification is passed.
After receiving the signed second information report transaction broadcasted by each of the other consensus nodes, the consensus node can firstly verify the signature of the signed second information report transaction, and when the signature is verified, the consensus node shows that the second information report transaction is really sent by the other consensus nodes, and at the moment, the second device information in the second information report transaction is recorded in the intelligent contract of the node.
And when the node performs signature verification on the signed second information report transaction, the public key corresponding to the consensus node is firstly adopted to decrypt the digital signature in the signed second information report transaction, then the received second information report transaction adopts the same abstract algorithm to calculate an abstract, the abstract is compared with a decrypted result, if the result is consistent, the signature verification is determined to be passed, and otherwise, the signature verification is determined not to be passed.
In one embodiment, if the received second information reporting transaction is not signed and verified by the consensus node, the transaction may be discarded.
Further, based on the first embodiment, a second embodiment of the method for executing blockchain business transactions according to the present invention is provided, in this embodiment, the step of calculating the parallelism according to the device information of each consensus node recorded in the intelligent contract in step S40 includes:
step S401, calculating to obtain a performance index value of the ith consensus node according to the equipment information of the ith consensus node recorded in the intelligent contract;
in view of the fact that there may be fault-caused downtime or attacked common-knowledge nodes in each common-knowledge node of the federation chain, in order to ensure that joint calculation of the parallelism can be completed even when some common-knowledge nodes are downtime or attacked, in this embodiment, a parallelism calculation method is provided.
Specifically, after the device information of each consensus node is recorded in the intelligent contract, the performance index value of the ith consensus node may be calculated according to the device information of the ith consensus node recorded in the intelligent contract. The performance index value may be one or more, for example, the number of CPUs may be used as the performance index value, and is not limited in this embodiment.
Step S402, after the performance index values of the consensus nodes are sorted from big to small, the minimum performance index value of the front n-f individual performance index values is selected, wherein n is the number of the consensus nodes in the alliance chain, and 3f +1 is equal to n;
after the consensus nodes calculate the performance index values of the consensus nodes, the performance index values of the consensus nodes can be sorted from large to small, and the minimum performance index value (hereinafter referred to as the minimum performance index value) in the top n-f ("-" represents a minus sign) individual performance index values is selected. n is the number of common identification nodes in the alliance chain, f is the number of the tolerant down nodes, and 3f +1 is n according to the principle of the Byzantine common identification algorithm.
And step S403, calculating to obtain the parallelism according to the minimum performance index value.
And the consensus node can calculate the parallelism according to the selected minimum performance index value. Specifically, the specific way of calculating the parallelism according to the minimum performance index value is not limited in this embodiment. For example, in one embodiment, if the minimum performance index value is the number of CPUs, the consensus node may directly use the minimum performance index value as the parallelism.
The performance index values of the common recognition nodes are sequenced from large to small, the minimum performance index value in the top n-f performance index values is selected, the parallelism is calculated according to the minimum performance index value, the parallelism is calculated under the condition that f common recognition nodes are down, and the consistent parallelism can still be calculated under the condition that no more than f common recognition nodes are down.
Further, in an embodiment, the step S401 includes:
step S4011, multiplying the number of CPUs of the ith consensus node recorded in the intelligent contract by the CPU frequency to obtain a first performance index value of the ith consensus node;
step S4012, the number of CPUs of the ith consensus node recorded in the intelligent contract is used as a second performance index value of the ith consensus node;
since the number of CPUs and the CPU frequency of each piece of consensus node device jointly determine the computational performance of the node, in this embodiment, to further improve the rationality of the parallelism computation, the device information of the ith consensus node may include the number of CPUs and the CPU frequency of the ith consensus node. That is, the consensus node may collect the number of CPUs and the CPU frequency of the node as information reporting transactions for submission.
In calculating the performance index value of the ith consensus node, two performance index values may be calculated. Specifically, the consensus node may multiply the number of CPUs of the ith consensus node recorded in the intelligent contract by the CPU frequency to obtain a performance index value of the ith consensus node (hereinafter, referred to as a first performance index value to distinguish). The consensus node also takes the number of CPUs of the ith consensus node recorded in the intelligent contract as another performance index value (hereinafter referred to as a second performance index value for distinction) of the ith consensus node. Namely, two performance index values corresponding to each consensus node are calculated.
The step S402 includes:
step S4021, sorting the first performance index values of the consensus nodes in descending order, and selecting the minimum first performance index value of the first n-f performance index values;
step S4022, sorting the second performance index values of the consensus nodes in descending order, and selecting the smallest second performance index value of the first n-f second performance index values;
after the first performance index values of the respective consensus nodes are obtained through calculation, the consensus nodes may sort the respective first performance index values in a descending order, and then select the smallest first performance index value (hereinafter referred to as the smallest first performance index value) from the first n-f first performance index values. After the second performance index values of the respective consensus nodes are obtained through calculation, the consensus nodes may sort the respective second performance index values in a descending order, and then select the smallest second performance index value (hereinafter referred to as the smallest second performance index value) from the top n-f second performance index values.
The step S403 includes:
step S4031 is performed to divide the minimum first performance index value by the minimum second performance index value and then round the result to obtain a parallelism.
After the consensus node calculates the minimum first performance index value and the minimum second performance index value, the minimum first performance index value may be divided by the minimum second performance index value, and the result may be rounded off to obtain the parallelism. For example, if Zmin is used to represent the minimum first performance index value and CPUmin is used to represent the minimum second performance index value, then the parallelism P is rounded (Zmin/CPUmin).
The parallelism calculated by the method in this embodiment is a reasonable parallelism calculated by comprehensively considering resource conditions of the respective consensus node devices, so that on one hand, performance of performing block chain transaction is improved, and on the other hand, storage space is saved.
For example, taking a scenario of 1W to 1 account transfer, and a federation chain of 4 consensus nodes as an example, the following is followed
The data in table 1 were machine configured and tested:
TABLE 1
The test results and trade performance comparison data are shown in table 2 below:
TABLE 2
From table 2, it can be known that the parallel scheme is better than the non-parallel scheme, and the transaction performance is lower than that of the scheme of the embodiment of the present invention due to the fact that the high parallel scheme has many more thread switches.
The storage performance comparison data is shown in table 3 below:
TABLE 3
According to the formula of rounding (Zmin/CPUmin), the parallelism P can be calculated to be 6, and as can be seen from the data in table 3, the non-parallel storage performance is the highest in the aspect of storage performance, and the scheme of the embodiment of the present invention is the second and the highest in the aspect of highly parallel.
Further, based on the first and/or second embodiments, a third embodiment of the method for performing blockchain business transaction according to the present invention is provided, in this embodiment, the step S50 includes:
step S501, dividing each business transaction in the target block to obtain a plurality of transaction sets, wherein one transaction set comprises at least one business transaction, and the number of the transaction sets is the same as the parallelism degree recorded in the intelligent contract;
in this embodiment, when the consensus node executes the service transaction in the target block, each service transaction in the target block may be divided to obtain a plurality of transaction sets, where one transaction set includes at least one service transaction, and the number of the transaction sets is the same as the parallelism recorded in the intelligent contract. The method for dividing the business transaction into transaction sets is not limited in this embodiment.
In some embodiments, when it is required to ensure that the transaction sets obtained by dividing the common nodes are the same, a dividing method may be preset, so that the transaction sets obtained by dividing the service transactions in the target block by the common nodes are the same. For example, in an embodiment, the number of the service transactions in the target block may be divided by the parallelism in the smart contract and rounded up to obtain the transaction number in each transaction set, and the service transactions arranged in sequence in the target block may be divided according to the transaction number to obtain a plurality of transaction sets. It is understood that the transaction sets partitioned by the method are the same for each consensus node. For another example, in another embodiment, the indexes of the business transactions in the target block may be modulo according to the parallelism in the smart contract, and the transactions of the same modulo result may be divided into one transaction set. It is understood that the transaction sets partitioned by the consensus nodes according to the method are also the same.
Step S502, respectively starting a thread for each transaction set, and executing the corresponding transaction set in parallel through each thread, wherein each thread executes each service transaction in the corresponding transaction set in a serial manner.
And respectively starting one thread aiming at each transaction set, namely starting m threads when m transaction sets exist, and executing the corresponding transaction sets in parallel through each thread, namely executing the jth transaction set by the jth thread, wherein the m threads are executed in parallel. And each thread executes each service transaction in the corresponding transaction set respectively according to a serial mode, namely, the jth thread executes each service transaction in the jth transaction set in a serial mode.
Further, in an embodiment, the step S501 includes:
step S5011, for any target business transaction in the target blocks, modulo the index of the target business transaction in the target blocks according to the parallelism degree recorded in the intelligent contract to obtain a modulo result;
in a many-to-one transfer scenario, when the collection account numbers of all business transactions in a target block are the same account number, the collection account numbers of all business transactions can be distinguished by adding the collection account numbers, so that conflict-free transactions are constructed, and conflicts caused by parallel execution are avoided.
Specifically, for any one service transaction in the target block (hereinafter referred to as a target service transaction for distinction), the consensus node may perform modulo on an index of the target service transaction in the target block according to the parallelism degree recorded in the intelligent contract, and an obtained result is referred to as a modulo result.
Step S5012, determining a target sub-account number corresponding to the target business transaction according to the modulus taking result, and using a transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction when the target business transaction is executed;
and the common identification node determines a sub-account number (hereinafter referred to as a target sub-account number) corresponding to the target service transaction according to the modulus result. The intelligent contract management method comprises the steps that a plurality of transfer sub-account numbers can be set in an intelligent contract in advance to serve as collection account numbers, and each transfer sub-account number can be numbered to distinguish each sub-account number. It should be noted that, since the intelligent contracts of the respective consensus nodes are the same, the respective transfer sub-account numbers and the corresponding numbers set in the intelligent contracts of the respective consensus nodes are also the same.
When the number of each transfer sub-account number is from 0, the consensus node can directly take the modulus result as the number of the target sub-account number; when the number of each transfer sub-account number is from 1, the consensus node may add 1 to the modulo result as the number of the target sub-account number. That is, the number of the target sub-account is determined based on the modulo result according to the different numbering modes of the transfer sub-accounts.
The consensus node determines that the target sub-account number corresponding to the target business transaction aims to take the transfer sub-account number corresponding to the target sub-account number as the collection account number of the target business transaction when the target business transaction is executed, so that the collection account numbers of the transactions needing to be executed in parallel are distinguished, and the occurrence of conflict during the transaction is avoided.
Step S5013, constructing each business transaction corresponding to the same sub-account number as a transaction set.
After determining the sub-account numbers respectively corresponding to the business transactions in the target block, the consensus node may construct the business transactions corresponding to the same sub-account number into a transaction set, that is, the business transactions corresponding to the same sub-account number need to be executed serially, and the business transactions corresponding to different sub-account numbers can be executed in parallel.
Further, in one embodiment, the step of performing the targeted business transaction includes:
step a, detecting whether a transfer sub-account number corresponding to the target sub-account number exists or not through the intelligent contract;
when executing each business transaction in the target block, the consensus node can firstly judge whether the corresponding transfer sub-account exists through an intelligent contract, and if not, the consensus node can be dynamically established.
Specifically, one of the business transactions (target business transaction) is taken as an example for explanation. The consensus node can detect whether the transfer sub-account number corresponding to the target service transaction exists or not through the intelligent contract, namely, whether the transfer sub-account number corresponding to the number exists or not is determined. For example, five transfer sub-account numbers are created in the intelligent contract of the consensus node in advance, the numbers are 0-4, the parallelism is 6, and if the index of the target service transaction is modulo 6 to obtain 5, that is, the number of the target sub-account number is 5, the consensus node detects that no transfer sub-account number with the number of 5 exists when detecting that the transfer sub-account number corresponding to the number of the target sub-account number exists, and then determines that the transfer sub-account number corresponding to the number of the target sub-account number does not exist.
B, if the account number exists, performing transaction execution by taking the transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction;
if the transfer sub-account number corresponding to the target sub-account number is detected to exist, the consensus node can directly perform transaction execution by taking the transfer sub-account number as a collection account number of the target business transaction.
And c, if the target business transaction does not exist, establishing a transfer sub-account number as the transfer sub-account number corresponding to the target sub-account number through the intelligent contract, and performing transaction execution by taking the transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction.
And if the transfer sub-account number corresponding to the target sub-account number does not exist, the consensus node can establish a transfer sub-account number through an intelligent contract, and the newly established transfer sub-account number is used as a receiving account number of the target business transaction for transaction execution. It should be noted that the intelligent contracts of the respective consensus nodes are the same, so that the transfer sub-account numbers created by the intelligent contracts received by the respective consensus nodes are also the same, thereby ensuring that the execution results of the respective business transactions in the target block by the respective consensus nodes are consistent.
In addition, an embodiment of the present invention further provides a device for performing blockchain service transaction, where, referring to fig. 4, the device is deployed at a consensus node in a federation chain, and the device includes:
the information collection module 10 is configured to collect first device information of a local node and report the first device information as first information to a transaction and submit the first device information;
a contract module 20, configured to record the first device information in an intelligent contract according to the submitted first information reporting transaction, and broadcast the first information reporting transaction to other consensus nodes in the federation chain;
the contract module 20 is further configured to receive second information report transactions broadcast by other respective consensus nodes, and record second device information of the other respective consensus nodes in the second information report transactions in the intelligent contract;
the contract module 20 is further configured to calculate a parallelism according to the device information of each consensus node recorded in the intelligent contract, and record the parallelism in the intelligent contract;
and the parallel execution module 30 is configured to, when executing a business transaction in a target block, start a plurality of threads according to the parallelism recorded in the intelligent contract to execute each business transaction in the target block in parallel.
Further, the contract module 20 is further configured to:
calculating to obtain a performance index value of the ith consensus node according to the equipment information of the ith consensus node recorded in the intelligent contract;
sorting the performance index values of all the consensus nodes in a descending order, and selecting the minimum performance index value in the front n-f individual performance index values, wherein n is the number of the consensus nodes in the alliance chain, and 3f +1 is n;
and calculating to obtain the parallelism according to the minimum performance index value.
Further, the device information of the ith consensus node includes the number of CPUs and the CPU frequency of the ith consensus node;
the contract module 20 is further configured to:
multiplying the number of CPUs of the ith consensus node recorded in the intelligent contract by the CPU frequency to obtain a first performance index value of the ith consensus node;
taking the number of CPUs of the ith consensus node recorded in the intelligent contract as a second performance index value of the ith consensus node;
sorting the first performance index values of all the consensus nodes according to a descending order, and selecting the minimum first performance index value of the first n-f first performance index values;
sorting the second performance index values of all the consensus nodes according to a descending order, and selecting the minimum second performance index value of the first n-f second performance index values;
and dividing the minimum first performance index value by the minimum second performance index value, and rounding to obtain the parallelism.
Further, the parallel execution module 30 is further configured to:
dividing each business transaction in the target block to obtain a plurality of transaction sets, wherein one transaction set comprises at least one business transaction, and the number of the transaction sets is the same as the parallelism degree recorded in the intelligent contract;
and respectively starting a thread aiming at each transaction set, and executing the corresponding transaction sets in parallel through each thread, wherein each thread executes each service transaction in the corresponding transaction set respectively according to a serial mode.
Further, the parallel execution module 30 is further configured to:
for any target business transaction in the target block, performing modulus operation on the index of the target business transaction in the target block according to the parallelism degree recorded in the intelligent contract to obtain a modulus operation result;
determining a target sub-account number corresponding to the target business transaction according to the modulus taking result, and taking a transfer sub-account number corresponding to the target sub-account number as a collection account number of the target business transaction when the target business transaction is executed;
and constructing each business transaction corresponding to the same sub-account number into a transaction set.
Further, the parallel execution module 30 is further configured to:
detecting whether a transfer sub-account number corresponding to the target sub-account number exists or not through the intelligent contract;
if the transaction number exists, the transfer sub-account number corresponding to the target sub-account number is used as a collection account number of the target business transaction for transaction execution;
and if the target business transaction does not exist, establishing a transfer sub-account number as the transfer sub-account number corresponding to the target sub-account number through the intelligent contract, and performing transaction execution by taking the transfer sub-account number corresponding to the target sub-account number as a receiving account number of the target business transaction.
Further, the contract module 20 is further configured to:
signing the first information reporting transaction by adopting a private key of the node, and broadcasting the signed first information reporting transaction to other consensus nodes in the alliance chain;
the step of recording the second information reported to the second device information of other common nodes in the transaction in the intelligent contract includes:
and performing signature verification on the signed second information reporting transaction by adopting the public keys of other common identification nodes, and recording the second equipment information of other common identification nodes in the second information reporting transaction in the intelligent contract when the signature verification is passed.
The expanded content of the specific implementation of the blockchain business transaction execution of the present invention is basically the same as that of each embodiment of the blockchain business transaction execution, and is not described herein again.
In addition, an embodiment of the present invention further provides a computer-readable storage medium, where the storage medium stores a blockchain service transaction execution program, and the blockchain service transaction execution program, when executed by a processor, implements the steps of the blockchain service transaction execution method described in the above embodiments.
The embodiments of the device for performing a blockchain service transaction and the computer-readable storage medium of the present invention can refer to the embodiments of the method for performing a blockchain service transaction of the present invention, and are not described herein again.
It should be noted that, in this document, 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 like elements in a process, method, article, or apparatus that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.