CN111047449B - Method and device for executing transaction in block chain - Google Patents
Method and device for executing transaction in block chain Download PDFInfo
- Publication number
- CN111047449B CN111047449B CN202010170493.9A CN202010170493A CN111047449B CN 111047449 B CN111047449 B CN 111047449B CN 202010170493 A CN202010170493 A CN 202010170493A CN 111047449 B CN111047449 B CN 111047449B
- Authority
- CN
- China
- Prior art keywords
- transaction
- local
- execution
- hash
- variable
- Prior art date
- Legal status (The legal status 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 status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION 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/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/14—Protection against unauthorised use of memory or access to memory
- G06F12/1458—Protection against unauthorised use of memory or access to memory by checking the subject access rights
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/62—Protecting access to data via a platform, e.g. using keys or access control rules
- G06F21/6218—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
- G06F21/6227—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database where protection concerns the structure of data, e.g. records, types, queries
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION 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/00—Payment architectures, schemes or protocols
- G06Q20/38—Payment protocols; Details thereof
- G06Q20/382—Payment protocols; Details thereof insuring higher security of transaction
- G06Q20/3825—Use of electronic signatures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION 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/00—Payment architectures, schemes or protocols
- G06Q20/38—Payment protocols; Details thereof
- G06Q20/382—Payment protocols; Details thereof insuring higher security of transaction
- G06Q20/3827—Use of message hashing
Landscapes
- Engineering & Computer Science (AREA)
- Business, Economics & Management (AREA)
- Theoretical Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Accounting & Taxation (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Finance (AREA)
- Strategic Management (AREA)
- General Business, Economics & Management (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Bioethics (AREA)
- General Health & Medical Sciences (AREA)
- Computer Hardware Design (AREA)
- Health & Medical Sciences (AREA)
- Databases & Information Systems (AREA)
- Development Economics (AREA)
- Economics (AREA)
- Marketing (AREA)
- Technology Law (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the specification provides a method and a device for executing transaction in a blockchain. The method includes speculative execution before the transaction is agreed upon, and official execution based on the agreement. The process of speculative execution comprises the steps of firstly reading a first transaction recorded locally; executing the transaction logic in the first transaction, and recording a variable operation request corresponding to an execution result in a memory; the transaction is then marked as a speculatively executed transaction. The formally executed process comprises the steps of obtaining a second transaction which is already known and is to be executed; judging whether the second transaction is a speculatively executed transaction, and if so, acquiring a corresponding variable operation request which is not submitted; then according to the variable operation request, judging whether the speculative execution of the second transaction conflicts with the consensus-based transaction execution; and if no conflict exists, directly submitting the variable operation corresponding to the variable operation request. Thus, the execution efficiency of the transaction is improved.
Description
Technical Field
One or more embodiments of the present disclosure relate to the field of blockchain technology, and more particularly, to a method and apparatus for performing transactions in a blockchain.
Background
The block chain technology is an application mode for realizing data distributed storage by utilizing computer technologies such as point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. In a blockchain network, the storage and recording of data is achieved by means of transactions. In early blockchain networks, only transactions in the form of transfers were supported. At present, more and more blockchain platforms support intelligent contracts to perform richer transactions. The intelligent contract is a transaction contract which can be automatically executed, is written into a block chain in a digital form, and ensures that the whole process of storage, reading and execution is transparent, traceable and not falsifiable by the characteristics of the block chain technology. Meanwhile, a set of state machine system is constructed by the block chain self-contained consensus algorithm, so that the intelligent contract can run efficiently. For example, the etherhouse provides an open-source blockchain underlying system, and by providing a plurality of interfaces, developers are allowed to develop various blockchain applications on the basis of the open-source blockchain underlying system and write intelligent contracts.
In this way, the blockchain platform allows users to conduct richer transactions, thereby providing richer functionality. Accordingly, more and more data storage, program applications (e.g., distributed applications Dapp), are implemented through blockchains. Correspondingly, a virtual machine is provided in each node of the block chain and used for executing the intelligent contract in the block chain, and the virtual machines in each node are ensured to have the same execution state and execution result through a consensus mechanism.
The inclusion of intelligent contracts, which may involve complex computational logic, further complicates the execution of transactions. The execution efficiency of the transaction becomes the main performance index of the blockchain platform.
It is therefore desirable to provide an efficient scheme for improving the efficiency of executing transactions in a blockchain and improving the performance of a blockchain platform.
Disclosure of Invention
One or more embodiments of the present disclosure describe a transaction speculative execution mechanism, which may accelerate the execution speed of a transaction and improve the performance of a platform when a recognized transaction is formally executed.
According to a first aspect, there is provided a method of speculatively executing transactions in a blockchain node, the method comprising:
reading a first transaction of a local record;
executing the transaction logic in the first transaction, and recording a variable operation request corresponding to an execution result in a memory;
marking the first transaction as a speculatively executed transaction.
In one embodiment, reading the first transaction of the local record may include: reading the first transaction from a first position of a local transaction list, wherein memory addresses of all local transactions are recorded in the local transaction list; and determining a first index of the first transaction in a local transaction hash list according to the transaction hash of the first transaction, and adding a pointer pointing to the first position in an entry corresponding to the first index.
Further, in an example, the local transaction list is a verified transaction list, in which a memory address of each verified local transaction is recorded; the local transaction hash list is a verified transaction hash list.
Further, the above method may be performed by a first thread, the verified transaction list being generated by a second thread, the second thread being used to verify the local transaction.
More specifically, verifying the local transaction may include verifying at least one of the following for the local transaction: and (4) transaction signature, and whether the transaction account number is legal or not.
In one embodiment, the determining a first index of the first transaction in the local transaction hash list may include: performing hash operation on the transaction content of the first transaction to obtain a transaction hash of the first transaction; and performing hash operation on the transaction hash to obtain a first hash value serving as an index value of the first index.
According to an embodiment, the recording, in the memory, the variable operation request corresponding to the execution result may include: creating a first transaction operation record in the memory, wherein
The method comprises the steps of comprising a read operation set and a write operation set; recording the variable operation request in the first transaction operation record, specifically including recording a variable read operation request included in the variable operation request in the read operation set, and recording a variable write operation request included in the variable operation request in the write operation set.
According to one embodiment, the first transaction operation record further comprises a speculative execution state; marking the first transaction as a speculatively executed transaction, comprising: marking the speculative execution state as completed speculative execution in the first transaction operational record.
According to one embodiment, the block number on which the variable operation request is based may also be recorded in the first transaction operation record.
According to a second aspect, there is provided a method of performing transactions in a blockchain, the method being performed by any node in a blockchain network, comprising:
obtaining a second transaction to be executed currently from the known transaction list;
judging whether the second transaction is a speculatively executed transaction or not, wherein the speculatively executed transaction records in a memory an uncommitted variable operation request corresponding to an execution result;
if the second transaction is a speculatively executed transaction, acquiring a variable operation request which is not submitted and corresponds to the second transaction;
judging whether the speculative execution of the second transaction conflicts with the consensus-based transaction execution according to the variable operation request;
and submitting the variable operation corresponding to the variable operation request under the condition that no conflict exists.
In one embodiment, determining whether the second transaction is a speculatively executed transaction may include: judging whether the second transaction is a local transaction or not based on a second transaction hash corresponding to the transaction content of the second transaction; if the second transaction is a local transaction, judging whether the state of the second transaction is that speculative execution is completed; if the state of the second transaction is that speculative execution is completed, determining that the second transaction is a speculatively executed transaction; if the status of the second transaction is not to complete speculative execution, then it is determined that the second transaction is not a speculatively executed transaction and the second transaction is marked as executing.
More specifically, in one embodiment, determining whether the second transaction is a local transaction may include: performing hash operation on the transaction content of the second transaction to obtain a second transaction hash; performing hash operation on the second transaction hash to obtain a second hash value, and retrieving a local transaction hash list by taking the second hash value as a second index; and if no effective pointer exists in the table entry corresponding to the second index in the local transaction hash list, determining that the second transaction is not a local transaction, and further determining that the second transaction is not a speculatively executed transaction.
Further, in one embodiment, determining whether the second transaction is a local transaction further comprises: if a second pointer exists in the table entry corresponding to the second index in the local transaction hash list, and the second pointer points to a second position in the local transaction list, reading a second memory address from the second position in the local transaction list; according to the second memory address, transaction contents stored in the memory are obtained, and a third transaction hash corresponding to the transaction contents is calculated; if the second transaction hash is not equal to the third transaction hash, determining that the second transaction is not a local transaction and further not a speculatively executed transaction; determining that the second transaction is a local transaction if the second transaction hash is equal to the third transaction hash.
In one embodiment, the local transaction list is a verified transaction list in which memory addresses of each verified local transaction are recorded; the local transaction hash list is a verified transaction hash list.
According to one embodiment, determining whether the status of the second transaction is completion of speculative execution may include: and inquiring whether the second transaction is marked to be completed speculatively in a second transaction operation record corresponding to the second transaction.
In one embodiment, obtaining the variable operation request corresponding to the second transaction that has not been submitted may include: and acquiring a variable operation request corresponding to the second transaction from the second transaction operation record.
According to one embodiment, the variable operation request includes a first read operation request for a first variable; determining whether the speculative execution of the second transaction conflicts with the consensus-based transaction execution may include: judging whether the speculative execution of the second transaction has a first conflict with the submitted transaction or not based on the first read operation request; if the first conflict does not exist, determining whether the speculative execution of the second transaction has a second conflict with other transactions being executed.
Further, in one embodiment, the determining of the first conflict may include: inquiring a modified variable table, wherein modification records of submitted transactions for all variables are recorded in the modified variable table; determining that the first conflict exists if a record of the modification of the first variable is contained in the modified variable table.
Or, in another embodiment, the first read operation request is issued based on a first numbered block; the determination of the first conflict may include: inquiring a modified variable table, wherein modification records of submitted transactions aiming at all variables and block numbers corresponding to the modification records are recorded in the modified variable table; if a first modified record aiming at the first variable is inquired from the modified variable table, and the second number corresponding to the first modified record is larger than the first number, the first conflict exists in the determination.
In one embodiment, the determination of the second conflict may include: acquiring a write operation set in an execution environment record table, and traversing each write operation request in the write operation set; determining that the second conflict exists if the first read operation request conflicts with a first write operation request in the set of write operations and a transaction corresponding to the first write operation request is ranked before the second transaction in the list of commonly recognized transactions.
In one embodiment, the method further comprises: and if the second transaction is not a speculatively executed transaction, executing the second transaction and submitting an execution result.
According to one embodiment, the method further comprises: if speculative execution of a second transaction conflicts with consensus-based transaction execution, discarding the variable operation request, re-executing the second transaction, and submitting a re-executed result.
According to a third aspect, there is provided an apparatus for speculatively executing transactions in a blockchain node, the apparatus comprising:
a reading unit configured to read a locally recorded first transaction;
the recording unit is configured to execute transaction logic in the first transaction and record a variable operation request corresponding to an execution result in a memory;
a marking unit configured to mark the first transaction as a speculatively executed transaction.
According to a fourth aspect, there is provided an apparatus for performing transactions in a blockchain, the apparatus being deployed in any node in a blockchain network, the apparatus comprising:
the transaction acquisition unit is configured to acquire a second transaction to be executed currently from the agreed transaction list;
the speculative judgment unit is configured to judge whether the second transaction is a speculatively executed transaction, wherein the speculatively executed transaction records in a memory an uncommitted variable operation request corresponding to an execution result;
the variable operation acquisition unit is configured to acquire an uncommitted variable operation request corresponding to the second transaction if the second transaction is a speculatively executed transaction;
a conflict judging unit configured to judge whether there is a conflict between speculative execution of the second transaction and consensus-based transaction execution according to the variable operation request;
and the variable operation submitting unit is configured to submit the variable operation corresponding to the variable operation request under the condition that no conflict exists.
According to a fifth aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of the first and second aspects.
According to a sixth aspect, there is provided a computing device comprising a memory and a processor, wherein the memory has stored therein executable code, and wherein the processor, when executing the executable code, implements the methods of the first and second aspects.
According to the method and the device provided by one embodiment of the specification, the concept of 'speculatively' executing the transaction is provided. Speculative execution may be understood as pre-execution or look-ahead execution of transactions for which no consensus has been reached, resulting in execution results, but which are not actually committed. The process of speculatively executing and the process of consensus may be performed in parallel. When the consensus result is obtained so as to carry out formal execution on the transaction, whether the execution result of speculative execution is available is judged, and if the execution result is available, the execution result is directly submitted without carrying out the transaction again. Therefore, the transaction can be speculatively executed in good use of the time waiting for consensus; under the condition that conflicts among transactions are less and speculative execution results are mostly available, the execution efficiency of the transactions can be greatly improved by the mode.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 illustrates a schematic diagram of transaction propagation, enbloking and execution, according to one embodiment;
FIG. 2 illustrates the processing of a transaction by an accounting node;
FIG. 3 shows a schematic diagram of a transaction execution framework including speculative execution, according to one embodiment;
FIG. 4 illustrates a flow diagram of a method of speculatively executing transactions, according to one embodiment;
FIG. 5 shows a schematic diagram of a local transaction list and a local transaction hash list, according to one embodiment;
FIG. 6 illustrates a flow diagram of a method of formally performing a consensus transaction, according to one embodiment;
FIG. 7 illustrates a flow of determining whether the second transaction is a local transaction in one embodiment;
fig. 8 shows a schematic block diagram of an arrangement for speculatively executing transactions in a node according to an embodiment;
figure 9 shows a schematic block diagram of a transaction execution apparatus according to one embodiment.
Detailed description of the invention
The scheme provided by the specification is described below with reference to the accompanying drawings.
FIG. 1 illustrates a schematic diagram of transaction propagation, enbloating, and execution, according to one embodiment. First, the blockchain network includes a plurality of nodes, and each node can communicate with each other. Some nodes may act as platforms to connect to several user terminals, which may then access the blockchain network through the platform nodes. At least some of the nodes of the blockchain network are accounting-capable nodes. The accounting node can pack the collected transactions into a predetermined block form, form a new block, and link the newly formed block to the existing block through a consensus mechanism to form a block chain.
Assume that a certain accounting node Bob in the network acquires a transaction Tx. If the node Bob is a platform node, the transaction Tx may be a transaction issued by a user terminal connected to the platform. Alternatively, the transaction Tx may be a transaction forwarded by another node Alice. Also, the transaction Tx may be a normal transfer transaction, a transaction that creates a smart contract, a transaction that invokes a smart contract.
The accounting node Bob will maintain a transaction pool locally and put the received transaction Tx into the transaction pool. When there are enough transactions in the transaction pool, node Bob extracts a portion of the transaction from the transaction pool and packs it into blocks. Generally, when a transaction is put into a transaction pool or extracted from the transaction pool and packaged, the node checks the transaction to verify its validity. After Bob packages a portion of the transaction, it broadcasts its own packaged transaction over the blockchain network in the hope of reaching consensus. Meanwhile, other accounting nodes in the block chain network can broadcast the packaged transaction to initiate consensus. Although theoretically, each transaction would be propagated to each node through the P2P propagation mechanism of the blockchain network, the transactions in the transaction pool at each accounting node are different due to the actual transmission delay of the network, and the like, and therefore the respective block packed is generally different. Finally, through a consensus mechanism set in the blockchain network, all accounting nodes agree on the newly generated blocks. Thus, each accounting node performs transactions in a consensus block to maintain consistency of data content recorded at various nodes throughout the network.
Fig. 2 shows the process of the accounting node processing the transaction. As shown in fig. 2, in brief, the accounting node first checks the transactions in the local transaction pool, packages the transactions into blocks, then initiates consensus, waits for the consensus result, and executes the transactions in the consensus block after the consensus result is obtained. It can be seen that in this process, the various steps are performed serially, in sequence.
To further improve the efficiency of executing a transaction, in accordance with at least one embodiment of the present specification, a concept of "speculatively" executing a transaction is presented. Speculative execution may be understood as pre-execution or look-ahead execution of transactions for which no consensus has been reached, resulting in execution results, but which are not actually committed. The process of speculatively executing and the process of consensus may be performed in parallel. When the consensus result is obtained so as to carry out formal execution on the transaction, whether the execution result of speculative execution is available is judged, and if the execution result is available, the execution result is directly submitted without carrying out the transaction again. Therefore, the transaction can be speculatively executed in good use of the time waiting for consensus; under the condition that conflicts among transactions are less and speculative execution results are mostly available, the execution efficiency of the transactions can be greatly improved by the mode.
Figure 3 illustrates a schematic diagram of a transaction execution framework including speculative execution, according to one embodiment. As shown, in one embodiment, the execution framework includes a pre-check thread, a speculative execution thread, and a formal execution thread. The pre-verification thread is used for performing preliminary verification on the transactions and filtering out illegal transactions. The verified transactions may be written to a list of verified transactions. And the speculative execution thread is used for carrying out speculative execution on the transaction which is subjected to the pre-verification. The speculative execution thread and the prepositive verification thread communicate through the verified transaction list. Specifically, the speculative execution thread reads the transaction from the verified transaction list, performs speculative execution, and records the speculative execution result in the transaction operation record.
The formal execution thread is used for performing formal execution on the commonly known transaction. The formal execution thread and the preposed verification thread are communicated through a verified transaction hash list, and are communicated with the speculative execution thread through the transaction operation record. Specifically, the formal execution thread determines whether the transaction to be formally executed has been speculatively executed, and the execution state and execution result of the transaction through the verified transaction hash list and the transaction operation record.
The specific structures of the verified transaction list, the verified transaction hash list and the transaction context are described in detail later with reference to the flow of the transaction execution steps.
It should be understood that although in fig. 3, the pre-check thread, the speculative execution thread, and the formal execution thread are each schematically illustrated as one thread, in practice, each of them may be implemented by several CPU threads. And, there is a difference in priority between these threads. The speculative execution thread has the lowest priority and the formal execution thread has a relatively higher priority. When the CPU hardware resources of the node are limited, the speculative execution thread is suspended or stopped when the regular execution thread starts to operate. The speculative execution thread may be executed in parallel with the formal execution thread, where the CPU hardware resources of the node may support.
The following describes the specific implementation steps in the speculative execution and formal execution processes, respectively.
Fig. 4 shows a flow diagram of a method of speculatively executing a transaction, according to one embodiment. The method may be performed by a node in a blockchain network, which may be embodied as any device, platform, or cluster of devices having computing, processing capabilities. As shown in fig. 4, the process of speculatively executing a transaction may include the steps of: step 41, reading a first transaction of a local record; step 42, executing the transaction logic in the first transaction, and recording the variable operation request corresponding to the execution result in the memory; step 43, the first transaction is marked as a speculatively executed transaction. The specific implementation of each of the above steps is described below.
First, at step 41, a first transaction of a local record is read. The first transaction may be any transaction in the local transaction pool, including a general transfer transaction, a transaction that creates a smart contract, and a transaction that invokes a smart contract, but is not limited thereto.
In one embodiment, the local transactions are recorded using a local transaction list. For example, whenever a transaction is generated or received and placed into the transaction pool, information for that transaction is added to the local transaction list. At this point it may be assumed that the transaction has been verified at other points in the transaction propagation.
FIG. 5 illustrates a schematic diagram of a local transaction list and a local transaction hash list, according to one embodiment. As the node continuously acquires local transactions, information of the local transactions is sequentially and continuously added to the local transaction list. The local transaction list includes a plurality of entries, each entry corresponding to a transaction. In one example, the transaction content of the transaction may be recorded in an entry of the local transaction list. More typically, however, as shown in fig. 5, a memory address of the local transaction is recorded in an entry of the local transaction list as a pointer (txp), and the transaction content of the transaction can be read through the memory address.
In connection with the local transaction list of fig. 5, in step 41 above, transactions may be read from the local transaction list in sequence for speculative execution. At this point, a location pointer may be set to record the read location in the local transaction list. Assume that a first transaction is currently read from a first location of the local transaction list. For example, in FIG. 5, assuming that the transaction pointed to by txp2 is currently read as the first transaction, then correspondingly, txp2 is stored in, for example, the 3 rd entry of the local transaction list, and the first location is 3.
To facilitate finding the same transaction at a later formal execution, a local transaction hash list is also created as shown on the right side of FIG. 5. The hash list includes a plurality of entries, one entry for each transaction, an index for entry i is determined based on the transaction identification of the corresponding local transaction i, and the entry i includes a pointer indicating the location of the local transaction i in the local transaction list.
The description is made in connection with the first transaction read above. Specifically, for a first transaction located at a first position of the local transaction list, a transaction identifier of the first transaction is determined according to transaction contents. In one specific example, each transaction is identified by a transaction hash, that is, the transaction identification of the first transaction is a hash value of its transaction content. Specifically, the transaction content of the first transaction may be obtained according to the memory address recorded in the first location, and the hash operation may be performed on the transaction content to obtain a corresponding transaction hash, which is used as the transaction identifier. In other examples, information uniquely determined according to the transaction content may be used as the transaction identifier through other algorithms. An index, referred to as a first index, of the first transaction in the local transaction hash list is then determined based on the transaction identification of the first transaction. And adding a pointer pointing to the first position in the table entry corresponding to the first index.
More specifically, in an example, the determining the first index according to the transaction identifier of the first transaction may be to use the transaction identifier as a corresponding index. However, in a more preferred embodiment, the transaction identifier is again hashed to obtain a hash value, which is used as an index.
For example, assume that the first transaction is the transaction to which txp2 corresponds. The transaction content of the transaction is hashed to obtain a transaction Hash1 (as an identifier), and then Hash operation is performed on the transaction Hash1 to obtain a Hash2 (as a Hash table index). Assuming the resulting Hash value Hash2 is 4, then in entry 4 of the local transaction Hash list, a pointer of 3 is added to indicate that the transaction is in entry 3 of the local transaction list.
The above describes populating the local transaction hash list with corresponding entries when a local transaction is read from the local transaction list for speculative execution. In another embodiment, the local transaction hash list may also be populated and constructed at the same time as the local transaction list. For example, each time a new local transaction is added to the local transaction list, a location pointer corresponding to the new local transaction is added to the local transaction hash list.
In the above embodiment, each local transaction is recorded by the local transaction list and the local transaction hash list. In another embodiment, the local transaction is also checked, or referred to as pre-check, and added to the list after the check is passed. At this time, the local transaction list may be referred to as a verified transaction list in which verified transaction information is recorded. Accordingly, the local transaction hash list may be referred to as a verified hash list. The verified transaction list and verified transaction hash list are structured and constructed in the same manner as the local transaction list and local transaction hash list shown in fig. 5, except that a verification step is added before adding to the table.
The above-described steps of checking may be performed by a pre-check thread as shown in fig. 3, and thus, the checked transaction list and the checked transaction hash list may be generated by the pre-check thread. Specifically, the pre-verification may include verifying whether the transaction signature of the local transaction is correct, whether the transaction account number is legal, whether the gas price (in the ethernet) is sufficient, and the like.
Thus, local transactions are recorded by the local transaction list or verified transaction list described above. Then, in step 41, the transaction can be read from the local transaction list or verified transaction list in sequence for speculative execution.
Further, in the next step 42, the transaction logic in the first transaction read above is executed, and the variable operation request corresponding to the execution result is recorded in the memory.
Specifically, when the first transaction is a common transfer transaction, the transaction logic can be understood as determining addition and subtraction operations of the amount of the related account; when the first transaction is a transaction involving a smart contract, then its transaction logic is execution logic in the contract code. Regardless of the transfer transaction or the transaction involving the smart contract, the final execution result includes a read/write operation request for a variable, which may be a variable characterizing the balance of the account or a variable defined in the smart contract.
Unlike the conventional formal execution, in the speculative execution, only the variable operation request is recorded, and the variable read-write operation is not really executed, that is, the execution result of the transaction is not really submitted.
In one embodiment, a transaction operation record is created in the memory for recording variable operation requests corresponding to the execution results of the speculative execution.
More specifically, in one embodiment, the transaction operation record may include a set of read operations (ReadSet), a set of write operations (WriteSet). Accordingly, when the variable operation request is recorded in the transaction operation record, the variable read operation request included in the variable operation request may be recorded in the read operation set, and the variable write operation request included in the variable read operation request may be recorded in the write operation set.
In one embodiment, when the operation request is recorded in the transaction operation record, the block number on which the variable operation request is based is also recorded. For example, assuming that n blocks are already known in the blockchain network and the speculative execution is currently performed for the (n + 1) th block to be formed, the block number n +1 is recorded for the variable operation request.
After the transaction logic of the first transaction is executed and the variable operation request corresponding to the execution result is recorded, the first transaction can be considered to have completed speculative execution. The first transaction is then marked as a speculatively executed transaction at step 43. In one embodiment, the transaction operation record includes a speculative execution status field; in this case, the speculative execution state may be marked as the speculative execution completed in the transaction operation record corresponding to the first transaction. In other examples, the execution status of the transaction may also be recorded in other forms. For example, a separate table is created and added to the transaction once it completes speculative execution.
Thus, through the flow shown in fig. 4, the local transaction is continuously read, speculative execution is performed, and the state and result of speculative execution are recorded. The speculative execution state and result can be used for accelerating execution speed and improving efficiency when formally executing the agreed transaction.
FIG. 6 illustrates a flow diagram of a method of formally performing a consensus transaction, according to one embodiment. The method may be performed by a node in a blockchain network, which may be embodied as any device, platform, or cluster of devices having computing, processing capabilities. As shown in fig. 6, the process of performing a transaction includes at least the following steps: step 61, obtaining a second transaction to be executed currently from the agreed transaction list; step 62, determining whether the second transaction is a speculatively executed transaction, wherein the speculatively executed transaction records in a memory an uncommitted variable operation request corresponding to an execution result; step 63, if the second transaction is a speculatively executed transaction, acquiring a variable operation request which is not submitted and corresponds to the second transaction; step 64, judging whether the speculative execution of the second transaction conflicts with the transaction execution based on consensus or not according to the variable operation request; and step 65, submitting the variable operation corresponding to the variable operation request under the condition that no conflict exists. The specific implementation of each of the above steps is described below.
First, in step 61, a second transaction currently pending for execution is obtained from the list of agreed transactions. It is understood that by using a pre-configured consensus algorithm in the blockchain network, a consensus is achieved between nodes regarding the next block to be linked, and the consensus is broadcast to each node in the blockchain network. The consensus block includes a list of known transactions, which list known transactions. After each node receives the consensus blocks, the nodes need to execute the transactions in turn according to the consensus transaction list. Accordingly, at step 61, the transactions are read from the list of recognized transactions in turn for execution. For simplicity and clarity, the currently read recognized transaction to be executed is referred to as the second transaction.
Next, at step 62, it is determined whether the second transaction is a speculatively executed transaction. If not, then jump to step 66 and execute the second transaction in a conventional manner; if yes, the judgment of the subsequent steps is carried out.
In one embodiment, to determine whether the second transaction is a speculatively executed transaction, a determination is first made as to whether the second transaction is received locally 621. Locally received transactions are hereinafter referred to as local transactions. If the second transaction is not a local transaction for the node, then it must not be speculatively executed, and the process jumps to step 66; if it is a local transaction, a further determination is made at step 622 as to whether the status of the second transaction is that speculative execution is complete.
It should be understood that, in general, the node stores the list of the known transactions in the known block in the memory after acquiring the list. However, the memory segment for storing transactions in the local transaction pool and the memory segment for storing the recognized transaction list are two separate and distinct memory segments. That is, even for the same transaction, it has different address pointers in the list of known transactions and in the list of local transactions. Therefore, it is impossible to determine whether the consensus transaction is a local transaction by directly comparing the memory addresses. Since the same transaction must have the same transaction hash, in one embodiment, the local transaction hash list is used as an intermediary to attempt to map the consensus transaction to the local transaction list, thereby determining whether the consensus transaction is a local transaction. This is also what is meant by the construction of the local transaction hash list in fig. 5.
Specifically, fig. 7 illustrates a flow of determining whether the second transaction is a local transaction in one embodiment, that is, the execution of step 621 described above.
As shown in fig. 7, first, in step 701, a hash operation is performed on the transaction content of the second transaction to obtain a second transaction hash. Here, the second transaction hash serves as an identification of the second transaction. It should be appreciated that in other examples, other forms of identification may be derived based on the transaction content through other algorithms. The identification is determined in a manner consistent with that described above when the local transaction hash table is constructed. For simplicity and clarity, in the following description, the second transaction hash is described as a specific example.
Then, in step 702, a second index of the transaction in the local transaction hash list is determined based on the second transaction hash, and the local transaction hash list is retrieved based on the second index. Corresponding to the description of FIG. 5 in constructing the local transaction hash list, in one example, the second transaction hash is directly used as the second index. More preferably, however, the second transaction hash is hashed again to obtain a second hash value, and the local transaction hash list is retrieved using the second hash value as a second index.
Next, in step 703, it is determined whether the entry corresponding to the second index contains a valid pointer. If not, then the process jumps to step 708 where it is determined that the second transaction is not a local transaction.
If a valid pointer is included, a second location in the local transaction list is obtained based on the valid pointer and a second memory address is read from the second location in the local transaction list, in step 704. For example, assuming that the second index obtained in step 702 is 13, then the 13 th entry of the local transaction hash list is looked up. Referring to FIG. 5, for example, a valid pointer 2 is recorded at entry 13, which points to entry 2 in the local transaction list. Thus, the second memory address txp1 is read from the 2 nd entry of the local transaction list.
Next, in step 705, the transaction content stored in the second memory address is obtained according to the second memory address, and a transaction hash corresponding to the transaction content is calculated, which is referred to as a third transaction hash. Further, at step 706, it is determined whether the second transaction hash and the third transaction hash match. If so, then in step 707, it is determined that the second transaction is a local transaction; otherwise, at step 708, it is determined that the second transaction is not a local transaction. The second memory address may be determined according to the transaction hash of the second transaction, but the case where the transaction hash of the stored transaction does not match the transaction hash of the second transaction may be caused by a possible hash collision when the index is determined by two hashes.
Thus, in the manner shown in fig. 7, it is determined whether the second transaction is a local transaction. In other embodiments, this may be determined in other ways, such as by the same process using the previously described verified transaction list and verified transaction hash list similar thereto. Or, in other examples, the transactions in the memory segment storing the local transactions are read one by one, the hash of the transactions is calculated, and the hash comparison is performed.
Returning to FIG. 6, if it is determined that the second transaction is a local transaction, then at step 622, it is determined whether the status of the second transaction is that speculative execution is complete. This step is performed in a manner corresponding to the manner in which step 43 of fig. 4 is performed. For example, in one embodiment, the execution status of a transaction is noted in a transaction operation record. Accordingly, in step 622, it is queried in the transaction operation record corresponding to the second transaction whether the second transaction is marked as being completed for speculative execution. In other embodiments, the execution status of the transaction is recorded by other forms, such as a separate status table. Then, accordingly, in this step, it is queried in the separate status table whether the second transaction is marked as completing speculative execution.
If the state of the second transaction is found not to be the completion of speculative execution through inquiry, the fact means that the second transaction is a local transaction but has not started speculative execution or has started speculative execution but has not completed execution. In such a case, the execution status of the second transaction is modified to be in execution at step 623, and then it jumps to step 66 for normal execution. The status flag of step 623 is to prevent the subsequent speculative execution thread from continuing to unnecessarily speculate the transaction.
If the status of the second transaction is found to be that speculative execution is completed by the query, the second transaction may be determined to be a speculatively executed transaction, and then step 63 is continued according to the flowchart of fig. 6.
At step 63, the variable operation request corresponding to the second transaction is obtained. Specifically, the variable operation request corresponding to the second transaction may be acquired from the transaction operation record. More specifically, the read operation request corresponding to the second transaction may be read from the read operation set, and the write operation request corresponding to the second transaction may be read from the write operation set.
It should be understood that after the variable operation request is obtained, the write operation request in the write operation set needs to be declared to the conflict detection module, that is, the write operation request is added to the execution environment record table. The conflict detection module and the execution environment record table are described in detail later in connection with the detection of a second conflict.
Then, at step 64, it is determined whether there is a conflict between speculative execution of the second transaction and consensus-based transaction execution based on the variable operation request. More specifically, the conflict determination may include, at step 641, determining whether the speculative execution of the second transaction conflicts with the committed transaction, such a conflict being referred to as a first conflict; and at step 642, determining whether the speculative execution of the second transaction conflicts with other transactions being executed, such conflict being referred to as a second conflict.
The conflict determination is made primarily based on the read operation request in the second transaction. Assume that the second transaction includes a first read request for the first variable. Then the determination of the first conflict in step 641 may be made by querying the modified record for the first variable in a modified variable table, wherein the modified record for each variable in the modified variable table includes the submitted transaction.
Specifically, in one embodiment, the first variable may be looked up in the modified variable table; if the modified variable table contains a record of modification of the first variable, it indicates that a formally submitted transaction modified the first variable after requesting to read the first variable at speculative execution of the second transaction, and therefore, it can be determined that the reading of the first variable at speculative execution was invalid, i.e., there is a conflict between speculative execution and submitted transaction.
It is to be understood that the modified variable table often takes the form of a hash of a variable when recording the variable. In order to avoid the misjudgment caused by the hash collision, in an embodiment, the modified variable table further records a block number corresponding to each modified record.
In such a case, the block number, on which the second transaction speculated to be executed, is also obtained from the transaction context, is referred to as the first number. Correspondingly, the determination in step 641 may specifically include querying the modified variable table, and if a first modified record for the first variable is queried from the modified variable table, and the second number of the block corresponding to the first modified record is greater than the first number, determining that a first conflict exists.
For example, assuming that the 10 th block is being formed when the second transaction is speculatively executed locally, the second transaction is executed based on the 10 th block, first numbered 10. However, in the consensus result, the second transaction is determined to be formally executed in block 11. If there are other transactions that modify the first variable during the execution of block 11, then a record of the modification to the first variable is included in the modified variable table, and the corresponding second number is 11. Since the second number is greater than the first number, meaning that a transaction following speculative execution has modified the first variable, the read operation request at speculative execution is invalid.
If it is determined that there is a first conflict, then at step 643 all variable operation requests for the second transaction are discarded, and then a jump is made to step 66, instead of performing conventionally.
If there is no first conflict, then at step 642 it is determined whether there is a second conflict.
It is to be understood that some transaction parallel execution schemes already exist for improving transaction execution efficiency. In parallel execution of transactions, conflict detection between transactions is essential. The detection of the second conflict, similar to the detection of a conflict when a transaction is executed in parallel, may be implemented using various conflict detection modules.
For example, in one embodiment, at step 642, a set of write operations (WriteSet) in an execution environment record table for recording variable operation requests for all transactions being executed may be obtained. Then, traversing (or playing) each write operation request in the write operation set; if the first read operation request in the second transaction conflicts with a certain write operation request in the write operation set, and the transaction corresponding to the certain write operation request is ranked before the second transaction in the commonly recognized transaction list, it means that the first variable requested to be read by the second transaction has been modified by other transactions in execution ranked before the second transaction, and thus it is determined that the second conflict exists.
Note that prior to step 64, the write operation request for the second transaction itself has also been added to the execution environment record table in order to detect whether there is a second conflict between the read operation requests for other transactions and the write operation request for the second transaction.
If there is a second conflict, then similarly at step 643, all variable operation requests for the second transaction are discarded, and then a jump is made to step 66 to perform the second transaction conventionally.
If there is no second conflict, it means that there is no conflict between speculative execution of the second transaction and execution of the consensus-based transaction, and then, in step 65, the variable operation corresponding to the variable operation request of the second transaction is submitted, i.e., the execution result of the second transaction is submitted. The speculative execution result of the second transaction is then validated.
Through the above process, it can be seen that if the second transaction has been speculatively executed and the result of the speculative execution does not conflict with the formal execution, only the variable operation result needs to be submitted during the formal execution, and the transaction logic of the whole transaction does not need to be re-executed. Especially for the transaction with more complex execution logic, the time consumption of formal execution can be greatly saved by the pre-speculative execution. Under the condition of low transaction conflict rate, the speculative execution mechanism can greatly improve the transaction execution efficiency, and further improve the performance of the block chain platform.
According to an embodiment of another aspect, an apparatus for speculatively executing transactions in blockchain nodes is provided, and the apparatus is deployed in any node in a blockchain network, and the node may be embodied as any device, platform or device cluster with computing and processing capabilities. Fig. 8 shows a schematic block diagram of an arrangement for speculatively executing transactions in a node according to an embodiment. As shown in fig. 8, the speculative execution device 800 includes:
a reading unit 81 configured to read a locally recorded first transaction;
a recording unit 82, configured to execute the transaction logic in the first transaction, and record a variable operation request corresponding to an execution result in a memory;
a marking unit 83 configured to mark the first transaction as a speculatively executed transaction.
Specifically, in one embodiment, the reading unit 81 includes (not shown):
the transaction reading module is configured to read the first transaction from a first position of a local transaction list, and memory addresses of the local transactions are recorded in the local transaction list;
and the hash adding module is configured to determine a first index of the first transaction in a local transaction hash list according to the transaction hash of the first transaction, and add a pointer pointing to the first position in an entry corresponding to the first index.
In a specific example, the local transaction list may be a verified transaction list in which memory addresses of each verified local transaction are recorded; accordingly, the local transaction hash list may be a verified transaction hash list.
In one embodiment, the apparatus is implemented by a first thread and the verified transaction list is generated by a second thread for verifying local transactions.
More specifically, verifying the local transaction may include verifying at least one of the following for the local transaction: and (4) transaction signature, and whether the transaction account number is legal or not.
In one embodiment, the hash addition module is configured to:
performing hash operation on the transaction content of the first transaction to obtain a transaction hash of the first transaction; and performing hash operation on the transaction hash to obtain a first hash value serving as an index value of the first index.
According to an embodiment, the recording unit 82 is configured to:
creating a first transaction operation record in the memory, wherein the first transaction operation record comprises a read operation set and a write operation set;
recording the variable operation request in the first transaction operation record, wherein the recording includes recording a variable read operation request included in the variable operation request in the read operation set, and recording a variable write operation request included in the variable operation request in the write operation set.
In one embodiment, the first transaction operation record further comprises a speculative execution state; the marking unit 83 is configured to: marking the speculative execution state as completed speculative execution in the first transaction operational record.
More specifically, in one embodiment, the recording unit 82 is configured to: the block number on which the variable operation request is based is also recorded in the first transaction operation record.
According to an embodiment of another aspect, an apparatus for performing transactions in a blockchain is provided, the apparatus being deployed in any node in a blockchain network, and the node may be embodied as any device, platform or device cluster having computing and processing capabilities. Figure 9 shows a schematic block diagram of a transaction execution apparatus according to one embodiment. As shown in fig. 9, the transaction execution apparatus 900 includes:
a transaction obtaining unit 91 configured to obtain a second transaction to be executed currently from the already-known transaction list;
a speculative judgment unit 92 configured to judge whether the second transaction is a speculatively executed transaction, where the speculatively executed transaction has a variable operation request, which is not yet submitted, recorded in a memory, and corresponds to an execution result;
a variable operation obtaining unit 93, configured to, if the second transaction is a speculatively executed transaction, obtain an uncommitted variable operation request corresponding to the second transaction;
a conflict judging unit 94 configured to judge whether there is a conflict between speculative execution of the second transaction and consensus-based transaction execution according to the variable operation request;
the variable operation submitting unit 95 is configured to submit the variable operation corresponding to the variable operation request if there is no conflict.
According to one embodiment, the speculative judgment unit 92 further includes:
the local transaction determination module 921 is configured to determine whether the second transaction is a local transaction based on a second transaction hash corresponding to the transaction content of the second transaction;
the execution state judgment module 922 is configured to judge whether the state of the second transaction is that speculative execution is completed if the second transaction is a local transaction;
a determining module 923 configured to determine that the second transaction is a speculatively executed transaction if the status of the second transaction is that speculative execution is completed; if the status of the second transaction is not to complete speculative execution, then it is determined that the second transaction is not a speculatively executed transaction and the second transaction is marked as executing.
Further, in one embodiment, the local transaction determination module 921 is configured to: performing hash operation on the transaction content of the second transaction to obtain a second transaction hash; performing hash operation on the second transaction hash to obtain a second hash value, and retrieving a local transaction hash list by taking the second hash value as a second index; and if no effective pointer exists in the table entry corresponding to the second index in the local transaction hash list, determining that the second transaction is not a local transaction, and further determining that the second transaction is not a speculatively executed transaction.
Further, the local transaction determination unit 921 is further configured to: if a second pointer exists in the table entry corresponding to the second index in the local transaction hash list, and the second pointer points to a second position in the local transaction list, reading a second memory address from the second position in the local transaction list; according to the second memory address, transaction contents stored in the memory are obtained, and a third transaction hash corresponding to the transaction contents is calculated; if the second transaction hash is not equal to the third transaction hash, determining that the second transaction is not a local transaction and further not a speculatively executed transaction; determining that the second transaction is a local transaction if the second transaction hash is equal to the third transaction hash.
In a specific example, the local transaction list may be a verified transaction list in which memory addresses of each verified local transaction are recorded; the local transaction hash list may be a verified transaction hash list.
According to one embodiment, the execution state determination unit 922 is configured to: and inquiring whether the second transaction is marked to be completed speculatively in a second transaction operation record corresponding to the second transaction.
In one embodiment, the variable operation acquiring unit 93 is configured to acquire the variable operation request corresponding to the second transaction from the second transaction operation record.
According to one embodiment, the variable operation request includes a first read operation request for a first variable; the conflict judgment unit 94 includes:
a first conflict judging module 941, configured to judge whether there is a first conflict between speculative execution of the second transaction and submitted transactions based on the first read operation request;
a second conflict determination module 942 is configured to determine if there is a second conflict between the speculative execution of the second transaction and other transactions being executed if there is no first conflict.
Further, in an embodiment, the first collision determination module 941 is configured to: inquiring a modified variable table, wherein modification records of submitted transactions for all variables are recorded in the modified variable table; determining that the first conflict exists if a record of the modification of the first variable is contained in the modified variable table.
In another embodiment, the first read operation request is issued based on a first numbered block; the first conflict determination module 941 is configured to: inquiring a modified variable table, wherein modification records of submitted transactions aiming at all variables and block numbers corresponding to the modification records are recorded in the modified variable table; if a first modified record aiming at the first variable is inquired from the modified variable table, and the second number corresponding to the first modified record is larger than the first number, the first conflict exists in the determination.
According to an embodiment, the second conflict determination module 942 is configured to: acquiring a write operation set in an execution environment record table, and traversing each write operation request in the write operation set, wherein the execution environment record table is used for recording variable operation requests of transactions in execution; determining that the second conflict exists if the first read operation request conflicts with a first write operation request in the set of write operations and a transaction corresponding to the first write operation request is ranked before the second transaction in the list of commonly recognized transactions.
According to one embodiment, the apparatus 900 further comprises a transaction executing unit 96 configured to execute the second transaction and submit the execution result if the speculative determining unit 92 determines that the second transaction is not a speculatively executed transaction.
According to one embodiment, the transaction execution unit 96 is further configured to discard the variant operation request, re-execute the second transaction, and submit the re-execution result if the conflict determination unit 94 determines that the speculative execution of the second transaction conflicts with consensus-based transaction execution.
By means of the above aspects, speculative execution of transactions before reaching a consensus may be utilized; therefore, when the common-recognition transaction is formally executed, the execution efficiency can be improved and the platform performance can be improved by utilizing the speculative execution result.
According to an embodiment of another aspect, there is also provided a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method described in connection with fig. 4 and 6.
According to an embodiment of yet another aspect, there is also provided a computing device comprising a memory and a processor, the memory having stored therein executable code, the processor, when executing the executable code, implementing the method described in connection with fig. 4 and 6.
Those skilled in the art will recognize that, in one or more of the examples described above, the functions described in this invention may be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium.
The above-mentioned embodiments, objects, technical solutions and advantages of the present invention are further described in detail, it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made on the basis of the technical solutions of the present invention should be included in the scope of the present invention.
Claims (36)
1. A method of speculatively executing transactions in blockchain nodes, the method being performed by any accounting node in a blockchain, comprising:
reading a first transaction of a local record;
executing the transaction logic in the first transaction, and recording the variable operation request which is not submitted and corresponds to the execution result in the memory;
marking the first transaction as a speculatively executed transaction; the speculatively executed transaction represents: a transaction in which an execution result is generated after pre-execution or forward-looking execution of a transaction for which a consensus is not yet agreed, but the execution result is not submitted;
obtaining a second transaction to be executed currently from the known transaction list;
judging whether the second transaction is a speculatively executed transaction or not, wherein the speculatively executed transaction records in a memory an uncommitted variable operation request corresponding to an execution result;
if the second transaction is a speculatively executed transaction, acquiring a variable operation request which is not submitted and corresponds to the second transaction; the variable operation request comprises a first read operation request aiming at a first variable;
judging whether the speculative execution of the second transaction has a first conflict with the submitted transaction or not based on the first read operation request; if the first conflict does not exist, judging whether the speculative execution of the second transaction has a second conflict with other transactions which are in execution and are ranked in front of the second transaction in the consensus sequence;
and submitting the variable operation corresponding to the variable operation request under the condition that no conflict exists.
2. The method of claim 1, wherein reading the locally recorded first transaction comprises:
reading the first transaction from a first position of a local transaction list, wherein memory addresses of all local transactions are recorded in the local transaction list;
and determining a first index of the first transaction in a local transaction hash list according to the transaction identifier of the first transaction, and adding a pointer pointing to the first position in an entry corresponding to the first index.
3. The method of claim 2, wherein,
the local transaction list is a verified transaction list, and the memory address of each verified local transaction is recorded in the local transaction list; the local transaction hash list is a verified transaction hash list.
4. The method of claim 3, wherein the method is performed by a first thread, and the verified transaction list is generated by a second thread, the second thread for verifying local transactions.
5. The method of claim 4, wherein said verifying the local transaction comprises verifying at least one of the following for the local transaction: and (4) transaction signature, and whether the transaction account number is legal or not.
6. The method of claim 2, wherein determining a first index of the first transaction in a local transaction hash list based on the transaction identification of the first transaction comprises:
performing hash operation on the transaction content of the first transaction to obtain a transaction identifier of the first transaction;
and performing hash operation on the transaction identifier to obtain a first hash value serving as an index value of the first index.
7. The method of claim 1, wherein recording the variable operation request corresponding to the execution result in the memory comprises:
creating a first transaction operation record in the memory, wherein the first transaction operation record comprises a read operation set and a write operation set;
recording the variable operation request in the first transaction operation record, wherein the recording includes recording a variable read operation request included in the variable operation request in the read operation set, and recording a variable write operation request included in the variable operation request in the write operation set.
8. The method of claim 7, wherein the first transaction operation record further comprises a speculative execution state;
marking the first transaction as a speculatively executed transaction, comprising: marking the speculative execution state as completed speculative execution in the first transaction operational record.
9. The method of claim 7, wherein recording the variable operation request in the first transaction operation record further comprises: and recording the block number based on which the variable read operation request is based in the first transaction operation record.
10. The method of claim 1, wherein determining whether the second transaction is a speculatively executed transaction comprises:
judging whether the second transaction is a local transaction or not based on a second transaction hash corresponding to the transaction content of the second transaction;
if the second transaction is a local transaction, judging whether the state of the second transaction is that speculative execution is completed;
if the state of the second transaction is that speculative execution is completed, determining that the second transaction is a speculatively executed transaction;
if the status of the second transaction is not to complete speculative execution, then it is determined that the second transaction is not a speculatively executed transaction and the second transaction is marked as executing.
11. The method of claim 10, wherein determining whether the second transaction is a local transaction comprises:
performing hash operation on the transaction content of the second transaction to obtain a second transaction hash;
performing hash operation on the second transaction hash to obtain a second hash value, and retrieving a local transaction hash list by taking the second hash value as a second index;
and if no effective pointer exists in the table entry corresponding to the second index in the local transaction hash list, determining that the second transaction is not a local transaction, and further determining that the second transaction is not a speculatively executed transaction.
12. The method of claim 11, wherein determining whether the second transaction is a local transaction further comprises:
if a second pointer exists in the table entry corresponding to the second index in the local transaction hash list, and the second pointer points to a second position in the local transaction list, reading a second memory address from the second position in the local transaction list;
according to the second memory address, transaction contents stored in the memory are obtained, and a third transaction hash corresponding to the transaction contents is calculated;
if the second transaction hash is not equal to the third transaction hash, determining that the second transaction is not a local transaction and further not a speculatively executed transaction;
determining that the second transaction is a local transaction if the second transaction hash is equal to the third transaction hash.
13. The method of claim 12, wherein the local transaction list is a verified transaction list in which memory addresses of each verified local transaction are recorded; the local transaction hash list is a verified transaction hash list.
14. The method of claim 10, wherein determining whether the status of the second transaction is completion of speculative execution comprises: and inquiring whether the second transaction is marked to be completed speculatively in a second transaction operation record corresponding to the second transaction.
15. The method of claim 14, wherein obtaining the uncommitted variable operation requests corresponding to the second transaction comprises:
and acquiring a variable operation request corresponding to the second transaction from the second transaction operation record.
16. The method of claim 1, wherein determining whether speculative execution of the second transaction has a first conflict with committed transactions based on the first read operation request comprises:
inquiring a modified variable table, wherein modification records of submitted transactions for all variables are recorded in the modified variable table;
determining that the first conflict exists if a record of the modification of the first variable is contained in the modified variable table.
17. The method of claim 1, wherein the first read operation request is issued based on a first numbered block;
based on the first read operation request, the determining whether the speculative execution of the second transaction has a first conflict with the committed transaction includes:
inquiring a modified variable table, wherein modification records of submitted transactions aiming at all variables and block numbers corresponding to the modification records are recorded in the modified variable table;
and if a first modified record aiming at the first variable is inquired from the modified variable table and a second number corresponding to the first modified record is greater than the first number, determining that the first conflict exists.
18. The method of claim 1, wherein determining whether the speculative execution of the second transaction has a second conflict with other transactions being executed comprises:
acquiring a write operation set in an execution environment record table, and traversing each write operation request in the write operation set, wherein the execution environment record table is used for recording variable operation requests of transactions in execution;
determining that the second conflict exists if the first read operation request conflicts with a first write operation request in the set of write operations and a transaction corresponding to the first write operation request is ranked before the second transaction in the list of commonly recognized transactions.
19. The method of claim 1, further comprising:
and if the second transaction is not a speculatively executed transaction, executing the second transaction and submitting an execution result.
20. The method of claim 1, further comprising:
if the speculative execution of the second transaction conflicts with consensus-based transaction execution, discarding the variable operation request, re-executing the second transaction, and submitting the re-executed result.
21. An apparatus for speculatively executing transactions in blockchain nodes, the apparatus being deployed in any accounting node in a blockchain, comprising:
a reading unit configured to read a locally recorded first transaction;
the recording unit is configured to execute the transaction logic in the first transaction and record the variable operation request which is not submitted and corresponds to the execution result in the memory;
a marking unit configured to mark the first transaction as a speculatively executed transaction; the speculatively executed transaction represents: a transaction in which an execution result is generated after pre-execution or forward-looking execution of a transaction for which a consensus is not yet agreed, but the execution result is not submitted;
the transaction acquisition unit is configured to acquire a second transaction to be executed currently from the agreed transaction list;
the speculative judgment unit is configured to judge whether the second transaction is a speculatively executed transaction, wherein the speculatively executed transaction records in a memory an uncommitted variable operation request corresponding to an execution result;
the variable operation acquisition unit is configured to acquire an uncommitted variable operation request corresponding to the second transaction if the second transaction is a speculatively executed transaction; the variable operation request comprises a first read operation request aiming at a first variable;
a conflict determination unit comprising: the first conflict judgment module is configured to judge whether the speculative execution of the second transaction has a first conflict with the submitted transaction based on the first read operation request; a second conflict judging module configured to judge whether the speculative execution of the second transaction has a second conflict with other transactions in execution if the first conflict does not exist;
and the variable operation submitting unit is configured to submit the variable operation corresponding to the variable operation request under the condition that no conflict exists.
22. The apparatus of claim 21, wherein the reading unit comprises:
the transaction reading module is configured to read the first transaction from a first position of a local transaction list, and memory addresses of the local transactions are recorded in the local transaction list;
and the hash adding module is configured to determine a first index of the first transaction in a local transaction hash list according to the transaction hash of the first transaction, and add a pointer pointing to the first position in an entry corresponding to the first index.
23. The apparatus of claim 22, wherein the hash addition module is configured to:
performing hash operation on the transaction content of the first transaction to obtain a transaction hash of the first transaction;
and performing hash operation on the transaction hash to obtain a first hash value serving as an index value of the first index.
24. The apparatus of claim 21, wherein,
the recording unit is configured to:
creating a first transaction operation record in the memory, wherein the first transaction operation record comprises a read operation set and a write operation set;
recording the variable operation request in the first transaction operation record, wherein the recording includes recording a variable read operation request included in the variable operation request in the read operation set, and recording a variable write operation request included in the variable operation request in the write operation set.
25. The apparatus of claim 24, wherein the recording unit is configured to: recording the block number based on which the variable operation request is based in the first transaction operation record.
26. The apparatus of claim 21, wherein the speculative determination unit comprises:
the local transaction judging module is configured to judge whether the second transaction is a local transaction or not based on a second transaction hash corresponding to the transaction content of the second transaction;
the execution state judgment module is configured to judge whether the state of the second transaction is the completion of speculative execution if the second transaction is a local transaction;
the determining module is configured to determine that the second transaction is a speculatively executed transaction if the state of the second transaction is that speculative execution is completed; if the status of the second transaction is not to complete speculative execution, then it is determined that the second transaction is not a speculatively executed transaction and the second transaction is marked as executing.
27. The apparatus of claim 26, wherein the local transaction determination module is configured to:
performing hash operation on the transaction content of the second transaction to obtain a second transaction hash;
performing hash operation on the second transaction hash to obtain a second hash value, and retrieving a local transaction hash list by taking the second hash value as a second index;
and if no effective pointer exists in the table entry corresponding to the second index in the local transaction hash list, determining that the second transaction is not a local transaction, and further determining that the second transaction is not a speculatively executed transaction.
28. The apparatus of claim 27, wherein the local transaction determination unit is further configured to:
if a second pointer exists in the table entry corresponding to the second index in the local transaction hash list, and the second pointer points to a second position in the local transaction list, reading a second memory address from the second position in the local transaction list;
according to the second memory address, transaction contents stored in the memory are obtained, and a third transaction hash corresponding to the transaction contents is calculated;
if the second transaction hash is not equal to the third transaction hash, determining that the second transaction is not a local transaction and further not a speculatively executed transaction;
determining that the second transaction is a local transaction if the second transaction hash is equal to the third transaction hash.
29. The apparatus of claim 26, wherein the execution state determination unit is configured to: and inquiring whether the second transaction is marked to be completed speculatively in a second transaction operation record corresponding to the second transaction.
30. The apparatus of claim 21, wherein the first collision determination module is configured to:
inquiring a modified variable table, wherein modification records of submitted transactions for all variables are recorded in the modified variable table;
determining that the first conflict exists if a record of the modification of the first variable is contained in the modified variable table.
31. The apparatus of claim 21, wherein the first read request is issued based on a first numbered block; the first conflict determination module is configured to:
inquiring a modified variable table, wherein modification records of submitted transactions aiming at all variables and block numbers corresponding to the modification records are recorded in the modified variable table;
and if a first modified record aiming at the first variable is inquired from the modified variable table and a second number corresponding to the first modified record is greater than the first number, determining that the first conflict exists.
32. The apparatus of claim 21, wherein the second collision determination module is configured to:
acquiring a write operation set in an execution environment record table, and traversing each write operation request in the write operation set, wherein the execution environment record table is used for recording variable operation requests of transactions in execution;
determining that the second conflict exists if the first read operation request conflicts with a first write operation request in the set of write operations and a transaction corresponding to the first write operation request is ranked before the second transaction in the list of commonly recognized transactions.
33. The apparatus according to claim 21, further comprising a transaction execution unit configured to execute the second transaction and submit an execution result if the speculative judgment unit judges that the second transaction is not a speculatively executed transaction.
34. The apparatus according to claim 21, further comprising a transaction execution unit configured to discard the variant operation request, re-execute the second transaction, and submit a result of the re-execution if the conflict determination unit determines that the speculative execution of the second transaction conflicts with consensus-based transaction execution.
35. A computer-readable storage medium, having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of any of claims 1-20.
36. A computing device comprising a memory and a processor, wherein the memory has stored therein executable code that, when executed by the processor, performs the method of any of claims 1-20.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010170493.9A CN111047449B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
CN202010754103.2A CN111882435B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010170493.9A CN111047449B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
Related Child Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010754103.2A Division CN111882435B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111047449A CN111047449A (en) | 2020-04-21 |
CN111047449B true CN111047449B (en) | 2020-06-23 |
Family
ID=70231147
Family Applications (2)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010170493.9A Active CN111047449B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
CN202010754103.2A Active CN111882435B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
Family Applications After (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010754103.2A Active CN111882435B (en) | 2020-03-12 | 2020-03-12 | Method and device for executing transaction in block chain |
Country Status (1)
Country | Link |
---|---|
CN (2) | CN111047449B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111522648B (en) * | 2020-07-03 | 2020-10-09 | 支付宝(杭州)信息技术有限公司 | Transaction processing method and device for block chain and electronic equipment |
CN111754349B (en) | 2020-08-28 | 2020-12-04 | 支付宝(杭州)信息技术有限公司 | Method and device for grouping transactions in blockchain |
CN111813795B (en) | 2020-08-28 | 2020-12-04 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for confirming transactions in a blockchain network |
CN111754350B (en) | 2020-08-28 | 2020-11-24 | 支付宝(杭州)信息技术有限公司 | Method and device for parallelly acquiring serial numbers of transaction access variables in block chain |
CN112001798B (en) * | 2020-10-28 | 2021-01-26 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for concurrently executing transactions in a blockchain |
CN112199204B (en) * | 2020-12-04 | 2021-03-12 | 支付宝(杭州)信息技术有限公司 | Method and device for processing transaction in block chain |
CN113254467B (en) * | 2021-07-02 | 2022-05-10 | 支付宝(杭州)信息技术有限公司 | Method and blockchain node for performing transactions in blockchain system |
CN114564412B (en) * | 2022-04-27 | 2022-07-22 | 北京微芯感知科技有限公司 | Method and system for deterministic transaction concurrent scheduling of block chains |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101807144A (en) * | 2010-03-17 | 2010-08-18 | 上海大学 | Prospective multi-threaded parallel execution optimization method |
CN107688999A (en) * | 2017-08-11 | 2018-02-13 | 杭州秘猿科技有限公司 | A kind of parallel transaction based on block chain performs method |
CN109040029A (en) * | 2018-07-13 | 2018-12-18 | 上海点融信息科技有限责任公司 | The method and apparatus of affairs are executed in block chain |
CN110046523A (en) * | 2019-03-15 | 2019-07-23 | 阿里巴巴集团控股有限公司 | Intelligent contract method of calibration and device and electronic equipment |
Family Cites Families (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9317886B2 (en) * | 2011-06-17 | 2016-04-19 | Chicago Mercantile Exchange Inc. | Facilitation of payments between counterparties by a central counterparty |
US20160225085A1 (en) * | 2015-01-30 | 2016-08-04 | Trading Technologies International, Inc. | System and Method for Implementing a Dynamic Simulation System |
US10692065B2 (en) * | 2017-06-19 | 2020-06-23 | Accenture Global Solutions Limited | Using a mixture model to generate simulated transaction information |
US11188920B2 (en) * | 2018-05-23 | 2021-11-30 | International Business Machines Corporation | Autocommit transaction management in a blockchain network |
US11070360B2 (en) * | 2018-08-13 | 2021-07-20 | International Business Machines Corporation | Parallel transaction validation and block generation in a blockchain |
CN109189396B (en) * | 2018-08-16 | 2022-04-12 | 北京京东尚科信息技术有限公司 | Intelligent contract engine assembly, operation method and storage medium |
CN109685502B (en) * | 2018-12-06 | 2021-04-30 | 成都佰纳瑞信息技术有限公司 | Accelerated consensus method applicable to block chain network |
CN113139873A (en) * | 2019-08-30 | 2021-07-20 | 创新先进技术有限公司 | Method and apparatus for concurrently executing transactions in a blockchain |
-
2020
- 2020-03-12 CN CN202010170493.9A patent/CN111047449B/en active Active
- 2020-03-12 CN CN202010754103.2A patent/CN111882435B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101807144A (en) * | 2010-03-17 | 2010-08-18 | 上海大学 | Prospective multi-threaded parallel execution optimization method |
CN107688999A (en) * | 2017-08-11 | 2018-02-13 | 杭州秘猿科技有限公司 | A kind of parallel transaction based on block chain performs method |
CN109040029A (en) * | 2018-07-13 | 2018-12-18 | 上海点融信息科技有限责任公司 | The method and apparatus of affairs are executed in block chain |
CN110046523A (en) * | 2019-03-15 | 2019-07-23 | 阿里巴巴集团控股有限公司 | Intelligent contract method of calibration and device and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
CN111047449A (en) | 2020-04-21 |
CN111882435A (en) | 2020-11-03 |
CN111882435B (en) | 2023-01-31 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111047449B (en) | Method and device for executing transaction in block chain | |
EP3678346B1 (en) | Blockchain smart contract verification method and apparatus, and storage medium | |
US11481765B2 (en) | Blockchain-based transaction processing method and apparatus and electronic device | |
CN107392608B (en) | Block chain system-based digital asset transaction method and block chain system | |
EP3816922A1 (en) | Blockchain-based transaction processing method and apparatus, and electronic device | |
CN111241061B (en) | Writing method of state database, data processing device and storage medium | |
US11250395B2 (en) | Blockchain-based transaction processing methods and apparatuses and electronic devices | |
CN110706101B (en) | Method and apparatus for concurrently executing transactions in a blockchain | |
CN110675255B (en) | Method and apparatus for concurrently executing transactions in a blockchain | |
US20230275771A1 (en) | Pre-execution of block chain transaction in parallel during block consensus | |
US11245762B1 (en) | Data request servicing using smart network interface cards | |
CN106599247B (en) | Method and device for merging data files in LSM-tree structure | |
CN110648124B (en) | Method and apparatus for concurrently executing transactions in a blockchain | |
WO2021135756A1 (en) | Method and device for proving account state existence, and state query method and device | |
WO2023184052A1 (en) | Data processing method, blockchain node and blockchain system | |
CN110689344B (en) | Method and apparatus for concurrently executing transactions in a blockchain | |
CN112711462A (en) | Cloud platform virtual CPU hot binding method and device and computer readable storage medium | |
WO2021064852A1 (en) | Transaction management device, transaction management program, and transaction management method | |
EP4394619A1 (en) | Data processing method and apparatus based on blockchain, and device and readable storage medium | |
CN113743949B (en) | Method for performing transactions in a blockchain, master node and slave node | |
CN115795563A (en) | State data checking method and device | |
CN116009940A (en) | Method, device, computer equipment and medium for changing consensus cluster | |
CN113064902A (en) | Method and device for retrieving transaction data on chain and electronic equipment | |
CN112783954B (en) | Data access method, device and server | |
JP6222100B2 (en) | Data storage device, data storage method and program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |