Transaction processing method and device and storage medium
By utilizing multi-core processors to process transaction instructions in parallel and perform conflict detection in the blockchain network, the problem of low transaction execution efficiency in blockchain is solved, achieving more efficient and accurate transaction processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-21
AI Technical Summary
The serial execution of blockchain transactions leads to wasted computing resources and low efficiency in concurrent transaction execution, affecting user experience and system throughput.
By utilizing multiple cores of the central processing unit to process multiple transaction instructions in parallel through target nodes in the blockchain network, transaction conflict detection and result updates are performed to ensure the consistency and accuracy of transaction results.
It improves the execution efficiency and accuracy of blockchain transactions, makes full use of the computing resources of multi-core processors, and reduces transaction queuing time.
Smart Images

Figure CN121903601A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain, and more specifically, to a transaction processing method, apparatus, and storage medium. Background Technology
[0002] There are multiple blockchain nodes on a blockchain network. In order to ensure that the transaction execution results of each node are consistent, the nodes determine the order of transaction execution through a consensus protocol and execute transactions sequentially in a serial manner. After the previous transaction is completed and the block state is stable, the node will execute the next transaction.
[0003] However, with the increasing prevalence of blockchain applications and the growth in transaction volume, the traditional serial execution method has become a bottleneck restricting blockchain performance. Currently, mainstream CPUs have a multi-core architecture, supporting multi-threaded program execution. However, blockchain transactions are executed serially, meaning that at any given moment, only one CPU core is utilized. Smart contract execution is confined to a single core, and the computing resources of the remaining cores are not effectively utilized, resulting in a significant waste of computing power. This leads to low concurrent execution efficiency on the blockchain, easily causing excessively long transaction queuing times, reducing user experience and overall system throughput.
[0004] There is currently no effective solution to the problem of low execution efficiency of transactions on the blockchain in related technologies. Summary of the Invention
[0005] The main objective of this application is to provide a transaction processing method, apparatus, and storage medium to solve the problem of low execution efficiency of transactions on the blockchain in related technologies.
[0006] To achieve the above objectives, according to one aspect of this application, a transaction processing method is provided. The method includes: receiving multiple transaction instructions to be processed by a target node in a blockchain network; processing the multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; and updating the blockchain based on the multiple transaction results to obtain an updated blockchain.
[0007] Furthermore, the process of a target node in the blockchain network receiving multiple transaction instructions to be processed includes: receiving a target block of the blockchain according to the target node, wherein the target block is a block that has been confirmed as valid by the consensus algorithm; writing the target block into the blockchain storage corresponding to the target node according to the target node; and retrieving multiple transaction instructions from the blockchain storage according to the target node.
[0008] Furthermore, processing multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results includes: processing multiple transaction instructions in parallel using multiple cores of the target node's central processing unit to obtain multiple local transaction records, wherein there is a one-to-one correspondence between local transaction records and cores, and each local transaction record includes transaction account and balance information; performing transaction conflict detection on multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether there are identical transaction accounts in different local transaction records; if the conflict detection results show no conflict, the multiple local transaction records are identified as multiple transaction results.
[0009] Furthermore, transaction conflict detection is performed on multiple local transaction records. The conflict detection results include: when the transaction account data format is serial number format, determining a global transaction account list based on the transaction accounts of multiple local transaction records; determining the root node of the binary search tree based on the transaction account with index zero in the global transaction account list; generating subtrees of the binary search tree layer by layer according to the order of index increment based on the transaction accounts in the global transaction account list; during the generation of subtrees of the binary search tree, if any newly generated subtree has a duplicate node with the previous subtree, the conflict detection result is determined to be conflict-free; if no newly generated subtree has a duplicate node with the corresponding previous subtree, the conflict detection result is determined to be conflict-free.
[0010] Furthermore, transaction conflict detection is performed on multiple local transaction records, and the conflict detection results include: when the data format of the transaction account is not a serial number format, all transaction accounts are obtained; a list is constructed based on all transaction accounts, and the length of the list is obtained to obtain a first length; a set is constructed based on all transaction accounts, and the length of the set is obtained to obtain a second length; if the first length and the second length are equal, the conflict detection result is determined to be that there is no conflict, and if the first length and the second length are not equal, the conflict detection result is determined to be that there is a conflict.
[0011] Furthermore, after performing transaction conflict detection on multiple local transaction records and obtaining the conflict detection results, the method also includes: if the conflict detection results indicate that a conflict exists, using multiple cores of the target node's central processing unit to serially process multiple transaction instructions to obtain multiple serial processing results; and determining the multiple serial processing results as multiple transaction results.
[0012] Furthermore, updating the blockchain based on multiple transaction results includes: converting the transaction account and balance information in each local transaction record into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; and writing the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0013] To achieve the above objectives, according to another aspect of this application, a transaction processing apparatus is provided. The apparatus includes: a transaction receiving unit for receiving multiple transaction instructions to be processed from a target node in a blockchain network; a multi-core processing unit for processing the multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; and a transaction updating unit for updating the blockchain based on the multiple transaction results to obtain an updated blockchain.
[0014] Furthermore, the transaction receiving unit includes: a block receiving module, used to receive a target block of the blockchain according to the target node, wherein the target block is a block that has been confirmed as valid by the consensus algorithm; a block writing module, used to write the target block into the blockchain storage corresponding to the target node according to the target node; and an instruction acquisition module, used to acquire multiple transaction instructions from the blockchain storage according to the target node.
[0015] Furthermore, the multi-core processing unit includes: a parallel processing module, used to process multiple transaction instructions in parallel using multiple cores of the target node's central processing unit to obtain multiple local transaction records, wherein there is a one-to-one correspondence between local transaction records and cores, and each local transaction record includes transaction account and balance information; a conflict detection module, used to perform transaction conflict detection on multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether there are identical transaction accounts in different local transaction records; and a result determination module, used to determine multiple local transaction records as multiple transaction results if the conflict detection results indicate that there is no conflict.
[0016] Furthermore, the conflict detection module includes: a list acquisition submodule, used to determine a global list of trading accounts based on the trading accounts of multiple local trading records when the data format of the trading accounts is serial number format; a root node determination submodule, used to determine the root node of the binary search tree based on the trading account with index zero in the global trading account list; a subtree layer generation submodule, used to generate subtree layers of the binary search tree layer by layer based on the trading accounts in the global trading account list in ascending order of index; and a first conflict detection submodule, used to determine that a conflict exists if any newly generated subtree layer has a duplicate node with the previous subtree layer during the process of generating the subtree layers of the binary search tree, and to determine that no conflict exists if no duplicate node exists between any newly generated subtree layer and the corresponding previous subtree layer.
[0017] Furthermore, the conflict detection module includes: an account acquisition submodule, used to acquire all trading accounts when the data format of the trading accounts is not a serial number format; a first length acquisition submodule, used to construct a list based on all trading accounts and obtain the length of the list to obtain a first length; a second length acquisition submodule, used to construct a set based on all trading accounts and obtain the length of the set to obtain a second length; and a second conflict detection submodule, used to determine that there is no conflict if the first length and the second length are equal, and to determine that there is a conflict if the first length and the second length are not equal.
[0018] Furthermore, the multi-core processing unit also includes: a serial processing module, used to perform transaction conflict detection on multiple local transaction records and obtain conflict detection results, and then, if the conflict detection results indicate that a conflict exists, use multiple cores of the target node's central processing unit to serially process multiple transaction instructions to obtain multiple serial processing results; and a second result determination module, used to determine the multiple serial processing results as multiple transaction results.
[0019] Furthermore, the transaction update unit includes: a data conversion module, used to convert the transaction account and balance information in each local transaction record into key-value pair data, resulting in multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; and a world state writing module, used to write the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0020] According to another aspect of this application, a computer-readable storage medium is provided, which includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform any transaction processing method.
[0021] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for performing any transaction processing method.
[0022] According to another aspect of this application, a computer program product is provided, including computer instructions that, when executed by a processor, implement the steps of the transaction processing method described above.
[0023] In this embodiment of the application, multiple transaction instructions to be processed are received by a target node in the blockchain network; multiple transaction instructions are processed by multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; and the blockchain is updated based on the multiple transaction results to obtain an updated blockchain, thereby solving the technical problem of low execution efficiency of transactions on the blockchain in the prior art. Attached Figure Description
[0024] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0025] Figure 1 A hardware structure block diagram of a computer terminal for implementing a transaction processing method is shown.
[0026] Figure 2 This is a flowchart of a transaction processing method provided according to an embodiment of this application;
[0027] Figure 3 This is a schematic diagram of a transaction processing apparatus provided according to an embodiment of this application;
[0028] Figure 4 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0029] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0030] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0031] It should be noted that the information collected in this application (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of this data all comply with relevant laws, regulations, and standards, necessary confidentiality measures have been taken, and they do not violate public order and good morals. Corresponding access points are provided for users to choose to authorize or refuse. For example, interfaces are set up between this system and relevant users or organizations, providing users with corresponding access points to choose to agree to or refuse automated decision-making results; if the user chooses to refuse, the process proceeds to the expert decision-making stage.
[0032] Example 1
[0033] According to an embodiment of this application, a method embodiment for transaction processing is also provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0034] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a transaction processing method is shown. Figure 1As shown, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) 102 (processor 102 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0035] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0036] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the transaction processing method in the embodiments of this application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-mentioned transaction processing method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0037] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0038] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0039] Under the aforementioned operating environment, this application provides the following: Figure 2 The transaction processing method shown. Figure 2 This is a flowchart of a transaction processing method according to Embodiment 1 of this application.
[0040] In step S201, the target node in the blockchain network receives multiple transaction instructions to be processed.
[0041] Optionally, the target node can listen to communications on the blockchain network to receive the consensus-reached block (i.e., the target block) and obtain multiple transaction instructions within it. Transaction instructions are data commands used to instruct smart contracts on how to execute operations; they include information about the transacting parties and the transfer amount. A multi-core processor integrates multiple independent processor cores on a single physical chip, each capable of executing independent threads, thus achieving substantial parallel computing.
[0042] Step S202: Utilize multiple cores of the target node's central processing unit to process multiple transaction instructions and obtain multiple transaction results.
[0043] It should be noted that the number of cores is equal to the number of trading orders, so as to enable multiple trading orders to be processed in parallel using multiple cores.
[0044] Optionally, a thread pool can be constructed based on multiple cores, pre-creating a preset number of threads (the preset number equals the number of CPU cores). Each thread in the thread pool is used to process one transaction instruction, and the thread pool is used to process multiple transaction instructions in parallel. This embodiment assumes that there is no mutual dependency between the multiple transaction instructions. Instead, parallel transactions are performed first, and then transaction conflict detection is performed based on multiple local transaction records. If the conflict detection result is that there is no conflict, it means that there is no mutual dependency between the transaction instructions, and the multiple local transaction records are determined as multiple transaction results. If the conflict detection result is that there is a conflict, it means that there is a mutual dependency between the transaction instructions. At this time, the multiple cores of the target node's CPU can be used to process the multiple transaction instructions serially to obtain multiple serial processing results; the multiple serial processing results are determined as multiple transaction results.
[0045] For example, 16 trading instructions are executed in parallel by 16 threads. During execution, each thread is responsible for one trading instruction, using its own core resources to complete operations such as calling the smart contract and calculating the account balance, and storing the results in its own local transaction record.
[0046] Step S203: Update the blockchain based on the results of multiple transactions to obtain the updated blockchain.
[0047] Optionally, if the transaction result is a partial transaction record, the transaction account and balance information in each partial transaction record are obtained, and all transaction account and balance information is written into the world state of the blockchain; if the transaction result is a serial processing result, the latest generated serial processing result is obtained, and multiple transaction accounts and their corresponding balance information (i.e., covering all records of multiple transactions in the serial processing) in the latest generated serial processing result are written into the world state of the blockchain. It should be noted that the blockchain network includes multiple nodes, the target node is one of the nodes where the transaction is to be executed, and the multiple nodes are used to maintain the blockchain.
[0048] In summary, by receiving multiple transaction instructions from the target node and processing them using the multiple cores of the target node's central processing unit to obtain multiple transaction results, the system achieves the processing of multiple transaction instructions using the node's multiple cores without compromising the atomicity of each transaction instruction, thus improving the execution efficiency of transactions on the blockchain.
[0049] To improve the execution efficiency of transactions on the blockchain, optionally, receiving multiple transaction instructions to be processed by a target node in the blockchain network includes: receiving a target block of the blockchain according to the target node, wherein the target block is a block confirmed as valid by the consensus algorithm; writing the target block into the blockchain storage corresponding to the target node according to the target node; and retrieving multiple transaction instructions from the blockchain storage according to the target node.
[0050] Optionally, the consensus algorithm is an algorithm used to reach a consensus on the validity of blockchain transactions. The target node first listens to the network to receive blocks confirmed as valid by the consensus algorithm, i.e., the target block, and then writes the target block into the target node's blockchain storage as the basis for subsequent transaction execution. Blockchain storage refers to multiple transaction instructions on the blockchain system stored on non-volatile memory, organized into blocks. World state storage refers to the business data on the blockchain system stored on non-volatile memory, organized into key-value pairs, including transaction accounts, balance information, and other business data.
[0051] In summary, by receiving the target block of the blockchain based on the target node, writing the target block into the blockchain storage corresponding to the target node, and retrieving multiple transaction instructions from the blockchain storage based on the target node, the execution efficiency of transactions on the blockchain is improved.
[0052] To improve the execution efficiency of transactions on the blockchain, optionally, multiple transaction instructions can be processed using multiple cores of the target node's central processing unit to obtain multiple transaction results. This includes: processing multiple transaction instructions in parallel using multiple cores of the target node's central processing unit to obtain multiple local transaction records, wherein there is a one-to-one correspondence between local transaction records and cores, and each local transaction record includes transaction account and balance information; performing transaction conflict detection on the multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether there are identical transaction accounts in different local transaction records; and if the conflict detection results indicate that there is no conflict, the multiple local transaction records are identified as multiple transaction results.
[0053] Optionally, the transaction instructions in this embodiment can refer to transaction instructions for blockchain smart contracts. The access operations of the blockchain smart contract to the world state include write operations (i.e., writing key-value pairs into the world state storage) and read operations (i.e., reading the key-value pair corresponding to the specified key name from the world state storage). The world state storage is the business data on the blockchain system stored on non-volatile memory, organized in key-value pairs, containing transaction accounts, balance information, and other business data. The transaction instructions provide the purpose of the transaction, while the world state provides the corresponding transaction account and balance information. Multiple empty lists can be created locally on the target node, and the world state can be accessed in parallel by multiple cores to process multiple transaction instructions. The processing results (i.e., parallel processing results) corresponding to all transaction instructions are stored in the corresponding empty lists, resulting in multiple local transaction lists. Each local transaction list contains a local transaction record, which contains the transaction account and updated balance information, with a one-to-one correspondence with the core that executed it. These local transaction records are isolated and not integrated into the overall blockchain state. After all core transactions have been executed, the local transaction records from all local transaction lists can be written to the global transaction result list. For example, the global transaction result list might include [(Account 1, Balance 1), (Account 2, Balance 2), (Account 3, Balance 3), (Account 4, Balance 4)]. When processing transaction instructions in parallel, multiple instructions may attempt to modify the same transaction account simultaneously. This can lead to data inconsistency or violate the atomicity of transactions. Therefore, transaction conflict detection is necessary before determining local transaction records as the final transaction results. Transaction conflict detection checks whether different local transaction records modify the same transaction account. If the conflict detection result indicates no conflict, meaning all local transaction records modify different transaction accounts, then these local transaction records can be directly determined as the final transaction results.
[0054] In summary, by utilizing multiple cores, parallel processing of multiple transaction instructions is achieved, and transaction conflict detection avoids violating the atomicity of transactions. If a contract (i.e., the transaction corresponding to a certain transaction instruction) takes too long to execute or has an infinite loop, it prevents other transaction instructions from being affected, thereby improving the execution efficiency of transactions on the blockchain.
[0055] To improve the execution efficiency of transactions on the blockchain, optionally, transaction conflict detection is performed on multiple local transaction records. The conflict detection results include: when the transaction account data format is a sequence number format, determining a global transaction account list based on the transaction accounts of multiple local transaction records; determining the root node of the binary search tree based on the transaction account with index zero in the global transaction account list; generating subtrees of the binary search tree layer by layer according to the order of index increment based on the transaction accounts in the global transaction account list; during the generation of subtrees of the binary search tree, if any newly generated subtree has a duplicate node with the previous subtree, the conflict detection result is determined to be a conflict; if none of the newly generated subtrees have duplicate nodes with the corresponding previous subtree, the conflict detection result is determined to be a non-conflict.
[0056] For example, when the data format of a trading account is a serial number (e.g., the serial number of trading account 1001), different trading accounts correspond to different serial number values. A global trading account list can be determined based on the trading accounts of multiple local trading records, for example, [1001, 1002, 1003, 1004, 1005, 1006]. Trading account 1001 is selected as the root node of a binary search tree. Starting from the trading account with index 1, subtrees of the binary search tree are generated layer by layer. Each subtree can include a left child node and a right child node. During the creation of a newly generated subtree, the trading account in the newly generated subtree is compared with the trading account in the previous subtree layer (in this embodiment, the root node is the initial subtree layer) (i.e., the current trading account). If the value of the account to be added is less than the value of the current account, and the left child node of the newly generated subtree is empty, then the left child node of the newly generated subtree is constructed based on the value of the account to be added. If the left child node is not empty, it is used as the new current account, and the size relationship between the account to be added and the current account is re-compared. If the value of the account to be added is greater than the value of the current account, and the right child node of the newly generated subtree is empty, then the right child node of the newly generated subtree is constructed based on the value of the account to be added. If the right child node is not empty, it is used as the new current account, and the size relationship between the account to be added and the current account is re-compared. If, during the size comparison, there are cases where the values are equal, that is, there are duplicate nodes, then the conflict detection result is determined to be a conflict. If a binary search tree is constructed for all accounts in turn without duplicate nodes, then the conflict detection result is that there is no conflict.
[0057] In summary, when the transaction account data format is serial number format, a binary search tree is used to achieve efficient transaction conflict detection by using transaction accounts with multiple local transaction records, thereby improving the execution efficiency of transactions on the blockchain.
[0058] To improve the execution efficiency of transactions on the blockchain, optionally, transaction conflict detection is performed on multiple local transaction records. The conflict detection results include: obtaining all transaction accounts when the data format of the transaction accounts is not a sequence number format; constructing a list based on all transaction accounts and obtaining the length of the list to obtain a first length; constructing a set based on all transaction accounts and obtaining the length of the set to obtain a second length; if the first length and the second length are equal, the conflict detection result is determined to be that there is no conflict; if the first length and the second length are not equal, the conflict detection result is determined to be that there is a conflict.
[0059] For example, if the trading account data format is not a serial number format, extract all trading accounts and construct a Python list [abc, cbd, abd, bce, gdj, abc] based on these trading accounts, where each element in the list represents a trading account. The length of the list is obtained using the `len` function, resulting in a first length of 6. This allows the list to be converted into a set to quickly construct a set based on all trading accounts. The length of the set is then obtained using the `len` function, resulting in a second length of 5. Since the two lengths are not equal, a conflict is detected; otherwise, no conflict is detected.
[0060] In summary, when the transaction account data format is not serial number format, by constructing a list based on all transaction accounts, efficient transaction conflict detection is achieved, thereby improving the execution efficiency of transactions on the blockchain.
[0061] To improve the accuracy of transactions on the blockchain, optionally, after performing transaction conflict detection on multiple local transaction records and obtaining conflict detection results, the method further includes: if the conflict detection result indicates the existence of a conflict, using multiple cores of the target node's central processing unit to serially process multiple transaction instructions to obtain multiple serial processing results; and determining the multiple serial processing results as multiple transaction results.
[0062] Optionally, if the conflict detection result indicates a conflict, a fallback to serial processing can be implemented to avoid data inconsistencies caused by the same trading account being processed by more than two core processes simultaneously. Serial processing continues until all trading instructions are processed, with each serial processing step yielding a result. For example, before serial processing, initial information on six trading accounts and their balances is obtained (e.g., transactions from trading account A to trading account B, trading account C to trading account D, and trading account E to trading account F). This requires three processing steps. After the first processing... The process involves updating the balance information of transaction accounts a and b to obtain the first serial processing result. After the second processing, the balance information of transaction accounts c and d is updated to obtain the second serial processing result. After the third processing, the balance information of transaction accounts e and f is updated to obtain the third serial processing result. These multiple serial processing results are then identified as multiple transaction results. The world state of the blockchain can be written using the multiple transaction accounts and their corresponding balance information (which covers all records of multiple transactions in the serial processing) in the latest generated serial processing result (i.e., the third serial processing result), thereby updating the blockchain.
[0063] In summary, when the conflict detection result indicates the existence of a conflict, multiple transaction instructions are processed serially using multiple cores of the target node's central processing unit, resulting in multiple serial processing results. These multiple serial processing results are then identified as multiple transaction results, thereby improving the accuracy of transactions on the blockchain.
[0064] To improve the execution efficiency of transactions on the blockchain, optionally, updating the blockchain based on multiple transaction results includes: converting the transaction account and balance information in each local transaction record into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; and writing the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0065] For example, the transaction account can be used as the key, and the corresponding balance information of the transaction account can be used as the key value to generate key-value pair data corresponding to local transaction records, resulting in multiple key-value pair data. These multiple key-value pair data are then written into the world state store of the blockchain to update the blockchain's business data.
[0066] In summary, by converting the transaction account and balance information in each local transaction record into key-value pairs, multiple key-value pairs are obtained. These multiple key-value pairs are then written into the world state of the blockchain, thereby improving the execution efficiency of transactions on the blockchain.
[0067] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0068] Example 2
[0069] This application also provides a transaction processing apparatus. It should be noted that the transaction processing apparatus of this application can be used to execute the transaction processing method provided in this application. The transaction processing apparatus provided in this application is described below.
[0070] According to embodiments of this application, an apparatus for implementing the above-described transaction processing method is also provided, such as... Figure 3 As shown, the device includes:
[0071] The transaction receiving unit 301 is used to receive multiple transaction instructions to be processed by the target node in the blockchain network.
[0072] The multi-core processing unit 302 is used to process multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions.
[0073] The transaction update unit 303 is used to update the blockchain based on the results of multiple transactions to obtain the updated blockchain.
[0074] The transaction processing apparatus provided in this application embodiment receives multiple transaction instructions to be processed from a target node in the blockchain network through a transaction receiving unit 301. A multi-core processing unit 302 processes these instructions using multiple cores of the target node's central processing unit, resulting in multiple transaction results. The number of cores is equal to the number of transaction instructions. A transaction updating unit 303 updates the blockchain based on these transaction results, obtaining an updated blockchain. This solves the problem of low execution efficiency of transactions on the blockchain in related technologies, thereby improving the execution efficiency of transactions on the blockchain.
[0075] Optionally, in the transaction processing apparatus provided in this application embodiment, the transaction receiving unit 301 includes: a block receiving module, used to receive a target block of the blockchain according to the target node, wherein the target block is a block confirmed as valid by the consensus algorithm; a block writing module, used to write the target block into the blockchain storage corresponding to the target node according to the target node; and an instruction acquisition module, used to acquire multiple transaction instructions from the blockchain storage according to the target node.
[0076] Optionally, in the transaction processing apparatus provided in this application embodiment, the multi-core processing unit 302 includes: a parallel processing module, used to process multiple transaction instructions in parallel using multiple cores of the central processing unit of the target node to obtain multiple local transaction records, wherein the local transaction records and cores have a one-to-one correspondence, and each local transaction record includes transaction account and balance information; a conflict detection module, used to perform transaction conflict detection on the multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether there is the same transaction account in different local transaction records; and a result determination module, used to determine the multiple local transaction records as multiple transaction results when the conflict detection results indicate that there is no conflict.
[0077] Optionally, in the transaction processing apparatus provided in this application embodiment, the conflict detection module includes: a list acquisition submodule, used to determine a global transaction account list based on the transaction accounts of multiple local transaction records when the data format of the transaction account is a serial number format; a root node determination submodule, used to determine the root node of the binary search tree based on the transaction account with index zero in the global transaction account list; a subtree layer generation submodule, used to generate subtree layers of the binary search tree layer by layer according to the transaction accounts in the global transaction account list in the order of index increment; and a first conflict detection submodule, used to determine that there is a conflict if any newly generated subtree layer has a duplicate node with the previous subtree layer during the process of generating the subtree layers of the binary search tree, and to determine that there is no conflict if there is no duplicate node between all newly generated subtree layers and the corresponding previous subtree layer.
[0078] Optionally, in the transaction processing apparatus provided in this application embodiment, the conflict detection module includes: an account acquisition submodule, used to acquire all transaction accounts when the data format of the transaction accounts is not a serial number format; a first length acquisition submodule, used to construct a list based on all transaction accounts and acquire the length of the list to obtain a first length; a second length acquisition submodule, used to construct a set based on all transaction accounts and acquire the length of the set to obtain a second length; and a second conflict detection submodule, used to determine that there is no conflict if the first length and the second length are equal, and to determine that there is a conflict if the first length and the second length are not equal.
[0079] Optionally, in the transaction processing apparatus provided in this application embodiment, the multi-core processing unit 302 further includes: a serial processing module, used to perform transaction conflict detection on multiple local transaction records and obtain conflict detection results, and then, if the conflict detection results indicate that a conflict exists, use multiple cores of the central processing unit of the target node to perform serial processing on multiple transaction instructions to obtain multiple serial processing results; and a second result determination module, used to determine the multiple serial processing results as multiple transaction results.
[0080] Optionally, in the transaction processing apparatus provided in this application embodiment, the transaction update unit 303 includes: a data conversion module, used to convert the transaction account and balance information in each local transaction record into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; and a world state writing module, used to write the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0081] It should be noted that the transaction receiving unit 301, multi-core processing unit 302, and transaction updating unit 303 mentioned above correspond to steps S201 to S203 in Embodiment 1. The instances and application scenarios implemented by the units and corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules or units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above modules can also be part of the device and run in the computer terminal 10 provided in Embodiment 1.
[0082] Example 3
[0083] Embodiments of this application may provide an electronic device. Figure 4 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 4 As shown, the electronic device may include: one or more ( Figure 4 (Only one is shown) processor 402, memory 404, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0084] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the methods and apparatus in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the above-described methods. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0085] The processor can access information and applications stored in memory via a transmission device to execute the following steps: receiving multiple transaction instructions to be processed by a target node in the blockchain network; processing the multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; updating the blockchain based on the multiple transaction results to obtain an updated blockchain.
[0086] The processor can also invoke information and applications stored in the memory via the transmission device to perform the following steps: receiving a target block of the blockchain according to the target node, wherein the target block is a block confirmed as valid by the consensus algorithm; writing the target block into the blockchain storage corresponding to the target node according to the target node; and obtaining multiple transaction instructions from the blockchain storage according to the target node.
[0087] The processor can also access information and applications stored in memory via a transmission device to perform the following steps: Utilizing multiple cores of the target node's central processing unit to process multiple transaction instructions in parallel, resulting in multiple local transaction records. Each local transaction record corresponds one-to-one with a core, and each local transaction record includes transaction account and balance information. Transaction conflict detection is performed on the multiple local transaction records to obtain conflict detection results, which characterize whether the same transaction account exists in different local transaction records. If the conflict detection results indicate no conflict, the multiple local transaction records are identified as multiple transaction results.
[0088] The processor can also invoke information and applications stored in the memory via a transmission device to perform the following steps: when the data format of the transaction account is a serial number format, determine a global transaction account list based on the transaction accounts of multiple local transaction records; determine the root node of the binary search tree based on the transaction account with index zero in the global transaction account list; generate subtrees of the binary search tree layer by layer according to the transaction accounts in the global transaction account list in ascending order of index; during the generation of subtrees of the binary search tree, if any newly generated subtree has a duplicate node with the previous subtree, the conflict detection result is determined to be a conflict; if none of the newly generated subtrees have duplicate nodes with the corresponding previous subtree, the conflict detection result is determined to be a conflict.
[0089] The processor can also call the information and application stored in the memory through the transmission device to perform the following steps: when the data format of the trading account is not a serial number format, obtain all trading accounts; construct a list based on all trading accounts and obtain the length of the list to obtain a first length; construct a set based on all trading accounts and obtain the length of the set to obtain a second length; if the first length and the second length are equal, determine that there is no conflict; if the first length and the second length are not equal, determine that there is a conflict.
[0090] The processor can also call the information and application programs stored in the memory through the transmission device to perform the following steps: if the conflict detection result indicates that a conflict exists, use multiple cores of the target node's central processing unit to serially process multiple transaction instructions to obtain multiple serial processing results; determine the multiple serial processing results as multiple transaction results.
[0091] The processor can also invoke information and applications stored in the memory via the transmission device to perform the following steps: converting the transaction account and balance information in each local transaction record into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; writing the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0092] This application provides a transaction processing scheme. It involves a target node in a blockchain network receiving multiple transaction instructions; processing these instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, where the number of cores equals the number of transaction instructions; and updating the blockchain based on these transaction results to obtain an updated blockchain. This solves the technical problem of low transaction execution efficiency on existing blockchain technologies.
[0093] Those skilled in the art will understand that Figure 4The structure shown is for illustrative purposes only. Electronic devices can also be smartphones, tablets, handheld computers, mobile internet devices (MIDs), PADs, and other terminal devices. Figure 4 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 4 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 4 The different configurations shown.
[0094] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0095] Example 4
[0096] Embodiments of this application also provide a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the transaction processing method provided in Embodiment 1.
[0097] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0098] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: receiving multiple transaction instructions to be processed by a target node in the blockchain network; processing the multiple transaction instructions using multiple cores of the target node's central processing unit to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; updating the blockchain based on the multiple transaction results to obtain an updated blockchain.
[0099] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: receiving a target block of the blockchain according to the target node, wherein the target block is a block confirmed as valid by the consensus algorithm; writing the target block into the blockchain storage corresponding to the target node according to the target node; and obtaining multiple transaction instructions from the blockchain storage according to the target node.
[0100] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: processing multiple transaction instructions in parallel using multiple cores of the target node's central processing unit to obtain multiple local transaction records, wherein the local transaction records and cores have a one-to-one correspondence, and each local transaction record includes transaction account and balance information; performing transaction conflict detection on the multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether there are identical transaction accounts in different local transaction records; and determining the multiple local transaction records as multiple transaction results if the conflict detection results indicate that there is no conflict.
[0101] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: when the data format of the transaction account is a serial number format, determining a global transaction account list based on the transaction accounts of multiple local transaction records; determining the root node of the binary search tree based on the transaction account with index zero in the global transaction account list; generating subtrees of the binary search tree layer by layer according to the transaction accounts in the global transaction account list in ascending order of index; during the generation of subtrees of the binary search tree, if any newly generated subtree has a duplicate node with the previous subtree, the conflict detection result is determined to be a conflict; if none of the newly generated subtrees have duplicate nodes with the corresponding previous subtree, the conflict detection result is determined to be a conflict.
[0102] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: when the data format of the transaction accounts is not a serial number format, obtain all transaction accounts; construct a list based on all transaction accounts and obtain the length of the list to obtain a first length; construct a set based on all transaction accounts and obtain the length of the set to obtain a second length; if the first length and the second length are equal, determine that there is no conflict; if the first length and the second length are not equal, determine that there is a conflict.
[0103] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: if the conflict detection result indicates that a conflict exists, multiple transaction instructions are serially processed using multiple cores of the target node's central processing unit to obtain multiple serial processing results; and the multiple serial processing results are determined as multiple transaction results.
[0104] Optionally, in this embodiment, the computer-readable storage medium is further configured to store program code for performing the following steps: converting transaction account and balance information in each local transaction record into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; writing the multiple key-value pair data into the world state of the blockchain to update the blockchain.
[0105] This application also provides a computer program product that, when executed on a data processing device, is suitable for performing transaction processing method steps.
[0106] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0107] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0108] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0109] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0110] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0111] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0112] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A transaction processing method, characterized in that, include: The target node in the blockchain network receives multiple transaction instructions to be processed. The multiple transaction instructions are processed using multiple cores of the central processing unit of the target node to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; The blockchain is updated based on the results of the multiple transactions to obtain the updated blockchain.
2. The method according to claim 1, characterized in that, The target node in the blockchain network receives multiple transaction instructions to be processed, including: The target node receives the target block of the blockchain, wherein the target block is a block that has been confirmed as valid by the consensus algorithm; Write the target block into the blockchain storage corresponding to the target node according to the target node; The target node retrieves the multiple transaction instructions from the blockchain storage.
3. The method according to claim 1, characterized in that, The multiple transaction instructions are processed using multiple cores of the target node's central processing unit to obtain multiple transaction results, including: The multiple transaction instructions are processed in parallel using multiple cores of the central processing unit of the target node to obtain multiple local transaction records. The local transaction records and the cores are in a one-to-one correspondence, and each local transaction record includes transaction account and balance information. Transaction conflict detection is performed on the multiple local transaction records to obtain conflict detection results, wherein the conflict detection results are used to characterize whether the same transaction account exists in different local transaction records; If the conflict detection result indicates that there is no conflict, the plurality of local transaction records are identified as the plurality of transaction results.
4. The method according to claim 3, characterized in that, Perform transaction conflict detection on the multiple local transaction records, and obtain the conflict detection results including: When the data format of the transaction account is a serial number format, a global transaction account list is determined based on the transaction accounts of the multiple local transaction records; The root node of the binary search tree is determined based on the transaction account with index zero in the global transaction account list; Following the order of index addition, the subtree layers of the binary search tree are generated layer by layer based on the transaction accounts in the global transaction account list; During the process of generating the subtree layers of the binary search tree, if any newly generated subtree layer has a duplicate node with the previous subtree layer, the conflict detection result is determined to be a conflict; if none of the newly generated subtree layers have duplicate nodes with the corresponding previous subtree layer, the conflict detection result is determined to be a conflict-free.
5. The method according to claim 3, characterized in that, Perform transaction conflict detection on the multiple local transaction records, and obtain the conflict detection results including: If the data format of the transaction account is not a serial number format, obtain all the transaction accounts; Construct a list based on all the aforementioned trading accounts, and obtain the length of the list to obtain a first length; Construct a set based on all the aforementioned transaction accounts, and obtain the length of the set to obtain a second length; If the first length is equal to the second length, the conflict detection result is determined to be that there is no conflict; if the first length is not equal to the second length, the conflict detection result is determined to be that there is a conflict.
6. The method according to claim 3, characterized in that, After performing transaction conflict detection on the multiple local transaction records and obtaining the conflict detection results, the method further includes: If the conflict detection result indicates that a conflict exists, the multiple transaction instructions are processed serially using multiple cores of the target node's central processing unit to obtain multiple serial processing results. The multiple serial processing results are determined as the multiple transaction results.
7. The method according to claim 3, characterized in that, Updating the blockchain based on the results of the multiple transactions includes: The transaction account and balance information in each of the local transaction records are converted into key-value pair data to obtain multiple key-value pair data, wherein each key-value pair data includes a key name and a key value; The multiple key-value pairs are written into the world state of the blockchain to update the blockchain.
8. A transaction processing apparatus, characterized in that, include: A transaction receiving unit is used to receive multiple transaction instructions to be processed from a target node in the blockchain network. A multi-core processing unit is used to process the multiple transaction instructions using multiple cores of the central processing unit of the target node to obtain multiple transaction results, wherein the number of cores is equal to the number of transaction instructions; The transaction update unit is used to update the blockchain based on the results of the multiple transactions to obtain the updated blockchain.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the computer-readable storage medium is located to perform the transaction processing method according to any one of claims 1 to 7.
10. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, performs the transaction processing method according to any one of claims 1 to 7.
11. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the steps of the transaction processing method according to any one of claims 1 to 7.