Block chain transaction execution method and device, electronic equipment and readable medium
By establishing an isolated transaction pool in the blockchain, the problem of repeated attempts to execute transactions in parallel is solved, the reliability and trust of the blockchain system are improved, and the certainty of the transaction sequence is achieved.
Patent Information
- Application Number
- CN202311562393.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-21
- Publication Date
- 2025-05-23
AI Technical Summary
In blockchain, the process of block-producing nodes repeatedly trying to execute transactions in parallel is wasted resources, and the order of transactions determined for the same batch of transactions is not necessarily the same, resulting in an increase in uncertainty in the blockchain and reducing the reliability and trust of the entire blockchain system.
By establishing a transaction pool of non-cross-contract transactions and a transaction pool of cross-contract transactions in the blockchain, we ensure that the data of different smart contracts is completely isolated, so that transactions are executed in parallel without conflict between different smart contracts in the blockchain, and the order of parallel execution of transactions is directly determined.
It improves the reliability and trust of the blockchain system, avoids resource waste, and ensures the certainty of transaction order, reducing the uncertainty of the blockchain.
Smart Images

Figure CN120031561A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and readable medium for executing blockchain transactions. Background Art
[0002] The transaction execution order in the blockchain refers to a data structure used to process the transaction execution order in blockchain technology. It is usually a directed acyclic structure in which transactions on different branches can be executed in parallel.
[0003] In the related technology, the block-producing node will repeatedly execute the transactions to be put on the chain in parallel until there are no read-write conflicts, thereby determining the transaction execution order of the blocks to be put on the chain, so that other slave nodes can execute transactions in parallel according to this transaction execution order.
[0004] However, there is a certain waste of resources in the process of block-producing nodes repeatedly trying to execute transactions in parallel, and the transaction order of the same batch of transactions may not be the same each time, which increases the uncertainty of the blockchain and reduces the reliability and trust of the entire blockchain system. Summary of the invention
[0005] Based on the above technical problems, the present application provides a method, device, electronic device and readable medium for executing blockchain transactions to improve the reliability and trust of the entire blockchain system.
[0006] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0007] According to one aspect of an embodiment of the present application, a method for executing a blockchain transaction is provided, comprising:
[0008] According to a preset concurrency number N, N transaction pools are determined from a transaction pool set of the blockchain, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and the second transaction pool corresponds to a smart contract that executes a cross-contract transaction;
[0009] Obtaining transactions to be executed from the N transaction pools respectively;
[0010] Parallel execution of pending transactions from different transaction pools to obtain the transaction results of each pending transaction;
[0011] A block to be chained is constructed according to the transaction results of each transaction to be executed, and the block to be chained is chained in the blockchain.
[0012] According to one aspect of an embodiment of the present application, a blockchain transaction execution device is provided, including:
[0013] The transaction pool determination module is configured to determine N transaction pools from the transaction pool set of the blockchain according to a preset concurrency number N, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and the second transaction pool corresponds to a smart contract that executes a cross-contract transaction;
[0014] A transaction acquisition module, configured to acquire transactions to be executed from the N transaction pools respectively;
[0015] A transaction execution module, configured to execute pending transactions from different transaction pools in parallel, and obtain transaction results of each pending transaction;
[0016] The block construction module is configured to construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
[0017] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module is specifically configured to: determine the first N transaction pools in the transaction pool sorting according to a preset concurrency number N and the transaction pool sorting of the transaction pools in the transaction pool set, wherein the transaction pool sorting is determined by sorting in reverse order according to the most recent transaction output time of each transaction pool in the transaction pool set.
[0018] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module is specifically configured to: determine the transaction acquisition amount corresponding to each of the N transaction pools according to a preset transaction number threshold; obtain transactions to be executed from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool; update the latest transaction output time of the N transaction pools according to the current moment, and update the ranking of the N transaction pools in the transaction pool ranking.
[0019] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module is specifically configured as follows: if the number of transactions to be executed obtained from the N transaction pools reaches the transaction number threshold or the N transaction pools are all empty, then stop obtaining transactions to be executed from the N transaction pools; if the number of transactions to be executed obtained from the N transaction pools does not reach the transaction number threshold and any transaction pool of the blockchain is not empty, then according to the current transaction pool sorting, re-determine the top N transaction pools in the transaction pool sorting, and obtain transactions to be executed from the re-determined top N transaction pools until the number of transactions reaches the transaction number threshold or the transaction pools of the blockchain are all empty.
[0020] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module is specifically configured as follows: if the number of transactions to be executed obtained from the N transaction pools does not reach the transaction number threshold and one of the N transaction pools is not empty, then continue to obtain transactions to be executed from the non-empty transaction pools among the N transaction pools until the number of transactions reaches the transaction number threshold or the N transaction pools are all empty.
[0021] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is specifically configured to: construct N-1 first cache pools corresponding to N-1 first transaction pools and a second cache pool corresponding to the second transaction pool according to the preset concurrency number N; obtain transactions to be executed from the N-1 first transaction pools and add them to the corresponding first cache pools; obtain transactions to be executed from the second transaction pool and add them to the second cache pool.
[0022] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is specifically configured to: in the process of executing pending transactions from the N-1 first cache pools, perform cross-contract transaction detection on each pending transaction; if any pending transaction is detected to be a cross-contract transaction, transfer the detected cross-contract transaction to the second cache pool; delete the first transaction pool corresponding to any pending transaction, and mark other transactions of any pending transaction calling a smart contract as cross-contract transactions.
[0023] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is specifically configured to: package the pending transactions in the N-1 first cache pools and the second cache pool into pre-chain blocks; broadcast the pre-chain blocks to other blockchain nodes in the blockchain, so that the other blockchain nodes can execute the pending transactions according to the transaction order in the pre-chain blocks.
[0024] In some embodiments of the present application, based on the above technical solution, pending transactions from different transaction pools are executed in parallel according to the transaction order in the pre-chain block; the block construction module is specifically configured to: construct a pending chain block according to the transaction results of each pending transaction, and obtain the parallel execution order of each pending transaction; broadcast the pending chain block and the parallel execution order to other blockchain nodes in the blockchain, so that the other blockchain nodes can verify the pending chain block and the parallel execution order according to the execution result of the pre-chain block; and according to the verification result fed back by the other blockchain nodes, the pending chain block is chained in the blockchain.
[0025] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is also configured to: receive a blockchain transaction sent by a client; and according to the smart contract called in the blockchain transaction, add the blockchain transaction to a transaction pool corresponding to the smart contract.
[0026] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is also configured to: if the transaction pool corresponding to the called smart contract is the first transaction pool, then check the contract call relationship of the smart contract called in the blockchain transaction; if the contract call relationship indicates that the blockchain transaction is a cross-contract transaction, then transfer all transactions in the first transaction pool corresponding to the smart contract to the second transaction pool; establish a corresponding relationship between the smart contract and the second transaction pool and delete the first transaction pool corresponding to the smart contract.
[0027] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute a method for executing a blockchain transaction in the above technical solution by executing the executable instructions.
[0028] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a method for executing a blockchain transaction in the above technical solution is implemented.
[0029] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the execution method of the blockchain transaction provided in the above-mentioned various optional implementations.
[0030] In an embodiment of the present application, by establishing a transaction pool for non-cross-contract transactions and a transaction pool for cross-contract transactions, the data of different smart contracts in the blockchain are completely isolated, thereby ensuring that non-cross-contract transactions and non-cross-contract transactions and cross-contract transactions can be executed in parallel without conflict. Therefore, the order of parallel execution of transactions can be directly determined at one time, and there is no need to use a brute force loop to construct the transaction execution order, which helps to improve the reliability and trust of the entire blockchain system.
[0031] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0033] Figure 1 The system architecture of the execution scheme applied to blockchain transactions according to the embodiment of the present application.
[0034] Figure 2 This is a schematic diagram of a blockchain network in an embodiment of the present application.
[0035] Figure 3 This is a schematic diagram of blocks in a blockchain network in an embodiment of the present application.
[0036] Figure 4 The present invention is a flowchart of a method for executing a blockchain transaction according to an embodiment of the present application.
[0037] Figure 5 This is a logical diagram of the transaction pool in an embodiment of the present application.
[0038] Figure 6 The present invention is a flowchart of a method for executing a blockchain transaction according to an embodiment of the present application.
[0039] Figure 7 The present invention is a flowchart of a method for executing a blockchain transaction according to an embodiment of the present application.
[0040] Figure 8 This is a schematic flowchart of the execution of blockchain transactions in an embodiment of the present application.
[0041] Fig. 9 This is a logic diagram for parallel scheduling of transactions based on smart contracts in an embodiment of the present application.
[0042] Fig.10 The block diagram schematically shows the composition of the execution device of the blockchain transaction in the embodiment of the present application.
[0043] Fig.11 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0044] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0045] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0046] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0047] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0048] It should be understood that the scheme of the present application can be applied to the scenario of blockchain transaction execution on the chain, and is particularly applied to the process in which the block node in the blockchain executes the blocks to be chained in parallel. Specifically, in the chain process in the blockchain, the block node and other slave nodes, verification nodes or endorsement nodes, etc. need to execute the blockchain transaction separately, and the order in which these nodes execute the blockchain transaction needs to be the same to ensure that a unified execution result can be obtained. Each block usually contains multiple blockchain transactions, and the block node can generally execute these blockchain transactions serially or in parallel. When executing transactions in parallel, the block node first executes the transaction in parallel during the transaction execution process. When the transaction execution is completed, the transaction read-write set check will be performed. If a read-write set conflict occurs, the transaction will be re-executed. At this time, the read set used by the transaction has modified the read-write set of the conflicting transaction, and no read-write set conflict will occur again until there is no read-write conflict, and then the transaction execution order is recorded. The recorded transaction execution order will be provided to other nodes. When other nodes need to execute transactions in the block, such as when verifying the block, they will execute transactions in parallel according to the transaction execution order determined by the block node.
[0049] The transaction execution order in the blockchain refers to a data structure used to process the transaction execution order in blockchain technology. It is usually directed acyclic, indicating that one transaction is executed before another transaction and there is no path that starts from a vertex, moves along the directed edge and finally returns to the initial vertex, so transactions on different branches in the structure can be executed in parallel. In some blockchain systems, this directed acyclic transaction execution order is used to replace the linear blockchain structure. In related technologies, the block-producing node will repeatedly execute the transactions to be chained in parallel until there is no read-write conflict, thereby determining the transaction execution order of the block to be chained, so that other slave nodes can execute transactions in parallel according to the transaction execution order. However, there is a certain waste of resources in the process of repeatedly trying to execute transactions in parallel by the block-producing node, and the transaction order determined for the same batch of transactions may not be the same each time, which increases the uncertainty of the blockchain and reduces the reliability and trust of the entire blockchain system.
[0050] Based on this, the technical solution of the embodiment of the present application proposes an execution solution for blockchain transactions. Specifically, Figure 1 As shown, the system architecture 100 for the execution scheme applied to blockchain transactions according to the embodiment of the present application may include a terminal device 110, a network 120 and a server 130. The terminal device 110 may include a smart phone, a tablet computer, a laptop computer, an intelligent voice interaction device, a smart home appliance, a vehicle terminal, an aircraft, etc. The server 130 may be a server that provides various services, which may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network, content distribution network) and big data and artificial intelligence platforms. The network 120 may be a communication medium of various connection types that can provide a communication link between the terminal device 110 and the server 130, such as a wired communication link or a wireless communication link.
[0051] According to the implementation needs, the system architecture in the embodiment of the present application can have any number of terminal devices, networks and servers. For example, the server 130 can be a server group composed of multiple server devices. In addition, the technical solution provided in the embodiment of the present application can be applied to the terminal device 110, can also be applied to the server 130, or can be implemented by the terminal device 110 and the server 130 together, and the present application does not make special restrictions on this. In the embodiment of the present application, the server 130 can be a server of a blockchain node, and the terminal device 110 can be a blockchain node or a user terminal, and the client software of the blockchain is running on the terminal device 110, so as to communicate with the server 130. The user sends a blockchain transaction to the server 130 of the blockchain through the terminal device 110. The server 130 regularly generates blocks according to the settings of the blockchain. In the process of generating blocks, the server 130 will execute the blockchain transaction and chain the transaction according to the execution scheme of the blockchain transaction proposed in this application.
[0052] Both the server 130 and the terminal device 110 can be blockchain nodes in the blockchain. Blockchain is a peer-to-peer distributed ledger consisting of multiple nodes. Each node contains all transaction records, and all nodes need to verify each transaction. Each node in the blockchain network can be a full node or a local blockchain node. A full node can be connected to other nodes, while a local blockchain node refers to an independent node running in the blockchain and is not connected to other nodes. The local blockchain node does not participate in the consensus mechanism of the blockchain network like a full node, but it can independently verify transactions and create new blocks. The confidential information sent by the second node to the first node can only be decrypted by the first node to obtain the content, thereby realizing confidential communication between the two nodes.
[0053] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks (i.e. blocks) generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain is maintained by the nodes in the blockchain network. For example, in Figure 2The blockchain network shown may include multiple nodes 201, and the multiple nodes 201 may be the various clients forming the blockchain network. Each node 201 may receive input information during normal operation, and maintain the shared data in the blockchain network based on the received input information. In order to ensure the information intercommunication within the blockchain network, there may be an information connection between each node in the blockchain network, and information may be transmitted between nodes through the above information connection. For example, when any node in the blockchain network receives input information, other nodes in the blockchain network obtain the input information according to the consensus algorithm, and store the input information as shared data, so that the data stored on all nodes in the blockchain network are consistent.
[0054] Each node in the blockchain network has a corresponding node identifier, and each node in the blockchain network can store the node identifiers of other nodes, so that the generated blocks can be broadcast to other nodes in the blockchain network according to the node identifiers of other nodes. A node identifier list can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly. The node identifier can be an IP (Internet Protocol, a protocol for interconnecting networks) address or any other information that can be used to identify the node.
[0055] Each node in the blockchain network stores the same blockchain. The blockchain consists of multiple blocks, see Figure 3 As shown, the blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores input information feature values, version numbers, timestamps, and difficulty values, and the block body stores input information. The next block of the genesis block uses the genesis block as its parent block. The next block also includes a block header and a block body. The block header stores input information feature values of the current block, feature values of the block header of the parent block, version numbers, timestamps, and difficulty values, and so on. This ensures that the block data stored in each block in the blockchain is associated with the block data stored in the parent block, thereby ensuring the security of the input information in the block.
[0056] The implementation details of the technical solution of the embodiment of the present application are described in detail below: Figure 4 A flowchart of a method for executing a blockchain transaction according to an embodiment of the present application is shown. The method for executing a blockchain transaction is applied to a blockchain system and can be executed by a device with a computing and processing function, such as a server or terminal device where a block generating node is located. Figure 4 As shown, the execution method of the blockchain transaction at least includes steps S410 to S440, which are described in detail as follows:
[0057] Step S410: According to a preset concurrency number N, N transaction pools are determined from a transaction pool set of the blockchain, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool. Each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and each second transaction pool corresponds to a smart contract that executes a cross-contract transaction.
[0058] The preset concurrency number N is used to indicate the concurrency capacity of the server where the current block-producing node is located. The concurrency number N is usually set according to the number of cores of the server, for example, equal to or less than the number of cores of the server. Usually, when the block-producing node in the blockchain starts to build a block, it will determine N transaction pools from the transaction pool set of the blockchain according to the preset concurrency number N. The transaction pool set of the blockchain will contain at least N transaction pools. The transaction pools of the blockchain are generally divided into two categories, the first transaction pool and the second transaction pool. Each non-cross-contract transaction smart contract in the blockchain has a separate first transaction pool, while the cross-contract transactions in the blockchain share the second transaction pool. In other words, the blockchain usually contains multiple first transaction pools and one second transaction pool. These first transaction pools and second transaction pools can be sub-transaction pools set in the total transaction pool of the blockchain. The blockchain will put the transaction into the corresponding transaction pool according to the smart contract called by the blockchain transaction. The block-producing node may determine N transaction pools in a cyclic manner according to a predetermined order, or may determine N transaction pools randomly or after sorting the transaction pools according to certain rules, such as sorting according to the number of transactions in each transaction pool or according to the average waiting time of transactions in the transaction pool.
[0059] Step S420, respectively obtaining transactions to be executed from the N transaction pools.
[0060] The block node will obtain pending transactions from each determined transaction pool. Specifically, the block node will pre-configure an acquisition strategy for obtaining pending transactions. The acquisition strategy usually specifies the specific method of obtaining transactions from each transaction pool, for example, obtaining a fixed number of pending transactions from each transaction pool, or temporarily determining the number of transactions to be obtained according to the specific situation of the determined N transaction pools. For example, the block node will first determine whether the transaction volume in the determined N transaction pools meets the predetermined number. If all meet, the predetermined number of transactions will be directly obtained from each transaction pool. If some are not satisfied, the block node can check whether there are enough transactions in the transaction pool that meets the predetermined number to fill the unsatisfied part of other transaction pools. Alternatively, the block node can re-select other transaction pools from the transaction pool set and obtain pending transactions from them to fill the unsatisfied transaction volume. The pending transactions obtained will be grouped according to the source transaction pool, that is, the pending transactions from different first transaction pools are grouped separately, and the pending transactions from the second transaction pool are all grouped into the same group.
[0061] Step S430, executing pending transactions from different transaction pools in parallel to obtain transaction results of each pending transaction.
[0062] Specifically, the block node can execute pending transactions from different transaction pools in parallel and obtain the transaction results of each pending transaction. For pending transactions in the same transaction pool, the block node will execute them serially, for example, in the order of the time when the transactions were added to the transaction pool or in the order of the transaction sequence numbers. The block node will call the contract engine to execute blockchain transactions, and for each non-cross-contract smart contract, a core in the contract engine will be called separately for execution, while for cross-contract smart contracts, all cross-contract smart contracts will be executed serially.
[0063] Step S440: construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
[0064] After all pending transactions are completed, the block-producing node will collect the transaction results of each pending transaction and build the pending block based on the transaction results. The pending block will be broadcasted by the block-producing node to other blockchain nodes responsible for verification in the blockchain for consensus on-chain operations, and other nodes in the blockchain can use the same method as the block-producing node to execute these pending transactions in parallel to verify the pending block and perform the subsequent consensus voting process, so as to put the pending block on the blockchain.
[0065] In an embodiment of the present application, by establishing a transaction pool for non-cross-contract transactions and a transaction pool for cross-contract transactions, the data of different smart contracts in the blockchain are completely isolated, thereby ensuring that non-cross-contract transactions and non-cross-contract transactions and cross-contract transactions can be executed in parallel without conflict. Therefore, the order of parallel execution of transactions can be directly determined at one time, and there is no need to use a brute force loop to construct the transaction execution order, which helps to improve the reliability and trust of the entire blockchain system.
[0066] In some optional embodiments of the present application, the block producing node also receives the blockchain transaction sent by the client, and according to the smart contract called in the blockchain transaction, adds the blockchain transaction to the transaction pool corresponding to the smart contract. Figure 5 , Figure 5This is a logical diagram of the transaction pool in the embodiment of the present application. If the blockchain transaction calls a non-cross-contract transaction smart contract, the block node will add the blockchain transaction to the corresponding first transaction contract, and if the blockchain transaction calls a cross-contract transaction smart contract, the block node will add the blockchain transaction to the second transaction pool. By adding transactions to different transaction pools according to the smart contract called by the blockchain transaction, the node can directly group and cache the blockchain transactions that can be parallel when the transaction is obtained. In the subsequent processing process, it is no longer necessary to judge the parallel relationship between transactions, which is conducive to improving the execution efficiency of the solution.
[0067] In some optional embodiments of the present application, if the transaction pool corresponding to the smart contract called by the blockchain exchange is the first transaction pool, the block node will check the contract call relationship of the smart contract called in the blockchain transaction. If it is found that the contract call relationship indicates that the blockchain contract is a cross-contract transaction, the block node will transfer all transactions in the first transaction pool of the smart contract to the second transaction pool, and then check the correspondence between the second transaction pool and the smart contract, and the first transaction pool corresponding to the smart contract. All transactions of the smart contract of the cross-contract transaction are placed in the second transaction pool, and when executed, they will be executed serially with other cross-contract transactions in the second transaction pool, without conflicting with other non-cross-contract transactions, which is conducive to ensuring the parallel capability of transactions between different transaction pools in the solution, avoiding read-write conflicts during parallel operation, and ensuring the reliability of the solution.
[0068] In the embodiments of the present application, it is also proposed to Figure 4 Other embodiments that refine the technical solution of the embodiment shown in the figure are as follows Figure 6 As shown, in a method for executing a blockchain transaction in an embodiment of the present application, the following steps may be included:
[0069] Step S610, according to a preset concurrency number N and the transaction pool ranking of the transaction pools in the transaction pool set, determine the first N transaction pools in the transaction pool ranking, wherein the transaction pool ranking is determined by sorting in reverse order according to the most recent transaction output time of each transaction pool in the transaction pool set, the concurrency number N is an integer greater than 0, the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes non-cross-contract transactions, and the second transaction pool corresponds to a smart contract that executes cross-contract transactions.
[0070] In this embodiment, the transaction pools in the transaction pool set are sorted in reverse order according to the latest transaction output time of each transaction pool, and the block node determines the top N transaction pools according to the transaction pool sorting. The latest transaction output time of the transaction pool refers to the time when the block node last obtained the pending transaction from the transaction pool. The closer the latest transaction output time is to the current time, the closer the transaction in the transaction pool is to be executed. The transaction pools are sorted in reverse order according to the latest transaction output time of each transaction pool. The longer the pending transaction in the transaction pool has not been called, the higher its ranking. Sorting the transaction pool in reverse order according to the latest transaction output time can ensure that within a certain period of time, the transactions in each transaction pool have the opportunity to be executed, so that the waiting execution time of the pending transactions is more average on the whole, avoiding the overall waiting time of the pending transactions being too long, which is conducive to shortening the average waiting time of blockchain transactions.
[0071] Step S620, respectively obtaining transactions to be executed from the N transaction pools.
[0072] Optionally, the implementation details of step S620 are the same as Figure 4 The step S420 shown in FIG. 1 is the same as that in FIG. 1 and will not be described in detail.
[0073] Step S630, executing pending transactions from different transaction pools in parallel to obtain transaction results of each pending transaction.
[0074] Optionally, the implementation details of step S630 are the same as Figure 4 The step S430 shown in FIG. 1 is consistent with the step S430 shown in FIG. 1 and will not be
[0075] Step S640: construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
[0076] Optionally, the implementation details of step S640 are the same as Figure 4 The step S440 shown in FIG. 1 is consistent with the step S440 shown in FIG. 1 and will not be
[0077] In an embodiment of the present application, by establishing a transaction pool for non-cross-contract transactions and a transaction pool for cross-contract transactions, the data of different smart contracts in the blockchain are completely isolated, thereby ensuring that non-cross-contract transactions and non-cross-contract transactions and cross-contract transactions can be executed in parallel without conflict. Therefore, the order of parallel execution of transactions can be directly determined at one time, and there is no need to use a brute force loop to construct the transaction execution order, which helps to improve the reliability and trust of the entire blockchain system.
[0078] In some optional embodiments of the present application, based on the above embodiments, in the process of obtaining transactions to be executed from N transaction pools respectively, the block node determines the transaction acquisition amount corresponding to each transaction pool in the N transaction pools according to the preset transaction number threshold, and then obtains the transactions to be executed from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool, and updates the latest transaction output time of the N transaction pools according to the current moment, and updates the order of the N transaction pools in the transaction pool order. Specifically, the block node can distribute the transaction number threshold to each transaction pool. For example, if the number of concurrent transactions is 10 and the transaction number threshold is 1000, the block node will obtain 100 transactions to be executed from each of the 10 transaction pools. After obtaining the transactions to be executed from the transaction pool, the block node will update the latest transaction output time and the transaction pool order of the transaction pool, so that the transaction pool that has not output transactions for a longer time is placed higher in the order, so as to increase the probability of outputting transactions when the transaction pool to be obtained is determined next time. By determining the transaction acquisition amount corresponding to each transaction pool according to a preset transaction number threshold, the transaction acquisition amount corresponding to each transaction pool can be adjusted according to the situation of each transaction pool, which is conducive to improving the flexibility of the solution.
[0079] In some optional embodiments of the present application, based on the above embodiments, after obtaining the pending transactions from N transaction pools according to the transaction acquisition amount corresponding to each transaction pool, if the transaction number of pending transactions obtained from the N transaction pools reaches the transaction number threshold or the N transaction pools are all empty, then stop obtaining pending transactions from the N transaction pools. If the transaction number of pending transactions obtained from the N transaction pools does not reach the transaction number threshold and any transaction pool of the blockchain is not empty, then according to the current transaction pool sorting, the first N transaction pools in the transaction pool sorting are re-determined, and pending transactions are obtained from the re-determined first N transaction pools until the transaction number reaches the transaction number threshold or the transaction pools of the blockchain are all empty. Specifically, when the transaction volume obtained from the N transaction pools does not reach the transaction number threshold, and the transaction pool of the blockchain is not empty as a whole, the block node will re-determine the transaction pool to obtain the transaction, and the method of re-determining the transaction pool is the same as that in the above embodiment, and is still determined according to the transaction pool sorting. It should be noted that, in the process of re-determination, since the latest transaction output time of the previously determined N transaction pools has been updated, the re-determined N transaction pools may be partially or completely different from the previously determined N transaction pools. For the re-determined transaction pools, the block node can be evenly distributed to each transaction pool according to the difference between the transaction volume and the transaction number threshold that has been obtained. In some embodiments, during the re-determination process, the number of transaction pools may change. For example, the block node obtains 100 transactions to be executed from each transaction pool, and 300 transactions are currently required to make the transaction number reach the transaction number threshold. The block node can determine the first three transaction pools in the transaction pool sorting as the transaction pools to obtain transactions. If the first three transaction pools re-determined still do not meet the transaction number threshold, the transaction pools are continued to be re-determined until the transaction number threshold is met or all transaction pools of the blockchain are empty. By re-determining the transaction pool to obtain the transaction to be executed, the block node can execute as many transactions as possible in one block, so that the blockchain transactions that would not have been executed in the current round are executed in advance, which is conducive to shortening the waiting time of blockchain transactions.
[0080] In some optional embodiments of the present application, based on the above embodiments, after obtaining the pending transactions from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool, if the number of transactions of the pending transactions obtained from the N transaction pools does not reach the transaction number threshold and one of the N transaction pools is not empty, the block node continues to obtain pending transactions from the non-empty transaction pools of the N transaction pools until the number of transactions reaches the transaction number threshold or the N transaction pools are all empty. In this embodiment, if the number of transactions obtained does not reach the transaction number threshold, the block node will not re-determine the transaction pool, but continue to obtain transactions from the already determined transaction pool until the transaction number threshold is met or the determined N transaction pools are all empty. In this way, during the transaction execution process, since the number of transaction pools is determined according to the number of concurrent transactions, the pending transactions from the N transaction pools can be executed in parallel, and there will be no situation where the transactions of some transaction pools need to wait for execution due to the number of transaction pools exceeding the number of concurrent transactions, and there is no need for context switching between threads during the execution process, which is conducive to improving the execution efficiency of transactions in the blockchain system.
[0081] In the embodiments of the present application, it is also proposed to Figure 4 Other embodiments that refine the technical solution of the embodiment shown in the figure are as follows Figure 7 As shown, in a method for executing a blockchain transaction in an embodiment of the present application, the following steps may be included:
[0082] Step S710: According to a preset concurrency number N, N transaction pools are determined from a transaction pool set of the blockchain, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool. Each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and each second transaction pool corresponds to a smart contract that executes a cross-contract transaction.
[0083] Optionally, the implementation details of step S710 are the same as Figure 4 The step S410 shown in FIG. 1 is consistent with the step S410 shown in FIG. 1 and will not be
[0084] Step S720: constructing N-1 first cache pools corresponding to N-1 first transaction pools and a second cache pool corresponding to the second transaction pool according to a preset concurrency number N;
[0085] Step S730, respectively obtaining transactions to be executed from N-1 of the first transaction pools and adding them to the corresponding first buffer pools;
[0086] Step S740: Obtain the to-be-executed transaction from the second transaction pool and add it to the second cache pool.
[0087] In this embodiment, the block-producing node will create a corresponding cache pool for each transaction pool. Specifically, among the N transaction pools selected by the block-producing node, the second transaction pool is usually included, and the other N-1 transaction pools are first transaction pools. A first cache pool is established for each first transaction pool, and the pending transactions obtained from the first transaction pool by the block-producing node are placed in the corresponding first cache pool. The second transaction pool corresponds to the second cache pool, and the second transaction pool will contain pending transactions for executing different smart contracts, and these pending transactions will be placed in the second cache pool. It can be understood that when executing transactions, the N-1 first cache pools and the second cache pool will be executed in parallel with each other, while the transactions within each cache pool will be executed serially. All cross-contract transactions are placed in the second transaction pool, so that the transaction increase rate in the second transaction pool will be higher than that in the first transaction pool corresponding to a single smart contract. By ensuring the creation of a second cache pool corresponding to the second transaction pool, cross-contract transactions in the second transaction pool can be executed every time a transaction is executed, preventing the efficiency of blockchain executing cross-contract transactions from failing to meet the generation rate of cross-contract transactions, resulting in excessive accumulation of cross-contract transactions and untimely execution of transactions, which is conducive to improving the timeliness of solution execution.
[0088] Step S750, executing pending transactions from different transaction pools in parallel to obtain transaction results of each pending transaction.
[0089] Optionally, the implementation details of step S750 are the same as Figure 4 The step S420 shown in FIG. 1 is the same as that in FIG. 1 and will not be described in detail.
[0090] Step S760: construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
[0091] Optionally, the implementation details of step S760 are the same as Figure 4 The step S420 shown in FIG. 1 is the same as that in FIG. 1 and will not be described in detail.
[0092] In an embodiment of the present application, by establishing a transaction pool for non-cross-contract transactions and a transaction pool for cross-contract transactions, the data of different smart contracts in the blockchain are completely isolated, thereby ensuring that non-cross-contract transactions and non-cross-contract transactions and cross-contract transactions can be executed in parallel without conflict. Therefore, the order of parallel execution of transactions can be directly determined at one time, and there is no need to use a brute force loop to construct the transaction execution order, which helps to improve the reliability and trust of the entire blockchain system.
[0093] In some optional embodiments of the present application, based on the above-mentioned embodiments, the block node performs a cross-contract transaction detection on each pending transaction in the process of executing pending transactions from the N-1 first cache pools; if any pending transaction is detected to be a cross-contract transaction, the detected cross-contract transaction is transferred to the second cache pool. The block node then deletes the first transaction pool corresponding to any pending transaction, and marks other transactions of any pending transaction calling the smart contract as cross-contract transactions. In this embodiment, the block node performs a cross-contract transaction detection on the executed transaction in the process of executing the transaction in the first cache pool, such as checking the interface call relationship within the smart contract. If it is found that the executed transaction is a cross-contract transaction, the block node will transfer the transaction to the second cache pool and execute it serially with other cross-contract transactions in the second cache pool. The block node will also delete the first transaction pool corresponding to the smart contract of the transaction, and mark all other pending transactions calling the smart contract as cross-contract transactions. In this way, when executing other transactions of the smart contract, the block-producing node will also transfer it to the second transaction pool, thereby avoiding the parallel process of other transactions being affected when the smart contract is changed to a cross-contract transaction, which is conducive to ensuring the stability of parallel execution of transactions.
[0094] In some optional embodiments of the present application, based on the above embodiments, after obtaining the pending transactions from the N transaction pools respectively, the block-producing node will package the pending transactions from the N-1 first cache pools and the second cache pool into pre-chain blocks, and then broadcast the pre-chain blocks to other blockchain nodes in the blockchain, so that the other blockchain nodes can execute the pending transactions according to the transaction order in the pre-chain blocks. In this embodiment, after obtaining the pending transactions to be chained, the block-producing node does not need to wait for these nodes to be executed on the block-producing node, but directly packages them into pre-chain blocks. The pre-chain blocks will be distributed to the slave nodes. Since different cache pools in the pre-chain block can be executed in parallel without noise read-write conflicts, these slave nodes do not need the block-producing node to provide the execution order, and directly execute transactions in parallel according to the transaction order in the received pre-chain block. The block-producing node actually executes transactions according to the transaction order in the pre-chain block, which ensures that the transaction execution order is consistent with the execution order of the block-producing node, so that the slave node does not need to wait for the block-producing node to provide the execution order, which advances the time point for the slave node to execute the transaction, and generally improves the degree of parallelism between the block-producing node and the slave node, thereby improving the overall throughput of the blockchain.
[0095] In some optional embodiments of the present application, based on the above embodiments, the pending transactions from different transaction pools are executed in parallel according to the transaction order in the pre-chain block. In the process of constructing the pending chain block according to the transaction results of each pending transaction and chaining the pending chain block in the blockchain, the block-producing node will construct the pending chain block according to the transaction results of each pending transaction and obtain the parallel execution order of each pending transaction; then broadcast the pending chain block and the parallel execution order to other blockchain nodes in the blockchain, so that the other blockchain nodes can verify the pending chain block and the parallel execution order according to the execution result of the pre-chain block; and then chain the pending chain block in the blockchain according to the verification result fed back by the other blockchain nodes. In this embodiment, after executing the transaction, the block-producing node will send the parallel execution order to other blockchain nodes in the blockchain, so that other blockchain nodes can verify the consistency of the parallel execution order, prevent the blockchain data from being inconsistent due to the execution order error, and improve the data reliability and confidence of the blockchain system.
[0096] The following is an example of the implementation details of the technical solution of the embodiment of the present application: Figure 8 , Figure 8 This is a schematic flow chart of the execution of blockchain transactions in the embodiment of this application. Figure 8As shown, when a user sends a blockchain transaction to the transaction pool of a blockchain node, the node groups and caches the transaction according to the contract called by the transaction. In the transaction pool of the blockchain, each contract that has never been involved in a cross-contract transaction has a first transaction pool. When a contract involves a cross-contract transaction, this contract is deleted from the ordinary contract transaction pool, and all related transactions are stored in the second transaction pool. When a node needs to package a block, its core engine will actively pull transactions from the transaction pool. The way to pull transactions will be the way to obtain transactions in the above scheme. Specifically, the transaction pulling strategy is based on the pre-configured concurrency number. For example, if the current concurrency number is 10 and the number of acquired transactions is 1000, the core engine will build a corresponding number of contract transaction cache pools according to the concurrency number, among which there must be a cache pool for storing transactions obtained from the cross-contract transaction pool, and then obtain transactions from the top ten contract transaction pools. This ranking is in reverse order of the most recently pulled transactions. Pull 100 transactions from each contract transaction pool and modify the contract ranking. Put the pulled transactions into the cache pool in sequence to ensure that the transactions of each contract can only be stored in one transaction cache pool. When the total number of transactions meets the conditions or the transaction pool is empty, exit the block pulling process. If there are still transactions in the transaction pool and the total number of pulled transactions does not meet the conditions, in the current example, it is less than 1000, repeat the steps of obtaining transactions from the top ten contract transaction pools and subsequent steps until the transaction pool is empty or the total number of transactions meets the conditions. Subsequently, the core engine will package the transactions obtained from the transaction pool into pre-chain blocks and distribute the pre-chain blocks to other nodes. The core reference will use the contract virtual machine to execute the obtained blockchain transactions in parallel based on the contract. For details, please refer to Fig. 9 , Fig. 9 This is a logic diagram of parallel scheduling of transactions based on smart contracts in an embodiment of this application. Fig. 9 As shown in the figure, each smart contract corresponds to a worker in the contract virtual machine. Within multiple transaction cache pools, transactions are executed serially; between transaction cache pools, transactions are executed in parallel. During the transaction execution process, the node will detect and adjust cross-contract call transactions. If a transaction in a non-cross-contract transaction pool is detected to have a cross-contract call, the transaction will be moved to the cache pool corresponding to the cross-contract transaction, and the current contract transaction pool will be deleted, and the transaction of the contract will be marked as a cross-contract transaction. After the block-producing node executes all contracts, it will sort out the parallel execution order of transactions and the transaction read and write collection, and then execute the subsequent consensus process through the consensus engine. After receiving the pre-chain block, the slave node will start executing the transaction, and in the consensus process, it will check the consistency of the transaction execution order and the execution result according to the execution result, and continue the subsequent block creation process.
[0097] It should be noted that although the steps of the method in the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0098] The following introduces the device implementation of the present application, which can be used to execute the execution method of the blockchain transaction in the above-mentioned embodiment of the present application. Fig.10 The block diagram schematically shows the composition of the execution device of the blockchain transaction in the embodiment of the present application. Fig.10 As shown, the execution device 1000 of the blockchain transaction may mainly include:
[0099] The transaction pool determination module 1010 is configured to determine N transaction pools from the transaction pool set of the blockchain according to a preset concurrency number N, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and the second transaction pool corresponds to a smart contract that executes a cross-contract transaction;
[0100] The transaction acquisition module 1020 is configured to respectively acquire transactions to be executed from the N transaction pools;
[0101] The transaction execution module 1030 is configured to execute pending transactions from different transaction pools in parallel and obtain transaction results of each pending transaction;
[0102] The block construction module 1040 is configured to construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
[0103] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module 1010 is specifically configured to: determine the first N transaction pools in the transaction pool sorting according to a preset concurrency number N and the transaction pool sorting of the transaction pools in the transaction pool set, wherein the transaction pool sorting is determined by sorting in reverse order according to the most recent transaction output time of each transaction pool in the transaction pool set.
[0104] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module 1010 is specifically configured to: determine the transaction acquisition amount corresponding to each of the N transaction pools according to a preset transaction number threshold; obtain transactions to be executed from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool; update the latest transaction output time of the N transaction pools according to the current moment, and update the ranking of the N transaction pools in the transaction pool ranking.
[0105] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module 1010 is specifically configured as follows: if the number of transactions to be executed obtained from the N transaction pools reaches the transaction number threshold or the N transaction pools are all empty, then stop obtaining transactions to be executed from the N transaction pools; if the number of transactions to be executed obtained from the N transaction pools does not reach the transaction number threshold and any transaction pool of the blockchain is not empty, then according to the current transaction pool sorting, re-determine the top N transaction pools in the transaction pool sorting, and obtain transactions to be executed from the re-determined top N transaction pools until the number of transactions reaches the transaction number threshold or the transaction pools of the blockchain are all empty.
[0106] In some embodiments of the present application, based on the above technical solution, the transaction pool determination module 1010 is specifically configured as follows: if the number of transactions to be executed obtained from the N transaction pools does not reach the transaction number threshold and one of the N transaction pools is not empty, then continue to obtain transactions to be executed from the non-empty transaction pools among the N transaction pools until the number of transactions reaches the transaction number threshold or the N transaction pools are all empty.
[0107] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module is specifically configured to: construct N-1 first cache pools corresponding to N-1 first transaction pools and a second cache pool corresponding to the second transaction pool according to the preset concurrency number N; obtain transactions to be executed from the N-1 first transaction pools and add them to the corresponding first cache pools; obtain transactions to be executed from the second transaction pool and add them to the second cache pool.
[0108] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module 1020 is specifically configured to: in the process of executing the pending transactions from the N-1 first cache pools, perform cross-contract transaction detection on each pending transaction; if any pending transaction is detected to be a cross-contract transaction, transfer the detected cross-contract transaction to the second cache pool; delete the first transaction pool corresponding to any pending transaction, and mark other transactions of the smart contract called by any pending transaction as cross-contract transactions.
[0109] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module 1020 is specifically configured to: package the pending transactions in the N-1 first cache pools and the second cache pool into pre-chain blocks; broadcast the pre-chain blocks to other blockchain nodes in the blockchain, so that the other blockchain nodes can execute the pending transactions according to the transaction order in the pre-chain blocks.
[0110] In some embodiments of the present application, based on the above technical solution, pending transactions from different transaction pools are executed in parallel according to the transaction order in the pre-chain block; the block construction module 1040 is specifically configured to: construct a pending chain block according to the transaction results of each pending transaction, and obtain the parallel execution order of each pending transaction; broadcast the pending chain block and the parallel execution order to other blockchain nodes in the blockchain, so that the other blockchain nodes can verify the pending chain block and the parallel execution order according to the execution result of the pre-chain block; and chain the pending chain block in the blockchain according to the verification result fed back by the other blockchain nodes.
[0111] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module 1020 is further configured to: receive a blockchain transaction sent by a client; and according to the smart contract called in the blockchain transaction, add the blockchain transaction to a transaction pool corresponding to the smart contract.
[0112] In some embodiments of the present application, based on the above technical solution, the transaction acquisition module 1020 is also configured to: if the transaction pool corresponding to the called smart contract is the first transaction pool, then check the contract call relationship of the smart contract called in the blockchain transaction; if the contract call relationship indicates that the blockchain transaction is a cross-contract transaction, then transfer all transactions in the first transaction pool corresponding to the smart contract to the second transaction pool; establish a corresponding relationship between the smart contract and the second transaction pool and delete the first transaction pool corresponding to the smart contract.
[0113] It should be noted that the apparatus provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module performs the operation has been described in detail in the method embodiment and will not be repeated here.
[0114] Fig.11 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0115] It should be noted that Fig.11 The computer system 1100 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0116] like Fig.11As shown, the computer system 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1102 or the program loaded from the storage part 1108 to the random access memory (RAM) 1103. Various programs and data required for system operation are also stored in the RAM 1103. The CPU 1101, the ROM 1102, and the RAM 1103 are connected to each other through a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0117] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0118] In particular, according to an embodiment of the present application, the process described in each method flow chart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, and the computer program contains a program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 1109, and / or installed from a removable medium 1111. When the computer program is executed by a central processing unit (CPU) 1101, various functions defined in the system of the present application are executed.
[0119] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0120] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0121] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0122] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation method of the present application.
[0123] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application.
[0124] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for executing a blockchain transaction, It is characterized in that include: According to a preset concurrency number N, N transaction pools are determined from a transaction pool set of the blockchain, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and the second transaction pool corresponds to a smart contract that executes a cross-contract transaction; Obtaining transactions to be executed from the N transaction pools respectively; Parallel execution of pending transactions from different transaction pools to obtain the transaction results of each pending transaction; A block to be chained is constructed according to the transaction results of each transaction to be executed, and the block to be chained is chained in the blockchain.
2. The method according to claim 1, It is characterized in that The method of determining N transaction pools from the transaction pool set of the blockchain according to the preset concurrent number N includes: According to a preset concurrency number N and a transaction pool ranking of the transaction pools in the transaction pool set, the first N transaction pools in the transaction pool ranking are determined, wherein the transaction pool ranking is determined by sorting in reverse order according to the most recent transaction output time of each transaction pool in the transaction pool set.
3. The method according to claim 2, It is characterized in that The obtaining the to-be-executed transactions from the N transaction pools respectively includes: Determine the transaction acquisition amount corresponding to each of the N transaction pools according to a preset transaction number threshold; According to the transaction acquisition amount corresponding to each transaction pool, respectively acquire transactions to be executed from the N transaction pools; The latest transaction output time of the N transaction pools is updated according to the current time, and the order of the N transaction pools in the transaction pool order is updated.
4. The method according to claim 3, It is characterized in that After acquiring the to-be-executed transactions from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool, the method further includes: If the number of pending transactions obtained from the N transaction pools reaches the transaction number threshold or the N transaction pools are all empty, then stop obtaining pending transactions from the N transaction pools; If the number of pending transactions obtained from the N transaction pools does not reach the transaction number threshold and any transaction pool of the blockchain is not empty, the first N transaction pools in the transaction pool ranking are re-determined according to the current transaction pool ranking, and pending transactions are obtained from the re-determined first N transaction pools until the number of transactions reaches the transaction number threshold or the transaction pools of the blockchain are all empty.
5. The method according to claim 3, It is characterized in that After acquiring the to-be-executed transactions from the N transaction pools respectively according to the transaction acquisition amount corresponding to each transaction pool, the method further includes: If the number of pending transactions obtained from the N transaction pools does not reach the transaction number threshold and one of the N transaction pools is not empty, continue to obtain pending transactions from the non-empty transaction pools among the N transaction pools until the number of transactions reaches the transaction number threshold or the N transaction pools are all empty.
6. The method according to claim 1, It is characterized in that The method further comprises: According to the preset concurrency number N, construct N-1 first cache pools corresponding to N-1 first transaction pools and a second cache pool corresponding to the second transaction pool; The obtaining the to-be-executed transactions from the N transaction pools respectively includes: Obtain transactions to be executed from N-1 of the first transaction pools respectively and add them to the corresponding first buffer pools; Obtain the to-be-executed transactions from the second transaction pool and add them to the second cache pool.
7. The method according to claim 6, It is characterized in that The method further comprises: In the process of executing the pending transactions from the N-1 first buffer pools, performing cross-contract transaction detection on each pending transaction; If it is detected that any transaction to be executed is a cross-contract transaction, the detected cross-contract transaction is transferred to the second cache pool; The first transaction pool corresponding to any of the pending transactions is deleted, and other transactions of the smart contract called by any of the pending transactions are marked as cross-contract transactions.
8. The method according to claim 6, It is characterized in that After respectively acquiring the to-be-executed transactions from the N transaction pools, the method further includes: Packing the pending transactions in the N-1 first cache pools and the second cache pools into pre-chain blocks; Broadcast the pre-chain block to other blockchain nodes in the blockchain so that the other blockchain nodes can execute the transactions to be executed according to the transaction order in the pre-chain block.
9. The method according to claim 8, It is characterized in that The pending transactions from different transaction pools are executed in parallel according to the transaction order in the pre-chain block; the pending chain block is constructed according to the transaction results of each pending transaction, and the pending chain block is chained in the blockchain, including: Constructing a block to be uploaded to the chain according to the transaction results of each transaction to be executed, and obtaining the parallel execution order of each transaction to be executed; Broadcasting the block to be chained and the parallel execution order to other blockchain nodes in the blockchain, so that the other blockchain nodes can verify the block to be chained and the parallel execution order according to the execution result of the pre-chained block; According to the verification results fed back by the other blockchain nodes, the block to be chained is chained in the blockchain.
10. The method according to claim 1, It is characterized in that The method further comprises: Receive blockchain transactions sent by the client; According to the smart contract called in the blockchain transaction, the blockchain transaction is added to the transaction pool corresponding to the smart contract.
11. The method according to claim 10, It is characterized in that The method further comprises: If the transaction pool corresponding to the called smart contract is the first transaction pool, checking the contract call relationship of the smart contract called in the blockchain transaction; If the contract call relationship indicates that the blockchain transaction is a cross-contract transaction, all transactions in the first transaction pool corresponding to the smart contract are transferred to the second transaction pool; Establish a corresponding relationship between the smart contract and the second transaction pool and delete the first transaction pool corresponding to the smart contract.
12. A blockchain transaction execution device, It is characterized in that include: The transaction pool determination module is configured to determine N transaction pools from the transaction pool set of the blockchain according to a preset concurrency number N, where the concurrency number N is an integer greater than 0, and the transaction pool set includes a first transaction pool and a second transaction pool, each first transaction pool corresponds to a smart contract that executes a non-cross-contract transaction, and the second transaction pool corresponds to a smart contract that executes a cross-contract transaction; A transaction acquisition module, configured to acquire transactions to be executed from the N transaction pools respectively; A transaction execution module, configured to execute pending transactions from different transaction pools in parallel, and obtain transaction results of each pending transaction; The block construction module is configured to construct a block to be chained according to the transaction results of each transaction to be executed, and chain the block to be chained in the blockchain.
13. An electronic device, It is characterized in that include: processor; A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the method for executing a blockchain transaction as described in any one of claims 1 to 11 by executing the executable instructions.
14. A computer readable medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method for executing a blockchain transaction as described in any one of claims 1 to 11 is implemented.
15. A computer program product, It is characterized in that The computer program product includes a computer program, which is stored in a computer-readable storage medium. The processor of the electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device executes the method for executing a blockchain transaction as claimed in any one of claims 1 to 11.