Disclosure of Invention
Embodiments of the present disclosure are directed to a method for performing transactions concurrently in a blockchain, which is more efficient and solves the deficiencies of the prior art.
To achieve the above object, one aspect of the present specification provides a method for concurrently executing multiple transactions in a blockchain, where the multiple transactions have a predetermined submission order, including a first transaction, the order in the first transaction includes at least one predetermined operation, the predetermined operation corresponds to the first operation when a predetermined condition is satisfied, and a current submission order of the first transaction is located at a position after a first bit, and the method is executed at a first node in the blockchain, and includes:
when a first predetermined operation of the at least one predetermined operation is executed, recording a first log in a first storage space corresponding to a first transaction, and recording a recording order of the first log in a log recorded in the first storage space, the first log corresponding to the first operation of the first predetermined operation, in the first storage space; and
skipping the first predetermined operation continues to perform operations in the first transaction that follow the first predetermined operation.
In one embodiment, a first operation of the first scheduled operations comprises a write operation on a first variable, and a read operation on the first variable is included after the first scheduled operation in the first transaction, and the method further comprises, upon execution of the read operation, in the event that it is determined that a first log is recorded in the first storage space, marking in a second storage space corresponding to the first transaction to indicate that the first transaction needs to be re-executed in its commit phase, wherein a commit order of the first transaction in the commit phase is first.
In one embodiment, a first operation of the first scheduled operations comprises a write operation on a first variable, and a read operation on the first variable is included after the first scheduled operation in the first transaction, and the method further comprises, upon execution of the read operation, in a case where it is determined that a first log is recorded in the first storage space, waiting until the first transaction reaches a commit stage, and then stopping waiting to re-execute the first transaction in the commit stage of the first transaction, wherein a commit order of the first transaction in the commit stage is first.
In one embodiment, a transaction execution window is preset in the first node, and the transactions are transactions arranged in a submission order currently included in the transaction execution window, where the first transaction is currently located at a position after a first position in the transaction execution window.
In one embodiment, the at least one predetermined operation includes at least one type of predetermined operation.
Another aspect of the present specification provides a method for concurrently executing multiple transactions in a blockchain, where the multiple transactions have a predetermined commit order, including a first transaction, the first transaction includes at least one predetermined operation in an order, the predetermined operation corresponds to a first operation when a predetermined condition is satisfied, and a current commit order of the first transaction is located at a first position, the first transaction has been previously executed before the commit order changes to the first position, and at least one log corresponding to the at least one predetermined operation and a recording order of the at least one log are currently recorded in a first storage space corresponding to the first transaction, the log corresponds to the first operation in the corresponding predetermined operation, and the method is executed at a first node in the blockchain, and includes:
acquiring the at least one log and the recording sequence of the at least one log;
on the basis of the recording sequence of the at least one log, sequentially judging whether a preset condition corresponding to the log is met or not for each log;
and in the case that the preset condition corresponding to the log is judged not to be satisfied, re-executing the first transaction and submitting the first transaction.
In one embodiment, the method further includes, in a case where it is determined that each of the predetermined conditions corresponding to the at least one log is satisfied, sequentially performing at least one first operation corresponding to the at least one log, based on a recording order of the at least one log, and submitting the first transaction.
In one embodiment, in the first transaction, the predetermined operation corresponds to a second operation if the predetermined condition is not satisfied, wherein, in the case where it is determined that the predetermined condition corresponding to the log is not satisfied, re-executing and submitting the first transaction includes, when the predetermined operation corresponding to the log is re-executed, executing the second operation corresponding to the predetermined operation.
In one embodiment, a transaction execution window is preset in the first node, and the transactions are transactions arranged in a submission order currently included in the transaction execution window, where the first transaction is currently located at a first position in the transaction execution window.
In one embodiment, the first predetermined operation is a transfer operation from the first account to a second account, and the first predetermined operation corresponds to an operation of transferring a first amount from the first account to the second account when a predetermined condition is satisfied.
In one embodiment, the predetermined condition is that the balance of the first account is equal to or greater than the first amount.
Another aspect of the present specification provides an apparatus for concurrently executing a plurality of transactions in a blockchain, wherein the plurality of transactions have a predetermined submission order, including a first transaction, the order in the first transaction includes at least one predetermined operation, the predetermined operation corresponds to the first operation when a predetermined condition is satisfied, and a current submission order of the first transaction is located at a position after a first bit, the apparatus is disposed in a first node in the blockchain, and includes:
a recording unit configured to, when a first predetermined operation out of the at least one predetermined operation is performed, record a first log in a first storage space corresponding to a first transaction, and record, in the first storage space, a recording order of the first log in logs already recorded in the first storage space, the first log corresponding to the first operation out of the first predetermined operation; and
and the execution unit is configured to skip the first predetermined operation and continue to execute the operation in the first transaction after the first predetermined operation.
In one embodiment, a first operation of the first predetermined operations includes a write operation on a first variable, and a read operation on the first variable is included after the first predetermined operation in the first transaction, and the apparatus further includes a marking unit configured to, when the read operation is executed, mark in a second storage space corresponding to the first transaction in a case where it is determined that a first log is recorded in the first storage space to indicate that the first transaction needs to be re-executed in a commit stage thereof, wherein a commit order of the first transaction in the commit stage is first.
In one embodiment, a first operation of the first predetermined operations includes a write operation on a first variable, and a read operation on the first variable is included after the first predetermined operation in the first transaction, and the apparatus further includes a waiting unit configured to, when executing to the read operation, wait until the first transaction reaches a commit stage and then stop waiting to re-execute the first transaction in the commit stage of the first transaction, in a case where it is determined that a first log is recorded in the first storage space, wherein a commit order of the first transaction in the commit stage is first.
Another aspect of the present specification provides an apparatus for concurrently executing a plurality of transactions in a blockchain, wherein the plurality of transactions have a predetermined commit order including a first transaction, the first transaction includes at least one predetermined operation in an order, the predetermined operation corresponds to a first operation when a predetermined condition is satisfied, and a current commit order of the first transaction is located at a first position, the first transaction has been previously executed before the commit order changes to the first position, and at least one log corresponding to the at least one predetermined operation and a recording order of the at least one log are currently recorded in a first storage space corresponding to the first transaction, the log corresponds to the first operation in the corresponding predetermined operation, the apparatus is disposed in a first node in the blockchain, and includes:
an acquisition unit configured to acquire the at least one log and a recording order of the at least one log;
a judging unit configured to judge, for each log in turn, whether a predetermined condition corresponding to the log is satisfied based on a recording order of the at least one log;
and the re-execution unit is configured to re-execute the first transaction and submit the first transaction in the case that the preset condition corresponding to the log is judged not to be satisfied.
In one embodiment, the apparatus further includes a submitting unit configured to, in a case where it is determined that each of the predetermined conditions corresponding to the at least one log is satisfied, sequentially perform at least one first operation corresponding to the at least one log, based on a recording order of the at least one log, and submit the first transaction.
In one embodiment, in the first transaction, the predetermined operation corresponds to a second operation if the predetermined condition is not satisfied, wherein in a case where it is determined that the predetermined condition corresponding to the log is not satisfied, the re-execution unit is further configured to, when the predetermined operation corresponding to the log is re-executed, execute the second operation corresponding to the predetermined operation.
Another aspect of the present specification provides a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any one of the above methods.
Another aspect of the present specification provides a computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor implements any one of the above methods when executing the executable code.
According to the scheme for concurrently executing the transaction, aiming at the scheduled operation comprising the condition judgment, the scheduled operation is not executed in the non-submission stage, only the record is carried out in the buffer area, and the scheduled operation is executed in the submission stage by judging whether the predetermined condition is met, so that compared with the scheme for previously executing the scheduled operation in the non-submission stage, the possible larger time cost caused by the re-execution of the transaction in the submission stage can be avoided, and meanwhile, other operations except the scheduled operation included in the transaction are executed in advance when the transaction is concurrently executed, and the efficiency for concurrently executing the transaction is integrally accelerated.
Detailed Description
The embodiments of the present specification will be described below with reference to the accompanying drawings.
Fig. 1 shows a block chain system according to an embodiment of the present disclosure. As shown in fig. 1, the system includes a plurality of nodes (6 nodes are schematically shown in the figure) forming a block chain, and the nodes are connected in pairs, wherein the nodes include, for example, a node 11, a node 12, and a node 13. As known to those skilled in the art, in a blockchain, some nodes collect multiple transactions in the blockchain into a transaction pool and compete for billing rights. For example, node 11 in the figure becomes the accounting node by acquiring accounting rights. Node 11, after becoming an accounting node, performs multiple transactions in its transaction pool and packages the multiple transactions into blocks for transmission to other nodes, such as node 12. Node 12 will authenticate the block and similarly perform transactions in the block. After a predetermined number of nodes verify the block, i.e., the block is known to be known, other nodes in the block chain (e.g., node 13) will not need to continue verifying the block, but will perform transactions directly in the block to update the local related data.
When the plurality of transactions are executed by each node, a predetermined number of transactions may be concurrently executed at one time in order to increase the execution speed. The concurrently executed transactions may involve the calculation of multiple variables, in case the same variable is not involved in both transactions, the execution order may not affect the final calculation result, and in case the same variable is involved in both transactions, the execution order may affect the final calculation result, e.g. the commit order of the first transaction precedes the second transaction, in which case the value of the first variable read by the second transaction is the wrong value, if the first transaction writes the first variable after the reading of the first variable was performed in the second transaction, the second transaction needs to be re-executed.
The concurrently executed transaction may include a predetermined action such as a transfer, the success of which depends on whether the transferred account balance is sufficient, e.g., if the transferred account balance is less than the transfer amount, the transfer will not be successfully executed. That is, whether the predetermined operation can be successfully performed is based on whether a predetermined condition is satisfied. Generally, before a transfer operation is performed, an account status is firstly acquired, after a transfer authority is determined according to the account status, the transfer operation is performed, wherein the transfer operation comprises the steps of acquiring a balance, determining whether the balance is sufficient, and modifying the balance of a corresponding account under the condition that the balance is sufficient. The account state acquisition time is long, the transfer operation time is short, if the two steps are fixedly combined together and executed concurrently, the possibility of transaction redoing is high due to high possibility of balance change, and finally, the transfer is completely and serially performed. If the account state is separated from the account state, the account state is allowed to be acquired in parallel, and the transfer operation is performed when the account state is submitted, so that the time-consuming operation of acquiring the account state is completed when the account state is executed in parallel, and meanwhile, the transfer operation is performed only when the account state is submitted, the transaction redo caused by balance change is avoided, and the execution of the transfer operation can be accelerated. Therefore, in the solution of the present embodiment, for the above-mentioned predetermined operation, in the non-submission stage of the transaction, the predetermined operation is not executed, but only the record of the predetermined operation is made in the log, and the other operations in the transaction are executed continuously after the record, and in the submission stage of the transaction, it is determined whether the predetermined operation can be successfully executed based on the record, and in the determination that the predetermined operation can be successfully executed, the predetermined operation is executed and the transaction is submitted, and in the determination that the predetermined operation cannot be successfully executed, the transaction is re-executed. Therefore, the time cost for executing the predetermined operation in advance is avoided while the transaction is executed concurrently, and the transaction executing speed is further accelerated.
Fig. 2 is a flowchart illustrating a method for concurrently executing multiple transactions in a blockchain, where the multiple transactions have a predetermined submission order, including a first transaction, the order in the first transaction includes at least one predetermined operation, the predetermined operation corresponds to the first operation when a predetermined condition is satisfied, and a current submission order of the first transaction is located at a position after a first position, and the method is executed at a first node in the blockchain, and includes:
step S202, when a first predetermined operation in the at least one predetermined operation is executed, recording a first log in a first storage space corresponding to a first transaction and a recording sequence of the first log in logs recorded in the first storage space, wherein the first log corresponds to the first operation in the first predetermined operation; and
and step S204, skipping the first predetermined operation and continuing to execute the operation in the first transaction after the first predetermined operation.
First, in step S202, when a first predetermined operation out of the at least one predetermined operation is performed, a first log corresponding to the first operation out of the first predetermined operation is recorded in a first storage space corresponding to a first transaction, and a recording order of the first log in logs already recorded in the first storage space.
As described above with reference to fig. 1, the method is performed at a node in the blockchain. The node performs commit on the associated transactions either while packaging the block or after receiving the newly generated block. For example, thousands of transactions may be included in a block, and the thousands may involve hundreds of variables, where multiple transactions may access different variables, or multiple transactions may access the same variable. In the prior art, in the accounting node, the respective transaction numbers of a plurality of transactions to be packed into one block have been determined according to predetermined rules, and the order of the transaction numbers indicates the execution order and the submission order of the transactions. In the embodiment of the present specification, in order to make the final calculation result the same as the serial calculation result in the prior art, a predetermined submission order is reserved for the multiple transactions in the block, for example, the number order of each transaction is used as its respective submission order, so that the multiple transactions can be executed concurrently, and the multiple transactions are submitted sequentially according to the number order of each transaction.
The predetermined operation is an operation that, when starting execution, needs to first determine whether a predetermined condition is satisfied, and then execute a corresponding operation according to the result of the determination. For example, the transfer operation is one of the predetermined operations. Before the transfer operation of the transaction is executed, account information is generally acquired first, whether the transfer right is available or not is determined, after the transfer right is determined to be available, the transfer operation is carried out, for example, the transfer operation comprises a first operation of transferring a first amount from a first account to a second account, generally, whether the balance of the first account is greater than or equal to the first amount is judged first (namely, whether a preset condition is met or not), and in the case that the balance of the first account is greater than or equal to the first amount, the first operation is executed. The operation also comprises a second operation of returning transfer failure information to the first account, for example, and the second operation is executed when the balance of the first account is judged to be less than the first amount. It is to be understood that the above description of the transfer operation is only illustrative and not restrictive, for example, the predetermined condition is not limited to the above predetermined condition, and may be set to, for example: the balance of the first account is equal to or greater than the first amount, and the balance of the second account after the transfer is less than the second amount, for example, the second operation is not limited to returning the transfer failure information, and it may be set, for example, to transfer a third amount from the first account to the second account, where the third amount is less than the first amount, for example, the first amount is 100 yuan, and the third amount is 1 yuan.
It is to be understood that the predetermined operation is not limited to the transfer operation, but may be any operation that performs a corresponding operation based on a predetermined condition, for example, the predetermined operation is a counting operation within a predetermined range, the counting operation adds 1 to the total count in a case where the total count is equal to or less than a predetermined value, and returns to the end of the count in a case where the total count is greater than the predetermined value. That is, in this scenario, the predetermined condition is that the total number of counts is equal to or less than a predetermined value, and in the case where the condition is satisfied, a first operation is performed, that is, 1 is added to the total number of counts, and in the case where the condition is not satisfied, a second operation is performed, that is, the end of counting is returned. The scheme of the embodiment of the present specification will be schematically described below by taking a transfer operation as an example.
For example, the at least one predetermined operation included in the first transaction includes a transfer operation, such as transferring 100 units to account B when the balance of account a is equal to or greater than 100 units, and returning "transfer failure" information to account a when the balance of account a is less than 100 units.
When a first transaction is executed in the process of concurrently executing transactions, in the case that the first transaction is in a non-submission stage, that is, the first transaction is not currently a transaction in which the first transaction is first in the submission order, when the transfer operation is executed, a determination as to whether a predetermined condition is satisfied may be performed first, but a log (for example, a first log) corresponding to the transfer operation is directly recorded in a first storage space corresponding to the first transaction in a buffer corresponding to the first transaction, an operation of transferring 100 elements from the account a to the account B (that is, the first operation) is directly recorded in the first log, and "transfer success" is notified to the transaction, and then the transfer operation in the first transaction is skipped, and the subsequent operations are continuously executed. That is, in this process, an actual transfer operation is not performed in advance, but only a log corresponding to the first operation is recorded. For at least one predetermined operation in the first transaction, for example, at least one log may be recorded successively in consecutive addresses sequentially arranged in the first storage space, and the at least one log corresponds to the at least one predetermined operation, so that the recording order of the at least one log is represented by the recording order of the addresses.
Fig. 3 schematically shows a schematic diagram of a first storage space in a first buffer. As shown in FIG. 3, the first buffer includes three first storage spaces corresponding to transactions 3-5, respectively, wherein logs corresponding to the transactions are recorded: logs 31 to 34, logs 41 to 43 and logs 51 to 52. For example, if the first transaction is transaction 3, the corresponding first storage space is a block of storage space corresponding to transaction 3. The left side of the figure is marked with 1-4 as address marks which represent four continuous address spaces, and in each address space, the logs 31-34 are stored, so that the recording sequence of the logs 31-34 can be determined to be the logs 31-32-33-34 based on the sequence of the addresses. The first buffer area may be a buffer area in a shared memory or a buffer area allocated to only a single thread, depending on the specific manner of concurrently executing transactions. It is to be understood that, in the embodiments of the present specification, the recording order of the at least one log is not limited in this way, for example, while recording the at least one log, the recording time of each log may be recorded accordingly, so that the recording order of the at least one log is recorded by the recording time, and so on.
It is to be understood that the at least one predetermined operation included in the first transaction is not limited to all transfer operations, for example, different types of predetermined operations such as transfer operations, counting operations, function operation operations, and the like may be included in the first transaction at the same time, and the first predetermined operation is not limited to transfer operations, but may be any predetermined operation included in the first transaction.
In one embodiment, due to the large number of transactions, a transaction execution window may be set to slide among a plurality of transactions arranged in a commit order (or transaction number) so that the plurality of transactions in the transaction execution window may be concurrently executed in the blockchain node, and the transaction execution window may be set to slide one transaction backward every time one transaction is committed. FIG. 4 illustrates a schematic diagram of a transaction execution window according to an embodiment of the present description. As shown in fig. 4, the ten numbers 1 to 10 in the figure represent ten transactions numbered 1 to 10, respectively, and the transaction execution window may include, for example, 5 transactions. The transaction execution window may initially fall on transactions 1 through 5. After transaction 1 is submitted, the window moves one transaction back, falling on transactions 2 to 6, and likewise after transaction 2 is submitted, the window moves one more transaction back, falling on transactions 3 to 7 as shown in the figure. In the method of FIG. 2, the first transaction may be any one of transactions 4-7 of FIG. 4, i.e., it is the first transaction in the order of presentation from a plurality of transactions that are executed concurrently.
In step S204, the operations subsequent to the first predetermined operation in the first transaction are executed continuously by skipping the first predetermined operation.
That is, in the embodiment of the present specification, in the first transaction, operations other than the at least one predetermined operation are performed in advance, so that only the at least one predetermined operation can be performed in the commit stage, thereby saving the total execution time.
In one embodiment, for example, the first transaction includes the above-described transfer operation, and the first operation performed when the predetermined condition is satisfied is, for example, as described above, transferring 100 units from the account a to the account B, and assuming that the balance of the account a is the variable k1 and the balance of the account B is the variable k2, the first operation corresponds to reading an initial value of the variable k1, determining whether the initial value is equal to or greater than 100, in the case where the initial value is determined to be equal to or greater than 100, reducing the initial value by 100 to obtain a second value, writing the value of the variable k1 to the second value, and similarly operating the variable k 2. That is, the transfer operation, when actually performed, would include read and write processes to the variable k 1. In the case where a read operation for the variable k1 is also included after the transfer operation in the first transaction, if the read operation for the variable k1 is continued by skipping the transfer operation in the non-commit stage as described above, the value of k1 read here is not the value after the transfer operation is actually performed, and thus an erroneous value of k1 is read. Thus, in embodiments of the present description, in order to avoid misreading of the variable, in the event that a read operation on variable k1 is also included after the transfer operation in the first transaction, after executing the code to the read operation, in the event that it is determined that there is a first journal in the first memory space, a flag may be placed in the second memory space in the second buffer corresponding to the first transaction to indicate that the first transaction needs to be re-executed in its commit stage, where the commit order of the first transaction in its commit stage is first, for example as shown in fig. 4, where transaction 3 is at bit 1 of the transaction execution window, and thus transaction 3 is currently the commit stage. In one embodiment, where a read operation to variable k1 is also included after the transfer operation in the first transaction, after executing code to the read operation, in the event that it is determined that a first journal exists in the first memory space, a wait may be made until the wait is stopped after the first transaction reaches the commit phase to re-execute the first transaction at the commit phase of the first transaction. That is, here, similar to a read-write conflict detection, a "transfer operation" is considered as a "write operation" to the relevant account balance, and a "read balance operation" is considered as a "read operation" to the account balance, so that in a case where a read operation is also included after the write operation, that is, an access conflict occurs, and thus redo or wait is required. The second buffer may be a buffer in the shared memory or a buffer allocated to a single thread according to a specific manner of concurrently executing transactions.
In one embodiment, the method of FIG. 2 is performed by thread 1, which, after executing code to the read operation, marks in its assigned second memory space corresponding to the first transaction that the first transaction needs to be re-executed. For example, fig. 5 shows a schematic diagram of the second storage space in the second buffer. As shown in fig. 5, the numbers 1-5 in the lower part of the figure represent transaction numbers, each transaction corresponding to a second memory space, for example a bit corresponding to the respective transaction, which is initially 0, marked by modifying it to 1. For example, the first transaction is transaction 3 in fig. 5, and assuming that transaction 3 does not currently reach the commit stage, the second storage space corresponding to the first transaction is the bit in the second buffer corresponding to transaction 3. Thread 1 thus modifies the bit in the second buffer in figure 5 corresponding to transaction 3 to 1 to mark. Thread 1 may then either continue to execute the current first transaction or may obtain a new task for execution and, after execution is complete, determine whether transaction 3 is currently in the commit stage based on the indicia in the second memory space corresponding to transaction 3, if transaction 3 reaches the commit stage (i.e., is first in the window) due to the movement of the transaction execution window as shown in fig. 4, may re-execute the first transaction based on the indicia, and if not in the commit stage, thread 1 may obtain a new task and subsequently repeat the above steps. After thread 1 re-executes the first transaction, the flag in the second memory space may be restored to 0.
In one embodiment, thread 1 marks in a second buffer in the shared memory that a first transaction needs to be re-executed in a second storage space corresponding to the first transaction after executing code to the read operation, so that thread 1 may fetch a new task for execution, and other threads (e.g., thread 2) may determine whether the first transaction is currently in a commit phase after reading the mark in the second storage space corresponding to the first transaction, and if so, thread 2 may begin re-executing the first transaction, and if not, thread 2 may fetch a new task for execution.
In one embodiment, thread 1 may wait after executing code to the read operation, e.g., thread 1 may sleep to wait, thread 1 awaken after receiving a notification to thread 1 that the previous transaction to the first transaction was after commit, thereby determining that the first transaction is in a commit phase, or actively determine whether the first transaction is in a commit phase when thread 1 grabs a pending task, in which case re-execution of the first transaction may begin when thread 1 determines that the first transaction is in a commit phase.
Figure 6 illustrates a method of concurrently executing multiple transactions in a blockchain according to one embodiment of the present description, wherein the plurality of transactions have a predetermined submission order, including a first transaction in which the order includes at least one predetermined operation, the predetermined operation corresponding to the first operation if a predetermined condition is satisfied, and the current commit order of the first transaction is at the first place, the first transaction having been previously executed before the commit order changes to the first place, and currently recording at least one log corresponding to the at least one predetermined operation and a recording order of the at least one log in a first storage space corresponding to the first transaction, the log corresponding to a first operation of respective predetermined operations, the method performed at a first node in a blockchain, comprising:
step S602, obtaining the at least one log and the recording sequence of the at least one log;
step S604, based on the recording sequence of at least one log, sequentially judging whether a preset condition corresponding to the log is met for each log;
step S606, in case that it is determined that the predetermined condition corresponding to the log is not satisfied, re-executing the first transaction and submitting the first transaction.
First, in step S602, the at least one log and a recording order of the at least one log are acquired.
In this method, a first transaction is in the commit phase, e.g., as shown in FIG. 4, the first transaction is, e.g., transaction 3 in FIG. 4, which is currently at position 1 of the transaction window, and thus is currently in the commit phase. Since at least one log corresponding to the at least one predetermined operation, respectively, and a recording order of the at least one log have been stored in the corresponding first storage space in fig. 3 by the method shown in fig. 2 in the non-commit stage of the first transaction, the step S602 may be started to be performed after the first transaction is changed from the non-commit stage to the commit stage. That is, the at least one log and the recording order thereof, for example, log 31-log 32-log 33-log 34, are obtained from the first storage space corresponding to the first transaction, the arrangement order of which represents the recording order thereof, and the first operation of the corresponding predetermined operations is recorded in each log, for example, log 34 corresponds to the transfer operation, which records 100 yuan transferred from account a to account B.
In one embodiment, after retrieving the at least one log and its recording order from the corresponding first storage space, the first storage space may be emptied for subsequent recording.
In step S604, it is determined whether a predetermined condition corresponding to the log is satisfied for each log in turn based on the recording order of the at least one log.
That is, the above determination is performed for each log in turn in the order of the log records 31 to 34. For example, after determining that the predetermined conditions are satisfied for all of the logs 31 to 33, the log 34 is determined, that is, whether the balance of the account a is greater than or equal to 100 yuan is determined, specifically, the value of the balance k1 of the account a is read, and it is determined whether the value of k1 minus 100 is greater than or equal to zero.
In step S606, in the case where it is judged that the predetermined condition corresponding to the log is not satisfied, the first transaction is re-executed and submitted.
In an example such as that shown in FIG. 3, the "log" may be any one of the logs 31-34, and the first transaction (i.e., transaction 3 in FIG. 3) may need to be re-executed and submitted as long as it is determined that the predetermined condition of any one of the logs 31-34 cannot be met. For example, it is determined that the predetermined condition of the log 34 cannot be met, i.e., the value of k1 minus 100 is less than zero, thereby determining that the predetermined condition cannot be met and that the first transaction needs to be re-executed. In this case, the transfer operation in the first transaction corresponds to the second operation if the predetermined condition is not satisfied, for example, the second operation is to return "transfer failure" to the account a, so that, when the first transaction is re-executed in the first node, because the first transaction is the transaction ranked first in the transaction execution window at this time (i.e., the first transaction is in the commit stage), the log is not recorded any more, and the second operation corresponding to the predetermined operation is directly executed, i.e., the "transfer failure" is returned to the account a, and after the first transaction is executed, the first transaction is committed. For example, the transfer operation in the first transaction corresponds to a second operation under the condition that the predetermined condition is not met, for example, the second operation is "transfer 1 yuan from the account a to the account B", so that, when the first transaction is re-executed in the first node, because the first transaction is the transaction arranged at the first position in the transaction execution window at this time, the log is not recorded any more, the second operation corresponding to the predetermined operation is directly executed, that is, transfer 1 yuan from the account a to the account B, and the first transaction is submitted after the first transaction is executed.
In one embodiment, in the case that the predetermined conditions corresponding to each log are judged to be satisfied sequentially for each log, for example, the predetermined conditions corresponding to the logs 31 to 34 are judged to be satisfied for the logs 31 to 34, the corresponding first operations in the logs 31 to 34 are sequentially executed based on the recording sequence of the logs 31 to 34, and the first transaction is submitted after the first operations are executed in combination with the execution information executed in advance in the non-submission stage of the first transaction.
Fig. 7 illustrates an apparatus 700 for concurrently executing a plurality of transactions in a blockchain, wherein the plurality of transactions have a predetermined submission order, including a first transaction, the order of the first transaction includes at least one predetermined operation, the predetermined operation corresponds to the first operation when a predetermined condition is satisfied, and the current submission order of the first transaction is located at a position after the first position, the apparatus is disposed in a first node in the blockchain, and includes:
a recording unit 71 configured to, when a first predetermined operation out of the at least one predetermined operation is performed, record a first log in a first storage space corresponding to a first transaction, and record, in the first storage space, a recording order of the first log in logs already recorded in the first storage space, the first log corresponding to the first operation out of the first predetermined operation; and
an execution unit 72 configured to skip the first predetermined operation to continue to execute an operation in the first transaction after the first predetermined operation.
In one embodiment, a first operation of the first predetermined operations includes a write operation on a first variable, the code following the code in the first transaction includes a read operation on the first variable, the apparatus further includes a marking unit 73 configured to, upon execution to the read operation, in a case where it is determined that a first log is recorded in the first storage space, mark in a second storage space corresponding to the first transaction to indicate that the first transaction needs to be re-executed in a commit stage thereof, wherein a commit order of the first transaction in the commit stage is first.
In one embodiment, a first operation of the first predetermined operations includes a write operation on a first variable, the code following the code in the first transaction includes a read operation on the first variable, and the apparatus further includes a waiting unit 74 configured to, when executing to the read operation, wait until the first transaction reaches a commit phase after stopping waiting to re-execute the first transaction in the commit phase of the first transaction, in a case where it is determined that a first log is recorded in the first storage space, wherein a commit order of the first transaction in the commit phase is first.
Figure 8 illustrates an apparatus 800 for concurrently performing multiple transactions in a blockchain according to one embodiment of the present description, wherein the plurality of transactions have a predetermined submission order, including a first transaction in which the order includes at least one predetermined operation, the predetermined operation corresponding to the first operation if a predetermined condition is satisfied, and the current commit order of the first transaction is at the first place, the first transaction having been previously executed before the commit order changes to the first place, and currently recording at least one log corresponding to the at least one predetermined operation and a recording order of the at least one log in a first storage space corresponding to the first transaction, the log corresponding to a first one of the respective predetermined operations, the apparatus deployed in a first node in a blockchain, comprising:
an acquiring unit 81 configured to acquire the at least one log and a recording order of the at least one log;
a judging unit 82 configured to judge, for each log in turn, whether a predetermined condition corresponding to the log is satisfied based on a recording order of the at least one log;
a re-execution unit 83 configured to re-execute the first transaction and submit the first transaction in case it is determined that the predetermined condition corresponding to the log is not satisfied.
In one embodiment, the apparatus further includes a submitting unit 84 configured to, in a case where it is determined that the respective predetermined conditions corresponding to the at least one log are satisfied, sequentially perform at least one first operation corresponding to the at least one log, based on a recording order of the at least one log, and submit the first transaction.
In one embodiment, in the first transaction, the predetermined operation corresponds to a second operation if the predetermined condition is not satisfied, wherein in the case where it is determined that the predetermined condition corresponding to the log is not satisfied, the re-execution unit 83 is further configured to, when re-executing the predetermined operation corresponding to the log, execute the second operation corresponding to the predetermined operation.
Another aspect of the present specification provides a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any one of the above methods.
Another aspect of the present specification provides a computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor implements any one of the above methods when executing the executable code.
According to the scheme for concurrently executing the transaction, aiming at the scheduled operation comprising the condition judgment, the scheduled operation is not executed in the non-submission stage, only the record is carried out in the buffer area, and the scheduled operation is executed in the submission stage by judging whether the predetermined condition is met, so that compared with the scheme for previously executing the scheduled operation in the non-submission stage, the possible larger time cost caused by the re-execution of the transaction in the submission stage can be avoided, and meanwhile, other operations except the scheduled operation included in the transaction are executed in advance when the transaction is concurrently executed, and the efficiency for concurrently executing the transaction is integrally accelerated. In addition, compared with the traditional serial execution of the transfer transaction of the blockchain, the transfer transaction is divided into two stages by recording the log, the originally conflicting transfer transaction is converted into the transaction which can be executed in parallel, and the system performance is prompted.
It is to be understood that the terms "first," "second," and the like, herein are used for descriptive purposes only and not for purposes of limitation, to distinguish between similar concepts.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may 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 may also be possible or may be advantageous.
It will be further appreciated by those of ordinary skill in the art that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether these functions are performed in hardware or software depends on the particular application of the solution and design constraints. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor, or a combination of the two. A software module may reside 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 above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.