Method and transaction execution device for improving execution speed of blockchain smart contract transaction
By dividing the global counter into multiple sub-counters to process smart contract transactions in parallel, the problem of read-write conflicts in the blockchain system is solved, and the transaction execution speed is significantly improved by up to 18 times.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI TREE-GRAPH BLOCKCHAIN INST
- Filing Date
- 2022-06-14
- Publication Date
- 2026-05-08
AI Technical Summary
In existing technologies, the parallel execution of blockchain smart contracts suffers from read-write conflicts, resulting in limited improvements in transaction execution speed and impacting user experience.
By dividing the global counter into multiple sub-counters, using a multi-core, multi-threaded approach to process smart contract transactions, and randomly assigning user addresses through hash encryption, the probability of read/write conflicts is reduced.
It significantly improves the parallel transaction execution speed of smart contracts by about 18 times, approaching the theoretical speed, and solves the problem of read-write conflicts affecting transaction throughput.
Smart Images

Figure CN115271715B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of big data processing and information technology, and more specifically, to a method and device for improving the transaction execution speed of blockchain smart contracts. Background Technology
[0002] Blockchain systems suffer from very limited transaction throughput due to issues with their consensus mechanisms. For example, Bitcoin can only process a maximum of 7 transactions per second, while Ethereum ETH1.0 supports a maximum of 30 to 40 transactions per second. However, with the development of consensus mechanisms in recent years, such as the sharding technology in Ethereum ETH2.0, some chains can now execute thousands of transactions per second.
[0003] Those skilled in the art will understand that the bottlenecks in transaction throughput are concentrated in disk I / O, network bandwidth, and transaction execution efficiency, among which improving transaction execution efficiency is the most challenging.
[0004] Typically, Ethereum transactions are executed sequentially, and the execution speed is limited by the single-core processing capacity. To further improve transaction execution efficiency, some literature has proposed parallelizing smart contract execution. For example, using multi-core, multi-threaded methods to parallelize transaction processing can improve efficiency.
[0005] However, the methods mentioned above for improving transaction execution efficiency are far from ideal and ineffective. The root cause is that during parallel processing, some read-write conflicts inherent in blockchain applications are inevitably encountered. For example, the sender address of the smart contract distributing tokens may be called by multiple threads simultaneously, leading to read-write conflicts.
[0006] Most of the aforementioned conflicts are concentrated in a single counter or array within the application, such as the following function in the token distribution smart contract code:
[0007]
[0008] When this function is called, the sender's balance (balance[msg.sender]) is decreased, while the receiver's balance (balance[to]) is increased by the corresponding amount. The sender's balance is a special field stored in the state tree. Operations on this field involve loading (SLOAD), incrementing the counter (ADD), and updating storage (SSTORE), among others. When two transactions trigger this function simultaneously, it can cause a state conflict in the sender's balance field, affecting the transaction's execution speed and prolonging its execution time. Multiple conflicts can severely impact transaction throughput.
[0009] According to experimental statistics, the application types of conflict can be mainly divided into three categories:
[0010] ① The first type is the distribution / airdrop of ERC20 tokens, which accounts for 60% of the conflicts;
[0011] ② The second type is open financial DIFI projects (Decentralized Finance), especially newly launched DIFI projects, which account for 29% of applications;
[0012] ③ The third type is MINT, a non-fungible token (NFT), which accounts for 10%.
[0013] In the above application scenarios, since the data is distributed through the same address within a short period of time, the number of read-write conflicts will be greatly increased, affecting the transaction throughput of the entire network.
[0014] In other words, the aforementioned issue with transaction throughput means that parallel execution of transactions cannot effectively improve transaction speed, and there is still a significant gap from the theoretical speed, resulting in unsatisfactory execution efficiency and seriously affecting user experience.
[0015] Therefore, how to further improve the transaction execution speed of blockchain smart contracts is an urgent problem that the industry needs to solve. Summary of the Invention
[0016] The purpose of this invention is to provide a method and apparatus for improving the transaction execution speed of blockchain smart contracts based on a partition counter. This method improves transaction execution efficiency by solving some problems in smart contracts that may lead to system call conflicts.
[0017] To achieve the above objectives, the technical solution of the present invention is as follows:
[0018] A method for improving the execution speed of blockchain smart contract transactions based on a partition counter, which parallelizes smart contract transactions through multi-core and multi-threading, includes the following steps:
[0019] Step S1: Based on the application type of native read-write conflicts in the application, identify all global counters of global variable types that are prone to read-write conflicts;
[0020] Step S2: Divide each identified global counter into N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter; wherein the number of sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter is determined based on the conflicting application type, traffic volume, and / or the number of microprocessors in the sender system; N is greater than or equal to 2;
[0021] Step S3: When a blockchain smart contract transaction arrives, according to a predetermined random algorithm, the blockchain smart contract transaction is assigned to one of the corresponding sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter for processing, and the count value of the corresponding sub-counter is obtained;
[0022] Step S4: When it is necessary to obtain the real-time value of the global counter, add the count values of the N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0023] Furthermore, the application types of read-write conflicts include the distribution / airdrop of ERC20 tokens, the open financial DIFI project, and the MINT application type of non-fungible tokens (NFTs).
[0024] Furthermore, in step S2, if each of the global counters involves processing a single sending address, the single sending address is changed to multiple sending addresses, and each sending address corresponds to one of the sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0025] Furthermore, in step S3, assigning the blockchain smart contract transaction to the corresponding sub-counter for processing is done by hashing and encrypting the sending address of the user's blockchain smart contract transaction.
[0026] Furthermore, the number of microprocessors in step S2 is N, and the number of sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter is N or greater than N.
[0027] Furthermore, the application type of read-write conflict is determined through the analysis of smart contract code, the detection of conflicting fields by tools, and the identification of conflicts in transaction memory.
[0028] To achieve the above objectives, another technical solution of the present invention is as follows:
[0029] A blockchain smart contract transaction execution device, employing a multi-core, multi-threaded approach to parallelize smart contract transactions, is characterized by comprising:
[0030] The identification module identifies all global counters of global variable types that are prone to read-write conflicts, based on the application type of native read-write conflicts in the application.
[0031] The partitioning module divides each identified global counter into N sub-counters: Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0032] The transaction module, when a blockchain smart contract transaction arrives, allocates the blockchain smart contract transaction to one of the corresponding sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter according to a specific random algorithm for processing, and obtains the count value of the corresponding sub-counter;
[0033] When the result generation module needs to obtain the real-time value of the global counter, it adds the count values of the N sub-counters, Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0034] To achieve the above objectives, the present invention also provides the following technical solution:
[0035] A readable storage medium storing executable instructions for executing the aforementioned method for improving the transaction execution speed of blockchain smart contracts based on partition counters.
[0036] To achieve the above objectives, another technical solution of the present invention is as follows:
[0037] A data processing terminal, used as a consensus node in a P2P network, receives, verifies consensus on, and stores blocks in the P2P network. The data processing terminal includes:
[0038] The aforementioned readable storage medium;
[0039] The processor retrieves and executes executable instructions from the readable storage medium to perform a method for improving the transaction execution speed of blockchain smart contracts based on a partition counter.
[0040] As can be seen from the above technical solution, this invention proposes a method for detecting block generation time in a permissionless blockchain system. By dividing the global counter, which is prone to read-write conflicts, into multiple sub-counters, the probability of read-write conflicts in the application during the parallel execution of smart contracts is effectively reduced, thereby greatly improving the speed of parallel execution of smart contracts. Typically, ordinary parallelization methods improve the execution speed of single-threaded smart contracts by about 9 times, while this method can improve it by up to 18 times, which is close to the theoretical near-term value. Attached Figure Description
[0041] Figure 1 The diagram shown is a schematic representation of the partition counter structure in an embodiment of the present invention.
[0042] Figure 2 The diagram shown is a flowchart illustrating the method for improving the transaction execution speed of blockchain smart contracts based on a partition counter according to the present invention.
[0043] Figure 3 The diagram shown is a preferred embodiment of the method for improving the transaction execution speed of blockchain smart contracts based on a partition counter according to the present invention. Detailed Implementation
[0044] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0045] It should be noted that this invention proposes a method for improving the transaction execution speed of blockchain smart contracts based on partition counters, which is used to solve the problem that parallel execution of smart contracts in blockchain systems can lead to read-write conflicts in native applications.
[0046] The blockchain smart contract transaction execution device of the present invention adopts a multi-core, multi-threaded approach to process smart contract transactions in parallel, including an identification module, a partitioning module, a transaction module, and a result generation module. Its core idea is to split the identification counters that are prone to conflict into multiple sub-counters, and assign the transaction value to the sub-counters for processing. Since the address of the sub-counter is derived using cryptographic hash, the sub-counter can be considered to be pseudo-randomly assigned.
[0047] The identification module can identify all fields of the global counter (globe counter) that are prone to read-write conflicts based on the application type of native read-write conflicts in the application. The application type of read-write conflicts can be determined through smart contract code analysis, tool detection of conflicting fields, and conflict identification of transaction memory. Typically, the application types of read-write conflicts include the distribution / airdrop of ERC20 tokens, open finance (DIFI) projects, and the MINT application type of non-fungible tokens (NFTs).
[0048] Please see Figure 1 , Figure 1 The diagram shown is a schematic representation of the partition counter structure in an embodiment of the present invention. Figure 1 As shown, each global counter can be divided into N sub-counters: Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0049] Specifically, most of these read-write conflicts are concentrated in a single global counter (globecounter) or array within the application, such as during token distribution or when the token balance of a sending address is being recorded. In an embodiment of the invention, the partitioning module can expand the single sending address of the global counter (globecounter) that is prone to read-write conflicts and is of a recognized global variable type into multiple sending addresses, each corresponding to a sub-counter.
[0050] When a blockchain smart contract transaction arrives, the transaction module assigns the transaction to one of the corresponding sub-counters (Sub-1 counter, Sub-2 counter, ..., Sub-N counter) for processing according to a specific random algorithm, and obtains the count value of the corresponding sub-counter.
[0051] The sum of the values of all sub-counters (Sub-1 counter, Sub-2 counter, ..., Sub-N counter) equals the value of the global counter. When the actual value of the global counter (globe counter) is needed, the result generation module can add up the values of all sub-counters to obtain the global counter (globe counter).
[0052] Please see Figure 2 , Figure 2 The diagram shows a flowchart illustrating the method for improving the transaction execution speed of blockchain smart contracts based on a partition counter, as described in this invention. Figure 2 As shown, this method for improving the execution speed of blockchain smart contract transactions is used to parallelize smart contract transactions through multi-core and multi-threading, and is characterized by the following steps:
[0053] Step S1: Based on the application type of native read-write conflicts in the application, identify all global counters of global variable types that are prone to read-write conflicts;
[0054] Step S2: Divide each identified global counter into N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter; wherein the number of sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter is determined based on the conflicting application type, traffic volume, and / or the number of microprocessors in the sender system; N is greater than or equal to 2.
[0055] For example, if the sender's system has 4 CPU cores, it can be divided into 4 sub-counters: Sub-1 counter, Sub-2 counter, Sub-3 counter, and Sub-4 counter. Of course, the relationship between CPU cores and sub-counters is not necessarily strongly bound or correlated.
[0056] Step S3: When a blockchain smart contract transaction arrives, according to a predetermined random algorithm, the blockchain smart contract transaction is assigned to one of the corresponding sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter for processing, and the count value of the corresponding sub-counter is obtained.
[0057] In step S3, assigning the blockchain smart contract transaction to the corresponding sub-counter for processing involves deriving the user's blockchain smart contract transaction sending address through hash encryption. In other words, since the user address is derived through hash encryption, the scheduling of the sub-counter can be considered random when a user address transaction request arrives.
[0058] Step S4: When it is necessary to obtain the real-time value of the global counter, add the count values of the N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
[0059] Example 1
[0060] Please see Figure 3 , Figure 3 The diagram shown is a preferred embodiment of the method for improving the transaction execution speed of blockchain smart contracts based on a partition counter according to the present invention. Figure 3 As shown, the method specifically includes the following steps:
[0061] First, identify the global counter field that is prone to read / write conflicts;
[0062] Second, the identified global counter field is divided into multiple sub-counters. The division of the sub-counter field can be based on the number of CPU cores in the sender's system and the traffic volume.
[0063] Third, when a transaction arrives, it is assigned to the corresponding subcounter field for processing according to a specific random algorithm. For example, the specific subcounter number can be obtained by dividing the transaction user's address by the number of subcounters. Since the user's transaction address itself is random, this method can achieve random selection of the subcounter.
[0064] Specifically, if the blockchain smart contract transaction code is implemented in Solidity and divided into 3 sub-counters, the code implementation would be as follows:
[0065]
[0066] As can be seen from the above, the global counter is divided into three sub-counters. When operations are needed on the global counter, the sub-counters can be randomly selected using `tx.origin%3`, and then the operations can be performed on them. When the real-time value of the global counter is needed, the values of the three sub-counters can be added together.
[0067] In an embodiment of the present invention, a readable storage medium is also proposed, which stores executable instructions for executing the above-described method for improving the transaction execution speed of blockchain smart contracts based on partition counters.
[0068] In an embodiment of the present invention, a data processing terminal is also proposed for use as a consensus node in a P2P network, receiving, verifying consensus, and storing blocks in the P2P network. The data processing terminal includes a readable storage medium and a processor as described above. The processor retrieves and executes executable instructions in the readable storage medium to execute a method for improving the transaction execution speed of blockchain smart contracts based on a partition counter.
[0069] Those skilled in the art will understand that all or part of the steps in the above methods can be implemented by a program instructing related hardware (e.g., a processor), and the program can be stored in a readable storage medium, such as a read-only memory, a disk, or an optical disk. All or part of the steps in the above embodiments can also be implemented using one or more integrated circuits. Accordingly, each module in the above embodiments can be implemented in hardware, such as by using an integrated circuit to implement its corresponding function, or it can be implemented as a software functional module, such as by a processor executing a program / instruction stored in memory to implement its corresponding function. The embodiments of the present invention are not limited to any particular combination of hardware and software.
[0070] The above description is merely a preferred embodiment of the present invention. The embodiments are not intended to limit the scope of patent protection of the present invention. Therefore, any equivalent structural changes made based on the description and drawings of the present invention should also be included within the scope of protection of the present invention.
Claims
1. A method for improving the execution speed of blockchain smart contract transactions, characterized in that, When applying parallel execution of smart contracts in a blockchain system, the inherent read-write conflicts in the blockchain application due to rapid distribution through the same address lead to poor transaction execution efficiency. This includes the following steps: Step S1: Based on the application type of native read-write conflicts in the application, identify all global counters of global variable types that are prone to read-write conflicts; Step S2: Divide each identified global counter that is prone to causing read / write conflicts into N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter; wherein the number of sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter is determined based on the application type, traffic volume, and / or the number of microprocessors in the sender system; N is greater than or equal to 2; Step S3: When a blockchain smart contract transaction arrives, according to a predetermined random algorithm, the blockchain smart contract transaction is assigned to one of the corresponding sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter for processing, and the count value of the corresponding sub-counter is obtained; Step S4: When it is necessary to obtain the real-time value of the global counter, add the count values of the N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
2. The method for improving the execution speed of blockchain smart contract transactions according to claim 1, characterized in that, In step S2, if each of the global counters involves processing a single sending address, the single sending address is changed to multiple sending addresses, and each sending address corresponds to one of the sub-counters Sub-1counter, Sub-2 counter, ..., Sub-N counter.
3. The method for improving the transaction execution speed of blockchain smart contracts according to claim 2, characterized in that, The step S3, which assigns the blockchain smart contract transaction to the corresponding sub-counter for processing, is based on the hash value of the blockchain smart contract transaction sending address, and allocates the transaction to the corresponding sub-counter.
4. The method for improving the transaction execution speed of blockchain smart contracts according to claim 1, characterized in that, The application types of read-write conflicts include the distribution / airdrop of ERC-20 tokens, open finance DeFi projects, and the Mint application type of non-fungible tokens (NFTs).
5. The method for improving the transaction execution speed of blockchain smart contracts according to claim 1, characterized in that, The application types of read-write conflicts are determined through the analysis of smart contract code, the detection of conflicting fields by tools, and the identification of conflicts in transaction memory.
6. A blockchain smart contract transaction execution device, characterized in that it employs a multi-core, multi-threaded approach to process smart contract transactions in parallel, and is further characterized in that... When applying parallel execution of smart contracts in a blockchain system, scenarios where the distribution of data through the same address within a short period leads to native read-write conflicts in the blockchain application, resulting in poor transaction execution efficiency improvements, include: The identification module identifies all global counters of global variable types that are prone to read-write conflicts, based on the application type of native read-write conflicts in the application. The partitioning module divides each identified global counter that is prone to read / write conflicts into N sub-counters, Sub-1 counter, Sub-2 counter, ..., Sub-N counter; wherein the number of sub-counters, Sub-1 counter, Sub-2 counter, ..., Sub-N counter is determined based on the application type, traffic volume, and / or the number of microprocessors in the sender system; N is greater than or equal to 2; The transaction module, when a blockchain smart contract transaction arrives, allocates the blockchain smart contract transaction to one of the corresponding sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter according to a predetermined random algorithm for processing, and obtains the count value of the corresponding sub-counter; When the result generation module needs to obtain the real-time value of the global counter, it adds the count values of the N sub-counters Sub-1 counter, Sub-2 counter, ..., Sub-N counter.
7. A readable storage medium, characterized in that, It stores executable instructions for performing a method for improving the execution speed of blockchain smart contract transactions as described in any one of claims 1 to 5.
8. A data processing terminal, used as a consensus node in a P2P network, receiving, verifying consensus, and storing blocks in the P2P network, characterized in that, The data processing terminal includes: Readable storage medium; A processor that retrieves and executes executable instructions in the readable storage medium to perform a method for improving the execution speed of blockchain smart contract transactions as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Counting processing method and device, server and counting processing system
CN112131267A