WO2021036259A1 - Method and device for executing transactions in parallel in blockchain - Google Patents

Method and device for executing transactions in parallel in blockchain Download PDF

Info

Publication number
WO2021036259A1
WO2021036259A1 PCT/CN2020/082696 CN2020082696W WO2021036259A1 WO 2021036259 A1 WO2021036259 A1 WO 2021036259A1 CN 2020082696 W CN2020082696 W CN 2020082696W WO 2021036259 A1 WO2021036259 A1 WO 2021036259A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
task
processed
buffer
variable
Prior art date
Application number
PCT/CN2020/082696
Other languages
French (fr)
Chinese (zh)
Inventor
刘晓建
张兆勇
Original Assignee
创新先进技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 创新先进技术有限公司 filed Critical 创新先进技术有限公司
Publication of WO2021036259A1 publication Critical patent/WO2021036259A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/389Keeping log of transactions for guaranteeing non-repudiation of a transaction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Definitions

  • the embodiments of this specification relate to the field of blockchain technology, and more specifically, to a method and device for concurrently executing transactions in a blockchain.
  • Blockchain technology is built on a peer-to-peer (P2P) network. It uses a chained data structure to verify and store data, uses a distributed node consensus algorithm to generate and update data, and uses cryptography to ensure the security of data transmission and access.
  • a new distributed infrastructure and computing paradigm that uses smart contracts composed of automated script codes to program and manipulate data.
  • Blockchain technology also known as distributed ledger technology, is a decentralized distributed database technology, which is characterized by decentralization, openness and transparency, non-tampering, and trustworthiness. Every piece of data in the blockchain will be broadcast to the blockchain nodes of the entire network, and each full node has a full amount of consistent data.
  • the nodes in the blockchain conduct transactions such as transfers and deposit data by sending transactions.
  • the accounting nodes in the blockchain collect transactions in the blockchain in the transaction pool, execute the transactions, and execute the transactions After that, these transactions are packaged into blocks and spread to the blockchain.
  • the verification node in the blockchain will verify the block sent from the accounting node. After the verification is passed, each node will execute each transaction included in the block when it receives the block. In order to ensure the data consistency of each node, when multiple transactions in the block are executed in each node, the order of submission of the multiple transactions needs to be consistent, so that consistent execution results can be obtained.
  • the accounting node before executing the transaction, the accounting node will number multiple transactions to be executed according to predetermined rules, and execute multiple transactions in sequence in the order of the numbers, that is, submit multiple transactions in turn, and other After receiving the block, the node also executes and submits the multiple transactions in sequence according to the above-mentioned transaction number sequence.
  • the multiple transactions are not necessarily mutually dependent. In the case where there is no dependency between the two transactions, concurrent execution of the two transactions does not affect the final result. And if there are dependencies between two transactions executed concurrently, the concurrent execution will affect the final result.
  • one aspect of this specification provides a method for concurrently executing transactions in a blockchain.
  • the method is executed on a first node in the blockchain.
  • the first node currently passes a preset predetermined number of transactions.
  • the executive body executes transactions concurrently, including a first executive body, which is currently processing a first transaction, and the method is executed by the first executive body, including:
  • the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory so as to be relative to the first to-be-processed task.
  • the transaction enters the waiting process;
  • the second to-be-processed task is continued to be executed based on the execution information corresponding to the second to-be-processed task, wherein the multiple to-be-processed tasks include The second task to be processed.
  • the method further includes, in a case where it is determined that the waiting processes of the multiple to-be-processed tasks are not finished, obtaining the second transaction to be processed from the first buffer in the shared memory, and Start the execution of the second transaction.
  • the shared memory includes a second buffer area, wherein, after a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the first to-be-processed task corresponding to the first transaction are recorded in the shared memory, and
  • the execution information corresponding to the first task to be processed includes, after processing the first transaction, in the case where it is determined that the second transaction has not been submitted, the first task to be processed corresponding to the first transaction is recorded in the second buffer.
  • a processing task wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission order.
  • determining whether there are pending tasks waiting for the end of the process includes: determining the first transaction based on the current transaction that should be submitted recorded in the shared memory Whether the waiting process of the pending task corresponding to the smallest transaction number in the second buffer zone is over, to determine whether there is a pending task waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the transaction submission sequence .
  • continuing to execute the second to-be-processed task includes: In the case where the waiting process of the second to-be-processed task in the second buffer is over, continue to perform the submission of the third transaction based on the execution information corresponding to the second to-be-processed task, wherein the second to-be-processed task Corresponds to the third transaction.
  • the shared memory includes a third buffer
  • the first transaction includes a read operation of the first variable
  • the shared memory Recording in the memory the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task includes, after requesting the reading of the first variable, in the third buffer
  • the first task to be processed corresponding to the first transaction is recorded, wherein the first task to be processed includes a record of the first variable.
  • the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to the read operation of the second variable in the second transaction.
  • the shared memory To determine whether there is a pending task waiting for the end of the process includes multiple pending tasks that have been recorded in, determining whether the variable value of the second variable is returned, and determining whether the variable value of the second variable is returned , It is determined that the waiting process of the second to-be-processed task ends.
  • determining whether there are pending tasks waiting for the end of the process includes: for multiple pending tasks that have been recorded in the third buffer , Based on the descending order of the transaction number corresponding to each task to be processed, determine in turn whether the waiting process of each task to be processed is over, wherein the second task to be processed is the first determined task to be processed after the waiting process ends, where , The transaction number corresponds to the predetermined submission sequence of the transaction.
  • determining whether the variable value of the second variable is returned includes determining whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory , Wherein the predetermined address corresponds to the second transaction.
  • continuing to execute the second to-be-processed task includes: When there is a second task to be processed waiting for the process to end in the third buffer, the second transaction is continued to be executed based on the execution information corresponding to the second task to be processed and the variable value of the second variable.
  • the shared memory includes a fourth buffer
  • the first transaction includes a read operation of the first variable
  • the shared memory Recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the memory includes, after executing the code of the read operation, determining that the submission sequence is before the first transaction, And whether each transaction that has not been submitted is a conflict transaction in which the write operation to the first variable has been performed, and the each transaction includes a second transaction, in the case of determining that the second transaction is the closest conflict transaction to the first transaction
  • the fourth buffer zone the first task to be processed corresponding to the first transaction is recorded, wherein the first task to be processed includes the record of the second transaction.
  • determining whether there are pending tasks waiting for the end of the process includes: determining whether there is a transaction that should be submitted currently recorded in the shared memory Whether there is a to-be-processed task waiting for the end of the process among the multiple to-be-processed tasks recorded in the fourth buffer.
  • the shared memory includes a fifth buffer
  • the first transaction includes a read operation of the first variable
  • the shared memory Recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the memory includes, after executing the code of the read operation, inferring that the order of submission is before the first transaction, And whether each transaction that has not been submitted is a conflict transaction that is about to write the first variable, and each transaction includes a second transaction.
  • the first task to be processed corresponding to the first transaction is recorded in the fifth buffer zone, wherein the first task to be processed includes a record of the second transaction.
  • the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed respectively, wherein, for multiple tasks to be processed that have been recorded in the shared memory, Determining whether there are pending tasks waiting for the end of the process includes determining whether there are pending tasks waiting for the end of the process in each buffer based on a predetermined sequence of the at least one buffer.
  • Another aspect of this specification provides a device for concurrently executing transactions in a blockchain.
  • the device is deployed in a first executor in a first node in the blockchain.
  • a predetermined number of executive bodies concurrently execute transactions, including a first executive body, which is currently processing the first transaction, and the device includes:
  • the recording unit is configured to record, in the shared memory, a first task to be processed corresponding to the first transaction and execution information corresponding to the first task to be processed after a predetermined operation is performed in the process of processing the first transaction, to Enter the waiting process with respect to the first transaction;
  • the determining unit is configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks that have been recorded in the shared memory, and the multiple pending tasks are recorded by the predetermined number of executives; as well as
  • the continuing execution unit is configured to continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, wherein the The multiple to-be-processed tasks include the second to-be-processed task.
  • the device further includes a transaction execution unit configured to, in a case where it is determined that the waiting processes of the multiple pending tasks are not finished, obtain the pending tasks from the first buffer in the shared memory. Process the second transaction, and start execution of the second transaction.
  • the shared memory includes a second buffer area, wherein the recording unit is further configured to, after processing the first transaction, in a case where it is determined that the second transaction has not been submitted, in the first transaction
  • the first to-be-processed task corresponding to the first transaction is recorded in the second buffer zone, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission sequence.
  • the determining unit is further configured to determine whether the waiting process of the task to be processed corresponding to the smallest transaction number in the second buffer is over based on the transaction currently to be submitted recorded in the shared memory, to It is determined whether there is a task to be processed waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the submission sequence of the transaction.
  • the continuing execution unit is further configured to, in a case where it is determined that the waiting process of the second to-be-processed task in the second buffer is over, based on the execution corresponding to the second to-be-processed task Information, continue to perform the submission of the third transaction, wherein the second pending task corresponds to the third transaction.
  • the shared memory includes a third buffer
  • the first transaction includes a read operation of the first variable
  • the recording unit is further configured to request the first variable
  • the first to-be-processed task corresponding to the first transaction is recorded in the third buffer, wherein the first to-be-processed task includes a record of the first variable.
  • the third buffer includes the second to-be-processed task, the second to-be-processed task corresponds to a reading operation of the second variable in the second transaction, and the determining unit further It is configured to determine whether the variable value of the second variable is returned, and in a case where it is determined that the variable value of the second variable is returned, it is determined that the waiting process of the second to-be-processed task ends.
  • the determining unit is further configured to, for a plurality of pending tasks that have been recorded in the third buffer, determine each pending task in sequence based on the order of the transaction number corresponding to each pending task from small to large. Whether the waiting process of the processing task ends, wherein the second task to be processed is the first determined task to be processed after the waiting process ends, and the transaction number corresponds to the predetermined submission sequence of the transaction.
  • the determining unit is further configured to determine whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory, wherein the predetermined The address corresponds to the second transaction.
  • the continuing execution unit is further configured to, in a case where it is determined that there is a second to-be-processed task waiting for the end of the process in the third buffer, based on the execution corresponding to the second to-be-processed task Information and the variable value of the second variable, continue to execute the second transaction.
  • the shared memory includes a fourth buffer area
  • the recording unit is further configured to, after executing the code of the read operation, determine that the submission sequence is before the first transaction and is not Whether each submitted transaction is a conflict transaction in which a write operation to the first variable has been performed, and each transaction includes a second transaction.
  • the first to-be-processed task corresponding to the first transaction is recorded in the fourth buffer zone, wherein the first to-be-processed task includes a record of the second transaction.
  • the determining unit is further configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks recorded in the fourth buffer based on the transaction currently to be submitted recorded in the shared memory. Processing tasks.
  • the shared memory includes a fifth buffer
  • the first transaction includes a read operation of the first variable
  • the recording unit is further configured to: After operating the code, it is inferred whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction that will write the first variable.
  • the each transaction includes a second transaction, and the second transaction is inferred.
  • the transaction is a conflicting transaction closest to the first transaction
  • the first pending task corresponding to the first transaction is recorded in the fifth buffer, wherein the first pending task includes a second transaction record of.
  • the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the determining unit is further configured to, based on the at least one buffer To determine whether there are pending tasks waiting for the end of the process in each buffer.
  • Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored.
  • the computer program is executed in a computer, the computer is caused to perform any of the above methods.
  • Another aspect of this specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, any one of the above methods is implemented.
  • the processing information of the transaction is recorded when the execution body needs to wait while executing the transaction, and other pending tasks or other pending transactions are obtained from the shared memory for processing, thereby It reduces the waiting time of the execution body and speeds up the overall speed of concurrent execution of transactions.
  • Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification
  • Figure 2 shows a schematic diagram of each node in the blockchain executing transactions concurrently through multiple threads
  • Fig. 3 shows a flowchart of a method for concurrently executing transactions in a blockchain according to an embodiment of the present specification
  • Fig. 4 shows a device 400 for concurrently executing transactions in a blockchain according to an embodiment of the present specification.
  • Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification.
  • the system includes multiple nodes (six nodes are schematically shown in the figure) constituting a blockchain, and these nodes are connected in pairs, including node 11, node 12, and node 13, for example.
  • some nodes collect multiple transactions in the blockchain and put them into the transaction pool and compete for the right to keep accounts.
  • the node 11 in the figure becomes a billing node by acquiring the billing right.
  • node 11 becomes an accounting node, it will execute multiple transactions in its transaction pool, package the multiple transactions into blocks and send them to other nodes, for example, to node 12.
  • the node 12 will verify the block and execute multiple transactions in the block in the same way. After a predetermined number of nodes verify the block, that is, a consensus on the block is reached, other nodes in the blockchain (such as node 13) will not need to continue to verify the block, but directly The transactions in this block are executed to update local related data.
  • Figure 2 shows a schematic diagram of each node in the blockchain executing transactions concurrently through multiple threads. It can be understood that the thread can also be replaced by an execution body such as a process and a coroutine.
  • the number of CPUs is limited, and the number of preset threads is also fixed. For example, assuming that the number of CPUs of the node is 4, the number of CPUs preset in the thread pool is The number of threads is 6, so that 6 threads compete to preempt the CPU, and only after the CPU is preempted, can the tasks in the task pool begin to be executed.
  • the calculation of multiple variables may be involved in the multiple transactions.
  • the order of execution will not affect The final calculation result, and in the case of two transactions involving the same variables, the order of execution will affect the final calculation result.
  • the conflicts of access variables between transactions are considered, so that some of the threads executed in parallel are The thread needs to go through a waiting process. Or you need to wait while waiting to return to access storage.
  • the graph includes the shared memory of the first node.
  • the shared memory includes, for example, a buffer 1 for indicating transactions to be processed.
  • the shared memory is readable and writable with respect to all threads. For example, there are currently 10 pending transactions 1, 2,...10 recorded in the first buffer.
  • the bit boxes corresponding to the numbers 1, 2,..., 10 in the figure should all be 1, indicating that they are all It is a transaction to be processed, where the serial number of transaction 1-10 corresponds to the order of submission of each transaction.
  • threads 1 to 4 preempt CPUs 1 to 4, respectively, so that threads 1 to 4 can respectively obtain a task from the first buffer for processing, for example, threads 1 to 4 start processing transactions respectively 1 to 4.
  • threads 1 to 4 After threads 1 to 4 start to process transactions 1 to 4, they respectively modify the corresponding bits of transactions 1 to 4 in the first buffer to 0 to indicate that these transactions have been executed. It can be understood that although the figure schematically shows that thread 1 preempts CPU1 and executes transaction 1, thread 2 preempts CPU2 and executes transaction 2, etc., it can be understood that the content shown in the figure is only for illustrative purposes. The number, CPU number, and transaction number do not correspond to each other. For example, thread 1 may preempt CPU2, execute transaction 3, and so on.
  • Figure 2 also shows multiple buffers for recording tasks to be processed, buffers 2 to 5, where each buffer corresponds to a waiting process.
  • buffer 2 corresponds to the waiting process of waiting for submission after the transaction is executed
  • buffer 3 corresponds to the waiting process of requesting a read to wait for the return variable value
  • buffer 4 corresponds to the waiting process of writing records based on variables before reading.
  • the waiting process of the previous transaction submission corresponds to the buffer 5 corresponding to the waiting process of waiting for the previous transaction submission or writing based on the transaction conflict probability before reading.
  • the process of executing the transaction includes the process of processing the transaction and the process of submitting the transaction.
  • the process of processing the transaction is to store the result of the transaction in the buffer corresponding to the transaction.
  • the final processing result is stored in the shared memory shared by each transaction. For example, after thread 3 has processed transaction 3, in order to ensure that the final results of executing each transaction are consistent, it is necessary to ensure that each transaction is submitted in the order of its number. Therefore, transaction 3 needs to wait for the previous transaction 2 to submit before submitting. In this case, thread 3 records the position corresponding to transaction 3 in buffer 2, for example, changing the initial 0 to 1, and then thread 3 goes to the buffer to obtain a new task. For example, thread 3 may first check whether there are tasks in buffer 2 waiting for the end of the process.
  • the thread 2 also records the current transaction window, and the current transaction window can be maintained by the thread that submitted the transaction, for example.
  • the first transaction in the transaction window can be modified to 2. Therefore, the transaction window moves one position backward among the multiple transactions to be submitted.
  • the thread starts to execute a new transaction (for example, transaction 7) according to the first position of the window, the last transaction in the transaction window can be updated from 6 to 7.
  • the thread 3 checks the buffer 2, it may first determine whether the transaction 2 is a transaction that should be submitted currently based on the window. In the case that there is no task waiting for the end of the process in the buffer 2, it can be checked whether there is a task waiting for the end of the process in the buffer 3, and so on.
  • the transaction to be processed can be obtained from buffer 1, for example, transaction 6.
  • thread 3 When thread 3 also encounters a waiting process in the process of executing transaction 6, it will also record the corresponding pending task in the corresponding one of buffers 2 to 5, for example, as shown by the dotted arrow on the right side of the figure , Thread 3 records the pending tasks corresponding to transaction 6 in buffer 4. Then, similarly, thread 3 first determines in buffers 2 to 5 whether there are pending tasks waiting for the end of the process.
  • FIG. 2 is only schematic, and is not used to limit the scope of the embodiments of the present specification.
  • the specific forms of the buffers 1 to 5 are not necessarily the forms shown in the figure, as long as they can record corresponding information.
  • the process of concurrently executing transactions according to the embodiments of the present specification will be described in detail.
  • Figure 3 shows a flow chart of a method for concurrently executing transactions in a blockchain according to an embodiment of the present specification.
  • the method is executed on a first node in the blockchain, and the first node is preset with a first node.
  • An executive body, the first executive body is currently processing a first transaction, and the method is executed by the first executive body, including:
  • Step S302 After a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory, so as to compare all The first transaction enters the waiting process;
  • Step S304 for the multiple pending tasks that have been recorded in the shared memory, it is determined whether there are pending tasks waiting for the end of the process.
  • Step S306 In the case where it is determined that the waiting process corresponding to the second to-be-processed task is over, continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task, wherein the plurality of to-be-processed tasks
  • the tasks include the second to-be-processed task.
  • step S302 after a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory to Enter the waiting process with respect to the first transaction.
  • the first executive body may be, for example, an executive body such as a thread, a process, or a coroutine, and the shared memory is shared with respect to multiple executive bodies used to execute transactions concurrently.
  • thread will be used as an example.
  • multiple waiting processes may be included, and the waiting processes may be caused by different reasons.
  • the multiple concurrently executed transactions have preset a predetermined submission order. For example, transactions 1 to 10 in Figure 2 must be numbered from small to large. Submit in order to ensure that the execution results of the multiple transactions by each node are the same.
  • the processing result is first saved in the buffer corresponding to the transaction, and after submission, the execution result is saved in the shared memory shared by each transaction.
  • the first variable needs to be written, and the value of the first variable after the write operation is first saved in the buffer corresponding to only the first transaction. It can be used in the first transaction, and the value will not be read or written when processing other transactions.
  • the value of the first transaction is stored in the shared memory, and other transactions can also read the value or modify the value by submitting it.
  • each transaction has a predetermined submission sequence, as shown in FIG. 2, for example, the first transaction is transaction 6 in FIG. 2, and the first executive body is thread 3 in the figure. If thread 3 finishes processing transaction 6 and the transaction before transaction 6 has not been submitted, at this time, thread 3 needs to wait for the completion of transaction 5 submission before submitting transaction 6.
  • the thread 3 may determine whether the transaction 5 is submitted based on the preset transaction window parameters in the shared memory.
  • the transaction window controls the maximum total number of transactions that can be executed concurrently.
  • the two sides of the transaction window are the transaction with the smallest number and the transaction with the largest number that are currently executed concurrently. For example, 1 and 6 in Figure 2 represent the current concurrently executed transactions. For transactions 1 ⁇ 6.
  • thread 3 can modify the bit corresponding to transaction 6 in buffer 2 to 1, as shown in Figure 2, to add a pending task corresponding to transaction 6, which can only wait until the transaction 5 After submission, execution can continue.
  • the execution information corresponding to the task to be processed that is, the current processing information of transaction 6, can be stored in the shared memory, for example, in the execution information buffer corresponding to each transaction.
  • transaction 6 includes a read operation on variable k1, and thread 3 sends a read request for variable k1 to the hardware or thread used to read the variable after starting to execute the code for the read operation. Then record "k1" in the byte corresponding to transaction 6 in the buffer 3 shown in Figure 2 to add a pending task corresponding to transaction 6, and the pending task waits until the value of the variable k1 returns Before continuing.
  • transaction 6 includes a read operation on variable k1. After thread 3 starts to execute the code for the read operation, it queries the write buffer in the shared memory, and the write buffer records the current The writing status of each variable (including variable k1) during the processing of each transaction. For example, the write buffer only records that transaction 4 writes to variable k1, and transaction 5 writes to variable k1 is not recorded. Because, based on this record, transaction 4 will change the value of k1 in the variable table in the shared memory after submission, therefore, transaction 6 needs to wait for transaction 4 to submit before reading the value of the variable k1, otherwise it will read the error The value of k1.
  • thread 3 After thread 3 checks the write buffer, it records "4" in the byte corresponding to transaction 6 in buffer 3 in Figure 2 to add a pending task corresponding to transaction 6, so The "4" corresponds to transaction 4, which means that the pending task can only be executed after transaction 4 is submitted.
  • transaction 6 includes a read operation on variable k1. After thread 3 starts to execute the code for the read operation, it infers whether each transaction (for example, transactions 1 to 5 in Figure 2) that is submitted in the order of submission before transaction 6 among multiple transactions being executed concurrently will write to variable k1 .
  • the transaction conflict probability of each variable can be determined in advance based on the transaction execution history in the node. When the transaction conflict probability of variable k1 is greater than a predetermined threshold, it can be inferred that transactions 1 to 5 will be performed on variable k1. Write operation. Therefore, after transaction 5 is submitted, the read operation in transaction 6 should be performed.
  • thread 3 can determine the conflict probability between transaction 6 and each previous transaction based on the transaction data of each transaction before transaction 6, and based on the conflict probability, infer whether each transaction will write k1, thereby Determine whether to wait for the submission or writing of the transaction. For example, in the case where it is determined that the write probability of transaction 4 to k1 is greater than or equal to a predetermined threshold, and the write probability of transaction 5 to k1 is less than the predetermined threshold, thread 3 in the buffer 5 in FIG. 2 corresponds to the word of transaction 6 Record "4" in the section to record a task to be executed corresponding to transaction 6. The task to be executed can only be executed after transaction 4 is submitted or written.
  • the waiting conditions in the embodiments of this specification are not limited to the above four conditions, but may be any waiting conditions triggered by a predetermined operation.
  • step S304 for the multiple pending tasks that have been recorded in the shared memory, it is determined whether there are pending tasks waiting for the end of the process.
  • the shared memory includes buffers 2 to 5, in which different types of pending tasks are recorded respectively.
  • thread 3 checks the buffers 2 to 5 in the shared memory in a predetermined order to obtain the waiting The pending task at the end of the process.
  • the tasks to be processed in the buffers 2 to 5 may be tasks to be processed recorded by any of the threads 1 to 4.
  • thread 3 may check buffer 2 first.
  • each pending task recorded in the buffer 2 corresponds to a transaction that has been processed and is waiting to be submitted.
  • the smallest transaction with a corresponding bit of 1 can be determined as transaction 2
  • thread 3 can determine whether the transaction that should be submitted is transaction 2 based on the transaction window in the shared memory.
  • the transaction that should be submitted is transaction 2, which means that the waiting process of the pending task corresponding to transaction 2 is over.
  • Thread 3 can obtain the execution information corresponding to transaction 2 from the buffer for storing transaction execution information in the shared memory. And continue to execute transaction 2 based on the execution information, that is, submit the transaction 2.
  • the thread 3 may check the buffer 3, for example. As mentioned above, each pending task recorded in the buffer 3 is waiting for the return of the corresponding variable value. For example, if "k2" is recorded in the byte corresponding to transaction 2 in buffer 3, it means that transaction 2 is waiting for the return of the value of variable k2. Thread 3 can determine whether the value of k2 has been written from the predetermined address in the shared memory corresponding to transaction 2. When the value of k2 is written, it indicates the waiting process of the pending task corresponding to transaction 2 End, wherein the predetermined address corresponds to the transaction 2.
  • the value of k2 can be written at this address by other threads performing read operations. In the case where it is determined that the value of k2 has not been written, it can be determined whether the waiting process is over for the tasks to be processed after transaction 2. For example, if "k1" is recorded in the byte corresponding to transaction 3, it can be determined whether the value of k1 has been written in the predetermined address corresponding to transaction 3.
  • thread 3 may check buffer 4, for example.
  • the pending tasks recorded in the buffer 4 correspond to transactions that wait for other transactions to be submitted for read operations based on write conditions. Similar to checking buffer 2, thread 3 can determine whether transaction 1 waiting for transaction 2 is submitted based on the transaction window in shared memory. In the case where transaction 1 is determined to be submitted, the pending task corresponding to transaction 2 is waiting The process is over. In the case where it is determined that the transaction 1 has not been submitted, the thread 3 can determine whether the waiting process of the task to be processed corresponding to the transaction after the transaction 2 has ended, for example, it can determine whether the waiting process corresponding to the transaction 3 has ended.
  • the thread 3 may check the buffer 5, for example.
  • the pending tasks recorded in the buffer 5 correspond to transactions waiting for other transactions to be submitted or written for read operations based on the conflict probability.
  • the thread 3 can similarly determine whether the transaction 1 waiting for the transaction 2 is submitted, or can determine whether the waiting process of the pending task corresponding to the transaction 2 is over based on the variable value written in the shared memory during the processing of the transaction 1 or not.
  • the buffers 2 to 5 included in the shared memory are only illustrative and not restrictive, and the sequence of checking the buffers is only illustrative and not restrictive. In specific implementation, it can be based on The scene needs to set up the buffer and check the order of the buffer.
  • the thread 3 may check the buffer 1 in the shared memory shown in FIG. 2, and the buffer 1 The transaction to be processed is recorded in, so that the thread 3 can obtain the transaction to be processed with the smallest number (for example, transaction 6) from the buffer 1, and start to execute the transaction.
  • step S306 in the case where it is determined that there is a second to-be-processed task waiting for the end of the process in the shared memory, continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task.
  • the thread 3 obtains the second to-be-processed task whose waiting process ends in the buffer 2, and then the thread 3 continues to execute the submission of the transaction corresponding to the second to-be-processed task based on the corresponding execution information. After the thread 3 determines that the waiting process of the second to-be-processed task ends, it removes the corresponding second to-be-processed task in the buffer, for example, changes the “1” corresponding to the second to-be-processed task in the buffer 2 to 0.
  • the thread 3 obtains the second task to be processed in the buffer 3, and the thread 3 continues to perform the operations following the read operation in the corresponding transaction based on the corresponding execution information and the value of the corresponding variable.
  • the thread 3 obtains the second task to be processed in the buffer 4, and the thread 3 continues to execute the corresponding read operation in the corresponding transaction based on the corresponding execution information.
  • the thread 3 obtains the second task to be processed in the buffer 5, and the thread 3 continues to execute the corresponding read operation in the corresponding transaction based on the corresponding execution information.
  • FIG. 4 shows another aspect of this specification according to an embodiment of the specification provides a device 400 for concurrently executing transactions in a blockchain, the device being deployed in the first execution body of the first node in the blockchain In the first node, the transaction is currently executed concurrently through a preset predetermined number of executive bodies, including a first executive body, and the first executive body is currently processing a first transaction, and the device includes:
  • the recording unit 41 is configured to record, in the shared memory, a first task to be processed corresponding to the first transaction and execution information corresponding to the first task to be processed after a predetermined operation is performed in the process of processing the first transaction, To enter the waiting process relative to the first transaction;
  • the determining unit 42 is configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks that have been recorded in the shared memory, and the multiple pending tasks are recorded by the predetermined number of executives. ;as well as
  • the continuing execution unit 43 is configured to continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, wherein
  • the multiple to-be-processed tasks include the second to-be-processed task.
  • the device further includes a transaction execution unit 44 configured to obtain from the first buffer in the shared memory when it is determined that the respective waiting processes of the multiple pending tasks have not ended. The second transaction to be processed, and the execution of the second transaction is started.
  • the shared memory includes a second buffer area, wherein the recording unit 41 is further configured to, after processing the first transaction, in a case where it is determined that the second transaction has not been submitted, in the The first to-be-processed task corresponding to the first transaction is recorded in the second buffer zone, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission sequence.
  • the determining unit 42 is further configured to determine whether the waiting process of the task to be processed corresponding to the smallest transaction number in the second buffer is over based on the transaction currently to be submitted recorded in the shared memory, To determine whether there is a task to be processed waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the submission sequence of the transaction.
  • the continued execution unit 43 is further configured to, in a case where it is determined that the waiting process of the second to-be-processed task in the second buffer is over, based on the corresponding to the second to-be-processed task Execution information, continue to execute the submission of the third transaction, wherein the second pending task corresponds to the third transaction.
  • the shared memory includes a third buffer area
  • the first transaction includes a read operation of the first variable
  • the recording unit 41 is further configured to: upon request, the first variable is read. After a variable is read, the first to-be-processed task corresponding to the first transaction is recorded in the third buffer, wherein the first to-be-processed task includes a record of the first variable.
  • the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to the reading operation of the second variable in the second transaction, and the determining unit 42 It is also configured to determine whether the variable value of the second variable is returned, and in a case where it is determined that the variable value of the second variable is returned, it is determined that the waiting process of the second to-be-processed task ends.
  • the determining unit 42 is further configured to, for the multiple pending tasks that have been recorded in the third buffer, determine each of the pending tasks in the descending order based on the transaction number corresponding to each pending task. Whether the waiting process of the task to be processed is completed, wherein the second task to be processed is the first determined task to be processed after the waiting process has ended, and the transaction number corresponds to the predetermined submission sequence of the transaction.
  • the determining unit 42 is further configured to determine whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory, wherein the The predetermined address corresponds to the second transaction.
  • the continued execution unit 43 is further configured to, in a case where it is determined that there is a second to-be-processed task waiting for the end of the process in the third buffer, based on the data corresponding to the second to-be-processed task The execution information and the variable value of the second variable continue to execute the second transaction.
  • the shared memory includes a fourth buffer
  • the first transaction includes a read operation of the first variable
  • the recording unit 41 is further configured to: After fetching the code of the operation, it is determined whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction in which the write operation to the first variable has been performed, and each transaction includes the second transaction. In the case where the second transaction is the conflicting transaction closest to the first transaction, the first pending task corresponding to the first transaction is recorded in the fourth buffer, wherein the first pending task includes the second The record of the transaction.
  • the determining unit 42 is further configured to determine whether there is a waiting process to be completed among the multiple pending tasks recorded in the fourth buffer based on the currently submitted transaction recorded in the shared memory. Pending tasks.
  • the shared memory includes a fifth buffer
  • the first transaction includes a read operation of the first variable
  • the recording unit 41 is further configured to: After fetching the code of the operation, it is inferred whether each transaction whose submission order is before the first transaction and is not submitted is a conflict transaction that will write the first variable.
  • Each transaction includes the second transaction. In the case where the second transaction is the closest conflict transaction to the first transaction, the first pending task corresponding to the first transaction is recorded in the fifth buffer, wherein the first pending task includes The record of the transaction.
  • the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the determining unit 42 is further configured to, based on the at least one buffer The predetermined sequence of zones determines whether there are pending tasks waiting for the end of the process in each buffer.
  • Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored.
  • the computer program is executed in a computer, the computer is caused to perform any of the above methods.
  • Another aspect of this specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, any one of the above methods is implemented.
  • the processing information of the transaction is recorded when the execution body needs to wait while executing the transaction, and other pending tasks or other pending transactions are obtained from the shared memory for processing, thereby It reduces the waiting time of the execution body and speeds up the overall speed of concurrent execution of transactions.
  • the steps of the method or algorithm described in combination with the embodiments disclosed in this document can be implemented by hardware, a software module executed by a processor, or a combination of the two.
  • the software module can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or all areas in the technical field. Any other known storage media.

Abstract

A method and device for executing transactions in parallel in a blockchain. The method is executed by a first executor in a first node in a blockchain, and comprises: after performing a predetermined operation during processing of a first transaction, recording, in a shared memory, a first pending task corresponding to the first transaction and execution information corresponding to the first pending task, and placing the first transaction in a waiting process (S302); determining, from multiple pending tasks already recorded in the shared memory, whether or not a pending task that has completed a waiting process is present, wherein the multiple pending tasks are recorded by a predetermined number of executors (S304); and if it is determined that a waiting process corresponding to a second pending task is over, executing the second pending task on the basis of execution information corresponding to the second pending task, wherein the multiple pending tasks comprise the second pending task (S306).

Description

在区块链中并发执行交易的方法和装置Method and device for concurrently executing transactions in blockchain 技术领域Technical field
本说明书实施例涉及区块链技术领域,更具体地,涉及一种在区块链中并发执行交易的方法和装置。The embodiments of this specification relate to the field of blockchain technology, and more specifically, to a method and device for concurrently executing transactions in a blockchain.
背景技术Background technique
区块链技术是构建在点对点(P2P)网络上,利用链式数据结构来验证与存储数据,利用分布式节点共识算法来生成和更新数据,利用密码学的方式保证数据传输和访问的安全,利用由自动化脚本代码组成的智能合约来编程和操作数据的一种全新的分布式基础架构与计算范式。区块链技术也被称之为分布式账本技术,是一种去中心化的分布式数据库技术,其特点是去中心化、公开透明、不可篡改、可信任。区块链的每笔数据,都会广播到全网的区块链节点,每个全节点都有全量的、一致的数据。区块链中的节点通过发送交易而进行转账、存入数据等业务,区块链中的记账节点在交易池中收集区块链中的交易,执行所述交易,并在执行所述交易之后,将这些交易打包到区块中并扩散到区块链中。区块链中的验证节点会对从记账节点发出的区块进行验证,在验证通过之后,每个节点在接收到该区块时,都会执行该区块中包括的每个交易。为了保证各个节点的数据一致性,各个节点中在执行区块中的多个交易时,对该多个交易的提交顺序需要是一致的,这样才能得到一致的执行结果。因此,在现有技术中,记账节点在执行交易之前会按照预定规则对将要执行的多个交易进行编号,并按照编号的顺序依次执行多个交易,也即依次提交多个交易,并且其它节点在接收到该区块之后,也是按照上述交易编号顺序依次执行并提交所述多个交易。然而,所述多个交易并不一定都是相互依赖的,在两个交易之间不存在依赖性的情况中,并发执行这两个交易并不影响最终的结果。而如果并发执行的两个交易存在依赖性,则该并发执行将影响到最终的结果。Blockchain technology is built on a peer-to-peer (P2P) network. It uses a chained data structure to verify and store data, uses a distributed node consensus algorithm to generate and update data, and uses cryptography to ensure the security of data transmission and access. A new distributed infrastructure and computing paradigm that uses smart contracts composed of automated script codes to program and manipulate data. Blockchain technology, also known as distributed ledger technology, is a decentralized distributed database technology, which is characterized by decentralization, openness and transparency, non-tampering, and trustworthiness. Every piece of data in the blockchain will be broadcast to the blockchain nodes of the entire network, and each full node has a full amount of consistent data. The nodes in the blockchain conduct transactions such as transfers and deposit data by sending transactions. The accounting nodes in the blockchain collect transactions in the blockchain in the transaction pool, execute the transactions, and execute the transactions After that, these transactions are packaged into blocks and spread to the blockchain. The verification node in the blockchain will verify the block sent from the accounting node. After the verification is passed, each node will execute each transaction included in the block when it receives the block. In order to ensure the data consistency of each node, when multiple transactions in the block are executed in each node, the order of submission of the multiple transactions needs to be consistent, so that consistent execution results can be obtained. Therefore, in the prior art, before executing the transaction, the accounting node will number multiple transactions to be executed according to predetermined rules, and execute multiple transactions in sequence in the order of the numbers, that is, submit multiple transactions in turn, and other After receiving the block, the node also executes and submits the multiple transactions in sequence according to the above-mentioned transaction number sequence. However, the multiple transactions are not necessarily mutually dependent. In the case where there is no dependency between the two transactions, concurrent execution of the two transactions does not affect the final result. And if there are dependencies between two transactions executed concurrently, the concurrent execution will affect the final result.
因此,需要一种更有效的在区块链中并发执行多个交易的方法。Therefore, there is a need for a more effective method of concurrently executing multiple transactions in the blockchain.
发明内容Summary of the invention
本说明书实施例旨在提供一种更有效的并发执行交易的方案,以解决现有技术中的不足。The embodiments of this specification aim to provide a more effective solution for concurrently executing transactions to solve the deficiencies in the prior art.
为实现上述目的,本说明书一个方面提供一种在区块链中并发执行交易的方法,所述方法在区块链中的第一节点执行,所述第一节点中当前通过预设的预定数目的执行体并发执行交易,其中包括第一执行体,所述第一执行体当前在处理第一交易,所述方法由所述第一执行体执行,包括:In order to achieve the above objective, one aspect of this specification provides a method for concurrently executing transactions in a blockchain. The method is executed on a first node in the blockchain. The first node currently passes a preset predetermined number of transactions. The executive body executes transactions concurrently, including a first executive body, which is currently processing a first transaction, and the method is executed by the first executive body, including:
在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;After a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory so as to be relative to the first to-be-processed task. The transaction enters the waiting process;
对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务,所述多个待处理任务由所述预定数目的执行体记录;以及For the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process, and the multiple pending tasks are recorded by the predetermined number of executives; and
在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。In the case where it is determined that the waiting process corresponding to the second to-be-processed task ends, the second to-be-processed task is continued to be executed based on the execution information corresponding to the second to-be-processed task, wherein the multiple to-be-processed tasks include The second task to be processed.
在一个实施例中,所述方法还包括,在确定所述多个待处理任务各自的等待过程都未结束的情况中,从共享内存中的第一缓冲区获取待处理的第二交易,并开始执行所述第二交易。In one embodiment, the method further includes, in a case where it is determined that the waiting processes of the multiple to-be-processed tasks are not finished, obtaining the second transaction to be processed from the first buffer in the shared memory, and Start the execution of the second transaction.
在一个实施例中,所述共享内存中包括第二缓冲区,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在处理完成第一交易之后,在确定第二交易未提交的情况中,在所述第二缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第二交易根据预定提交顺序为所述第一交易的前一个交易。In one embodiment, the shared memory includes a second buffer area, wherein, after a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the first to-be-processed task corresponding to the first transaction are recorded in the shared memory, and The execution information corresponding to the first task to be processed includes, after processing the first transaction, in the case where it is determined that the second transaction has not been submitted, the first task to be processed corresponding to the first transaction is recorded in the second buffer. A processing task, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission order.
在一个实施例中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于共享内存中记录的当前应提交的交易,确定所述第二缓冲区中对应于最小交易编号的待处理任务的等待过程是否结束,以确定所述第二缓冲区中是否存在等待过程结束的待处理任务,其中,所述交易编号对应于交易的提交顺序。In one embodiment, for the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes: determining the first transaction based on the current transaction that should be submitted recorded in the shared memory Whether the waiting process of the pending task corresponding to the smallest transaction number in the second buffer zone is over, to determine whether there is a pending task waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the transaction submission sequence .
在一个实施例中,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务包括,在确定所述第二缓冲区中的第二待处理任务的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行对第三交易的提交,其中所述第二待处理任务与所述第三交易相 对应。In one embodiment, in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, based on the execution information corresponding to the second to-be-processed task, continuing to execute the second to-be-processed task includes: In the case where the waiting process of the second to-be-processed task in the second buffer is over, continue to perform the submission of the third transaction based on the execution information corresponding to the second to-be-processed task, wherein the second to-be-processed task Corresponds to the third transaction.
在一个实施例中,所述共享内存中包括第三缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在请求对所述第一变量的读取之后,在所述第三缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对所述第一变量的记录。In one embodiment, the shared memory includes a third buffer, and the first transaction includes a read operation of the first variable, wherein, after a predetermined operation is performed in the process of processing the first transaction, the shared memory Recording in the memory the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task includes, after requesting the reading of the first variable, in the third buffer The first task to be processed corresponding to the first transaction is recorded, wherein the first task to be processed includes a record of the first variable.
在一个实施例中,所述第三缓冲区中包括所述第二待处理任务,所述第二待处理任务与第二交易中对第二变量的读取操作相对应,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任包括,确定所述第二变量的变量值是否被返回,在确定所述第二变量的变量值被返回的情况中,确定该第二待处理任务的等待过程结束。In an embodiment, the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to the read operation of the second variable in the second transaction. For the shared memory To determine whether there is a pending task waiting for the end of the process includes multiple pending tasks that have been recorded in, determining whether the variable value of the second variable is returned, and determining whether the variable value of the second variable is returned , It is determined that the waiting process of the second to-be-processed task ends.
在一个实施例中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,对于所述第三缓冲区中已经记录的多个待处理任务,基于各个待处理任务对应的交易编号从小至大的顺序,依次确定各个待处理任务的等待过程是否结束,其中,所述第二待处理任务为首次确定的等待过程结束的待处理任务,其中,所述交易编号对应于交易的预定提交顺序。In one embodiment, for the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes: for multiple pending tasks that have been recorded in the third buffer , Based on the descending order of the transaction number corresponding to each task to be processed, determine in turn whether the waiting process of each task to be processed is over, wherein the second task to be processed is the first determined task to be processed after the waiting process ends, where , The transaction number corresponds to the predetermined submission sequence of the transaction.
在一个实施例中,确定所述第二变量的变量值是否被返回包括,基于在共享内存中的预定地址是否存储有第二变量的变量值,确定所述第二变量的变量值是否被返回,其中,所述预定地址与所述第二交易相对应。In one embodiment, determining whether the variable value of the second variable is returned includes determining whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory , Wherein the predetermined address corresponds to the second transaction.
在一个实施例中,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务包括,在确定所述第三缓冲区中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息和所述第二变量的变量值,继续执行所述第二交易。In one embodiment, in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, based on the execution information corresponding to the second to-be-processed task, continuing to execute the second to-be-processed task includes: When there is a second task to be processed waiting for the process to end in the third buffer, the second transaction is continued to be executed based on the execution information corresponding to the second task to be processed and the variable value of the second variable.
在一个实施例中,所述共享内存中包括第四缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在执行到所述读取操作的代码之后,确定提交顺序在第一交易之前、且未提交的各个交易是否为已执行了对第一变量的写操作的冲突交易,所述各个交易中包括第二交易,在确定所述第二交易为距离第一交易最近的冲突交易的情况中,在第四缓冲区中记录与第一 交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fourth buffer, the first transaction includes a read operation of the first variable, wherein, after a predetermined operation is performed in the process of processing the first transaction, the shared memory Recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the memory includes, after executing the code of the read operation, determining that the submission sequence is before the first transaction, And whether each transaction that has not been submitted is a conflict transaction in which the write operation to the first variable has been performed, and the each transaction includes a second transaction, in the case of determining that the second transaction is the closest conflict transaction to the first transaction In the fourth buffer zone, the first task to be processed corresponding to the first transaction is recorded, wherein the first task to be processed includes the record of the second transaction.
在一个实施例中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于共享内存中记录的当前应提交的交易,确定在所述第四缓冲区中记录的多个待处理任务中是否存在等待过程结束的待处理任务。In one embodiment, for the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes: determining whether there is a transaction that should be submitted currently recorded in the shared memory Whether there is a to-be-processed task waiting for the end of the process among the multiple to-be-processed tasks recorded in the fourth buffer.
在一个实施例中,所述共享内存中包括第五缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在执行到所述读取操作的代码之后,推断提交顺序在第一交易之前、且未提交的各个交易是否为将要对第一变量进行写操作的冲突交易,所述各个交易中包括第二交易,在推断所述第二交易为距离第一交易最近的冲突交易的情况中,在所述第五缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fifth buffer, and the first transaction includes a read operation of the first variable, wherein, after a predetermined operation is performed in the process of processing the first transaction, the shared memory Recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the memory includes, after executing the code of the read operation, inferring that the order of submission is before the first transaction, And whether each transaction that has not been submitted is a conflict transaction that is about to write the first variable, and each transaction includes a second transaction. In the case of inferring that the second transaction is the closest conflict transaction to the first transaction, The first task to be processed corresponding to the first transaction is recorded in the fifth buffer zone, wherein the first task to be processed includes a record of the second transaction.
在一个实施例中,所述共享内存中包括至少一个缓冲区,所述至少一个缓冲区与至少一种待处理任务分别对应,其中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于所述至少一个缓冲区的预定顺序,确定各个缓冲区中是否存在等待过程结束的待处理任务。In one embodiment, the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed respectively, wherein, for multiple tasks to be processed that have been recorded in the shared memory, Determining whether there are pending tasks waiting for the end of the process includes determining whether there are pending tasks waiting for the end of the process in each buffer based on a predetermined sequence of the at least one buffer.
本说明书另一方面提供一种在区块链中并发执行交易的装置,所述装置部署在区块链中的第一节点中的第一执行体中,所述第一节点中当前通过预设的预定数目的执行体并发执行交易,其中包括第一执行体,所述第一执行体当前在处理所述第一交易,所述装置,包括:Another aspect of this specification provides a device for concurrently executing transactions in a blockchain. The device is deployed in a first executor in a first node in the blockchain. A predetermined number of executive bodies concurrently execute transactions, including a first executive body, which is currently processing the first transaction, and the device includes:
记录单元,配置为,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;The recording unit is configured to record, in the shared memory, a first task to be processed corresponding to the first transaction and execution information corresponding to the first task to be processed after a predetermined operation is performed in the process of processing the first transaction, to Enter the waiting process with respect to the first transaction;
确定单元,配置为,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务,所述多个待处理任务由所述预定数目的执行体记录;以及The determining unit is configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks that have been recorded in the shared memory, and the multiple pending tasks are recorded by the predetermined number of executives; as well as
继续执行单元,配置为,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。The continuing execution unit is configured to continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, wherein the The multiple to-be-processed tasks include the second to-be-processed task.
在一个实施例中,所述装置还包括,交易执行单元,配置为,在确定所述多个待处理任务各自的等待过程都未结束的情况中,从共享内存中的第一缓冲区获取待处理的第二交易,并开始执行所述第二交易。In an embodiment, the device further includes a transaction execution unit configured to, in a case where it is determined that the waiting processes of the multiple pending tasks are not finished, obtain the pending tasks from the first buffer in the shared memory. Process the second transaction, and start execution of the second transaction.
在一个实施例中,所述共享内存中包括第二缓冲区,其中,所述记录单元还配置为,在处理完成第一交易之后,在确定第二交易未提交的情况中,在所述第二缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第二交易根据预定提交顺序为所述第一交易的前一个交易。In one embodiment, the shared memory includes a second buffer area, wherein the recording unit is further configured to, after processing the first transaction, in a case where it is determined that the second transaction has not been submitted, in the first transaction The first to-be-processed task corresponding to the first transaction is recorded in the second buffer zone, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission sequence.
在一个实施例中,所述确定单元还配置为,基于共享内存中记录的当前应提交的交易,确定所述第二缓冲区中对应于最小交易编号的待处理任务的等待过程是否结束,以确定所述第二缓冲区中是否存在等待过程结束的待处理任务,其中,所述交易编号对应于交易的提交顺序。In an embodiment, the determining unit is further configured to determine whether the waiting process of the task to be processed corresponding to the smallest transaction number in the second buffer is over based on the transaction currently to be submitted recorded in the shared memory, to It is determined whether there is a task to be processed waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the submission sequence of the transaction.
在一个实施例中,所述继续执行单元还配置为,在确定所述第二缓冲区中的第二待处理任务的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行对第三交易的提交,其中所述第二待处理任务与所述第三交易相对应。In an embodiment, the continuing execution unit is further configured to, in a case where it is determined that the waiting process of the second to-be-processed task in the second buffer is over, based on the execution corresponding to the second to-be-processed task Information, continue to perform the submission of the third transaction, wherein the second pending task corresponds to the third transaction.
在一个实施例中,所述共享内存中包括第三缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元还配置为,在请求对所述第一变量的读取之后,在所述第三缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对所述第一变量的记录。In an embodiment, the shared memory includes a third buffer, and the first transaction includes a read operation of the first variable, wherein the recording unit is further configured to request the first variable After the variable is read, the first to-be-processed task corresponding to the first transaction is recorded in the third buffer, wherein the first to-be-processed task includes a record of the first variable.
在一个实施例中,所述第三缓冲区中包括所述第二待处理任务,所述第二待处理任务与第二交易中对第二变量的读取操作相对应,所述确定单元还配置为,确定所述第二变量的变量值是否被返回,在确定所述第二变量的变量值被返回的情况中,确定该第二待处理任务的等待过程结束。In an embodiment, the third buffer includes the second to-be-processed task, the second to-be-processed task corresponds to a reading operation of the second variable in the second transaction, and the determining unit further It is configured to determine whether the variable value of the second variable is returned, and in a case where it is determined that the variable value of the second variable is returned, it is determined that the waiting process of the second to-be-processed task ends.
在一个实施例中,所述确定单元还配置为,对于所述第三缓冲区中已经记录的多个待处理任务,基于各个待处理任务对应的交易编号从小至大的顺序,依次确定各个待处理任务的等待过程是否结束,其中,所述第二待处理任务为首次确定的等待过程结束的待处理任务,其中,所述交易编号对应于交易的预定提交顺序。In one embodiment, the determining unit is further configured to, for a plurality of pending tasks that have been recorded in the third buffer, determine each pending task in sequence based on the order of the transaction number corresponding to each pending task from small to large. Whether the waiting process of the processing task ends, wherein the second task to be processed is the first determined task to be processed after the waiting process ends, and the transaction number corresponds to the predetermined submission sequence of the transaction.
在一个实施例中,所述确定单元还配置为,基于在共享内存中的预定地址是否存储有第二变量的变量值,确定所述第二变量的变量值是否被返回,其中,所述预定地址与所述第二交易相对应。In an embodiment, the determining unit is further configured to determine whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory, wherein the predetermined The address corresponds to the second transaction.
在一个实施例中,所述继续执行单元还配置为,在确定所述第三缓冲区中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息和所述第二变量的变量值,继续执行所述第二交易。In an embodiment, the continuing execution unit is further configured to, in a case where it is determined that there is a second to-be-processed task waiting for the end of the process in the third buffer, based on the execution corresponding to the second to-be-processed task Information and the variable value of the second variable, continue to execute the second transaction.
在一个实施例中,所述共享内存中包括第四缓冲区,其中,所述记录单元还配置为,在执行到所述读取操作的代码之后,确定提交顺序在第一交易之前、且未提交的各个交易是否为已执行了对第一变量的写操作的冲突交易,所述各个交易中包括第二交易,在确定所述第二交易为距离第一交易最近的冲突交易的情况中,在第四缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fourth buffer area, wherein the recording unit is further configured to, after executing the code of the read operation, determine that the submission sequence is before the first transaction and is not Whether each submitted transaction is a conflict transaction in which a write operation to the first variable has been performed, and each transaction includes a second transaction. In the case of determining that the second transaction is the closest conflict transaction to the first transaction, The first to-be-processed task corresponding to the first transaction is recorded in the fourth buffer zone, wherein the first to-be-processed task includes a record of the second transaction.
在一个实施例中,所述确定单元还配置为,基于共享内存中记录的当前应提交的交易,确定在所述第四缓冲区中记录的多个待处理任务中是否存在等待过程结束的待处理任务。In an embodiment, the determining unit is further configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks recorded in the fourth buffer based on the transaction currently to be submitted recorded in the shared memory. Processing tasks.
在一个实施例中,所述共享内存中包括第五缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元还配置为,在执行到所述读取操作的代码之后,推断提交顺序在第一交易之前、且未提交的各个交易是否为将要对第一变量进行写操作的冲突交易,所述各个交易中包括第二交易,在推断所述第二交易为距离第一交易最近的冲突交易的情况中,在所述第五缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fifth buffer, and the first transaction includes a read operation of the first variable, wherein the recording unit is further configured to: After operating the code, it is inferred whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction that will write the first variable. The each transaction includes a second transaction, and the second transaction is inferred. In the case where the transaction is a conflicting transaction closest to the first transaction, the first pending task corresponding to the first transaction is recorded in the fifth buffer, wherein the first pending task includes a second transaction record of.
在一个实施例中,所述共享内存中包括至少一个缓冲区,所述至少一个缓冲区与至少一种待处理任务分别对应,其中,所述确定单元还配置为,基于所述至少一个缓冲区的预定顺序,确定各个缓冲区中是否存在等待过程结束的待处理任务。In an embodiment, the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the determining unit is further configured to, based on the at least one buffer To determine whether there are pending tasks waiting for the end of the process in each buffer.
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执上述任一项方法。Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to perform any of the above methods.
本说明书另一方面提供一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现上述任一项方法。Another aspect of this specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, any one of the above methods is implemented.
通过根据本说明书实施例的并发执行交易的方案,在执行体执行交易过程中需要等待时记录对该交易的处理信息,并从共享内存中获取其它待处理任务或其它待处理交易进行处理,从而减少了执行体的等待时间,加快了交易并发执行的总体速度。Through the solution of concurrently executing transactions according to the embodiments of this specification, the processing information of the transaction is recorded when the execution body needs to wait while executing the transaction, and other pending tasks or other pending transactions are obtained from the shared memory for processing, thereby It reduces the waiting time of the execution body and speeds up the overall speed of concurrent execution of transactions.
附图说明Description of the drawings
通过结合附图描述本说明书实施例,可以使得本说明书实施例更加清楚:By describing the embodiments of this specification in conjunction with the accompanying drawings, the embodiments of this specification can be made clearer:
图1示出根据本说明书实施例的区块链系统示意图;Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification;
图2示出在区块链中各个节点通过多个线程并发执行交易的示意图;Figure 2 shows a schematic diagram of each node in the blockchain executing transactions concurrently through multiple threads;
图3示出根据本说明书一个实施例的一种在区块链中并发执行交易的方法流程图;Fig. 3 shows a flowchart of a method for concurrently executing transactions in a blockchain according to an embodiment of the present specification;
图4示出根据本说明书一个实施例的一种在区块链中并发执行交易的装置400。Fig. 4 shows a device 400 for concurrently executing transactions in a blockchain according to an embodiment of the present specification.
具体实施方式detailed description
下面将结合附图描述本说明书实施例。The embodiments of this specification will be described below in conjunction with the drawings.
图1示出根据本说明书实施例的区块链系统示意图。如图1所示,所述系统中包括构成区块链的多个节点(图中示意示出6个节点),这些节点两两相连,其中例如包括节点11、节点12和节点13。如本领域技术人员所知,在区块链中,一些节点会收集区块链中的多个交易放入交易池中并竞争记账权。例如图中的节点11通过获取记账权而成为记账节点。节点11在成为记账节点之后会执行其交易池中的多个交易,并将该多个交易打包成区块发送给其它节点,例如发送给节点12。节点12将会对该区块进行验证,并同样地执行该区块中的多个交易。在预定数目个节点对该区块进行验证之后,也即对该区块达到了共识,区块链中的其它节点(例如节点13)将不需要继续对该区块进行验证,而是直接对该区块中的交易进行执行,以更新本地的相关数据。Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification. As shown in FIG. 1, the system includes multiple nodes (six nodes are schematically shown in the figure) constituting a blockchain, and these nodes are connected in pairs, including node 11, node 12, and node 13, for example. As those skilled in the art know, in the blockchain, some nodes collect multiple transactions in the blockchain and put them into the transaction pool and compete for the right to keep accounts. For example, the node 11 in the figure becomes a billing node by acquiring the billing right. After node 11 becomes an accounting node, it will execute multiple transactions in its transaction pool, package the multiple transactions into blocks and send them to other nodes, for example, to node 12. The node 12 will verify the block and execute multiple transactions in the block in the same way. After a predetermined number of nodes verify the block, that is, a consensus on the block is reached, other nodes in the blockchain (such as node 13) will not need to continue to verify the block, but directly The transactions in this block are executed to update local related data.
图2示出在区块链中各个节点通过多个线程并发执行交易的示意图。可以理解,所述线程也可以替换为进程、协程等执行体。如图2中所示,在每个节点中,通常,CPU的数目是有限的,预设的线程的数目也是固定的,例如,假设该节点的CPU数为4个,线程池中预设的线程数目为6个,从而6个线程竞争抢占CPU,并且只有在抢占到CPU之后,才能开始执行任务池中的任务。Figure 2 shows a schematic diagram of each node in the blockchain executing transactions concurrently through multiple threads. It can be understood that the thread can also be replaced by an execution body such as a process and a coroutine. As shown in Figure 2, in each node, usually, the number of CPUs is limited, and the number of preset threads is also fixed. For example, assuming that the number of CPUs of the node is 4, the number of CPUs preset in the thread pool is The number of threads is 6, so that 6 threads compete to preempt the CPU, and only after the CPU is preempted, can the tasks in the task pool begin to be executed.
在多个线程并发执行多个交易的过程中,所述多个交易中可能涉及到对多个变量的计算,在两个交易中不涉及相同的变量的情况中,其执行顺序并不会影响最终的计算结果,而在两个交易中涉及相同的变量的情况中,其执行顺序将会影响最终的计算结果。在本说明书实施例中,为了保证各个节点对多个交易的执行结果是相同的,在并发执行多个交易的同时,考虑交易之间对访问变量的冲突,从而使得并行执行的线程中的一些 线程需要经过等待过程。或者在等待返回访问存储时需要进行等待。In the process of concurrent execution of multiple transactions by multiple threads, the calculation of multiple variables may be involved in the multiple transactions. In the case that the same variables are not involved in the two transactions, the order of execution will not affect The final calculation result, and in the case of two transactions involving the same variables, the order of execution will affect the final calculation result. In the embodiments of this specification, in order to ensure that the execution results of multiple transactions by each node are the same, while multiple transactions are executed concurrently, the conflicts of access variables between transactions are considered, so that some of the threads executed in parallel are The thread needs to go through a waiting process. Or you need to wait while waiting to return to access storage.
如图2中所示,该图中包括第一节点的共享内存,该共享内存中例如包括用于指示待处理交易的缓冲区1,该共享内存是相对于全部线程可读写的。例如,第一缓冲区中当前记录了10个待处理的交易1、2、…10,其中,图中数字1、2、…、10对应的位框中初始应都为1,表示,其都是待处理的交易,其中,交易1~10的编号对应于各个交易的提交顺序。在开始并发执行交易之后,例如,线程1~4分别抢占到CPU1~4,从而,线程1~4可分别从第一缓冲区中获取一个任务进行处理,例如,线程1~4分别开始处理交易1~4,线程1~4在开始处理交易1~4之后,分别将第一缓冲区中交易1~4对应的位分别修改为0,以表示这些交易已经开始执行。可以理解,虽然图中示意示出,线程1抢占到CPU1,并执行交易1,线程2抢占到CPU2,并执行交易2等等,可以理解,图中所示内容仅是为了示意说明,线程的编号、CPU的编号和交易的编号并不是相互对应的,例如,线程1有可能抢占到CPU2,执行交易3等等。As shown in FIG. 2, the graph includes the shared memory of the first node. The shared memory includes, for example, a buffer 1 for indicating transactions to be processed. The shared memory is readable and writable with respect to all threads. For example, there are currently 10 pending transactions 1, 2,...10 recorded in the first buffer. The bit boxes corresponding to the numbers 1, 2,..., 10 in the figure should all be 1, indicating that they are all It is a transaction to be processed, where the serial number of transaction 1-10 corresponds to the order of submission of each transaction. After starting to execute transactions concurrently, for example, threads 1 to 4 preempt CPUs 1 to 4, respectively, so that threads 1 to 4 can respectively obtain a task from the first buffer for processing, for example, threads 1 to 4 start processing transactions respectively 1 to 4. After threads 1 to 4 start to process transactions 1 to 4, they respectively modify the corresponding bits of transactions 1 to 4 in the first buffer to 0 to indicate that these transactions have been executed. It can be understood that although the figure schematically shows that thread 1 preempts CPU1 and executes transaction 1, thread 2 preempts CPU2 and executes transaction 2, etc., it can be understood that the content shown in the figure is only for illustrative purposes. The number, CPU number, and transaction number do not correspond to each other. For example, thread 1 may preempt CPU2, execute transaction 3, and so on.
图2中还示出了用于记录待处理任务的多个缓冲区,缓冲区2~5,其中,每个缓冲区与一种等待过程相对应。例如,缓冲区2与执行完交易等待提交的等待过程相对应,缓冲区3与请求读取以等待返回变量值的等待过程相对应,缓冲区4与在读取前基于变量写入记录等待在前交易提交的等待过程相对应,缓冲区5与在读取前基于交易冲突概率等待在前交易提交或写入的等待过程相对应。在本说明书实施例中,为了并发执行交易,执行交易的过程包括处理交易的过程和提交交易的过程,其中,所述处理交易的过程是将处理交易的结果存储到与该交易对应的缓冲区中,所述提交交易的过程是将最终的处理结果存储到各个交易共用的共享内存中。例如,当线程3处理完交易3之后,为了保证执行各个交易的最终结果一致,需要保证各个交易按照其编号顺序先后提交,因此,交易3需要等待前面的交易2提交之后再提交。在该情况中,线程3在缓冲区2中与交易3对应的位置进行记录,例如将初始的0改为1,然后,线程3到缓冲区中去获取新的任务。例如,线程3可首先检查缓冲区2中有没有等待过程结束的任务。图2中的共享内存中还记录了当前交易窗口,该当前交易窗口例如可由提交完交易的线程进行维护。例如,线程1在提交了交易1之后,可将该交易窗口中的首交易修改为2。从而交易窗口在待提交的多个交易中向后移动一位,当线程根据窗口首位而开始执行一个新交易(例如交易7)时,可将交易窗口中的末交易由6更新为7。在此时,例如,线程3在检查缓冲区2之后,可首先基于所述窗口确定交易2是否为当前应提交的交易。在缓冲区2中没有等待过程结束的任务的情况中,可以检查缓冲区3中有没有等待过程结束 的任务,等等。在缓冲区2~5中都没有等待过程结束的任务的情况中,则可以从缓冲区1中获取待处理的交易,例如交易6。线程3当在执行交易6的过程中也遇到等待过程时,也将到缓冲区2~5中的相应的一个中记录下相应的待处理任务,例如,如图中右侧虚线箭头所示,线程3在缓冲区4中记录与交易6对应的待处理任务。然后,类似地,线程3首先在缓冲区2~5确定有没有等待过程结束的待处理任务。Figure 2 also shows multiple buffers for recording tasks to be processed, buffers 2 to 5, where each buffer corresponds to a waiting process. For example, buffer 2 corresponds to the waiting process of waiting for submission after the transaction is executed, buffer 3 corresponds to the waiting process of requesting a read to wait for the return variable value, and buffer 4 corresponds to the waiting process of writing records based on variables before reading. The waiting process of the previous transaction submission corresponds to the buffer 5 corresponding to the waiting process of waiting for the previous transaction submission or writing based on the transaction conflict probability before reading. In the embodiment of this specification, in order to execute the transaction concurrently, the process of executing the transaction includes the process of processing the transaction and the process of submitting the transaction. The process of processing the transaction is to store the result of the transaction in the buffer corresponding to the transaction. In the process of submitting a transaction, the final processing result is stored in the shared memory shared by each transaction. For example, after thread 3 has processed transaction 3, in order to ensure that the final results of executing each transaction are consistent, it is necessary to ensure that each transaction is submitted in the order of its number. Therefore, transaction 3 needs to wait for the previous transaction 2 to submit before submitting. In this case, thread 3 records the position corresponding to transaction 3 in buffer 2, for example, changing the initial 0 to 1, and then thread 3 goes to the buffer to obtain a new task. For example, thread 3 may first check whether there are tasks in buffer 2 waiting for the end of the process. The shared memory in FIG. 2 also records the current transaction window, and the current transaction window can be maintained by the thread that submitted the transaction, for example. For example, after thread 1 submits transaction 1, the first transaction in the transaction window can be modified to 2. Therefore, the transaction window moves one position backward among the multiple transactions to be submitted. When the thread starts to execute a new transaction (for example, transaction 7) according to the first position of the window, the last transaction in the transaction window can be updated from 6 to 7. At this time, for example, after the thread 3 checks the buffer 2, it may first determine whether the transaction 2 is a transaction that should be submitted currently based on the window. In the case that there is no task waiting for the end of the process in the buffer 2, it can be checked whether there is a task waiting for the end of the process in the buffer 3, and so on. In the case that there is no task waiting for the end of the process in buffers 2 to 5, the transaction to be processed can be obtained from buffer 1, for example, transaction 6. When thread 3 also encounters a waiting process in the process of executing transaction 6, it will also record the corresponding pending task in the corresponding one of buffers 2 to 5, for example, as shown by the dotted arrow on the right side of the figure , Thread 3 records the pending tasks corresponding to transaction 6 in buffer 4. Then, similarly, thread 3 first determines in buffers 2 to 5 whether there are pending tasks waiting for the end of the process.
可以理解,上文对图2的描述只是示意性地,而不是用于限制本说明书实施例的范围。例如,所述缓冲区1~5的具体形式不一定为图中所示形式,只要其能记录下相应的信息即可。下文将详细描述根据本说明书实施例的并发执行交易的过程。It can be understood that the above description of FIG. 2 is only schematic, and is not used to limit the scope of the embodiments of the present specification. For example, the specific forms of the buffers 1 to 5 are not necessarily the forms shown in the figure, as long as they can record corresponding information. Hereinafter, the process of concurrently executing transactions according to the embodiments of the present specification will be described in detail.
图3示出根据本说明书一个实施例的一种在区块链中并发执行交易的方法流程图,所述方法在区块链中的第一节点执行,所述第一节点中预设有第一执行体,所述第一执行体当前在处理第一交易,所述方法由所述第一执行体执行,包括:Figure 3 shows a flow chart of a method for concurrently executing transactions in a blockchain according to an embodiment of the present specification. The method is executed on a first node in the blockchain, and the first node is preset with a first node. An executive body, the first executive body is currently processing a first transaction, and the method is executed by the first executive body, including:
步骤S302,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;Step S302: After a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory, so as to compare all The first transaction enters the waiting process;
步骤S304,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务;以及Step S304, for the multiple pending tasks that have been recorded in the shared memory, it is determined whether there are pending tasks waiting for the end of the process; and
步骤S306,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。Step S306: In the case where it is determined that the waiting process corresponding to the second to-be-processed task is over, continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task, wherein the plurality of to-be-processed tasks The tasks include the second to-be-processed task.
首先,在步骤S302,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程。First, in step S302, after a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory to Enter the waiting process with respect to the first transaction.
如上文中参考图2所述,所述第一执行体例如可以为线程、进程、协程等执行主体,所述共享内存相对于用于并发执行交易的多个执行体是共享的。下文中将以线程为例进行说明。As described above with reference to FIG. 2, the first executive body may be, for example, an executive body such as a thread, a process, or a coroutine, and the shared memory is shared with respect to multiple executive bodies used to execute transactions concurrently. In the following, thread will be used as an example.
在节点中并发执行交易的过程中,对于其中一个正在执行的交易,可能会包括多个等待过程,所述等待过程可能是由于不同的原因引起的。In the process of concurrently executing transactions in nodes, for one of the transactions being executed, multiple waiting processes may be included, and the waiting processes may be caused by different reasons.
在一个实施例中,如上文中参考图2中所述,所述多个并发执行的交易已经预设了 预定的提交顺序,例如图2中的交易1~10必须按照其编号的从小到大的顺序进行先后提交,以保证各个节点对该多个交易的执行结果是相同的。这里,在节点中,线程在执行交易时,将处理结果先保存到仅与该交易对应的缓冲区中,而在提交之后,才将该执行结果保存到各个交易共用的共享内存中。例如,在处理第一交易的过程中,需要对第一变量进行写操作,则在仅与第一交易对应的缓冲区中先保存该写操作之后的第一变量的值,该值仅在处理该第一交易时可以使用,在处理其它交易时并不会对该值进行读写。而在提交第一交易之后,第一交易的值被存到共享内存中,其它交易也可以读取到该值,或者通过提交对该值进行修改。In one embodiment, as described above with reference to Figure 2, the multiple concurrently executed transactions have preset a predetermined submission order. For example, transactions 1 to 10 in Figure 2 must be numbered from small to large. Submit in order to ensure that the execution results of the multiple transactions by each node are the same. Here, in the node, when the thread executes the transaction, the processing result is first saved in the buffer corresponding to the transaction, and after submission, the execution result is saved in the shared memory shared by each transaction. For example, in the process of processing the first transaction, the first variable needs to be written, and the value of the first variable after the write operation is first saved in the buffer corresponding to only the first transaction. It can be used in the first transaction, and the value will not be read or written when processing other transactions. After the first transaction is submitted, the value of the first transaction is stored in the shared memory, and other transactions can also read the value or modify the value by submitting it.
由于各个交易具有预定的提交顺序,因此,如图2中所示,例如所述第一交易为图2中的交易6,则第一执行体为图中的线程3。如果线程3在处理完交易6之后,交易6之前的交易还未提交,此时,线程3需要等待交易5提交完成之后才能进行对交易6的提交。这里,线程3可基于共享内存中预设的交易窗口参数确定交易5是否提交。通过该交易窗口控制可同时并发执行的交易的最大总数,该交易窗口的两边分别是当前并发执行的编号最小的交易和编号最大的交易,例如图2中的1和6表示当前并发执行的交易为交易1~6。从而,通过确定交易5是否为交易窗口中的最小交易,从而确定交易5当前是否应提交。在该情况中,线程3可如图2中所示,将缓冲区2中的与交易6对应的位修改为1,以添加一个与交易6对应的待处理任务,该待处理任务只有等到交易5提交之后才可以继续执行,同时,可将与该待处理任务对应的执行信息,也即交易6的当前处理信息存储到该共享内存中的例如与各个交易分别对应的执行信息缓冲区中。Since each transaction has a predetermined submission sequence, as shown in FIG. 2, for example, the first transaction is transaction 6 in FIG. 2, and the first executive body is thread 3 in the figure. If thread 3 finishes processing transaction 6 and the transaction before transaction 6 has not been submitted, at this time, thread 3 needs to wait for the completion of transaction 5 submission before submitting transaction 6. Here, the thread 3 may determine whether the transaction 5 is submitted based on the preset transaction window parameters in the shared memory. The transaction window controls the maximum total number of transactions that can be executed concurrently. The two sides of the transaction window are the transaction with the smallest number and the transaction with the largest number that are currently executed concurrently. For example, 1 and 6 in Figure 2 represent the current concurrently executed transactions. For transactions 1~6. Thus, by determining whether transaction 5 is the smallest transaction in the transaction window, it is determined whether transaction 5 should be submitted currently. In this case, thread 3 can modify the bit corresponding to transaction 6 in buffer 2 to 1, as shown in Figure 2, to add a pending task corresponding to transaction 6, which can only wait until the transaction 5 After submission, execution can continue. At the same time, the execution information corresponding to the task to be processed, that is, the current processing information of transaction 6, can be stored in the shared memory, for example, in the execution information buffer corresponding to each transaction.
在一个实施例中,交易6中包括对变量k1的读取操作,线程3在开始执行该读取操作的代码之后,向用于读取变量的硬件或线程发出对变量k1的读取请求,之后在图2中所示的缓冲区3中的与交易6对应的字节中记录“k1”,以添加一个与交易6对应的待处理任务,该待处理任务在等到变量k1的值返回之后才继续执行。In one embodiment, transaction 6 includes a read operation on variable k1, and thread 3 sends a read request for variable k1 to the hardware or thread used to read the variable after starting to execute the code for the read operation. Then record "k1" in the byte corresponding to transaction 6 in the buffer 3 shown in Figure 2 to add a pending task corresponding to transaction 6, and the pending task waits until the value of the variable k1 returns Before continuing.
在一个实施例中,交易6中包括对变量k1的读取操作,线程3在开始执行该读取操作的代码之后,查询共享内存中的写入缓冲区,该写入缓冲区中记录了当前对各个交易的处理过程中对各个变量(包括变量k1)的写入情况。例如,写入缓冲区中仅记录了交易4对变量k1进行了写入,未记录交易5对变量k1的写入。由于,基于该记录,交易4在提交之后将改变共享内存中的变量表中的k1的值,因此,交易6需要在等待交易4提交之后再读取该变量k1的值,否则将读取错误的k1的值。线程3在进行该对写入缓冲区的检查之后,在图2中的缓冲区3中的与交易6对应的字节中记录“4”,以添加 一个与交易6对应的待处理任务,所述“4”与交易4相对应,表示该待处理任务在等到交易4提交之后才可以继续执行。In one embodiment, transaction 6 includes a read operation on variable k1. After thread 3 starts to execute the code for the read operation, it queries the write buffer in the shared memory, and the write buffer records the current The writing status of each variable (including variable k1) during the processing of each transaction. For example, the write buffer only records that transaction 4 writes to variable k1, and transaction 5 writes to variable k1 is not recorded. Because, based on this record, transaction 4 will change the value of k1 in the variable table in the shared memory after submission, therefore, transaction 6 needs to wait for transaction 4 to submit before reading the value of the variable k1, otherwise it will read the error The value of k1. After thread 3 checks the write buffer, it records "4" in the byte corresponding to transaction 6 in buffer 3 in Figure 2 to add a pending task corresponding to transaction 6, so The "4" corresponds to transaction 4, which means that the pending task can only be executed after transaction 4 is submitted.
在一个实施例中,交易6中包括对变量k1的读取操作。线程3在开始执行该读取操作的代码之后,推断正在并发执行的多个交易中提交顺序在交易6之前的各个交易(例如图2中的交易1~5)是否将要对变量k1进行写操作。在一种方法中,可预先基于该节点中的交易执行历史,确定各个变量的交易冲突概率,当变量k1的交易冲突概率大于预定阈值时,则可推断交易1~5都将要对变量k1进行写操作,从而,需要等交易5提交之后,再进行交易6中的读取操作,如果交易5在处理过程中将对k1的写入值写入共享内存中与交易5对应的缓冲区(该缓冲区不是与各个交易对应的变量表)中,则可等交易5执行完对k1的写入后,进行对k1的读取。在一种方法中,线程3可基于交易6前面各个交易的交易数据,确定交易6与前面各个交易的冲突概率,并基于该冲突概率,推断所述各个交易是否将要对k1进行写操作,从而确定是否等待该交易的提交或写入。例如,在确定交易4对k1的写入概率大于等于预定阈值、且交易5对k1的写入概率小于预定阈值的情况中,线程3在图2中的缓冲区5中与交易6对应的字节中记录“4”,以记录一个与交易6对应的待执行任务,该待执行任务只有等到交易4提交或写入之后才可以继续执行。In one embodiment, transaction 6 includes a read operation on variable k1. After thread 3 starts to execute the code for the read operation, it infers whether each transaction (for example, transactions 1 to 5 in Figure 2) that is submitted in the order of submission before transaction 6 among multiple transactions being executed concurrently will write to variable k1 . In one method, the transaction conflict probability of each variable can be determined in advance based on the transaction execution history in the node. When the transaction conflict probability of variable k1 is greater than a predetermined threshold, it can be inferred that transactions 1 to 5 will be performed on variable k1. Write operation. Therefore, after transaction 5 is submitted, the read operation in transaction 6 should be performed. If transaction 5 writes the value written to k1 into the buffer corresponding to transaction 5 in the shared memory during processing (the If the buffer is not in the variable table corresponding to each transaction), then after transaction 5 finishes writing to k1, read k1. In one method, thread 3 can determine the conflict probability between transaction 6 and each previous transaction based on the transaction data of each transaction before transaction 6, and based on the conflict probability, infer whether each transaction will write k1, thereby Determine whether to wait for the submission or writing of the transaction. For example, in the case where it is determined that the write probability of transaction 4 to k1 is greater than or equal to a predetermined threshold, and the write probability of transaction 5 to k1 is less than the predetermined threshold, thread 3 in the buffer 5 in FIG. 2 corresponds to the word of transaction 6 Record "4" in the section to record a task to be executed corresponding to transaction 6. The task to be executed can only be executed after transaction 4 is submitted or written.
上文虽然列举了四种等待情况,然而,本说明书实施例中的等待情况不限于上述四种情况,而是可以为任意由预定操作触发的等待情况。Although four waiting conditions are listed above, the waiting conditions in the embodiments of this specification are not limited to the above four conditions, but may be any waiting conditions triggered by a predetermined operation.
在步骤S304,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务。In step S304, for the multiple pending tasks that have been recorded in the shared memory, it is determined whether there are pending tasks waiting for the end of the process.
如上文中所述,所述共享内存中包括缓冲区2~5,其中分别记录了不同类型的待处理任务。例如,线程3在通过上述步骤S302在共享内存中存入与交易6对应的第一待处理任务之后,线程3以预定顺序检查共享内存中的缓冲区2~5,以用于获取其中的等待过程结束的待处理任务。可以理解,在图2中,所述缓冲区2~5中的待处理任务可以是由线程1~4中任一线程记录的待处理任务。As described above, the shared memory includes buffers 2 to 5, in which different types of pending tasks are recorded respectively. For example, after thread 3 stores the first pending task corresponding to transaction 6 in the shared memory through the above step S302, thread 3 checks the buffers 2 to 5 in the shared memory in a predetermined order to obtain the waiting The pending task at the end of the process. It can be understood that, in FIG. 2, the tasks to be processed in the buffers 2 to 5 may be tasks to be processed recorded by any of the threads 1 to 4.
例如,首先,线程3可首先检查缓冲区2。如上文所述,缓冲区2中记录的各个待处理任务与处理完成等待提交的交易相对应。例如,如图2所示,在缓冲区2中,可确定对应位为1的最小交易为交易2,线程3可基于共享内存中的交易窗口确定当前应提交的交易是否为交易2,如果当前应提交的交易为交易2,则表示与交易2对应的该待 处理任务等待过程结束,线程3可从共享内存中的用于存储交易执行信息的缓冲区中获取与交易2对应的执行信息,并基于该执行信息继续执行交易2,即进行对交易2的提交。For example, first, thread 3 may check buffer 2 first. As described above, each pending task recorded in the buffer 2 corresponds to a transaction that has been processed and is waiting to be submitted. For example, as shown in Figure 2, in buffer 2, the smallest transaction with a corresponding bit of 1 can be determined as transaction 2, and thread 3 can determine whether the transaction that should be submitted is transaction 2 based on the transaction window in the shared memory. The transaction that should be submitted is transaction 2, which means that the waiting process of the pending task corresponding to transaction 2 is over. Thread 3 can obtain the execution information corresponding to transaction 2 from the buffer for storing transaction execution information in the shared memory. And continue to execute transaction 2 based on the execution information, that is, submit the transaction 2.
在线程3在缓冲区2中没有发现等待过程结束的待处理任务的情况中,线程3例如可检查缓冲区3。如上文所述,缓冲区3中记录的各个待处理任务都在等待相应变量值的返回。例如,缓冲区3中的与交易2对应的字节中记录有“k2”,则表示交易2在等待变量k2的值的返回。线程3可从与交易2对应的共享内存中的预定地址中确定是否已写入k2的值,在k2的值被写入的情况中,则表示与交易2对应的该待处理任务的等待过程结束,其中,所述预定地址与所述交易2相对应。其中,该k2的值可由执行读取操作的其它线程在该地址写入。在确定k2的值未被写入的情况中,可对交易2之后的待处理任务确定等待过程是否结束。例如,交易3对应的字节中记录了“k1”,则可在与交易3对应的预定地址确定是否已写入k1的值。In the case that the thread 3 does not find a pending task waiting for the end of the process in the buffer 2, the thread 3 may check the buffer 3, for example. As mentioned above, each pending task recorded in the buffer 3 is waiting for the return of the corresponding variable value. For example, if "k2" is recorded in the byte corresponding to transaction 2 in buffer 3, it means that transaction 2 is waiting for the return of the value of variable k2. Thread 3 can determine whether the value of k2 has been written from the predetermined address in the shared memory corresponding to transaction 2. When the value of k2 is written, it indicates the waiting process of the pending task corresponding to transaction 2 End, wherein the predetermined address corresponds to the transaction 2. Among them, the value of k2 can be written at this address by other threads performing read operations. In the case where it is determined that the value of k2 has not been written, it can be determined whether the waiting process is over for the tasks to be processed after transaction 2. For example, if "k1" is recorded in the byte corresponding to transaction 3, it can be determined whether the value of k1 has been written in the predetermined address corresponding to transaction 3.
在线程3在缓冲区2和3中都没有发现等待过程结束的待处理任务的情况中,线程3例如可检查缓冲区4。如上文所述,缓冲区4中记录的待处理任务对应于基于写入情况等待其它交易提交以进行读取操作的交易。与检查缓冲区2类似地,线程3可基于共享内存中的交易窗口,确定例如交易2等待的交易1是否提交,在确定交易1提交的情况中,则与交易2对应的待处理任务的等待过程结束。在确定交易1未提交的情况中,线程3可以确定对应于交易2之后的交易的待处理任务的等待过程是否结束,例如可确定交易3对应的等待过程是否结束。In the case that thread 3 does not find a pending task waiting for the end of the process in both buffers 2 and 3, thread 3 may check buffer 4, for example. As described above, the pending tasks recorded in the buffer 4 correspond to transactions that wait for other transactions to be submitted for read operations based on write conditions. Similar to checking buffer 2, thread 3 can determine whether transaction 1 waiting for transaction 2 is submitted based on the transaction window in shared memory. In the case where transaction 1 is determined to be submitted, the pending task corresponding to transaction 2 is waiting The process is over. In the case where it is determined that the transaction 1 has not been submitted, the thread 3 can determine whether the waiting process of the task to be processed corresponding to the transaction after the transaction 2 has ended, for example, it can determine whether the waiting process corresponding to the transaction 3 has ended.
在线程3在缓冲区2~4都没有发现等待过程结束的待处理任务的情况中,线程3例如可检查缓冲区5。如上文所述,缓冲区5中记录的待处理任务对应于基于冲突概率等待其它交易提交或写入以进行读取操作的交易。线程3可类似地确定交易2等待的交易1是否提交,或者可基于交易1在处理过程中在共享内存中写入的变量值,确定与交易2对应的待处理任务的等待过程是否结束。In the case that the thread 3 does not find any pending tasks waiting for the end of the process in the buffers 2 to 4, the thread 3 may check the buffer 5, for example. As described above, the pending tasks recorded in the buffer 5 correspond to transactions waiting for other transactions to be submitted or written for read operations based on the conflict probability. The thread 3 can similarly determine whether the transaction 1 waiting for the transaction 2 is submitted, or can determine whether the waiting process of the pending task corresponding to the transaction 2 is over based on the variable value written in the shared memory during the processing of the transaction 1 or not.
可以理解,上述共享内存中包括的缓冲区2~5仅仅是示意性地,而不是限制性的,上述检查缓冲区的顺序仅是示意性地,而不是限制性,在具体实施中,可根据场景的需要设置缓冲区、以及检查缓冲区的顺序。It can be understood that the buffers 2 to 5 included in the shared memory are only illustrative and not restrictive, and the sequence of checking the buffers is only illustrative and not restrictive. In specific implementation, it can be based on The scene needs to set up the buffer and check the order of the buffer.
在一个实施例中,在缓冲区2~5中都未检查到等待过程结束的待处理任务的情况中,线程3可检查图2中所示的共享内存中的缓冲区1,该缓冲区1中记录了待处理的交易, 从而,线程3可以从该缓冲区1中获取编号最小的待处理交易(例如交易6),并开始执行该交易。In one embodiment, in the case that no pending task waiting for the end of the process is checked in the buffers 2 to 5, the thread 3 may check the buffer 1 in the shared memory shown in FIG. 2, and the buffer 1 The transaction to be processed is recorded in, so that the thread 3 can obtain the transaction to be processed with the smallest number (for example, transaction 6) from the buffer 1, and start to execute the transaction.
在步骤S306,在确定所述共享内存中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务。In step S306, in the case where it is determined that there is a second to-be-processed task waiting for the end of the process in the shared memory, continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task.
在一个实施例中,线程3在缓冲区2中获取等待过程结束的第二待处理任务,则线程3基于对应的执行信息,继续执行对该第二待处理任务对应的交易的提交。线程3在确定该第二待处理任务的等待过程结束之后,将缓冲区中相应的第二待处理任务去除,例如将缓冲区2中的第二待处理任务对应的“1”修改为0。In one embodiment, the thread 3 obtains the second to-be-processed task whose waiting process ends in the buffer 2, and then the thread 3 continues to execute the submission of the transaction corresponding to the second to-be-processed task based on the corresponding execution information. After the thread 3 determines that the waiting process of the second to-be-processed task ends, it removes the corresponding second to-be-processed task in the buffer, for example, changes the “1” corresponding to the second to-be-processed task in the buffer 2 to 0.
在一个实施例中,线程3在缓冲区3中获取第二待处理任务,则线程3基于相应的执行信息和相应的变量的值,继续执行相应的交易中读取操作后面的操作。In one embodiment, the thread 3 obtains the second task to be processed in the buffer 3, and the thread 3 continues to perform the operations following the read operation in the corresponding transaction based on the corresponding execution information and the value of the corresponding variable.
在一个实施例中,线程3在缓冲区4中获取第二待处理任务,则线程3基于相应的执行信息,继续执行相应的交易中的相应读取操作。In one embodiment, the thread 3 obtains the second task to be processed in the buffer 4, and the thread 3 continues to execute the corresponding read operation in the corresponding transaction based on the corresponding execution information.
在一个实施例中,线程3在缓冲区5中获取第二待处理任务,则线程3基于相应的执行信息,继续执行相应的交易中的相应读取操作。In one embodiment, the thread 3 obtains the second task to be processed in the buffer 5, and the thread 3 continues to execute the corresponding read operation in the corresponding transaction based on the corresponding execution information.
图4示出根据本说明书一个实施例的本说明书另一方面提供一种在区块链中并发执行交易的装置400,所述装置部署在区块链中的第一节点中的第一执行体中,所述第一节点中当前通过预设的预定数目的执行体并发执行交易,其中包括第一执行体,所述第一执行体当前在处理第一交易,所述装置,包括:FIG. 4 shows another aspect of this specification according to an embodiment of the specification provides a device 400 for concurrently executing transactions in a blockchain, the device being deployed in the first execution body of the first node in the blockchain In the first node, the transaction is currently executed concurrently through a preset predetermined number of executive bodies, including a first executive body, and the first executive body is currently processing a first transaction, and the device includes:
记录单元41,配置为,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;The recording unit 41 is configured to record, in the shared memory, a first task to be processed corresponding to the first transaction and execution information corresponding to the first task to be processed after a predetermined operation is performed in the process of processing the first transaction, To enter the waiting process relative to the first transaction;
确定单元42,配置为,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务,所述多个待处理任务由所述预定数目的执行体记录;以及The determining unit 42 is configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks that have been recorded in the shared memory, and the multiple pending tasks are recorded by the predetermined number of executives. ;as well as
继续执行单元43,配置为,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。The continuing execution unit 43 is configured to continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, wherein The multiple to-be-processed tasks include the second to-be-processed task.
在一个实施例中,所述装置还包括,交易执行单元44,配置为,在确定所述多个待处理任务各自的等待过程都未结束的情况中,从共享内存中的第一缓冲区获取待处理的第二交易,并开始执行所述第二交易。In one embodiment, the device further includes a transaction execution unit 44 configured to obtain from the first buffer in the shared memory when it is determined that the respective waiting processes of the multiple pending tasks have not ended. The second transaction to be processed, and the execution of the second transaction is started.
在一个实施例中,所述共享内存中包括第二缓冲区,其中,所述记录单元41还配置为,在处理完成第一交易之后,在确定第二交易未提交的情况中,在所述第二缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第二交易根据预定提交顺序为所述第一交易的前一个交易。In an embodiment, the shared memory includes a second buffer area, wherein the recording unit 41 is further configured to, after processing the first transaction, in a case where it is determined that the second transaction has not been submitted, in the The first to-be-processed task corresponding to the first transaction is recorded in the second buffer zone, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission sequence.
在一个实施例中,所述确定单元42还配置为,基于共享内存中记录的当前应提交的交易,确定所述第二缓冲区中对应于最小交易编号的待处理任务的等待过程是否结束,以确定所述第二缓冲区中是否存在等待过程结束的待处理任务,其中,所述交易编号对应于交易的提交顺序。In one embodiment, the determining unit 42 is further configured to determine whether the waiting process of the task to be processed corresponding to the smallest transaction number in the second buffer is over based on the transaction currently to be submitted recorded in the shared memory, To determine whether there is a task to be processed waiting for the end of the process in the second buffer zone, wherein the transaction number corresponds to the submission sequence of the transaction.
在一个实施例中,所述继续执行单元43还配置为,在确定所述第二缓冲区中的第二待处理任务的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行对第三交易的提交,其中所述第二待处理任务与所述第三交易相对应。In one embodiment, the continued execution unit 43 is further configured to, in a case where it is determined that the waiting process of the second to-be-processed task in the second buffer is over, based on the corresponding to the second to-be-processed task Execution information, continue to execute the submission of the third transaction, wherein the second pending task corresponds to the third transaction.
在一个实施例中,所述共享内存中包括第三缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元41还配置为,在请求对所述第一变量的读取之后,在所述第三缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对所述第一变量的记录。In an embodiment, the shared memory includes a third buffer area, and the first transaction includes a read operation of the first variable, wherein the recording unit 41 is further configured to: upon request, the first variable is read. After a variable is read, the first to-be-processed task corresponding to the first transaction is recorded in the third buffer, wherein the first to-be-processed task includes a record of the first variable.
在一个实施例中,所述第三缓冲区中包括所述第二待处理任务,所述第二待处理任务与第二交易中对第二变量的读取操作相对应,所述确定单元42还配置为,确定所述第二变量的变量值是否被返回,在确定所述第二变量的变量值被返回的情况中,确定该第二待处理任务的等待过程结束。In one embodiment, the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to the reading operation of the second variable in the second transaction, and the determining unit 42 It is also configured to determine whether the variable value of the second variable is returned, and in a case where it is determined that the variable value of the second variable is returned, it is determined that the waiting process of the second to-be-processed task ends.
在一个实施例中,所述确定单元42还配置为,对于所述第三缓冲区中已经记录的多个待处理任务,基于各个待处理任务对应的交易编号从小至大的顺序,依次确定各个待处理任务的等待过程是否结束,其中,所述第二待处理任务为首次确定的等待过程结束的待处理任务,其中,所述交易编号对应于交易的预定提交顺序。In an embodiment, the determining unit 42 is further configured to, for the multiple pending tasks that have been recorded in the third buffer, determine each of the pending tasks in the descending order based on the transaction number corresponding to each pending task. Whether the waiting process of the task to be processed is completed, wherein the second task to be processed is the first determined task to be processed after the waiting process has ended, and the transaction number corresponds to the predetermined submission sequence of the transaction.
在一个实施例中,所述确定单元42还配置为,基于在共享内存中的预定地址是否存储有第二变量的变量值,确定所述第二变量的变量值是否被返回,其中,所述预定地址与所述第二交易相对应。In an embodiment, the determining unit 42 is further configured to determine whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory, wherein the The predetermined address corresponds to the second transaction.
在一个实施例中,所述继续执行单元43还配置为,在确定所述第三缓冲区中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息和所述第二变量的变量值,继续执行所述第二交易。In one embodiment, the continued execution unit 43 is further configured to, in a case where it is determined that there is a second to-be-processed task waiting for the end of the process in the third buffer, based on the data corresponding to the second to-be-processed task The execution information and the variable value of the second variable continue to execute the second transaction.
在一个实施例中,所述共享内存中包括第四缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元41还配置为,在执行到所述读取操作的代码之后,确定提交顺序在第一交易之前、且未提交的各个交易是否为已执行了对第一变量的写操作的冲突交易,所述各个交易中包括第二交易,在确定所述第二交易为距离第一交易最近的冲突交易的情况中,在第四缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fourth buffer, and the first transaction includes a read operation of the first variable, wherein the recording unit 41 is further configured to: After fetching the code of the operation, it is determined whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction in which the write operation to the first variable has been performed, and each transaction includes the second transaction. In the case where the second transaction is the conflicting transaction closest to the first transaction, the first pending task corresponding to the first transaction is recorded in the fourth buffer, wherein the first pending task includes the second The record of the transaction.
在一个实施例中,所述确定单元42还配置为,基于共享内存中记录的当前应提交的交易,确定在所述第四缓冲区中记录的多个待处理任务中是否存在等待过程结束的待处理任务。In an embodiment, the determining unit 42 is further configured to determine whether there is a waiting process to be completed among the multiple pending tasks recorded in the fourth buffer based on the currently submitted transaction recorded in the shared memory. Pending tasks.
在一个实施例中,所述共享内存中包括第五缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元41还配置为,在执行到所述读取操作的代码之后,推断提交顺序在第一交易之前、且未提交的各个交易是否为将要对第一变量进行写操作的冲突交易,所述各个交易中包括第二交易,在推断所述第二交易为距离第一交易最近的冲突交易的情况中,在所述第五缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。In one embodiment, the shared memory includes a fifth buffer, and the first transaction includes a read operation of the first variable, wherein the recording unit 41 is further configured to: After fetching the code of the operation, it is inferred whether each transaction whose submission order is before the first transaction and is not submitted is a conflict transaction that will write the first variable. Each transaction includes the second transaction. In the case where the second transaction is the closest conflict transaction to the first transaction, the first pending task corresponding to the first transaction is recorded in the fifth buffer, wherein the first pending task includes The record of the transaction.
在一个实施例中,所述共享内存中包括至少一个缓冲区,所述至少一个缓冲区与至少一种待处理任务分别对应,其中,所述确定单元42还配置为,基于所述至少一个缓冲区的预定顺序,确定各个缓冲区中是否存在等待过程结束的待处理任务。In an embodiment, the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the determining unit 42 is further configured to, based on the at least one buffer The predetermined sequence of zones determines whether there are pending tasks waiting for the end of the process in each buffer.
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执上述任一项方法。Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to perform any of the above methods.
本说明书另一方面提供一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现上述任一项方法。Another aspect of this specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, any one of the above methods is implemented.
通过根据本说明书实施例的并发执行交易的方案,在执行体执行交易过程中需要等待时记录对该交易的处理信息,并从共享内存中获取其它待处理任务或其它待处理交易进行处理,从而减少了执行体的等待时间,加快了交易并发执行的总体速度。Through the solution of concurrently executing transactions according to the embodiments of this specification, the processing information of the transaction is recorded when the execution body needs to wait while executing the transaction, and other pending tasks or other pending transactions are obtained from the shared memory for processing, thereby It reduces the waiting time of the execution body and speeds up the overall speed of concurrent execution of transactions.
需要理解,本文中的“第一”,“第二”等描述,仅仅为了描述的简单而对相似概念进行区分,并不具有其他限定作用。It should be understood that the descriptions of "first", "second", etc. in this article are merely to distinguish similar concepts for the sake of simplicity of description, and do not have other limiting effects.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than in the embodiments and still achieve desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown in order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
本领域普通技术人员应该还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执轨道,取决于技术方案的特定应用和设计约束条件。本领域普通技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art should be further aware that the units and algorithm steps of the examples described in the embodiments disclosed herein can be implemented by electronic hardware, computer software or a combination of the two, in order to clearly illustrate the hardware For the interchangeability with software, the composition and steps of each example have been described generally in terms of function in the above description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of the present application.
结合本文中所公开的实施例描述的方法或算法的步骤可以用硬件、处理器执轨道的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of the method or algorithm described in combination with the embodiments disclosed in this document can be implemented by hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or all areas in the technical field. Any other known storage media.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific embodiments of the present invention, and are not intended to limit the scope of the present invention. The protection scope, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims (30)

  1. 一种在区块链中并发执行交易的方法,所述方法在区块链中的第一节点执行,所述第一节点中当前通过预设的预定数目的执行体并发执行交易,所述预定数目的执行体中包括第一执行体,所述第一执行体当前在处理第一交易,所述方法由所述第一执行体执行,包括:A method for concurrently executing transactions in a blockchain. The method is executed at a first node in the blockchain. The first node currently executes transactions concurrently through a preset predetermined number of executive entities. The predetermined The number of executive bodies includes a first executive body, which is currently processing a first transaction, and the method is executed by the first executive body, including:
    在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;After a predetermined operation is performed in the process of processing the first transaction, the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task are recorded in the shared memory so as to be relative to the first to-be-processed task. The transaction enters the waiting process;
    对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务,所述多个待处理任务由所述预定数目的执行体记录;以及For the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process, and the multiple pending tasks are recorded by the predetermined number of executives; and
    在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。In the case where it is determined that the waiting process corresponding to the second to-be-processed task ends, the second to-be-processed task is continued to be executed based on the execution information corresponding to the second to-be-processed task, wherein the multiple to-be-processed tasks include The second task to be processed.
  2. 根据权利要求1所述的方法,还包括,在确定所述多个待处理任务各自的等待过程都未结束的情况中,从共享内存中的第一缓冲区获取待处理的第二交易,并开始执行所述第二交易。The method according to claim 1, further comprising, in the case where it is determined that the respective waiting processes of the plurality of to-be-processed tasks are not finished, obtaining the second transaction to be processed from the first buffer in the shared memory, and Start the execution of the second transaction.
  3. 根据权利要求1所述的方法,其中,所述共享内存中包括第二缓冲区,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在处理完成第一交易之后,在确定第二交易未提交的情况中,在所述第二缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第二交易根据预定提交顺序为所述第一交易的前一个交易。The method according to claim 1, wherein the shared memory includes a second buffer, wherein after a predetermined operation is performed in the process of processing the first transaction, the first transaction corresponding to the first transaction is recorded in the shared memory. The to-be-processed task and the execution information corresponding to the first to-be-processed task include, after processing the first transaction, in the case where it is determined that the second transaction has not been submitted, recording the first transaction in the second buffer The corresponding first task to be processed, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission order.
  4. 根据权利要求3所述的方法,其中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于共享内存中记录的当前应提交的交易,确定所述第二缓冲区中对应于最小交易编号的待处理任务的等待过程是否结束,以确定所述第二缓冲区中是否存在等待过程结束的待处理任务,其中,所述交易编号对应于交易的提交顺序。The method according to claim 3, wherein, for the plurality of pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes, based on the current transactions recorded in the shared memory that should be submitted , Determine whether the waiting process of the task to be processed corresponding to the smallest transaction number in the second buffer is over, to determine whether there is a task to be processed in the second buffer that has the end of the waiting process, wherein the transaction number corresponds to The order of submission of the transaction.
  5. 根据权利要求4所述的方法,其中,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务包括,在确定所述第二缓冲区中的第二待处理任务的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行对第三交易的提交,其中所述第二待处理任 务与所述第三交易相对应。The method according to claim 4, wherein, in a case where it is determined that the waiting process corresponding to the second to-be-processed task ends, continuing to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task comprises , In the case of determining that the waiting process of the second to-be-processed task in the second buffer is over, continue to perform the submission of the third transaction based on the execution information corresponding to the second to-be-processed task, wherein the The second pending task corresponds to the third transaction.
  6. 根据权利要求1所述的方法,其中,所述共享内存中包括第三缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在请求对所述第一变量的读取之后,在所述第三缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对所述第一变量的记录。The method according to claim 1, wherein the shared memory includes a third buffer, the first transaction includes a read operation of a first variable, and wherein the predetermined is performed in the process of processing the first transaction After the operation, recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the shared memory includes, after requesting the reading of the first variable, in the The first to-be-processed task corresponding to the first transaction is recorded in the third buffer, wherein the first to-be-processed task includes a record of the first variable.
  7. 根据权利要求6所述的方法,其中,所述第三缓冲区中包括所述第二待处理任务,所述第二待处理任务与第二交易中对第二变量的读取操作相对应,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任包括,确定所述第二变量的变量值是否被返回,在确定所述第二变量的变量值被返回的情况中,确定该第二待处理任务的等待过程结束。The method according to claim 6, wherein the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to a reading operation of a second variable in a second transaction, For the multiple pending tasks that have been recorded in the shared memory, determining whether there are any pending tasks waiting for the end of the process includes determining whether the variable value of the second variable is returned, and determining whether the variable of the second variable is returned. In the case where the value is returned, it is determined that the waiting process of the second to-be-processed task ends.
  8. 根据权利要求7所述的方法,其中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,对于所述第三缓冲区中已经记录的多个待处理任务,基于各个待处理任务对应的交易编号从小至大的顺序,依次确定各个待处理任务的等待过程是否结束,其中,所述第二待处理任务为首次确定的等待过程结束的待处理任务,其中,所述交易编号对应于交易的预定提交顺序。The method according to claim 7, wherein, for the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes: Multiple pending tasks, based on the descending order of the transaction number corresponding to each pending task, determine in turn whether the waiting process of each pending task is over, wherein, the second pending task is the end of the waiting process determined for the first time The task to be processed, wherein the transaction number corresponds to a predetermined submission sequence of the transaction.
  9. 根据权利要求7所述的方法,其中,确定所述第二变量的变量值是否被返回包括,基于在共享内存中的预定地址是否存储有第二变量的变量值,确定所述第二变量的变量值是否被返回,其中,所述预定地址与所述第二交易相对应。The method according to claim 7, wherein determining whether the variable value of the second variable is returned comprises, based on whether the variable value of the second variable is stored in a predetermined address in the shared memory, determining the value of the second variable Whether the variable value is returned, wherein the predetermined address corresponds to the second transaction.
  10. 根据权利要求7所述的方法,其中,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务包括,在确定所述第三缓冲区中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息和所述第二变量的变量值,继续执行所述第二交易。8. The method according to claim 7, wherein, in a case where it is determined that the waiting process corresponding to the second to-be-processed task is finished, continuing to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task comprises In the case where it is determined that there is a second to-be-processed task waiting for the end of the process in the third buffer, continue to execute all based on the execution information corresponding to the second to-be-processed task and the variable value of the second variable The second transaction.
  11. 根据权利要求1所述的方法,其中,所述共享内存中包括第四缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在执行到所述读取操作的代码之后,确定提交顺序在第一交易之前、且未提交的各个交易是否为已执行了对第一变量的写操作的冲突交易,所述各个交易中包括第二交易,在确定所述第二交易为距离第一交易最近的冲突交易的情况中,在第四缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第 二交易的记录。The method according to claim 1, wherein the shared memory includes a fourth buffer, the first transaction includes a read operation of the first variable, and wherein the predetermined is performed in the process of processing the first transaction After the operation, recording in the shared memory the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task includes, after the code for the read operation is executed, determining that the order of submission is Whether each transaction that has not been submitted before the first transaction is a conflict transaction in which the write operation to the first variable has been performed, the each transaction includes a second transaction, and the second transaction is determined to be the closest to the first transaction In the case of conflicting transactions, the first to-be-processed task corresponding to the first transaction is recorded in the fourth buffer zone, wherein the first to-be-processed task includes a record of the second transaction.
  12. 根据权利要求11所述的方法,其中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于共享内存中记录的当前应提交的交易,确定在所述第四缓冲区中记录的多个待处理任务中是否存在等待过程结束的待处理任务。The method according to claim 11, wherein, for the multiple pending tasks that have been recorded in the shared memory, determining whether there are pending tasks waiting for the end of the process includes, based on the current transactions recorded in the shared memory that should be submitted , Determining whether there is a pending task waiting for the end of the process among the multiple pending tasks recorded in the fourth buffer.
  13. 根据权利要求1所述的方法,其中,所述共享内存中包括第五缓冲区,所述第一交易中包括对第一变量的读取操作,其中,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息包括,在执行到所述读取操作的代码之后,推断提交顺序在第一交易之前、且未提交的各个交易是否为将要对第一变量进行写操作的冲突交易,所述各个交易中包括第二交易,在推断所述第二交易为距离第一交易最近的冲突交易的情况中,在所述第五缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。The method according to claim 1, wherein the shared memory includes a fifth buffer, the first transaction includes a read operation of a first variable, and wherein the predetermined is performed in the process of processing the first transaction After the operation, recording the first to-be-processed task corresponding to the first transaction and the execution information corresponding to the first to-be-processed task in the shared memory includes, after executing the code of the read operation, inferring the submission sequence is Whether each transaction that has not been submitted before the first transaction is a conflict transaction that is about to write the first variable, the each transaction includes a second transaction, and it is inferred that the second transaction is the closest conflict to the first transaction In the case of a transaction, the first task to be processed corresponding to the first transaction is recorded in the fifth buffer zone, wherein the first task to be processed includes a record of the second transaction.
  14. 根据权利要求1所述的方法,其中,所述共享内存中包括至少一个缓冲区,所述至少一个缓冲区与至少一种待处理任务分别对应,其中,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务包括,基于所述至少一个缓冲区的预定顺序,确定各个缓冲区中是否存在等待过程结束的待处理任务。The method according to claim 1, wherein the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the number of records in the shared memory is Determining whether there is a pending task waiting for the end of the process includes determining whether there is a pending task waiting for the end of the process in each buffer based on a predetermined sequence of the at least one buffer.
  15. 一种在区块链中并发执行交易的装置,所述装置部署在区块链中的第一节点中的第一执行体中,所述第一节点中当前通过预设的预定数目的执行体并发执行交易,其中包括第一执行体,所述第一执行体当前在处理第一交易,所述装置,包括:A device for concurrently executing transactions in a blockchain. The device is deployed in a first executor in a first node in the blockchain. The first node currently passes a preset predetermined number of executors. The concurrent execution transaction includes a first executive body, and the first executive body is currently processing the first transaction, and the device includes:
    记录单元,配置为,在处理第一交易的过程中进行预定操作之后,在共享内存中记录与第一交易对应的第一待处理任务、以及与该第一待处理任务对应的执行信息,以相对于所述第一交易进入等待过程;The recording unit is configured to record, in the shared memory, a first task to be processed corresponding to the first transaction and execution information corresponding to the first task to be processed after a predetermined operation is performed in the process of processing the first transaction, to Enter the waiting process with respect to the first transaction;
    确定单元,配置为,对于所述共享内存中已经记录的多个待处理任务,确定其中是否存在等待过程结束的待处理任务,所述多个待处理任务由所述预定数目的执行体记录;以及The determining unit is configured to determine whether there is a pending task waiting for the end of the process among the multiple pending tasks that have been recorded in the shared memory, and the multiple pending tasks are recorded by the predetermined number of executives; as well as
    继续执行单元,配置为,在确定第二待处理任务对应的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行该第二待处理任务,其中,所述多个待处理任务中包括所述第二待处理任务。The continuing execution unit is configured to continue to execute the second to-be-processed task based on the execution information corresponding to the second to-be-processed task in a case where it is determined that the waiting process corresponding to the second to-be-processed task is over, wherein the The multiple to-be-processed tasks include the second to-be-processed task.
  16. 根据权利要求15所述的装置,还包括,交易执行单元,配置为,在确定所述多 个待处理任务各自的等待过程都未结束的情况中,从共享内存中的第一缓冲区获取待处理的第二交易,并开始执行所述第二交易。The device according to claim 15, further comprising a transaction execution unit configured to, in a case where it is determined that the waiting processes of the multiple pending tasks are not finished, obtain the pending tasks from the first buffer in the shared memory. Process the second transaction, and start execution of the second transaction.
  17. 根据权利要求15所述的装置,其中,所述共享内存中包括第二缓冲区,其中,所述记录单元还配置为,在处理完成第一交易之后,在确定第二交易未提交的情况中,在所述第二缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第二交易根据预定提交顺序为所述第一交易的前一个交易。The device according to claim 15, wherein the shared memory includes a second buffer area, and wherein the recording unit is further configured to, after processing the first transaction, in a case where it is determined that the second transaction has not been submitted , Record the first pending task corresponding to the first transaction in the second buffer zone, wherein the second transaction is the previous transaction of the first transaction according to a predetermined submission order.
  18. 根据权利要求17所述的装置,其中,所述确定单元还配置为,基于共享内存中记录的当前应提交的交易,确定所述第二缓冲区中对应于最小交易编号的待处理任务的等待过程是否结束,以确定所述第二缓冲区中是否存在等待过程结束的待处理任务,其中,所述交易编号对应于交易的提交顺序。The device according to claim 17, wherein the determining unit is further configured to determine the waiting task of the task to be processed corresponding to the smallest transaction number in the second buffer based on the transaction that should be submitted currently recorded in the shared memory Whether the process is over to determine whether there is a pending task waiting for the process to end in the second buffer zone, wherein the transaction number corresponds to the order of submission of the transaction.
  19. 根据权利要求18所述的装置,其中,所述继续执行单元还配置为,在确定所述第二缓冲区中的第二待处理任务的等待过程结束的情况中,基于与所述第二待处理任务对应的执行信息,继续执行对第三交易的提交,其中所述第二待处理任务与所述第三交易相对应。The apparatus according to claim 18, wherein the continuing execution unit is further configured to, in a case where it is determined that the waiting process of the second pending task in the second buffer is over, based on the comparison with the second pending task The execution information corresponding to the processing task continues to execute the submission of the third transaction, wherein the second pending task corresponds to the third transaction.
  20. 根据权利要求15所述的装置,其中,所述共享内存中包括第三缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元还配置为,在请求对所述第一变量的读取之后,在所述第三缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对所述第一变量的记录。The device according to claim 15, wherein the shared memory includes a third buffer, and the first transaction includes a read operation of a first variable, wherein the recording unit is further configured to: After the first variable is read, the first task to be processed corresponding to the first transaction is recorded in the third buffer area, wherein the first task to be processed includes information about the first variable recording.
  21. 根据权利要求20所述的装置,其中,所述第三缓冲区中包括所述第二待处理任务,所述第二待处理任务与第二交易中对第二变量的读取操作相对应,所述确定单元还配置为,确定所述第二变量的变量值是否被返回,在确定所述第二变量的变量值被返回的情况中,确定该第二待处理任务的等待过程结束。22. The device of claim 20, wherein the third buffer includes the second to-be-processed task, and the second to-be-processed task corresponds to a read operation of a second variable in a second transaction, The determining unit is further configured to determine whether the variable value of the second variable is returned, and in a case where the variable value of the second variable is determined to be returned, determine that the waiting process of the second to-be-processed task ends.
  22. 根据权利要求21所述的装置,其中,所述确定单元还配置为,对于所述第三缓冲区中已经记录的多个待处理任务,基于各个待处理任务对应的交易编号从小至大的顺序,依次确定各个待处理任务的等待过程是否结束,其中,所述第二待处理任务为首次确定的等待过程结束的待处理任务,其中,所述交易编号对应于交易的预定提交顺序。22. The device according to claim 21, wherein the determining unit is further configured to, for the multiple pending tasks that have been recorded in the third buffer, based on the descending order of the transaction number corresponding to each pending task , Determine in turn whether the waiting process of each task to be processed is over, wherein the second task to be processed is the first determined task to be processed after the waiting process ends, and the transaction number corresponds to the predetermined submission sequence of the transaction.
  23. 根据权利要求21所述的装置,其中,所述确定单元还配置为,基于在共享内存中的预定地址是否存储有第二变量的变量值,确定所述第二变量的变量值是否被返回,其中,所述预定地址与所述第二交易相对应。22. The apparatus according to claim 21, wherein the determining unit is further configured to determine whether the variable value of the second variable is returned based on whether the variable value of the second variable is stored at a predetermined address in the shared memory, Wherein, the predetermined address corresponds to the second transaction.
  24. 根据权利要求21所述的装置,其中,所述继续执行单元还配置为,在确定所述 第三缓冲区中存在等待过程结束的第二待处理任务的情况中,基于与所述第二待处理任务对应的执行信息和所述第二变量的变量值,继续执行所述第二交易。21. The apparatus according to claim 21, wherein the continuing execution unit is further configured to, in a case where it is determined that there is a second pending task waiting for the end of the process in the third buffer area, based on the comparison with the second pending task. The execution information corresponding to the processing task and the variable value of the second variable are processed, and the second transaction is continued to be executed.
  25. 根据权利要求15所述的装置,其中,所述共享内存中包括第四缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元还配置为,在执行到所述读取操作的代码之后,确定提交顺序在第一交易之前、且未提交的各个交易是否为已执行了对第一变量的写操作的冲突交易,所述各个交易中包括第二交易,在确定所述第二交易为距离第一交易最近的冲突交易的情况中,在第四缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。The device according to claim 15, wherein the shared memory includes a fourth buffer, and the first transaction includes a read operation of a first variable, wherein the recording unit is further configured to execute After the code of the read operation, it is determined whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction in which the write operation to the first variable has been performed, and the each transaction includes the second transaction , In the case of determining that the second transaction is the closest conflict transaction to the first transaction, the first pending task corresponding to the first transaction is recorded in the fourth buffer, wherein the first pending task is Including the record of the second transaction.
  26. 根据权利要求25所述的装置,其中,所述确定单元还配置为,基于共享内存中记录的当前应提交的交易,确定在所述第四缓冲区中记录的多个待处理任务中是否存在等待过程结束的待处理任务。The device according to claim 25, wherein the determining unit is further configured to determine whether there are multiple pending tasks recorded in the fourth buffer based on the currently submitted transaction recorded in the shared memory Pending tasks waiting for the end of the process.
  27. 根据权利要求15所述的装置,其中,所述共享内存中包括第五缓冲区,所述第一交易中包括对第一变量的读取操作,其中,所述记录单元还配置为,在执行到所述读取操作的代码之后,推断提交顺序在第一交易之前、且未提交的各个交易是否为将要对第一变量进行写操作的冲突交易,所述各个交易中包括第二交易,在推断所述第二交易为距离第一交易最近的冲突交易的情况中,在所述第五缓冲区中记录与第一交易对应的第一待处理任务,其中,所述第一待处理任务中包括对第二交易的记录。The device according to claim 15, wherein the shared memory includes a fifth buffer, and the first transaction includes a read operation of a first variable, wherein the recording unit is further configured to execute After the code of the read operation, it is inferred whether each transaction whose submission sequence is before the first transaction and is not submitted is a conflict transaction that will write the first variable, and each transaction includes the second transaction. In the case where it is inferred that the second transaction is the closest conflict transaction to the first transaction, the first pending task corresponding to the first transaction is recorded in the fifth buffer, wherein the first pending task is Including the record of the second transaction.
  28. 根据权利要求15所述的装置,其中,所述共享内存中包括至少一个缓冲区,所述至少一个缓冲区与至少一种待处理任务分别对应,其中,所述确定单元还配置为,基于所述至少一个缓冲区的预定顺序,确定各个缓冲区中是否存在等待过程结束的待处理任务。The device according to claim 15, wherein the shared memory includes at least one buffer, and the at least one buffer corresponds to at least one task to be processed, wherein the determining unit is further configured to Describe the predetermined sequence of the at least one buffer zone, and determine whether there are pending tasks in each buffer zone waiting for the process to end.
  29. 一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行权利要求1-14中任一项的所述的方法。A computer-readable storage medium having a computer program stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method according to any one of claims 1-14.
  30. 一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现权利要求1-14中任一项所述的方法。A computing device, comprising a memory and a processor, characterized in that executable code is stored in the memory, and when the processor executes the executable code, the method described in any one of claims 1-14 is implemented. method.
PCT/CN2020/082696 2019-08-30 2020-04-01 Method and device for executing transactions in parallel in blockchain WO2021036259A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910816530.6A CN110689344B (en) 2019-08-30 2019-08-30 Method and apparatus for concurrently executing transactions in a blockchain
CN201910816530.6 2019-08-30

Publications (1)

Publication Number Publication Date
WO2021036259A1 true WO2021036259A1 (en) 2021-03-04

Family

ID=69107726

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/082696 WO2021036259A1 (en) 2019-08-30 2020-04-01 Method and device for executing transactions in parallel in blockchain

Country Status (3)

Country Link
CN (2) CN113435885A (en)
TW (1) TWI732501B (en)
WO (1) WO2021036259A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113435885A (en) * 2019-08-30 2021-09-24 创新先进技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain
CN112001798B (en) * 2020-10-28 2021-01-26 支付宝(杭州)信息技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704269A (en) * 2017-10-16 2018-02-16 中国银行股份有限公司 A kind of method and system based on block chain generation block
CN108537543A (en) * 2018-03-30 2018-09-14 百度在线网络技术(北京)有限公司 Method for parallel processing, device, equipment and the storage medium of block chain data
CN108681565A (en) * 2018-04-28 2018-10-19 百度在线网络技术(北京)有限公司 block chain data parallel processing method, device, equipment and storage medium
CN110689344A (en) * 2019-08-30 2020-01-14 阿里巴巴集团控股有限公司 Method and apparatus for concurrently executing transactions in a blockchain

Family Cites Families (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10255108B2 (en) * 2016-01-26 2019-04-09 International Business Machines Corporation Parallel execution of blockchain transactions
CN106406896B (en) * 2016-09-27 2020-03-17 北京天德科技有限公司 Block chain block building method based on parallel Pipeline technology
US20180158034A1 (en) * 2016-12-07 2018-06-07 International Business Machines Corporation Dynamic reordering of blockchain transactions to optimize performance and scalability
US20180218455A1 (en) * 2017-01-30 2018-08-02 Dais Technology, Inc. System for creating and utilizing smart policies on a blockchain
US10679210B2 (en) * 2017-06-26 2020-06-09 International Business Machines Corporation Blockchain transaction commitment ordering
CN107453896B (en) * 2017-06-27 2020-08-04 创新先进技术有限公司 Method and device for processing multiple block chain network data and server
CN107562775B (en) * 2017-07-14 2020-04-24 创新先进技术有限公司 Data processing method and device based on block chain
US10984134B2 (en) * 2017-07-14 2021-04-20 Microsoft Technology Licensing, Llc Blockchain system for leveraging member nodes to achieve consensus
US10761877B2 (en) * 2017-07-21 2020-09-01 Intel Corporation Apparatuses, methods, and systems for blockchain transaction acceleration
CN107592292B (en) * 2017-07-26 2019-08-09 阿里巴巴集团控股有限公司 A kind of block chain communication method between nodes and device
CN107688999B (en) * 2017-08-11 2020-11-13 杭州溪塔科技有限公司 Block chain-based parallel transaction execution method
CN107590738A (en) * 2017-08-24 2018-01-16 阿里巴巴集团控股有限公司 Processing method, device and the server of selection common recognition node
CN108804112B (en) * 2018-05-22 2022-02-11 上海分布信息科技有限公司 Block chain settlement processing method and system
CN109447635B (en) * 2018-10-15 2022-02-01 北京京东尚科信息技术有限公司 Information storage method and device for block chain
CN109636384A (en) * 2018-10-26 2019-04-16 阿里巴巴集团控股有限公司 A kind of parallelization executes the method, apparatus and system of block chain transaction
CN110009316A (en) * 2018-12-14 2019-07-12 阿里巴巴集团控股有限公司 Event-handling method and device, electronic equipment based on block chain
CN110020856B (en) * 2019-01-31 2020-06-05 阿里巴巴集团控股有限公司 Method, node and storage medium for realizing mixed transaction in block chain
CN109872139B (en) * 2019-01-31 2020-10-23 杭州复杂美科技有限公司 Transaction replacement method, apparatus and storage medium
CN109784930B (en) * 2019-02-18 2023-07-18 深圳市迅雷网络技术有限公司 Block chain transaction data processing method and device, electronic equipment and medium
CN110011981B (en) * 2019-03-15 2021-06-29 湖北工程学院 Trusted cloud storage method and system based on block chain
CN110135985B (en) * 2019-04-04 2021-07-27 杭州抖音科技有限公司 Parallel execution method and system for transactions on block chain
CN113222752A (en) * 2019-04-12 2021-08-06 创新先进技术有限公司 Data processing system, method, computing device and storage medium based on block chain
CN110147273A (en) * 2019-05-17 2019-08-20 深圳前海微众银行股份有限公司 A kind of task executing method and device
CN110163609B (en) * 2019-05-28 2024-02-27 深圳前海微众银行股份有限公司 Method and device for processing data in block chain

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704269A (en) * 2017-10-16 2018-02-16 中国银行股份有限公司 A kind of method and system based on block chain generation block
CN108537543A (en) * 2018-03-30 2018-09-14 百度在线网络技术(北京)有限公司 Method for parallel processing, device, equipment and the storage medium of block chain data
CN108681565A (en) * 2018-04-28 2018-10-19 百度在线网络技术(北京)有限公司 block chain data parallel processing method, device, equipment and storage medium
CN110689344A (en) * 2019-08-30 2020-01-14 阿里巴巴集团控股有限公司 Method and apparatus for concurrently executing transactions in a blockchain

Also Published As

Publication number Publication date
TWI732501B (en) 2021-07-01
CN110689344A (en) 2020-01-14
CN110689344B (en) 2021-04-09
CN113435885A (en) 2021-09-24
TW202109512A (en) 2021-03-01

Similar Documents

Publication Publication Date Title
WO2021036258A1 (en) Method and apparatus for concurrently executing transactions in block chain
WO2021036254A1 (en) Method and apparatus for concurrently executing transactions in blockchain
JP6724039B2 (en) Processing database transactions in distributed computing systems
TW201909613A (en) Method, device and electronic device for processing consensus request in blockchain consensus network
US8881153B2 (en) Speculative thread execution with hardware transactional memory
JP5467661B2 (en) Method, system, and computer program for prioritization for contention arbitration in transaction memory management (priority for contention arbitration in transaction memory management)
TWI730690B (en) Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment
WO2021036260A1 (en) Method and apparatus for concurrently executing transactions in blockchain
WO2021027956A1 (en) Blockchain system-based transaction processing method and device
JPH0773087A (en) Method for recovery of file state in data processing system
WO2021036259A1 (en) Method and device for executing transactions in parallel in blockchain
JP2017509985A (en) Method and processor for data processing
US11803447B2 (en) Transaction processing method, apparatus, and electronic device for blockchain
CN110706108B (en) Method and apparatus for concurrently executing transactions in a blockchain
CN105808210A (en) Shared resource access method and apparatus
WO2022002128A1 (en) Data reading method, data writing method, device, and system
EP3951611A1 (en) Block verification method, apparatus and device
WO2021057165A1 (en) Method for concurrently executing transactions in blockchain, and device
US11983168B2 (en) Block verification method, apparatus and device
CN116450316A (en) Method, device, electronic equipment and storage medium for parallel transaction processing
JPS6022784B2 (en) Duplicate data integrity maintenance method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20857081

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20857081

Country of ref document: EP

Kind code of ref document: A1