Smart contract transaction processing method, device and system
By concurrently pre-execute multiple transactions of smart contracts and classified processing according to conflict conditions, the problem of low transaction execution efficiency caused by the correlation of multiple transactions in smart contracts is solved, and efficient and accurate transaction execution is achieved.
Patent Information
- Application Number
- CN202411135447.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-08-19
AI Technical Summary
There is a strong correlation between multiple transactions in a smart contract, which leads to low transaction execution efficiency and is difficult to meet actual needs.
By concurrently pre-execute multiple transactions of smart contracts, obtain their respective read and write sets, and classify transactions according to conflicting conditions. The read and write sets of non-conflict transactions are stored directly on the blockchain, and the conflicting transactions are pre-execute concurrently and processed cyclically until the read and write sets of all transactions are stored.
The concurrent execution of multiple related transactions is realized, which improves the efficiency of transaction execution and ensures the accuracy of transactions.
Smart Images

Figure CN118657616B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of blockchain technology, and in particular to a transaction processing method, device and system for smart contracts. Background Art
[0002] In the related technology, since there are usually multiple transactions in a smart contract and there is a strong correlation between the multiple transactions, it is necessary to execute different transactions in sequence according to the correlation between the transactions to ensure the accuracy of transaction execution. However, the efficiency of executing transactions in this way is low and it is difficult to meet actual needs. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a transaction processing method, device and system for a smart contract.
[0004] According to a first aspect of an embodiment of the present disclosure, a transaction processing method for a smart contract is provided, comprising:
[0005] Concurrently pre-execute multiple first transactions of the smart contract to obtain read-write sets corresponding to each of the multiple first transactions; the read-write set includes the first key value read and / or the second key value written when the corresponding first transaction is pre-executed;
[0006] According to the first key value and / or the second key value, obtaining conflicting transactions and non-conflicting transactions from the multiple first transactions based on a first conflict condition, wherein the conflicting transaction includes a first transaction that satisfies the first conflict condition among the multiple first transactions, and the non-conflicting transaction includes remaining first transactions among the multiple first transactions except the conflicting transaction;
[0007] According to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transaction, the read-write set corresponding to the non-conflicting transaction is stored in the blockchain;
[0008] The blockchain state of the blockchain is updated, and concurrent pre-execution operations are performed on the conflicting transactions, and transaction conflicts are classified according to the results of the concurrent pre-execution operations, and read-write sets corresponding to non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, and the concurrent pre-execution operations are cyclically performed on the remaining conflicting transactions when the third preset condition is met, and transaction conflicts are classified according to the results of the concurrent pre-execution operations, and the read-write sets corresponding to non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, until the read-write sets of each of the multiple first transactions are stored in the blockchain.
[0009] According to a second aspect of an embodiment of the present disclosure, there is provided a transaction processing device for a smart contract, comprising:
[0010] A pre-execution unit includes a plurality of first transactions of concurrently pre-executing a smart contract, and obtains a read-write set corresponding to each of the plurality of first transactions; the read-write set includes a first key value read and / or a second key value written during the pre-execution of the corresponding first transaction;
[0011] an acquiring unit, comprising acquiring conflicting transactions and non-conflicting transactions from the plurality of first transactions based on a first conflict condition according to the first key value and / or the second key value, wherein the conflicting transaction includes a first transaction that satisfies the first conflict condition among the plurality of first transactions, and the non-conflicting transaction includes remaining first transactions among the plurality of first transactions except the conflicting transaction;
[0012] A first storage unit, comprising storing a read-write set corresponding to the non-conflicting transaction in a blockchain according to a first key value read and / or a second key value written during pre-execution of the non-conflicting transaction;
[0013] The second storage unit includes the steps of updating the blockchain state of the blockchain, performing a concurrent pre-execution operation on the conflicting transaction, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, updating the blockchain state of the blockchain, and cyclically executing the concurrent pre-execution operation on the remaining conflicting transactions when a third preset condition is met, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, and updating the blockchain state of the blockchain, until the read-write sets of each of the multiple first transactions are stored in the blockchain.
[0014] According to a third aspect of an embodiment of the present disclosure, an electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method described in any one of the first aspects is implemented.
[0015] According to a fourth aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method according to any one of the first aspects is implemented.
[0016] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising a computer program, wherein the computer program implements the method as described in any one of the first aspects when executed by a processor.
[0017] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: obtaining read-write sets corresponding to each of the multiple first transactions by concurrently pre-executing multiple first transactions of a smart contract, obtaining conflicting transactions and non-conflicting transactions from the multiple first transactions based on the first conflict condition according to the first key value and / or the second key value, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transactions, updating the blockchain state of the blockchain, performing concurrent pre-execution operations on the conflicting transactions, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, updating the blockchain state of the blockchain, and cyclically performing concurrent pre-execution operations on the remaining conflicting transactions, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, and updating the blockchain state of the blockchain, until the read-write sets of each of the multiple first transactions are stored in the blockchain, thereby enabling the concurrent execution of multiple associated transactions, while ensuring the accuracy of transaction execution and improving the efficiency of transaction execution.
[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0020] Figure 1 The present invention is a flowchart of a transaction processing method of a smart contract according to an exemplary embodiment.
[0021] Figure 2 It is a flow chart of another smart contract transaction processing method according to an exemplary embodiment.
[0022] Figure 3 It is a flowchart of another smart contract transaction processing method according to an exemplary embodiment.
[0023] Figure 4 It is a directed graph proposed in an embodiment of the present disclosure.
[0024] Figure 5 It is another directed graph shown in the embodiment of the present disclosure.
[0025] Figure 6 It is a block diagram of a transaction processing device for a smart contract according to an exemplary embodiment.
[0026] Figure 7It is a block diagram of a device for transaction processing of a smart contract according to an exemplary embodiment. DETAILED DESCRIPTION
[0027] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0028] The terms used in the disclosed embodiments are only for the purpose of describing specific embodiments, and are not intended to limit the disclosed embodiments. The singular forms "a", "an" and "the" used in the disclosed embodiments and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0029] It should be understood that although the terms first, second, third, etc. may be used to describe various information in the disclosed embodiments, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the disclosed embodiments, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein may be interpreted as "at" or "when" or "in response to determination".
[0030] In addition, various forms of processes shown in the embodiments of the present disclosure may be used to reorder, add or delete steps. For example, the steps described in the present application may be performed in parallel, sequentially or in different orders, as long as the desired results of the technical solution disclosed in the present disclosure can be achieved, and this document does not limit this.
[0031] In the related technology, since there are usually multiple transactions in a smart contract and there is a strong correlation between the multiple transactions, it is necessary to execute different transactions in sequence according to the correlation between the transactions to ensure the accuracy of transaction execution. However, the efficiency of executing transactions in this way is low and it is difficult to meet actual needs.
[0032] In order to solve the above problems, the present disclosure provides a transaction processing method, device and system for a smart contract, which obtains read-write sets corresponding to each of the multiple first transactions by concurrently pre-executing multiple first transactions of the smart contract, obtains conflicting transactions and non-conflicting transactions from the multiple first transactions based on a first conflict condition according to a first key value and / or a second key value, stores the read-write sets corresponding to the non-conflicting transactions in a blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transactions, updates the blockchain state of the blockchain, performs concurrent pre-execution operations on the conflicting transactions, classifies the transaction conflicts according to the concurrent pre-execution operation results, stores the read-write sets corresponding to the non-conflicting transactions in the blockchain, updates the blockchain state of the blockchain, and cyclically performs concurrent pre-execution operations on the remaining conflicting transactions, classifies the transaction conflicts according to the concurrent pre-execution operation results, stores the read-write sets corresponding to the non-conflicting transactions in the blockchain, and updates the blockchain state of the blockchain, until the read-write sets of each of the multiple first transactions are stored in the blockchain, thereby enabling multiple associated transactions to be executed concurrently, while ensuring the accuracy of transaction execution and improving the efficiency of transaction execution.
[0033] Figure 1 is a flow chart of a transaction processing method of a smart contract according to an exemplary embodiment. Figure 1 As shown, it should be noted that the transaction processing method of the smart contract of the embodiment of the present disclosure is applied to the transaction processing device of the smart contract. Figure 1 As shown, the method may include the following steps:
[0034] Step 101, concurrently pre-execute multiple first transactions of the smart contract to obtain read-write sets corresponding to each of the multiple first transactions.
[0035] The read-write set includes the first key value read and / or the second key value written during the pre-execution of the corresponding first transaction.
[0036] It should be noted that smart contract transactions (referred to as transactions) are the units of program execution on the blockchain. After the transaction is executed according to the steps specified in the smart contract, the transaction will generate a read-write set for the blockchain state. The read-write set is divided into a read set and a write set, and their format is a "key-value pair", that is, (key=..., value=...). After the read-write set is generated, it is stored in the cache and is written into the blockchain state only after the read-write set is applied.
[0037] In addition, applying a read-write set refers to the operation of writing the key-value pairs in the write set into the blockchain state.
[0038] In addition, the above-mentioned pre-execution can refer to the process of running a smart contract without recording the results of the operation, that is, not writing the above-mentioned read-write set into the blockchain for the time being. A complete execution process includes executing transactions and recording the execution results; but pre-execution is only a smart execution transaction.
[0039] In one embodiment, multiple first transactions of the smart contract are pre-executed concurrently to obtain read-write sets corresponding to each of the multiple first transactions, thereby obtaining the first key value read and / or the second key value written when each first transaction is pre-executed.
[0040] Step 102: acquiring conflicting transactions and non-conflicting transactions from a plurality of first transactions based on a first conflict condition according to the first key value and / or the second key value.
[0041] The conflicting transaction includes a first transaction that satisfies a first conflicting condition among the multiple first transactions, and the non-conflicting transaction includes the remaining first transactions among the multiple first transactions except the conflicting transaction.
[0042] It should be noted that since there are associations between multiple first transactions, read-write conflicts may occur if multiple first transactions are executed at the same time. Read-write conflicts refer to the situation where two or more transactions read and write data of the same key at the same time during the concurrent execution of transactions. Read-write conflicts usually cause transactions to be re-executed. Specifically, for two transactions Ti and Tj, if Ti reads the key key and Tj writes the same key, and the key value read is different from the key value written, and Tj precedes Ti in order, then it is called a read-write conflict, because Tj writes the key first, so the value read by Ti is changed, so the read-write set of Ti cannot be applied, and Ti needs to be re-executed.
[0043] In one embodiment, according to the first key value and / or the second key value, conflicting transactions are obtained from multiple first transactions based on the first conflict condition, and other transactions in the multiple first transactions except the conflicting transaction are non-conflicting transactions.
[0044] Step 103: store the read-write set corresponding to the non-conflicting transaction in the blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transaction.
[0045] In one embodiment, after the non-conflicting transaction is obtained, the first key value read and / or the second key value written during the pre-execution of the non-conflicting transaction is written into the blockchain, thereby completing the execution operation of the non-conflicting transaction.
[0046] In some embodiments of the present disclosure, the first sorting corresponding to the non-conflicting transactions can be determined according to the directed acyclic graph corresponding to the non-conflicting transactions and the directions indicated by the directed edges in the directed acyclic graph. According to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transactions, the read-write set corresponding to the non-conflicting transactions is stored in the blockchain according to the first sorting.
[0047] Step 104, updating the blockchain state of the blockchain, performing concurrent pre-execution operations on conflicting transactions, classifying transaction conflicts according to the results of the concurrent pre-execution operations, storing read-write sets corresponding to non-conflicting transactions in the blockchain, and updating the blockchain state of the blockchain, and cyclically performing concurrent pre-execution operations on the remaining conflicting transactions when the third preset condition is met, classifying transaction conflicts according to the results of the concurrent pre-execution operations, storing read-write sets corresponding to non-conflicting transactions in the blockchain, and updating the blockchain state of the blockchain, until the read-write sets of each of the plurality of first transactions are stored in the blockchain.
[0048] In one embodiment, after the execution operation of the non-conflicting transaction is completed, the blockchain state of the blockchain needs to be updated, and the execution of the remaining first transaction is completed based on the blockchain with the updated state.
[0049] As an example of a possible implementation, after updating the blockchain state, a concurrent pre-execution operation is performed on the conflicting transactions, and the transaction conflicts are classified according to the concurrent pre-execution operation results, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain.
[0050] In one embodiment, the method of classifying transaction conflicts based on the concurrent pre-execution operation results may be the same as the method of obtaining conflicting transactions and non-conflicting transactions from multiple first transactions in step 102, or may be different.
[0051] As an example of a possible implementation, the blockchain state of the blockchain is updated, and when the third preset condition is met, the remaining conflicting transactions are cyclically executed with concurrent pre-execution operations, and the transaction conflicts are classified according to the results of the concurrent pre-execution operations, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, until the read-write sets of each of the multiple first transactions are stored in the blockchain.
[0052] It should be noted that the third preset condition may be whether the current number of cycles is less than a number of cycles preset according to actual needs, and the preset number of cycles may be an integer greater than or equal to 0.
[0053] In some embodiments of the present disclosure, when the number of the above-mentioned cyclic execution operations is greater than a preset number, the currently remaining conflicting transactions may be executed in a serial manner, thereby ensuring that the execution operations of all first transactions are completed within a reasonable time.
[0054] In the disclosed embodiment, since the pre-execution of a transaction takes a long time, while the time required to write a read-write set to a blockchain is short, multiple first transactions are pre-executed concurrently, and then the read-write sets without conflicts are written to the blockchain through multiple rounds, which effectively reduces the time required to execute multiple first transactions and improves the efficiency of executing the first transactions while ensuring that the result of executing the first transactions is uniquely determined.
[0055] According to the transaction processing method of the smart contract proposed in the embodiment of the present disclosure, by concurrently pre-executing multiple first transactions of the smart contract, the read-write sets corresponding to the multiple first transactions are obtained, and the conflicting transactions and non-conflicting transactions are obtained from the multiple first transactions based on the first conflict condition according to the first key value and / or the second key value, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transactions, and the blockchain state of the blockchain is updated, and the conflicting transactions are concurrently pre-executed, and the transaction conflicts are classified according to the results of the concurrent pre-execution operations, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, and the remaining conflicting transactions are cyclically executed The concurrent pre-execution operation is performed, and the transaction conflicts are classified according to the results of the concurrent pre-execution operation, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, until the read-write sets of each of the multiple first transactions are stored in the blockchain, so that multiple related transactions can be executed concurrently, and the efficiency of transaction execution is improved while ensuring the accuracy of transaction execution.
[0056] Next, the implementation process of obtaining conflicting transactions and non-conflicting transactions from a plurality of first transactions based on the first conflict condition according to the first key value and / or the second key value will be described in detail.
[0057] Figure 2 FIG. 1 is a flow chart showing another method for processing transactions of a smart contract according to an exemplary embodiment. Figure 2 As shown, based on the above embodiments, Figure 1 The process of obtaining conflicting transactions and non-conflicting transactions from a plurality of first transactions based on the first conflict condition according to the first key value and / or the second key value in step 102 may include the following steps:
[0058] Step 201: Generate a directed graph associated with a plurality of first transactions according to the first key value read and / or the second key value written during the pre-execution of each first transaction.
[0059] In one embodiment, the multiple first transactions may be used as nodes in a directed graph, and directed edges between the multiple first transactions may be generated according to the first key value read and / or the second key value written during pre-execution of each first transaction, thereby obtaining a directed graph associated with the multiple first transactions.
[0060] In some embodiments of the present disclosure, step 201 may specifically include the following steps:
[0061] Step a1: construct multiple nodes of a directed graph based on multiple first transactions.
[0062] In one embodiment, each first transaction in the plurality of first transactions is taken as a node in a directed graph.
[0063] Step a2: for any two first transactions among the multiple first transactions, if the first key value of one of the two first transactions is the same as the second key value of the other first transaction, a directed edge is constructed between the nodes corresponding to the two first transactions, wherein the direction of the directed edge is from the node corresponding to the other first transaction to the node corresponding to one of the first transactions.
[0064] The directed graph includes a plurality of first transactions and directed edges connecting the plurality of first transactions.
[0065] In one embodiment, based on any two first transactions among multiple first transactions, the following steps are respectively performed to obtain a directed graph: determining whether there is a situation in which the first key value of one of the two first transactions is the same as the second key value of the other first transaction; if there is a situation in which the first key value of one of the first transactions is the same as the second key value of the other first transaction, determining from multiple nodes a first node corresponding to one of the first transactions and a second node corresponding to the other first transaction; and constructing a directed edge from the second node to the first node.
[0066] Step 202: According to the directed edges, conflicting transactions satisfying the first conflict condition and the directed edges corresponding to the conflicting transactions are removed from the directed graph to obtain a directed acyclic graph.
[0067] It can be understood that since the edges in a directed graph are directed edges, there may be a ring formed by directed edges and nodes in the directed graph. The nodes corresponding to this ring are the nodes where conflicts exist, that is, the conflicting transactions proposed in some embodiments of the present disclosure. Therefore, the conflicting transactions that meet the first conflict condition and the directed edges corresponding to the conflicting transactions can be removed from the directed graph to obtain a directed acyclic graph.
[0068] In some embodiments of the present disclosure, step 202 may specifically include the following steps:
[0069] Step b1, according to the directed edges, using a first graph theory algorithm to determine at least one strongly connected component in the directed graph.
[0070] In some implementations of the present disclosure, the first graph theory algorithm may be a Tarjan algorithm, which is used to determine all strongly connected components in a directed graph.
[0071] It should be noted that a strongly connected component can be a special subgraph in a directed graph, in which any two vertices are reachable from each other. That is, for any pair of vertices u and v in a strongly connected component, there is a path from u to v and from v to u. In other words, if there is a strongly connected component containing more than one node, the nodes cannot be topologically sorted, that is, the order of u and v cannot be determined.
[0072] Step b2: determining a plurality of first transactions corresponding to each strongly interconnected component in at least one strongly interconnected component.
[0073] It can be understood that one strongly connected component corresponds to multiple nodes in the directed graph, that is, one strongly connected component corresponds to multiple first transactions.
[0074] Step b3: for each of the multiple first transactions corresponding to the strongly connected component, determine a conflicting transaction that meets a first preset condition from the multiple first transactions.
[0075] In one embodiment, according to the first preset adjustment component, one first transaction is selected from multiple first transactions corresponding to the strongly connected component as a non-conflicting transaction, and other first transactions in the strongly connected component are selected as conflicting transactions.
[0076] It should be noted that the first preset condition may be a pre-set condition, and the first preset condition corresponding to each strong interconnection component is the same, thereby ensuring that the results of executing multiple first transactions are uniquely determined.
[0077] For example, the first preset condition may be that the number of the two first transactions is the smallest. The number may be preset.
[0078] Step b4, removing the conflicting transactions and the directed edges corresponding to the conflicting transactions from the directed graph to obtain a directed acyclic graph.
[0079] In one embodiment, the directed acyclic graph only includes non-conflicting transactions and directed edges corresponding to the non-conflicting transactions, that is, there is no cycle formed by nodes and directed edges.
[0080] Step 203: determine the nodes in the directed acyclic graph as non-conflicting transactions.
[0081] It can be understood that after removing conflicting transactions using the first graph theory algorithm, the read-write sets corresponding to the remaining non-conflicting transactions can be written into the blockchain.
[0082] Next, we will perform concurrent pre-execution operations on conflicting transactions, classify transaction conflicts based on the results of concurrent pre-execution operations, and store the read-write sets corresponding to non-conflicting transactions in the blockchain in detail.
[0083] Figure 3 FIG. 1 is a flowchart of another method for processing transactions of a smart contract according to an exemplary embodiment. Figure 3 As shown, based on the above embodiments, Figure 1 The implementation process of performing concurrent pre-execution operations on conflicting transactions in step 104, classifying transaction conflicts according to the concurrent pre-execution operation results, and storing read-write sets corresponding to non-conflicting transactions in the blockchain may include the following steps:
[0084] Step 301: when there are multiple conflicting transactions, determine the multiple conflicting transactions as multiple second transactions.
[0085] It is understandable that after the conflicting transactions among the multiple first transactions are screened out, the conflicting transactions need to be processed to ensure that each of the multiple first transactions can eventually complete the execution operation.
[0086] Step 302: Perform concurrent pre-execution operations on the multiple second transactions to obtain read-write sets corresponding to the multiple second transactions.
[0087] The read-write set includes the third key value read and / or the fourth key value written during the pre-execution of the corresponding second transaction.
[0088] In one embodiment, multiple second transactions of the smart contract are pre-executed concurrently to obtain read-write sets corresponding to each of the multiple second transactions, thereby obtaining the third key value read and / or the fourth key value written during the pre-execution of each second transaction.
[0089] Step 303: classify the transaction conflicts of the plurality of second transactions based on the second conflict condition according to the third key value and / or the fourth key value to obtain conflicting transactions and non-conflicting transactions.
[0090] The conflicting transaction includes the second transaction that satisfies the second conflicting condition among the plurality of second transactions, and the non-conflicting transaction includes the remaining second transactions among the plurality of second transactions except the conflicting transaction.
[0091] In some embodiments of the present disclosure, step 303 may specifically include the following steps:
[0092] Step c1: generating a plurality of directed graphs corresponding to the second transactions according to the third key value and / or the fourth key value.
[0093] The directed graph includes a plurality of second transactions and directed edges connecting the plurality of second transactions.
[0094] In one embodiment, the multiple second transactions may be used as nodes in a directed graph, and directed edges between the multiple second transactions may be generated according to the third key value read and / or the fourth key value written during pre-execution of each second transaction, thereby obtaining a directed graph associated with the multiple second transactions.
[0095] In some embodiments of the present disclosure, multiple nodes of a directed graph are constructed based on multiple second transactions. For any two second transactions among the multiple second transactions, if the third key value of one of the two second transactions is the same as the fourth key value of the other second transaction, a directed edge is constructed between the nodes corresponding to the any two second transactions, wherein the direction of the directed edge is from the node corresponding to the other second transaction to the node corresponding to one of the second transactions.
[0096] Step c2: based on the directed edges, remove the conflicting transactions satisfying the second conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph corresponding to the plurality of second transactions, so as to obtain a directed acyclic graph corresponding to the plurality of second transactions.
[0097] It can be understood that since the edges in a directed graph are directed edges, there may be a ring formed by directed edges and nodes in the directed graph. The nodes corresponding to this ring are the nodes where conflicts exist, that is, the conflicting transactions proposed in some embodiments of the present disclosure. Therefore, the conflicting transactions that meet the first conflict condition and the directed edges corresponding to the conflicting transactions can be removed from the directed graph to obtain a directed acyclic graph.
[0098] In some embodiments of the present disclosure, step c2 may specifically include the following steps:
[0099] Step c21, using a second graph theory algorithm, identifying conflict loops in a directed graph corresponding to a plurality of second transactions according to directed edges, and obtaining an identification result.
[0100] In some embodiments of the present disclosure, the second graph theory algorithm may be the Johnson algorithm. It is understandable that the Johnson algorithm is more complex than the Tarjan algorithm. For conflicting transactions screened out using the Tarjan algorithm, it is more efficient to further screen out conflicts using the Johnson algorithm.
[0101] Step c22, determining whether the recognition result meets the second preset condition.
[0102] In some embodiments of the present disclosure, step c22 may specifically include the following steps:
[0103] Count the number of second conflict rings currently identified;
[0104] When the number of second conflict rings is greater than or equal to the first preset threshold and all conflict rings in the directed graph are not identified, determining that the identification result does not meet the second preset condition;
[0105] When the number of second conflicting rings is less than the first preset threshold and all conflicting rings in the directed graph have been identified, it is determined that the identification result satisfies the second preset condition.
[0106] In some embodiments of the present disclosure, when the recognition result does not satisfy the second preset condition, all second transactions are executed in a serial execution manner.
[0107] In one embodiment, when the Johnson algorithm is used to identify the conflict ring in the conflict graph, the number of the currently identified second conflict rings is counted in real time.
[0108] As an example, when the current number of second conflict rings is greater than or equal to the first preset threshold and not all conflict rings in the directed graph are identified, it means that the identification time is too long and it is difficult to use the Johnson algorithm to identify all conflict rings. Therefore, it can be determined that the identification result does not meet the second preset condition.
[0109] As another example, when the number of current second conflict rings is less than the first preset threshold and all conflict rings in the directed graph have been identified, it means that the Johnson algorithm can identify all conflict rings, and therefore it can be determined that the conflict rings meet the second preset condition.
[0110] Step c23: when the identification result satisfies the second preset condition, determine the number of first conflict rings associated with each second transaction in the plurality of second transactions according to the identification result.
[0111] In one embodiment, when the identification result satisfies the second preset condition, the number of first conflict rings in which each second transaction in the plurality of second transactions exists is determined, that is, the number of all first conflict rings including the nodes corresponding to the second transactions.
[0112] Step c24, determining the second transaction with the largest number of first conflicting rings, and obtaining the conflicting transaction.
[0113] Step c25, remove the conflicting transactions and the directed edges associated with the conflicting transactions from the directed graph corresponding to the multiple second transactions, update the recognition result based on the current directed graph, return to execute the step of determining the number of first conflict rings associated with each second transaction in the multiple second transactions according to the recognition result, until there are no conflict rings in the directed graph, and obtain a directed acyclic graph.
[0114] It can be understood that the conflicting transactions with the largest number of first conflict rings and the corresponding directed edges are removed preferentially, so as to remove as many conflict rings as possible at one time. After the recognition result is updated based on the current directed graph (that is, the number of conflict rings corresponding to the second transaction is updated), the second transactions with the largest number of current first conflict rings are removed one by one in the above manner until there are no conflict rings in the directed graph, and a directed acyclic graph is obtained, thereby improving the efficiency of generating a valid acyclic graph.
[0115] Step 304: store the read-write set corresponding to the non-conflicting transaction in the blockchain according to the third key value read and / or the fourth key value written during the pre-execution of the non-conflicting transaction.
[0116] In some embodiments of the present disclosure, the second sorting corresponding to the non-conflicting transactions can be determined according to the directed acyclic graph corresponding to the non-conflicting transactions and the directions indicated by the directed edges in the directed acyclic graph. According to the third key value read and / or the fourth key value written during the pre-execution of the non-conflicting transactions, the read-write set corresponding to the non-conflicting transactions is stored in the blockchain according to the second sorting.
[0117] For example, if Figure 4 As shown, assuming Figure 4 It is a directed graph composed of the first transaction nodes. In this directed graph, all strongly connected components in the directed graph are found through the Tarjan algorithm. For example, there is a strong connected component between node A and node B, and there is a strong connected component between node E and node D. Node A, node D and the associated directed edges are removed to obtain a directed acyclic graph.
[0118] In another example, suppose Figure 5 It is a directed graph composed of the second transaction nodes. The Johnson algorithm is used to find the node with the most associated conflict rings in the current graph, that is, node A (associated with 3 conflict rings). Node A and the corresponding directed edges are removed. According to the current directed graph, the number of conflict rings associated with the remaining nodes is updated. Then the node with the most associated conflict rings is found to be node E. Node E and the corresponding directed edges are removed to obtain a directed acyclic graph.
[0119] Figure 6 1 is a block diagram of a transaction processing device for a smart contract according to an exemplary embodiment. Figure 6 The device includes a pre-execution unit 601, an acquisition unit 602, a first storage unit 603 and a second storage unit 604.
[0120] The pre-execution unit 601 includes a plurality of first transactions of concurrently pre-executing the smart contract, and obtains a read-write set corresponding to each of the plurality of first transactions; the read-write set includes the first key value read and / or the second key value written during the pre-execution of the corresponding first transaction;
[0121] The acquiring unit 602 includes acquiring conflicting transactions and non-conflicting transactions from a plurality of first transactions based on a first conflict condition according to the first key value and / or the second key value, wherein the conflicting transactions include first transactions that meet the first conflict condition among the plurality of first transactions, and the non-conflicting transactions include remaining first transactions among the plurality of first transactions except the conflicting transactions;
[0122] The first storage unit 603 includes storing the read-write set corresponding to the non-conflicting transaction in the blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transaction;
[0123] The second storage unit 604 includes the steps of updating the blockchain state of the blockchain, performing concurrent pre-execution operations on conflicting transactions, classifying transaction conflicts according to the concurrent pre-execution operation results, storing read-write sets corresponding to non-conflicting transactions in the blockchain, updating the blockchain state of the blockchain, cyclically performing concurrent pre-execution operations on the remaining conflicting transactions, classifying transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain when the third preset condition is met, and updating the blockchain state of the blockchain, until the read-write sets of each of the plurality of first transactions are stored in the blockchain.
[0124] In some embodiments of the present disclosure, the acquisition unit 602 may be specifically used to:
[0125] Generate a directed graph associated with the plurality of first transactions according to the first key value read and / or the second key value written during the pre-execution of each first transaction; the directed graph includes the plurality of first transactions and directed edges connecting the plurality of first transactions;
[0126] According to the directed edges, the conflicting transactions satisfying the first conflict condition and the directed edges corresponding to the conflicting transactions are removed from the directed graph to obtain a directed acyclic graph;
[0127] Identify nodes in the directed acyclic graph as non-conflicting transactions.
[0128] In some embodiments of the present disclosure, the acquisition unit 602 may also be used to:
[0129] constructing a plurality of nodes of a directed graph based on the plurality of first transactions;
[0130] For any two first transactions among the multiple first transactions, if the first key value of one of the two first transactions is the same as the second key value of the other first transaction, a directed edge is constructed between the nodes corresponding to the two first transactions, wherein the direction of the directed edge is from the node corresponding to the other first transaction to the node corresponding to one of the first transactions.
[0131] In some embodiments of the present disclosure, the acquisition unit 602 may also be used to:
[0132] According to the directed edges, at least one strongly connected component in the directed graph is determined using a first graph theory algorithm;
[0133] Determine a plurality of first transactions corresponding to each strongly interconnected component in at least one strongly interconnected component;
[0134] For each of the multiple first transactions corresponding to the strongly interconnected component, determining a conflicting transaction that meets a first preset condition from the multiple first transactions;
[0135] Conflicting transactions and directed edges corresponding to conflicting transactions are removed from the directed graph to obtain a directed acyclic graph.
[0136] In some embodiments of the present disclosure, the second storage unit 604 may also be used for:
[0137] In the case where there are multiple conflicting transactions, the multiple conflicting transactions are determined as multiple second transactions;
[0138] Performing concurrent pre-execution operations on the plurality of second transactions to obtain read-write sets corresponding to the plurality of second transactions; the read-write sets include the third key value read and / or the fourth key value written during the pre-execution of the corresponding second transaction;
[0139] According to the third key value and / or the fourth key value, based on the second conflict condition, the multiple second transactions are classified into conflicting transactions and non-conflicting transactions, wherein the conflicting transactions include the second transactions that meet the second conflict condition among the multiple second transactions, and the non-conflicting transactions include the remaining second transactions among the multiple second transactions except the conflicting transactions;
[0140] According to the third key value read and / or the fourth key value written during the pre-execution of the non-conflicting transaction, the read-write set corresponding to the non-conflicting transaction is stored in the blockchain.
[0141] In some embodiments of the present disclosure, the second storage unit 604 may also be used for:
[0142] Generate a directed graph corresponding to the plurality of second transactions according to the third key value and / or the fourth key value; the directed graph includes the plurality of second transactions and directed edges connecting the plurality of second transactions;
[0143] According to the directed edges, removing the conflicting transactions satisfying the second conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph corresponding to the plurality of second transactions, to obtain a directed acyclic graph corresponding to the plurality of second transactions;
[0144] The nodes in the directed acyclic graph corresponding to the plurality of second transactions are determined as non-conflicting transactions.
[0145] In some embodiments of the present disclosure, the second storage unit 604 may also be used for:
[0146] Using the second graph theory algorithm, identifying conflict loops in the directed graph corresponding to the plurality of second transactions according to the directed edges, and obtaining an identification result;
[0147] Determining whether the recognition result meets a second preset condition;
[0148] In the case where the identification result satisfies the second preset condition, determining the number of first conflict rings associated with each second transaction in the plurality of second transactions according to the identification result;
[0149] Determine the second transaction with the largest number of first conflicting rings to obtain the conflicting transaction;
[0150] The conflicting transaction and the directed edges associated with the conflicting transaction are removed from the directed graph corresponding to the multiple second transactions, the recognition result is updated based on the current directed graph, and the step of determining the number of first conflict rings associated with each second transaction in the multiple second transactions according to the recognition result is returned to execute until no conflict rings exist in the directed graph, thereby obtaining a directed acyclic graph.
[0151] In some embodiments of the present disclosure, the second storage unit 604 may also be used for:
[0152] Count the number of second conflict rings currently identified;
[0153] When the number of second conflict rings is greater than or equal to the first preset threshold and all conflict rings in the directed graph are not identified, determining that the identification result does not meet the second preset condition;
[0154] When the number of second conflicting rings is less than the first preset threshold and all conflicting rings in the directed graph have been identified, it is determined that the identification result satisfies the second preset condition.
[0155] In some embodiments of the present disclosure, the second storage unit 604 may also be used for:
[0156] When the conflict ring does not satisfy the second preset condition, all second transactions are executed in a serial execution manner.
[0157] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0158] According to the transaction processing device of the smart contract proposed in the embodiment of the present disclosure, by concurrently pre-executing multiple first transactions of the smart contract, the read-write sets corresponding to the multiple first transactions are obtained, and the conflicting transactions and non-conflicting transactions are obtained from the multiple first transactions based on the first conflict condition according to the first key value and / or the second key value, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain according to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transactions, and the blockchain state of the blockchain is updated, and the conflicting transactions are concurrently pre-executed, and the transaction conflicts are classified according to the results of the concurrent pre-execution operations, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, and the remaining conflicting transactions are cyclically executed The concurrent pre-execution operation is performed, and the transaction conflicts are classified according to the results of the concurrent pre-execution operation, and the read-write sets corresponding to the non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, until the read-write sets of each of the multiple first transactions are stored in the blockchain, so that multiple related transactions can be executed concurrently, and the efficiency of transaction execution is improved while ensuring the accuracy of transaction execution.
[0159] Figure 7 700 is a block diagram of a device for transaction processing of a smart contract according to an exemplary embodiment. For example, the device 700 may be an electronic device, such as a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0160] Reference Figure 7 , the device 700 may include one or more of the following components: a processing component 702 , a memory 704 , a power component 706 , a multimedia component 708 , an audio component 710 , an input / output (I / O) interface 712 , a sensor component 714 , and a communication component 716 .
[0161] The processing component 702 generally controls the overall operation of the device 700, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 702 may include one or more processors 720 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 702 may include one or more modules to facilitate the interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia module to facilitate the interaction between the multimedia component 708 and the processing component 702.
[0162] The memory 704 is configured to store various types of data to support operations on the device 700. Examples of such data include instructions for any application or method operating on the device 700, contact data, phone book data, messages, pictures, videos, etc. The memory 704 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0163] The power component 706 provides power to the various components of the device 700. The power component 706 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 700.
[0164] The multimedia component 708 includes a screen that provides an output interface between the device 700 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 708 includes a front camera and / or a rear camera. When the device 700 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0165] The audio component 710 is configured to output and / or input audio signals. For example, the audio component 710 includes a microphone (MIC), and when the device 700 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 704 or sent via the communication component 716. In some embodiments, the audio component 710 also includes a speaker for outputting audio signals.
[0166] I / O interface 712 provides an interface between processing component 702 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.
[0167] The sensor assembly 714 includes one or more sensors for providing various aspects of status assessment for the device 700. For example, the sensor assembly 714 can detect the open / closed state of the device 700, the relative positioning of components, such as the display and keypad of the device 700, and the sensor assembly 714 can also detect the position change of the device 700 or a component of the device 700, the presence or absence of user contact with the device 700, the orientation or acceleration / deceleration of the device 700, and the temperature change of the device 700. The sensor assembly 714 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 714 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 714 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0168] The communication component 716 is configured to facilitate wired or wireless communication between the device 700 and other devices. The device 700 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 716 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 716 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0169] In an exemplary embodiment, the apparatus 700 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above methods.
[0170] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 704 including instructions, and the instructions can be executed by a processor 720 of the device 700 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0171] In an exemplary embodiment, a computer program product is also provided, comprising a computer program, which implements the above method when executed by the processor 720 of the device 700.
[0172] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.
[0173] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A transaction processing method for a smart contract, characterized in that: include: Concurrently pre-execute multiple first transactions of the smart contract to obtain read-write sets corresponding to each of the multiple first transactions; the read-write set includes the first key value read and / or the second key value written when the corresponding first transaction is pre-executed; According to the first key value and / or the second key value, obtaining conflicting transactions and non-conflicting transactions from the multiple first transactions based on a first conflict condition, wherein the conflicting transaction includes a first transaction that satisfies the first conflict condition among the multiple first transactions, and the non-conflicting transaction includes remaining first transactions among the multiple first transactions except the conflicting transaction; According to the first key value read and / or the second key value written during the pre-execution of the non-conflicting transaction, the read-write set corresponding to the non-conflicting transaction is stored in the blockchain; The blockchain state of the blockchain is updated, and concurrent pre-execution operations are performed on the conflicting transactions, and transaction conflicts are classified according to the concurrent pre-execution operation results, and read-write sets corresponding to non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, and the concurrent pre-execution operations are cyclically performed on the remaining conflicting transactions when a third preset condition is met, and transaction conflicts are classified according to the concurrent pre-execution operation results, and read-write sets corresponding to non-conflicting transactions are stored in the blockchain, and the blockchain state of the blockchain is updated, until the read-write sets of each of the multiple first transactions are stored in the blockchain; the third preset condition is whether the current number of cycles is less than the number of cycles preset according to actual needs; The acquiring, according to the first key value and / or the second key value, conflicting transactions and non-conflicting transactions from the plurality of first transactions based on a first conflict condition includes: Generate a directed graph associated with the plurality of first transactions according to the first key value read and / or the second key value written during the pre-execution of each of the first transactions; the directed graph includes the plurality of first transactions and directed edges connecting the plurality of first transactions; According to the directed edges, removing the conflicting transactions satisfying the first conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph to obtain a directed acyclic graph; Determining nodes in the directed acyclic graph as the non-conflicting transactions; The performing of concurrent pre-execution operations on the conflicting transactions, classifying the transaction conflicts according to the concurrent pre-execution operation results, and storing the read-write sets corresponding to the non-conflicting transactions in the blockchain include: In the case where there are multiple conflicting transactions, determining the multiple conflicting transactions as multiple second transactions; Performing the concurrent pre-execution operation on the multiple second transactions to obtain read-write sets corresponding to the multiple second transactions; the read-write sets include the third key value read and / or the fourth key value written during the pre-execution of the corresponding second transaction; According to the third key value and / or the fourth key value, based on the second conflict condition, the transaction conflict classification is performed on the multiple second transactions to obtain conflicting transactions and non-conflicting transactions, wherein the conflicting transactions include second transactions that meet the second conflicting condition among the multiple second transactions, and the non-conflicting transactions include the remaining second transactions among the multiple second transactions except the conflicting transactions; According to the third key value read and / or the fourth key value written during the pre-execution of the non-conflicting transaction, the read-write set corresponding to the non-conflicting transaction is stored in the blockchain.
2. The transaction processing method of the smart contract according to claim 1, characterized in that: The first key value read and / or the second key value written during the pre-execution of each of the first transactions generates a directed graph associated with the plurality of first transactions, including: constructing a plurality of nodes of the directed graph based on the plurality of first transactions; For any two first transactions among the multiple first transactions, if the first key value of one of the any two first transactions is the same as the second key value of the other first transaction, a directed edge is constructed between the nodes corresponding to the any two first transactions, wherein the direction of the directed edge is from the node corresponding to the other first transaction to the node corresponding to one of the first transactions.
3. The transaction processing method of the smart contract according to claim 1, characterized in that: The step of removing the conflicting transactions satisfying the first conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph according to the directed edges to obtain a directed acyclic graph includes: Determine at least one strongly connected component in the directed graph using a first graph theory algorithm according to the directed edges; Determine a plurality of first transactions corresponding to each of the at least one strongly interconnected component; For each of the multiple first transactions corresponding to the strong interconnection component, determine the conflicting transaction that meets the first preset condition from the multiple first transactions corresponding to the strong interconnection component; The conflicting transaction and the directed edges corresponding to the conflicting transaction are removed from the directed graph to obtain a directed acyclic graph.
4. The transaction processing method of the smart contract according to claim 1, characterized in that: The classifying the transaction conflicts of the plurality of second transactions based on the second conflict condition according to the third key value and / or the fourth key value to obtain conflicting transactions and non-conflicting transactions includes: Generate a directed graph corresponding to the plurality of second transactions according to the third key value and / or the fourth key value; the directed graph includes the plurality of second transactions and directed edges connecting the plurality of second transactions; According to the directed edges, removing the conflicting transactions satisfying the second conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph corresponding to the multiple second transactions, to obtain a directed acyclic graph corresponding to the multiple second transactions; The nodes in the directed acyclic graph corresponding to the multiple second transactions are determined as the non-conflicting transactions.
5. The transaction processing method of the smart contract according to claim 4, characterized in that: The removing, according to the directed edges, the conflicting transactions satisfying the second conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph corresponding to the plurality of second transactions to obtain the directed acyclic graph corresponding to the plurality of second transactions comprises: Using a second graph theory algorithm, identifying conflict loops in the directed graph corresponding to the plurality of second transactions according to the directed edges, and obtaining an identification result; Determining whether the recognition result meets a second preset condition; In a case where the identification result satisfies a second preset condition, determining the number of first conflict rings associated with each second transaction in the plurality of second transactions according to the identification result; Determine the second transaction with the largest number of first conflicting rings to obtain the conflicting transaction; The conflicting transaction and the directed edge associated with the conflicting transaction are removed from the directed graph corresponding to the multiple second transactions, the identification result is updated based on the current directed graph, and the step of determining the number of first conflict rings associated with each second transaction in the multiple second transactions according to the identification result is returned to execute until there are no conflict rings in the current directed graph, thereby obtaining a directed acyclic graph.
6. The transaction processing method of the smart contract according to claim 5, characterized in that: The determining whether the recognition result satisfies a second preset condition includes: Count the number of second conflict rings currently identified; When the number of the second conflict rings is greater than or equal to the first preset threshold and all conflict rings in the directed graph are not identified, determining that the identification result does not meet the second preset condition; When the number of the second conflicting rings is less than the first preset threshold and all the conflicting rings in the directed graph have been identified, it is determined that the identification result satisfies a second preset condition.
7. The transaction processing method of the smart contract according to claim 6, characterized in that: After determining whether the recognition result satisfies the second preset condition, the method further includes: When the conflict ring does not satisfy the second preset condition, all the second transactions are executed in a serial execution manner.
8. A transaction processing device for a smart contract, characterized in that: include: A pre-execution unit includes a plurality of first transactions of concurrently pre-executing a smart contract, and obtains a read-write set corresponding to each of the plurality of first transactions; the read-write set includes a first key value read and / or a second key value written during the pre-execution of the corresponding first transaction; an acquiring unit, comprising acquiring conflicting transactions and non-conflicting transactions from the plurality of first transactions based on a first conflict condition according to the first key value and / or the second key value, wherein the conflicting transaction includes a first transaction that satisfies the first conflict condition among the plurality of first transactions, and the non-conflicting transaction includes remaining first transactions among the plurality of first transactions except the conflicting transaction; A first storage unit, comprising storing a read-write set corresponding to the non-conflicting transaction in a blockchain according to a first key value read and / or a second key value written during pre-execution of the non-conflicting transaction; The second storage unit includes the steps of updating the blockchain state of the blockchain, performing a concurrent pre-execution operation on the conflicting transaction, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, updating the blockchain state of the blockchain, and cyclically performing the concurrent pre-execution operation on the remaining conflicting transactions when a third preset condition is met, classifying the transaction conflicts according to the concurrent pre-execution operation results, storing the read-write sets corresponding to the non-conflicting transactions in the blockchain, and updating the blockchain state of the blockchain, until the read-write sets of the respective first transactions are stored in the blockchain; the third preset condition is whether the current number of cycles is less than the number of cycles preset according to actual needs; The acquisition unit is specifically used for: Generate a directed graph associated with the plurality of first transactions according to the first key value read and / or the second key value written during the pre-execution of each of the first transactions; the directed graph includes the plurality of first transactions and directed edges connecting the plurality of first transactions; According to the directed edges, removing the conflicting transactions satisfying the first conflict condition and the directed edges corresponding to the conflicting transactions from the directed graph to obtain a directed acyclic graph; Determining nodes in the directed acyclic graph as the non-conflicting transactions; Wherein, the second storage unit is specifically used for: In the case where there are multiple conflicting transactions, determining the multiple conflicting transactions as multiple second transactions; Performing the concurrent pre-execution operation on the multiple second transactions to obtain read-write sets corresponding to the multiple second transactions; the read-write sets include the third key value read and / or the fourth key value written during the pre-execution of the corresponding second transaction; According to the third key value and / or the fourth key value, based on the second conflict condition, the transaction conflict classification is performed on the multiple second transactions to obtain conflicting transactions and non-conflicting transactions, wherein the conflicting transactions include second transactions that meet the second conflicting condition among the multiple second transactions, and the non-conflicting transactions include the remaining second transactions among the multiple second transactions except the conflicting transactions; According to the third key value read and / or the fourth key value written during the pre-execution of the non-conflicting transaction, the read-write set corresponding to the non-conflicting transaction is stored in the blockchain.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that The computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Patent Citations
Block chain parallel transaction processing method and device
CN112559174A
Intelligent contract conflict detection method based on directed acyclic graph
CN112837153A