Disclosure of Invention
The embodiment of the specification aims to provide a transaction execution scheme, which reduces transaction execution time and improves system efficiency of blockchain nodes.
A first aspect of the present description provides a transaction execution method performed by a block link point, the block link point comprising a host and a first computing device, the method comprising:
The method comprises the steps that a host sends partial transactions in a first block to first computing equipment, wherein the partial transactions comprise first transactions, the first transactions comprise reading operations on first variables, the host comprises first storage spaces, the first storage spaces are used for storing a plurality of pieces of first information of the first block in the execution process of the first block, the plurality of pieces of first information respectively indicate the current states of the plurality of variables accessed in the execution process, and the first computing equipment comprises second storage spaces;
The first computing device reads the first state of the first variable from the second storage space and obtains an execution result of the first transaction according to the first state at least in the case that the first state of the first variable is stored in the second storage space after the first transaction starts to be executed;
The host computer submits the first transaction under the condition that the first state is determined to be the current state of the first variable according to the first information and the second information after sequentially submitting the transactions, the submitting sequence of which is before the first transaction, in the first block.
In one embodiment, the method further comprises the host notifying the first computing device to re-execute the first transaction if the first state is determined not to be the current state of the first variable based on the first information and the second information after sequentially submitting transactions in the first block that are in sequence before the first transaction.
In one implementation, the method further comprises the steps that before the first transaction is executed, the first computing device sends a reading request of the first variable corresponding to a second transaction to the host, the host responds to the reading request of the first computing device and sends the current first state of the first variable and identification of a third transaction to the first computing device, the third transaction is a transaction written in the first state, and the first computing device records first state information of the first variable in the second storage space, wherein the first state information comprises the first state and the identification of the third transaction, and the second information is the identification of the third transaction.
In one embodiment, the method further includes, after the host computer sends the first state of the first variable and the identification of the third transaction to the first computing device, recording first execution information corresponding to the first variable and the first computing device in the first storage space, where the first execution information includes the second transaction and the third transaction, and indicates that the state written by the third transaction is read in execution of the second transaction.
In one embodiment, the method further includes, after receiving the execution result and the second information, the host recording second execution information corresponding to the first variable and the first computing device in the first storage space, the second execution information including the first transaction and the third transaction.
In one embodiment, the first information of the first variable is an identification of a transaction written into a current state of the first variable, and determining that the first state is the current state of the first variable according to the first information and the second information includes determining that the first state is the current state of the first variable if the first information of the first variable is the identification of the third transaction.
In one embodiment, the method further comprises the host sending a commit order of the partial transactions to the first computing device;
The reading the first state of the first variable at least in the case where the first state of the first variable is determined to be stored in the second storage space includes reading the first state in the case where the first state information of the first variable is determined to be stored in the second storage space and the order of commit of the third transaction is prior to the first transaction.
In one embodiment, the method further comprises the first computing device re-executing the first transaction after storing the first state information in the second storage space, in the event that it is determined that information is stored in the second storage space that the first transaction read the state of the first variable written by the fourth transaction.
In one embodiment, the method further includes, when the first computing device determines that the read information of the first variable by the first transaction is not stored in the second storage space, recording, in the second storage space, information that the first transaction has read the state of the first variable written by the third transaction, and after obtaining the execution result of the first transaction, the first computing device obtaining the second information from the second storage space.
In one embodiment, the first transaction further includes a write operation to a second variable, and the method further includes the first computing device recording second state information of the second variable in the second storage space after performing the write operation, where the second state information includes an identification of the first transaction and a second state of the second variable written by the first transaction.
In one embodiment, the method further comprises the host, after submitting the first transaction, recording a current state of the second variable as the second state and recording the first transaction as a transaction writing the second state of the second variable.
In one embodiment, third execution information corresponding to a second variable and a second computing device is stored in the first storage space, the third execution information includes a fifth transaction and a sixth transaction, the third execution information indicates that a state of the second variable written by the sixth transaction is read in execution of the fifth transaction, a commit order of the fifth transaction is after the first transaction, and a commit order of the sixth transaction is before the first transaction, and the method further includes the host notifying the second computing device to re-execute the fifth transaction according to the third execution information after receiving the execution result, after the first transaction is submitted, or before the fifth transaction is submitted.
In one embodiment, the first computing device is one computing unit included in an FPGA chip.
A second aspect of the present specification provides a transaction execution method, the method being performed by a computing device comprised by a blockchain node, the blockchain node further comprising a host, the method comprising:
Receiving a partial transaction in a first block from a host, wherein the partial transaction comprises a first transaction comprising a read operation of a first variable;
after starting to execute the first transaction, at least in the case of determining that the first state of the first variable is stored in the storage space of the computing device, reading the first state of the first variable from the storage space, and obtaining an execution result of the first transaction according to the first state;
And sending the execution result and second information to the host, wherein the second information indicates that the first state is read in the execution of the first transaction.
In one embodiment, the method further comprises, before executing the first transaction, sending a read request of the first variable corresponding to a second transaction to the host, receiving, from the host, a current first state of the first variable and an identification of a third transaction, the third transaction being a transaction written in the first state, and recording, in the storage space, first state information of the first variable, the first state information including an identification of the first state and the third transaction, wherein the second information is the identification of the third transaction.
In one embodiment, the method further comprises receiving a commit order for the partial transactions from a host, the reading the first state of the first variable at least in the case where the first state of the first variable is determined to be stored in the storage space includes reading the first state in the case where the first state information of the first variable is determined to be stored in the storage space and the commit order for the third transaction is prior to the first transaction.
In one embodiment, the method further comprises re-executing the first transaction after storing the first state information of the first variable in the memory space, in the event that it is determined that information is stored in the memory space in which the first transaction reads the state value of the first variable written by the fourth transaction.
In one embodiment, the method further includes, in a case where it is determined that the read information of the first variable by the first transaction is not stored in the storage space, recording, in the storage space, information that the first transaction reads the state value of the first variable written by the third transaction, and after obtaining the execution result of the first transaction, obtaining the second information from the storage space.
In one embodiment, the first transaction further includes a write operation to a second variable, and the method further includes recording second state information of the second variable in the memory space after performing the write operation, where the second state information includes an identification of the first transaction and a second state of the second variable written by the first transaction.
A third aspect of the present specification provides a transaction execution method performed by a host included in a blockchain node, the blockchain node further including a computing device therein, the method comprising:
Transmitting part of transactions in a first block to the computing device, wherein the part of transactions comprise first transactions, the first transactions comprise reading operations on first variables, the host comprises first storage spaces, the first storage spaces are used for storing a plurality of pieces of first information of the first block in the process of executing the first block, the plurality of pieces of first information respectively indicate the current states of the plurality of variables accessed in the process of executing, and the computing device comprises second storage spaces;
Receiving, from the computing device, a result of execution of the first transaction and second information indicating a first state in which a first variable stored in the second storage space was read in the execution of the first transaction;
After sequentially submitting the transactions of the first block, which are sequentially submitted before the first transaction, the first transaction is submitted under the condition that the first state is determined to be the current state of the first variable according to the first information and the second information.
A fourth aspect of the present description provides a blockchain node, comprising a host and a computing device,
The host is configured to send partial transactions in a first block to the computing device and receive execution results of the transactions from the computing device, and comprises a first storage space, wherein the first storage space is used for storing a plurality of pieces of first information of the first block in the execution process of the first block, and the plurality of pieces of first information respectively indicate the current states of a plurality of variables accessed in the execution process;
The computing device is configured to receive the partial transaction from the host, execute the partial transaction, and send execution results of the transaction and second information to the host, wherein the computing device comprises a second storage space for storing states of variables accessed during execution of the partial transaction, and the second information indicates states of variables read during the execution.
In one embodiment, the first information is an identifier of a transaction written in the current state, the second storage space is further used for storing an identifier of a second transaction corresponding to a first state of the first variable read by a first transaction in the partial transaction, the second transaction is a transaction written in the first state, the second information is an identifier of the second transaction,
The host is further configured to determine whether the first transaction was executed successfully based on the identification of the second transaction and the first information of the first variable.
In one embodiment, the host is further configured to record, after receiving the execution result and the second information, execution information corresponding to the first variable and the first computing device in the first storage space, the execution information including the first transaction and the second transaction, indicating a status in which the second transaction write was read in execution of the first transaction.
A fifth aspect of the present specification provides a computing device for a blockchain node, the blockchain node further including a host, the computing device comprising:
a receiving unit, configured to receive a partial transaction in a first block from a host, where the partial transaction includes a first transaction, and the first transaction includes a read operation on a first variable;
A reading unit, configured to, after starting execution of the first transaction, at least in a case where a first state of the first variable is determined to be stored in a storage space, read the first state of the first variable from the storage space, and obtain an execution result of the first transaction according to the first state;
and the sending unit is used for sending the execution result and second information to the host, wherein the second information indicates that the first state is read in the execution of the first transaction.
A sixth aspect of the present specification provides a host for a blockchain node, the blockchain node further including a computing device therein, the host comprising:
A sending unit, configured to send a part of transactions in a first block to the computing device, where the part of transactions includes a first transaction, the first transaction includes a read operation on a first variable, the host includes a first storage space, the first storage space is used to store, during execution of the first block, a plurality of first information of the first block, where the plurality of first information indicates current states of a plurality of variables accessed during the execution, and the computing device includes a second storage space;
A receiving unit configured to receive, from the computing device, an execution result of the first transaction and second information indicating that a first state of a first variable stored in the second storage space is read in execution of the first transaction;
And the submitting unit is used for submitting the first transaction under the condition that the first state is determined to be the current state of the first variable according to the global execution information after sequentially submitting the transactions, the submitting sequence of which is before the first transaction, in the first block.
A seventh aspect of the present specification provides a computing device comprising a memory having executable code stored therein and a processor which when executing the executable code implements the method of the second or third aspects of the present specification.
An eighth aspect of the present description provides a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of the second or fourth aspect of the present description.
According to the transaction execution scheme provided by the embodiment of the specification, states of variables accessed in the transaction execution process are respectively cached in a plurality of computing devices which do not share a memory in a blockchain node, and for the variables frequently read only, the state values of the variables cached in the computing devices are correct state values, so that the computing devices can directly read the correct state values of the variables from a local memory without passing through a host, the communication time with the host is shortened, the transaction execution time is shortened, and the system performance is improved.
Detailed Description
Embodiments of the present specification will be described below with reference to the accompanying drawings.
FIG. 1 illustrates an architecture diagram of a blockchain node provided by embodiments of the present description. As shown in FIG. 1, a blockchain node includes a host 100, a computing device 210, and a computing device 220 therein. The host 100 includes a processor 101 and a memory 102, where the memory 102 may store global information of the computing device 210 and the computing device 220 during the execution of the block. The host 100 may be configured to receive transactions from clients or other block link points, determine a plurality of transactions in a block and a commit order for the plurality of transactions by consensus, send the plurality of transactions in the block to the computing device 210 and the computing device 220, coordinate parallel execution of the transactions by the computing device 210 and the computing device 220, and perform operations of generating the block, updating world state, etc. after the execution of the transactions is completed.
Computing device 210 and computing device 220 are used to execute transactions in parallel. Computing device 210 and computing device 220 may be two spatially separated devices, for example, they may be two computers in communication with a host, or may be two computing chips plugged onto a host, or the like. Or computing device 210 and computing device 220 may be two sub-devices included in one overall device, e.g., two sub-devices (e.g., computing units) in one FPGA chip plugged onto a host. The computing device 210 includes a processor 211 and a memory 212, the memory 212 is used for storing state information of variables acquired during the execution of the transaction by the processor 211, the computing device 220 includes a processor 221 and a memory 222, and the memory 222 is used for storing state information of variables acquired during the execution of the transaction by the processor 221. Computing device 210 and computing device 220, whether spatially separated or integrated into one device, have respective memory spaces and memory 212 is separate from memory 222, i.e., computing device 210 and computing device 220 do not share memory.
It will be appreciated that while only two computing devices are shown in fig. 1 as examples, this is not intended to limit the scope of the embodiments of the present description. In one embodiment, a blockchain node may include only a host 100 and one computing device, such as a computer in communication with the host, or may be a computing chip or the like mounted to the host, and transactions performed in parallel by the host and the computing device. In another implementation, a blockchain node may include a host 100 and more than two (e.g., 3) computing devices that may execute multiple transactions in a block in parallel. In addition, although the host 100 is shown in fig. 1 as storing global information through the memory 102, the computing devices 210 and 220 store status information through respective memories, and the embodiment of the present specification is not limited thereto, and other storage media may be used for storing information.
In the related art, the computing device 210 and the computing device 220 do not store state information in their respective memories when executing a plurality of transactions in one block in parallel. This is because both computing device 210 and computing device 220 are executing transactions in parallel, which may change the state of the same variable. The computing device 210 and the computing device 220 are not in communication with each other, e.g., the computing device 210 is not aware of status information in the computing device 220 during execution of the transaction. Thus, even if the computing device 210 stores status information obtained during the local execution of a transaction, the status information may be incorrect for a particular transaction, and executing the transaction based on the status information may result in a transaction execution failure. It is common practice that, each time a transaction is executed, the computing device 210 obtains status information from the host 100 when it is required to read the status information, and executes the transaction based on the obtained status information. After executing the completed transaction, the computing device 210 sends the execution result of the transaction to the host, and the host 100 determines whether the transaction was executed successfully based on the cache information, and in the event of successful execution, submits the transaction.
In the related art, since the data cache is not enabled in the computing device, all data access requests must be sent to the host 100, which increases the number of communications between the computing device and the host, reduces the transaction execution speed, and limits the system performance.
The embodiment of the specification provides a transaction execution scheme, wherein a computing device stores state information of variables in a local memory, the computing device directly executes a transaction based on the locally cached state information when executing the transaction, and sends an execution result of the transaction and the read state information to a host, and the host side determines whether the transaction is successfully executed or not through the stored global information, so that the transaction execution speed is improved especially in a scene that the read variables in the transaction are mostly read-only variables.
Fig. 2 is a flowchart of a transaction execution method according to an embodiment of the present disclosure. The computing device shown in fig. 2 may be the computing device 210 or the computing device 220 in fig. 1, and the computing device 210 is described below as an example. The method flow shown in fig. 2 is a flow in the case where a read operation on a variable is included in a transaction performed by a computing device. The respective steps shown in fig. 2 will be described in detail below.
First, in step S201, the host 100 transmits a partial transaction of block B1 to the computing device 210.
The host 100 determines a plurality of transactions included in a block to be executed (e.g., block B1) and a commit order of the plurality of transactions by consensus with hosts of other nodes in the blockchain. After determining the plurality of transactions in block B1, the host 100 may divide the plurality of transactions into two sets of transactions and transmit the two sets of transactions to the computing device 210 and the computing device 220, respectively, such that the computing device 210 and the computing device 220 may execute the two sets of transactions in parallel. Specifically, the host 100 may randomly divide the plurality of transactions into two sets of transactions, or may divide the plurality of transactions into two sets of transactions according to a preset rule. For example, the host 100 sends to a group of transactions in the computing device 210 including odd-numbered transactions such as transaction Tx1, transaction Tx3, transaction Tx5, transaction Tx7, etc., and the host 100 sends to a group of transactions in the computing device 220 including even-numbered transactions such as transaction Tx2, transaction Tx4, transaction Tx6, transaction Tx8, etc.
In step S203, the computing device 210 determines whether the variable Key1 to be read in the transaction Txi (described below as Tx1 and Tx3, respectively) is hit in the buffer.
The computing device 210, upon receiving, for example, transaction Tx1, transaction Tx3, transaction Tx5, and transaction Tx7, may execute the 4 transactions in parallel, or may execute the 4 transactions in series.
Fig. 3 illustrates an architectural diagram of buffers in memory 212 of computing device 210. As shown in fig. 3, the memory 212 may include a buffer 1, a buffer 2, and a buffer 3. Wherein buffer 1 is used to store state values of various variables to provide the state values of the variables when computing device 210 performs transactions. Wherein the computing device 210 stores the state value of the variable in the buffer 1 after obtaining the state value of the variable from the host during execution of the transaction or in the case of writing the state value of the variable during execution of the transaction. Buffer 2 is, for example, a private buffer corresponding to transaction Tx3, and computing device 210 establishes buffer 2 after reading state value V0 of variable Key1, for example, during execution of transaction Tx3, and stores state information of variable Key1 read by transaction Tx3 in buffer 2. Buffer 3, for example, is a private buffer corresponding to transaction Tx5, and may be established similarly to buffer 2. It will be appreciated that other buffers corresponding to other transactions may also be included in memory 212, not shown in FIG. 3.
Specifically, "Tx-1, V0" is included in the information of the variable Key1 in the buffer 1, and the state value V0 indicating Key1 is a state value corresponding to the previous block of the block B1. Also included in the information of variable Key1 in buffer 1 are "Tx3, V13", which indicates that state value V13 of Key1 is written when transaction Tx3 is performed. That is, tx-1 and Tx3 recorded in the buffer 1 are used to indicate transaction numbers to which the state value of the variable Key1 is written. The buffer 2 includes "Key1, tx-1", which indicates that the state value of the variable Key1 corresponding to transaction Tx-1 was read when transaction Tx3 was executed.
It will be appreciated that the specific content of each buffer shown in fig. 3 is merely exemplary and is not intended to limit the scope of the embodiments of the present description. In the case where the computing device 210 executes a plurality of transactions in parallel, reading of the state value corresponding to the current transaction is facilitated when a read operation in the transaction is performed by recording the number of the write transaction corresponding to each state value of the variable in the buffer 1. When the computing device 210 serially executes a plurality of transactions in order of transaction numbers from small to large, for example, serially executes the transactions Tx1, tx3, tx5, and Tx7, only the latest state value of the variable may be recorded in the buffer 1, so that the latest state value may be read for continuing to execute the current transaction when a read operation in the transaction is executed. The buffer 2 is not limited to recording the transaction number corresponding to the variable value read in the transaction Tx3, and may record other information for specifying the variable value, for example, version number information of the state value V0 of the recordable variable in the buffer 2. By storing information indicating the status of the variable read during execution of the transaction in a private buffer of the transaction (e.g., buffer 2 corresponding to transaction Tx 3), the computing device, upon completion of the transaction and transmission of the execution result to the host, may read the information from the private buffer and transmit the information to the host along with the execution result so that the host may determine whether the transaction needs to be re-executed based on the information (this portion will be described in detail in later steps). In addition, the computing device may also determine whether the transaction needs to be re-executed based on information in the private buffer of the transaction (this portion of the content will be described in detail below).
Assume that computing device 210 first performs transaction Tx1, with a read operation to variable Key1 included in transaction Tx 1. After performing this read operation into transaction Tx1, computing device 210 first determines whether variable Key1 can be hit in buffer 1 in memory, i.e., determines whether state information for Key1 is stored in buffer 1.
In the case where it is determined that the state information of Key1 is not stored in the buffer 1, the computing device 210 executes step S205, and transmits a state read request to the host 100 for reading the current state (i.e., the latest state) of the variable Key 1.
In step S207, the host 100 reads the current state of the variable Key1 in response to the read request of the computing device 210.
A global buffer corresponding to the execution block B1 is provided in the memory 102 of the host 100. Fig. 4 shows a schematic diagram of a global buffer. In one embodiment, the global buffer may store the current state of each variable (not shown in FIG. 4). Specifically, after reading the state of an arbitrary variable from the state database in response to a read request by any one of the computing devices in executing the block B, the host 100 may store the read state as the current state of the variable in association with the variable in the global buffer, or upon determining that the transaction written with the arbitrary variable in the block B1 is successfully executed and submitting the transaction, the host may store the state of the variable written with the transaction as the current state of the variable in association with the variable in the global buffer. Taking the variable Key1 as an example, after receiving a read request for the variable Key1 sent by the computing device 210 when executing the transaction Tx1, the host 100 first determines whether the variable Key1 is hit in the global buffer, and if not hit, it indicates that the variable Key1 is not accessed by the transaction currently, so the host 100 reads the state value V0 of the variable Key1 (i.e., the current state of the variable Key 1) from the state database, and stores the current state V0 of the variable Key1 in the global buffer.
In another embodiment, as shown in fig. 4, in addition to the current state of the variable, a transaction number corresponding to the current state, that is, a number of a transaction written into the current state, may be stored in the global buffer. For example, the current state of the read variable Key1 is the state V0 of the variable Key1 corresponding to the previous block of the block B1, and thus the transaction number corresponding to the state V0 may be recorded as Tx-1.
In another embodiment, as shown in FIG. 4, the global buffer may store state information for a variable read by a transaction performed by computing device 210 and computing device 220, respectively, to read the variable, in addition to the current state of the variable and an identification of the associated transaction. In this embodiment, after reading the state V0 of the variable Key1 from the state database in response to the above-described read request, the host 100 may perform step S209 of adding the record "Tx1, tx-1" associated with the variable Key1 and the computing device 210 in the global buffer, for indicating that the state value (i.e., V0) of the variable Key1 corresponding to the transaction Tx-1 was read during the execution of the transaction Tx 1. By recording this information, it may be determined from this information whether the transaction needs to be re-executed before submitting the transaction.
In step S211, the host 100 returns the current state V0 of the variable Key1 to the computing device 210.
In one implementation, host 100 may return state V0 only to computing device 210.
In another implementation, the host 100 may return the state V0 and the corresponding transaction number Tx-1 to the computing device 210.
In step S213, the computing device 210 updates buffer 1 and the private buffer corresponding to transaction Tx1.
In one implementation, computing device 210 may store a state value "V0" in association with variable Key1 only in buffer 1 to indicate the current state of variable Key 1.
In another implementation, as shown in FIG. 3, computing device 210 may store "Tx-1, V0" in buffer 1 in association with a variable Key. The computing device 210 may also store "Key1, tx-1" (not shown in fig. 3) in a private buffer corresponding to transaction Tx 1.
In step S215, the computing device 210 continues to execute the transaction Tx1 based on the state V0, resulting in an execution result of the transaction Tx 1. The computing device 210 may generate a read set and a write set during execution of the transaction Tx1, wherein the read set includes state values of the respective variables read during execution of the transaction and the write set includes state values of the respective variables written during execution of the transaction. The execution result includes, for example, a write set generated during execution of the transaction Tx 1.
In step S217, the computing device 210 transmits the execution result of the transaction Tx1 and information indicating the status read by the transaction Tx1 to the host 100.
In one embodiment, the computing device 210 may obtain the state value V0 of the variable Key1 read during execution of the transaction Tx1 from the read set of the transaction Tx1, and send the execution result of the transaction Tx1 and the state value V0 to the host 100.
In another embodiment, the computing device 210 may read the transaction number "Tx-1" corresponding to the state value (V0) of the variable key1 read in the execution of the transaction Tx1 from the private cache corresponding to the transaction Tx1, and transmit the execution result of the transaction Tx1 to the host 100 together with the transaction number "Tx-1".
Alternatively, the host 100 performs step S219 after receiving the execution result of the transaction Tx1 and the information indicating the state, and records the information of the states of the respective variables read by the transaction Tx1 in the global buffer. Here, since the host 100 has previously recorded "Tx1 Tx-1" in the global buffer in association with the variable Key1 and the computing device 210, repeated storage is not required here, and if the state of other variables stored in the computing device 210 is also read in the execution of the transaction Tx1, the information of the read state may be similarly recorded in the global buffer in association with the computing device 210 and the other variables. By making this record, it can be determined from the record whether the transaction Tx1 has read the wrong state before submitting the transaction Tx1, and thus whether to re-execute the transaction Tx 1.
In step S221, the host 100 determines whether the transaction Tx1 is successfully executed.
In one embodiment, computing device 210 sends the execution result of transaction Tx1 and the state value V0 of variable Key1 to host 100, with the current state of variable Key1 recorded in the global buffer as V0. Thus, the host 100 can determine the state of the correct variable Key1 read by the transaction Tx1 by comparing the state value V0 included in the execution result and the state value V0 recorded in the global buffer to be identical, and thus can determine that the transaction Tx1 was successfully executed.
In another embodiment, the computing device 210 sends the execution result of the transaction Tx1 to the host 100 together with the transaction number "Tx-1" corresponding to the state value V0 read from the private buffer of the transaction Tx1, the related transaction in which the current state V0 of the variable Key1 is recorded in the global buffer being the transaction Tx-1. Therefore, the host 100 can determine the state of the correct variable Key1 read by the transaction Tx1 according to the transaction number "Tx-1" corresponding to the received state value V0 and the transaction number "Tx-1" associated with the current state value of the variable Key1 recorded in the global buffer, so that it can be determined that the transaction Tx1 is successfully executed.
At step S225, the host 100 may submit the transaction Tx1 after determining that the transaction Tx1 was successfully executed.
Specifically, the host 100 may update the variable status information in the global buffer according to the execution result of the transaction Tx1, and put the execution result of the transaction Tx1 into the data set of the submitted transaction. Specifically, if transaction Tx1 further includes a write operation to any variable (e.g., variable Key 2) (e.g., the written state value of variable Key2 is V21), host 100 may record the current state of variable Key2 as V21 in the global buffer, and the related transaction is transaction Tx1. The host 100 may delete the read information of the transaction Tx1 recorded in the global buffer (for example, "Tx1 Tx-1") on the state of the variable Key1, and delete the read information ("Tx 1 Tx-1") in fig. 4.
Returning again to step S203, assume that the transaction Tx3 to be performed by the computing device 210 also includes a read operation to variable Key1. Assuming that computing device 210 performs the read operation in transaction Tx3 after submitting transaction Tx1, computing device 210 determines whether the variable Key1 to be read in transaction Tx3 is hit in buffer 1 after performing the read operation in transaction Tx 3. At this time, since the transaction Tx1 of reading the variable Key1 has been executed previously, key1 may be hit in the buffer 1, so that the computing device 210 may directly read the state value V0 of the variable Key1 from the buffer 1, and execute step S215, to continue executing the transaction Tx3 based on the state value V0 of the variable Key1 read from the buffer 1, resulting in an execution result of the transaction Tx 3.
In one embodiment, computing device 210 performs transactions Tx1, tx3, tx5, etc. in order of transaction numbers, with only the latest state of the states acquired by computing device 210 of variable Key1 being recorded in buffer 1. Thus, computing device 210 may read the state value of variable Key1 from buffer 1 when performing a read operation in transaction Tx 3. In this embodiment, a transaction number corresponding to the state value of variable Key1 may also be recorded in buffer 1, and after reading the state value, computing device 210 may also store the transaction number corresponding to the state value (e.g., transaction Tx-1) in association with variable Key1 into a private buffer corresponding to transaction Tx3 (e.g., buffer 2 in fig. 3).
In another implementation, computing device 210 performs transactions Tx1, tx3, tx5, and so on, for example, in parallel. The computing device 210 may record a plurality of state values for each variable and a transaction number corresponding to each state value in the buffer 1 (e.g., as shown in fig. 3). As shown in fig. 3, assuming that "Tx-1, V0" and "Tx5, V15" (data in the dashed box shown in fig. 3 is currently recorded in the entry of variable Key1 in buffer 1), since the transaction number of transaction Tx3 (i.e., 3) is smaller than the transaction number of transaction Tx5 (i.e., 5) and greater than the transaction number of transaction Tx-1, computing device 210 reads the state value "V0" from buffer 1 before the execution of transaction Tx3 and continues to execute transaction Tx3 based on "V0". Likewise, after reading the state value "V0", the computing device 210 may record "Key1, tx-1" in the buffer 2 corresponding to transaction Tx3 to indicate that the state value V0 corresponding to transaction Tx-1 was read during execution of transaction Tx3.
The computing device 210 performs step S217 after performing the completion transaction Tx3, and transmits the result of the execution of the transaction Tx3 and information indicating the status read by the transaction Tx3 to the host 100. Similarly to the above, the status information indicating that the transaction Tx3 reads may be the status value V0, or may be the transaction number "Tx-1" corresponding to the status value V0.
Optionally, the host 100 performs step S219 after receiving the execution result of the transaction Tx3 and the information indicating the status, records the reading of the variable Key1 by the transaction Tx3 in the global buffer, for example, as shown in fig. 4, the host 100 may record "Tx3 Tx-1" in the global buffer corresponding to the variable Key1 and the computing device 210 to indicate that the transaction Tx3 has read the status of the variable Key1 written by the transaction Tx-1. By making this record, if the variable Key1 is written to the transaction committed before the transaction Tx3 is committed, it can be determined from the record whether the transaction Tx3 has read the wrong state, and thus it can be determined whether to re-execute the transaction Tx 3.
After that, the host 10 executes step S221 to determine whether the transaction Tx3 was successfully executed.
Specifically, the host 100 submits the respective transactions in order of the transaction numbers from small to large, i.e., the submission of the transaction Tx3 is started after the transaction Tx2 is submitted. Upon submitting transaction Tx3, host 100 determines whether transaction Tx3 has read an outdated state value based on the information of the current state of variable Key1 recorded in the global buffer and the information of the indicated state of transaction Tx3, thereby determining whether transaction Tx3 was successfully executed.
In one embodiment, computing device 210 sends the state value V0 read from transaction Tx3 obtained from the read set of transaction Tx3 to host 100 along with the execution result of transaction Tx3, assuming that the current state value of variable Key1 is recorded in the global buffer as V12, for example. The host 100 may determine that the value "V0" of the variable Key1 read in the execution of the transaction Tx3 does not coincide with the current state value of the variable Key1, and thus, the host 100 may determine that the transaction Tx3 has failed to be executed.
In another embodiment, computing device 210 sends transaction number "Tx-1" corresponding to state value V0 to host 100 along with the result of the execution of transaction Tx 3. Suppose that the transaction number in which the current state of the write variable Key1 is recorded in the current global buffer in the host 100 is transaction TX2. The host 100 may determine that the related transaction "Tx-1" of the state value of the variable Key1 read in the transaction Tx3 is inconsistent with the related transaction "Tx2" of the current state of the variable Key1, and thus, the host 100 may determine that the transaction Tx3 failed to execute. Alternatively, in the case where the host 100 has recorded "Tx3 Tx-1" in the global buffer after receiving the execution result of the transaction Tx3 and the information indicating the state as described above, the host 100 may acquire from the record that the related transaction of the state value of Key1 read by the transaction Tx3 is "Tx-1", and determine that the related transaction "Tx-1" of the state value of variable Key1 read in the transaction Tx3 is inconsistent with the related transaction "Tx2" of the current state of variable Key1 accordingly.
After determining that the transaction Tx3 fails to be executed, the host 100 executes step S223 to notify the computing device 210 to re-execute the transaction Tx3. In one embodiment, the host 100 may include the current state value of the variable Key1 and the associated transaction "Tx2, V12" in the notification, such that the computing device 210 may re-execute the transaction Tx3 based on the state value V12. Wherein, after transmitting "Tx2, V12" to computing device 210, host 100 may accordingly record "Tx3, tx2" in an entry associated with Key1 and computing device 210 in the global buffer to indicate that the state value of variable Key1 written by transaction Tx2 was read in the execution of transaction Tx3. Assuming that the transaction Tx3 also includes a write operation to the variable Key1, after determining that the transaction Tx3 fails to execute, the host 100 may also search for other transactions in the global buffer that read the state value of the variable Key1 written by the transaction Tx3 from the information corresponding to the computing device 210 and the Key1, and notify the computing device 210 to re-execute the other transactions, since the reading of the state value of the Key1 written by the transaction Tx3 by other transactions is possible to be recorded in the global buffer only in the information corresponding to the computing device 210 and the Key1 at this time.
After receiving "Tx2, V12", computing device 210 may record "Tx2, V12" (as shown in the dashed box in FIG. 3) in buffer 1 between "Tx-1, V0" and "Tx5, V15" to indicate that V12 is the status value written by transaction Tx 2. In the process of re-executing the transaction Tx3, the computing device 210 may read, from the buffer 1, a state value corresponding to the maximum transaction number with a transaction number smaller than 3 (i.e., V12 corresponding to Tx 2) from the state values of the variable Key1, and may also modify "Key1, tx-1" to "Key1, tx2" in the buffer 2. Thereafter, the computing device 210 may re-execute the transaction Tx3 based on the state value V12 and transmit the execution result of the re-execution to the host 100.
In addition to the above-described operation of reading the variable Key1, the transaction Tx3 may include an operation of writing the variable Key1 after the read operation, for updating the state of the variable Key1 to a new state (e.g., V13). In this case, the computing device 210 also performs an operation of writing the variable Key1 after performing an operation of reading the variable Key1 in the process of performing the transaction Tx3 through the above-described step S215. FIG. 5 illustrates a flow chart of a method for writing variables in a blockchain node provided by embodiments of the present description.
As shown in fig. 5, in step S501, the computing device 210 performs a write operation to the variable Key1, specifically, writes the state value V13 written to the variable Key1 in the read-write set of the transaction Tx 3.
In step S503, the computing device 210 updates the buffer 1 based on the above-described write operation.
Specifically, computing device 210 writes state value "V13" written in execution of transaction Tx3 in buffer 1 in association with variable Key 1. In one implementation, computing device 210 performs transactions in order of transaction number from small to large, and thus computing device 210 may write only "V13" into buffer 1 in association with variable Key1 and delete the previous old state value of variable Key 1.
In another embodiment, computing device 210 executes multiple transactions in parallel, so that computing device 210 may add "Tx3, V13" between "Tx-1, V0" and "Tx5, V15" in the entry of variable Key1 to indicate that transaction Tx3 written variable Key1 and transaction Tx3 corresponds to state value V13, as shown in fig. 3.
The computing device 210 may perform step S505 after performing the above operation, and transmit the state update information of the variable Key1 to the host 100. In one implementation, computing device 210 may send information including "Key1, tx3, V13" to host 100 immediately after performing the write operation described above. In another embodiment, the computing device 210 may send the execution result of the transaction Tx3 to the host 100 after the execution of the transaction Tx3 is completed, where the execution result includes the value of the variable written during the execution of the transaction Tx3, thereby sending the state update information of the variable Key1 to the host 100.
After receiving the status update information of the variable Key1, the host 100 executes step S507, determines information of transactions that need to be re-executed in the respective computing devices based on the status update information, and notifies the respective computing devices in step S509. The host 100 may perform the steps S507 and S509 immediately after receiving the status update information, or may perform the steps S507 and S509 after submitting the transaction Tx 3.
Specifically, referring to FIG. 4, assuming that "Tx5, tx2" is recorded in the global buffer in association with variable Key1 and computing device 210, indicating that the state value of variable Key1 written by transaction Tx2 was read during execution of transaction Tx5, the commit order of transaction Tx2 precedes transaction Tx3, and execution of transaction Tx3 in turn updates the state value of variable Key1, host 100 may determine that the incorrect (or outdated) state value of variable Key1 was read during execution of transaction Tx5, and thus transaction Tx5 needs to be re-executed. The host 100 may then notify the computing device 210 to re-execute the transaction Tx5. Similarly, assuming that the transaction Tx5 includes a write to variable Key2, after determining that the transaction Tx5 failed to execute, the host 100 may also look up other transactions in the global buffer for which the state value of variable Key2 written by the transaction Tx5 was read from the information corresponding to the computing device 210 and Key2, and notify the computing device 210 to re-execute the other transactions. The computing device 210 re-executes the transaction Tx5 in step S511 after receiving the notification. In re-executing transaction Tx5, computing device 210 may read the state value "V13" of variable Key1 from buffer 1 for executing transaction Tx5, since "Tx3, V13" has been previously added to the entry of variable Key1 in buffer 1 by execution of transaction Tx3, such that transaction Tx5 reads the correct state value.
Referring also to fig. 4, assuming that "Tx4, tx2" is recorded in the global buffer in association with variable Key1 and computing device 220, indicating that the state value of variable Key1 written by transaction Tx2 was read in the execution of transaction Tx4, the commit order of transaction Tx2 precedes transaction Tx3, and the execution of transaction Tx3 in turn updates the state value of variable Key1, it may be determined that the erroneous state value of variable Key1 was read in the course of the execution of transaction Tx4, and thus transaction Tx4 also needs to be re-executed, host 100 may likewise execute step S211, informing computing device 220 to re-execute transaction Tx4. The computing device 220 re-executes the transaction Tx4 at step S513. In one embodiment, the host 100 may send "Tx3, V13" to the computing device 220 along with the notification, so that the computing device 220 may re-execute transaction Tx4 based on the status value "V13".
In one embodiment, the host 100 may notify the computing device 220 that transaction Tx4 needs to be re-executed after transaction Tx3 commits, after which the host 100 modifies the current state of variable Key1 to "V13" in the global buffer and modifies the identity of the relevant transaction to "Tx3". Upon re-executing transaction Tx4, computing device 220 requests from host 100 to read the current state of variable Key1 (i.e., "V13") and the associated transaction number (i.e., "Tx 3") so that computing device 220 may obtain the correct state value for re-executing transaction Tx4. After sending "Tx 3V 13" to computing device 220, host 100 may delete "Tx4Tx2" associated with variable Key1 and computing device 220 in the global buffer and record "Tx4Tx 3" at that location.
Referring to fig. 3, assume that computing device 210 performed a read operation of variable Key1 in transaction Tx5, read state value V0, and recorded "Key1, tx-1" in memory 212 in buffer 3 corresponding to transaction Tx5, prior to performing the above-described write operation of transaction Tx 3. Assuming that the computing device 210 again performs a read operation of the variable Key1 in the transaction Tx5 after recording "Tx 3V 13" in the buffer 1 as described above, when the read state value is "V13", the computing device 210 determines that "Key1 Tx-1" has been recorded in the buffer 3 in the process of recording "Key1 Tx3" to the buffer 3 after reading the state value V13, so that it can be determined that the transaction Tx5 has read the wrong state value in the previous execution, thus rollback the execution of the transaction Tx5, and re-execute the transaction Tx5. Wherein, in the execution of rollback on transaction Tx5, it may include deleting "Tx 5V 15" in the entry of variable Key1 in buffer 1 and deleting "Key1, tx-1" in buffer 3.
In re-executing transaction Tx5, computing device 210 will read "Tx 3V 13" according to the contents of buffer 1, and thus read the correct state value, when performing the first read of variable Key1 in transaction Tx 5.
2-5, By means of the transaction execution scheme provided by the embodiment of the present disclosure, states of variables accessed in a transaction execution process are respectively cached in a plurality of computing devices in a blockchain node, where the states of the variables cached in the computing devices are correct state values for the variables frequently read only, and the computing devices can directly read the state values of the variables from a local memory without going through a host, so that a duration of communication with the host is reduced, a transaction execution time is shortened, and system performance is improved.
FIG. 6 is an architecture diagram of a computing device for a blockchain node further including a host for performing the method of FIG. 2 or FIG. 5, according to embodiments of the present disclosure, including:
A receiving unit 61, configured to receive a partial transaction in a first block from a host, where the partial transaction includes a first transaction, and the first transaction includes a read operation on a first variable;
a reading unit 62, configured to, after starting to execute the first transaction, at least in a case where it is determined that the first state of the first variable is stored in the memory, read the first state of the first variable from the memory, and obtain an execution result of the first transaction according to the first state;
a transmitting unit 63 for transmitting the execution result and information indicating the status read in the execution of the first transaction to the host.
FIG. 7 is an architecture diagram of a host for a blockchain node further including a computing device therein for performing the method of FIG. 2 or FIG. 5, according to embodiments of the present disclosure, including:
a sending unit 71, configured to send a part of transactions in a first block to the computing device, where the part of transactions includes a first transaction, where the first transaction includes a read operation on a first variable, and the host includes a first storage space, where the first storage space is used to store, during execution of the first block, a plurality of first information of the first block, where the plurality of first information indicates current states of a plurality of variables accessed during the execution, and the computing device includes a second storage space;
A receiving unit 72, configured to receive, from the computing device, a result of execution of the first transaction and second information, where the second information indicates a first state in which a first variable stored in the second storage space is read in execution of the first transaction;
A submitting unit 73, configured to, after submitting the transactions in the first block in sequence that are in the order before the first transaction, submit the first transaction if it is determined that the first state is the current state of the first variable according to the global execution information.
It should be understood that the description of "first," "second," etc. herein is merely for simplicity of description and does not have other limiting effect on the similar concepts.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing describes specific embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Those of ordinary skill would further appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, in computer software, or in a combination of the two, and that the elements and steps of the examples have been generally described in terms of function in the foregoing description to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Those of ordinary skill in the art may implement the described functionality using different approaches for each particular application, but such implementation is not considered to be beyond the scope of the present application. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The foregoing description of the embodiments has been provided for the purpose of illustrating the general principles of the invention, and is not meant to limit the scope of the invention, but to limit the invention to the particular embodiments, and any modifications, equivalents, improvements, etc. that fall within the spirit and principles of the invention are intended to be included within the scope of the invention.