Block chain parallel execution method and device, computer equipment and storage medium

By obtaining transactions in the blockchain system, the read -write collection collection, detection dependency relationship and perform parallel execution of the blockchain transaction solve the problem of slow execution of blockchain transactions, and improve the efficiency of transaction processing.

CN119379433APending Publication Date: 2025-01-28HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411320033.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-20
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

In blockchain systems where Ethereum virtual machine (EVM) is the execution environment, block transactions are usually executed in a serial manner, resulting in slower transaction execution.

Method used

By obtaining the first reading and writing collection generated by each transaction simulation, conflict detection is performed to obtain the dependent relationship between each transaction, and it is implemented parallel according to the dependency relationship.

Benefits of technology

The parallel execution of blockchain transactions reduced the conflict during parallel execution of transactions, and significantly increased the transaction volume per second (TPS) for blockchain processing transactions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119379433A_ABST
    Figure CN119379433A_ABST
Patent Text Reader

Abstract

The invention is suitable for the technical field of block chains, and provides a block chain parallel execution method and device, computer equipment and a storage medium, and the method comprises the steps: obtaining a first read-write set generated during simulation execution of each transaction; according to the first read-write set, performing conflict detection on each transaction to obtain a dependency relationship between the transactions; and executing each transaction in parallel according to the dependency relationship. According to the embodiment of the invention, the parallel execution of each transaction is realized according to the dependency relationship, so that the problem of conflicts during parallel execution of the transactions is solved, and the TPS of the block chain for processing the transactions is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of blockchain technology, and in particular, relates to a blockchain parallel execution method, device, computer equipment and storage medium. Background Art

[0002] In blockchain systems, especially those using EVM (Ethereum Virtual Machine) as the execution environment, block transactions are often executed in a serial manner, which means that transactions are executed one by one in the order they are in the block, and the transaction execution speed is slow. Summary of the invention

[0003] In view of this, embodiments of the present application provide a blockchain parallel execution method, apparatus, computer device, and storage medium to increase the speed of blockchain transaction execution.

[0004] A first aspect of an embodiment of the present application provides a blockchain parallel execution method, the blockchain parallel execution method comprising:

[0005] Get the first read-write set generated during the simulation execution of each transaction;

[0006] Perform conflict detection on each transaction according to the first read-write set to obtain a dependency relationship between each transaction;

[0007] According to the dependency relationship, each transaction is executed in parallel.

[0008] In one embodiment, before performing conflict detection on each transaction according to the first read-write set and obtaining the dependency relationship between each transaction, the method further includes:

[0009] Calculate the hash value of each transaction;

[0010] Hash mapping is performed on the first read-write set and the corresponding hash value of each transaction, so that the first read-write set is called through the hash value.

[0011] In one embodiment, performing conflict detection on each transaction according to the first read-write set to obtain the dependency relationship between each transaction includes:

[0012] According to the hash value of each transaction included in the transaction block, obtaining the first read-write set of each transaction;

[0013] The first read-write set of each transaction is traversed, conflict detection is performed on each transaction, and dependency relationships between each transaction are obtained.

[0014] In one embodiment, executing each transaction in parallel according to the dependency relationship includes:

[0015] Encapsulate each transaction contained in the transaction block into a corresponding transaction task;

[0016] Through multiple threads, the transaction tasks without the dependency are executed in parallel, and the transaction tasks with the dependency are executed in parallel in an orderly manner according to the dependency; wherein each thread is used to execute one transaction task;

[0017] After the transaction task is executed, a corresponding execution result is obtained, and the execution result includes a second read-write set and a transaction fee generated by executing the transaction task.

[0018] In one embodiment, after obtaining the corresponding execution result, the method further includes:

[0019] Verify the execution result, and repeat the failed transaction task until the repeated transaction task is successfully executed;

[0020] The second read-write set generated by the successfully executed transaction task is written into the global mapping table, so that other threads in the multiple threads can perceive the status of the transaction task by querying the global mapping table.

[0021] In one embodiment, the blockchain parallel execution method further includes:

[0022] The transaction fees of each transaction are settled uniformly according to the execution results of each transaction.

[0023] In one embodiment, executing each transaction in parallel according to the dependency relationship further includes:

[0024] Get the execution ledger;

[0025] Data is read from the global mapping table or the execution ledger so that each thread executes a corresponding transaction task.

[0026] The first aspect of the embodiments of the present application provides a blockchain parallel execution method, which obtains the first read-write set generated by each transaction included in the transaction block during the simulated execution; then, based on the first read-write set, conflicts are detected for each transaction to obtain the dependency relationship between each transaction; finally, based on the dependency relationship, each transaction is executed in parallel. In this way, the parallel execution of each transaction is achieved based on the dependency relationship, which is conducive to solving the problem of conflicts generated when transactions are executed in parallel, so that the number of transactions per second (TPS) when the blockchain processes transactions is significantly improved.

[0027] A second aspect of an embodiment of the present application provides a blockchain parallel execution device, the blockchain parallel execution device comprising:

[0028] A first acquisition module, used to acquire a first read-write set generated when each transaction simulation is executed;

[0029] A second acquisition module, configured to perform conflict detection on each transaction according to the first read-write set, and obtain a dependency relationship between each transaction;

[0030] The transaction execution module is used to execute each transaction in parallel according to the dependency relationship.

[0031] A third aspect of an embodiment of the present application provides a computer device, comprising 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 steps of the blockchain parallel execution method as described in the first aspect of the embodiment of the present application are implemented.

[0032] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the blockchain parallel execution method as described in the first aspect of the embodiment of the present application are implemented.

[0033] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0035] Figure 1 It is a schematic diagram of a blockchain parallel execution method provided in an embodiment of the present application;

[0036] Figure 2 It is a schematic diagram of another blockchain parallel execution method provided in an embodiment of the present application;

[0037] Figure 3 is a schematic diagram of a parallel executor provided in an embodiment of the present application;

[0038] Figure 4 It is a structural diagram of a blockchain parallel execution device provided in an embodiment of the present application;

[0039] Figure 5 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0041] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0042] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0043] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. "Multiple" means "two" or "more than two".

[0044] In blockchain systems, especially those using EVM as the execution environment, block transactions are often executed in a serial manner, which means that transactions are executed one by one in the order in which they appear in the block, and the transaction execution speed is limited. In addition, the BlockSTM (Block Software Transactional Memory) algorithm proposed by the Aptos project, although it can support optimistic parallelism of block transactions in the MoveVM virtual machine and Rust environment, cannot be directly applied to EVM-compatible blockchains. Moreover, pure optimistic parallel execution will cause a large number of transactions to be executed repeatedly when there are many transaction conflicts, wasting CPU (Central Processing Unit) resources, making it difficult to improve the TPS of blockchain transaction processing.

[0045] Therefore, the embodiment of the present application provides a blockchain parallel execution method, which obtains the first read-write set generated when each transaction is simulated and executed; then, based on the first read-write set, conflicts are detected for each transaction to obtain the dependency relationship between each transaction; finally, based on the dependency relationship, each transaction is executed in parallel. The present application implements the parallel execution of each transaction based on the dependency relationship, which is conducive to solving the problem of conflicts generated when transactions are executed in parallel, so that the TPS of blockchain processing transactions is significantly improved.

[0046] Embodiment 1

[0047] like Figure 1 As shown, the blockchain parallel execution method provided in the embodiment of the present application includes the following steps S1 to S3:

[0048] Step S1, obtain the first read-write set generated when each transaction simulation is executed, and proceed to step S2.

[0049] In the application, each EVM opcode has a fixed gas cost. For example, SSTORE (storage state variables) consumes more gas than SLOAD (load state variables). Gas is consumed when performing write operations and writing data. For example, modifying account balances, contract storage variables, etc. consumes gas. When performing read operations and reading data, gas is usually not consumed. However, there are exceptions, such as reading the storage variables of smart contracts.

[0050] In the application, for EVM to execute transactions, it is necessary to pre-purchase gas fees before the actual execution of the transaction, and settle the gas fees after the actual execution of the transaction, and pay them to the blocker. Therefore, in order to avoid the problem of insufficient gas fees when settling gas fees after the actual execution of the transaction, this application uses the estimateGas interface to obtain the transaction fee (gas fee) required to execute each transaction, so that the corresponding gas fee can be purchased before the transaction is actually executed, so that in the fee settlement stage after the transaction is executed, there are enough gas fees to pay to the blocker, thereby improving the success rate of transaction execution.

[0051] In the application, in the process of obtaining the transaction fee consumed for executing each transaction through the estimateGas interface, each transaction is simulated through the estimateGas interface, and the first read-write set generated during the simulation execution is obtained to perform dependency analysis between these transactions.

[0052] In the application, when simulating the execution of each transaction, the corresponding read set needs to be obtained, which includes but is not limited to the account balance that needs to be read, which is used to verify whether the sender has enough balance to complete the transaction; the account addresses of the two parties to the transaction need to be read, which are used to identify the accounts and ensure that the transaction occurs between the correct accounts; the account status of the transaction recipient needs to be read to ensure that the account is not frozen or is in a normal state, which helps prevent illegal accounts from participating in the transaction, etc. Then execute the corresponding transaction, and obtain the write set after the transaction is executed. The write set refers to the data set that is modified in the read set during the transaction execution process. Finally, the read set and write set of each transaction, that is, the first read-write set, are recorded.

[0053] In the application, EVM can also simulate the execution of each transaction through some smart contract debugging tools that provide simulated execution functions (for example, Remix IDE, Hardhat, etc.), or simulate the execution of each transaction by writing custom scripts, which is not limited here.

[0054] In one embodiment, before entering step S2, the method further includes:

[0055] Calculate the hash value of each transaction;

[0056] Hash mapping is performed on the first read-write set and the corresponding hash value of each transaction, so that the first read-write set is called through the hash value.

[0057] In the application, in Ethereum, each transaction has a unique hash value to identify the transaction for tracking in the blockchain. The hash value of the transaction is very important for ensuring the integrity and immutability of the transaction. Therefore, before entering step S2, it is also necessary to calculate the hash value of each transaction, and associate and bind the hash value of each transaction with the corresponding first read-write set through hash mapping to facilitate storage and calling the first read-write set through the hash value.

[0058] In the application, when calculating the hash value of each transaction, the transaction data of each transaction can be first converted into the RLP (Recursive Length Prefix) encoding format, and then the Keccak-256 hash function is used to perform hash calculation on the RLP-encoded transaction data. The result of the hash calculation is the hash value of the corresponding transaction.

[0059] In the application, you can also arbitrarily select a data structure for hash mapping, including but not limited to a dictionary, a hash table, a tree, etc. After calculating the hash value of each transaction, the hash value of each transaction is associated and bound with the first read-write set so that the first read-write set can be called through the transaction hash value.

[0060] In the application, the transaction block contains the hash value of each transaction. Before the transaction is sent to the blockchain for actual execution, the corresponding first read-write set can be obtained through the hash value, conflict detection can be performed, and the dependency relationship between each transaction can be obtained.

[0061] Step S2: Perform conflict detection on each transaction according to the first read-write set, obtain the dependency relationship between each transaction, and proceed to step S3.

[0062] In the application, when conflict detection is performed on each transaction, the read-write set of each transaction can be traversed to check whether there is a conflict. For example, if there is a write-write conflict between two transactions (that is, the two transactions try to write to the same address), the two transactions are considered to be in conflict; if there is a read-write conflict between two transactions (that is, one transaction reads the address that another transaction tries to write), the two transactions are considered to be in conflict, that is, there is a dependency relationship between the two transactions; if there is neither a write-write conflict, nor a read-write conflict, nor a read-read conflict between the two transactions (that is, the two transactions try to write to two different addresses, one transaction does not need to read the address that the other transaction tries to write, and the two transactions try to read two different addresses), the two transactions are considered to be non-conflicting, that is, there is no dependency relationship between the two transactions.

[0063] In the application, after conflict detection is performed on each transaction, the conflict detection result of each transaction can be obtained, and then the dependency relationship between each transaction can be determined according to the conflict detection result.

[0064] In the application, each transaction corresponds to a conflict detection result. For example, a transaction corresponds to a conflict detection result. This conflict detection result includes all transactions that conflict with this transaction. When this transaction does not conflict with any other transaction, the conflict detection result does not include any transaction.

[0065] In one embodiment, step S2 specifically includes:

[0066] According to the hash value of each transaction included in the transaction block, obtaining the first read-write set of each transaction;

[0067] The first read-write set of each transaction is traversed, conflict detection is performed on each transaction, and dependency relationships between each transaction are obtained.

[0068] In the application, after conflict detection is performed on each transaction, the dependency relationship between each transaction can also be represented by constructing a transaction dependency graph. For example, in the transaction dependency graph, if transaction A depends on transaction B (i.e., A must be executed after B is executed), an edge from B to A is added to the graph, indicating that transaction B has a dependency relationship with transaction A; if transaction B depends on transaction A (i.e., B must be executed after A is executed), an edge from A to B is added to the graph, indicating that transaction A has a dependency relationship with transaction B; if transaction A does not have a dependency relationship with transaction B, the edges from B to A and from A to B are deleted from the transaction dependency graph. It should be noted that the dependency relationship between each transaction can also be represented in other ways, which are not limited here.

[0069] Step S3: Execute each transaction in parallel according to the dependency relationship.

[0070] In the application, after obtaining the dependency relationship between each transaction, transactions without dependencies can be executed in parallel, and transactions with dependencies can be executed in parallel according to the order indicated in the dependencies. For example, transaction A depends on transaction B (that is, A must be executed after B). When executing in parallel, the thread executing transaction B will execute first, and after transaction B is completed, the thread executing transaction A will execute again, thereby reducing the number of repeated executions of transactions with dependencies during parallel execution, which is beneficial to improving the utilization of CPU resources.

[0071] For example, transaction A and transaction C both depend on transaction B, and there is no dependency between transaction A and transaction C (that is, A and C must be executed after B). When executing in parallel, the thread executing transaction B executes first. After transaction B is completed, the thread executing transaction A and the thread executing transaction C are executed in parallel, reducing the number of repeated executions of transactions A and C.

[0072] In one embodiment, Figure 2 Said step S3 comprises the following steps S31 to S33:

[0073] Step S31, encapsulating each transaction contained in the transaction block into a corresponding transaction task;

[0074] Step S32: executing the transaction tasks without the dependency relationship in parallel through multiple threads, and executing the transaction tasks with the dependency relationship in parallel in an orderly manner according to the dependency relationship;

[0075] Step S33: After the transaction task is executed, a corresponding execution result is obtained, wherein the execution result includes a second read-write set and a transaction fee generated by executing the transaction task.

[0076] In step S31, each transaction is encapsulated as a transaction task. In step S32, each transaction task is assigned to a thread for execution. During the parallel execution of multiple threads, transaction tasks that have no dependencies can be directly executed in parallel, and transaction tasks that have dependencies are executed in parallel in the order of dependencies (i.e., transaction tasks that have dependencies will be executed in parallel after the transactions they depend on are completed), thereby reducing the number of repeated executions of transactions with dependencies during parallel execution, which is beneficial to improving the utilization of CPU resources.

[0077] For example, there are four transactions A, B, C, and D, among which transaction A depends on transaction B (that is, A must be executed after B), and there is no dependency between transaction B and transaction C, transaction C and transaction D, and transaction B and transaction D. When executed in parallel, the thread executing transaction D, the thread executing transaction C, and the thread executing transaction B can be directly executed in parallel, and after transaction B is completed, the thread executing transaction A will be executed again, that is, the execution of the four transactions is completed without repeated execution.

[0078] In the application, each thread is used to execute a transaction task. After each transaction task is completed, an execution result is generated regardless of whether the transaction is executed successfully or failed. The execution result includes but is not limited to the second read-write set and transaction fee generated by executing the transaction task.

[0079] In the application, the second read-write set may be the same as or different from the first read-write set. If a transaction has no dependency relationship with all other transactions, the second read-write set is the same as the first read-write set. If a transaction has a dependency relationship with one or more other transactions, the second read-write set is different from the first read-write set.

[0080] In one embodiment, after step S3, the following steps are included:

[0081] Verify the execution result, and repeat the failed transaction task until the repeated transaction task is successfully executed;

[0082] The second read-write set generated by the successfully executed transaction task is written into the global mapping table, so that other threads in the multiple threads can perceive the status of the transaction task by querying the global mapping table.

[0083] In the application, since the dependency relationship between each transaction obtained through the first read-write set may have errors (that is, the obtained dependency relationship is not completely accurate), therefore, after each transaction task is actually executed, it is necessary to analyze the second read-write set generated by executing the transaction task to know whether there is actually a conflict between the transaction task and other transaction tasks. If there is a conflict, the execution result of the transaction task is discarded, and the transaction task is placed in the queue of execution tasks waiting for repeated execution. It can be understood that after repeated execution, the execution result of the repeated transaction task also needs to be verified again to ensure that the transaction is successfully executed.

[0084] In the application, by verifying the execution result of the transaction task, the execution status of the transaction task can be obtained. For the transaction task that failed to execute, the corresponding failure reason can be obtained by verifying the execution result. If the execution failure is caused by the dependency between the transaction task and other transaction tasks, the dependency of the transaction can be updated, and then the transaction task is repeated, which is conducive to ensuring the success rate of transaction execution. After repeated execution, an execution result will also be obtained to indicate the execution status of the repeated transaction task. Correspondingly, after repeated execution, the execution result of the repeated transaction task also needs to be verified again. In the application, by verifying the execution result of the transaction task, for the transaction task that was successfully executed, the second read-write set generated by it can be written into the global mapping table, so that other threads can obtain the status of transaction execution by reading the global mapping table.

[0085] In the application, the global mapping table is a data structure for storing key-value pairs, where each key is unique and mapped to a specific value. For example, when the second read-write set is written into the global mapping table, the hash value is also written at the same time. At this time, the hash value of each transaction corresponds to the second read-write set one by one. It should be noted that the first read-write set obtained when simulating the execution of each transaction and the second read-write set obtained when actually executing each transaction do not share the same global mapping table. The global mapping table where the first read-write set is located is used for conflict analysis, and the global mapping table where the second read-write set is located is used to guide the perception of transaction data for parallel execution.

[0086] In applications, such as Figure 3 In the diagram of a parallel executor of a virtual machine shown in FIG, MVHashMap can be regarded as a global mapping table, key represents the account address and operation type of the operation, TxnIndexCells is used to store the write data generated when a transaction task is executed, and WriteCell represents the data of a write operation, including the flag, execution times, and actual written data. Specifically, the structure used to manage transaction memory in a block software is as follows:

[0087] type MVHashMapstruct{#define a structure type MVHashMap;

[0088] lock sync.Mutex# is used to synchronize access to the entire MVHashMap;

[0089] m cmap.ConcurrentMap[string,*TxnIndexCells]#ConcurrentMap is used to store key-value pairs;

[0090] }

[0091] type TxnIndexCellsstruct{#Indicates the set of data written for a specific key (account address and operation type combination);

[0092] rwsync.RWMutex# is used to synchronize read and write access to data in TxnIndexCells;

[0093] The tm*treemap.Map#TxnIndexCells object contains a treemap, which is used to store the written data generated when executing a transaction task;

[0094] }

[0095] type WriteCellstruct{#Represents the data of a write operation, including the flag, execution times and actual written data;

[0096] flag uint#flag is used to indicate the status of writing data;

[0097] incarnation int # is used to indicate the number of times a transaction is executed;

[0098] data interface{}# represents the actual written data;

[0099] }.

[0100] In such Figure 3 In the parallel executor diagram shown in the figure, the overall execution process is managed through three pipelines: chTasks, chResult, and chSettle. When the transaction block is input into the block of the parallel executor, the transactions included in the block will be encapsulated into execution tasks one by one, such as tx1, tx2, ..., txn;

[0101] The encapsulated execution tasks are managed by the chTasks pipeline and assigned to the corresponding (n) threads. For example, tx1 corresponds to thread 1, tx2 corresponds to thread 2, ..., txn corresponds to thread n.

[0102] Each thread executes the transaction task through Execute. After the execution is completed, each thread passes the corresponding execution result to the chResults pipeline and proceeds to the next step;

[0103] Through the chResults pipeline, the execution result of each thread is passed to Step for verification. The transaction tasks that pass the verification enter the chSettle pipeline.

[0104] During the verification process, if the (second) read-write set of a transaction does not conflict with the read-write set of other transactions, and all transactions before the transaction have been executed and verified, it means that the transaction will not change again, and the write set generated by it can be marked as completed; if the (second) read-write set of a transaction conflicts with the read-write set of other transactions, it means that the transaction depends on other transactions, and its dependency relationship needs to be updated, and the write set generated by it is marked as estimated (if other threads read estimated data during the execution of transaction tasks, they need to be aborted), and the task is re-added to chTasks for repeated execution;

[0105] Through the chSettle pipeline, the verified execution results of each thread are passed to Settle, and the write data of the latest execution of each transaction task is written into the final ledger for storage;

[0106] When a thread senses that a transaction task has entered Settle, it means that the transaction task has been executed and passed the verification, all transaction tasks before the transaction task have also been executed, and the transaction task will no longer be executed repeatedly. Therefore, it can be considered that the transaction task has been executed deterministically, and the second read-write set generated when the transaction task is executed will no longer change.

[0107] In one embodiment, step S32 includes:

[0108] Get the execution ledger;

[0109] Read data from the global mapping table or the execution ledger so that each thread can execute the corresponding transaction task. Figure 3 For the parallel executor shown in the figure, the current execution ledger will be passed in as cleanDB during initialization. The execution ledger status is the ledger status after the previous block is submitted, and all subsequent operations depend on the execution ledger. For each task encapsulated by a transaction, an execution ledger will be copied from cleanDB through deep copy. In Execute, each thread can execute the corresponding transaction task by reading and writing the execution ledger.

[0110] In the application, the execution ledger refers to the source of data that needs to be read when the thread executes a transaction task.

[0111] In the application, when obtaining the data required by each thread to execute the transaction task, it is necessary to first determine whether there is data to be read in the global mapping table; if there is data to be read in the global mapping table, the required data is read from the global mapping table and the corresponding transaction task is executed; if there is no data to be read in the global mapping table, the required data is read from the execution ledger and the corresponding transaction task is executed.

[0112] It should be noted that the data in the execution ledger has not been modified before the transaction task of this block is executed (that is, the state of the execution ledger is the state of the ledger after the previous block is submitted). When a transaction task is executed, it is often necessary to sense whether other transaction tasks have modified the data needed by the transaction task before the transaction task is executed (that is, the (second) write set). Therefore, before reading the ledger data, the transaction task will first read the required data from the global mapping table. Only when the required data cannot be read from the global mapping table will it read the required data from the execution ledger.

[0113] In the application, when a thread executes a transaction task, the data that needs to be read includes but is not limited to the account balance, account address, transaction amount of the transaction sender, and the account address, account status and other data of the transaction receiver.

[0114] In one embodiment, after step S3, the method further includes:

[0115] The transaction fees of each transaction are settled uniformly according to the execution results of each transaction.

[0116] In the application, compared with the current method of settling transaction fees (gas fees) immediately after each transaction is executed, this application adapts the EVM execution logic, adds the Apply Message No Fee Burn Or Tip method, records the transaction fees (gas fees) that need to be settled for each transaction in the execution result, and settles the transaction fees (gas fees) of each transaction in a unified manner after the parallel execution is completed, thereby reducing the transaction conflict problem caused by the gas fee calculation.

[0117] In applications, for Figure 3 For the parallel executor shown in the figure, when all the transaction tasks passed in have completed the Settle operation, it indicates that all the transaction tasks of the block have been executed. At this time, the transaction fees (gas fees) generated by all the transaction tasks during the execution process can be collected, and then a unified settlement is performed (if not settled uniformly, it is assumed that there are read-write and / or write-write conflicts between all transactions), and after settlement, the transaction fees (gas fees) are updated to the final ledger to complete the transaction execution process of the block.

[0118] Before each transaction is executed, the application performs corresponding conflict detection by simulating the first read-write set generated during execution, obtains the dependency relationship between each transaction, and then realizes the parallel execution of each transaction according to the dependency relationship, reduces the conflict of parallel execution of transactions, and significantly improves the TPS of blockchain transaction processing. In addition, the conflicting transactions are repeatedly executed to ensure the success rate of transaction execution. In addition, after the parallel execution is completed, the transaction fee (gas fee) of each transaction is uniformly settled, which can effectively solve the transaction conflict problem caused by gas fee calculation.

[0119] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0120] Embodiment 2

[0121] The present application also provides a blockchain parallel execution device for executing the method steps in the above blockchain parallel execution method embodiment. The device can be a virtual appliance in a computer device, which is run by a processor of the computer device, or it can be the computer device itself.

[0122] like Figure 4 As shown, the blockchain parallel execution device 100 provided in the embodiment of the present application includes:

[0123] A first acquisition module 101 is used to acquire a first read-write set generated when each transaction simulation is executed;

[0124] A second acquisition module 102, configured to perform conflict detection on each transaction according to the first read-write set, and obtain a dependency relationship between each transaction;

[0125] The transaction execution module 103 is used to execute each transaction in parallel according to the dependency relationship.

[0126] In one embodiment, the blockchain parallel execution device 100 further includes a mapping module 104, which is used to: calculate the hash value of each transaction;

[0127] Hash mapping is performed on the first read-write set and the corresponding hash value of each transaction, so that the first read-write set is called through the hash value.

[0128] In one embodiment, the second acquisition module 102 is further configured to:

[0129] According to the hash value of each transaction included in the transaction block, obtaining the first read-write set of each transaction;

[0130] The first read-write set of each transaction is traversed, conflict detection is performed on each transaction, and dependency relationships between each transaction are obtained.

[0131] In one embodiment, the transaction execution module 103 is further configured to:

[0132] Encapsulate each transaction contained in the transaction block into a corresponding transaction task;

[0133] Through multiple threads, the transaction tasks without the dependency are executed in parallel, and the transaction tasks with the dependency are executed in parallel in an orderly manner according to the dependency; wherein each thread is used to execute one transaction task;

[0134] After the transaction task is executed, a corresponding execution result is obtained, and the execution result includes a second read-write set and a transaction fee generated by executing the transaction task.

[0135] In one embodiment, the transaction execution module 103 is further configured to:

[0136] Verify the execution result, and repeat the failed transaction task until the repeated transaction task is successfully executed;

[0137] The second read-write set generated by the successfully executed transaction task is written into the global mapping table, so that other threads in the multiple threads can perceive the status of the transaction task by querying the global mapping table.

[0138] In one embodiment, the blockchain parallel execution device 100 further includes a settlement module 105, which is used to:

[0139] The transaction fees of each transaction are settled uniformly according to the execution results of each transaction.

[0140] In one embodiment, the transaction execution module 103 is further configured to:

[0141] Get the execution ledger;

[0142] Data is read from the global mapping table or the execution ledger so that each thread executes a corresponding transaction task.

[0143] In application, each unit in the above device may be a software program module, or may be implemented by different logic circuits integrated in a processor or independent physical components connected to a processor, or may be implemented by multiple distributed processors.

[0144] Embodiment 3

[0145] like Figure 5 As shown, the embodiment of the present application further provides a computer device 200, including: at least one processor 201 ( Figure 5 Only one processor is shown in the figure), memory 202, and a computer program 203 stored in the memory 202 and executable on at least one processor 201. When the processor 201 executes the computer program 203, the steps in the above-mentioned method embodiments are implemented.

[0146] In applications, computer devices may include but are not limited to processors, memory, Figure 5 It is only an example of a computer device and does not constitute a limitation of the computer device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, such as human-computer interaction devices, input and output devices, network access devices, etc. The network access device may include a communication module for the computer device to communicate with the user terminal.

[0147] In applications, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. For example, the processor may be a timing controller (TCON). A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0148] In applications, the memory may be an internal storage unit of a computer device in some embodiments, such as a hard disk or memory of the computer device. The memory may also be an external storage device of the computer device in other embodiments, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device. The memory may also include both an internal storage unit of the computer device and an external storage device. The memory is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as program code of a computer program. The memory may also be used to temporarily store data that has been output or is to be output.

[0149] In the application, the communication module can be set as any device that can directly or indirectly perform long-distance wired or wireless communication with the user terminal according to actual needs. For example, the communication module can provide communication solutions including wireless local area networks (WLAN) (such as Wi-Fi networks), Bluetooth, Zigbee, mobile communication networks, global navigation satellite systems (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc., which are applied to network devices. The communication module may include an antenna, and the antenna may have only one array element or an antenna array including multiple array elements. The communication module can receive electromagnetic waves through the antenna, frequency modulate and filter the electromagnetic wave signals, and send the processed signals to the processor. The communication module can also receive the signal to be sent from the processor, frequency modulate and amplify it, and convert it into electromagnetic waves for radiation through the antenna.

[0150] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / modules are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0151] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned function allocation can be completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The functional modules in the embodiment can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules. In addition, the specific names of the functional modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0152] The embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0153] An embodiment of the present application provides a computer program product. When the computer program product is executed on a computer device, the computer device can implement the steps in the above-mentioned various method embodiments.

[0154] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include at least: any entity or device capable of carrying the computer program code to a computer device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.

[0155] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0156] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0157] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0158] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0159] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A blockchain parallel execution method, characterized in that: The blockchain parallel execution method comprises: Get the first read-write set generated during the simulation execution of each transaction; Perform conflict detection on each transaction according to the first read-write set to obtain a dependency relationship between each transaction; According to the dependency relationship, each transaction is executed in parallel.

2. The blockchain parallel execution method according to claim 1, characterized in that: Before performing conflict detection on each transaction according to the first read-write set to obtain the dependency relationship between each transaction, the method further includes: Calculate the hash value of each transaction; Hash mapping is performed on the first read-write set and the corresponding hash value of each transaction, so that the first read-write set is called through the hash value.

3. The blockchain parallel execution method according to claim 2, characterized in that: The performing conflict detection on each transaction according to the first read-write set to obtain the dependency relationship between each transaction includes: According to the hash value of each transaction included in the transaction block, obtaining the first read-write set of each transaction; The first read-write set of each transaction is traversed, conflict detection is performed on each transaction, and dependency relationships between each transaction are obtained.

4. The blockchain parallel execution method according to claim 2, characterized in that: The executing each transaction in parallel according to the dependency relationship includes: Encapsulate each transaction contained in the transaction block into a corresponding transaction task; Through multiple threads, the transaction tasks without the dependency are executed in parallel, and the transaction tasks with the dependency are executed in parallel in an orderly manner according to the dependency; wherein each thread is used to execute one transaction task; After the transaction task is executed, a corresponding execution result is obtained, and the execution result includes a second read-write set and a transaction fee generated by executing the transaction task.

5. The blockchain parallel execution method according to claim 4, characterized in that: After obtaining the corresponding execution results, it also includes: Verify the execution result, and repeat the failed transaction task until the repeated transaction task is successfully executed; The second read-write set generated by the successfully executed transaction task is written into the global mapping table, so that other threads in the multiple threads can perceive the status of the transaction task by querying the global mapping table.

6. The blockchain parallel execution method according to claim 4 or 5, characterized in that: The blockchain parallel execution method further includes: The transaction fees of each transaction are settled uniformly according to the execution results of each transaction.

7. The blockchain parallel execution method according to claim 5, characterized in that: The executing each transaction in parallel according to the dependency relationship further includes: Get the execution ledger; Data is read from the global mapping table or the execution ledger so that each thread executes a corresponding transaction task.

8. A blockchain parallel execution device, characterized in that: The blockchain parallel execution device comprises: A first acquisition module, used to acquire a first read-write set generated when each transaction simulation is executed; A second acquisition module, configured to perform conflict detection on each transaction according to the first read-write set, and obtain a dependency relationship between each transaction; The transaction execution module is used to execute each transaction in parallel according to the dependency relationship.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the blockchain parallel execution method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the blockchain parallel execution method as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Federal learning-oriented block chain mixed granularity parallel transaction processing method

    CN120031662A

  • A blockchain hybrid granularity parallel transaction processing method for federated learning

    CN120031662B