Intelligent contract efficient execution method and system

Through the full parallel method and DAG graph topology sorting technology, the low performance and security risks caused by serial execution in the smart contract execution method are solved, and efficient and secure smart contract execution is achieved.

CN119722061APending Publication Date: 2025-03-28SHANDONG INST OF BLOCKCHAIN
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411694311.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The existing smart contract execution methods have serial execution restrictions, resulting in low throughput and performance, increasing transaction latency and cost. At the same time, the parallel solution of EOS may lead to imbalance of network nodes and pose security risks.

Method used

The contract transaction data is pre-executed by a full-scale parallel method, and read sets are generated and written sets are topologically sorted by building a DAG graph to ensure the correct processing of transaction dependencies, thereby achieving efficient execution of smart contracts.

Benefits of technology

Improve the execution efficiency of smart contracts, increase throughput, reduce transaction costs, and ensure transaction security by avoiding node imbalance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119722061A_ABST
    Figure CN119722061A_ABST
Patent Text Reader

Abstract

The invention provides a smart contract efficient execution method and system, and belongs to the technical field of block chains. The method comprises the following steps: pre-executing contract transaction data based on a full-amount parallel method, namely, distributing an independent temporary cache region for each contract transaction data, and generating a read set and a write set by executing read-write operation; detecting whether variables in the read set and the write set have transaction conflicts with read sets and write sets of other transactions, and updating a read set cache and a write set cache according to a judgment result of the transaction conflicts; comparing the updated read set cache with the updated write set cache, and judging whether a conflict relationship exists or not again; constructing a DAG graph according to the conflict relation and carrying out topological sorting; packing the DAG with the topological sequence into a block to execute a consensus operation; and after the consensus is completed, taking an obtained topological sorting result as an execution sequence of the smart contract by all nodes on the block. According to the invention, efficient execution of the smart contract can be realized on the basis of ensuring transaction security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of blockchain technology, and in particular to a method and system for efficiently executing a smart contract. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] With the digital transformation of the global economy, the number of blockchain transactions and contracts has increased exponentially, and traditional contract execution methods can no longer meet the needs of rapid growth. Improving the efficiency of smart contract execution has significant effects in responding to the digital economic transformation, ensuring transaction security and reducing transaction costs. It is one of the key factors in promoting the development and innovation of the digital economy; therefore, improving the execution efficiency of smart contracts is of great significance.

[0004] However, the inventors found that the existing smart contract execution methods have some technical problems, such as:

[0005] (1) For example, in the patent application No. 201811073894.1, a smart contract processing method based on Ethereum virtual machine is executed serially, that is, each contract is executed sequentially in a block. Although Ethereum has wide support and application in smart contract development and ecosystem, serial execution limits its throughput and performance, resulting in transaction delays and increased costs.

[0006] (2) As a blockchain technology platform different from Ethereum, EOS adopts a parallel smart contract execution solution, which executes smart contracts in parallel according to different shards, improving the overall throughput and performance. EOS's parallel solution can process transactions faster and reduce transaction costs, giving it a clear advantage in high-frequency trading scenarios. However, EOS's sharding mechanism may cause imbalances in some nodes in the network, posing certain security risks. Summary of the invention

[0007] In order to overcome the above-mentioned deficiencies of the prior art, the present invention provides a method and system for efficiently executing smart contracts, which can achieve efficient execution of smart contracts on the basis of ensuring transaction security.

[0008] To achieve the above objectives, one or more embodiments of the present invention provide the following technical solutions:

[0009] The first aspect of the present invention provides a method for efficiently executing a smart contract.

[0010] A smart contract efficient execution method, comprising:

[0011] Get transaction data;

[0012] Filtering contract transaction data from the transaction data;

[0013] Pre-execution operations are performed on the contract transaction data based on a full parallel method, specifically: an independent temporary cache area is allocated for each contract transaction data, and a read set and a write set are generated by performing read and write operations; whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and the read set cache and the write set cache are updated according to the judgment result of the transaction conflict;

[0014] The updated read-set cache and write-set cache are compared, and it is determined again whether there is a conflict relationship; a DAG graph is constructed according to the obtained conflict relationship, and the DAG graph is topologically sorted; the DAG graph with the topological order is packaged into a block, and a consensus operation is performed; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0015] Furthermore, a read set and a write set are generated based on the read and write operations, including: allocating an independent temporary cache area for each transaction; whenever a state variable is accessed during the execution of a transaction, the variable is recorded in the read set; whenever a state variable is modified during the execution of a transaction, the variable is recorded in the write set.

[0016] Furthermore, when performing transaction conflict detection, if both the first condition and the second condition are met, it is considered that the variables in the read set and write set have a transaction conflict with the read set and write set of other transactions; otherwise, it is considered that there is no transaction conflict. The first condition is: the key value in the read set of the transaction also appears in the write set; the second condition is: the execution sequence number of the transaction is less than or equal to the execution sequence number corresponding to the key value in the write set.

[0017] Furthermore, the read set cache and write set cache are updated according to the judgment result of the transaction conflict, including: if there is no transaction conflict, the transaction is placed in the execution completion queue, and the read set cache and write set cache are updated with the read set, write set and execution sequence number of the transaction; if there is a transaction conflict, the transaction is placed in the contract execution pool and then executed again until all transactions pass the transaction conflict detection during execution.

[0018] Furthermore, a DAG graph is constructed according to the obtained conflict relationship, including: respectively checking whether the key values ​​in the read set cache and the write set cache of the current transaction have been written by other transactions in the write set cache, and if so, marking other transactions that have written the key values ​​before the transaction; checking whether the key values ​​in the write set cache of the current transaction have been read by other transactions in the read set cache, and if so, marking other transactions that have read the key values ​​before the transaction.

[0019] Furthermore, constructing a DAG graph based on the obtained conflict relationship also includes: creating a node for each transaction, and if a key value in the read set or write set of transaction A is covered by the write set of transaction B, adding an edge in the DAG graph from transaction B to transaction A to represent the dependency relationship between transactions.

[0020] Furthermore, an enqueue depth variable is created. Whenever a node has a dependency, the depth is increased by 1 and the dependency relationship between the nodes is recorded. The DAG graph is topologically sorted based on the dependency relationship.

[0021] A second aspect of the present invention provides an efficient execution system for smart contracts.

[0022] A smart contract efficient execution system, comprising:

[0023] The data acquisition module is configured to: acquire transaction data, and filter out contract transaction data from the transaction data;

[0024] The pre-execution module is configured to: perform pre-execution operations on the contract transaction data based on a full parallel method, specifically: allocate an independent temporary cache area for each contract transaction data and generate a read set and a write set by performing read and write operations; detect whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and update the read set cache and the write set cache according to the judgment result of the transaction conflict;

[0025] The DAG drawing module is configured to: compare the updated read set cache and write set cache, and determine again whether there is a conflict relationship; construct a DAG graph according to the obtained conflict relationship, and topologically sort the DAG graph; pack the DAG graph with the topological order into a block, and perform a consensus operation; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0026] The third aspect of the present invention provides a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the steps in a method for efficient execution of a smart contract as described in the first aspect of the present invention.

[0027] The fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the method for efficient execution of a smart contract as described in the first aspect of the present invention are implemented.

[0028] One or more of the above technical solutions have the following beneficial effects:

[0029] (1) The present invention provides a method for efficient execution of smart contracts. A DAG graph is constructed based on the conflict relationship between the read set cache and the write set cache formed in the contract transaction data. All nodes can obtain transaction dependencies based on the generated DAG graph; data without dependencies can be executed simultaneously. Moreover, the DAG graph constructed by the present invention is based on transaction granularity. When a large number of transactions are generated in a block, the DAG graph constructed at the transaction granularity can achieve a greater degree of parallelism. Therefore, the present invention can effectively increase throughput, improve execution efficiency, and achieve efficient execution of smart contracts.

[0030] (2) When the present invention performs pre-execution operations on contract transaction data based on a full parallel method, an independent temporary cache area is allocated for each contract transaction data and a read set and a write set are generated by performing read and write operations. In other words, the pre-execution result of the present invention uses an isolated temporary cache, which does not affect the correct execution of the contract; and it is no longer processed in a single parallel manner, but the execution order and method are judged based on the dependency relationship between nodes. Therefore, the present invention can avoid the problem of node imbalance and ensure transaction security.

[0031] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0033] Figure 1 This is a flow chart of a method for efficiently executing a smart contract in Embodiment 1 of the present invention.

[0034] Figure 2 This is a conflict detection flow chart of the first execution situation in the first embodiment of the present invention.

[0035] Figure 3 This is a conflict detection flow chart for the second execution scenario in the first embodiment of the present invention.

[0036] Figure 4 This is a first example diagram of transaction node dependency in the first embodiment of the present invention. DETAILED DESCRIPTION

[0037] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0038] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.

[0039] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0040] Embodiment 1

[0041] This embodiment discloses a method for efficiently executing a smart contract.

[0042] like Figure 1 As shown, a smart contract efficient execution method includes:

[0043] Step S1, obtaining transaction data, and filtering out contract transaction data from the transaction data;

[0044] Step S2: pre-execution operation is performed on the contract transaction data based on the full parallel method, specifically: an independent temporary cache area is allocated for each contract transaction data, and a read set and a write set are generated by performing read and write operations; whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and the read set cache and the write set cache are updated according to the judgment result of the transaction conflict;

[0045] Step S3: Compare the updated read set cache and write set cache, and determine again whether there is a conflict relationship; construct a DAG graph according to the obtained conflict relationship, and topologically sort the DAG graph; pack the DAG graph with topological order into a block, and perform a consensus operation; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0046] Based on the above process, the present invention can realize the efficient execution of smart contracts on the basis of ensuring transaction security. To facilitate understanding of the technical solution of the present invention, the specific implementation steps of the technical solution of the present invention are further explained and illustrated below.

[0047] Step S1: Obtain transaction data, and filter out contract transaction data from the transaction data.

[0048] This embodiment is mainly aimed at the use scenario of the trusted sharing model for the development and utilization of data elements. It saves data usage traces through smart contracts, improves data tracing efficiency, and audits data flow process.

[0049] Before obtaining transaction data, the transaction pool already contains contract transactions and other types of transactions initiated by users. During intelligent saving execution, the master node can pull sufficient transactions from the transaction pool for packaging by traversing a certain amount of data. At the same time, after pulling the transaction data, the master node can also filter out contract transactions from the transaction data according to the transaction type and hand them over to the DAG drawing module.

[0050] Step S2: Perform pre-execution operations on the contract transaction data based on the full parallel method to generate a read-write set of the transaction. In order to avoid the pre-execution result affecting the correctness of the contract, the pre-execution result uses an isolated temporary cache.

[0051] Step S2-1: Allocate an independent temporary cache area for each contract transaction data and generate a read set and a write set by performing read and write operations.

[0052] Each contract transaction data is allocated an independent temporary cache area, namely the read set cache and the write set cache; specifically, the read set cache (ReadCache) is used to store all read set contents and the latest execution sequence number (execSeq), and the write set cache (WriteCache) is used to store all write set contents and the latest execution sequence number (execSeq). Among them, the execution queue is used to store all pending contracts that have not passed the conflict detection, and the execution completion queue is used to store all contracts that have passed the conflict detection and completed execution.

[0053] First, the contract transaction data is preprocessed, that is, a separate temporary cache area is allocated for each transaction. Then, read and write operations are performed on each transaction. Specifically, when performing a read operation, each time a state variable is accessed during the transaction execution, the variable is recorded in the read set; when performing a write operation, each time a state variable is modified during the transaction execution, the variable is recorded in the write set. Based on this process, the generated read set and write set are expressed as:

[0054]

[0055] Among them, R and W represent the read set and write set respectively; i represents the i-th state variable read, w j represents the jth state variable written; n and m represent the number of state variables in the read set and write set, respectively.

[0056] Step S2-2: Check whether the variables in the read set and write set have transaction conflicts with the read set and write set of other transactions.

[0057] When performing transaction conflict detection, if both the first and second conditions are met, it is considered that the variables in the read set and write set have a transaction conflict with the read set and write set of other transactions; otherwise, it is considered that there is no transaction conflict. The first condition is that the key value key in the read set of the transaction also appears in the write set; the second condition is that the execution sequence number of the transaction is less than or equal to the execution sequence number corresponding to the key value key in the write set.

[0058] Step S2-3: Update the read-set cache and the write-set cache according to the judgment result of the transaction conflict.

[0059] If there is no transaction conflict, the transaction is placed in the execution completion queue, and the read set cache and write set cache are updated with the read set, write set and execution sequence number of the transaction; if there is a transaction conflict, the transaction is placed in the contract execution pool and re-executed later until all transactions pass the transaction conflict detection during execution. For ease of understanding, this embodiment uses the following assumptions to illustrate the judgment and execution process of transaction conflicts:

[0060] Assume that there are 4 transactions, namely tx0, tx1, tx2 and tx3 (0 and 1 represent transaction numbers, not the order in which transactions are executed). These 4 transactions have the following read-write sets:

[0061] tx0: read set R = {k1}, write set W {K2};

[0062] tx1: read set R = {k2}, write set W {k3};

[0063] tx2: read set R = {k1}, write set W {k3};

[0064] tx3: read set R = {k1}, write set W {k2};

[0065] From the read-write sets of the above four transactions, we can know that: tx0 and tx1 have a read-write conflict of k2, tx1 and tx2 have a write-write conflict of k3, and tx2 and tx3 have a read-write conflict of k2. Taking tx0 and tx1 as an example, tx0 and tx1 are executed concurrently. Assuming that there is no data in the execution completion queue at this time, the execution sequence numbers obtained are all 0. At this time, the conflict detection process is:

[0066] When tx1 is executed first and tx0 is executed later, the conflict detection process is as follows Figure 2 As shown, tx1 is executed first, and the write-set cache and read-set cache are empty. The conflict detection and verification of tx1 succeeds, and the write-set cache and read-set cache are updated. Afterwards, when tx0 is executed, it is checked that the read set k1 of tx0 does not exist in the write-set cache. The verification succeeds, and the write-set cache and read-set cache are updated.

[0067] When tx0 is executed first and tx1 is executed later, the conflict detection process is as follows Figure 3 As shown, that is, tx0 is executed first, and the write-set cache and the read-set cache are empty. The conflict detection check of tx0 is successful, and the write-set cache and the read-set cache are updated. Subsequently, when tx1 is executed, it is checked that the read-set cache k2 of tx1 exists in the write-set cache and the execution sequence number is equal. If the check fails, it is re-executed. Then, tx1 is re-executed, and tx0 already exists in the execution completion queue. At this time, the execution sequence number obtained is 1; after the execution is completed, it is checked that the read-set cache k2 of tx1 exists in the write-set cache, but the execution sequence number is greater than that in the write-set cache. The check succeeds, and the write-set cache and the read-set cache are updated.

[0068] Step S3: Compare the updated read set cache and write set cache, and determine again whether there is a conflict relationship; construct a DAG graph according to the obtained conflict relationship, and topologically sort the DAG graph; pack the DAG graph with topological order into a block, and perform a consensus operation; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0069] The updated read-set cache is compared with the write-set cache to determine if there is a conflict. If there is a conflict, it is added to the dependency array to ensure that the nodes with dependencies can be executed in the correct order.

[0070] Step S3-1: construct a DAG graph according to the obtained conflict relationship.

[0071] Step S3-1-1, check whether the key value key in the read set cache of the current transaction has been written by other transactions in the write set cache. If so, mark other transactions that have written the key value key before this transaction; check whether the key value key in the write set cache of the current transaction has been written by other transactions in the write set cache. If so, mark other transactions that have written the key value key before this transaction. Check whether the key value in the write set cache of the current transaction has been read by other transactions in the read set cache. If so, mark other transactions that have read the key value before this transaction. For ease of understanding, still taking the above tx0-tx3 as an example, specifically:

[0072] Check whether the key value in the read set cache has been written by other transactions:

[0073] tx0: read set R(tx0) = {k1}, write set W(tx0) = {k2}, k1 has not been written by other transactions.

[0074] tx1: read set R(tx1)={k2}, write set W(tx1)={k3}, k2 is written by tx0 and tx3.

[0075] tx2: read set R(tx2) = {k1}, write set W(tx2) = {k3}, k1 has not been written by other transactions.

[0076] tx3: read set R(tx3) = {k1}, write set W(tx3) = {k2}, k1 has not been written by other transactions.

[0077] Check whether the key value in the write-set cache has been written by other transactions:

[0078] tx0: write set W(tx0) = {k2}, k2 is read by tx1 and written by tx3.

[0079] tx1: write set W(tx1) = {k3}, k3 is written by tx2.

[0080] tx2: write set W(tx2) = {k3}, k3 is written by tx1.

[0081] tx3: write set W(tx3) = {k2}, k2 is read by tx1 and written by tx0.

[0082] Check whether the key value in the write set is read by other transactions:

[0083] tx0: write set W(tx0) = {k2}, k2 is read by tx1.

[0084] tx1: write set W(tx1) = {k3}, k3 is written by tx2.

[0085] tx2: write set W(tx2) = {k3}, k3 is written by tx1.

[0086] tx3: write set W(tx3) = {k2}, k2 is read in by tx1.

[0087] Step S3-1-2: Create a node for each transaction. If a key value in the read set or write set of transaction A is overwritten by the write set of transaction B, to ensure the correctness of the dependency, add an edge from transaction B to transaction A in the DAG graph to indicate the dependency between transactions. This ensures that the nodes with dependencies can be executed in the correct order. Figure 4 As shown, a node is created for each transaction and a dependency edge is generated, specifically:

[0088] tx0 writes k2, tx1 reads k2, so tx0 points to tx1.

[0089] tx0 writes k2, tx3 writes k2, so tx0 points to tx3.

[0090] tx1 writes to k3, tx2 writes to k3, so tx1 points to tx2.

[0091] tx3 writes k2, tx1 reads k2, so tx3 points to tx1.

[0092] Step S3-2: topologically sort the DAG graph, create an entry depth variable, and whenever a node has a dependency, the depth is increased by 1 and the dependency relationship between the nodes is recorded; topologically sort the DAG graph based on the dependency relationship.

[0093] First, create an entry depth variable. Whenever a node has a dependency, the depth is increased by 1; the dependencies between nodes are recorded. Then, check the nodes with a depth of 0 and add them to the queue that can be executed immediately. These nodes are starting nodes without other dependencies and can be executed directly. After the current node is executed, the depth of the node that it is a parent node depends on is reduced by 1 until the depth of a node is reduced to 0; at this time, the node is added to the queue that can be executed immediately, indicating that the execution of this node can begin. Continue to execute this step until all nodes in the DAG graph are executed.

[0094] Step S3-3: Pack the DAG graph with topological order into the block and perform consensus operation; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0095] Based on the above process, the present invention can realize the efficient execution of smart contracts on the basis of ensuring transaction security.

[0096] Embodiment 2

[0097] This embodiment discloses a smart contract efficient execution system.

[0098] A smart contract efficient execution system, comprising:

[0099] The data acquisition module is configured to: acquire transaction data, and filter out contract transaction data from the transaction data;

[0100] The pre-execution module is configured to: perform pre-execution operations on the contract transaction data based on a full parallel method, specifically: allocate an independent temporary cache area for each contract transaction data and generate a read set and a write set by performing read and write operations; detect whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and update the read set cache and the write set cache according to the judgment result of the transaction conflict;

[0101] The DAG drawing module is configured to: compare the updated read set cache and write set cache, and determine again whether there is a conflict relationship; construct a DAG graph according to the obtained conflict relationship, and topologically sort the DAG graph; pack the DAG graph with the topological order into a block, and perform a consensus operation; when the consensus is completed, all nodes on the block use the obtained topological sorting result as the final execution order of the smart contract.

[0102] Embodiment 3

[0103] The purpose of this embodiment is to provide a computer-readable storage medium.

[0104] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in a method for efficient execution of a smart contract as described in Embodiment 1 of the present disclosure.

[0105] Embodiment 4

[0106] The purpose of this embodiment is to provide an electronic device.

[0107] An electronic device includes a memory, a processor, and a program stored in the memory and executable on the processor. When the processor executes the program, the steps in a method for efficiently executing a smart contract as described in Embodiment 1 of the present disclosure are implemented.

[0108] The steps involved in the apparatuses of the above embodiments 2, 3 and 4 correspond to the method embodiment 1, and the specific implementation methods can refer to the relevant description part of embodiment 1. The term "computer-readable storage medium" should be understood as a single medium or multiple media including one or more instruction sets; it should also be understood to include any medium that can store, encode or carry an instruction set for execution by a processor and enable the processor to execute any method in the present invention.

[0109] Those skilled in the art should understand that the modules or steps of the present invention described above can be implemented by a general-purpose computer device, or alternatively, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. The present invention is not limited to any specific combination of hardware and software.

[0110] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.

Claims

1. A smart contract efficient execution method, characterized in that: include: Get transaction data; Filtering contract transaction data from the transaction data; Pre-execution operations are performed on the contract transaction data based on a full parallel method, specifically: an independent temporary cache area is allocated for each contract transaction data, and a read set and a write set are generated by performing read and write operations; whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and the read set cache and the write set cache are updated according to the judgment result of the transaction conflict; Compare the updated read-set cache and write-set cache and determine again whether there is a conflict relationship; Construct a DAG graph according to the obtained conflict relationship, and perform topological sorting on the DAG graph; The DAG graph with topological order is packaged into a block and consensus operations are performed; when the consensus is completed, all nodes on the block use the obtained topological sorting results as the final execution order of the smart contract.

2. A smart contract efficient execution method as claimed in claim 1, characterized in that: Generate read sets and write sets based on read and write operations, including: allocating an independent temporary cache area for each transaction; whenever a state variable is accessed during the execution of a transaction, record the state variable in the read set; whenever a state variable is modified during the execution of a transaction, record the state variable in the write set.

3. A smart contract efficient execution method as claimed in claim 1, characterized in that: When performing transaction conflict detection, if the first and second conditions are met at the same time, it is considered that the variables in the read set and write set have a transaction conflict with the read set and write set of other transactions; Otherwise, it is considered that there is no transaction conflict; The first condition is that the key value in the read set of the transaction also appears in the write set; the second condition is that the execution sequence number of the transaction is less than or equal to the execution sequence number corresponding to the key value in the write set.

4. A smart contract efficient execution method as claimed in claim 1, characterized in that: The read set cache and write set cache are updated according to the judgment result of the transaction conflict, including: if there is no transaction conflict, the transaction is placed in the execution completion queue, and the read set cache and write set cache are updated with the read set, write set and execution sequence number of the transaction; if there is a transaction conflict, the transaction is placed in the contract execution pool and then re-executed until all transactions pass the transaction conflict detection during execution.

5. A smart contract efficient execution method as claimed in claim 1, characterized in that: A DAG graph is constructed according to the obtained conflict relationship, including: checking whether the key values ​​in the read set cache and the write set cache of the current transaction have been written by other transactions in the write set cache. If so, marking other transactions that have written the key values ​​before this transaction; checking whether the key values ​​in the write set cache of the current transaction have been read by other transactions in the read set cache. If so, marking other transactions that have read the key values ​​before this transaction.

6. A smart contract efficient execution method as claimed in claim 5, characterized in that: Constructing a DAG graph according to the obtained conflict relationship also includes: creating a node for each transaction, if a key value in the read set or write set of transaction A is covered by the write set of transaction B, then adding an edge in the DAG graph from transaction B to transaction A to represent the dependency relationship between transactions.

7. A smart contract efficient execution method as claimed in claim 6, characterized in that: Create an enqueued depth variable. Whenever a node has a dependency, the depth is increased by 1 and the dependency relationship between the nodes is recorded. The DAG graph is topologically sorted based on the dependency relationship.

8. An efficient execution system for smart contracts, characterized in that: include: The data acquisition module is configured to: acquire transaction data, and filter out contract transaction data from the transaction data; The pre-execution module is configured to: perform pre-execution operations on the contract transaction data based on a full parallel method, specifically: allocate an independent temporary cache area for each contract transaction data and generate a read set and a write set by performing read and write operations; detect whether the variables in the read set and the write set have transaction conflicts with the read set and the write set of other transactions, and update the read set cache and the write set cache according to the judgment result of the transaction conflict; The DAG drawing module is configured to: compare the updated read set cache and the write set cache, and determine again whether there is a conflict relationship; construct a DAG graph according to the obtained conflict relationship, and perform topological sorting on the DAG graph; The DAG graph with topological order is packaged into a block and consensus operations are performed; when the consensus is completed, all nodes on the block use the obtained topological sorting results as the final execution order of the smart contract.

9. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the steps in the efficient execution method of a smart contract as described in any one of claims 1 to 7 are implemented.

10. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the efficient execution method of a smart contract as described in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Intelligent contract processing method and device based on Ethernet virtual machine

    CN109034814A