Transaction execution method and device based on block chain, equipment, medium and product
By grouping and executing transactions to be executed in the blockchain system, and determining the execution order with account information, the problem of low transaction execution efficiency in the existing technology is solved, and high-performance transaction execution is achieved.
Patent Information
- Application Number
- CN202311633721.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-30
- Publication Date
- 2025-05-30
AI Technical Summary
During the transaction execution process of existing blockchain systems, serial execution leads to insufficient resource utilization, and there are a large number of unnecessary operations during parallel execution, affecting performance.
By obtaining the transactions to be executed in the current block, grouping transactions according to the smart contract, executing transactions between each contract group in parallel, and determining the execution order within the contract group in combination with account information, achieving safe "controllable" parallel execution of transactions.
Compared with separate serial execution, the performance improvement is huge, reducing a large amount of meaningless execution, and improving the throughput and transaction execution efficiency of the blockchain.
Smart Images

Figure CN120069868A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology. Specifically, it relates to a transaction execution method based on blockchain, a transaction execution device based on blockchain, an electronic device, a computer-readable storage medium, and a computer program product. Background Art
[0002] In blockchain, due to the need to support a large number of actual services, higher requirements are imposed on the performance of the blockchain. Transaction execution is a key step in a round of consensus in the blockchain and has a great impact on performance. Currently, for transaction scheduling and execution, blockchain systems usually adopt two main methods. The first is pure serial execution. In this method, transactions do not need to consider whether there are conflicts between each other, but the multi-core characteristics of the CPU are not fully utilized, resulting in low transaction execution efficiency. The other method is parallel scheduling execution. However, when there are many conflicts between transactions, re-execution is required, which will introduce a large number of meaningless operations, instead causing damage to performance and reducing transaction execution efficiency. Summary of the Invention
[0003] To solve the above technical problems, embodiments of the present application provide a transaction execution method based on blockchain, a transaction execution device based on blockchain, an electronic device, a computer-readable storage medium, and a computer program product, which can achieve secure and "controllable" parallel execution of transactions. Compared with separate serial execution, the performance is greatly improved. At the same time, compared with complete parallel execution, a large number of meaningless executions can be reduced.
[0004] Other features and advantages of the present application will become apparent through the following detailed description, or be learned in part through the practice of the present application.
[0005] According to one aspect of the embodiments of the present application, a transaction execution method based on blockchain is provided, including: obtaining multiple to-be-executed transactions in the current block, and grouping the to-be-executed transactions according to the smart contracts called by each to-be-executed transaction to obtain to-be-executed transactions in multiple contract groups; parallelly executing the to-be-executed transactions between each contract group; during the process of executing the to-be-executed transactions in any one contract group, determining the execution order of the to-be-executed transactions in the contract group according to the account information to which the to-be-executed transactions in the contract group belong; and executing the to-be-executed transactions in the contract group according to the execution order.
[0006] According to one aspect of the embodiments of the present application, a transaction execution device based on a blockchain is provided. The device includes: a grouping module, configured to obtain multiple to-be-executed transactions in a current block, and group the to-be-executed transactions according to the smart contracts invoked by the to-be-executed transactions, so as to obtain to-be-executed transactions of multiple contract groups; an execution module, configured to execute the to-be-executed transactions between the contract groups in parallel; a determination module, configured to determine the execution order of the to-be-executed transactions in a contract group according to the account information to which the to-be-executed transactions in the contract group belong during the process of executing the to-be-executed transactions in any one contract group; and the execution module is further configured to execute the to-be-executed transactions in the contract group according to the execution order.
[0007] In an embodiment of the present application, the determination module is further configured to, if the account information to which the to-be-executed transactions in the contract group belong is different, group the to-be-executed transactions in the contract group according to the account information, so as to obtain to-be-executed transactions of multiple account groups; determine that the execution order of the to-be-executed transactions between the multiple account groups is to be executed in parallel, and determine that the execution order of the to-be-executed transactions in any one account group is to be executed serially.
[0008] In an embodiment of the present application, the determination module is further configured to, if the account information to which the to-be-executed transactions in the contract group belong is related, determine that the execution order of the to-be-executed transactions in the contract group is to be executed serially; determine the transaction logic relationship between the to-be-executed transactions in the contract group according to the transaction content of the to-be-executed transactions in the contract group; and determine the serial execution order of the to-be-executed transactions in the contract group according to the transaction logic relationship.
[0009] In an embodiment of the present application, the determination module is further configured to traverse the to-be-executed transactions in the contract group, and obtain the calling party account of the smart contract invoked by the currently traversed to-be-executed transaction; determine the transaction calling party of the to-be-executed transaction according to the calling party account and the transaction account of the currently traversed to-be-executed transaction; construct an account group for each transaction calling party, and write the to-be-executed transactions corresponding to each transaction calling party into the corresponding account group, so as to obtain the to-be-executed transactions of the multiple account groups.
[0010] In one embodiment of the present application, the grouping module is further configured to obtain the contract information carried by the to-be-executed transaction; if it is determined according to the contract information that the number of smart contracts invoked by the to-be-executed transaction includes at least two, then the to-be-executed transaction is regarded as the to-be-executed transaction of the multi-contract group; if it is determined according to the contract information that the number of smart contracts invoked by the to-be-executed transaction is one, then the to-be-executed transaction is regarded as the to-be-executed transaction of the single-contract group corresponding to the smart contract; the execution module is further configured to execute the to-be-executed transactions between each single-contract group in parallel, and after the to-be-executed transactions of each single-contract group are executed, execute the to-be-executed transactions within the multi-contract group.
[0011] In one embodiment of the present application, the execution module is further configured to determine an invoking contract and an invoked contract according to the invocation relationship of at least two of the smart contracts; execute the to-be-executed transaction according to the invoking contract to obtain the context information of the to-be-executed transaction; generate a sub-transaction according to the context information of the to-be-executed transaction, and send the sub-transaction to the invoked contract for execution.
[0012] In one embodiment of the present application, the grouping module is further configured to, if it is determined according to the contract information carried by the to-be-executed transaction that the smart contracts invoked by the target to-be-executed transaction include at least two smart contracts with an invocation relationship, write the target to-be-executed transaction into the target contract group corresponding to the invoked smart contract; the execution module is further configured to, when executing the target to-be-executed transaction in the target contract group according to the execution order, execute the target to-be-executed transaction according to the smart contract corresponding to the target contract group to obtain the context information of the target to-be-executed transaction; generate a sub-transaction according to the context information, and write the sub-transaction into the contract group corresponding to the invoked smart contract.
[0013] In one embodiment of the present application, the grouping module is further configured to traverse each to-be-executed transaction in the current block and obtain the smart contract invoked by the current to-be-executed transaction; if the smart contract invoked by the current to-be-executed transaction is already associated with a pre-constructed shard cache, write the current to-be-executed transaction into the shard cache; if the smart contract invoked by the current to-be-executed transaction is not associated with the shard cache, construct a new shard cache for the smart contract, and write the current to-be-executed transaction into the new shard cache; obtain the to-be-executed transactions of the multiple contract groups according to each shard cache.
[0014] In one embodiment of the present application, the execution module is further configured to obtain the resource information required by the smart contracts respectively corresponding to each contract group; determine whether there is a resource competition relationship between the smart contracts according to the resource information required by the smart contracts; if there is no resource competition relationship between the smart contracts, then execute the pending transactions between each contract group in parallel.
[0015] In one embodiment of the present application, the execution module is further configured to obtain the contract code of the smart contract and the contract call chain of the historical transactions of the blockchain; determine whether there is a dependency relationship between the smart contracts according to the contract code of the smart contract and the contract call chain; if there is no dependency relationship between the smart contracts, then execute the pending transactions between each contract group in parallel.
[0016] In one embodiment of the present application, the execution module is further configured to, if it is determined that there is a call relationship between the smart contracts according to the contract code of the smart contract or the contract call chain, then construct a contract call graph according to the contract code and the contract call chain; obtain the call depth of the call relationship according to the contract call graph; if the call depth is greater than a preset depth threshold, then determine that there is a dependency relationship between the smart contracts.
[0017] In one embodiment of the present application, the execution module is further configured to, during the process of executing the pending transactions between each contract group in parallel, obtain the resource utilization rate of the blockchain and the transaction load of each contract group; determine to re-adjust the number of concurrently executed threads according to the resource utilization rate and the transaction load; execute the pending transactions between each contract group in parallel according to the adjusted number of threads.
[0018] According to one aspect of the embodiments of the present application, there is provided an electronic device, including one or more processors; a storage device for storing one or more computer programs, when the one or more computer programs are executed by the one or more processors, enabling the electronic device to implement the blockchain-based transaction execution method as described above.
[0019] According to one aspect of the embodiments of the present application, there is provided a computer-readable storage medium, on which a computer program is stored, when the computer program is executed by a processor of an electronic device, enabling the electronic device to execute the blockchain-based transaction execution method as described above.
[0020] According to one aspect of the embodiments of the present application, there is provided a computer program product, including a computer program, the computer program is stored in a computer-readable storage medium, and a processor of an electronic device reads and executes the computer program from the computer-readable storage medium, enabling the electronic device to execute the blockchain-based transaction execution method as described above.
[0021] In the technical solution provided by the embodiments of the present application, the blockchain node obtains multiple to-be-executed transactions in the current block, and groups the to-be-executed transactions according to the smart contracts invoked by each to-be-executed transaction, obtaining the to-be-executed transactions of multiple contract groups; since smart contracts are usually isolated from each other and there is no data conflict between different contracts, the to-be-executed transactions of each contract group can be executed in parallel, making full use of the parallel capabilities of the multi-core processor, thereby improving the contract execution performance; and during the execution of the to-be-executed transactions within any one contract group, the execution order of the to-be-executed transactions within the contract group is further determined according to the account information to which the to-be-executed transactions within the contract group belong, and the to-be-executed transactions within the contract group are executed according to the execution order, that is, considering the relationship between the account and the transaction, minimizing the ineffective execution, thereby realizing the secure and "controllable" parallel execution of transactions, with a huge performance improvement compared to the separate serial execution; at the same time, compared to the complete parallel execution, a large number of meaningless executions can be reduced.
[0022] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application. Obviously, the accompanying drawings in the following description are only some embodiments of the present application, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts. In the drawings:
[0024] Figure 1A is a schematic diagram of the structure of the blockchain network;
[0025] Figure 1B is a schematic diagram of the block generation process in the blockchain;
[0026] Figure 2 is a schematic diagram of an implementation environment related to the present application;
[0027] Figure 3 is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0028] Figure 4 is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0029] Figure 5 is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0030] Figure 6It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0031] Figure 7 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0032] Figure 8 It is a schematic structural diagram of a blockchain node shown in an exemplary embodiment of the present application;
[0033] Figure 9 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0034] Figure 10 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0035] Figure 11 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0036] Figure 12 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0037] Figure 13 It is a flowchart of a transaction execution method shown in an exemplary embodiment of the present application;
[0038] Figure 14 It is a schematic diagram of the call relationship between an account and a contract shown in an exemplary embodiment of the present application;
[0039] Figure 15 It is a schematic diagram of a contract group shown in an exemplary embodiment of the present application;
[0040] Figure 16 It is a flowchart of the construction of a contract group shown in an exemplary embodiment of the present application;
[0041] Figure 17 It is a schematic diagram of another call relationship between an account and a contract shown in another exemplary embodiment of the present application;
[0042] Figure 18 It is a schematic diagram of another contract group shown in another exemplary embodiment of the present application;
[0043] Figure 19 It is the process of constructing an account group shown in another exemplary embodiment of the present application;
[0044] Figure 20 It is a block diagram of the structure of a blockchain-based transaction execution device shown in an exemplary embodiment of the present application;
[0045] Figure 21 The figure shows a schematic structural diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application. Detailed implementation manners
[0046] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0047] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be fully or partially implemented by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of the overall module or unit that includes the function of the module or unit.
[0048] The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can 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.
[0049] The flowcharts shown in the drawings are only exemplary illustrations, and do not necessarily include all contents and operations / steps, nor do they necessarily need to be executed in the described order. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined. Therefore, the actual execution order may change according to the actual situation.
[0050] It should also be noted that: "a plurality of" mentioned in the present application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0051] The technical solution of the embodiments of the present application relates to the field of blockchain technology. Before introducing the technical solution of the embodiments of the present application, blockchain technology will be briefly introduced.
[0052] Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. Essentially, blockchain is a decentralized database, a series of data blocks generated by using cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block. Blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer.
[0053] Please refer to Figure 1A , the blockchain network can include multiple nodes 101, and the multiple nodes 101 can refer to each client in the blockchain. Each node 101 can receive input information during normal operation and maintain the shared data in the blockchain based on the received input information. To ensure information intercommunication within the blockchain, there can be information connections between each node in the blockchain, and nodes can transmit information through the above information connections. For example, when any node in the blockchain receives input information, other nodes in the blockchain obtain the input information according to the consensus algorithm and store the input information as data in the shared data, so that the data stored on all nodes in the blockchain is consistent.
[0054] It can be understood that each node in the blockchain network can be a server or a client. Among them, the server can be an independent physical server, a server cluster or a 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), and big data and intelligent platforms. Among them, the client can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, a client used in a car, an aircraft, etc., but is not limited thereto. Each node can be directly or indirectly connected through wired or wireless communication methods, and this application does not make any restrictions here.
[0055] When generating each block in the blockchain, refer to Figure 1B, when the node where the blockchain is located receives the input information, it verifies the input information. After the verification is completed, it stores the input information in the memory pool and updates the hash tree used to record the input information; then, it updates the update timestamp to the time when the input information is received, and tries different random numbers, calculates the eigenvalue multiple times until a reasonable eigenvalue is found, stores the information correspondingly, generates a block header and a block body, and obtains the current block. Subsequently, the node where the blockchain is located sends the newly generated block to other nodes in the blockchain it belongs to according to the node identifiers of other nodes in the blockchain, and other nodes verify the newly generated block and add the newly generated block to the blockchain they store after the verification is completed. In the process of generating the block mentioned above, the process of packing the block, broadcasting the block externally, and verifying by other nodes and linking into the blockchain is the consensus process.
[0056] See Figure 1A In the blockchain network shown by the nodes, the services implemented by the applications of each node include: smart contracts, which are computerized protocols that can execute the terms of a certain contract and are implemented by code deployed on a shared ledger to execute when certain conditions are met. According to actual business needs, the code is used to complete automated transactions, such as querying the logistics status of the goods purchased by the buyer and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods; of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0057] The technical solutions of the embodiments of the present application are introduced in detail below:
[0058] Please refer to Figure 2 , Figure 2 is a schematic diagram of an implementation environment involved in the present application. This implementation environment mainly includes the trading party 201, and the blockchain nodes 101 and 102 in the blockchain network; in an example, the trading party can be a terminal or a server off the blockchain, or a node on the blockchain.
[0059] Among them, the trading party generates a transaction to be executed, and can send the transaction to be executed to the blockchain. The blockchain node 101 generates a block based on the transaction to be executed and broadcasts the block to other blockchain nodes 102.
[0060] The blockchain node 102 is used to obtain multiple transactions to be executed in the current block, group the transactions to be executed according to the smart contracts called by each transaction to be executed, and obtain the transactions to be executed in multiple contract groups; execute the transactions to be executed between each contract group in parallel; during the execution of the transactions to be executed in any one contract group, determine the execution order of the transactions to be executed in the contract group according to the account information to which the transactions to be executed in the contract group belong; execute the transactions to be executed in the contract group according to the execution order.
[0061] After that, blockchain node 102 obtains the transaction results of each transaction to be executed, and returns the obtained transaction results to blockchain node 101 to complete the consensus on the current block.
[0062] It should be noted that in the specific implementation manner of this application, if the transaction to be executed and / or the smart contract involves an object, when the embodiments of this application are applied to a specific product or technology, object permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with the relevant regulations and standards of relevant countries and regions.
[0063] The following elaborates in detail on various implementation details of the technical solutions of the embodiments of this application:
[0064] As Figure 3 shown, Figure 3 is a flowchart of a transaction execution method based on blockchain shown in an embodiment of this application. This method can be applied to Figure 2 the implementation environment shown, and this method can be executed by Figure 2 the blockchain node shown. The transaction execution method based on blockchain may include steps S310 to S340, which are introduced in detail as follows:
[0065] S310. Obtain multiple transactions to be executed in the current block, and group the transactions to be executed according to the smart contracts called by each transaction to be executed, so as to obtain the transactions to be executed in multiple contract groups.
[0066] In the embodiments of this application, the current block refers to the block to be consensus, that is, after the blockchain consensus main node generates the block and broadcasts it to the slave nodes, the slave nodes perform consensus processing on the block, and the block includes multiple transactions to be executed; the current block may also be a block newly generated by the blockchain node.
[0067] Among them, each transaction to be executed calls a smart contract. A smart contract refers to program code that runs on a node and can execute any calculation and implement complex logic. This program code indicates the execution process and processing logic of the smart contract, such as input, output, intermediate conversion logic, etc. In one example, the smart contract called by the transaction can be determined according to the contract information carried by the transaction to be executed. The contract information includes contract name, contract address, and contract ABI (Application Binary Interface), etc. There is a contract warehouse on the blockchain node locally, and the contract warehouse includes various smart contracts deployed locally. Therefore, the smart contract called by the transaction to be executed can be determined through the contract information and the contract warehouse.
[0068] It should be understood that the smart contracts called by different to-be-executed transactions may be different. The to-be-executed transactions can be grouped according to the smart contracts they call. That is, all the to-be-executed transactions that call contract A are placed in one group, and all the to-be-executed transactions that call contract B are placed in another group, and so on. After grouping, for the convenience of distinction, the contract name is used as the identifier of the group, and the to-be-executed transactions of multiple contract groups are obtained. For example, contract group A and contract group B are obtained. Contract group A includes to-be-executed transactions 1, 3, and 4; contract group B includes to-be-executed transactions 2 and 5.
[0069] In one example, the node can group the contracts with similar functions or similar execution paths in advance locally. For example, contract group C and contract group D are obtained. Then, when grouping according to the smart contract, the to-be-executed transactions are grouped based on this contract group. For example, if the contracts called by to-be-executed transactions 6 and 7 are within contract group C, then to-be-executed transactions 6 and 7 are taken as a group of transactions of the contract group; if the contract called by to-be-executed transaction 8 is not within any contract group, then the contract called by to-be-executed transaction 8 can be separately divided into a group, and then to-be-executed transaction 8 is taken as a transaction of a new contract group. In this way, it can be ensured that the transactions within the same group are more likely to be independent, reducing the transaction conflicts between different groups.
[0070] S320. Execute the to-be-executed transactions between each contract group in parallel.
[0071] In the embodiments of the present application, different contracts often form different namespaces. Contracts are often isolated from each other and are not affected during execution. There is generally no data conflict between different contracts, that is, they do not modify the state of the same account at the same time. When multiple transactions call different contracts, the probability of conflict between these transactions is even smaller. Therefore, different contract groups can be executed simultaneously without waiting for the results of other contract groups. In this way, the parallel computing power of the multi-core processor can be utilized to improve the execution performance of the contract, thereby increasing the throughput of the blockchain. For example, to-be-executed transaction 1 of contract group A and to-be-executed transaction 2 of contract group B can be executed in parallel.
[0072] S330. During the execution of the to-be-executed transactions within any contract group, determine the execution order of the to-be-executed transactions within the contract group according to the account information to which the to-be-executed transactions within the contract group belong.
[0073] In the embodiments of the present application, within each contract group, a contract group may include multiple to-be-executed transactions. During the execution of the to-be-executed transactions within any contract group, the execution order of the transactions within the contract group is further determined according to the account information to which the to-be-executed transactions belong. For example, contract group A and contract group B can be executed in parallel. However, when contract group A includes to-be-executed transactions 1, 3, and 4, it is necessary to first determine which transaction to execute.
[0074] Among them, the account information of the to-be-executed transactions within the contract group includes the account information of the account that initiated the transaction and the account information related to the transaction. Through the account information of the to-be-executed transactions, the to-be-executed transactions within the contract group can be classified, and then based on the classification result, the execution order of the to-be-executed transactions can be determined. The execution order includes serial execution and parallel execution, and the execution order should avoid transaction conflicts between the to-be-executed transactions.
[0075] S340. Execute the to-be-executed transactions within the contract group according to the execution order.
[0076] In the embodiment of the present application, within the contract group, the to-be-executed transactions are executed in sequence based on the execution order of the to-be-executed transactions.
[0077] In the embodiment of the present application, the blockchain node obtains multiple to-be-executed transactions in the current block and groups the to-be-executed transactions according to the smart contracts called by each to-be-executed transaction, obtaining the to-be-executed transactions of multiple contract groups; since smart contracts are usually isolated from each other and there is no data conflict between different contracts, the to-be-executed transactions of each contract group can be executed in parallel, making full use of the parallel capabilities of multi-core processors, thereby improving the contract execution performance; and during the process of executing the to-be-executed transactions within any contract group, the execution order of the to-be-executed transactions within the contract group is further determined according to the account information of the to-be-executed transactions within the contract group, and the to-be-executed transactions within the contract group are executed according to the execution order, that is, considering the relationship between the account and the transaction, minimizing the ineffective execution. In this way, the secure and "controllable" parallel execution of transactions is realized, and compared with the separate serial execution, the performance is greatly improved; at the same time, compared with the complete parallel execution, a large number of meaningless executions can be reduced.
[0078] In an embodiment of the present application, another blockchain-based transaction execution method is provided. This blockchain-based transaction execution method can be applied to Figure 2 the implementation environment shown, and this method can be executed by Figure 2 the blockchain node shown in Figure 4 As shown, on the basis of Figure 3 this, S330 is extended to S410 - S420. The details of S410 - S420 are introduced as follows:
[0079] S410. During the process of executing the to-be-executed transactions within any contract group, if the account information of the to-be-executed transactions within the contract group is different, then group the to-be-executed transactions within the contract group according to the account information, obtaining the to-be-executed transactions of multiple account groups.
[0080] In the embodiments of the present application, when the account information corresponding to the to-be-executed transactions within a contract group corresponds to different accounts, the to-be-executed transactions within the contract group are grouped according to the account information of the to-be-executed transactions. That is, all the to-be-executed transactions involving account a are placed in one group, all the to-be-executed transactions involving account b are placed in another group, and so on. After grouping, for the convenience of distinction, the account name is used as the identifier for grouping, and the to-be-executed transactions of multiple account groups are obtained.
[0081] In one example, the node can pre-group the accounts using similar contracts or similar functions locally, such as obtaining account group c and account group d. Then, when grouping according to the account information, the to-be-executed transactions are grouped based on this account group. For example, if the accounts involved in to-be-executed transactions 6 and 7 are within account group c, then to-be-executed transactions 6 and 7 are taken as the transactions of one account group; if the account involved in to-be-executed transaction 8 is not within any account group, then the account involved in to-be-executed transaction 8 can be separately divided into a group, and then to-be-executed transaction 8 is taken as the transaction of a new account group. This can ensure that the transactions within the same group are more likely to be related and reduce the competition within a group.
[0082] In another example, the transaction history of the accounts can be considered, and the accounts with similar transaction patterns or access patterns are grouped into one group. When grouping according to the account information, the to-be-executed transactions are grouped based on this account group.
[0083] S420. Determine that the execution order of the to-be-executed transactions between multiple account groups is parallel execution, and determine that the execution order of the to-be-executed transactions within any one account group is serial execution.
[0084] Since different accounts are often independent of each other, and generally there will be no data conflicts between different accounts, that is to say, they will not modify the state of the same contract at the same time. Therefore, different account groups can also be executed simultaneously without waiting for the results of other account groups, and it is determined that the execution order of the to-be-executed transactions between multiple account groups is parallel execution; in this way, the parallel computing power of the multi-core processor can be utilized to further improve the throughput of the blockchain.
[0085] For the to-be-executed transactions within each account group, the probability of conflict is relatively high. Therefore, it is determined that the execution order of the to-be-executed transactions within the account group is serial execution.
[0086] It should be noted that Figure 4 For other detailed introductions of steps S310 - S320 and S340 shown in Figure 3 please refer to the steps S310 - S320 and S340 shown in
[0087] In the embodiment of the present application, on the basis of contract grouping, when the account information of the to-be-executed transactions within the contract group is different, a further transaction group is realized based on the accounts. Since different accounts are often independent of each other, the transactions between them rarely conflict during execution and can be executed in parallel more efficiently, improving the performance of the overall system.
[0088] The embodiment of the present application also provides another blockchain-based transaction execution method. This blockchain-based transaction execution method can be applied to Figure 2 the implementation environment shown in Figure 2 and can be executed by the blockchain node shown in Figure 5 As shown in Figure 4 on the basis shown in
[0089] S510. If the account information of the to-be-executed transactions within the contract group is relevant, determine that the execution order of the to-be-executed transactions within the contract group is serial execution.
[0090] In the embodiment of the present application, if the account information of the to-be-executed transactions within the contract group is relevant, such as the same account information or similar functions, the probability of conflict between the to-be-executed transactions is greater. Therefore, determine that the execution order of the to-be-executed transactions within the contract group is serial execution.
[0091] S520. Determine the transaction logic relationship between the to-be-executed transactions within the contract group according to the transaction content of each to-be-executed transaction within the contract group.
[0092] S530. Determine the serial execution order of the to-be-executed transactions within the contract group according to the transaction logic relationship.
[0093] It can be understood that after determining serial execution, it is necessary to further determine the order of each to-be-executed transaction within the contract group. Among them, first analyze the transaction content of each to-be-executed transaction in this group. Among them, the transaction content can be determined based on the smart contract code corresponding to this contract group and information such as the data input and output of the transaction. Then analyze the transaction content of each to-be-executed transaction and find the logical relationship between the transactions, such as determining the data transfer and status change situation based on this transaction content.
[0094] According to the trading logical relationship, a trading graph or a directed graph is established, where nodes represent the to-be-executed transactions and directed edges represent the logical relationships between the transactions; by performing a topological sort on the trading graph, the serial execution order of the to-be-executed transactions can be determined. Among them, the topological sort ensures that there are no reverse edges between any two directed nodes in the graph. Based on the result of the topological sort, the serial execution order of the to-be-executed transactions is further determined. This order ensures that within the contract group, each transaction is executed after the transactions it depends on are completed, so as to meet the logical dependencies between the transactions.
[0095] It can be understood that in S520, if there is no trading logical relationship for the to-be-executed transactions, the serial execution order is determined based on the trading time of the to-be-executed transactions. In one example, in step S520, it is determined that some of the to-be-executed transactions have trading logical relationships and some do not. At this time, the execution order of the part of the to-be-executed transactions with trading logical relationships is prior to that of the part of the to-be-executed transactions without trading logical relationships.
[0096] It should be noted that Figure 5 For other detailed introductions of steps S310 - S320, S410 - S420, and S340 shown in Figure 4 Please refer to steps S310 - S320, S410 - S420, and S340 shown in
[0097] In the embodiments of the present application, when the account information of the to-be-executed transactions within the contract group is relevant, the trading logical relationships between the to-be-executed transactions within the contract group are determined, and then the trading execution order within the contract group is determined according to the trading logical relationships, improving the reliability of trading execution to ensure the correctness of transactions.
[0098] The embodiments of the present application provide another blockchain-based trading execution method. This blockchain-based trading execution method can be applied to Figure 2 the implementation environment shown in Figure 2 and can be executed by the blockchain node shown in Figure 6 As shown in Figure 4 this blockchain-based trading execution method expands S410 shown in
[0099] S610. During the process of executing the to-be-executed transactions within any contract group, traverse the to-be-executed transactions within the contract group and obtain the calling party account of the smart contract called by the currently traversed to-be-executed transaction.
[0100] In the embodiments of the present application, the to-be-executed transactions in the contract group can be sorted in advance based on the transaction time of the to-be-executed transactions in the contract group, so as to facilitate traversing the to-be-executed transactions in the contract group. When traversing, obtain the calling party account of the smart contract called by the currently traversed to-be-executed transaction, that is, the calling party account of the called smart contract. In one example, the account of the transaction initiator can be used as the calling party account.
[0101] S620. Determine the transaction calling party of the to-be-executed transaction according to the calling party account and the transaction account of the currently traversed to-be-executed transaction.
[0102] In the embodiments of the present application, the transaction accounts of the currently traversed to-be-executed transactions include the sender and receiver accounts in the transaction. For example, if the to-be-executed transaction is a transfer from account A to account B, the sender account is account A and the receiver account is account B. Among them, according to the calling party account and the transaction account of the to-be-executed transaction, the account with the same account can be used as the transaction calling party. For example, if the calling party account is account A, the sender account is account A, and the receiver account is account B, then it can be determined that the transaction calling party is A. If there is no same account between the calling party account and the transaction account of the to-be-executed transaction, such as the calling party account is account C, the sender account is account A, and the receiver account is account B. At this time, it can be determined whether there is a correlation between account A and account C. If there is a correlation, account C can be used as the transaction calling party. If there is no correlation, the to-be-executed transaction can be requested to be confirmed from account A. If account A confirms the to-be-executed transaction, account C is used as the transaction calling party. If account A does not confirm the to-be-executed transaction, the to-be-executed transaction is ignored.
[0103] S630. Construct an account group for each transaction calling party, and write the to-be-executed transactions corresponding to each transaction calling party into the corresponding account group to obtain the to-be-executed transactions of multiple account groups.
[0104] Construct an account group for each transaction calling party. Then, for each to-be-executed transaction, the to-be-executed transactions corresponding to each transaction calling party are written into the corresponding account group. For example, construct account group A for transaction calling party A. The to-be-executed transactions 8 and 9 corresponding to this transaction calling party A are then written into account group A, so as to obtain the to-be-executed transactions of multiple account groups.
[0105] It should be noted that Figure 6 For the detailed introduction of steps S310 - S320, S420, and S340 shown in Figure 4 please refer to steps S310 - S320, S420, and S340 shown in
[0106] In the embodiments of the present application, by traversing the to-be-executed transactions in the contract group and determining the transaction caller through the caller account and the transaction account corresponding to the currently traversed to-be-executed transaction, an account group is constructed, ensuring the orderliness of the grouping of to-be-executed transactions and improving the accuracy of account group construction.
[0107] In an embodiment of the present application, another blockchain-based transaction execution method is further provided. This blockchain-based transaction execution method can be applied to Figure 3 the implementation environment shown in Figure 3 and can be executed by the blockchain node shown in Figure 7 As shown in Figure 3 Based on what is shown in
[0108] S710. Obtain multiple to-be-executed transactions in the current block and obtain the contract information carried by the to-be-executed transactions.
[0109] S720. If it is determined according to the contract information that the number of smart contracts called by the to-be-executed transaction includes at least two, then regard the to-be-executed transaction as the to-be-executed transaction of the multi-contract group.
[0110] S730. If it is determined according to the contract information that the number of smart contracts called by the to-be-executed transaction is one, then regard the to-be-executed transaction as the to-be-executed transaction of the single-contract group corresponding to the smart contract.
[0111] In the embodiments of the present application, the smart contract called by the to-be-executed transaction can be determined through the contract information carried by the to-be-executed transaction. If the number of smart contracts called includes at least two, regardless of whether there is a calling relationship between the at least two smart contracts, a multi-contract group is created for the to-be-executed transaction, and then the to-be-executed transaction is regarded as the to-be-executed transaction of the multi-contract group, that is, the transactions corresponding to single contracts and multi-contracts are stored in different groups. For example, if the smart contracts called by the to-be-executed transaction include contract E and contract F, then the to-be-executed transaction is regarded as the to-be-executed transaction of the multi-contract group E-F, that is, the name of the contract called by the to-be-executed transaction is used as the identifier of the multi-contract group to distinguish it from other contract groups.
[0112] If it is determined according to the contract information that the number of smart contracts called by the to-be-executed transaction is one, then all the to-be-executed transactions that call this smart contract are divided into one group, and then the to-be-executed transaction is regarded as the to-be-executed transaction of the single-contract group corresponding to the smart contract. If the smart contract called by the to-be-executed transaction is contract A, the to-be-executed transaction is regarded as the to-be-executed transaction of the single-contract group A.
[0113] S740. Execute the pending transactions between each single contract group in parallel, and after the pending transactions of each single contract group are executed, execute the pending transactions within the multi - contract group.
[0114] In the embodiments of the present application, there is generally no data conflict between single contract groups, and the status of the same account will not be modified simultaneously. Therefore, the pending transactions between each single contract group are executed in parallel. For the pending transactions of the multi - contract group, since multiple contracts are called, the probability of conflict is higher than that of the single contract group, and the execution of the pending transactions of the multi - contract group may affect the single contract group. Therefore, after the pending transactions of each single contract group are executed, the pending transactions of the multi - contract group are executed.
[0115] It can be understood that there can be multiple pending transactions within the multi - contract group. The execution order between these multiple pending transactions can be a serial execution order or a parallel execution order, which is specifically determined according to the accounts to which the pending transactions belong.
[0116] It should be noted that Figure 7 For other detailed introductions of steps S330 - S340 shown in Figure 3 Please refer to steps S330 - S340 shown in
[0117] In the embodiments of the present application, for pending transactions that involve at least two contract calls, they are grouped separately and placed in a multi - contract group. Then, when executing the transactions of the contract group, after the pending transactions of each single contract group are executed, the pending transactions of the multi - contract group are executed, avoiding the impact of the multi - contract group on the single contract group and ensuring the correctness of the execution of each contract group.
[0118] The embodiments of the present application provide another blockchain - based transaction execution method. This blockchain - based transaction execution method can be applied to Figure 2 the implementation environment shown in Figure 2 and can be executed by the blockchain node shown in Figure 8 As shown in Figure 7 On this basis, this blockchain - based transaction execution method expands S740 to S810 - S830. The detailed introduction of steps S810 - S830 is as follows:
[0119] S810. Execute the pending transactions between each single contract group in parallel, and after the pending transactions of each single contract group are executed, determine the calling contract and the called contract according to the call relationship of at least two smart contracts.
[0120] In the embodiments of the present application, the call relationship between at least two smart contracts can be determined based on the smart contract code, and the contract information of the called contract is described in the smart contract code. Therefore, it can be determined whether there is a call relationship before the smart contract. When there is a call relationship between at least two smart contracts, the calling contract and the called contract in the two smart contracts are determined. For example, if smart contract C calls smart contract D, then the calling contract is contract C and the called contract is contract D.
[0121] S820. Execute the to-be-executed transaction according to the calling contract to obtain the context information of the to-be-executed transaction.
[0122] In the embodiments of the present application, the to-be-executed transaction is executed according to the calling contract, such as reading data and modifying the transaction status. During the execution of the to-be-executed transaction, the context information of the to-be-executed transaction is collected. The context information includes various environment and status information required for executing the transaction to help ensure the correct execution of the transaction and record the execution result. For example, the context information includes the input data required by the calling contract and the called contract, the output data of the calling contract, the state of the smart contract before the transaction execution, and the state change after the transaction execution, etc.
[0123] S830. Generate a sub-transaction according to the context information of the to-be-executed transaction and send the sub-transaction to the called contract for execution.
[0124] In one example, the context information of the to-be-executed transaction can be used as the sub-transaction, and then the sub-transaction is sent to the called contract for execution. After receiving the sub-transaction, the called contract executes the smart contract code therein. At this stage, the called contract can read the context information and perform corresponding operations as needed. The execution of the called contract may cause state modification and event triggering, which are used as the execution result of the called contract, and then the execution result is returned to the calling contract. Based on the contract code of the calling contract, the calling contract continues to execute the to-be-executed transaction based on the execution result.
[0125] It should be noted that Figure 8 For other detailed introductions of steps S710 - S730 and S330 - S340 shown in Figure 7 Please refer to steps S710 - S730 and S330 - S340 shown in
[0126] In the embodiments of the present application, cross-contract transactions with dependencies are grouped together and executed in the order of dependencies, ensuring the correct collaborative execution of the calling contract and the called contract and improving the correctness of cross-contract transaction execution.
[0127] The embodiments of the present application provide another blockchain-based transaction execution method. The blockchain-based transaction execution method can be applied toFigure 2 In the implementation environment shown, this method can be executed by Figure 2 the blockchain node shown in Figure 9 As shown, this blockchain-based transaction execution method will Figure 3 On the basis shown in , step S310 is extended to step S910, and S340 is extended to S920 - S930. S910 - S930 are introduced in detail as follows:
[0128] S910. Obtain multiple to-be-executed transactions in the current block. If it is determined according to the contract information carried by the to-be-executed transactions that the smart contracts called by the target to-be-executed transaction include at least two smart contracts with a call relationship, then write the target to-be-executed transaction into the target contract group corresponding to the called smart contract.
[0129] It should be noted that Figure 7 and Figure 9 are two different grouping and execution methods for cross-contract transactions. Refer to Figure 7 In S710 in , obtain contract information. If it is determined according to the contract information that the smart contracts called by the target to-be-executed transaction include at least two smart contracts with a call relationship, when grouping the target to-be-executed transaction, write the target to-be-executed transaction into the target contract group corresponding to the called smart contract. For example, if smart contract C calls smart contract D, then write the target to-be-executed transaction into contract group C. Among them, the target to-be-executed transaction can be any transaction in the block.
[0130] S920. When executing the target to-be-executed transactions in the target contract group according to the execution order, execute the target to-be-executed transactions according to the smart contract corresponding to the target contract group to obtain the context information of the target to-be-executed transactions.
[0131] After grouping the to-be-executed transactions in the block to obtain the to-be-executed transactions of multiple contract groups, when parallelizing the to-be-executed transactions between each contract group, and during the process of the to-be-executed transactions in the target contract group, when executing up to the target to-be-executed transaction according to the execution order, at this time, execute the target execution transaction according to the smart contract corresponding to the target contract group and obtain the corresponding context information. That is, for the process of executing the target execution transaction based on smart contract C and obtaining the corresponding context information, please refer to Figure 7 .
[0132] S930. Generate sub-transactions according to the context information and write the sub-transactions into the contract group corresponding to the called smart contract.
[0133] Use the context information as a sub - transaction and write the sub - transaction into the contract group corresponding to the called smart contract. For example, write the sub - transaction into contract group D. When executing the transactions in contract group D, first execute the to - be - executed transactions in the contract group, and after all the to - be - executed transactions are executed, execute the sub - transaction according to smart contract D.
[0134] It should be noted that Figure 9 For the detailed introduction of steps S320 - S330 shown in Figure 3 please refer to steps S320 - S330 shown in
[0135] In the embodiments of the present application, for the to - be - executed transactions where the number of called contracts includes at least two and the contracts have a calling relationship, write the to - be - executed transactions into the contract group corresponding to the calling contract, and execute the to - be - executed transactions normally. Then, construct a sub - transaction by obtaining context information and write it into the contract group corresponding to the called contract for execution, avoiding the impact of multiple contract groups on a single contract group and improving the correctness of cross - contract transaction execution.
[0136] The embodiments of the present application provide another blockchain - based transaction execution method. This blockchain - based transaction execution method can be applied to Figure 2 the implementation environment shown in Figure 2 and can be executed by the blockchain node shown in Figure 10 As shown, this blockchain - based transaction execution method expands Figure 3 S310 shown in
[0137] S1010. Traverse each to - be - executed transaction in the current block and obtain the smart contract called by the current to - be - executed transaction.
[0138] The to - be - executed transactions in the current block can be sorted in advance based on the transaction time of the to - be - executed transactions to facilitate traversing the to - be - executed transactions in the current block. When traversing, obtain the smart contract called by the currently traversed to - be - executed transaction.
[0139] S1020. If the smart contract called by the current to - be - executed transaction has been associated with a pre - constructed shard cache, write the current to - be - executed transaction into the shard cache.
[0140] In the embodiments of the present application, a shard cache for caching transactions is pre - constructed, and the shard cache is associated with the smart contract. Here, the association between the shard cache and the smart contract can be that the smart contract exists in the shard cache or is marked for association. In one example, the blockchain slave node can pre - select smart contracts with a call frequency greater than a preset frequency threshold, and then construct a shard cache for the selected smart contracts.
[0141] If the smart contract called by the currently to-be-executed transaction has been associated with a shard cache, the currently to-be-executed transaction can be directly written into the shard cache.
[0142] S1030. If the smart contract called by the currently to-be-executed transaction is not associated with a shard cache, a new shard cache is constructed for the smart contract, and the currently to-be-executed transaction is written into the new shard cache.
[0143] If the smart contract called by the currently to-be-executed transaction is not associated with a shard cache, a new shard cache needs to be constructed for the smart contract. Then, the currently to-be-executed transaction is written into the new shard cache, and subsequent transactions that call the smart contract are also written into the new shard cache, so that each to-be-executed transaction can be written into the corresponding shard cache.
[0144] S1040. Obtain the to-be-executed transactions of multiple contract groups according to each shard cache.
[0145] In the embodiment of the present application, each shard cache can be used as a contract group, and the to-be-executed transactions in the shard cache are the to-be-executed transactions within the contract group. Among them, the shard cache can be identified and distinguished by the corresponding smart contract name.
[0146] It should be noted that Figure 10 For the detailed introduction of steps S320 - S340, please refer to Figure 3 the steps S320 - S340 shown therein, which will not be elaborated herein.
[0147] In the embodiment of the present application, by traversing the to-be-executed transactions in the previous block, and then according to the association between the smart contract called by the currently to-be-executed transaction and the shard cache, the transaction is written into the corresponding shard cache, and then a contract group is obtained, ensuring the orderliness of the grouping of to-be-executed transactions and improving the accuracy of contract group construction.
[0148] The embodiment of the present application provides another blockchain-based transaction execution method. This blockchain-based transaction execution method can be applied to Figure 2 the implementation environment shown therein. This method can be executed by Figure 2 the blockchain node shown therein. As Figure 11 shown, on the basis of what is shown in Figure 10 this blockchain-based transaction execution method expands S320 to S1110 - S1130. That is, after grouping based on the smart contract shown in Figure 10 shown, when parallelly executing the to-be-executed transactions of each contract group, it is necessary to avoid conflicts between contracts. The detailed introduction of steps S1110 - S1130 is as follows:
[0149] S1110. Obtain the resource information required for the smart contracts corresponding to each contract group.
[0150] It can be understood that the execution of a smart contract may require corresponding resources. If multiple contracts require the same resources, there may be a situation of competing for resources, resulting in conflicts. Therefore, for each smart contract group, it is necessary to clarify the resource information required by the contracts within the group during execution. This resource information includes but is not limited to computing resources, storage resources, network resources, etc. If a contract needs to read and write shared state variables, it may need to access external data sources or perform complex calculations.
[0151] S1120. Determine whether there is a resource competition relationship between smart contracts based on the resource information required for the smart contracts.
[0152] S1130. If there is no resource competition relationship between smart contracts, then execute the pending transactions between each contract group in parallel.
[0153] In one example, for the contracts within each contract group, analyze their resource requirements, that is, match the resource information required for the smart contracts with the preset shared resources to determine whether there is competition for the shared resources. The shared resources may include global state, storage areas, etc. If there is competition for the shared resources, it means that there is a resource competition relationship between the contracts.
[0154] In another example, if two or more smart contracts need to access or modify the same resource simultaneously and no appropriate synchronization mechanism is adopted, it also means that there is a resource competition relationship between the contracts.
[0155] In the embodiments of the present application, for contract groups without a resource competition relationship, the pending transactions can be safely executed in parallel. When executing in parallel, it is necessary to ensure that the pending transactions within each contract group are scheduled according to their internal execution order to maintain the correct execution of the contracts.
[0156] In other embodiments, for contract groups with a resource competition relationship, when the pending transactions of the contract groups are executed in parallel, the probability of conflicts is relatively high. Therefore, they can be merged into one contract group. For example, if contract group A and contract group B have a resource competition relationship, then contract group A and contract group B are merged into a contract group A - B, and contract group A - B is executed in parallel with other contract groups.
[0157] In other embodiments, if there is a resource competition relationship between the smart contracts in a certain contract group, a lock mechanism, a transaction mechanism, or the contract logic can be redesigned to avoid resource competition.
[0158] It should be noted that Figure 11For a detailed introduction to steps S1010 - S1040 and S330 - S340 shown in Figure 10 steps S1010 - S1040 and S330 - S340, which will not be elaborated here.
[0159] In the embodiments of the present application, resource information required by smart contracts is used to determine whether there is a resource competition relationship between contracts. Then, when there is no resource competition relationship between contracts, the contract group is executed in parallel, avoiding contract conflicts, improving the overall execution efficiency of smart contracts, and ensuring the correctness of contracts and data consistency.
[0160] It should be noted that the embodiments of the present application provide another blockchain - based transaction execution method, which can be applied to Figure 2 the implementation environment shown in Figure 2 and can be executed by the blockchain node shown in Figure 12 As shown in Figure 10 step S320 shown in
[0161] S1210. Obtain the contract code of the smart contracts corresponding to each contract group and the contract call chain of the historical transactions of the blockchain.
[0162] In the embodiments of the present application, the blockchain node can obtain the contract code of the smart contracts corresponding to each contract group. Through the contract code, the execution logic and rules of the smart contracts can be determined to determine whether the contract has calls and interactions with other contracts.
[0163] To ensure the confirmation of the dependency relationship between contracts, in the embodiments of the present application, the historical transactions of the blockchain are also analyzed. The historical transactions are the transactions that called the smart contract. It can be understood that the historical transactions can be local or from other blockchain nodes of the blockchain.
[0164] Among them, the contract call chain of the smart contract can be determined by the execution footprint of correctly executing the historical transaction by the smart contract; or the contract call chain can be obtained by viewing information such as call records or contract addresses in the transaction.
[0165] S1220. Determine whether there is a dependency relationship between smart contracts according to the contract code of the smart contracts and the contract call chain.
[0166] In the embodiments of the present application, it is necessary to determine whether there is a dependency relationship between smart contracts by combining the contract code of the smart contracts and the contract call chain. If it is determined through the contract code of smart contract A that contract A calls contract B, and it is also determined through the contract call chain that contract A has called contract B, then it is directly determined that there is a dependency relationship between contract A and contract B. If it is determined through the contract code that contract A does not call contract B, and it is determined through the contract call chain that contract A does not call contract B, then it is determined that there is no dependency relationship between contract A and contract B.
[0167] In one example, if it is preliminarily determined that there is a call relationship between smart contracts based on the contract code of the smart contracts or the contract call chain, then a contract call graph is constructed according to the contract code and the contract call chain; the call depth of the call relationship is obtained based on the contract call graph to further analyze whether there is a dependency relationship; wherein, if the call depth is greater than a preset depth threshold, it is determined that there is a dependency relationship between the smart contracts.
[0168] For example, if it is determined through the contract code of smart contract A that contract A calls contract B, but it is determined through the contract call chain that contract A does not call contract B, or if it is determined through the contract code that contract A does not call contract B, but the contract call chain determines that contract A calls contract B, it can be preliminarily determined that there is a call relationship between contract A and contract B, and it is necessary to further analyze the call depth of the call relationship.
[0169] For each smart contract, identify the statements that call other contracts from its contract code, and construct a call graph according to the call statements and the contract call chain, where the nodes represent contracts and the directed edges represent call relationships. Then, by traversing the call graph, calculate the call depth from the current contract to other contracts, and this depth represents the nested level of the call relationship.
[0170] In other embodiments, the complexity of the call relationship can also be analyzed. The complexity can include multiple aspects, such as the number of calls within a contract, the number of branches in the call chain, etc. Therefore, the number of calls within each contract can be counted to understand its complexity. For the call chain between contracts, analyze whether there is a multi-branch call, that is, whether a contract calls multiple contracts simultaneously, which may lead to race conditions during parallel execution. It can be understood that the more calls within a contract, the higher its complexity, and the more branches in the call chain, the higher its complexity.
[0171] Among them, in the analysis of the call relationship, it is necessary to pay attention to whether there is a recursive call situation. Recursive calls may increase the complexity and depth of execution; in addition, it is also possible to identify whether there is a circular call situation between contracts. Circular dependencies may lead to deadlocks or unsolvable race conditions during parallel execution. Among them, loops can be detected in the call graph to ensure that the call relationships between contracts do not form a cycle. Circular calls will also increase the complexity and depth of execution.
[0172] If the analysis result shows that the depth or complexity of the call relationships among the contracts within a certain contract group is greater than a preset threshold, it is finally determined that there is a dependency relationship, and it may be necessary to consider executing them serially to avoid potential problems during parallel execution.
[0173] S1230. If there is no dependency relationship among the smart contracts, then execute the pending transactions among the contract groups in parallel.
[0174] In the embodiments of the present application, for contract groups without dependency relationships, the pending transactions can be safely executed in parallel. During parallel execution, it is necessary to ensure that the pending transactions within each contract group are scheduled according to their internal execution order to maintain the correct execution of the contracts.
[0175] In other embodiments, for contract groups with dependency relationships, they can be merged into one contract group. For example, if there is a resource competition relationship between contract group A and contract group B, then contract group A and contract group B are merged into a contract group A - B, and contract group A - B is executed in parallel with other contract groups.
[0176] It should be noted that Figure 12 For the detailed introduction of steps S1010 - S1040 and S330 - S340 shown in Figure 10 please refer to steps S1010 - S1040 and S330 - S340 shown in
[0177] In the embodiments of the present application, it is determined whether there is a dependency relationship among the contracts according to the contract code of the smart contracts and the corresponding contract call chain, and reasonable processing is performed in the case of dependencies to improve the execution efficiency and parallelism of the smart contracts and avoid contract conflict situations.
[0178] It is worth noting that in the embodiments of the present application, Figure 11 shown in Figure 12 and the embodiments shown in Figure 11 and Figure 12 can be combined, that is, it is determined that there is no resource competition relationship among the smart contracts according to the resource information required by the smart contracts, and further it is determined whether there is a dependency relationship among the smart contracts according to the contract code and contract call chain of the smart contracts. If there is no dependency relationship, then the pending transactions of each contract group are executed in parallel; in addition, Figures 3 to 9 the embodiments shown in
[0179] The embodiments of the present application provide another blockchain - based transaction execution method. This blockchain - based transaction execution method includes that it can be applied to Figure 2 the implementation environment shown in Figure 2 and this method can be executed by the blockchain node shown inFigure 13 As shown, based on the method for executing transactions on a blockchain, on the basis of what is shown in Figures 3 to 12 , step S320 is extended to steps S1310 to S1330. Among them, S1310 to S1330 are introduced in detail as follows:
[0180] S1310. During the process of parallelly executing the to-be-executed transactions between each contract group, obtain the resource utilization rate of the blockchain and the transaction load of each contract group.
[0181] In the embodiments of the present application, during the process of parallelly executing the to-be-executed transactions between each contract group, the number of parallel executions can be adjusted according to the real-time state and load conditions of the blockchain, so as to maximize the parallel performance of the blockchain. Among them, the resource utilization rate of the blockchain includes CPU utilization rate, memory utilization rate, and storage utilization rate. Through the CPU utilization rate, the usage of the current computing resources can be understood. By understanding the memory utilization rate, it is ensured that there is no memory bottleneck; by checking the storage utilization rate, it is ensured that the read and write operations of data do not become bottlenecks.
[0182] The transaction load of the contract group includes the number of to-be-executed transactions within each contract group, and also includes the complexity of the transaction determined by calculating the computing and storage requirements of each transaction, and the transaction response time determined by measuring the response time of the transaction.
[0183] S1320. Determine the number of threads for re-adjusting concurrent execution according to the resource utilization rate and the transaction load.
[0184] S1330. Parallelly execute the to-be-executed transactions between each contract group according to the adjusted number of threads.
[0185] Combine the information of the resource utilization rate and the transaction load to form a comprehensive understanding of the blockchain load, and judge whether the blockchain is in a high-load, low-load, or moderate state according to the current load situation. For example, if the resource utilization rate of the blockchain is less than the preset resource threshold, it means that the resources are sufficient, but the transaction load is greater than the preset load threshold, indicating a high load, and it is determined that the blockchain is in a low-load state; if the resource utilization rate of the blockchain is greater than the preset resource threshold, it means that the resources are limited, but the transaction load is less than the preset load threshold, indicating a low load, and it is determined that the blockchain is in a high-load state.
[0186] In one example, according to the total resource utilization rate of the system and the transaction load of each contract group, adopt a load balancing strategy. This load balancing strategy includes dynamically setting a dynamic adjustment threshold for the number of threads. When the blockchain is in a low-load state, consider increasing the number of threads to improve the parallel processing ability; when the blockchain is in a high-load state, consider reducing the number of threads to release resources or reduce energy consumption; and then, according to the dynamically adjusted number of threads, re-arrange the parallel execution of the to-be-executed transactions between each contract group.
[0187] For example, if the number of contract groups is 5 and the adjusted number of threads is 3, then 3 contract groups need to be selected from the 5 contract groups for parallel execution. Among them, the selection can be random or based on the importance of the functions of the smart contracts corresponding to each contract group.
[0188] It should be noted that Figure 13 For the detailed introduction of steps S310, S330 to S340 shown in Figure 3 steps S310, S330 to S340 shown in
[0189] In the embodiments of the present application, during the process of parallelly executing the to-be-executed transactions between contract groups, by obtaining the resource utilization rate of the blockchain and the transaction loads of each contract group, the number of concurrently executed threads can be intelligently adjusted in different scenarios, so as to achieve the optimal utilization of the blockchain performance.
[0190] For the convenience of understanding, the following is a detailed description of the blockchain-based transaction execution method provided by the embodiments of the present application based on Figure 2 the implementation environment shown in
[0191] When a blockchain node obtains a block, it first optimizes the transaction scheduling based on the smart contracts called by each to-be-executed transaction in the block. As Figure 14 shown, the embodiments of the present application construct a simple contract call relationship. For the to-be-executed transactions tx1 and tx2, account A1 calls contract C1; for the to-be-executed transactions tx3 and tx4, account A2 calls contract C2; for the to-be-executed transactions tx5 and tx6, account A3 calls contract C3. In the actual call process, there is often no conflict between contracts. At this time, sharding (i.e., grouping) is performed based on the contracts.
[0192] As Figure 15 shown, a contract group is constructed for each called contract. For example, in contract group 1, all transactions call contract C1; in contract group 2, all transactions call contract C2; in contract group 2, all transactions call contract C3. Through this sharding method, compared with serial execution, the parallelism of contract execution is increased, and the execution performance of the contract is improved; in Figure 15 each contract group, all transactions are calls to this contract by the same account, so there is no need to perform secondary grouping based on the account.
[0193] As Figure 16As shown in the figure, the specific contract group construction includes: First, construct shard caches to cache the sharded transactions. Then, traverse all the transactions in the block. For the currently traversed transaction tx, obtain the contract tx.call called by the transaction based on the call method in the contract tx = block.txs[i]. If the contract tx.call called by the transaction already exists in the shard cache, then directly put the transaction tx into the shard cache. If the contract called by the transaction does not exist in the shard cache, then construct a new shard cache shards[call] for this contract and put the transaction tx into the shard cache shards[call], and then continue to traverse the next one. Finally, when all the transactions in the block have been grouped by contract, use a shard cache as a contract group, and this process ends.
[0194] Subsequently, execute the transactions grouped by contract in parallel. At this time, the transactions in each contract group are from the same account. When the same account calls the same contract, the possibility of conflicts between transactions will increase. Therefore, the transactions between contract groups can be executed in parallel, while the transactions within a contract group are executed serially.
[0195] In one example, to support more complex smart contract logic, it is allowed that a transaction can call the functions of other contracts during the execution process. For example, a transaction of contract A can call the functions of contract B, which can achieve the cooperation and communication between contracts and improve the functionality of smart contracts. However, the difficulty of doing this is how to ensure the atomicity and consistency of the transactions of cross-contract calls. That is to say, if a transaction involves the functions of multiple contracts, then they either all execute successfully or all fail and roll back, and it is necessary to ensure that the states of all contracts are consistent.
[0196] In the embodiment of the present application, during the execution of all transactions, if a cross-contract call situation is found, the cross-contract transactions can be grouped separately, that is, write the transactions into a multi-contract group, and then execute the separate multi-contract group after all the contract groups have been executed finally; or write the cross-contract transactions into the contract group of the calling contract. Then, when the execution of this layer of contract is completed, construct the context information of the transaction. After all the contract groups have been executed finally, write the sub-transactions into the contract group of the called contract, and finally execute the sub-transactions. If the sub-transactions also execute successfully, then this transaction is successful, otherwise it fails. In this way, the atomicity and consistency of the cross-contract call transactions can be ensured.
[0197] In one example, as Figure 17As shown, there are also complex contract call relationships. For tx1, account A1 calls contract C1; for tx2, account A2 calls contract C1; for tx3, account A2 calls contract C2; for tx4, account A3 calls contract C2; for tx5, account A3 calls contract C3; for tx6, account A1 calls contract C3.
[0198] In the actual call process, there are often no conflicts between contracts and no conflicts between accounts. At this time, two-level grouping can be performed based on contracts and accounts, and three contract groups as shown in Figure 18 can be constructed. Since the contracts within each contract group are called by different accounts, secondary grouping can be performed based on accounts. Through this sharding method, compared with serial execution, the parallelism of contract execution will be increased, and the execution performance of the contract will be improved. Compared with complete parallel scheduling, the actual relationship between contracts and accounts is considered, and invalid repeated calls are minimized. For example, in Figure 18 , for the transactions calling C1 in shard 1, since account A1 and account A2 are different, they are divided into two account groups within shard 1, that is, account group 1 includes tx1 and account group 2 includes tx2.
[0199] For example, as shown in Figure 19 , the specific account group construction process includes: The account group logic is similar to the contract group logic. First, construct a sub-shard cache slices to cache the transactions after grouping. Then, traverse all the transactions in the contract group. For the currently traversed transaction in the contract group, judge who sent the transaction based on the caller account account in the contract. If the transaction caller tx.account already exists in the sub-shard cache, the transaction can be directly put into the shard cache. If the transaction caller does not exist in the sub-shard cache, a new sub-shard cache slices[account] is constructed for this account, and the transaction is put into the sub-shard cache slices[account], and then continue to traverse the next one. Finally, when all the transactions in the contract shard have been grouped by account, the sub-shard cache is used as the account group, and this process ends.
[0200] Subsequently, the transactions grouped based on accounts are executed in parallel. At the same time, since the transactions in each contract group come from different accounts, the account groups between different contract groups can also be executed in parallel, which will further improve the contract execution efficiency.
[0201] The transaction execution method provided by the embodiments of the present application proposes an optimized transaction scheduling scheme based on contracts and account grouping in a blockchain. In this scheme, it is not a simple serial execution nor a complete parallel execution, but a "controllable" parallel scheduling method based on contract and account grouping. First, the transactions in a block are grouped based on the smart contracts they call. The basis for this optimization is that there are often no conflicts between contracts, while there are often conflicts among transactions accessing the same contract. After grouping based on contracts, different contracts form different contract groups, and parallel execution is carried out among different contract groups. Through this safe "controllable" parallel scheduling method, on the one hand, it has a high performance improvement compared with serial execution, and on the other hand, it is more reliable than complete parallel scheduling, avoiding a large number of meaningless parallel schedules in extreme cases. Secondly, in order to further achieve parallel execution of transactions within each contract group, within each contract group, a two-layer concurrent scheduling execution is implemented based on accounts. The basis for this optimization is that there are often no call conflicts between different accounts. Through the two-layer concurrent scheduling model, in a conflict-free scenario, the concurrent performance will be the same as that of complete concurrent scheduling.
[0202] The device embodiments of the present application are introduced, which can be used to execute the blockchain-based transaction execution method in the above embodiments of the present application. For the details not disclosed in the device embodiments of the present application, please refer to the embodiments of the above blockchain-based transaction execution method of the present application.
[0203] The embodiments of the present application provide a blockchain-based transaction execution device, as Figure 20 shown. The blockchain-based transaction execution device can be configured in a blockchain node. The device includes:
[0204] A grouping module 2010, configured to obtain multiple to-be-executed transactions in the current block, and group the to-be-executed transactions according to the smart contracts called by the to-be-executed transactions, so as to obtain the to-be-executed transactions of multiple contract groups;
[0205] An execution module 2020, configured to execute the to-be-executed transactions between each contract group in parallel;
[0206] A determination module 2030, configured to determine the execution order of the to-be-executed transactions in the contract group according to the account information to which the to-be-executed transactions in the contract group belong during the process of executing the to-be-executed transactions in any contract group;
[0207] The execution module 2020 is further configured to execute the to-be-executed transactions in the contract group according to the execution order.
[0208] In one embodiment of the present application, based on the foregoing solution, the determining module is further configured to, if the account information to which the to-be-executed transactions in the contract group belong is different, group the to-be-executed transactions in the contract group according to the account information to obtain to-be-executed transactions of multiple account groups; determine that the execution order of the to-be-executed transactions between the multiple account groups is parallel execution, and determine that the execution order of the to-be-executed transactions within any one account group is serial execution.
[0209] In one embodiment of the present application, based on the foregoing solution, the determining module is further configured to, if the account information to which the to-be-executed transactions in the contract group belong is relevant, determine that the execution order of the to-be-executed transactions in the contract group is serial execution; determine the transaction logic relationship between the to-be-executed transactions in the contract group according to the transaction content of each to-be-executed transaction in the contract group; and determine the serial execution order of the to-be-executed transactions in the contract group according to the transaction logic relationship.
[0210] In one embodiment of the present application, based on the foregoing solution, the determining module is further configured to traverse the to-be-executed transactions in the contract group and obtain the calling party account of the smart contract called by the currently traversed to-be-executed transaction; determine the transaction calling party of the to-be-executed transaction according to the calling party account and the transaction account of the currently traversed to-be-executed transaction; construct an account group for each transaction calling party, and write the to-be-executed transactions corresponding to each transaction calling party into the corresponding account group to obtain the to-be-executed transactions of the multiple account groups.
[0211] In one embodiment of the present application, based on the foregoing solution, the grouping module is further configured to obtain the contract information carried by the to-be-executed transaction; if it is determined according to the contract information that the number of smart contracts called by the to-be-executed transaction includes at least two, then regard the to-be-executed transaction as the to-be-executed transaction of a multi-contract group; if it is determined according to the contract information that the number of smart contracts called by the to-be-executed transaction is one, then regard the to-be-executed transaction as the to-be-executed transaction of the single-contract group corresponding to the smart contract; the execution module is further configured to parallel-execute the to-be-executed transactions between the single-contract groups, and after the to-be-executed transactions in each single-contract group are executed, execute the to-be-executed transactions in the multi-contract group.
[0212] In one embodiment of the present application, based on the foregoing solution, the execution module is further configured to determine a calling contract and a called contract according to the calling relationship of at least two of the smart contracts; execute the to-be-executed transaction according to the calling contract to obtain the context information of the to-be-executed transaction; generate a sub-transaction according to the context information of the to-be-executed transaction, and send the sub-transaction to the called contract for execution.
[0213] In one embodiment of the present application, based on the foregoing solution, if the grouping module further determines that the smart contracts called by the target pending transaction include at least two smart contracts with a calling relationship according to the contract information carried by the pending transaction to be executed, the target pending transaction is written into the target contract group corresponding to the called smart contract; the execution module is further configured to, when executing the target pending transaction in the target contract group according to the execution order, execute the target pending transaction according to the smart contract corresponding to the target contract group to obtain the context information of the target pending transaction; generate a sub-transaction according to the context information, and write the sub-transaction into the contract group corresponding to the called smart contract.
[0214] In one embodiment of the present application, based on the foregoing solution, the grouping module is further configured to traverse each pending transaction in the current block and obtain the smart contract called by the current pending transaction; if the smart contract called by the current pending transaction has been associated with a pre-constructed shard cache, write the current pending transaction into the shard cache; if the smart contract called by the current pending transaction is not associated with the shard cache, construct a new shard cache for the smart contract, and write the current pending transaction into the new shard cache; obtain the pending transactions of the multiple contract groups according to each shard cache.
[0215] In one embodiment of the present application, based on the foregoing solution, the execution module is further configured to obtain the resource information required by the smart contracts corresponding to each contract group; determine whether there is a resource competition relationship between the smart contracts according to the resource information required by the smart contracts; if there is no resource competition relationship between the smart contracts, execute the pending transactions between the contract groups in parallel.
[0216] In one embodiment of the present application, based on the foregoing solution, the execution module is further configured to obtain the contract code of the smart contract and the contract call chain of the historical transactions of the blockchain; determine whether there is a dependency relationship between the smart contracts according to the contract code of the smart contract and the contract call chain; if there is no dependency relationship between the smart contracts, execute the pending transactions between the contract groups in parallel.
[0217] In one embodiment of the present application, based on the foregoing solution, if the execution module further determines that there is a calling relationship between the smart contracts according to the contract code of the smart contract or the contract call chain, a contract call graph is constructed according to the contract code and the contract call chain; the call depth of the calling relationship is obtained according to the contract call graph; if the call depth is greater than a preset depth threshold, it is determined that there is a dependency relationship between the smart contracts.
[0218] In one embodiment of the present application, based on the foregoing solution, the execution module is further configured to, during the parallel execution of the to-be-executed transactions between each contract group, obtain the resource utilization rate of the blockchain and the transaction loads of each contract group; determine the number of threads for concurrent execution to be readjusted according to the resource utilization rate and the transaction loads; and parallelly execute the to-be-executed transactions between each contract group according to the adjusted number of threads.
[0219] It should be noted that the device provided in the above embodiment and the method provided in the above embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated herein.
[0220] An embodiment of the present application further provides an electronic device, including one or more processors and a storage device. The storage device is configured to store one or more computer programs. When the one or more computer programs are executed by the one or more processors, the electronic device implements the blockchain-based transaction execution method as described above.
[0221] Figure 21 The structural schematic diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application is shown.
[0222] It should be noted that Figure 21 The computer system 2100 of the shown electronic device is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application. Among them, the electronic device may be a terminal or a server.
[0223] As Figure 21 shown, the computer system 2100 includes a processor (Central Processing Unit, CPU) 2101, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 2102 or the program loaded from the storage section 2108 into the random access memory (RAM) 2103, such as executing the method in the above embodiment. In the RAM 2103, various programs and data required for system operations are also stored. The CPU 2101, the ROM 2102, and the RAM 2103 are connected to each other through a bus 2104. The input / output (Input / Output, I / O) interface 2105 is also connected to the bus 2104.
[0224] In some embodiments, the following components are connected to the I / O interface 2105: an input section 2106 including a keyboard, a mouse, etc.; an output section 2107 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 2108 including a hard disk, etc.; and a communication section 2109 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 2109 performs communication processing via a network such as the Internet. The drive 2110 is also connected to the I / O interface 2105 as needed. A removable medium 2111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 2110 as needed so that a computer program read therefrom is installed into the storage section 2108 as needed.
[0225] Specifically, according to the embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as computer programs. For example, the embodiments of the present application include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 2109, and / or installed from the removable medium 2111. When the computer program is executed by a processor (CPU) 2101, various functions defined in the system of the present application are executed.
[0226] It should be noted that the computer-readable medium shown in the embodiments of the present application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium 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 disc 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 signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable computer program. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0227] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of devices, methods, and computer program products according to various embodiments of the present application. Among them, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and a computer program.
[0228] The units or modules involved in the embodiments described in this application can be implemented in software or in hardware, and the described units or modules can also be provided in a processor. Among them, the names of these units or modules do not, in some cases, constitute a limitation on the units or modules themselves.
[0229] On the other hand, this application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described above is implemented. The computer-readable storage medium can be included in the electronic device described in the above embodiments, or can exist alone without being assembled into the electronic device.
[0230] On the other hand, this application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the method described above in each of the above embodiments.
[0231] It should be noted that although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0232] Those skilled in the art will readily think of other implementation schemes of this application after considering the specification and practicing the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application, which follow the general principles of this application and include the common general knowledge or conventional technical means in the technical field not disclosed in this application.
[0233] The above content is only a preferred exemplary embodiment of this application and is not used to limit the implementation scheme of this application. Those of ordinary skill in the art can make corresponding adaptations or modifications very conveniently according to the main idea and spirit of this application. Therefore, the protection scope of this application should be subject to the protection scope required by the claims.
Claims
1. A transaction execution method based on blockchain, characterized in that, it includes: Obtain multiple to-be-executed transactions in the current block, and group the to-be-executed transactions according to the smart contracts invoked by each to-be-executed transaction to obtain to-be-executed transactions of multiple contract groups; Execute the to-be-executed transactions between each contract group in parallel; During the process of executing the to-be-executed transactions within any one contract group, determine the execution order of the to-be-executed transactions within the contract group according to the account information to which the to-be-executed transactions within the contract group belong; Execute the to-be-executed transactions within the contract group according to the execution order.
2. The method according to claim 1, characterized in that, The determining the execution order of the to-be-executed transactions within the contract group according to the account information to which the to-be-executed transactions within the contract group belong includes: If the account information to which the to-be-executed transactions within the contract group belong is different, then group the to-be-executed transactions within the contract group according to the account information to obtain to-be-executed transactions of multiple account groups; Determine that the execution order of the to-be-executed transactions between multiple account groups is to execute in parallel, and determine that the execution order of the to-be-executed transactions within any one account group is to execute serially.
3. The method according to claim 2, characterized in that, The determining the execution order of the to-be-executed transactions within the contract group according to the account information to which the to-be-executed transactions within the contract group belong, the method further includes: If the account information to which the to-be-executed transactions within the contract group belong is relevant, then determine that the execution order of the to-be-executed transactions within the contract group is to execute serially; Determine the transaction logic relationship between the to-be-executed transactions within the contract group according to the transaction content of each to-be-executed transaction within the contract group; Determine the serial execution order of the to-be-executed transactions within the contract group according to the transaction logic relationship.
4. The method according to claim 2, characterized in that, The grouping the to-be-executed transactions within the contract group according to the account information to obtain to-be-executed transactions of multiple account groups includes: Traverse the to-be-executed transactions within the contract group, and obtain the calling party account of the smart contract invoked by the currently traversed to-be-executed transaction; Determine the transaction calling party of the to-be-executed transaction according to the calling party account and the transaction account of the currently traversed to-be-executed transaction; Construct an account group for each transaction calling party, and write the to-be-executed transactions corresponding to each transaction calling party into the corresponding account group to obtain the to-be-executed transactions of multiple account groups.
5. The method according to claim 1, characterized in that, The grouping the to-be-executed transactions according to the smart contracts invoked by each to-be-executed transaction to obtain to-be-executed transactions of multiple contract groups includes: Obtain the contract information carried by the to-be-executed transaction; If it is determined according to the contract information that the number of smart contracts invoked by the to-be-executed transaction includes at least two, then regard the to-be-executed transaction as a to-be-executed transaction of multiple contract groups; If it is determined according to the contract information that the number of smart contracts invoked by the to-be-executed transaction is one, then regard the to-be-executed transaction as a to-be-executed transaction of the single contract group corresponding to the smart contract; Parallel execution of the to-be-executed transactions among the contract groups includes: Parallelly execute the to-be-executed transactions among each of the single contract groups, and after the to-be-executed transactions of each single contract group are executed, execute the to-be-executed transactions within the multi-contract group.
6. The method according to claim 5, wherein, Executing the to-be-executed transactions of the multi-contract group includes: Determine the calling contract and the called contract according to the call relationships of at least two of the smart contracts; Execute the to-be-executed transaction according to the calling contract to obtain the context information of the to-be-executed transaction; Generate a sub-transaction according to the context information of the to-be-executed transaction and send the sub-transaction to the called contract for execution.
7. The method according to claim 1, wherein, Grouping the to-be-executed transactions according to the smart contracts called by the to-be-executed transactions to obtain the to-be-executed transactions of multiple contract groups includes: If it is determined according to the contract information carried by the to-be-executed transaction that the smart contracts called by the target to-be-executed transaction include at least two smart contracts with call relationships, write the target to-be-executed transaction into the target contract group corresponding to the called smart contract; Executing the to-be-executed transactions within the contract group according to the execution order includes: When executing the target to-be-executed transaction within the target contract group according to the execution order, execute the target to-be-executed transaction according to the smart contract corresponding to the target contract group to obtain the context information of the target to-be-executed transaction; Generate a sub-transaction according to the context information and write the sub-transaction into the contract group corresponding to the called smart contract.
8. The method according to claim 1, wherein, Grouping the to-be-executed transactions according to the smart contracts called by the to-be-executed transactions to obtain the to-be-executed transactions of multiple contract groups includes: Traverse each to-be-executed transaction in the current block and obtain the smart contract called by the current to-be-executed transaction; If the smart contract called by the current to-be-executed transaction is already associated with a pre-constructed shard cache, write the current to-be-executed transaction into the shard cache; If the smart contract called by the current to-be-executed transaction is not associated with the shard cache, construct a new shard cache for the smart contract and write the current to-be-executed transaction into the new shard cache; Obtain the to-be-executed transactions of the multiple contract groups according to each shard cache.
9. The method according to claim 8, wherein, Parallel execution of the to-be-executed transactions among the contract groups includes: Obtain the resource information required by the smart contracts respectively corresponding to the contract groups; Determine whether there is a resource competition relationship among the smart contracts according to the resource information required by the smart contracts; If there is no resource competition relationship among the smart contracts, parallelly execute the to-be-executed transactions among the contract groups.
10. The method according to claim 8, wherein, Parallel execution of the to-be-executed transactions among the contract groups includes: Obtain the contract code of the smart contract and the contract call chain of the historical transactions of the blockchain; Determine whether there is a dependency relationship between the smart contracts according to the contract code of the smart contracts and the contract call chain; If there is no dependency relationship between the smart contracts, then execute the to-be-executed transactions between each contract group in parallel.
11. The method according to claim 10, wherein, the determining whether there is a dependency relationship between the smart contracts according to the contract code of the smart contracts and the contract call chain includes: If it is determined that there is a call relationship between the smart contracts according to the contract code of the smart contracts or the contract call chain, then construct a contract call graph according to the contract code and the contract call chain; Obtain the call depth of the call relationship according to the contract call graph; If the call depth is greater than a preset depth threshold, it is determined that there is a dependency relationship between the smart contracts.
12. The method according to any one of claims 1 to 11, wherein, the executing the to-be-executed transactions between each contract group in parallel includes: During the process of executing the to-be-executed transactions between each contract group in parallel, obtain the resource utilization rate of the blockchain and the transaction load of each contract group; Determine the number of threads for concurrent execution to be readjusted according to the resource utilization rate and the transaction load; Execute the to-be-executed transactions between each contract group in parallel according to the adjusted number of threads.
13. A transaction execution device based on a blockchain, wherein, comprising: A grouping module, configured to obtain multiple to-be-executed transactions in the current block, and group the to-be-executed transactions according to the smart contracts called by each to-be-executed transaction, so as to obtain the to-be-executed transactions of multiple contract groups; An execution module, configured to execute the to-be-executed transactions between each contract group in parallel; A determination module, configured to determine the execution order of the to-be-executed transactions in the contract group according to the account information to which the to-be-executed transactions in the contract group belong during the process of executing the to-be-executed transactions in any contract group; The execution module is further configured to execute the to-be-executed transactions in the contract group according to the execution order.
14. An electronic device, wherein, comprising: One or more processors; A storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, enable the electronic device to execute the method according to any one of claims 1 to 12.
15. A computer-readable storage medium, wherein, a computer program is stored thereon, and when the computer program is executed by a processor of an electronic device, enable the electronic device to execute the method according to any one of claims 1 to 12.
16. A computer program product, wherein, the computer program product includes a computer program, the computer program is stored in a computer-readable storage medium, and a processor of an electronic device reads and executes the computer program from the computer-readable storage medium, enabling the electronic device to execute the method according to any one of claims 1 to 12.