WO2021036253A1 - 在区块链中并发执行交易的方法和装置 - Google Patents

在区块链中并发执行交易的方法和装置 Download PDF

Info

Publication number
WO2021036253A1
WO2021036253A1 PCT/CN2020/082454 CN2020082454W WO2021036253A1 WO 2021036253 A1 WO2021036253 A1 WO 2021036253A1 CN 2020082454 W CN2020082454 W CN 2020082454W WO 2021036253 A1 WO2021036253 A1 WO 2021036253A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
variable
transactions
field
read
Prior art date
Application number
PCT/CN2020/082454
Other languages
English (en)
French (fr)
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 WO2021036253A1 publication Critical patent/WO2021036253A1/zh

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
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • 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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5061Partitioning or combining of resources

Definitions

  • the embodiments of this specification relate to the field of blockchain technology, and more specifically, to a method and device for concurrently executing multiple 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.
  • the embodiments of this specification aim to provide a more effective method for concurrently executing multiple transactions in the blockchain.
  • one aspect of this specification provides a method for concurrently executing multiple transactions in a blockchain, wherein the multiple transactions have a predetermined submission order, including the first transaction, and the method is in the block chain.
  • the first node in the chain the first node is preset with a variable access table, and the variable access table includes a write field corresponding to the first variable, wherein the write field is used to record the multiple transactions
  • the method includes: for each previous transaction, determining based on the write field: whether the write to the first variable in the previous transaction has been performed Operation, wherein the previous transaction is a transaction of the plurality of transactions whose submission sequence is before the first transaction; and based on the determination result, the read operation of the first variable in the first transaction is performed .
  • variable access table is stored locally, wherein, based on the determination result, executing the read operation of the first variable in the first transaction includes: In the case where the write field determines that the write operation to the first variable is not performed, the read operation to the first variable in the first transaction is performed.
  • executing the read operation of the first variable in the first transaction includes, for a second transaction of the plurality of transactions whose submission order is before the first transaction, In the case where it is determined based on the write field that the write operation to the first variable in the second transaction has been performed, wait with respect to the first transaction to execute the transaction in the first transaction after the second transaction is submitted. Describe the read operation of the first variable.
  • variable access table is stored locally, and for each previous transaction, determining based on the write field: whether the write operation to the first variable in the previous transaction has been performed includes Sending a report to the local dedicated hardware to request the dedicated hardware to make the determination, and based on the determination result, performing the read operation of the first variable in the first transaction includes, while sending the report, Perform a read operation on the first variable in the first transaction, and before submitting the first transaction, determine whether to re-execute the first transaction based on the determination result received from the dedicated hardware.
  • the variable access table is stored in a dedicated server, wherein, for each previous transaction, it is determined based on the write field: whether the writing of the first variable in the previous transaction has been performed
  • the operation includes sending a report to the dedicated server to request the dedicated server to make the determination, and based on the determination result, performing the read operation of the first variable in the first transaction includes, sending the report At the same time, request the dedicated server to perform the read operation of the first variable in the first transaction, and before submitting the first transaction, determine whether to re-execute the first transaction based on the determination result received from the dedicated server .
  • variable access table further includes a read field corresponding to the first variable, and the read field is used to record the execution of the read operation on the first variable in the multiple transactions ,
  • the method further includes, after performing the read operation on the first variable in the first transaction, modifying the read field accordingly.
  • the read field includes a plurality of bits corresponding to the plurality of transactions, and modifying the read field accordingly includes modifying the bit corresponding to the first transaction in the read field accordingly.
  • the plurality of transactions further includes a second transaction, wherein the order of submission of the second transaction is the first among the plurality of transactions, and the second transaction includes For the write operation of the first variable, when the second transaction is submitted after the read field is modified accordingly, the method further includes, based on the read field, determining whether the transaction in the first transaction has been executed.
  • the read operation of the first variable in the case of determining that the read operation of the first variable in the first transaction has been performed, notify the local to re-execute the read operation of the first variable in the first transaction.
  • the plurality of transactions further include a third transaction, wherein the order of submission of the third transaction is between the first transaction and the second transaction, and the method further includes: After receiving the notification to re-execute the read operation on the first variable in the first transaction, determine based on the write field whether the write operation on the first variable in the third transaction has been performed; after determining that the third transaction has been performed In the case of a write operation in a transaction, a wait is performed to re-execute the read operation of the first variable in the first transaction after the write operation to the first variable in the third transaction is submitted.
  • the predetermined number of bits included in the write field corresponds to a predetermined number of transactions
  • the method further includes, after submitting the second transaction, comparing the write field with the first transaction. The first value of the bit corresponding to the second transaction is restored, where the first value is used to record: the write operation to the first variable in the second transaction has been performed.
  • the predetermined number of bits included in the read field corresponds to a predetermined number of transactions
  • the second transaction further includes a read operation on the first field
  • the method further includes: After the second transaction, restore the first value of the bit corresponding to the second transaction in the read field, where the first value is used to record: the pair of the first transaction in the second transaction has been executed Read operation of variables.
  • a transaction execution window is preset in the first node, and the multiple transactions are multiple transactions currently included in the transaction execution window, wherein the number of the multiple transactions is less than or equal to the For a predetermined number, the method further includes, after submitting the second transaction, moving the transaction execution window backward by one transaction among the plurality of transactions included in the first node and arranged in a predetermined submission order.
  • variable access table further includes a first global variable, which is used to indicate the position of the transaction execution window.
  • variable access table further includes a serial number field corresponding to the first variable, which is used to indicate the transaction batch corresponding to the first variable.
  • variable access table includes a key corresponding to the first variable, and the key is a hash value of the first variable.
  • Another aspect of this specification provides a device for concurrently executing multiple transactions in a blockchain, wherein the multiple transactions have a predetermined submission sequence, including the first transaction, and the device is deployed in the blockchain.
  • the first node is preset with a variable access table, and the variable access table includes a write field corresponding to the first variable, wherein the write field is used to record pairs in the multiple transactions
  • the device includes:
  • the first determining unit is configured to, for each previous transaction, determine based on the write field: whether the write operation of the first variable in the previous transaction has been performed, wherein the previous transaction is the previous transaction. Among the multiple transactions, the transaction whose submission sequence is before the first transaction; and
  • the execution unit is configured to execute the read operation of the first variable in the first transaction based on the determination result.
  • variable access table is stored locally, and the execution unit is further configured to, for each previous transaction, determine based on the write field that the write operation to the first variable has not been performed In the case of performing the read operation on the first variable in the first transaction.
  • the execution unit is further configured to, for a second transaction in the plurality of transactions whose submission sequence is before the first transaction, determine based on the write field that the pair in the second transaction has been executed. In the case of the write operation of the first variable, wait with respect to the first transaction to execute the read operation of the first variable in the first transaction after the second transaction is submitted.
  • variable access table is stored locally, and the first determining unit is further configured to send a report to the local dedicated hardware to request the dedicated hardware to make the determination,
  • the execution unit is further configured to execute the read operation of the first variable in the first transaction while sending the report, and before submitting the first transaction, based on the determination result received from the dedicated hardware To determine whether to re-execute the first transaction.
  • variable access table is stored in a dedicated server, wherein the first determining unit is further configured to send a report to the dedicated server to request the dedicated server to make the determination,
  • the execution unit is further configured to execute the read operation of the first variable in the first transaction while sending the report, and before submitting the first transaction, based on the determination result received from the dedicated server To determine whether to re-execute the first transaction.
  • variable access table further includes a read field corresponding to the first variable, and the read field is used to record the execution of the read operation on the first variable in the multiple transactions
  • the device further includes a modification unit configured to modify the read field accordingly after performing the read operation on the first variable in the first transaction.
  • the read field includes a plurality of bits corresponding to the plurality of transactions, wherein the modification unit is further configured to modify the bit corresponding to the first transaction in the read field accordingly.
  • the plurality of transactions further includes a second transaction, wherein the order of submission of the second transaction is the first among the plurality of transactions, and the second transaction includes For the write operation of the first variable, when the second transaction is submitted after the read field is modified accordingly, the device further includes:
  • the second determining unit is configured to determine, based on the read field, whether a read operation on the first variable in the first transaction has been performed;
  • the notification unit is configured to notify the local to re-execute the read operation of the first variable in the first transaction when it is determined that the read operation of the first variable in the first transaction has been performed.
  • the plurality of transactions further include a third transaction, wherein the order of submission of the third transaction is between the first transaction and the second transaction, and the device further includes:
  • the third determining unit is configured to, after receiving a notification from the local to re-execute the read operation of the first variable in the first transaction, determine whether the first variable in the third transaction has been executed based on the write field. Write operation;
  • the waiting unit is configured to, in the case where it is determined that the write operation in the third transaction has been performed, wait, so as to re-execute the first variable in the first transaction after the write operation to the first variable in the third transaction is submitted.
  • a variable read operation is configured to, in the case where it is determined that the write operation in the third transaction has been performed, wait, so as to re-execute the first variable in the first transaction after the write operation to the first variable in the third transaction is submitted.
  • the predetermined number of bits included in the write field correspond to a predetermined number of transactions
  • the device further includes a first restoration unit configured to, after submitting the second transaction, reset all The first value of the bit corresponding to the second transaction in the description field is restored, where the first value is used to record: the write operation to the first variable in the second transaction has been performed.
  • the predetermined number of bits included in the read field corresponds to a predetermined number of transactions
  • the second transaction further includes a read operation on the first field
  • the device further includes: Unit, configured to, after submitting the second transaction, restore the first value of the bit corresponding to the second transaction in the read field, where the first value is used to record: the second transaction has been executed The read operation of the first variable in the transaction.
  • a transaction execution window is preset in the first node, and the multiple transactions are multiple transactions currently included in the transaction execution window, wherein the number of the multiple transactions is less than or equal to the For a predetermined number
  • the device further includes a window moving unit configured to, after submitting the second transaction, place the transaction execution window in the plurality of transactions included in the first node and arranged in a predetermined submission order Move backward one transaction.
  • 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 execute 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 Multiple interdependent transactions can be executed concurrently.
  • these transactions can be executed serially, thereby ensuring the consistency of the calculation results while speeding up the processing speed and improving the processing performance .
  • Figure 1 shows a blockchain system according to an embodiment of this specification
  • Figure 2 shows a flow chart of a method for concurrently executing multiple transactions in a blockchain according to an embodiment of the present specification
  • FIG. 3 shows an entry corresponding to the first variable in the variable access table in FIG. 1;
  • Fig. 4 shows a schematic diagram of a transaction execution window according to an embodiment of the present specification
  • Fig. 5 shows a device 5000 for concurrently executing multiple 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.
  • the multiple transactions may involve the calculation of multiple variables.
  • the order of execution will not affect the final calculation results, and the same variables are involved in the two transactions.
  • the order of execution will affect the final calculation result. Therefore, in the embodiment of this specification, in order to ensure that each node performs the same results for multiple transactions, each node has its own variable access table preset, as shown in the figure with node 11, node 12 and node 13.
  • Corresponding variable access table 11, variable access table 12 and variable access table 13 respectively.
  • the variable access table includes entries for each variable involved in multiple transactions, and the variable entries include the execution record of each transaction on the variable.
  • the variable access table includes k 1 , k 2 ,...k n, etc., and writes corresponding to k 1 , k 2 ,...k n respectively Field, read field, window position (field) and serial number (field).
  • k 1 , k 2 ,...k n are the keys corresponding to the various variables included in the multiple transactions, for example, the hash value of each variable, and n may take a larger value, for example, 100 Million.
  • the write field is used to record the write operation performed on the corresponding variable by the executive body corresponding to each transaction
  • the read field is used to record the read operation performed on the corresponding variable by the executive body corresponding to each transaction.
  • the executive body may be, for example, a thread, a process, Any of the coroutines.
  • a transaction execution window can be set, that is, only multiple transactions in the transaction execution window are currently executed concurrently.
  • the window position in the variable access table is used to indicate the position of the current transaction execution window, and the window position field value can be obtained based on a preset global variable corresponding to the window position.
  • the serial number is the transaction batch number.
  • the table is accessed by referring to variables, so that for multiple transactions that do not have mutual dependencies, the multiple transactions can be executed concurrently.
  • the multiple transactions can be executed serially by rereading, waiting, etc., so as to ensure that the calculation results of each node are consistent, and concurrently execute some transactions, which saves processing time and improves Computational efficiency.
  • variable access table is not limited to the table shown in FIG. 1, but can be changed as needed.
  • variable access table does not necessarily include a window position field, a serial number field, etc.
  • Figure 2 shows a flow chart of a method for concurrently executing multiple transactions in a blockchain according to an embodiment of the present specification, wherein the multiple transactions have a predetermined submission sequence, including the first transaction, and the method is The first node in the blockchain executes, and the first node is preset with a variable access table, and the variable access table includes a write field corresponding to the first variable, wherein the write field is used to record the multiple The execution of a write operation to the first variable in a transaction, the method includes:
  • Step S202 For each previous transaction, determine based on the write field: whether the write operation to the first variable in the previous transaction has been performed, wherein the previous transaction is among the multiple transactions Submit the transaction before the first transaction in the order of submission;
  • Step S204 based on the determination result, execute the read operation of the first variable in the first transaction.
  • this method is executed on a node in the blockchain.
  • the node packs a block, or after the node receives a newly generated block, it will execute and submit multiple related transactions.
  • a block may include thousands of transactions, and these thousands of transactions may involve hundreds of variables. Among them, multiple transactions may access different variables, or multiple transactions may access the same variable.
  • the respective transaction numbers of multiple transactions to be packaged into a block have been determined according to predetermined rules, and the order of the transaction numbers indicates the execution order and submission order of the transactions.
  • the predetermined submission order is reserved for multiple transactions in the block, that is, the serial number sequence of each transaction is taken as the order of submission.
  • the respective submission order and at the same time, based on the variable access table preset by each node, makes each transaction without a dependency relationship can be executed concurrently, and enables each transaction with a dependency relationship to be executed serially according to its serial number. For transaction 1 and transaction 2, if the first variable is written in transaction 1, and the first variable is read in transaction 2, transaction 2 depends on the result of transaction 1.
  • Fig. 3 shows an entry corresponding to the first variable in the variable access table in Fig. 1.
  • the first variable corresponds to, for example, k1 in the variable access table
  • k1 is the key value of the first variable, which is, for example, the hash value of the first variable. It can be understood that k1 is not limited to the hash value of the first variable, but may also be any identifier of the first variable.
  • the fields corresponding to k1 include the following fields corresponding to the first variable: a write field, a read field, a window position field, and a serial number field.
  • both the write field and the read field include a predetermined number of bits (only 6 bits are schematically shown in the figure), for example, the number of bits is 64 bits, and the number of bits should be greater than or equal to the number of concurrently executed transactions in the blockchain The maximum number, so that each transaction executed concurrently can uniquely correspond to a bit in this field.
  • the initial value of each bit in the write field and the read field is 0.
  • the write field is used to record whether each write operation included in multiple transactions executed concurrently has been performed
  • the read field is used to record whether each read operation included in multiple transactions executed concurrently has been performed.
  • the transaction number can be modulo 64 to determine its corresponding bit in 64 bits. That is to say, in order to save memory, the read-write field is set as a ring buffer, so that multiple transactions can reuse the read-write field. For example, the read-write field can record up to 64 transaction access information Therefore, transaction 1 and transaction 65 will use the same location for recording.
  • the bit corresponding to, for example, the first transaction in the write field when the first transaction has not performed the write operation to the first variable, the value in the bit corresponding to the first transaction is 0, and when the first transaction is executed, the first variable is After the write operation, the value in this bit can be modified to 1.
  • executing the write operation to the variable means that the write operation is executed in the local memory without actually writing the variable.
  • the write operation is performed.
  • the value of each bit in the read field can be similarly modified. For example, when the first transaction does not perform the read operation on the first variable, the value in the bit corresponding to the first transaction in the read field is 0, and when the first transaction executes the After the read operation of the first variable, the value in this bit can be modified to 1.
  • performing a read operation on a variable refers to reading a stored variable to obtain the current value of the variable.
  • the read-write field shown in FIG. 3 is only a specific implementation of the read-write field according to this example, and the read-write field according to the embodiment of this specification is not limited to the specific form shown in FIG. 3, as long as it can record
  • the execution body of each transaction executed concurrently can read/write the first variable.
  • a transaction execution window may be set when the transaction is executed, and the transaction execution window may include a predetermined number of transactions.
  • the purpose of the transaction execution window is to make the executor know that "the input information obtained by this transaction is the latest when the transaction at the lower limit of the window is executed, and the final submission can be made without waiting for other transactions."
  • Transaction the execution body cannot determine whether the transaction has received the latest input after executing the transaction. Therefore, it will not be submitted until it is at the lower limit of the window. Before submitting, the transaction may find itself marked to be redone. ;
  • the window upper limit is used to limit the amount of resources used to execute the transaction. If the upper limit is infinite, even if no transaction is finally submitted, the execution body can continue to process the transaction until the memory resources are exhausted.
  • FIG. 4 shows a schematic diagram of a transaction execution window according to an embodiment of the present specification.
  • ten numbers from 1 to 10 in the figure represent ten transactions with numbers from 1 to 10, respectively, and the transaction execution window may include, for example, 5 transactions.
  • the transaction execution window can initially fall on transactions 1 to 5. After transaction 1 is submitted, the window moves one transaction back, that is, it falls on transactions 2 to 6. Similarly, after transaction 2 is submitted, the window moves one transaction back, so that it falls to transaction 3 as shown in the figure. Up to 7.
  • the window position field in FIG. 3 is used to indicate the current position of the transaction execution window.
  • the window position field corresponds to the first global variable, for example, so that the field corresponding to each variable can obtain the current window position based on the first global variable.
  • the first global variable can be set equal to the starting transaction number, ending transaction number, etc. of the current window, for example.
  • the window position in FIG. 3 may be filled in, for example, "3", that is, in this case, the window position is identified by the initial transaction in the window.
  • the window position field can correspond to multiple values, for example, the first value corresponds to the transaction number that should be submitted serially, the second value corresponds to the maximum number of transactions that are processed, or the second value can be Include the number of transactions for the window and so on.
  • each batch of transactions can be set to include 1000 transactions, and a batch number can be set for each batch of transactions.
  • the serial number field can indicate the batch number of the currently processed transaction.
  • the current batch number of the first transaction can be compared with the batch number indicated in the serial number field of the first variable recorded in the variable access table, if the two are consistent , You can continue to perform the operation, if the two are inconsistent, you can clear the existing data corresponding to the first variable in the variable access table.
  • the serial number shown in Figure 3 is "2", which means that the transaction being executed is the second batch of transactions.
  • the second batch of transactions is also numbered from 1 to 1000, which is compared with the first batch by the serial number "2".
  • the transaction number from 1 to 1000 is distinguished.
  • the sequence number field By adding the sequence number field to the variable access table, the reset setting of the variable access table can be eliminated.
  • the access rate of each variable may be different, and some variables (such as variable k2) can easily cause conflicts.
  • the serial number field is used to determine whether the batch number is out of date, it can be used as a mark for the variable k2. If the serial number method is not used, it can be cleared asynchronously.
  • variable access table shown in FIG. 3 is only illustrative, and is not used to limit the scope of the embodiments of the present specification.
  • the variable access table can only include write fields and read fields.
  • only the write field may be included in the variable access table. Therefore, when the read operation in the transaction is performed, the read operation can be performed by judging based on the write field whether the concurrently executed transaction with the previous number has performed the write operation.
  • all transactions with a later number can be notified, so that all transactions with a later number that have performed a read operation re-execute the read operation.
  • only the read field may be included in the variable access table, so that the read operation in the transaction can be performed directly, and the write operation of the transaction can be determined based on the read field to determine the serial number later. Whether the transactions executed at the same time perform the read operation, and notify the transaction that performed the read operation to re-execute the read operation after submission.
  • step S202 for each previous transaction, it is determined based on the write field: whether the write operation to the first variable in the previous transaction has been performed, where the previous transaction is the multiple The transaction whose submission sequence is before the first transaction among the transactions.
  • transactions 3-7 are currently executed concurrently in the blockchain node, for example, through
  • the five executive bodies 3-7 execute transactions 3-7 concurrently.
  • transactions 3-7 are executed concurrently in a virtual machine.
  • transaction 6 is the first transaction, which is about to perform a read operation on the first variable. Since transactions 3 to 7 are submitted in the order of the transaction number, transaction 6 needs to determine whether transactions 3 to 5 that are being executed at the same time have a write operation. If any of transactions 3 to 5 has a write operation, the write operation is required. The operation will eventually change the value of the first variable.
  • transaction 6 needs to wait for the previous transaction including the write operation to be submitted before reading the value of the first variable after the write operation.
  • transaction 4 includes a write operation to the first variable, and the write operation in transaction 4 has been executed currently in the node, so that the write field corresponding to the first variable in the variable access table corresponds to transaction 4 Modified to 1, the executor corresponding to transaction 6 in the node can learn that other executors in the node have performed the write operation to the first variable in transaction 4 based on the variable access table.
  • the blockchain node is deployed on a server, so that the variable access table is stored in the local shared memory.
  • the executive body corresponding to transaction 6 can be found in the variable access table. Get the search results almost at the same time.
  • the blockchain nodes are deployed on multiple servers, so that the variable access table is stored on a dedicated server, for example, and other servers in the node can access the dedicated server and receive from the dedicated server. Go to the variable to access the information in the table.
  • step S204 based on the determination result, perform a read operation on the first variable in the first transaction.
  • the executor corresponding to transaction 6 can learn the search result almost at the same time as the variable access table is searched, and then learn the search result after the search result is obtained. Perform subsequent operations based on this result. For example, transaction 6 is determined after performing the above query for each of its previous transactions: transactions 3 to 5 currently do not write to the first variable, that is to say, the execution of transactions 3 to 5 has not changed the first variable. The value of a variable, therefore, the executive body 6 executes the reading of the value of the first variable.
  • executive body 6 determines: executive body 4 has already performed the write operation to the first variable, transaction 6 waits until transaction 4 is submitted, and then determines whether to proceed Reading of the first variable. After transaction 4 is submitted, as mentioned above, the transaction execution window will be moved to 5-9, and the executive body 6 can perform the above-mentioned query for each previous transaction again, that is, whether the executive body 5 has performed the query based on the variable access table For the write operation of the first variable, in the case that the executor 5 has also performed the write operation, the executor 6 will wait for the transaction 5 to be submitted before reading.
  • the executive body 6 determines: both transaction 4 and executive body 5 have performed the write operation to the first variable, then the transaction 6 waits until after the transaction 5 is submitted Then read the first variable. That is, the executor 6 needs to wait until the write operation of the transaction that is in front of the transaction 6 and the closest to the transaction 6 among the concurrently executed multiple transactions is submitted before performing the read operation. In the concurrently executed transaction, the write operation of the transaction after transaction 6 does not affect the execution of the read operation of transaction 6.
  • the variable access table is stored locally, and the executor corresponding to transaction 6 can send a report to the local dedicated hardware to request the dedicated hardware to determine in the above steps.
  • the dedicated hardware is, for example, a local CPU or FPGA dedicated to accessing and rewriting the variable access table.
  • the executor 6 executes the reading operation of the first variable while sending the report, that is, it directly reads the first variable without waiting for the query result to be received.
  • the executive body 6 determines whether to re-read the first variable based on the information received from the dedicated hardware. For example, after the dedicated hardware receives the report and makes an inquiry, it is determined that there is a transaction that performed the write operation to the first variable in the transactions 3 to 5 before the transaction 6. In this case, the dedicated hardware notifies the execution body 6 to renew Read the first variable.
  • variable access table is, for example, stored on a dedicated server
  • transactions 3-7 are currently executed concurrently through server 1
  • the executive body corresponding to transaction 6 in server 1 will execute the read operation of the first variable.
  • the server 1 sends a report that the first variable is about to be read to the dedicated server to request the dedicated server to determine whether the execution body of the concurrently executed transaction before the transaction 6 has performed a write operation to the first variable. While the server 1 sends the report, the executor 6 requests the dedicated server to perform the reading operation of the first variable, that is, since it takes a long communication time to receive the query result from the dedicated server, here Read the first variable directly without waiting to receive the query result.
  • the executive body 6 determines whether to re-read the first variable based on the information received from the dedicated server. For example, after the dedicated server receives the report and makes an inquiry, it is determined that there is a transaction that performed a write operation to the first variable in transactions 3 to 5 before transaction 6. In this case, the dedicated server notifies the executive body 6 to renew Read the first variable.
  • the executive body 6 in order to reduce the development difficulty, the executive body 6 usually re-executes all the transactions 6 after receiving the notification.
  • the dedicated server informs the executive 6 of the re-reading of the first variable based on the write, and the executive 6 re-executes the transaction 6 before the submission.
  • the dedicated server informs the executive 6 of the re-reading of the first variable based on the write, and the executive 6 re-executes the transaction 6 before the submission.
  • the server does not notify the executive body 6 to re-read, the executive body 6 can submit the transaction 6 directly.
  • the execution body 6 After the execution body 6 performs the read operation on the first variable as described above, the bit corresponding to transaction 6 in the read field corresponding to the first variable in the variable access table is modified to, for example, "1". Body 6 is, for example, 0 before performing a read operation.
  • the plurality of transactions further includes a second transaction, wherein the order of submission of the second transaction is the first among the plurality of transactions, and the second transaction includes For the write operation of the first variable, when the second transaction is submitted after the read field is modified accordingly, as shown in the dashed box in FIG. 2, the method further includes the following steps:
  • Step S206 based on the read field, determine whether the read operation of the first variable in the first transaction has been performed.
  • Step S208 In the case where it is determined that the read operation of the first variable in the first transaction has been performed, notify the local to re-execute the read operation of the first variable in the first transaction.
  • transaction 3 shown in FIG. 4 is the second transaction.
  • the executor 6 has performed the read operation as described above, for example, the executor 3 has performed the write operation.
  • the executive body 3 stores the value to be written to the first variable in a predetermined location in the memory, and then changes the bit corresponding to transaction 3 in the write field corresponding to the first variable in the variable access table to " 1".
  • the executive body 7 will perform a read operation on the first variable after the modification. Similar to the above, it can be known that the executive body 3 has performed the writing of the first variable by querying the variable access table. Therefore, the executive body 7 will wait for the transaction 3 to be submitted before performing the above-mentioned read operation.
  • execution body 3 will submit transaction 3 after transaction 3 has been executed. For example, process 3 may determine whether to submit transaction 3 currently based on the window position field in the table. After transaction 3 is submitted, the first variable is actually written, and the value of the first variable is modified. When transaction 3 is submitted, the following steps will be performed.
  • step S206 based on the read field, it is determined whether the read operation of the first variable in the first transaction has been performed.
  • the executive body 3 After transaction 3 is submitted, the executive body 3 will determine whether the corresponding executive body has read the first variable for several other transactions in the window before the submission (that is, transactions 4-7), if If the read operation has been performed, the corresponding executor is notified to re-execute the read operation. For example, as described above, transaction 6 (that is, the first transaction) is a transaction after transaction 3 in the window, and execution body 3 determines execution body 6 based on the bit corresponding to transaction 6 in the read field. Whether the read operation of the first variable has been performed.
  • step S208 in the case where it is determined that the read operation of the first variable in the first transaction has been performed, the local is notified to re-execute the read operation of the first variable in the first transaction.
  • the executor 3 determines that the executor 6 has performed the read operation based on the variable access table, and then informs the executor 6 to re-execute the read operation on the first variable.
  • the executive body 3 can be marked in the private storage space of the transaction 6 to notify the executive body 6 to perform the reread operation, and the transaction 6 can check whether it is submitted before or at other times. The accent mark exists.
  • the executor 3 can send an asynchronous signal to the executor 6 after the marking. After receiving the asynchronous signal, the executor 6 checks whether the current transaction is set to need to be reread (because the executor is receiving the asynchronous signal).
  • the transaction may no longer be executed 6), if necessary, transfer to the re-reading process.
  • the server entrusts the host with the executive body 6 to mark through the network to notify the executive body 6 to perform the reread operation.
  • Execution body 6 can immediately re-execute the read operation, or execute body 6 can check whether execution bodies 4 and 5 have subsequent write operations from the variable access table. For example, if execution body 4 also performs a write operation, execute Body 6 can wait until transaction 4 is submitted before performing the read operation again.
  • the transaction execution window moves one bit backward, that is, it is located on transactions 4 to 8.
  • the execution body 3 also changes the value in the write field corresponding to the first variable in the variable access table.
  • the bit corresponding to transaction 3 is cleared so as not to affect the use of this bit by subsequent transactions.
  • executor 3 will also modify the corresponding value in the read field to 1 after the previous read operation, and after submitting transaction 3, executor 3 will also clear the bit .
  • Fig. 5 shows a device 5000 for concurrently executing multiple transactions in a blockchain according to an embodiment of the present specification, wherein the multiple transactions have a predetermined submission sequence, including the first transaction, and the device is deployed in In the first node in the blockchain, the first node is preset with a variable access table, and the variable access table includes a write field corresponding to the first variable, wherein the write field is used to record the multiple For execution of a write operation to the first variable in a transaction, the device includes:
  • the first determining unit 501 is configured to, for each previous transaction, determine based on the write field: whether a write operation to the first variable in the previous transaction has been performed, where the previous transaction is Among the plurality of transactions, the transaction whose submission order is before the first transaction; and
  • the execution unit 502 is configured to execute a read operation on the first variable in the first transaction based on the determination result.
  • variable access table is stored locally, and the execution unit 502 is further configured to determine, based on the write field, that writing to the first variable has not been performed for each previous transaction. In the case of operation, the read operation of the first variable in the first transaction is performed.
  • the execution unit 502 is further configured to, for a second transaction of the plurality of transactions whose submission sequence is before the first transaction, determine that the second transaction in the second transaction has been executed based on the write field In the case of a write operation to the first variable, wait with respect to the first transaction, so as to execute the read operation of the first variable in the first transaction after the second transaction is submitted.
  • variable access table is stored locally, wherein the first determining unit 501 is further configured to send a report to the local dedicated hardware to request the dedicated hardware to make the determination,
  • the execution unit 502 is further configured to execute the read operation of the first variable in the first transaction while sending the report, and before submitting the first transaction, based on the determination received from the dedicated hardware As a result, it is determined whether to re-execute the first transaction.
  • variable access table is stored in a dedicated server, wherein the first determining unit 501 is further configured to send a report to the dedicated server to request the dedicated server to make the determination,
  • the execution unit 502 is further configured to request the dedicated server to execute the read operation of the first variable in the first transaction while sending the report, and before submitting the first transaction, based on the The determination result received by the dedicated server determines whether to re-execute the first transaction.
  • variable access table further includes a read field corresponding to the first variable, and the read field is used to record the execution of the read operation on the first variable in the multiple transactions
  • the device further includes a modification unit 503 configured to modify the read field accordingly after performing the read operation on the first variable in the first transaction.
  • the read field includes a plurality of bits corresponding to the plurality of transactions, wherein the modification unit is further configured to modify the bit corresponding to the first transaction in the read field accordingly.
  • the plurality of transactions further includes a second transaction, wherein the order of submission of the second transaction is the first among the plurality of transactions, and the second transaction includes For the write operation of the first variable, when the second transaction is submitted after the read field is modified accordingly, the device further includes:
  • the second determining unit 504 is configured to determine, based on the read field, whether the read operation of the first variable in the first transaction has been performed.
  • the notification unit 505 is configured to notify the local to re-execute the read operation of the first variable in the first transaction when it is determined that the read operation of the first variable in the first transaction has been performed.
  • the plurality of transactions further include a third transaction, wherein the order of submission of the third transaction is between the first transaction and the second transaction, and the device further includes:
  • the third determining unit 506 is configured to, after receiving a notification to re-execute the read operation of the first variable in the first transaction from the local, determine whether the first variable in the third transaction has been executed based on the write field. Write operation of variables;
  • the waiting unit 507 is configured to, in the case where it is determined that the write operation in the third transaction has been performed, wait to re-execute the pair in the first transaction after submitting the write operation to the first variable in the third transaction Read operation of the first variable.
  • the predetermined number of bits included in the write field correspond to a predetermined number of transactions
  • the device further includes a first restoration unit 508 configured to: after submitting the second transaction, The first value of the bit corresponding to the second transaction in the write field is restored, where the first value is used to record that the write operation to the first variable in the second transaction has been performed.
  • the predetermined number of bits included in the read field corresponds to a predetermined number of transactions
  • the second transaction further includes a read operation on the first field
  • the device further includes:
  • the unit 509 is configured to, after submitting the second transaction, restore the first value of the bit corresponding to the second transaction in the read field, where the first value is used to record: 2.
  • a transaction execution window is preset in the first node, and the multiple transactions are multiple transactions currently included in the transaction execution window, wherein the number of the multiple transactions is less than or equal to the For a predetermined number, the device further includes a window moving unit 510 configured to, after submitting the second transaction, arrange the transaction execution window in the first node including a plurality of transactions arranged in a predetermined submission order Move backward one transaction in the middle.
  • 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 execute 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 Multiple interdependent transactions can be executed concurrently.
  • these transactions can be executed serially, thereby ensuring the consistency of the calculation results while speeding up the processing speed and improving the processing performance .
  • 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

一种在区块链中并发执行多个交易的方法,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述方法在区块链中的第一节点执行,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述方法包括:对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作(S202),其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及基于所述确定结果,执行第一交易中的对所述第一变量的读操作(S204)。

Description

在区块链中并发执行交易的方法和装置 技术领域
本说明书实施例涉及区块链技术领域,更具体地,涉及一种在区块链中并发执行多个交易的方法和装置。
背景技术
区块链技术是构建在点对点(P2P)网络上,利用链式数据结构来验证与存储数据,利用分布式节点共识算法来生成和更新数据,利用密码学的方式保证数据传输和访问的安全,利用由自动化脚本代码组成的智能合约来编程和操作数据的一种全新的分布式基础架构与计算范式。区块链技术也被称之为分布式账本技术,是一种去中心化的分布式数据库技术,其特点是去中心化、公开透明、不可篡改、可信任。区块链的每笔数据,都会广播到全网的区块链节点,每个全节点都有全量的、一致的数据。区块链中的节点通过发送交易而进行转账、存入数据等业务,区块链中的记账节点在交易池中收集区块链中的交易,执行所述交易,并在执行所述交易之后,将这些交易打包到区块中并扩散到区块链中。区块链中的验证节点会对从记账节点发出的区块进行验证,在验证通过之后,每个节点在接收到该区块时,都会执行该区块中包括的每个交易。为了保证各个节点的数据一致性,各个节点中在执行区块中的多个交易时,对该多个交易的提交顺序需要是一致的,这样才能得到一致的执行结果。因此,在现有技术中,记账节点在执行交易之前会按照预定规则对将要执行的多个交易进行编号,并按照编号的顺序依次执行多个交易,也即依次提交多个交易,并且其它节点在接收到该区块之后,也是按照上述交易编号顺序依次执行并提交所述多个交易。然而,所述多个交易并不一定都是相互依赖的,在两个交易之间不存在依赖性的情况中,并发执行这两个交易并不影响最终的结果。而如果并发执行的两个交易存在依赖性,则该并发执行将影响到最终的结果。
因此,需要一种更有效的在区块链中并发执行多个交易的方法。
发明内容
本说明书实施例旨在提供一种更有效的在区块链中并发执行多个交易的方法。
为实现上述目的,本说明书一个方面提供一种在区块链中并发执行多个交易的方 法,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述方法在区块链中的第一节点执行,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述方法包括:对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在对于每个在前交易,基于所述写字段确定未执行对所述第一变量的写操作的情况中,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,对于所述多个交易中提交顺序在所述第一交易之前的第二交易,基于所述写字段确定已执行该第二交易中的对所述第一变量的写操作的情况中,相对于第一交易进行等待,以在提交第二交易之后执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作包括,向本地专用硬件发送报告,以请求所述专用硬件进行所述确定,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用硬件接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表存储在专用服务器中,其中,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作包括,向所述专用服务器发送报告,以请求所述专用服务器进行所述确定,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在发送所述报告的同时,请求所述专用服务器执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用服务器接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表中还包括与所述第一变量对应的读字段,所述读字段用于记录所述多个交易中的对所述第一变量的读操作的执行,所述方法还包括, 在执行第一交易中的对所述第一变量的读操作之后,相应地修改所述读字段。
在一个实施例中,所述读字段包括与所述多个交易分别对应的多位,其中,相应地修改所述读字段包括,相应地修改所述读字段中与第一交易对应的位。
在一个实施例中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,所述方法还包括,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述多个交易中还包括第三交易,其中,所述第三交易的提交顺序在所述第一交易和第二交易之间,所述方法还包括:在从本地接收重新执行第一交易中的对所述第一变量的读操作的通知之后,基于所述写字段确定是否已执行了第三交易中对第一变量的写操作;在确定已执行了第三交易中的写操作的情况中,进行等待,以在提交了第三交易中对第一变量的写操作之后,重新执行第一交易中对第一变量的读操作。
在一个实施例中,所述写字段中包括的预定数目的位与预定数目的交易分别对应,所述方法还包括,在提交所述第二交易之后,将所述写字段中与所述第二交易对应的位的第一值复原,其中所述第一值用于记录:已执行所述第二交易中的对所述第一变量的写操作。
在一个实施例中,所述读字段中包括的预定数目的位与预定数目的交易分别对应,所述第二交易中还包括对第一字段的读操作,所述方法还包括,在提交所述第二交易之后,将所述读字段中与所述第二交易对应的位的第一值复原,其中该第一值用于记录:已执行所述第二交易中的对所述第一变量的读操作。
在一个实施例中,所述第一节点中预设有交易执行窗口,所述多个交易为所述交易执行窗口当前包括的多个交易,其中,所述多个交易的数目小于等于所述预定数目,所述方法还包括,在提交所述第二交易之后,将所述交易执行窗口在所述第一节点中包括的以预定提交顺序排列的多个交易中向后移动一个交易。
在一个实施例中,所述变量访问表中还包括第一全局变量,用于指示所述交易执行窗口的位置。
在一个实施例中,所述变量访问表中还包括与所述第一变量对应的序列号字段,用于指示所述第一变量对应的交易批次。
在一个实施例中,所述变量访问表中包括与所述第一变量对应的键,所述键为所述第一变量的哈希值。
本说明书另一方面提供一种在区块链中并发执行多个交易的装置,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述装置部署在区块链中的第一节点中,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述装置包括:
第一确定单元,配置为,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及
执行单元,配置为,基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,所述执行单元还配置为,在对于每个在前交易,基于所述写字段确定未执行对所述第一变量的写操作的情况中,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述执行单元还配置为,对于所述多个交易中提交顺序在所述第一交易之前的第二交易,基于所述写字段确定已执行该第二交易中的对所述第一变量的写操作的情况中,相对于第一交易进行等待,以在提交第二交易之后执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,所述第一确定单元还配置为,向本地专用硬件发送报告,以请求所述专用硬件进行所述确定,
所述执行单元还配置为,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用硬件接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表存储在专用服务器中,其中,所述第一确定单元还配置为,向所述专用服务器发送报告,以请求所述专用服务器进行所述确定,
所述执行单元还配置为,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用服务器接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表中还包括与所述第一变量对应的读字段,所述读字段用于记录所述多个交易中的对所述第一变量的读操作的执行,所述装置还包括,修改单元,配置为,在执行第一交易中的对所述第一变量的读操作之后,相应地修改所述读字段。
在一个实施例中,所述读字段包括与所述多个交易分别对应的多位,其中,所述修改单元还配置为,相应地修改所述读字段中与第一交易对应的位。
在一个实施例中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,所述装置还包括,
第二确定单元,配置为,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;
通知单元,配置为,在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述多个交易中还包括第三交易,其中,所述第三交易的提交顺序在所述第一交易和第二交易之间,所述装置还包括:
第三确定单元,配置为,在从本地接收重新执行第一交易中的对所述第一变量的读操作的通知之后,基于所述写字段确定是否已执行了第三交易中对第一变量的写操作;
等待单元,配置为,在确定已执行了第三交易中的写操作的情况中,进行等待,以在提交了第三交易中对第一变量的写操作之后,重新执行第一交易中对第一变量的读操作。
在一个实施例中,所述写字段中包括的预定数目的位与预定数目的交易分别对应,所述装置还包括,第一复原单元,配置为,在提交所述第二交易之后,将所述写字段中与所述第二交易对应的位的第一值复原,其中所述第一值用于记录:已执行所述第二交易中的对所述第一变量的写操作。
在一个实施例中,所述读字段中包括的预定数目的位与预定数目的交易分别对应, 所述第二交易中还包括对第一字段的读操作,所述装置还包括,第二复原单元,配置为,在提交所述第二交易之后,将所述读字段中与所述第二交易对应的位的第一值复原,其中该第一值用于记录:已执行所述第二交易中的对所述第一变量的读操作。
在一个实施例中,所述第一节点中预设有交易执行窗口,所述多个交易为所述交易执行窗口当前包括的多个交易,其中,所述多个交易的数目小于等于所述预定数目,所述装置还包括,窗口移动单元,配置为,在提交所述第二交易之后,将所述交易执行窗口在所述第一节点中包括的以预定提交顺序排列的多个交易中向后移动一个交易。
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行上述任一项方法。
本说明书另一方面提供一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现上述任一项方法。
通过根据本说明书实施例的在区块链中并发执行交易的方案,通过利用变量访问表记录交易执行窗口中并发执行的多个交易执行的对同一个变量的读写操作,从而可使得对于没有相互依赖性的多个交易,可并发执行这些交易,对于具有相互依赖性的多个交易,可串行执行这些交易,从而在保证计算结果一致性的同时,加快了处理速度,提高了处理性能。
附图说明
通过结合附图描述本说明书实施例,可以使得本说明书实施例更加清楚。
图1示出根据本说明书实施例的区块链系统;
图2示出根据本说明书实施例的一种在区块链中并发执行多个交易的方法流程图;
图3示出图1中的变量访问表中与第一变量相对应的条目;
图4示出了根据本说明书实施例的交易执行窗口的示意图;
图5示出根据本说明书实施例的一种在区块链中并发执行多个交易的装置5000。
具体实施方式
下面将结合附图描述本说明书实施例。
图1示出根据本说明书实施例的区块链系统示意图。如图1所示,所述系统中包 括构成区块链的多个节点(图中示意示出6个节点),这些节点两两相连,其中例如包括节点11、节点12和节点13。如本领域技术人员所知,在区块链中,一些节点会收集区块链中的多个交易放入交易池中并竞争记账权。例如图中的节点11通过获取记账权而成为记账节点。节点11在成为记账节点之后会执行其交易池中的多个交易,并将该多个交易打包成区块发送给其它节点,例如发送给节点12。节点12将会对该区块进行验证,并同样地执行该区块中的多个交易。在预定数目个节点对该区块进行验证之后,也即对该区块达到了共识,区块链中的其它节点(例如节点13)将不需要继续对该区块进行验证,而是直接对该区块中的交易进行执行,以更新本地的相关数据。
所述多个交易中可能涉及到对多个变量的计算,在两个交易中不涉及相同的变量的情况中,其执行顺序并不会影响最终的计算结果,而在两个交易中涉及相同的变量的情况中,其执行顺序将会影响最终的计算结果。因此,在本说明书实施例中,为了保证各个节点对多个交易的执行结果是相同的,在各个节点都预设了各自的变量访问表,如图中的与节点11、节点12和节点13分别对应的变量访问表11、变量访问表12和变量访问表13。该变量访问表中包括多个交易中涉及的各个变量的条目,在变量的条目中,包括各个交易对该变量的执行记录。例如,如图中对节点11的变量访问表11中放大所示,该变量访问表中包括k 1,k 2,…k n等,以及与k 1,k 2,…k n分别对应的写字段,读字段,窗口位置(字段)和序列号(字段)。其中,k 1,k 2,…k n分别为与多个交易中包括的各个变量相对应的键(key),其例如为各个变量的哈希值,n例如可以取较大值,例如100万。其中,写字段用于记录各个交易对应的执行体对相应变量执行的写操作,读字段用于记录各个交易对应的执行体对相应变量执行的读操作,该执行体例如可以为线程、进程、协程中的任一个。在本说明书实施例中,由于交易数量较多,可设定交易执行窗口,即当前只并发执行交易执行窗口中的多个交易。在该情况中,如图中所示,变量访问表中的窗口位置用于指示当前交易执行窗口的位置,该窗口位置字段值可基于对应于窗口位置预设的全局变量获取。所述序列号为交易批次号。
从而,在执行区块中的多个交易(例如交易执行窗口中的多个交易)时,通过参考变量访问表,使得对于不存在相互依赖关系的多个交易,可并发执行该多个交易,而对于存在相互依赖关系的多个交易,可通过重读、等待等方式串行执行该多个交易,从而在保证各个节点计算结果一致的同时,对部分交易并发执行,节省了处理时间,提高了计算效率。
可以理解,上文对图1的描述只是示意性地,而不是用于限制本说明书实施例的 范围。例如,所述变量访问表不限于为图1中所示的表,而可以根据需要进行变化。例如,所述变量访问表中不一定包括窗口位置字段和序列号字段等。下文将详细描述根据本说明书实施例的并发执行交易的过程。
图2示出根据本说明书实施例的一种在区块链中并发执行多个交易的方法流程图,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述方法在区块链中的第一节点执行,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述方法包括:
步骤S202,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;
步骤S204,基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
如上文中参考图1中所述,该方法在区块链中的一个节点执行。该节点在打包区块时,或者该节点在接收到新生成的区块之后,都会对相关的多个交易进行执行提交。例如,一个区块中可包括几千笔交易,而这几千笔交易可能涉及几百个变量,其中,多个交易可能访问不同的变量,或者,多个交易可能访问相同的变量。在现有技术中,在记账节点中,已经根据预定规则确定了将打包到一个区块中的多个交易各自的交易编号,该交易编号的顺序指示了交易的执行顺序和提交顺序。在本说明书实施例中,为了使得最后的计算结果与现有技术中的串行计算结果相同,对区块中的多个交易保留预定好的提交顺序,即,以各个交易的编号顺序作为其各自的提交顺序,同时,基于各个节点预设的变量访问表,使得没有依赖关系的各个交易可并发执行,并使得具有依赖关系的各个交易依据其编号的先后串行执行,其中,对于先后编号的交易1和交易2,如果在交易1中对第一变量进行写入,在交易2中对第一变量进行读取,则交易2依赖于交易1的结果。
图3示出图1中的变量访问表中与第一变量相对应的条目。如图3中所示,第一变量例如与变量访问表中的k1对应,k1为第一变量的键值,其例如为第一变量的哈希值。可以理解,k1不限于为第一变量的哈希值,而还可以为第一变量的任意标识。在变量访问表中,k1对应的字段包括以下与第一变量对应的几个字段:写字段、读字段、窗口位置字段、以及序列号字段。其中,写字段和读字段都包括预定数目的位数(图中仅 示意示出6位),例如,所述位数为64位,该位数应大于等于区块链中并发执行的交易的最大数目,从而使得并发执行的每个交易都可以与该字段中的一位唯一对应。其中,如图3中所示,写字段和读字段中各位的初始值都为0。其中,所述写字段用于记录并发执行的多个交易中包括的各个写操作是否已执行,所述读字段用于记录并发执行的多个交易中包括的各个读操作是否已执行。例如,在写字段中,对于预定数目的并发执行的多个交易(例如5个交易),可通过将其交易编号对64取模,从而确定其在64位中对应的位。也就是说,出于节省内存的考虑,将所述读写字段设置为环形缓冲区,从而多个交易可复用该读写字段,例如,读写字段中最多能记录64个交易的访问信息,从而,交易1和交易65会使用同一个位置进行记录。在写字段中与例如第一交易相应的位中,当第一交易未执行对第一变量的写操作时,第一交易对应的位中的值为0,当第一交易执行对第一变量的写操作之后,可将该位中的值修改为1。在本说明书实施例中,执行对变量的写操作是指,在本地内存中执行该写操作,而并未对变量进行实际的写操作,在本实施例中,仅在提交该交易时,才对变量进行实际的写操作。读字段的各位的值可类似地修改,例如,当第一交易未执行对第一变量的读操作时,在读字段中与第一交易相应的位中的值为0,当第一交易执行对第一变量的读操作之后,可将该位中的值修改为1。在本说明书实施例中,执行对变量的读操作是指,对存储的变量进行读取,以获取该变量的当前值。
可以理解,图3所示的读写字段只是根据本实例的读写字段的一种具体实现方式,根据本说明书实施例的读写字段不限于为图3所示的具体形式,只要其可以记录并发执行的各个交易的执行体对第一变量的读操作/写操作即可。
通常,在需要执行的交易数目较多的情况中,在执行交易时可设置交易执行窗口,该交易执行窗口可包括预定数目的交易。交易执行窗口的目的是:使得执行体在执行完窗口下限处的交易时,知道“这个交易获得的输入信息都是最新的,而不用等待其它交易就可以进行最终提交”,而对于窗口中间的交易,其执行体在执行完该交易之后不能确定此交易是否获得了最新的输入,因此要等到它位于窗口下限时,才能最终提交,在提交之前,该交易可能发现自己被标记了要重做;窗口上限用于限制执行交易所使用的资源量,如果上限是无限大,则就算没有交易最终提交,执行体也可以一直处理交易,直到内存资源耗光。
将该交易执行窗口在以提交顺序(或交易编号)排列的多个交易中滑动,使得在区块链节点中可并发执行该交易执行窗口中的多个交易,并且可设定,每提交一个交易, 就将交易执行窗口向后滑动一个交易。图4示出了根据本说明书实施例的交易执行窗口的示意图。如图4中所示,图中1到10十个数字表示编号分别为1到10的十个交易,所述交易执行窗口例如可包括5个交易。该交易执行窗口初始可落在交易1到5上。在提交交易1之后,窗口往后移动一个交易,即落到交易2到6上,同样地,在提交交易2之后,窗口再往后移动一个交易,从而如图中所示,落到交易3到7上。
从而,图3中的窗口位置字段用于指示交易执行窗口目前所在位置。该窗口位置字段例如对应于第一全局变量,从而每个变量对应的该字段都可以基于该第一全局变量获取当前的窗口位置。该第一全局变量例如可以设定为等于当前窗口的起始交易编号、结束交易编号等。例如在窗口位置如图4所示的情况中,图3中的窗口位置例如可填入“3”,即,在该情况中,以窗口中的起始交易标识窗口位置。该窗口位置字段可以对应于多个值,例如第一个值对应于当前应串行提交的交易编号,第二个值对应于出于被处理状态的交易的最大编号,或者第二个值可以为窗口包括交易的数目等等。
在一个区块中包括几千个交易的情况中,可对这些交易分批执行,例如可设定每批交易包括1000个交易,并且对于每批交易设定批号。从而,所述序列号字段可指示当前处理交易的批号。例如,在执行第一交易对第一变量的写或读操作时,可比较该第一交易的当前批号与变量访问表中记录的第一变量的序列号字段中指示的批号,如果二者一致,则可继续执行所述操作,如果二者不一致,则可清空变量访问表中与第一变量对应的已有数据。例如,图3所示的序列号为“2”,这表示,正在执行的交易为第二批交易,该第二批交易同样从1到1000编号,其通过序列号“2”与第一批中编号从1到1000的交易相区分。通过在变量访问表中加入序列号字段,可免去对变量访问表的清零设置。在变量访问表中,各个变量的访问率可能不同,有的变量(例如变量k2)很容易引起冲突。对于该变量k2,需要将其标记出来,以使得对该变量k2的读访问者在等前序交易提交之后再进行。如果通过序列号字段,通过判断批号是否过时,就可以作为对该变量k2的标记。如果不采用序列号的方法,则可以通过异步的方式进行清零。
可以理解,图3所示的变量访问表仅仅是示意性的,并不用于限制本说明书实施例的范围。例如,在并发执行的交易数量较少的情况中,不需要对交易进行分批,也不需要通过交易执行窗口控制交易执行数量,从而变量访问表中可以仅包括写字段和读字段。在一个实施例中,在变量访问表中可仅包括写字段,从而,在执行交易中的读操作时,可通过基于写字段判断编号在前的并发执行的交易是否执行了写操作来进行读操作,而在执行交易的写操作时,可对编号在后的交易都进行通知,以使得编号在后的执行过 读操作的交易都重新执行读操作。在一个实施例中,在变量访问表中可仅包括读字段,从而,在执行交易中的读操作时,可直接进行,在执行交易的写操作时,可通过基于读字段判断编号在后的同时执行的交易是否执行了读操作,并在提交之后通知执行了读操作的交易重新执行读操作。
下面详细描述该方法中的步骤。
首先,在步骤S202,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易。
例如,参考图4中的交易执行窗口,例如所述窗口如图中所示落在交易3~7上,即,在区块链节点中当前对交易3~7进行并发执行,例如,可通过5个执行体3~7并发执行交易3~7,例如在以太坊节点中,具体是在虚拟机中对交易3~7进行并发执行。在该情况中,假设交易6为所述第一交易,其即将执行对第一变量的读操作。由于交易3~7是按照该交易编号顺序依次提交,因此,交易6需要判断正在同时执行的交易3~5有没有进行写操作,如果交易3~5中任一个交易进行了写操作,该写操作将最终改变第一变量的值,因此,交易6需要等前面的包括写操作的交易提交了之后,才能读取到第一变量的经过该写操作的值。例如,交易4中包括对第一变量的写操作,并且在节点中当前已经执行了交易4中的所述写操作,从而变量访问表中与第一变量对应的写字段中与交易4对应位被修改为1,节点中与交易6对应的执行体基于所述变量访问表可获知节点中的其它执行体已经执行了交易4中的对第一变量的写操作。
在一个实施例中,区块链节点部署在一台服务器上,从而所述变量访问表存储在本地的共享内存中,在该情况中,与交易6对应的执行体可在查找变量访问表的近乎同时获知查找结果。
在一个实施例中,区块链节点部署在多台服务器上,从而,所述变量访问表例如存储在一台专用服务器上,该节点中的其它服务器可通过访问该专用服务器而从专用服务器接收到该变量访问表中的信息。
在步骤S204,基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,在所述变量访问表存储在本地的共享内存中的情况中,与交易6对应的执行体可在查找变量访问表的近乎同时获知查找结果,并在获知查找结果之后再基于该结果进行后续的操作。例如,交易6在对其之前的每个交易都进行上述查询之后 确定:交易3~5目前都未进行对第一变量的写操作,也就是说,交易3~5的执行目前都未改变第一变量的值,因此,执行体6执行对第一变量的值的读取。例如,执行体6在对其之前的每个交易都进行上述查询之后确定:执行体4已经进行了对第一变量的写操作,则交易6进行等待,直到交易4提交之后,再确定是否进行对第一变量的读取。在交易4提交之后,如前文所述,交易执行窗口将移动到5~9上,执行体6可再次对其之前的每个交易进行上述查询,即基于变量访问表查询执行体5是否进行了对第一变量的写操作,在执行体5也进行了所述写操作的情况中,执行体6将等待交易5提交之后再读取。再例如,执行体6在对其之前的每个交易都进行上述查询之后确定:交易4和执行体5都已经进行了对第一变量的写操作,则交易6进行等待,直到交易5提交之后再进行对第一变量的读取。即,执行体6需要等到并发执行的多个交易中的在交易6前面的且距离交易6最近的交易的写操作提交之后再进行读操作。而并发执行的交易中的在交易6后面的交易的写操作并不影响交易6的读操作的执行。
在一个实施例中,所述变量访问表存储在本地,与交易6对应的执行体可向本地专用硬件发送报告,以请求所述专用硬件上述步骤中的确定。所述专用硬件例如为本地的专用于访问和改写变量访问表的CPU或FPGA等。执行体6在发送所述报告的同时,执行对第一变量的读取操作,即,这里不等待接收到查询结果而直接进行对第一变量的读取。在交易6提交之前,由执行体6基于从专用硬件接收的信息确定是否要进行对第一变量的重新读取。例如,在专用硬件接收到所述报告并进行查询之后确定在交易6之前的交易3~5中存在执行了对第一变量的写操作的交易,在该情况中,专用硬件通知执行体6重新进行对第一变量的读取。
在所述变量访问表例如存储在一台专用服务器上的情况中,例如当前通过服务器1并发执行交易3~7,服务器1中与交易6对应的执行体将要执行对第一变量的读取操作。服务器1向专用服务器发送将要读取第一变量的报告,以请求专用服务器进行确定在交易6之前的并发执行的交易的执行体是否进行了对第一变量的写操作。服务器1在发送所述报告的同时,由执行体6请求所述专用服务器执行对第一变量的读取操作,即,由于接收到来自专用服务器的查询结果需要经过较长通信时间,因此,这里不等待接收到查询结果而直接进行对第一变量的读取。在交易6提交之前,由执行体6基于从专用服务器接收的信息确定是否要进行对第一变量的重新读取。例如,在专用服务器接收到所述报告并进行查询之后确定在交易6之前的交易3~5中存在执行了对第一变量的写操作的交易,在该情况中,专用服务器通知执行体6重新进行对第一变量的读取。这里, 为了降低开发难度,执行体6在接收到该通知之后,通常是重新执行全部交易6。例如,在上述查询中未查询到交易3~5中存在执行了对第一变量的写操作的交易,但是交易3~5的执行体在执行体6进行读取之后后续进行了写操作,并在提交之后写入专用服务器的变量访问表中,从而专用服务器基于该写入通知执行体6进行对第一变量的重新读取,则执行体6在提交前重新执行交易6。而在上述查询中未查询到交易3~5中存在执行了对第一变量的写操作的交易,且交易3~5的执行体在执行体6进行读取之后也未进行写操作,即专用服务器未通知执行体6进行重新读取,则执行体6可直接提交交易6。
在由执行体6如上述进行对第一变量的读操作之后,将变量访问表中的与第一变量对应的读字段中的对应于交易6的位修改为例如“1”,该位在执行体6为执行读操作之前例如为0。
在一个实施例中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,如图2中虚线框所示,所述方法还包括以下步骤:
步骤S206,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;以及
步骤S208,在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
在上述实施例中,例如图4中所示的交易3即为所述第二交易。在执行体6如上所述进行了读操作之后,例如执行体3执行了写操作。具体是,执行体3将将要对第一变量进行写入的值存入内存预定位置中,然后将变量访问表中的与第一变量对应的写字段中的对应于交易3的位修改为“1”。在经过该修改之后,例如执行体7在该修改之后将要进行对第一变量的读操作,其与上文类似地,通过查询变量访问表可获知执行体3已经执行了对第一变量的写操作,从而,执行体7将等待交易3提交之后再进行上述读操作。
由于交易3位于交易执行窗口的最左边,因此,执行体3在执行完交易3之后,将进行对交易3的提交。例如,进程3可基于表中的窗口位置字段确定当前是否提交交易3。在提交了交易3之后,也即对第一变量进行了实际写入,修改了第一变量的值。 当提交了交易3之后,将进行如下步骤。
在步骤S206,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作。
在上述提交交易3之后,执行体3将针对该提交之前在所述窗口中的其它几个交易(即交易4~7)确定其对应执行体是否已进行了对第一变量的读操作,如果已经进行了读操作,则通知相应执行体重新执行读操作。例如,如上文所述,交易6(即所述第一交易)为所述窗口中在交易3之后的一个交易,则执行体3基于所述读字段中与交易6对应的位确定执行体6是否已经执行了对第一变量的读操作。
在步骤S208,在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
在通过上述步骤的确定之后,执行体3在基于变量访问表确定执行体6已经进行了读操作之后,通知执行体6重新执行对第一变量的读操作。其中,在变量访问表存储在本地共享内存中的情况中,执行体3可在交易6的私有存储空间中进行标记,以通知执行体6进行重读操作,交易6在提交前或其它时机检查是否存在该重读标记。或者,执行体3在进行所述标记之后,可向执行体6发送异步信号,执行体6在接收到该异步信号之后,检查当前交易是否被设置为需要重读(因为该执行体在接收到异步信号时,可能已经不在执行交易6了),若需要,则转入重读流程。在变量访问表存储在另外的专用服务器的情况中,该服务器通过网络委托执行体6所在主机进行标记,以通知执行体6进行重读操作。
执行体6可立即重新执行该读操作,或者,执行体6可从变量访问表查看执行体4和5后续有没有进行写操作,例如,在执行体4也进行了写操作的情况中,执行体6可等到交易4提交之后再重新执行读操作。
另外,在提交了交易3之后,交易执行窗口往后移动一位,即位于交易4~8上,在该情况中,执行体3还将变量访问表中与第一变量对应的写字段中的与交易3对应的位清零,以使得不影响后续交易对该位的使用。类似地,如果交易3中还包括读操作,执行体3在之前执行读操作之后也将读字段中的相应为修改为1,而在提交交易3之后,执行体3同样地将该位清零。
图5示出根据本说明书实施例的一种在区块链中并发执行多个交易的装置5000,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述装置部署在区块链 中的第一节点中,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述装置包括:
第一确定单元501,配置为,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及
执行单元502,配置为,基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,所述执行单元502还配置为,在对于每个在前交易,基于所述写字段确定未执行对所述第一变量的写操作的情况中,执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述执行单元502还配置为,对于所述多个交易中提交顺序在所述第一交易之前的第二交易,基于所述写字段确定已执行该第二交易中的对所述第一变量的写操作的情况中,相对于第一交易进行等待,以在提交第二交易之后执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述变量访问表存储在本地,其中,所述第一确定单元501还配置为,向本地专用硬件发送报告,以请求所述专用硬件进行所述确定,
所述执行单元502还配置为,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用硬件接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表存储在专用服务器中,其中,所述第一确定单元501还配置为,向所述专用服务器发送报告,以请求所述专用服务器进行所述确定,
所述执行单元502还配置为,在发送所述报告的同时,请求所述专用服务器执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用服务器接收的确定结果,确定是否重新执行第一交易。
在一个实施例中,所述变量访问表中还包括与所述第一变量对应的读字段,所述读字段用于记录所述多个交易中的对所述第一变量的读操作的执行,所述装置还包括,修改单元503,配置为,在执行第一交易中的对所述第一变量的读操作之后,相应地修 改所述读字段。
在一个实施例中,所述读字段包括与所述多个交易分别对应的多位,其中,所述修改单元还配置为,相应地修改所述读字段中与第一交易对应的位。
在一个实施例中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,所述装置还包括,
第二确定单元504,配置为,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;以及
通知单元505,配置为,在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
在一个实施例中,所述多个交易中还包括第三交易,其中,所述第三交易的提交顺序在所述第一交易和第二交易之间,所述装置还包括:
第三确定单元506,配置为,在从本地接收重新执行第一交易中的对所述第一变量的读操作的通知之后,基于所述写字段确定是否已执行了第三交易中对第一变量的写操作;
等待单元507,配置为,在确定已执行了第三交易中的写操作的情况中,进行等待,以在提交了第三交易中对第一变量的写操作之后,重新执行第一交易中对第一变量的读操作。
在一个实施例中,所述写字段中包括的预定数目的位与预定数目的交易分别对应,所述装置还包括,第一复原单元508,配置为,在提交所述第二交易之后,将所述写字段中与所述第二交易对应的位的第一值复原,其中所述第一值用于记录:已执行所述第二交易中的对所述第一变量的写操作。
在一个实施例中,所述读字段中包括的预定数目的位与预定数目的交易分别对应,所述第二交易中还包括对第一字段的读操作,所述装置还包括,第二复原单元509,配置为,在提交所述第二交易之后,将所述读字段中与所述第二交易对应的位的第一值复原,其中该第一值用于记录:已执行所述第二交易中的对所述第一变量的读操作。
在一个实施例中,所述第一节点中预设有交易执行窗口,所述多个交易为所述交易执行窗口当前包括的多个交易,其中,所述多个交易的数目小于等于所述预定数目,所述装置还包括,窗口移动单元510,配置为,在提交所述第二交易之后,将所述交易执行窗口在所述第一节点中包括的以预定提交顺序排列的多个交易中向后移动一个交 易。
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行上述任一项方法。
本说明书另一方面提供一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现上述任一项方法。
通过根据本说明书实施例的在区块链中并发执行交易的方案,通过利用变量访问表记录交易执行窗口中并发执行的多个交易执行的对同一个变量的读写操作,从而可使得对于没有相互依赖性的多个交易,可并发执行这些交易,对于具有相互依赖性的多个交易,可串行执行这些交易,从而在保证计算结果一致性的同时,加快了处理速度,提高了处理性能。
需要理解,本文中的“第一”,“第二”等描述,仅仅为了描述的简单而对相似概念执行区分,并不具有其他限定作用。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
上述对本说明书特定实施例执行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
本领域普通技术人员应该还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执轨道,取决于技术方案的特定应用和设计约束条件。本领域普通技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
结合本文中所公开的实施例描述的方法或算法的步骤可以用硬件、处理器执轨道的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果执行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (32)

  1. 一种在区块链中并发执行多个交易的方法,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述方法在区块链中的第一节点执行,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述方法包括:
    对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及
    基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
  2. 根据权利要求1所述的方法,其中,所述变量访问表存储在本地,其中,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在对于每个在前交易,基于所述写字段确定未执行对所述第一变量的写操作的情况中,执行第一交易中的对所述第一变量的读操作。
  3. 根据权利要求1所述的方法,其中,基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,对于所述多个交易中提交顺序在所述第一交易之前的第二交易,基于所述写字段确定已执行该第二交易中的对所述第一变量的写操作的情况中,相对于第一交易进行等待,以在提交第二交易之后执行第一交易中的对所述第一变量的读操作。
  4. 根据权利要求1所述的方法,其中,所述变量访问表存储在本地,其中,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作包括,向本地专用硬件发送报告,以请求所述专用硬件进行所述确定,
    基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用硬件接收的确定结果,确定是否重新执行第一交易。
  5. 根据权利要求1所述的方法,其中,所述变量访问表存储在专用服务器中,其中,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作包括,向所述专用服务器发送报告,以请求所述专用服务器进行所述确定,
    基于所述确定结果,执行第一交易中的对所述第一变量的读操作包括,在发送所述报告的同时,请求所述专用服务器执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用服务器接收的确定结果,确定是否重新执行第一交易。
  6. 根据权利要求1所述的方法,其中,所述变量访问表中还包括与所述第一变量对应的读字段,所述读字段用于记录所述多个交易中的对所述第一变量的读操作的执行,所述方法还包括,在执行第一交易中的对所述第一变量的读操作之后,相应地修改所述读字段。
  7. 根据权利要求6所述的方法,其中,所述读字段包括与所述多个交易分别对应的多位,其中,相应地修改所述读字段包括,相应地修改所述读字段中与第一交易对应的位。
  8. 根据权利要求6所述的方法,其中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,所述方法还包括,
    基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;以及
    在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
  9. 根据权利要求8所述的方法,其中,所述多个交易中还包括第三交易,其中,所述第三交易的提交顺序在所述第一交易和第二交易之间,所述方法还包括:
    在从本地接收重新执行第一交易中的对所述第一变量的读操作的通知之后,基于所述写字段确定是否已执行了第三交易中对第一变量的写操作;
    在确定已执行了第三交易中的写操作的情况中,进行等待,以在提交了第三交易中对第一变量的写操作之后,重新执行第一交易中对第一变量的读操作。
  10. 根据权利要求8所述的方法,其中,所述写字段中包括的预定数目的位与预定数目的交易分别对应,所述方法还包括,在提交所述第二交易之后,将所述写字段中与所述第二交易对应的位的第一值复原,其中所述第一值用于记录:已执行所述第二交易中的对所述第一变量的写操作。
  11. 根据权利要求10所述的方法,其中,所述读字段中包括的预定数目的位与预定数目的交易分别对应,所述第二交易中还包括对第一字段的读操作,所述方法还包括,在提交所述第二交易之后,将所述读字段中与所述第二交易对应的位的第一值复原,其中该第一值用于记录:已执行所述第二交易中的对所述第一变量的读操作。
  12. 根据权利要求10所述的方法,其中,所述第一节点中预设有交易执行窗口,所述多个交易为所述交易执行窗口当前包括的多个交易,其中,所述多个交易的数目小于等于所述预定数目,所述方法还包括,在提交所述第二交易之后,将所述交易执行窗 口在所述第一节点中包括的以预定提交顺序排列的多个交易中向后移动一个交易。
  13. 根据权利要求12所述的方法,所述变量访问表中还包括第一全局变量,用于指示所述交易执行窗口的位置。
  14. 根据权利要求1所述的方法,所述变量访问表中还包括与所述第一变量对应的序列号字段,用于指示所述第一变量对应的交易批次。
  15. 根据权利要求1所述的方法,其中,所述变量访问表中包括与所述第一变量对应的键,所述键为所述第一变量的哈希值。
  16. 一种在区块链中并发执行多个交易的装置,其中,所述多个交易具有预定的提交顺序,其中包括第一交易,所述装置部署在区块链中的第一节点中,所述第一节点预设有变量访问表,所述变量访问表中包括与第一变量对应的写字段,其中,所述写字段用于记录所述多个交易中的对所述第一变量的写操作的执行,所述装置包括:
    第一确定单元,配置为,对于每个在前交易,基于所述写字段确定:是否已执行该在前交易中的对所述第一变量的写操作,其中,所述在前交易为所述多个交易中提交顺序在所述第一交易之前的交易;以及
    执行单元,配置为,基于所述确定结果,执行第一交易中的对所述第一变量的读操作。
  17. 根据权利要求16所述的装置,其中,所述变量访问表存储在本地,其中,所述执行单元还配置为,在对于每个在前交易,基于所述写字段确定未执行对所述第一变量的写操作的情况中,执行第一交易中的对所述第一变量的读操作。
  18. 根据权利要求16所述的装置,其中,所述执行单元还配置为,对于所述多个交易中提交顺序在所述第一交易之前的第二交易,基于所述写字段确定已执行该第二交易中的对所述第一变量的写操作的情况中,相对于第一交易进行等待,以在提交第二交易之后执行第一交易中的对所述第一变量的读操作。
  19. 根据权利要求16所述的装置,其中,所述变量访问表存储在本地,其中,所述第一确定单元还配置为,向本地专用硬件发送报告,以请求所述专用硬件进行所述确定,
    所述执行单元还配置为,在发送所述报告的同时,执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用硬件接收的确定结果,确定是否重新执行第一交易。
  20. 根据权利要求16所述的装置,其中,所述变量访问表存储在专用服务器中,其中,所述第一确定单元还配置为,向所述专用服务器发送报告,以请求所述专用服务 器进行所述确定,
    所述执行单元还配置为,在发送所述报告的同时,请求所述专用服务器执行第一交易中的对所述第一变量的读操作,以及在提交第一交易之前,基于从所述专用服务器接收的确定结果,确定是否重新执行第一交易。
  21. 根据权利要求16所述的装置,其中,所述变量访问表中还包括与所述第一变量对应的读字段,所述读字段用于记录所述多个交易中的对所述第一变量的读操作的执行,所述装置还包括,修改单元,配置为,在执行第一交易中的对所述第一变量的读操作之后,相应地修改所述读字段。
  22. 根据权利要求21所述的装置,其中,所述读字段包括与所述多个交易分别对应的多位,其中,所述修改单元还配置为,相应地修改所述读字段中与第一交易对应的位。
  23. 根据权利要求21所述的装置,其中,所述多个交易中还包括第二交易,其中,所述第二交易的提交顺序在所述多个交易中位于第一位,所述第二交易中包括对所述第一变量的写操作,当在相应地修改所述读字段之后提交所述第二交易的情况中,所述装置还包括,
    第二确定单元,配置为,基于所述读字段,确定是否已执行第一交易中的对所述第一变量的读操作;以及
    通知单元,配置为,在确定已执行第一交易中的对所述第一变量的读操作的情况中,通知本地重新执行第一交易中的对所述第一变量的读操作。
  24. 根据权利要求23所述的装置,其中,所述多个交易中还包括第三交易,其中,所述第三交易的提交顺序在所述第一交易和第二交易之间,所述装置还包括:
    第三确定单元,配置为,在从本地接收重新执行第一交易中的对所述第一变量的读操作的通知之后,基于所述写字段确定是否已执行了第三交易中对第一变量的写操作;
    等待单元,配置为,在确定已执行了第三交易中的写操作的情况中,进行等待,以在提交了第三交易中对第一变量的写操作之后,重新执行第一交易中对第一变量的读操作。
  25. 根据权利要求23所述的装置,其中,所述写字段中包括的预定数目的位与预定数目的交易分别对应,所述装置还包括,第一复原单元,配置为,在提交所述第二交易之后,将所述写字段中与所述第二交易对应的位的第一值复原,其中所述第一值用于记录:已执行所述第二交易中的对所述第一变量的写操作。
  26. 根据权利要求25所述的装置,其中,所述读字段中包括的预定数目的位与预 定数目的交易分别对应,所述第二交易中还包括对第一字段的读操作,所述装置还包括,第二复原单元,配置为,在提交所述第二交易之后,将所述读字段中与所述第二交易对应的位的第一值复原,其中该第一值用于记录:已执行所述第二交易中的对所述第一变量的读操作。
  27. 根据权利要求25所述的装置,其中,所述第一节点中预设有交易执行窗口,所述多个交易为所述交易执行窗口当前包括的多个交易,其中,所述多个交易的数目小于等于所述预定数目,所述装置还包括,窗口移动单元,配置为,在提交所述第二交易之后,将所述交易执行窗口在所述第一节点中包括的以预定提交顺序排列的多个交易中向后移动一个交易。
  28. 根据权利要求27所述的装置,所述变量访问表中还包括第一全局变量,用于指示所述交易执行窗口的位置。
  29. 根据权利要求16所述的装置,所述变量访问表中还包括与所述第一变量对应的序列号字段,用于指示所述第一变量对应的交易批次。
  30. 根据权利要求16所述的装置,其中,所述变量访问表中包括与所述第一变量对应的键,所述键为所述第一变量的哈希值。
  31. 一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行权利要求1-15中任一项的所述的方法。
  32. 一种计算设备,包括存储器和处理器,其特征在于,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现权利要求1-15中任一项所述的方法。
PCT/CN2020/082454 2019-08-30 2020-03-31 在区块链中并发执行交易的方法和装置 WO2021036253A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910816544.8A CN110706101B (zh) 2019-08-30 2019-08-30 在区块链中并发执行交易的方法和装置
CN201910816544.8 2019-08-30

Publications (1)

Publication Number Publication Date
WO2021036253A1 true WO2021036253A1 (zh) 2021-03-04

Family

ID=69194057

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/082454 WO2021036253A1 (zh) 2019-08-30 2020-03-31 在区块链中并发执行交易的方法和装置

Country Status (3)

Country Link
CN (2) CN110706101B (zh)
TW (1) TWI730690B (zh)
WO (1) WO2021036253A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110706101B (zh) * 2019-08-30 2021-06-29 创新先进技术有限公司 在区块链中并发执行交易的方法和装置
CN111476663B (zh) * 2020-04-15 2022-08-12 腾讯科技(深圳)有限公司 一种数据处理方法、装置、节点设备及存储介质
EP3977390B1 (en) * 2020-08-03 2023-12-06 Alipay (Hangzhou) Information Technology Co., Ltd. Blockchain transaction processing systems and methods
CN111813795B (zh) 2020-08-28 2020-12-04 支付宝(杭州)信息技术有限公司 在区块链网络中确认交易的方法及装置
CN111754350B (zh) * 2020-08-28 2020-11-24 支付宝(杭州)信息技术有限公司 并行获取区块链中的交易访问变量的编号的方法和装置
CN112001798B (zh) * 2020-10-28 2021-01-26 支付宝(杭州)信息技术有限公司 在区块链中并发执行交易的方法和装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1610884A (zh) * 2001-11-13 2005-04-27 皇家飞利浦电子股份有限公司 对于大数据结构的表目锁定
CN104750720A (zh) * 2013-12-30 2015-07-01 中国银联股份有限公司 多线程并发访问环境下高性能数据处理的实现
US10333694B1 (en) * 2018-10-15 2019-06-25 Accelor Ltd. Systems and methods for secure smart contract execution via read-only distributed ledger
CN110706101A (zh) * 2019-08-30 2020-01-17 阿里巴巴集团控股有限公司 在区块链中并发执行交易的方法和装置

Family Cites Families (20)

* 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
CN107018125B (zh) * 2017-02-17 2019-08-09 阿里巴巴集团控股有限公司 一种区块链系统、数据存储方法及装置
TWI646487B (zh) * 2017-06-23 2019-01-01 現代財富控股有限公司 具權限分級和避免重複執行的智能合約執行系統及其方法
US11281644B2 (en) * 2017-07-28 2022-03-22 Hitachi, Ltd. Blockchain logging of data from multiple systems
CN107688999B (zh) * 2017-08-11 2020-11-13 杭州溪塔科技有限公司 一种基于区块链的并行交易执行方法
CN107967291B (zh) * 2017-10-12 2019-08-13 腾讯科技(深圳)有限公司 日志条目复制方法、装置、计算机设备及存储介质
CN107832154B (zh) * 2017-11-14 2020-07-17 浙江亿邦通信科技有限公司 一种多进程处理方法、处理装置及应用
US11823178B2 (en) * 2017-11-17 2023-11-21 International Business Machines Corporation Optimization of high volume transaction performance on a blockchain
CN108681565B (zh) * 2018-04-28 2020-11-10 百度在线网络技术(北京)有限公司 区块链数据并行处理方法、装置、设备和存储介质
CN109064171A (zh) * 2018-07-26 2018-12-21 杭州秘猿科技有限公司 一种区块链并行交易的方法、装置及电子系统
CN109300036B (zh) * 2018-09-14 2020-08-14 百度在线网络技术(北京)有限公司 区块链网络的分叉回归方法和装置
CN111782275B (zh) * 2018-10-25 2024-02-06 创新先进技术有限公司 基于区块链的交易处理方法及装置、电子设备
CN109636384A (zh) * 2018-10-26 2019-04-16 阿里巴巴集团控股有限公司 一种并行化执行区块链交易的方法、装置及系统
CN109508337A (zh) * 2018-11-12 2019-03-22 杭州秘猿科技有限公司 一种交易并行执行方法、装置、电子设备及系统
US11277389B2 (en) * 2018-11-27 2022-03-15 Advanced New Technologies Co., Ltd. System and method for information protection
CN109559226B (zh) * 2018-11-28 2021-03-02 连连银加信息技术有限公司 区块链交易执行方法、系统及电子设备和存储介质
CN109547211B (zh) * 2018-11-29 2020-06-30 浙江大学 应用数字签名技术的分级并发拜占庭共识方法及系统
SG11201907157XA (en) * 2018-12-28 2019-09-27 Alibaba Group Holding Ltd Parallel execution of transactions in a blockchain network
CN109784930B (zh) * 2019-02-18 2023-07-18 深圳市迅雷网络技术有限公司 一种区块链交易数据的处理方法、装置、电子设备及介质
CN110135985B (zh) * 2019-04-04 2021-07-27 杭州抖音科技有限公司 一种区块链上交易的并行执行方法及系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1610884A (zh) * 2001-11-13 2005-04-27 皇家飞利浦电子股份有限公司 对于大数据结构的表目锁定
CN104750720A (zh) * 2013-12-30 2015-07-01 中国银联股份有限公司 多线程并发访问环境下高性能数据处理的实现
US10333694B1 (en) * 2018-10-15 2019-06-25 Accelor Ltd. Systems and methods for secure smart contract execution via read-only distributed ledger
CN110706101A (zh) * 2019-08-30 2020-01-17 阿里巴巴集团控股有限公司 在区块链中并发执行交易的方法和装置

Also Published As

Publication number Publication date
TW202109510A (zh) 2021-03-01
TWI730690B (zh) 2021-06-11
CN113570460A (zh) 2021-10-29
CN110706101B (zh) 2021-06-29
CN110706101A (zh) 2020-01-17

Similar Documents

Publication Publication Date Title
WO2021036253A1 (zh) 在区块链中并发执行交易的方法和装置
US9990391B1 (en) Transactional messages in journal-based storage systems
US10108658B1 (en) Deferred assignments in journal-based storage systems
CN108073656A (zh) 一种数据同步方法及相关设备
WO2021036258A1 (zh) 在区块链中并发执行交易的方法和装置
CN113743950B (zh) 在区块链系统中执行交易的方法、节点和区块链系统
US10324905B1 (en) Proactive state change acceptability verification in journal-based storage systems
CN110569264B (zh) 合约数据处理方法、装置、计算机可读存储介质和计算机设备
US20180322301A1 (en) Commit and rollback of data streams provided by partially trusted entities
EP3961461A1 (en) Method and apparatus for obtaining number for transaction-accessed variable in blockchain in parallel
CN111125040A (zh) 管理重做日志的方法、装置及存储介质
JP2023541298A (ja) トランザクション処理方法、システム、装置、機器、及びプログラム
CN114827165A (zh) 对多个交易进行分组的方法和区块链节点
CN114942847A (zh) 执行交易的方法和区块链节点
CN113744062B (zh) 在区块链中执行交易的方法、区块链节点和区块链
WO2021036259A1 (zh) 在区块链中并发执行交易的方法和装置
CN110706108B (zh) 在区块链中并发执行交易的方法和装置
KR101797482B1 (ko) 데이터베이스 시스템에서 블록 복구 방법, 장치 및 컴퓨터 판독가능 매체에 저장된 컴퓨터-프로그램
CN112783954B (zh) 数据访问方法、装置及服务器
WO2021057165A1 (zh) 在区块链中并发执行交易的方法和装置
CN113836238A (zh) 数据命令的批量处理方法及装置
CN107102898B (zh) 一种基于numa架构的内存管理、构建数据结构的方法及装置
CN113256419B (zh) 一种区块链交易检索方法及系统
WO2024026784A1 (zh) 事务处理方法、装置、节点及计算机可读存储介质
US11983168B2 (en) Block verification method, apparatus and device

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: 20856543

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: 20856543

Country of ref document: EP

Kind code of ref document: A1