Transaction execution method and device in block chain, computer equipment and storage medium
By obtaining transaction tasks and contract information in the blockchain system, finding method hash values and reusing contract processes, the problem of low execution efficiency of blockchain system when processing large amounts of transactions is solved, and higher resource utilization and processing performance are achieved.
Patent Information
- Application Number
- CN202311817676.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-25
- Publication Date
- 2025-06-27
AI Technical Summary
The existing blockchain system is less efficient in handling large amounts of transactions, resulting in poor performance of the entire blockchain.
By obtaining transaction tasks and contract information, finding the method hash value in the contract warehouse, and looking up the contract package from the mapping table based on the hash value, reusing the contract process to perform the transaction task.
It improves the efficiency of transaction execution in the blockchain, reduces resource consumption, and significantly improves the processing performance of the entire blockchain.
Smart Images

Figure CN120219072A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to a method, apparatus, computer device, storage medium, and computer program product for transaction execution in a blockchain. Background Art
[0002] A blockchain is a new type of decentralized distributed ledger technology that can securely store transactions or other data. The feature is that the information stored on the blockchain cannot be forged or tampered with. The blockchain consensus algorithm drives each node on the blockchain to participate in the verification process of transactions, ensuring that the transactions on the blockchain are all confirmed and trustworthy.
[0003] However, in the current method of transaction execution in a blockchain, since the deployment and execution of each contract require starting an independent process, when the number of transaction tasks is large and involves multiple contracts, each contract needs to run independently. Therefore, when the blockchain system processes a large number of transactions, it is prone to the problem of low execution efficiency, which may further have a negative impact on the performance of the entire blockchain, resulting in poor processing performance of the entire blockchain. Summary of the Invention
[0004] Based on this, in view of the above technical problems, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for transaction execution in a blockchain, which can effectively improve the efficiency of transaction execution in the blockchain and at the same time improve the processing performance of the entire blockchain.
[0005] In a first aspect, this application provides a method for transaction execution in a blockchain. The method includes: obtaining a transaction task and contract information corresponding to the transaction task; looking up a method hash value corresponding to the contract information from a contract repository; when the method hash value is found, looking up a contract program package to be called from a mapping table based on the method hash value; and reusing a contract process corresponding to the contract program package so that the contract process executes the transaction task to obtain a first execution result.
[0006] In a second aspect, this application also provides a device for transaction execution in a blockchain. The device includes: an obtaining module, configured to obtain a transaction task and contract information corresponding to the transaction task; a looking-up module, configured to look up a method hash value corresponding to the contract information from a contract repository; when the method hash value is found, looking up a contract program package to be called from a mapping table based on the method hash value; and a reusing module, configured to reuse a contract process corresponding to the contract program package so that the contract process executes the transaction task to obtain a first execution result.
[0007] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the following steps are implemented: obtaining a transaction task and contract information corresponding to the transaction task; searching in a contract repository for a method hash value corresponding to the contract information; when the method hash value is found, searching in a mapping table for a contract program package to be called based on the method hash value; and reusing a contract process corresponding to the contract program package so that the contract process executes the transaction task to obtain a first execution result.
[0008] In a fourth aspect, the present application further provides a computer-readable storage medium. On the computer-readable storage medium, a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: obtaining a transaction task and contract information corresponding to the transaction task; searching in a contract repository for a method hash value corresponding to the contract information; when the method hash value is found, searching in a mapping table for a contract program package to be called based on the method hash value; and reusing a contract process corresponding to the contract program package so that the contract process executes the transaction task to obtain a first execution result.
[0009] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program. When the computer program is executed by a processor, the following steps are implemented: obtaining a transaction task and contract information corresponding to the transaction task; searching in a contract repository for a method hash value corresponding to the contract information; when the method hash value is found, searching in a mapping table for a contract program package to be called based on the method hash value; and reusing a contract process corresponding to the contract program package so that the contract process executes the transaction task to obtain a first execution result.
[0010] The above transaction execution method, device, computer device, storage medium, and computer program product in the blockchain obtain a transaction task and contract information corresponding to the transaction task, and search for a method hash value corresponding to the contract information in a contract repository; when the method hash value is found, the contract program package to be called is searched for in a mapping table based on the method hash value, and the contract process corresponding to the contract program package is reused, so that the contract process executes the transaction task to obtain a first execution result. Since the method hash value corresponding to the contract information can be found in the contract repository and the contract program package to be called can be found through the mapping table, after each node in the node cluster obtains the transaction task and the contract information corresponding to the transaction task, the method hash value can be quickly located based on the contract repository, and at the same time, the process of the contract program package to be called can be quickly located based on the mapping table, thereby realizing the reuse of the contract process, avoiding the running of a large number of duplicate contract processes, and reducing the resource consumption of the entire blockchain system. Compared with the traditional solution, the method provided in this application can significantly improve the resource utilization rate and reduce the system pressure when processing a large number of transaction tasks, effectively improving the efficiency of transaction execution in the blockchain while improving the processing performance of the entire blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 FIG. 6 is an alternative schematic structural diagram of a distributed system 100 applied to a blockchain system in one embodiment;
[0012] Figure 2 FIG. 10 is an alternative schematic diagram of a block structure in one embodiment;
[0013] Figure 3 FIG. 14 is an application environment diagram of a transaction execution method in a blockchain in one embodiment;
[0014] Figure 4 FIG. 18 is a schematic system architecture diagram of a contract process compression scheme based on contract method stack hash in one embodiment;
[0015] Figure 5 FIG. 22 is a schematic structural diagram of a contract repository in one embodiment;
[0016] Figure 6 FIG. 26 is a schematic diagram of a method hash contract mapping table in one embodiment;
[0017] Figure 7 FIG. 30 is a schematic diagram of a transaction call flow based on contract method stack hash in one embodiment;
[0018] Figure 8 FIG. 34 is a schematic diagram of the interaction of a contract deployment module in one embodiment;
[0019] Figure 9Schematic diagram of contract installation process based on contract method stack hash in an embodiment;
[0020] Figure 10 Interaction diagram of transaction call module in an embodiment;
[0021] Figure 11 Block diagram of the structure of a transaction execution device in a blockchain in an embodiment;
[0022] Figure 12 Internal structure diagram of a computer device in an embodiment. Detailed implementation manners
[0023] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0024] It should be noted that in the following description, the terms "first, second, and third" involved are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first, second, and third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0025] The system involved in the embodiments of the present invention can be a distributed system formed by connecting a client and multiple nodes (any form of computing device accessing the network, such as a server, a user terminal) through network communication.
[0026] Taking the distributed system as a blockchain system as an example, refer to Figure 1 , Figure 1 is an optional schematic structural diagram of the distributed system 100 provided by the embodiments of the present invention applied to a blockchain system, formed by multiple nodes (any form of computing device accessing the network, such as a server, a user terminal) and a client. A peer-to-peer (Peer To Peer) network is formed between the nodes. The Peer To Peer protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). In a distributed system, any machine such as a server or a terminal can join and become a node. A node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer.
[0027] Refer to Figure 1 shows the functions of each node in the blockchain system. The functions involved include:
[0028] 1) Routing, a basic function of a node, used to support communication between nodes.
[0029] In addition to having routing functions, a node can also have the following functions:
[0030] 2) An application, which is used to be deployed in a blockchain, implements specific services according to actual business requirements, records data related to the implemented functions to form record data, carries a digital signature in the record data to indicate the source of the task data, and sends the record data to other nodes in the blockchain system. When other nodes verify the source and integrity of the record data successfully, they add the record data to a temporary block.
[0031] For example, the services implemented by the application include:
[0032] 2.1) A wallet, which is used to provide the function of conducting electronic currency transactions, including initiating a transaction (i.e., sending the transaction record of the current transaction to other nodes in the blockchain system. After other nodes verify it successfully, as a response to acknowledging the validity of the transaction, they deposit the record data of the transaction into the temporary block of the blockchain. Of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;
[0033] 2.2) A shared ledger, which is used to provide functions such as storing, querying, and modifying account data. It sends the record data of the operations on the account data to other nodes in the blockchain system. After other nodes verify its validity, as a response to acknowledging the validity of the account data, they deposit the record data into the temporary block, and can also send a confirmation to the node that initiated the operation.
[0034] 2.3) A smart contract, which is a computerized protocol that can execute the terms of a certain contract. It is implemented by code deployed on the shared ledger and executed when certain conditions are met. According to actual business requirements, 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.
[0035] 3) A blockchain includes a series of blocks (Block) that are sequentially connected in the order of generation. Once a new block is added to the blockchain, it will not be removed again. The block records the record data submitted by nodes in the blockchain system.
[0036] See Figure 2 , Figure 2It is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction records stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected through the hash value to form a blockchain. In addition, the block may also include information such as the timestamp when the block is generated. A blockchain, in essence, is a decentralized database, a series of data blocks generated by using cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.
[0037] In one embodiment, as Figure 3 shown, a method for transaction execution in a blockchain is provided. Taking the example that this method is applied to Figure 1 the node cluster in the blockchain system as an example, it includes the following steps:
[0038] Step 302, obtain the transaction task and the contract information corresponding to the transaction task.
[0039] Among them, a blockchain is a chain composed of one block after another. Each block stores certain information, and they are connected into a chain in the order of their respective generation times. This chain is stored in all servers. As long as one server in the entire system can work, the entire blockchain is secure. These servers are called nodes in the blockchain system, and they provide storage space and computing power support for the entire blockchain system. If you want to modify the information in the blockchain, you must obtain the consent of more than half of the nodes and modify the information in all nodes. These nodes are usually in the hands of different entities. Therefore, it is extremely difficult to tamper with the information in the blockchain. Compared with traditional networks, the blockchain has two core features: one is that the data is difficult to tamper with, and the other is decentralization. Based on these two features, the information recorded by the blockchain is more authentic and reliable, which can help solve the problem of people not trusting each other. The types of blockchains include public blockchains, consortium blockchains, private blockchains, etc. The blockchain system in this application can be a consortium blockchain system.
[0040] A transaction task refers to a transaction task generated by the client. In some cases, the transaction task in this application can also be called a transaction. The transaction tasks generated by the client can include different types of transaction tasks. For example, the transaction tasks generated by the client include but are not limited to transaction tasks for installing (deploying) contracts, transaction tasks for business transfers, etc.
[0041] The contract information corresponding to a trading task refers to the contract information carried by the trading task. In this application, the contract information carried by the trading task may include information such as the contract name, contract method, and contract input parameters. For example, the contract information carried by a certain trading task A sent by the client includes: contract name: Contract 1, contract method (invocation method): Method 1-Set, contract input parameters: {A, 100}, invoker: Alice, timestamp: 152311312391, etc.
[0042] Specifically, after a newly created blockchain is started, when the node cluster in the blockchain system receives a trading request carrying a trading task sent by the client, the node cluster can verify the trading request to obtain the corresponding verification result. When the verification result indicates that the verification is passed, the node cluster can send the trading task carried in the trading request to the trading pool module and schedule the execution and verification module to process this trading task, that is, each node in the node cluster can obtain this trading task and the contract information corresponding to this trading task from the local trading pool maintained by itself.
[0043] For example, as Figure 4 shown, it is a schematic diagram of the system architecture of the contract process compression scheme based on the contract method stack hash. After a newly created blockchain is started, when node A in the node cluster of the blockchain system receives trading task A and trading task B sent by client A through the network module, node A can respectively verify trading task A and trading task B through the verification module to obtain the corresponding verification results. When the verification results of trading task A and trading task B both indicate that the verification is passed, that is, after node A successfully verifies trading task A and trading task B sent by the client, node A can send trading task A and trading task B to the trading pool module for storage and schedule the execution and verification module to process trading task A and trading task B, that is, node A can obtain trading task A and trading task B from the trading pool through the scheduling execution and verification module for contract execution and verification. For example, node A obtains trading task A from the trading pool through the scheduling execution and verification module, and the contract information carried by trading task A includes: contract name: Contract 1, contract method (invocation method): Method 1-Set, contract input parameters: {A, 100}, invoker: Alice, timestamp: 152311312391, etc.
[0044] Step 304, search for the method hash value corresponding to the contract information in the contract repository.
[0045] Among them, the method hash value refers to the hash value obtained by analyzing the method call stack of each contract method in the smart contract and calculating based on the method call stack of each contract method. This hash value is the method hash value. In some cases, the method hash value in this application can also be referred to as the method hash. For example, as Figure 5 shown, it is a schematic diagram of the structure of the contract repository. Figure 5 As shown in Figure 5 , Contract 1 in it includes Method 1, Method 2, and Method 3. The node cluster can respectively analyze the call stacks of each contract method (Method 1, Method 2, and Method 3) in this Contract 1, and calculate the corresponding hash values based on the call stacks of each contract method (Method 1, Method 2, and Method 3) as follows: Method Hash 1, Method Hash 2, and Method Hash 3. That is, the method hash value corresponding to Contract 1 includes: Method Hash 1, Method Hash 2, and Method Hash 3.
[0046] Specifically, after each node in the node cluster obtains the transaction task and the contract information corresponding to this transaction task from the local transaction pool maintained by itself, each node in the node cluster can look up the method hash value corresponding to the contract information of this transaction task in the contract repository. For example, each node in the node cluster can obtain the contract name (contract name) in the contract information of this transaction task, and look up the method hash value corresponding to the contract name (contract name) of this transaction task in the contract repository.
[0047] For example, taking Node A in the node cluster of the blockchain system as an example for illustration. Assume that Node A obtains transaction task A and the contract information carried by transaction task A through the scheduling execution and verification module, including: contract name: Contract 1, contract method (invocation method): Method 1-Set, contract input parameters: {A, 100}, caller: Alice, timestamp: 152311312391. Further, Node A can obtain that the contract name in the contract information of transaction task A is Contract 1, and look up the method hash value corresponding to Contract 1 in the contract repository as shown in Figure 5 including: Method Hash 1, Method Hash 2, and Method Hash 3.
[0048] Step 306, when the method hash value is found, look up the contract program package to be called from the mapping table based on the method hash value.
[0049] Among them, the mapping table refers to a table used to store the mapping relationship between the method hash (value) and the contract program package. For example, as Figure 6 shown, it is a schematic diagram of the method hash contract mapping table. Figure 6 There is a mapping relationship between Method Hash 1 and Contract Package 1 in Figure 6 .
[0050] Specifically, after each node in the node cluster looks up the method hash value corresponding to the contract information of the transaction task from the contract repository, when the method hash value corresponding to the contract information of the transaction task is found, each node in the node cluster can look up the contract program package to be called from the mapping table based on the found method hash value. That is, the mapping table maintains the mapping relationship between different method hash values and contract program packages. Therefore, each node in the node cluster can quickly locate the process of the contract program package to be called based on the mapping table.
[0051] For example, take node A in the node cluster of the blockchain system as an example for illustration. Assume that node A obtains the contract name in the contract information of transaction task A as contract 1, and looks up the method hash values corresponding to contract 1 from the contract repository as shown in Figure 5 including: method hash 1, method hash 2, and method hash 3. That is, when node A finds the method hash values corresponding to the contract information (contract 1) of transaction task A from the contract repository as shown in Figure 5 , node A can look up the contract program package to be called from the mapping table based on the found method hash 1, method hash 2, and method hash 3. Since Figure 6 the mapping relationship in the method hash - contract mapping table as shown in is: method hash 1 - contract program package 1, method hash 2 - contract program package 1, method hash 3 - contract program package 1, so node A can look up the contract program packages corresponding to method hash 1, method hash 2, and method hash 3 from the method hash - contract mapping table as shown in Figure 6 respectively, and the contract program packages are: contract program package 1.
[0052] Step 308, reuse the contract process corresponding to the contract program package to enable the contract process to execute the transaction task and obtain the first execution result.
[0053] Among them, the contract process refers to the process of running a specific contract program package. A process refers to a running activity of a program on a certain data set in a computer. It is the basic unit for the system to allocate resources and is the basis of the operating system structure. That is, the process in this application is the basic execution unit in the operating system, which contains all the resources required for the program to run, such as code, data, file descriptors, etc. Each process has its own independent address space, and communication between processes needs to be achieved through the inter - process communication (IPC) mechanism. The operating system is responsible for managing the scheduling, resource allocation, and isolation of processes. The context switch between processes usually occurs in the kernel state, so the overhead is relatively large. Processes are suitable for CPU - intensive tasks and scenarios that require resource isolation.
[0054] The first execution result refers to the execution result obtained by executing the transaction task. For example, the first execution results in this application include: the result of successful execution and the result of failed execution.
[0055] Specifically, after each node in the node cluster locates the contract program package to be called from the mapping table based on the found method hash value, each node in the node cluster can reuse the contract process corresponding to the contract program package to be called, so that the contract process executes the transaction task and obtains the first execution result. Among them, the contract processes reused by each node in the node cluster can be processes running locally or processes running on other nodes, which are not specifically limited here.
[0056] For example, taking node A in the node cluster of the blockchain system as an example for illustration. Suppose node A locates the contract program package corresponding to method hash 1, method hash 2, and method hash 3 as contract program package 1 from the method hash - contract mapping table as shown in Figure 6 After that, node A can reuse the contract process corresponding to contract program package 1 (i.e., contract program package 1 process), so that the contract program package 1 process executes transaction task A and obtains the execution result corresponding to transaction task A. Among them, if the contract process corresponding to contract program package 1 (i.e., contract program package 1 process) runs on node A itself, node A directly calls the contract process corresponding to contract program package 1 (i.e., contract program package 1 process) and executes transaction task A through the contract program package 1 process to obtain the execution result corresponding to transaction task A; if the contract process corresponding to contract program package 1 (i.e., contract program package 1 process) runs on other devices (other nodes), node A can send transaction task A to the contract process corresponding to contract program package 1 (i.e., contract program package 1 process), so that the contract program package 1 process executes transaction task A, obtains the execution result corresponding to transaction task A, and returns the execution result corresponding to transaction task A to node A.
[0057] In this embodiment, by obtaining a transaction task and contract information corresponding to the transaction task, and looking up a method hash value corresponding to the contract information in a contract repository; when the method hash value is found, looking up a contract package to be called from a mapping table based on the method hash value, and reusing a contract process corresponding to the contract package, so that the contract process executes the transaction task to obtain a first execution result. Since a method hash value corresponding to the contract information can be found in the contract repository and a contract package to be called can be found through the mapping table, after each node in the node cluster obtains the transaction task and the contract information corresponding to the transaction task, the method hash value can be quickly located based on the contract repository, and at the same time, the process of the contract package to be called can be quickly located based on the mapping table, thereby realizing the reuse of the contract process, avoiding the running of a large number of duplicate contract processes, and thus reducing the resource consumption of the entire blockchain system. Compared with the traditional solution, the method provided in this application can significantly improve resource utilization and reduce system pressure when processing a large number of transaction tasks, effectively improving the efficiency of transaction execution in the blockchain while improving the processing performance of the entire blockchain.
[0058] In one embodiment, the method further includes:
[0059] Receiving a transaction request sent by a client;
[0060] Performing signature verification and permission verification on the transaction request to obtain a verification result;
[0061] When the verification result indicates that the verification is passed, storing the transaction task carried in the transaction request in a transaction pool;
[0062] The obtaining of the transaction task and the contract information corresponding to the transaction task includes:
[0063] Obtaining the transaction task from the transaction pool and obtaining the contract information corresponding to the transaction task.
[0064] Among them, the client, also known as the user terminal, refers to a program that provides local services corresponding to the server. Except for some applications that only run locally, it is generally installed on ordinary client machines and needs to cooperate with the server to run. For example, the client in this application can include different user terminals.
[0065] The transaction pool is used to store transaction tasks to be processed and provide transaction data for blockchain nodes. The transaction pool sorts the transaction tasks according to strategies such as transaction fees and priorities for subsequent packaging into blocks.
[0066] Specifically, after a newly created blockchain is started, when the node cluster in the blockchain system receives a transaction request carrying a transaction task sent by a client, the node cluster can verify the transaction request, that is, the node cluster needs to perform signature verification and permission verification on the transaction request to obtain the corresponding verification result. When the verification result indicates that the verification is passed, the node cluster can send the transaction task carried in the transaction request to the transaction pool module for storage, and schedule the execution and verification module to process this transaction task, that is, each node in the node cluster can obtain this transaction task and the contract information corresponding to this transaction task from the local transaction pool maintained by itself.
[0067] For example, taking node A in the node cluster of the blockchain system as an example for illustration. After a newly created blockchain is started, when node A in the node cluster of the blockchain system receives transaction task A and transaction task B sent by client A through the network module as shown in Figure 4 below, node A can perform signature verification and permission verification on transaction task A and transaction task B respectively through the verification module to obtain the corresponding verification results. When the verification results of both transaction task A and transaction task B indicate that the verification is passed, that is, after node A successfully verifies transaction task A and transaction task B sent by the client, node A can send transaction task A and transaction task B to the transaction pool module for storage, and schedule the execution and verification module to process transaction task A and transaction task B, that is, node A can obtain transaction task A and transaction task B from the transaction pool through the scheduling execution and verification module for contract execution and verification. For example, the information obtained by node A from the transaction pool through the scheduling execution and verification module for transaction task A and the contract information carried by transaction task A includes: contract name: contract 1, contract method (invocation method): method 1 - Set, contract input parameters: {A, 100}, caller: Alice, timestamp: 152311312391, etc. In addition, in some cases, if the verification results of both transaction task A and transaction task B indicate that the verification fails, then node A can discard transaction task A and transaction task B.
[0068] In this embodiment, based on the contract repository, the method hash value can be quickly located, and at the same time, based on the mapping table, the process of the contract program package to be called can be quickly located, thereby realizing the reuse of the contract process, avoiding the operation of a large number of duplicate contract processes, and thus reducing the resource consumption of the entire blockchain system. Compared with the traditional solution, the method provided in this application can significantly improve the resource utilization rate and reduce the system pressure when processing a large number of transaction tasks, effectively improving the transaction execution efficiency in the blockchain while improving the processing performance of the entire blockchain.
[0069] In one embodiment, the contract processes corresponding to the contract package include a first contract process and a second contract process. The first contract process is a process running on the local node in the blockchain, and the second contract process is a process running on other nodes in the blockchain. The step of reusing the contract processes corresponding to the contract package to enable the contract processes to execute transaction tasks and obtain a first execution result includes:
[0070] Execute the transaction task through the first contract process to obtain a first execution result; or,
[0071] Send the transaction task to the second contract process to enable the second contract process to execute the transaction task and obtain a first execution result.
[0072] Herein, the first contract process and the second contract process are only used to distinguish contract processes running on different devices (nodes). For example, the first contract is a process running on the local node (node A) in the blockchain, and the second contract process is a process running on other nodes (node B) in the blockchain.
[0073] Specifically, after each node in the node cluster finds the contract package to be called from the mapping table based on the found method hash value, each node in the node cluster can reuse the contract processes corresponding to the contract package to be called to enable the contract processes to execute transaction tasks and obtain a first execution result. That is, each node in the node cluster can execute the transaction task through the first contract process to obtain a first execution result; or, each node in the node cluster can send the transaction task to the second contract process to enable the second contract process to execute the transaction task and obtain a first execution result, and obtain the first execution result obtained from executing the transaction task from the second contract process.
[0074] For example, take node A in the node cluster of the blockchain system as an example for illustration. Assume that node A obtains from Figure 6In the method hash contract mapping table shown in , after finding that the contract packages corresponding to method hash 1, method hash 2, and method hash 3 are contract package 1, node A can reuse the contract process corresponding to this contract package 1 (i.e., the contract package 1 process) to enable the contract package 1 process to execute transaction task A and obtain the execution result corresponding to transaction task A. That is, when the contract process corresponding to contract package 1 (i.e., the contract package 1 process) runs on the local side of node A, node A can directly call the contract process corresponding to this contract package 1 (i.e., the contract package 1 process) and execute transaction task A through the contract package 1 process to obtain the execution result corresponding to transaction task A; when the contract process corresponding to contract package 1 (i.e., the contract package 1 process) runs on other devices (other nodes), node A can send this transaction task A to the contract process corresponding to this contract package 1 (i.e., the contract package 1 process) to enable the contract package 1 process to execute transaction task A, obtain the execution result corresponding to transaction task A, and return the execution result corresponding to this transaction task A to node A. This enables, by adopting the contract process reuse technology based on contract method stack comparison, the avoidance of the operation of a large number of duplicate contract processes, thereby reducing the consumption of system resources. Compared with the traditional solution, the solution in the embodiment of the present application can significantly improve resource utilization and reduce system pressure when processing a large number of transactions.
[0075] In one embodiment, after reusing the contract process corresponding to the contract package to enable the contract process to execute the transaction task and obtain the first execution result, the method further includes:
[0076] Obtaining the first execution result and the read-write set for executing the transaction task from the contract process; wherein, the read-write set has an association relationship with the contract identifier in the contract information, and the read-write set has no association relationship with the contract package;
[0077] Adding the first execution result and the read-write set to the transaction task and storing them in the new block;
[0078] Sending the new block to other nodes in the blockchain for consensus;
[0079] When the new block reaches consensus, storing the new block in the block ledger maintained by itself.
[0080] Wherein, the read-write set refers to the data generated during the execution of the transaction task, and in some cases, the read-write set is the state data.
[0081] Other nodes refer to the nodes in the node cluster of the blockchain system except the local node. For example, if the local node is node A, then other nodes refer to the nodes in the node cluster of the blockchain system except node A.
[0082] The block ledger is used to store the confirmed block information, forming a chain structure, where each block contains a set of transactions and metadata.
[0083] Specifically, taking node A in the node cluster of the blockchain system as an example for illustration. As Figure 7 shown, it is a schematic diagram of the transaction call process based on the contract method stack hash. Node A can reuse the contract process 1 corresponding to the contract package 1, so that the contract process 1 executes the transaction task A. After obtaining the first execution result A, node A can obtain the first execution result A and the read-write set A (status data) of executing the transaction task A from the contract process 1, add the first execution result A and the read-write set A to the transaction task A, and store them in the new block; further, node A can send the new block to other nodes in the blockchain for consensus; when the new block reaches consensus, node A can store the new block in the local block ledger maintained by itself. Among them, the read-write set A in the embodiment of the present application has an association relationship with the contract identifier (contract name) in the contract information corresponding to the transaction task A, and the read-write set A has no association relationship with the contract package 1.
[0084] In this embodiment, the transaction runtime decoupling technology of separating the contract program from the contract name is adopted, so that the contract package can be shared among multiple contract names, realizing the decoupling between the contract program and the contract name. This design can further improve the flexibility and efficiency of contract execution, thereby improving the execution efficiency of the entire system when processing a large number of transactions.
[0085] In one embodiment, the method further includes:
[0086] Obtain the initialization transaction task and the contract information corresponding to the initialization transaction task from the transaction pool;
[0087] Determine the method call stack based on the contract information corresponding to the initialization transaction task;
[0088] Determine the target method hash value based on the method call stack;
[0089] When the target method hash value does not exist in the mapping table, add the mapping relationship between the target method hash value and the target contract package to the mapping table;
[0090] Start the contract process corresponding to the target contract package, so that the contract process executes the initialization transaction task to obtain the second execution result;
[0091] Determine the deployment result of the smart contract according to the second execution result.
[0092] Among them, the initialization transaction task refers to the transaction task used to deploy (initialize) a contract. When the initialization transaction task is successfully executed, that is, when the second execution result is the result of successful transaction execution, it indicates that the contract deployment (initialization) is successful; when the initialization transaction task fails to execute, that is, when the second execution result is the result of failed transaction execution, it indicates that the contract deployment (initialization) fails.
[0093] The method call stack refers to performing static analysis before the contract runs to obtain all possible call stack codes of each contract method. It can be understood that in some cases, the method call stack in this application can also be referred to as the method stack.
[0094] The target method hash value refers to the hash value calculated by analyzing the method call stacks of each contract method in the smart contract and based on the method call stacks of each contract method. For example, as Figure 8 shown, it is a schematic diagram of the interaction of the contract deployment module. Assume that node A in the node cluster obtains that the contract name in the contract information of the initialization transaction task is contract 2, and determines that all possible method call stacks corresponding to contract 2 include: method 1 - method 1 call stack, method 2 - method 2 call stack, and method 3 - method 3 call stack. Calculate the method hashes corresponding to each method call stack respectively, and the target method hash value corresponding to this contract 2 can be obtained, including: method 1 - method hash 1, method 2 - method hash 2, and method 3 - method hash 3. Among them, there is a mapping relationship between each target method hash value and the target contract package. For example, as Figure 8 shown, when the target method hash value is method hash 1, there is a mapping relationship between method hash 1 and contract package 1; when the target method hash value is method hash 2, there is a mapping relationship between method hash 2 and contract package 1; when the target method hash value is method hash 3, there is a mapping relationship between method hash 3 and contract package 1.
[0095] The second execution result refers to the execution result obtained by executing the initialization transaction task. For example, the second execution result in this application includes: the result of successful execution and the result of failed execution. When the initialization transaction task is successfully executed, that is, when the second execution result is the result of successful transaction execution, it indicates that the contract deployment (initialization) is successful; when the initialization transaction task fails to execute, that is, when the second execution result is the result of failed transaction execution, it indicates that the contract deployment (initialization) fails.
[0096] The deployment result of the smart contract includes: the result of failed smart contract deployment (initialization) and the result of successful smart contract deployment (initialization). It can be understood that in some cases, the smart contract in this application can also be referred to as a contract.
[0097] Specifically, take node A in the node cluster of the blockchain system as an example for illustration. As Figure 8As shown in the figure, it is a schematic diagram of the interaction of the contract deployment module. Assume that node A obtains the initialization transaction task A and the contract information carried by the initialization transaction task A from the transaction pool through the scheduling execution and verification module, such as Figure 8 shown in: Contract name: Contract 2. Further, based on the contract name in the contract information of the initialization transaction task A being Contract 2, node A can determine all possible method call stacks corresponding to Contract 2, including: Method 1 - Method 1 call stack, Method 2 - Method 2 call stack, and Method 3 - Method 3 call stack, and calculate the method hash corresponding to each method call stack respectively, then the target method hash values corresponding to this Contract 2 can be obtained, including: Method 1 - Method Hash 1, Method 2 - Method Hash 4, and Method 3 - Method Hash 5. Further, node A can look up whether there are mapping relationships for Method Hash 1, Method Hash 4, and Method Hash 5 in the method hash - contract mapping table as shown in Figure 8 Since the existing mapping relationships in the method hash - contract mapping table as shown in Figure 8 are: there are mapping relationships between Method Hash 1 - Contract Package 1, Method Hash 2 - Contract Package 1, and Method Hash 3 - Contract Package 1. Therefore, when node A determines that Method Hash 4 does not exist in the method hash - contract mapping table as shown in Figure 8 , node A adds the mapping relationship between Method Hash 4 and the target contract package, that is, Contract Package 2, to the method hash - contract mapping table as shown in Figure 8 ; Similarly, when node A determines that Method Hash 5 does not exist in the method hash - contract mapping table as shown in Figure 8 , node A adds the mapping relationship between Method Hash 5 and the target contract package, that is, Contract Package 2, to the method hash - contract mapping table as shown in Figure 8 , and starts the contract process corresponding to the target contract package, that is, the Contract Package 2 process, so that the newly started Contract Package 2 process executes the initialization transaction task A, that is, runs Method Hash 4 and Method Hash 5 through the Contract Package 2 process, obtains the second execution result corresponding to the initialization transaction task A, and determines the deployment result of Contract 2 according to the second execution result. That is, when the initialization transaction task A is executed successfully, that is, the second execution result is the result of successful transaction execution, it is determined that Contract 2 is deployed (initialized) successfully; when the initialization transaction task A is executed failed, that is, the second execution result is the result of failed transaction execution, it is determined that Contract 2 is deployed (initialized) failed.
[0098] In this embodiment, a transaction runtime decoupling technology that separates the contract program from the contract name is adopted, enabling the contract package to be shared among multiple contract names, realizing the decoupling between the contract program and the contract name. This design can further improve the flexibility and efficiency of contract execution, thereby improving the execution efficiency of the entire system when processing a large number of transactions.
[0099] In one embodiment, before obtaining the initialization transaction task and the contract information corresponding to the initialization transaction task from the transaction pool, the method further includes:
[0100] Receiving a transaction request sent by a client;
[0101] Performing signature verification and permission verification on the transaction request to obtain a verification result;
[0102] When the verification result indicates that the verification is passed, storing the initialization transaction task for deploying the smart contract carried in the transaction request into the transaction pool.
[0103] Specifically, after a newly created blockchain is started, when the node cluster in the blockchain system receives a transaction request sent by a client, the node cluster can verify the transaction request, that is, the node cluster needs to perform signature verification and permission verification on the transaction request to obtain the corresponding verification result. When the verification result indicates that the verification is passed, the node cluster can send the initialization transaction task for deploying the smart contract carried in the transaction request to the transaction pool module for storage, and schedule and execute the initialization transaction task through the scheduling execution and verification module for processing, that is, each node in the node cluster can obtain the initialization transaction task and the contract information corresponding to the initialization transaction task from the local transaction pool maintained by itself.
[0104] For example, taking node A in the node cluster of the blockchain system as an example for illustration. After a newly created blockchain is started, when node A receives the initialization transaction task A sent by client A through the network module as shown in Figure 4 , node A can perform signature verification and permission verification on the initialization transaction task A through the verification module to obtain the corresponding verification result. When the verification result of the initialization transaction task A indicates that the verification is passed, that is, after node A successfully verifies the initialization transaction task A sent by the client, node A can send the initialization transaction task A to the transaction pool module for storage, and schedule and execute the initialization transaction task A through the scheduling execution and verification module for processing, that is, node A can obtain the initialization transaction task A from the transaction pool through the scheduling execution and verification module for contract execution and verification. For example, node A obtains the initialization transaction task A and the contract information carried by the initialization transaction task A from the transaction pool through the scheduling execution and verification module, including: contract name: contract 2. In addition, in some cases, if the verification result of the initialization transaction task A indicates that the verification fails, then node A can discard the initialization transaction task A.
[0105] In a traditional blockchain system, the deployment and execution of each contract require starting an independent process. When the number of transactions is large and involves multiple contracts, this can lead to a large amount of resource waste and system pressure. In this embodiment, by analyzing the call stack of contract methods and calculating their hash values, the same contract methods are classified into the same process for execution. This can achieve the reuse of processes, avoid the problem of a large number of duplicate contract processes running, and thus improve the execution efficiency and resource utilization rate of the system.
[0106] In one embodiment, the contract information corresponding to the initialization transaction task includes the contract name; the steps for determining the method call stack based on the contract information corresponding to the initialization transaction task include:
[0107] Based on the contract name, determine each contract method in the smart contract corresponding to the contract name;
[0108] Determine the method call stack corresponding to each contract method;
[0109] Use the method call stack corresponding to each contract method as the method call stack of the contract information corresponding to the initialization transaction task.
[0110] Specifically, take node A in the node cluster of the blockchain system as an example for illustration. As Figure 8 shown, it is a schematic diagram of the interaction of the contract deployment module. Assume that node A obtains the initialization transaction task A and the contract information carried by the initialization transaction task A from the transaction pool through the scheduling execution and verification module. As Figure 8 shown in the figure: contract name: contract 2. Further, node A can determine each contract method in the smart contract corresponding to contract 2 based on the contract name in the contract information of the initialization transaction task A, including method 1, method 2, and method 3, and determine all possible method call stacks of each contract method, including: method 1 - method 1 call stack, method 2 - method 2 call stack, and method 3 - method 3 call stack. Then, use the method call stack corresponding to each contract method, that is, method 1 - method 1 call stack, method 2 - method 2 call stack, and method 3 - method 3 call stack, as the method call stack of contract 2 corresponding to the initialization transaction task A. Further, node A can calculate the method hash corresponding to each method call stack respectively, and thus obtain the target method hash values corresponding to this contract 2, including: method 1 - method hash 1, method 2 - method hash 4, and method 3 - method hash 5. This enables the solution provided in the embodiment of the present application to identify and reuse similar contract codes, which means that contract methods with generality (such as the deposit evidence method) can be shared among multiple contracts. This can reduce the complexity of contract development, improve the generality and maintainability of contract codes, and is conducive to the rapid development and iteration of blockchain applications.
[0111] In one embodiment, after starting a contract process corresponding to a target contract package to enable the contract process to execute an initialization transaction task and obtaining a second execution result, the method further includes:
[0112] Storing the initialization transaction task carrying the second execution result into a new block;
[0113] Sending the new block to other nodes in the blockchain for consensus;
[0114] When the new block reaches a consensus, storing the new block into the block ledger maintained by itself.
[0115] Specifically, taking node A in the node cluster of the blockchain system as an example for illustration. As Figure 9 shown, it is a schematic diagram of the contract installation process based on the contract method stack hash. Node A starts a contract process corresponding to the target contract package, that is, the contract package 2 process, to enable the newly started contract package 2 process to execute the initialization transaction task A, obtain the second execution result A corresponding to the initialization transaction task A, and after determining the deployment result of contract 2 based on the second execution result A, node A can store the initialization transaction task A carrying the second execution result A into a new block and send the new block to other nodes in the blockchain for consensus; when the new block reaches a consensus, node A stores the new block into the block ledger maintained by itself.
[0116] In this embodiment, based on the contract repository, the method hash value can be quickly located, and at the same time, based on the mapping table, the process of the contract package to be called can be quickly located, thereby realizing the reuse of the contract process, avoiding the operation of a large number of duplicate contract processes, and thus reducing the resource consumption of the entire blockchain system. Compared with the traditional solution, the method provided in this application can significantly improve the resource utilization rate and reduce the system pressure when processing a large number of transaction tasks, effectively improving the transaction execution efficiency in the blockchain while improving the processing performance of the entire blockchain.
[0117] In one embodiment, before obtaining a transaction task and contract information corresponding to the transaction task, the method further includes:
[0118] Obtaining each contract method corresponding to the contract information;
[0119] Determining the method hash value of each contract method;
[0120] Constructing a mapping table based on the mapping relationship between each method hash value and the contract package.
[0121] Specifically, taking node A in the node cluster of the blockchain system as an example for illustration. As Figure 6As shown in the figure, it is a schematic diagram of a method hash contract mapping table. Before node A obtains a transaction task and the contract information corresponding to the transaction task from the transaction pool, node A can obtain each contract method (contract name) corresponding to each contract information and determine the method hash value of each contract method; further, node A can construct a method hash contract mapping table as shown in Figure 6 as shown in the figure.
[0122] For example, among the contract information obtained by node A, there is a contract 2 as shown in Figure 8 as shown in the figure. Node A can determine that the contract methods corresponding to contract 2 include: method 1, method 2, and method 3, and determine that all possible method call stacks of each contract method (method 1, method 2, and method 3) include: method 1 - method 1 call stack, method 2 - method 2 call stack, and method 3 - method 3 call stack, and calculate the method hash corresponding to each method call stack respectively, then the method hash values of each contract method in this contract 2 can be obtained, including: method 1 - method hash 1, method 2 - method hash 4, and method 3 - method hash 5; further, node A can construct a method hash contract mapping table as shown in Figure 8 as shown in the figure based on the mapping relationship between each method hash value and the contract package, that is, there is a mapping relationship between method hash 1 - contract package 1, method hash 4 - contract package 2, and method hash 5 - contract package 2. This makes the contract package and the contract name separated. The mapping of the contract name and the method hash is stored in the contract repository, while the mapping of the method hash and the contract package is recorded in the method hash contract mapping table. This design enables the contract package to be shared among multiple contract names, realizing the decoupling between the contract program and the contract name. During the transaction execution process, the contract package process interacts with the transaction context, and the read-write set recorded in the transaction context is only related to the contract name and has nothing to do with the contract package. This decoupling technology can further improve the flexibility and efficiency of contract execution.
[0123] In one embodiment, the method further includes:
[0124] Extracting the target contract method and target method parameters corresponding to the transaction task from the smart contract node tree; the sub-tree in the smart contract node tree is a security division of each contract method and the corresponding method parameters in the smart contract and is generated based on each divided contract method and method parameter;
[0125] Determining the riskiness of the transaction task based on the target contract method and the target method parameters;
[0126] When the riskiness is that there is a security risk, performing the step of reusing the contract process corresponding to the contract package.
[0127] Among them, the smart contract node tree refers to a tree structure obtained by disassembling each contract method and method parameter in the smart contract, that is, the smart contract node tree. That is, the smart contract node tree refers to transforming the smart contract into a tree-like structure composed of each contract method and method parameter. For example, each smart contract in this application corresponds to a smart contract node tree. It can be understood that in some cases, the smart contract node tree in this application can also be called a disassembled matching tree.
[0128] The smart contract method and method parameter refer to a specific type of smart contract method included in a smart contract and the method parameter corresponding to the smart contract method. For example, as Figure 4 shown in Contract 1, the smart contract methods included are: Method 1, Method 2, Method 3... Method n; among them, the method parameters corresponding to Method 1 can further include: Parameter 1 and Parameter 2. Then, the smart contract method corresponding to a certain transaction task extracted by the node cluster from the smart contract node tree can be: Method 1, and the extracted method parameters can be: Parameter 1 and Parameter 2 corresponding to Method 1.
[0129] The target contract method corresponding to the transaction task refers to the contract method included in the contract information carried by the transaction task, and the target method parameter corresponding to the transaction task refers to the contract input parameter included in the contract information carried by the transaction task. For example, the contract information carried by a certain transaction task A sent by the client includes: contract name (Contract 1), contract method (Method 1), and contract input parameter (the value of Parameter 1 is 30).
[0130] The security classification means dividing each contract method included in a smart contract and the parameters corresponding to each contract method according to whether there are security risks. For example, the methods (Method 1, Method 2... Method n) included in Contract 1 and the parameters corresponding to each method (for example, Parameter 1 and Parameter 2 corresponding to Method 1) are divided according to whether there are security risks.
[0131] The riskiness of the transaction task refers to the risk situation of the transaction task, which is used to evaluate the risk situation of the transaction task. For example, the riskiness of the transaction task in this application can include: there may be two situations of security risks and no risks. It can be understood that in some cases, the classification granularity of the riskiness of the transaction task can be finer, including but not limited to the above two situations.
[0132] In some cases, the riskiness of the transaction task in this application specifically refers to the contract security risk. The contract security risk means that the contract may cause adverse effects on the host during execution. For example, during execution, it may occupy too much CPU (Central Processing Unit) memory, have more network accesses, access the files of the host, write to the host disk, use the devices of the host, and so on.
[0133] Specifically, after the node cluster obtains the transaction task carried in the transaction request, the node cluster may, according to the contract information carried in the transaction task. For example, the node cluster may search for the smart contract node tree corresponding to the contract name according to the contract name in the contract information carried in the transaction task, and extract the target smart contract method and the target method parameters corresponding to the transaction task from the found smart contract node tree. Among them, the sub-tree in the smart contract node tree is a security division of each contract method and the corresponding method parameters in the smart contract, and is generated based on each contract method and method parameter after the division.
[0134] Furthermore, the node cluster may perform a risk assessment on the contract method and the contract input parameters in the contract information carried in the transaction task based on the smart contract method and method parameters extracted from the smart contract node tree, so as to obtain the risk of the transaction task. For example, assume that the contract method and method parameters extracted by the node cluster from the smart contract node tree are: method n and empty data respectively. Then the node cluster may perform a risk assessment on the contract method (method n) and the contract input parameters in the contract information carried by the transaction task A according to the method n extracted from the smart contract node tree, and obtain the risk of the transaction task A as: there is a security risk. Since the contract method and method parameters extracted from the smart contract node tree are: method n and empty data respectively, it means that regardless of whether the transaction task A carries contract input parameters, as long as the transaction task needs to call method n, the risk of the transaction task A is: there is a security risk. When the risk of the transaction task A is a security risk, the node cluster may run the smart contract method corresponding to the transaction task A through a process to execute the transaction task A, that is, the node cluster may execute the steps of reusing the contract process of the contract program package. Since the sub-tree in the smart contract node tree is a pre-security division of each method and the corresponding parameters of the smart contract, and is composed of each method and the corresponding parameters after the division, when the node cluster receives a transaction request carrying a transaction task sent by the client, it may extract the contract method and method parameters corresponding to the transaction task from the smart contract node tree, and quickly and accurately determine the risk of the transaction task based on the contract method and method parameters, so as to adopt an optimal processing method for transaction tasks with different risks, that is, automatically allocate transaction tasks with different risks to processes or coroutines for execution, thereby achieving higher resource utilization in different scenarios, being able to efficiently obtain and execute smart contracts, ensuring the high performance of smart contract execution, and further ensuring the high performance of transaction task execution.
[0135] In one embodiment, the method further includes:
[0136] When the risk is that there is no security risk, create a contract coroutine corresponding to the contract program package so that the contract coroutine executes the transaction task.
[0137] Among them, a coroutine refers to a lightweight thread that allows multiple tasks to be executed in a single thread. Coroutines achieve concurrency by performing cooperative context switching between tasks. This means that when executing one task, the coroutine can suspend its execution, hand over control to another task, and then resume execution when appropriate. The advantage of coroutines is that they perform context switching in user mode, so the overhead is relatively small, while avoiding many problems in multi-threaded programming, such as race conditions and deadlocks. Coroutines are suitable for I / O (input / output) intensive tasks and high concurrency scenarios.
[0138] Specifically, when the risk of a transaction task is that there is no security risk, the node cluster can create a contract coroutine corresponding to the contract package so that the contract coroutine executes the transaction task, that is, the smart contract method corresponding to the transaction task is run through the created contract coroutine to execute the transaction task. In the embodiment of the present application, for transaction tasks with contract security risks, the node cluster usually uses containers or processes to execute, because containers and processes contain all the resources required for program operation, and the operating system can control the process through tools such as Cgroups, such as limiting its CPU and memory usage, not allowing it to write to the disk, not allowing it to access the network, isolating it from the memory and users of other processes, etc. For transaction tasks without security risks, for example, some transaction tasks only perform simple queries and writes with the blockchain. At this time, there is no need to start a special process to execute, because this consumes a lot of resources and has low performance. When executing this type of transaction task, a lightweight coroutine can be started for execution, which is more efficient and occupies less operating system resources. As a result, it is possible to quickly and accurately determine the risk of transaction tasks based on contract methods and method parameters, so as to adopt the optimal processing method for transaction tasks with different risks, that is, to automatically assign transaction tasks with different risks to processes or coroutines for execution, thereby achieving higher resource utilization in different scenarios, and being able to efficiently obtain and execute smart contracts, ensuring high performance of smart contract execution, and thus also ensuring high performance of transaction task execution.
[0139] In one embodiment, the present application further provides an application scenario, which applies the above-mentioned transaction execution method in the blockchain. Specifically, the application of the transaction execution method in the blockchain in the application scenario is as follows:
[0140] When the number of transactions is large and involves multiple contracts, the above-mentioned transaction execution method in the blockchain can be adopted. That is, in the blockchain system, when each node in the node cluster obtains a transaction task and the contract information corresponding to the transaction task, and after looking up the method hash value corresponding to the contract information from the contract repository; when each node in the node cluster finds the method hash value corresponding to the contract information, each node in the node cluster can look up the contract package to be called from the mapping table based on the found method hash value, and reuse the contract process corresponding to the contract package, so that the contract process executes the transaction task to obtain the first execution result. Thus, based on the process reuse of the contract method stack hash and the decoupling technology of separating the contract program from the contract name, the resource utilization rate and execution efficiency of the blockchain system are significantly improved. When dealing with a large number of transactions, this solution can effectively reduce the system pressure and reduce resource waste. At the same time, the sharing of general contract methods helps to reduce the complexity of contract development, improve the generality and maintainability of contract code, and thus promote the rapid development and iteration of blockchain applications. That is, the contract process compression scheme based on the contract method stack hash proposed in this application can achieve the reuse of processes, avoid the problem of running a large number of duplicate contract processes, improve the execution efficiency and resource utilization rate of the system, and thus effectively improve the performance of contract execution and also improve the processing performance of the entire blockchain.
[0141] The method provided by the embodiments of this application can be applied to various blockchain scenarios. The following takes the scenario where the number of transactions in the blockchain is large and involves multiple contracts as an example to illustrate the transaction execution method in the blockchain provided by the embodiments of this application.
[0142] Blockchain: A distributed ledger technology in the field of information technology, generally composed of consensus, transaction blocks and state data storage, cryptographic identity security, etc. Since the ledger is distributedly stored and the blocks are consensus-based, it has characteristics such as immutability, traceability, and common maintenance.
[0143] Smart contract: A smart contract (English: Smart contract) is a computer protocol designed to spread, verify, or execute contracts in an information-based manner. Smart contracts allow for trusted transactions without a third party, and these transactions are irreversible.
[0144] Block ledger: The block ledger is the core data structure in the blockchain system, used to store and manage all confirmed blocks. The block ledger is organized in a chain structure, and each block contains a set of transactions, a block header (including metadata such as the hash value of the previous block, timestamp, etc.), and other information. The block ledger provides a public and immutable transaction history record for the blockchain system, ensuring the transparency and consistency of the system.
[0145] State Data: State data is a data structure used in a blockchain system to represent the current state of the system. State data includes the balances of all accounts, the states of smart contracts, and other relevant information. State data is continuously updated as transactions are executed, reflecting the global state of the blockchain system at a certain point in time. In a blockchain system, state data is usually stored in the form of a Merkle tree or other cryptographic data structures to ensure its integrity and security.
[0146] Transaction Pool: The transaction pool (also known as the memory pool or mempool) is a data structure in a blockchain network used to store pending transactions that have not yet been packed into blocks. When a user submits a new transaction to the blockchain network, the transaction first enters the transaction pool. When a blockchain node is preparing to generate a new block, it will select a certain number of transactions from the transaction pool for packing. The transaction pool helps to improve the processing capacity of the blockchain network. At the same time, it can also be used as a strategy to let nodes preferentially select transactions with higher transaction fees for packing, thereby increasing the income of the nodes.
[0147] Method Stack: The method stack refers to performing static analysis before the contract runs to obtain all possible call stack codes of the method.
[0148] Process Reuse: Process reuse refers to reusing existing created processes to execute new tasks in an operating system instead of creating a new process every time. Process reuse can reduce the overhead of process creation and destruction, improve the utilization rate of system resources and execution efficiency. In some scenarios, such as when dealing with a large number of similar tasks, process reuse can significantly reduce system pressure and improve performance. There are various ways to implement process reuse, such as process pools (ProcessPool) and thread pools (Thread Pool).
[0149] The traditional solution has the following several defects:
[0150] 1. High resource consumption: In the traditional solution, the deployment and execution of each contract require starting an independent process. When the number of transactions is large and involves multiple contracts, this will lead to a large amount of resource waste and system pressure, reducing the stability and scalability of the system.
[0151] 2. Low execution efficiency: Since contract process reuse is not implemented in the traditional solution and each contract needs to run independently, the system will have low execution efficiency when processing a large number of transactions. In addition, due to the tight coupling between the contract program and the contract name, the flexibility and efficiency during the contract execution process are also restricted.
[0152] 3. Poor generality: In traditional solutions, similar contract codes cannot be shared among multiple contracts, which means that general contract methods (such as the deposit and proof method) need to be repeatedly written and deployed in each contract. This not only increases the complexity of contract development but also reduces the generality and maintainability of contract codes, which is not conducive to the rapid development and iteration of blockchain applications.
[0153] Therefore, to solve the above problems, this application proposes a contract process compression scheme based on the hash of the contract method stack. This scheme focuses on solving the above problems, that is, the main innovation points of the technical solution provided by this application include:
[0154] 1. Contract process reuse technology based on contract method stack comparison: In a traditional blockchain system, the deployment and execution of each contract require starting an independent process. When the number of transactions is large and involves multiple contracts, this will lead to a large amount of resource waste and system pressure. This scheme classifies the same contract methods into the same process for execution by analyzing the call stack of contract methods and calculating their hash values. In this way, the reuse of processes can be achieved, avoiding the problem of a large number of repeated contract processes running, and improving the execution efficiency and resource utilization rate of the system.
[0155] 2. Transaction runtime decoupling technology that separates contract programs from contract names: In this scheme, the contract program package and the contract name are separated. The mapping between the contract name and the method hash is stored in the contract repository, while the mapping between the method hash and the contract program package is recorded in the method hash contract mapping table. This design enables the contract program package to be shared among multiple contract names, achieving decoupling between the contract program and the contract name. During the transaction execution process, the contract program package process interacts with the transaction context, and the read-write sets recorded in the transaction context are only related to the contract name and have nothing to do with the contract program package. This decoupling technology can further improve the flexibility and efficiency of contract execution.
[0156] The advantages of this scheme are as follows:
[0157] 1. Improved resource utilization rate: This scheme can avoid the operation of a large number of repeated contract processes through the contract process reuse technology based on contract method stack comparison, thereby reducing the consumption of system resources. Compared with traditional solutions, this scheme can significantly improve resource utilization rate and reduce system pressure when processing a large number of transactions.
[0158] 2. Improved execution efficiency: Since this scheme adopts the transaction runtime decoupling technology that separates contract programs from contract names, the contract program package can be shared among multiple contract names, achieving decoupling between the contract program and the contract name. This design can further improve the flexibility and efficiency of contract execution, thereby improving the execution efficiency of the entire system when processing a large number of transactions.
[0159] 3. Enhanced versatility: This solution can identify and reuse similar contract codes, which means that common contract methods (such as evidence storage methods) can be shared among multiple contracts. This can reduce the complexity of contract development, improve the versatility and maintainability of contract codes, and facilitate the rapid development and iteration of blockchain applications.
[0160] The specific structure of the text in the embodiments of the present application is as follows:
[0161] 1. The system architecture of the contract process compression solution based on the contract method stack hash is explained, and the system architecture of the entire solution is designed, including the network module, verification module, transaction pool module, scheduling execution and verification module, consensus module and storage module of the blockchain node. At the same time, the contract method stack hash architecture diagram, contract deployment module interaction diagram and transaction call module interaction diagram are introduced in detail. The above system architecture is the operating basis of the entire environment. The above solution and system architecture ensure the efficient and stable operation of the system.
[0162] 2. Designed the full life cycle process of the contract process compression solution based on the contract method stack hash. Including the contract installation process based on the contract method stack hash (the process of disassembling the method code, calculating the hash, determining whether it is repeated, and whether it is necessary to start the contract process during the installation process), and the transaction call process based on the contract method stack hash (the process of retrieving the process where the contract package is located according to the method hash when calling the transaction, and using the process to execute the transaction).
[0163] On the product side, the application scenarios of the method provided by this application on the product side mainly include the following aspects:
[0164] 1. Supply chain finance: In the field of supply chain finance, transactions between multiple enterprises often involve similar contract logic, such as invoice chaining, cargo tracking, etc. This solution can realize the reuse of contract processes and the sharing of common contract methods, improve the efficiency of processing a large number of transactions, reduce system resource consumption, and facilitate the rapid development and iteration of supply chain finance applications.
[0165] 2. Cross-chain transactions: In cross-chain transaction scenarios, multiple blockchains need to transfer assets and share information. This solution can achieve the reuse of contract logic between multiple blockchains through the technology of contract method stack comparison and separation of contract program and contract name, improve the execution efficiency of cross-chain transactions, and reduce the complexity of cross-chain operations.
[0166] 3. IoT data transactions: In the IoT field, data generated by a large number of devices needs to be traded and shared among different participants. This solution can realize the reuse of general contract methods, improve the efficiency of data transactions, reduce resource consumption, and help the rapid construction and operation of IoT data transaction platforms.
[0167] 4. Digital Identity Authentication: In the digital identity authentication scenario, multiple applications and services need to verify the identity of users. This solution can achieve the reuse of identity authentication contract logic, improve authentication efficiency, reduce system resource consumption, and is conducive to building an efficient and secure digital identity authentication platform.
[0168] 5. Financial Derivatives Trading: In the financial derivatives trading scenario, various financial products have similar contract logics, such as options, futures, etc. This solution can achieve the reuse of financial derivatives contract processes, improve trading execution efficiency, reduce resource consumption, and contribute to the rapid development and operation of the financial derivatives trading platform.
[0169] On the technical side, the implementation process of the method provided in 1.1 of this application is as follows:
[0170] 1.1.1 System Architecture of the Contract Process Compression Scheme Based on Contract Method Stack Hash
[0171] As Figure 4 shown, it is a schematic diagram of the system architecture of the contract process compression scheme based on contract method stack hash, which describes the system architecture of the contract process compression scheme based on contract method stack hash. The internal implementation of this service (node) and the interaction between each module are specifically described as follows:
[0172] 1. Network Module: The network module is responsible for handling the communication between blockchain nodes, including sending and receiving transactions, consensus information, block data, etc. It ensures that the information in the blockchain network can be transmitted and synchronized among each node.
[0173] 2. Verification Module: The verification module is responsible for performing certificate verification and permission verification on transactions to ensure the legality and security of transactions.
[0174] 1) Certificate Verification: The certificate verification module is responsible for verifying the identity of the transaction sender to ensure the legality of the transaction by checking the digital certificate and signature of the sender.
[0175] 2) Permission Verification: The permission verification module is responsible for checking whether the transaction sender has the permission to execute the transaction, such as contract deployment, contract call, etc.
[0176] 3. Transaction Pool Module: The transaction pool module is responsible for storing the transactions to be processed and providing transaction data for blockchain nodes. The transaction pool will sort the transactions according to strategies such as transaction fees and priorities for subsequent packaging into blocks.
[0177] 4. Scheduling Execution and Verification Module: The scheduling execution and verification module is responsible for obtaining transactions from the transaction pool and performing contract execution and verification. It includes the following sub-modules:
[0178] 1) Block transaction packager: Responsible for retrieving transactions from the transaction pool and packaging them into new blocks.
[0179] 2) Virtual machine engine: Responsible for executing contract code and handling transaction logic.
[0180] 3) Block generator: Responsible for generating new blocks, including transaction data, block headers, and other information.
[0181] 4) Contract repository: Responsible for storing the mapping relationship between contract names and method hashes.
[0182] 5) Contract method call stack analyzer: Responsible for analyzing the call stack of contract methods and calculating method hashes.
[0183] 6) Method hash - contract mapping table: Responsible for storing the mapping relationship between method hashes and contract packages.
[0184] 7) Contract process pool: Responsible for managing contract processes and realizing the reuse of contract processes.
[0185] 5. Consensus module: The consensus module is responsible for reaching a consensus on the newly generated blocks to ensure that the entire blockchain network reaches an agreement. There are various consensus algorithms, such as Proof of Work (PoW), Proof of Stake (PoS), etc.
[0186] 6. Storage module: The storage module is responsible for storing the data of blockchain nodes, including the block ledger and state data.
[0187] 1) Block ledger: The block ledger is responsible for storing the block data that has passed the consensus, forming the entire blockchain.
[0188] 2) State data: The state data is responsible for storing the state information on the blockchain nodes, such as contract execution results, account balances, etc.
[0189] 1.1.2 Contract method stack hash architecture diagram
[0190] As Figure 5 shown, the contract repository not only saves the contract package but also saves the mapping between the contract method name and its method hash for quick positioning of the hash next time; as Figure 6 shown in the method hash - contract mapping table, it maintains the mapping between method hashes and contract packages for quick positioning of the contract package process next time. Among them, specific active contract methods will only be active in one contract package process.
[0191] 1.1.3 Contract deployment module interaction diagram
[0192] As Figure 8As shown, during the contract deployment process, the method call stack is analyzed first, and then the hash is calculated. If the hash does not appear in the method hash contract mapping table, it is added. If there is an addition, the process of the contract program package is run for the newly added method.
[0193] 1.1.4 Interaction Diagram of Transaction Call Module
[0194] As Figure 10 shown, it is the interaction diagram of the transaction call module. As Figure 10 in the interaction process shown, when a transaction is called, the method hash is calculated, the contract program package is obtained, and then the transaction is sent to the corresponding process. The context of the transaction has nothing to do with the program package and only relates to the contract name.
[0195] 1.1.5 Contract Installation Process Based on Contract Method Stack Hash
[0196] This section mainly introduces the process of disassembling method code, calculating hash, determining duplication, and whether it is necessary to start the contract process during the contract installation. As Figure 9 shown, it is the schematic diagram of the contract installation process based on the contract method stack hash, specifically as follows:
[0197] 1. Start
[0198] 2. The user writes the source code of the smart contract locally
[0199] 3. The user packs all parameters including the above source code
[0200] 4. The user signs the above packed content
[0201] 5. The user sends the above packed content and signature to the blockchain node together
[0202] 6. The blockchain node network module receives the above request
[0203] 7. The blockchain node authentication module verifies the certificate and signature of the above request. Is the verification passed? If yes, go to 9; otherwise, go to 8
[0204] 8. Return the result that the signature verification fails. Go to 28
[0205] 9. The authentication module verifies the permission of the above request. Is the verification passed? If yes, go to 11; otherwise, go to 10
[0206] 10. Return the result that the permission verification fails and go to 28
[0207] 11. The transaction pool receives this contract deployment transaction
[0208] 12. The scheduling execution and verification module periodically fetches transactions from the transaction pool and obtains the transaction for this new deployment contract.
[0209] 13. The contract method call stack analyzer analyzes the code of the contract source code.
[0210] 14. The contract repository records the method hash mapping, that is, the mapping between the method name and the method call stack.
[0211] 15. The contract repository records the hash of the method call stack and replaces the above mapping with the mapping between the method name and the hash.
[0212] 16. The contract repository queries whether all the method hashes in this contract already exist in the method hash contract mapping table.
[0213] 17. If there are method hashes that do not exist, go to 18; otherwise, go to 19.
[0214] 18. Add the mapping between the method hash and the contract package to the method hash contract mapping table.
[0215] 19. Start this contract package as a contract process and execute the initialization transaction.
[0216] 20. If the initialization transaction is executed successfully, go to 21; otherwise, go to 22.
[0217] 21. Return the information indicating successful contract initialization and go to 23.
[0218] 22. Return the error indicating failed contract initialization.
[0219] 23. Record the result of contract initialization.
[0220] 24. Store this transaction into the block and send it to all nodes through the consensus module for consensus.
[0221] 25. If the consensus is passed, go to 26; otherwise, go to 28.
[0222] 26. All nodes append the block to the block ledger.
[0223] 27. All nodes update the data in the block to the state data, such as the latest result obtained from contract execution.
[0224] 28. End
[0225] 1.1.6 Transaction Call Process Based on Contract Method Stack Hash
[0226] This section mainly introduces the process of retrieving the process where the contract package is located based on the method hash during transaction call and using this process to execute the transaction. For example Figure 7As shown below, it is a schematic diagram of the transaction call process based on the contract method stack hash, specifically as follows:
[0227] 1. Start
[0228] 2. The user specifies the contract, method, parameters, etc. to be called
[0229] 3. The user packs the above parameters
[0230] 4. The user signs the above packed content
[0231] 5. The user sends the above packed content and signature to the blockchain node together
[0232] 6. The blockchain node network module receives the above request
[0233] 7. The blockchain node authentication module verifies the certificate and signature of the above request. If the verification passes, go to 9; otherwise, go to 8
[0234] 8. Return the result that the signature verification fails and go to 26
[0235] 9. The authentication module verifies the permissions of the above request. If the verification passes, go to 11; otherwise, go to 10
[0236] 10. Return the result that the permission verification fails and go to 26
[0237] 11. The transaction pool receives this transaction
[0238] 12. The scheduling execution and verification module periodically fetches transactions from the transaction pool and fetches this transaction
[0239] 13. The scheduling execution and verification module queries the method hash corresponding to this method from the contract repository
[0240] 14. Query the program package that should be called by the method hash through the method hash - contract mapping table
[0241] 15. The scheduling execution and verification module sends the transaction to the process corresponding to the contract program package for execution
[0242] 16. The contract program package process interacts with the transaction context during the execution of the transaction to obtain and store data
[0243] 17. The read - write set recorded by the transaction context is only related to the contract name and has nothing to do with the contract program package
[0244] 18. Whether the transaction is executed successfully. If yes, go to 19; otherwise, go to 20
[0245] 19. Return the information indicating successful contract execution and go to 21
[0246] 20. Return the error indicating failed contract execution
[0247] 21. Record the result of contract execution
[0248] 22. Store this transaction in the block and send it to all nodes through the consensus module for consensus
[0249] 23. Whether the consensus is passed. If yes, go to 24; otherwise, go to 26
[0250] 24. All nodes append the block to the block ledger
[0251] 25. All nodes update the data in the block to the state data, such as the latest result obtained from contract execution
[0252] 26. End
[0253] The beneficial effects produced by the technical solution of this application include:
[0254] Through the process reuse based on the hash of the contract method stack and the decoupling technology of separating the contract program from the contract name, the resource utilization rate and execution efficiency of the blockchain system are significantly improved. When dealing with a large number of transactions, the method provided by this solution can reduce the system pressure and resource waste. At the same time, the sharing of general contract methods helps to reduce the complexity of contract development, improve the generality and maintainability of contract code, and thus promote the rapid development and iteration of blockchain applications.
[0255] It should be understood that although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same moment, but can be executed at different moments, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0256] Based on the same inventive concept, an embodiment of the present application further provides a transaction execution device in a blockchain for implementing the transaction execution method in the blockchain involved above. The implementation solutions provided by this device to solve problems are similar to the implementation solutions recorded in the above method. Therefore, the specific limitations in one or more embodiments of the transaction execution device in the blockchain provided below can refer to the limitations on the transaction execution method in the blockchain above, and will not be repeated here.
[0257] In one embodiment, as Figure 11 shown, a transaction execution device in a blockchain is provided, including: an acquisition module 1102, a search module 1104, and a reuse module 1106, where:
[0258] The acquisition module 1102 is configured to acquire a transaction task and contract information corresponding to the transaction task.
[0259] The search module 1104 is configured to search for a method hash value corresponding to the contract information from a contract repository; when the method hash value is found, search for a contract program package to be called from a mapping table based on the method hash value.
[0260] The reuse module 1106 is configured to reuse a contract process corresponding to the contract program package, so that the contract process executes the transaction task to obtain a first execution result.
[0261] In one embodiment, the device further includes: a receiving module, configured to receive a transaction request sent by a client; a verification module, configured to perform signature verification and permission verification on the transaction request to obtain a verification result; a storage module, configured to store the transaction task carried in the transaction request in a transaction pool when the verification result indicates that the verification is passed; the acquisition module is further configured to acquire a transaction task from the transaction pool and acquire contract information corresponding to the transaction task.
[0262] In one embodiment, the contract process corresponding to the contract program package includes a first contract process and a second contract process. The first contract process is a process running on the local node in the blockchain, and the second contract process is a process running on other nodes in the blockchain; the device further includes: an execution module, configured to execute the transaction task through the first contract process to obtain a first execution result; a sending module, configured to send the transaction task to the second contract process, so that the second contract process executes the transaction task to obtain a first execution result.
[0263] In one embodiment, the acquisition module is further configured to obtain the first execution result and the read-write set for executing the transaction task from the contract process; wherein, the read-write set has an association relationship with the contract identifier in the contract information, and the read-write set has no association relationship with the contract package; the apparatus further includes: a storage module, configured to add the first execution result and the read-write set to the transaction task and store them in a new block; a sending module, configured to send the new block to other nodes in the blockchain for consensus; the storage module is further configured to, after the new block reaches consensus, store the new block in the block ledger maintained by itself.
[0264] In one embodiment, the acquisition module is further configured to obtain an initialization transaction task and the contract information corresponding to the initialization transaction task from a transaction pool; the apparatus further includes: a determination module, configured to determine a method call stack based on the contract information corresponding to the initialization transaction task; based on the method call stack, determine a target method hash value; an addition module, configured to, when the target method hash value does not exist in the mapping table, add a mapping relationship between the target method hash value and a target contract package to the mapping table; a start module, configured to start a contract process corresponding to the target contract package, so that the contract process executes the initialization transaction task to obtain a second execution result; the determination module is further configured to determine a deployment result of the smart contract according to the second execution result.
[0265] In one embodiment, the apparatus further includes: a receiving module, configured to receive a transaction request sent by a client; a verification module, configured to perform signature verification and permission verification on the transaction request to obtain a verification result; a storage module, configured to, when the verification result indicates that the verification is passed, store the initialization transaction task carried in the transaction request for deploying the smart contract in a transaction pool.
[0266] In one embodiment, the contract information corresponding to the initialization transaction task includes a contract name; the determination module is further configured to, based on the contract name, determine each contract method in the smart contract corresponding to the contract name; determine the method call stack corresponding to each contract method; and use the method call stack corresponding to each contract method as the method call stack of the contract information corresponding to the initialization transaction task.
[0267] In one embodiment, the apparatus further includes: a storage module, configured to store the initialization transaction task carrying the second execution result in a new block; a sending module, configured to send the new block to other nodes in the blockchain for consensus; the storage module is further configured to, after the new block reaches consensus, store the new block in the block ledger maintained by itself.
[0268] In one embodiment, the obtaining module is further configured to obtain each contract method corresponding to the contract information; the apparatus further includes: a determining module, configured to determine a method hash value of each of the contract methods; and a constructing module, configured to construct the mapping table based on a mapping relationship between each of the method hash values and the contract package.
[0269] In one embodiment, the apparatus further includes: an extracting module, configured to extract a target contract method and target method parameters corresponding to the transaction task from the smart contract node tree; a subtree in the smart contract node tree is generated by performing security partitioning on each contract method and corresponding method parameters in the smart contract, and based on each of the contract methods and the method parameters after partitioning; a determining module, configured to determine the riskiness of the transaction task based on the target contract method and the target method parameters; and an executing module, configured to execute the step of reusing the contract process corresponding to the contract package when the riskiness indicates a security risk.
[0270] In one embodiment, the apparatus further includes: a creating module, configured to create a contract coroutine corresponding to the contract package when the riskiness indicates no security risk, so that the contract coroutine executes the transaction task.
[0271] Each module in the above transaction execution apparatus in the blockchain can be implemented in whole or in part by software, hardware, and a combination thereof. The above modules can be embedded in the processor in the computer device in hardware form or be independent of the processor, or can be stored in the memory in the computer device in software form, so as to be called by the processor to execute the operations corresponding to the above respective modules.
[0272] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 12 shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O), and a communication interface. Among them, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store transaction execution data in the blockchain. The input / output interface of the computer device is used for exchanging information between the processor and external devices. The communication interface of the computer device is used for communicating with an external terminal through a network connection. The computer program, when executed by the processor, implements a transaction execution method in a blockchain.
[0273] Those skilled in the art can understand that Figure 12 the structure shown in Figure 12 is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device to which the solution of this application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0274] In one embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiments are implemented.
[0275] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0276] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0277] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions.
[0278] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0279] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0280] The above-described embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A transaction execution method in a blockchain, characterized in that, The method includes: Obtain a transaction task and contract information corresponding to the transaction task; Search for a method hash value corresponding to the contract information in a contract repository; When the method hash value is found, search for a contract package to be called from a mapping table based on the method hash value; Reuse a contract process corresponding to the contract package so that the contract process executes the transaction task to obtain a first execution result.
2. The method according to claim 1, wherein The method further includes: Receive a transaction request sent by a client; Perform signature verification and permission verification on the transaction request to obtain a verification result; When the verification result indicates that the verification is passed, store the transaction task carried in the transaction request in a transaction pool; The obtaining of the transaction task and the contract information corresponding to the transaction task includes: Obtain a transaction task from the transaction pool and obtain contract information corresponding to the transaction task.
3. The method according to claim 1, characterized in that The contract process corresponding to the contract package includes a first contract process and a second contract process. The first contract process is a process running on a local node in a blockchain, and the second contract process is a process running on other nodes in the blockchain; The reusing of the contract process corresponding to the contract package so that the contract process executes the transaction task to obtain a first execution result includes: Execute the transaction task through the first contract process to obtain a first execution result; Or, Send the transaction task to the second contract process so that the second contract process executes the transaction task to obtain a first execution result.
4. The method according to claim 1, wherein After the reusing of the contract process corresponding to the contract package so that the contract process executes the transaction task to obtain a first execution result, the method further includes: Obtain the first execution result and a read-write set for executing the transaction task from the contract process; wherein, the read-write set has an association relationship with a contract identifier in the contract information, and the read-write set has no association relationship with the contract package; Add the first execution result and the read-write set to the transaction task and store them in a new block; Send the new block to other nodes in the blockchain for consensus; When the new block reaches consensus, store the new block in a block ledger maintained by itself.
5. The method according to claim 1, wherein The method further includes: Obtain an initialization transaction task and contract information corresponding to the initialization transaction task from a transaction pool; Determine a method call stack based on the contract information corresponding to the initialization transaction task; Determine a target method hash value based on the method call stack; When the target method hash value does not exist in the mapping table, add a mapping relationship between the target method hash value and a target contract package to the mapping table; Start a contract process corresponding to the target contract package so that the contract process executes the initialization transaction task to obtain a second execution result; Determine a deployment result of a smart contract according to the second execution result.
6. The method according to claim 5, wherein Before the obtaining of the initialization transaction task and the contract information corresponding to the initialization transaction task from the transaction pool, the method further includes: Receive a transaction request sent by a client; Perform signature verification and permission verification on the transaction request to obtain a verification result; When the verification result indicates successful verification, store the initialization transaction task carried in the transaction request for deploying the smart contract into the transaction pool.
7. The method according to claim 5, wherein The contract information corresponding to the initialization transaction task includes a contract name; the method of determining the method call stack based on the contract information corresponding to the initialization transaction task includes: Based on the contract name, determine each contract method in the smart contract corresponding to the contract name; Determine the method call stack corresponding to each contract method; Use the method call stack corresponding to each contract method as the method call stack of the contract information corresponding to the initialization transaction task.
8. The method according to claim 5, wherein After starting the contract process corresponding to the target contract package to enable the contract process to execute the initialization transaction task and obtain a second execution result, the method further includes: Store the initialization transaction task carrying the second execution result into a new block; Send the new block to other nodes in the blockchain for consensus; When the new block reaches consensus, store the new block into the block ledger maintained by itself.
9. The method according to claim 1, wherein Before obtaining the transaction task and the contract information corresponding to the transaction task, the method further includes: Obtain each contract method corresponding to the contract information; Determine the method hash value of each contract method; Based on the mapping relationship between each method hash value and the contract package, construct the mapping table.
10. The method according to claim 1, characterized in that The method further includes: Extract the target contract method and target method parameters corresponding to the transaction task from the smart contract node tree; the subtrees in the smart contract node tree are obtained by performing security partitioning on each contract method and corresponding method parameters in the smart contract and generating them based on the partitioned contract methods and method parameters; Based on the target contract method and the target method parameters, determine the riskiness of the transaction task; When the riskiness indicates a security risk, perform the step of reusing the contract process corresponding to the contract package.
11. The method according to claim 10, characterized in that, The method further includes: When the riskiness indicates no security risk, create a contract coroutine corresponding to the contract package to enable the contract coroutine to execute the transaction task.
12. A transaction execution device in a blockchain, characterized in that, The device includes: An acquisition module for acquiring a transaction task and the contract information corresponding to the transaction task; A lookup module for looking up the method hash value corresponding to the contract information from the contract repository; when the method hash value is found, look up the required contract package to be called from the mapping table based on the method hash value; A reuse module for reusing the contract process corresponding to the contract package to enable the contract process to execute the transaction task and obtain a first execution result.
13. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 11.