Methods of transaction execution, nodes, and blockchain systems
Patent Information
- Application Number
- CN202310640869.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2043-05-31
AI Technical Summary
[0016] According to a fifth aspect of the embodiments of this specification, therein is provided a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the method as described in any of the first aspects.
Smart Images

Figure CN116662292B_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification belong to the field of blockchain technology, and in particular relate to a transaction execution method, node, and blockchain system. Background Technology
[0002] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. In a blockchain system, data blocks are sequentially linked to form a chain-like data structure, and a distributed ledger is cryptographically guaranteed to be immutable and unforgeable. Users can participate in blockchain-related transactions through blockchain nodes. For example, multiple blockchain nodes corresponding to different users can perform secure multi-party computation (SMPC) on the private data of a particular node based on privacy technologies such as homomorphic encryption and zero-knowledge proofs. Furthermore, blockchain networks enable transfers between different user accounts; and they can also issue NFTs (Non-Fungible Tokens) representing digital artworks, digital avatars, GIFs, and other digital collectibles, allowing ownership of these digital collectibles to circulate among users on the blockchain network, thereby generating value corresponding to the digital collectibles.
[0003] In related technologies, for each block that has passed consensus, the blockchain nodes in the blockchain network execute the blockchain transactions in each block in order of block height. After the transactions in any block are executed, the corresponding execution results are submitted in order of block height to complete the on-chain notarization of the block. Summary of the Invention
[0004] This specification provides a method for executing transactions, nodes, and a blockchain system. Specifically, this specification is implemented through the following technical solutions:
[0005] According to a first aspect of the embodiments of this specification, a method for executing a transaction is provided, applied to a first node in a blockchain system, the first node including a control process and multiple computing processes, the method comprising:
[0006] The control process acquires the first transaction to be executed in the first block;
[0007] If the control process determines that there is a second block in the execution phase, in response to the fact that the first transaction does not depend on the second transaction in the second block, it sends the first transaction to the first computing process among the plurality of computing processes.
[0008] The first computing process executes the first received transaction.
[0009] According to a second aspect of the embodiments of this specification, a first node in a blockchain system is provided, the first node comprising a control process and a plurality of computing processes, the control process being used for:
[0010] Retrieve the first transaction to be executed in the first block;
[0011] If it is determined that a second block is in the execution phase, in response to the first transaction not depending on the second transaction in the second block, the first transaction is sent to the first computing process among the plurality of computing processes for execution.
[0012] According to a third aspect of the embodiments of this specification, a blockchain system is provided, including a first node and a second node, wherein the first node includes a control process and multiple computing processes, wherein:
[0013] The second node is used to send the first transaction to be executed in the first block to the first node;
[0014] The first node is used to send the first transaction to the first computing process among the plurality of computing processes for execution, in response to the fact that the first transaction does not depend on the second transaction in the second block, if it is determined that there is a second block in the execution phase.
[0015] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method as described in any one of the first aspects.
[0016] According to a fifth aspect of the embodiments of this specification, therein is provided a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the method as described in any of the first aspects.
[0017] In the technical solution provided in this specification, the first node in the blockchain network includes a control process and multiple computing processes. The control process first obtains the first transaction to be executed in the first block, and then, in response to the existence of a second block in the execution stage, sends the first transaction to the first computing process among the multiple computing processes, since the first transaction does not depend on the second transaction in the second block. Finally, the first computing process executes the received first transaction.
[0018] It is understandable that the existence of a second block in the execution phase indicates that the first node is currently executing transactions within that second block. Combined with the fact that the first transaction is sent to the first computation process for execution in response to the first transaction not depending on the second transaction in the second block, it is clear that the first node can execute both the first and second transactions simultaneously, provided the first transaction does not depend on the second transaction. In other words, if the first transaction in the first block does not depend on the second transaction in the second block, the first node can execute the first transaction in the first block and the second transaction in the second block in parallel. Compared to related technical solutions that execute different blocks sequentially, the first node in this solution can execute multiple blocks in parallel, significantly accelerating the overall block execution speed and contributing to improved block execution and subsequent processing efficiency.
[0019] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this specification. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of a blockchain system provided in an exemplary embodiment;
[0022] Figure 2 This is a schematic diagram of a transaction execution process in a blockchain node provided by related technologies;
[0023] Figure 3 This is a flowchart illustrating a method for executing a transaction, as provided in an exemplary embodiment.
[0024] Figure 4 This is a schematic diagram of a transaction execution process in a blockchain node, provided as an embodiment.
[0025] Figure 5 This is a schematic diagram of the structure of a first node in a blockchain system provided in an exemplary embodiment;
[0026] Figure 6 This is a schematic diagram of the structure of a device provided in an exemplary embodiment. Detailed Implementation
[0027] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this specification.
[0028] It should be noted that in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification. In some other embodiments, the methods may include more or fewer steps than those described in this specification. Furthermore, a single step described in this specification may be broken down into multiple steps in other embodiments; and multiple steps described in this specification may be combined into a single step in other embodiments. It should be understood that although the terms first, second, third, etc., may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."
[0029] Figure 1 This is a schematic diagram of a blockchain system provided in an exemplary embodiment. For example... Figure 1As shown, a blockchain system is a distributed network built through multiple nodes. It involves peer-to-peer (P2P) communication between any two nodes at the application layer. For example, any two nodes from n1 to n5 can communicate at the application layer via a P2P network. The blockchain system utilizes a chain-like block structure to construct a decentralized (or multi-centralized) distributed ledger, which is stored on each node (or most nodes, such as consensus nodes) within the distributed blockchain system. Therefore, the blockchain system needs to address the consistency and correctness of the ledger data across these decentralized (or multi-centralized) nodes. Accordingly, each node in the blockchain system runs a blockchain program. Under certain fault-tolerance requirements, a consensus mechanism ensures that all loyal nodes have the same transactions, thereby guaranteeing consistent execution results for the same transactions. Transactions are packaged into blocks, and the world state is updated based on the execution results of the same transactions. The current mainstream consensus mechanisms include, but are not limited to: Proof of Work (POW), Proof of Stake (POS), Practical Byzantine Fault Tolerance (PBFT) algorithm, Honey Badger Byzantine Fault Tolerance (HoneyBadgerBFT) algorithm, etc.
[0030] In the blockchain field, a transaction refers to a unit of task executed and recorded within the blockchain. A transaction typically includes a send field (From), a receive field (To), and a data field (Data). Blockchain transactions can include platform transactions and contract transactions. Platform transactions primarily revolve around platform account operations, including account creation, transfers, account freezing, account unfreezing, asset issuance, and notarization. Contract transactions primarily revolve around contract execution operations, including contract deployment, contract invocation, and contract upgrades.
[0031] For example, in the case of a transfer transaction, the From field represents the account address that initiated the transaction (i.e., initiated the transfer task to another account), the To field represents the account address that received the transaction (i.e., received the transfer), and the Data field includes the transfer amount. In the case of a transaction that invokes a contract, the From field represents the account address that initiated the transaction, the To field represents the account address of the contract invoked by the transaction, and the Data field includes the function name in the invoked contract and the parameters passed to that function, etc., to be used to retrieve and execute the function's code from the blockchain during transaction execution.
[0032] Accounts in a blockchain can generally be divided into two types:
[0033] Contract account: Stores the executed smart contract code and the values of the state within the smart contract code; it can typically only be activated by an external account.
[0034] Externally owned account: The account of a blockchain user.
[0035] In blockchain, a smart contract is a contract that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract in the blockchain involves initiating a transaction pointing to the smart contract's address, causing each node in the blockchain to run the smart contract code in a distributed manner. It's important to note that besides users creating smart contracts, the system can also set smart contracts in the genesis block. These contracts are generally called genesis contracts. Typically, the genesis contract can set some blockchain data structures, parameters, attributes, and methods. Furthermore, accounts with system administrator privileges can create or modify system-level contracts (referred to as system contracts). These system contracts can be used to add data structures related to different services within the blockchain.
[0036] In a contract deployment scenario, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying the contract) to a server such as... Figure 1 In the blockchain shown, the `data` field of the transaction includes the code (such as bytecode or machine code) of the contract to be created, and the `to` field of the transaction is empty, indicating that the transaction is used to deploy the contract. After the nodes reach an agreement through the consensus mechanism, the contract address "0x6f8ae93…" is determined. Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates state storage corresponding to the contract account, and saves the contract code in the contract's state storage, thus the contract is successfully created.
[0037] In scenarios where contracts are invoked, for example, Bob sends a transaction to invoke a smart contract, such as... Figure 1 In the blockchain shown, the `from` field of this transaction is the address of the account of the transaction initiator (i.e., Bob), the `to` field "0x6f8ae93…" represents the address of the smart contract being invoked, and the `data` field of the transaction includes the method and parameters for invoking the smart contract. After consensus is reached on this transaction in the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract separately, and updating the state database based on the execution of the contract.
[0038] Blockchain nodes in the blockchain system can execute blockchain transactions. A blockchain node can include multiple threads, allowing the node to execute transactions concurrently. For example, when there are multiple transactions to be executed, the blockchain node can distribute these transactions to multiple threads, so that each thread can execute (i.e., execute concurrently) the transactions it receives, thereby improving the overall execution efficiency of blockchain transactions.
[0039] For example, for transfer transactions, blockchain nodes first divide multiple transactions into multiple transaction groups based on the accounts accessed by the transactions. These transaction groups do not access the same accounts, thus allowing for parallel execution of each transaction group. However, when a smart contract is invoked within a transaction, the variables accessed in that transaction cannot be predicted before execution, making it impossible to effectively group multiple transactions and thus preventing parallel execution. In one embodiment, a second node in the blockchain (e.g., Figure 1 Node n1 in the blockchain pre-executes multiple transactions, obtaining pre-execution information for each transaction (including pre-execution read / write sets, transaction time metrics, etc.), and sends this pre-execution information to other nodes in the blockchain, including the first node, through a consensus process with other nodes (e.g., node n1). Figure 1 The other nodes (n2 to n5) can group multiple transactions according to the pre-execution read / write set of multiple transactions, so that the multiple transactions can be executed in parallel according to the grouping result.
[0040] In related technologies, for each block that has passed consensus, the blockchain nodes in the blockchain network execute the blockchain transactions in each block sequentially according to the block height. After the transactions in any block are completed, the corresponding execution results are submitted according to the block height order to complete the on-chain notarization of that block. Figure 2 The transaction execution flow shown is as follows: the first node is processing transactions in blocks N, N+1, and N+2 sequentially in a pipeline manner. The processing of any block requires the cooperation of multiple pipelines. Taking block N as an example, after the consensus pipeline reaches consensus on block N, the analysis pipeline begins to analyze the transactions according to its pre-execution information (i.e., divides the transactions into groups). After analysis, the execution pipeline controls multiple computation processes to execute the transactions in each transaction group in parallel and updates the relevant state data in the cache based on the execution results. Then, after the update, the verification pipeline participates in the proof process for the execution results. If the proof passes, the persistence pipeline submits the block and execution results to persist the block and its corresponding state data.
[0041] The parallel execution of transactions is limited to within block N, block N+1, or block N+2. Specifically, multiple transactions within block N can be executed in parallel, as can multiple transactions within block N+1, and multiple transactions within block N+2. However, these parallel execution operations are performed sequentially across different blocks. For example, block N+1 is executed after block N is completed and its state is updated, and block N+2 is executed after block N+1 is completed and its state is updated. This will not be elaborated further. It is evident that the blocks in this scheme need to be executed sequentially, resulting in low overall block execution efficiency, and the execution method needs improvement.
[0042] In response, this specification provides a new method for executing transactions, which will be discussed below. Figure 3 This execution method will be described in detail.
[0043] Figure 3 This is a flowchart illustrating a method for executing a transaction, as provided in an exemplary embodiment. Figure 3 As shown, the method is applied to the first node in a blockchain system. The first node can be the node that initiates the consensus proposal in the blockchain system (such as the master node), or it can be another blockchain node (such as a slave node). Regardless of whether it is the master node or the slave node in the blockchain system, each node can be implemented as any device, platform, equipment or cluster of devices with computing / processing capabilities.
[0044] The first node may contain a control process and multiple computing processes. It should be noted that the control process and the multiple computing processes can be separate concepts, logically belonging to the first node. The node program of the first node (used to implement the node's control logic) can be deployed on any physical device, while any of the control process and multiple computing processes can be deployed on that physical device or on other physical devices (e.g., processes can be deployed in a cluster on different cloud servers). Regardless of the deployment method, the different processes can be considered "remote," and information and data exchange can be achieved through appropriate inter-process communication technologies, such as RPC (Remote Procedure Call), PIPE (pipeline) technology, and message queue technology. This specification does not impose any limitations on this. The method includes the following steps 302-306.
[0045] Step 302: The control process obtains the first transaction to be executed in the first block.
[0046] Step 304: If the control process determines that there is a second block in the execution phase, in response to the first transaction not depending on the second transaction in the second block, the control process sends the first transaction to the first computing process among the plurality of computing processes.
[0047] In this specification, a first block may contain at least one first transaction to be executed, and a first node may obtain the aforementioned first transactions on a block-by-block basis. For example, when a first node participates in the consensus process for the first block, it may obtain each first transaction in the first block during the consensus process (e.g., each first transaction may be included in a consensus proposal for the first block, sent by the master node that initiated the proposal to other nodes participating in the consensus in the blockchain network); or, it may receive each first transaction from other nodes in the blockchain network (such as the aforementioned master node), and these transactions may be sent by the other nodes when the consensus of the first block is passed. Furthermore, this specification does not limit the block height of the first block and the second block. The following embodiments use an example where the block height of the first block is higher than the block height of the second block for illustration. Figure 4 As shown, when block N is the second block, the first block can be block N+1; while when block N+1 is the second block, the first block can be block N+2, which will not be elaborated further.
[0048] It is understandable that the second block can also contain at least one block. The control process determines that a second block is in the execution phase, indicating that the first node is currently executing transactions within the second block, meaning that all transactions in the second block have not yet been completed. At this point, the first transaction is sent to the first computation process for execution, enabling the first node to execute the first and second blocks in parallel (the execution of any block as described in this specification refers to the execution of transactions within that block). Specifically, when the second block contains multiple second transactions, all second transactions may be in several states at the current moment: all second transactions may be executing and not yet completed; some second transactions may be executing and not yet completed, while the remaining second transactions have been completed (i.e., completed); some second transactions may be executing and not yet completed, while the remaining second transactions have not yet started execution; or some second transactions may have been completed, another part may be executing and not yet completed, and the remaining second transactions have not yet started execution. Regardless of the state, the second transactions that have not been completed at the current moment include the aforementioned second transactions that are currently executing and not yet completed, and may also include second transactions that have not yet started execution.
[0049] In one embodiment, the first transaction not depending on the second transaction in the second block can be understood as the first transaction not depending on the second transaction in the second block that has not yet been completed at the current time. Specifically, there may be various situations. For example, the first transaction in the first block may not depend on the second transaction in the second block. Where the first block contains multiple first transactions, if each of the first transactions does not depend on the second transaction in the second block, then each first transaction can be sent to the first computing process among the multiple computing processes; or, if only a portion of all the first transactions does not depend on the second transaction in the second block, then these portions of the first transactions can be sent to the first computing process among the multiple computing processes. Therefore, the first transactions sent by the control process to the first computing process for execution while executing the second transaction, as described in this specification, are all first transactions that do not depend on the second transaction. In this way, regardless of how many first transactions in the first block do not depend on the second transaction, these portions of the first transactions can be sent to the corresponding first computing process for execution, thus fully realizing the parallel execution of independent transactions within different blocks. For example, considering that dependent transactions need to be executed in the order of their dependencies, the second transaction that has already been completed at the current moment must not depend on the first transaction (the first transaction has not yet been executed). Therefore, it is only necessary to ensure that the first transaction does not depend on the second transaction that has not yet been completed in the second block at the current moment before the first transaction can be executed in parallel. In this way, the number of second transactions that the control process needs to compare to see if they are dependent on by the first transaction can be reduced, thereby reducing the workload of the control process.
[0050] Under normal circumstances, the actual execution process of any transaction (i.e., the execution process of the first node for that transaction) is the same as its pre-execution process (such as the pre-execution process of the master node for that transaction), and the corresponding execution results and read / write sets are also consistent. Therefore, the dependency relationship between transactions can be determined based on the pre-execution information generated during the pre-execution phase—this dependency relationship is used to reflect the interrelationships between transactions during their actual execution phase.
[0051] In one embodiment, the control process can further determine the first pre-execution read set and the first pre-execution write set of the first transaction from the first pre-execution information of the first transaction; and determine the second pre-execution read set and the second pre-execution write set of the second transaction from the second pre-execution information of the second transaction. The control process can obtain the pre-execution information of any transaction simultaneously, such as receiving each first transaction and its corresponding first pre-execution information from the master node, and receiving each second transaction and its corresponding second pre-execution information from the master node, etc., which will not be elaborated further. The pre-execution information of any transaction can include the pre-execution read and write sets of the transaction. The pre-execution read and write sets can include a pre-execution read set and a pre-execution write set, wherein the pre-execution read set includes key-value pairs of variables read by the transaction during pre-execution, and the pre-execution write set includes key-value pairs of variables written by the transaction during pre-execution. The variables include, for example, external accounts in the blockchain, or variables defined in a contract account. Based on this, if the second pre-execution write set has no intersection with either the first pre-execution write set or the first pre-execution read set, it can be determined that the first transaction does not depend on the second transaction. It is understandable that the second pre-execution write set has no intersection with the first pre-execution write set and the first pre-execution read set. This indicates that during the pre-execution phase, the variables written by the second transaction will neither be read by the first transaction nor written by the first transaction. Therefore, the write operation on the variables during the pre-execution of the second transaction will not affect the pre-execution process of the first transaction. So at this point, it can be determined that the first transaction does not depend on the second transaction.
[0052] Where the first node is not the master node in the blockchain system, the first pre-execution information of each of the multiple first transactions in the first block can be obtained by the master node through pre-execution of the multiple first transactions. Based on this, the control process can obtain the first pre-execution information of each of the multiple first transactions from the master node.
[0053] In one embodiment, to further improve transaction execution efficiency, when a first block contains multiple first transactions, the multiple first transactions can be divided into corresponding transaction groups according to the first pre-execution information, and the first transactions can be sent in units of transaction groups. The multiple first transactions can be grouped by their provider (such as the master node), or they can be grouped by the first node. For example, when the control process obtains the first transactions to be executed in the first block, it can obtain M transaction groups based on the first pre-execution information of each of the multiple first transactions. Specifically, it can obtain M transaction groups processed according to the grouping situation (such as packaging, compression, etc.), from which at least one corresponding first transaction can be extracted; or, it can obtain all the first transactions and the corresponding grouping information, whereby the grouping information is used to characterize the grouping situation of the M transaction groups (i.e., which transactions each group specifically contains). For another example, when the aforementioned multiple first transactions are obtained, the control process can also group the multiple first transactions into M transaction groups according to the first pre-execution information of each of the multiple first transactions. Where M > 1, the transaction is divided into at least two transaction groups, with each transaction group containing a distinct first transaction. Furthermore, there can be continuous dependencies between the first transactions within any transaction group. For example, if first transaction Tx1 depends on Tx2, and first transaction Tx2 depends on both Tx3 and Tx4, then first transactions Tx1 through Tx4 can be grouped into the same transaction group. Based on these transaction groups, the control process can, in response to each transaction in the M transaction groups not depending on a second transaction in the second block, send the M transaction groups to the corresponding first computation processes among the multiple computation processes. In this way, first transactions with interdependent relationships are grouped into the same transaction group, while first transactions without dependencies are grouped into different transaction groups. This facilitates the first computation process receiving any transaction group to execute each transaction in the order of dependencies within that group, minimizing the risk of errors in execution results due to disordered transaction execution order.
[0054] It should be noted that, for the multiple computing processes in the first node, the first computing process used to execute the first transaction can be any part or all of the multiple computing processes. If the computing process executing the second transaction is denoted as the second computing process, then at the current moment, any second computing process may have received at least one second transaction but has not yet started execution, or may be currently executing at least one received second transaction. It is understood that any of the multiple computing processes can be the first computing process, the second computing process, or both; in other words, the first computing process and the second computing process described in this specification may overlap.
[0055] It should also be noted that if a first computing process is also a second computing process, then for the first transaction it receives, that computing process can execute the first and second transactions sequentially (e.g., executing the first transaction after the second transaction is completed), or multiple threads within it can execute the first and second transactions in parallel. However, regardless of the execution method, for the first block and the second block, the two blocks are still executed in parallel.
[0056] In one embodiment, as described above, the first transaction is divided into M transaction groups, and the number of first computing processes is denoted as N. When N≥M, in order to speed up the overall execution speed of all first transactions, i.e., improve the overall execution efficiency of the M transaction groups, the M transaction groups can be sent to different computing processes respectively. Each computing process receives at most one transaction group. At this time, the computing process that receives the transaction group can execute each first transaction in that transaction group, while the computing processes that receive different transaction groups can execute the first transactions in different transaction groups in parallel, thereby realizing the parallel execution of all first transactions at the M transaction group level.
[0057] When N < M, at least one computing process will receive multiple transaction groups, and the scheduling of the M transaction groups will affect the overall execution efficiency of all first transactions. As mentioned above, each first transaction has its own first pre-execution information. In addition to the aforementioned first pre-execution read-write set, the first pre-execution information of any first transaction further includes an execution time consumption index for characterizing the time length required to execute the first transaction, wherein the index can be the pre-execution time consumption of the any first transaction (that is, the time length actually consumed for pre-executing the transaction); alternatively, considering that the execution time consumption of a transaction is usually positively correlated with its handling fee (such as Gas), the index can also be the handling fee of the any first transaction. It can be understood that the time length required to execute the any first transaction is positively correlated with the pre-execution time consumption or the handling fee. Based on this, the control process can further determine the expected group time consumption index of the plurality of transaction groups according to the execution time consumption indexes of the first transactions respectively included in the M transaction groups, and the expected group time consumption index of any transaction group is used for characterizing the total time length required for executing all first transactions in the transaction group. It can be understood that, when any transaction group only includes one first transaction, the execution time consumption index of the first transaction can be used as the expected group time consumption index of the transaction group; when any transaction group includes a plurality of first transactions, the expected group time consumption index of the transaction group can be determined according to the dependency relationship among these first transactions and the execution time consumption indexes of the respective first transactions.
[0058] Further, when the control process sends the M transaction groups to corresponding first computing processes among the plurality of computing processes respectively, the M transaction groups can be distributed to the N first computing processes according to the expected group time consumption indexes, so that the expected task time consumption indexes of the N first computing processes tend to be consistent, wherein the transaction groups received by respective first computing processes are different from each other, and the expected task time consumption index of any first computing process is the total time length required for the first computing process to execute all first transactions in the transaction groups received by itself. It can be understood that the expected task time consumption indexes of the N first computing processes (that is, the time length required for the computing processes to execute all transactions in all transaction groups received by themselves) tend to be consistent, which ensures that the N first computing processes complete their respective received transactions at the same time as much as possible, or the time points when they complete their respective received transactions are as close as possible, avoiding that some first computing processes consume a long time waiting for other first computing processes to complete execution.
[0059] Step 306: the first computing process executes the received first transactions.
[0060] In one embodiment, the first block may contain multiple first transactions. When the first computing process executes a received first transaction, it can execute the at least two first transactions in parallel through multiple threads if at least two first transactions have been received. This approach is applicable to any first computing process, and the multiple threads can run within that first computing process, acquiring and executing corresponding first transactions through thread scheduling and task contention.
[0061] It is understandable that the existence of a second block in the execution phase indicates that the first node is currently executing transactions within that second block. Combined with the fact that the first transaction is sent to the first computation process for execution in response to the first transaction not depending on the second transaction in the second block, it is clear that the first node can execute both the first and second transactions simultaneously, provided the first transaction does not depend on the second transaction. In other words, if the first transaction in the first block does not depend on the second transaction in the second block, the first node can execute the first transaction in the first block and the second transaction in the second block in parallel. Compared to related technical solutions that execute different blocks sequentially, the first node in this solution can execute multiple blocks in parallel, significantly accelerating the overall block execution speed and contributing to improved block execution and subsequent processing efficiency.
[0062] like Figure 4 As shown, at time Tn+1, multiple transactions in block N+2 (i.e., the first transactions) have completed N+1 analysis (i.e., grouping). At this time, the corresponding computation process (i.e., the second computation process) has not yet completed executing all the transactions in block N. However, since the first transactions do not depend on the unexecuted transactions in block N, the control process can schedule the first transaction to the corresponding first computation process for execution. That is, the execution pipeline can begin processing the execution operations of each transaction in the first block. Similarly, at time Tn+2, the transactions in block N+1 have not yet been fully executed. Under the aforementioned conditions, the execution of the transactions in block N+2 can also begin at this time. In this way, the transactions in blocks N and N+1 can be executed in parallel for a period of time starting at time Tn+1, and the transactions in blocks N+1 and N+2 can be executed in parallel for a period of time starting at time Tn+2, thereby helping to improve the overall execution efficiency of the above blocks.
[0063] This concludes the explanation of the parallel execution process of the first transactions in the first block that do not depend on the second transaction. In addition, the first node can also successfully execute the first transactions that depend on the second transaction. It should be noted that because the first transaction depends on the second transaction, to ensure that the execution result of the first transaction is accurate, effective, and conforms to the parameter state corresponding to the block height, the first transaction must be executed only after the second transaction it depends on has been completed. For example, the control process can, in response to the first transaction depending on the second transaction in the second block, send the execution result of the second transaction and the first transaction to the third computing process among the multiple computing processes for execution, after determining that the second transaction has been completed. In this method, the second computing process can return its execution result to the control process after executing the second transaction, and the control process can then send the execution result and the second transaction (as a computing task) together to the corresponding third process. As another example, the control process can also, in response to the first transaction depending on the second transaction in the second block, send the first transaction to the third computing process among the multiple computing processes, and trigger the third computing process to execute the first transaction based on the execution result of the second transaction after the second transaction has been completed. In this approach, if the third process is the same as the second computational process executing the second transaction, then that process can directly use the execution result obtained from executing the second transaction to execute the received first transaction. If the third process is not the same as the second computational process executing the second transaction, then the control process can send the computation result of the second transaction returned by the second computational process to the third process; or it can instruct the second computational process to send the execution result of the second transaction to the third process via inter-process communication. It should also be noted that for the first transaction that does not depend on the second transaction, since the second transaction has already been completed when this part of the first transaction is executed, the computational process used to execute this part of the first transaction can be the second computational process executing the second transaction, or it can be the first computational process executing the first transaction, or any computational process other than the first and second computational processes; in other words, the computational process used to execute the first transaction that does not depend on the second transaction can be any computational process in the first node.
[0064] In one embodiment, for any block in the first block and the second block, the control process can submit the block based on the execution results of each transaction in the block, provided that all transactions in the block have been executed and the preceding block has been committed. In this way, the execution and submission process for the block can be completed, and the corresponding transactions and execution results can be persistently recorded in the storage space of the blockchain node.
[0065] Figure 5 This is a schematic diagram of the structure of the first node in a blockchain system, provided as an exemplary embodiment. For example... Figure 5 As shown, the first node includes a control process 52 and multiple computing processes 54, wherein,
[0066] The control process 52 is used to obtain the first transaction to be executed in the first block; and, in the case that it is determined that there is a second block in the execution stage, in response to the first transaction not depending on the second transaction in the second block, to send the first transaction to the first computing process 54 among the plurality of computing processes 54.
[0067] The first computing process 54 is used to execute the received first transaction.
[0068] Optionally, the first transaction does not depend on the second transaction in the second block, including:
[0069] The first transaction does not depend on all the second transactions in the second block; or...
[0070] The first transaction does not depend on the second transaction that has not yet been completed in the second block at the current time.
[0071] Optional,
[0072] It also includes: the control process 52 determining the first pre-execution read set and the first pre-execution write set of the first transaction from the first pre-execution information of the first transaction; and determining the second pre-execution read set and the second pre-execution write set of the second transaction from the second pre-execution information of the second transaction;
[0073] The control process 52 determines that the first transaction does not depend on the second transaction, including: determining that the first transaction does not depend on the second transaction when there is no intersection between the second pre-execution write set and both the first pre-execution write set and the first pre-execution read set.
[0074] Optionally, the first block may contain multiple first transactions.
[0075] The control process 52 obtains the first transaction to be executed in the first block, including: obtaining M transaction groups, wherein the M transaction groups are obtained by grouping the multiple first transactions based on the first pre-execution information of each of the multiple first transactions; or, the method further includes: the control process 52 groups the multiple first transactions according to the first pre-execution information of each of the multiple first transactions to obtain M transaction groups; wherein, M>1, and the first transactions in each transaction group are different;
[0076] In response to that the first transaction does not depend on the second transaction in the second block, the control process 52 sends the first transaction to a first computing process 54 among the plurality of computing processes 54, which comprises: in response to that each transaction in the M transaction groups does not depend on the second transaction in the second block, sending the M transaction groups respectively to corresponding first computing processes 54 among the plurality of computing processes 54.
[0077] Optionally, the number N of the first computing processes 54 is less than M, and first pre-execution information of any first transaction includes an execution time consumption index used for characterizing the time length required for executing the first transaction,
[0078] The method further comprises: the control process 52 determines group expected time consumption indexes of the plurality of transaction groups according to execution time consumption indexes of respective first transactions comprised in the M transaction groups respectively, wherein the group expected time consumption index of any transaction group is used for characterizing the total time length required for executing all first transactions in the transaction group;
[0079] The step that the control process 52 sends the M transaction groups respectively to corresponding first computing processes 54 among the plurality of computing processes 54 comprises: distributing the M transaction groups to the N first computing processes 54 according to the group expected time consumption indexes, so that task expected time consumption indexes of the N first computing processes 54 tend to be consistent, wherein the transaction groups received by respective first computing processes 54 are different from each other, and the task expected time consumption index of any first computing process 54 is the total time length required for the first computing process 54 to execute all first transactions in the transaction groups received thereby.
[0080] Optionally, under the condition that a first node is not a master node in the blockchain system, the step that the control process 52 acquires first pre-execution information of each of the plurality of first transactions comprises:
[0081] acquiring first pre-execution information of each of the plurality of first transactions from the master node, wherein the first pre-execution information is obtained by the master node pre-executing the plurality of first transactions.
[0082] Optionally, the first block comprises a plurality of first transactions, and the step that the first computing process 54 executes received first transactions comprises:
[0083] when at least two first transactions are received, the first computing process 54 executes the at least two first transactions in parallel through a plurality of threads.
[0084] Optionally, the method further comprises:
[0085] In response to the first transaction depending on a second transaction in the second block, if the control process 52 determines that the second transaction has been completed, it sends the execution result of the second transaction and the first transaction to the third computing process 54 among the plurality of computing processes 54 for execution; or,
[0086] In response to the first transaction depending on the second transaction in the second block, the control process 52 sends the first transaction to the third computing process 54 among the plurality of computing processes 54, and triggers the third computing process 54 to execute the first transaction based on the execution result of the second transaction after the second transaction has been completed.
[0087] Optional, also includes:
[0088] For any one of the first block and the second block, if all transactions in the first block have been executed and the previous block of the first block has been committed, the control process 52 shall commit the first block based on the execution results of the transactions in the first block.
[0089] The specific implementation of the transaction execution process of the first node can be found in the description of the foregoing embodiments, and will not be repeated here.
[0090] Based on the same concept as the foregoing method embodiments, this specification also provides a blockchain system, which includes a first node and a second node. The first node includes a control process and multiple computing processes, wherein:
[0091] The second node is used to send the first transaction to be executed in the first block to the first node;
[0092] The first node is used to send the first transaction to the first computing process among the plurality of computing processes for execution, in response to the fact that the first transaction does not depend on the second transaction in the second block, if it is determined that there is a second block in the execution phase.
[0093] Figure 6 This is a schematic diagram of the structure of a device provided in an exemplary embodiment. Please refer to... Figure 6At the hardware level, the device includes a processor 602, an internal bus 604, a network interface 606, memory 608, and non-volatile memory 610, and may also include other hardware required for services. One or more embodiments of this specification can be implemented in software, such as the processor 602 reading the corresponding computer program from the non-volatile memory 610 into memory 608 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0094] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0095] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0096] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this invention does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0097] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0098] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0099] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0100] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0101] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0102] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0103] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0104] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0105] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0106] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage devices.
[0107] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0108] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of this specification. Various modifications and variations can be made to the one or more embodiments of this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A transaction execution method, applied to a first node in a blockchain system, wherein the first node comprises a control process and a plurality of computing processes, the method comprises: The control process acquires a first transaction to be executed in a first block; The control process detects whether there is a second block in an execution stage; In a case where a second block in the execution stage is detected, the control process determines a first pre-execution read set and a first pre-execution write set of the first transaction from first pre-execution information of the first transaction, and determines a second pre-execution read set and a second pre-execution write set of a second transaction from second pre-execution information of the second transaction that has not been executed completely at the current moment; If there is no intersection between the second pre-execution write set and both the first pre-execution write set and the first pre-execution read set, sending the first transaction to a first computing process among the plurality of computing processes, so that the first node starts executing the first transaction when all the second transactions in the second block have not been executed completely; The first computing process executes the received first transaction.
2. The method according to claim 1, wherein the first block comprises a plurality of first transactions, The control process acquires a first transaction to be executed in the first block, including: M transaction groups are acquired, wherein the M transaction groups are obtained by grouping the plurality of first transactions based on the first pre-execution information of each of the plurality of first transactions; Or, the method further comprises: grouping, by the control process, the plurality of first transactions based on the first pre-execution information of each of the plurality of first transactions to obtain M transaction groups; wherein M>1, and the first transactions in each transaction group are different from each other; In response to the first transaction not depending on the second transaction in the second block, the control process sending the first transaction to the first computing process among the plurality of computing processes comprises: in response to each transaction in the M transaction groups not depending on the second transaction in the second block, sending the M transaction groups respectively to corresponding first computing processes among the plurality of computing processes.
3. The method according to claim 2, wherein the number N of first computing processes is less than M, and the first pre-execution information of any first transaction comprises an execution time consumption indicator used for characterizing the time length required for executing the first transaction, The method further comprises: the control process determines, according to the execution time consumption indicators of the respective first transactions included in the M transaction groups, expected grouping time consumption indicators of the plurality of transaction groups, wherein the expected grouping time consumption indicator of any transaction group is used for characterizing the total time length required for executing all the first transactions in the transaction group; sending, by the control process, the M transaction groups respectively to corresponding first computing processes among the plurality of computing processes comprises: distributing the M transaction groups to the N first computing processes according to the expected grouping time consumption indicators, so that expected task time consumption indicators of the N first computing processes tend to be consistent, wherein the transaction groups received by the respective first computing processes are different from each other, and the expected task time consumption indicator of any first computing process is the total time length required for the first computing process to execute all the first transactions in the transaction group received by the first computing process.
4. The method according to claim 2, wherein when the first node is not the master node in the blockchain system, the control process obtains the first pre-execution information for each of the plurality of first transactions, including: The master node obtains the first pre-execution information for each of the multiple first transactions. The first pre-execution information is obtained by the master node pre-executing the multiple first transactions.
5. The method according to claim 1, wherein the first block contains multiple first transactions, and the first computing process executes the received first transactions, comprising: Upon receiving at least two first transactions, the first computing process executes the at least two first transactions in parallel using multiple threads.
6. The method according to claim 1, further comprising: In response to the first transaction depending on a second transaction in the second block, the control process, upon determining that the second transaction has been completed, sends the execution result of the second transaction and the first transaction to a third computing process among the plurality of computing processes for execution; or, In response to the first transaction depending on the second transaction in the second block, the control process sends the first transaction to the third computing process among the plurality of computing processes, and triggers the third computing process to execute the first transaction based on the execution result of the second transaction after the second transaction has been completed.
7. The method according to claim 1, further comprising: For either the first block or the second block, if all transactions in that block have been executed and the preceding block of that block has been committed, the control process commits that block based on the execution results of all transactions in that block.
8. A first node in a blockchain system, the first node comprising a control process and multiple computation processes, wherein, The control process is used to obtain the first transaction to be executed in the first block, detect whether there is a second block in the execution stage; and, if a second block in the execution stage is detected, determine the first pre-execution read set and the first pre-execution write set of the first transaction from the first pre-execution information of the first transaction, and determine the second pre-execution read set and the second pre-execution write set of the second transaction from the second pre-execution information of the second transaction that has not been completed at the current time. If the second pre-execution write set has no intersection with either the first pre-execution write set or the first pre-execution read set, then the first transaction is sent to the first computing process among the multiple computing processes, so that the first node can start executing the first transaction even if the second transaction in the second block has not been fully executed. The first computing process is used to execute the first received transaction.
9. A blockchain system, comprising a first node and a second node, wherein the first node includes a control process and multiple computing processes, wherein: The second node is used to send the first transaction to be executed in the first block to the first node; The first node is used to detect whether there is a second block in the execution phase; and, if a second block in the execution phase is detected, to determine the first pre-execution read set and the first pre-execution write set of the first transaction from the first pre-execution information of the first transaction, and to determine the second pre-execution read set and the second pre-execution write set of the second transaction from the second pre-execution information of the second transaction that has not been completed at the current time. If the second pre-execution write set has no intersection with either the first pre-execution write set or the first pre-execution read set, then the first transaction is sent to the first computing process among the plurality of computing processes for execution.
10. An electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1-7 by executing the executable instructions.
11. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-7.
Citation Information
Patent Citations
Block chain transaction execution method, block chain node and control device
CN113064730A
Block chain transaction stepless prediction execution method and system
CN114416765A