CN113743941B - Method for executing transaction in block chain, block chain and main node - Google Patents
Method for executing transaction in block chain, block chain and main node Download PDFInfo
- Publication number
- CN113743941B CN113743941B CN202111296820.6A CN202111296820A CN113743941B CN 113743941 B CN113743941 B CN 113743941B CN 202111296820 A CN202111296820 A CN 202111296820A CN 113743941 B CN113743941 B CN 113743941B
- Authority
- CN
- China
- Prior art keywords
- transaction
- execution
- transactions
- read
- executing
- 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
- 238000000034 method Methods 0.000 title claims abstract description 89
- 230000008569 process Effects 0.000 claims abstract description 30
- 238000001514 detection method Methods 0.000 claims description 22
- 238000003860 storage Methods 0.000 claims description 14
- 238000012545 processing Methods 0.000 claims description 12
- 238000004590 computer program Methods 0.000 claims description 10
- 238000005096 rolling process Methods 0.000 claims description 5
- 238000010586 diagram Methods 0.000 description 20
- 230000006870 function Effects 0.000 description 11
- 230000006872 improvement Effects 0.000 description 9
- 238000005516 engineering process Methods 0.000 description 7
- 238000004422 calculation algorithm Methods 0.000 description 3
- 230000008859 change Effects 0.000 description 3
- 238000004891 communication Methods 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 2
- 230000018109 developmental process Effects 0.000 description 2
- 239000000463 material Substances 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- OKTJSMMVPCPJKN-UHFFFAOYSA-N Carbon Chemical compound [C] OKTJSMMVPCPJKN-UHFFFAOYSA-N 0.000 description 1
- 108010001267 Protein Subunits Proteins 0.000 description 1
- 230000004931 aggregating effect Effects 0.000 description 1
- 230000004075 alteration Effects 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 239000007795 chemical reaction product Substances 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 229910021389 graphene Inorganic materials 0.000 description 1
- 230000000977 initiatory effect Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000005055 memory storage Effects 0.000 description 1
- 229920001296 polysiloxane Polymers 0.000 description 1
- 239000000047 product Substances 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
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
- 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/3829—Payment protocols; Details thereof insuring higher security of transaction involving key management
Landscapes
- Business, Economics & Management (AREA)
- Engineering & Computer Science (AREA)
- Accounting & Taxation (AREA)
- Computer Security & Cryptography (AREA)
- Finance (AREA)
- Strategic Management (AREA)
- Physics & Mathematics (AREA)
- General Business, Economics & Management (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A method, blockchain and master node for performing transactions in a blockchain. The blockchain comprises a master node and a slave node, and the method comprises the following steps: the main node executes each received transaction in advance based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after pre-executing each transaction, the master node serially processes each transaction as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the event that no conflict is determined to exist, updating a pre-execution state set and a pre-execution transaction set; the master node sends a plurality of transactions arranged in sequence in the pre-execution transaction set, the arrangement sequence of the transactions in the pre-execution transaction set and a pre-execution read-write set of the transactions to the slave node; and the slave node executes the multiple transactions according to the arrangement sequence of the multiple transactions and the pre-execution read-write set of each transaction.
Description
Technical Field
The embodiments of the present specification relate to the field of blockchain technology, and more particularly, to a method for performing transactions in a blockchain, and a master node.
Background
The Blockchain (Blockchain) is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. In the block chain system, data blocks are combined into a chain data structure in a sequential connection mode according to a time sequence, and the data blocks are guaranteed to be not falsified and not forged in a cryptographic mode. When the block chain node executes a plurality of transactions in the block, the transaction execution speed can be increased by executing the transactions in parallel. However, transactions that invoke smart contracts are generally not able to be executed in parallel because the accessed variables cannot be predicted prior to execution.
Disclosure of Invention
The invention aims to provide a method for executing transaction in a block chain, the block chain and a main node, which improve the transaction execution speed in the block chain.
A first aspect of the specification provides a method of performing a transaction in a blockchain, the blockchain comprising a master node and a slave node, the method comprising: the main node executes each received transaction in advance based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after pre-executing each transaction, the master node serially processes each transaction as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in the pre-execution transaction set, for example, the first transaction sequence is recorded at the end position of the pre-execution transaction set; the master node sends a plurality of transactions (for example, the first n transactions in a sequential arrangement) recorded in advance in the pre-executed transaction set, an arrangement order of the transactions in the pre-executed transaction set, and a pre-executed read-write set of the transactions to the slave node; and the slave node executes the multiple transactions according to the arrangement sequence of the multiple transactions and the pre-execution read-write set of each transaction.
A second aspect of the specification provides a method of performing a transaction in a blockchain, the blockchain comprising a master node and a slave node, the method comprising:
the main node executes each received transaction in advance based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after pre-executing each transaction, the master node serially processes each transaction as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
the master node determining a plurality of previously recorded sequentially ordered transactions from the set of pre-executed transactions;
the main node groups the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
the master node sends the plurality of transactions, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the grouping results of the plurality of transactions to the slave node;
the slave node executes the multiple transactions in parallel according to the arrangement sequence and grouping result of the multiple transactions.
A third aspect of the specification provides a method of performing a transaction in a blockchain, the blockchain comprising a master node and slave nodes, the method performed by the master node comprising: pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set; and sending a plurality of transactions which are recorded in advance in the pre-execution transaction set and are arranged in sequence, the arrangement sequence of the transactions in the pre-execution transaction set and a pre-execution read-write set of the transactions to the slave node.
A fourth aspect of the specification provides a method of performing a transaction in a blockchain, the blockchain including a master node and slave nodes, the method performed by the master node comprising:
pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
determining a plurality of previously recorded sequentially ordered transactions from the set of pre-executed transactions;
grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
and sending the plurality of transactions, the arrangement sequence of the transactions in the pre-execution transaction set and the grouping results of the transactions to the slave node.
A fifth aspect of the present specification provides a blockchain, where the blockchain includes a master node and a slave node, where the master node is configured to pre-execute each received transaction based on a set of pre-execution states to obtain a set of pre-execution reads and writes for each transaction; after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set; the master node is further configured to send a plurality of transactions recorded in advance in the pre-execution transaction set in sequence, an arrangement sequence of the transactions in the pre-execution transaction set, and a pre-execution read-write set of the transactions to the slave node; and the slave node is used for executing the transactions according to the arrangement sequence of the transactions and the pre-execution read-write set of each transaction.
A sixth aspect of the present specification provides a blockchain comprising a master node and a slave node,
the main node is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set; determining a plurality of previously recorded sequentially ordered transactions from the set of pre-executed transactions; grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions; sending the plurality of transactions, the arranging sequence of the plurality of transactions in the pre-execution transaction set, and the grouping results of the plurality of transactions to the slave node;
the slave node is used for executing the plurality of transactions in parallel according to the arrangement sequence and the grouping result of the plurality of transactions.
A seventh aspect of the present specification provides a block-chaining master node, comprising: the pre-execution unit is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; a conflict detection unit for serially performing the following processing for each transaction after each transaction is pre-executed: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set; and the sending unit is used for sending the plurality of transactions which are recorded in advance in the pre-execution transaction set and are arranged in the sequence, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the pre-execution read-write set of the plurality of transactions to a slave node.
An eighth aspect of the present specification provides a block chain master node, including:
the pre-execution unit is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
a conflict detection unit for serially performing the following processing for each transaction after each transaction is pre-executed: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction which is pre-executed, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
a determining unit for determining a plurality of transactions recorded in sequence from the pre-execution transaction set;
the grouping unit is used for grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
and the sending unit is used for sending the plurality of transactions, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the grouping results of the plurality of transactions to the slave node.
A ninth aspect of the present specification provides a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of the third or fourth aspect of the present specification.
A tenth aspect of the present specification provides a blockchain master node comprising a memory and a processor, the memory having stored therein executable code, the processor, when executing the executable code, implementing the method of the third or fourth aspect of the present specification.
According to the scheme provided by the embodiment of the specification, when the main node in the block chain executes the transaction in advance, the conflict among the transactions is considered, and the order of submitting the transactions is determined according to the sequence of detecting the conflict of the execution in advance of each transaction, so that the world state of the slave node when executing the transaction is consistent with the world state of the main node when executing the transaction in advance under the condition that the main node does not do harm, the transaction is prevented from being executed again due to the change of the world state when each slave node executes the transaction, and the transaction execution speed is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments described in the present disclosure, and it is obvious for a person skilled in the art to obtain other drawings based on these drawings without inventive labor.
FIG. 1 is a block chain architecture diagram applied in one embodiment of the present disclosure;
fig. 2 is a structural diagram of a master node and a slave node of a block chain provided in an embodiment of the present specification;
fig. 3 is a flowchart of a method for executing a transaction between a master node and a slave node according to an embodiment of the present disclosure;
fig. 4 is a structural diagram of a master node and a slave node of a block chain provided in an embodiment of the present specification;
fig. 5 is a flowchart of a method for executing a transaction between a master node and a slave node according to an embodiment of the present disclosure;
fig. 6 is an architecture diagram of a block chain master node according to an embodiment of the present disclosure;
fig. 7 is an architecture diagram of a block chain master node according to an embodiment of the present disclosure.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present specification without making any creative effort shall fall within the protection scope of the present specification.
Fig. 1 shows a block chain architecture diagram applied in the embodiment of the present specification. As shown in fig. 1, the block chain includes, for example, 6 nodes including a master node 1, a slave node 2, and a slave node 5. The lines between the nodes schematically represent P2P (Peer-to-Peer) connections. All the nodes store the full-amount accounts, namely the states of all the blocks and all the accounts. Wherein each node in the blockchain generates the same state in the blockchain by performing the same transaction, each node in the blockchain storing the same state database. In contrast, the master node 1 may be responsible for receiving transactions from clients and initiating consensus proposals to the respective slave nodes, including information such as multiple transactions in a block to be blocked (e.g., block B1) and the order of submission of the multiple transactions. After the node in the blockchain agrees on the consensus proposal successfully, the nodes may perform the multiple transactions according to the order of submission in the consensus proposal, thereby generating block B1.
It is to be appreciated that the blockchain shown in fig. 1 is merely exemplary, and that embodiments of the specification are not limited to application to the blockchain shown in fig. 1, and may also be applied to, for example, a blockchain system that includes shards.
In addition, although fig. 1 shows that the blockchain includes 6 nodes, the embodiments of the present specification are not limited thereto, and may include other numbers of nodes. Specifically, the nodes included in the block chain can meet the Byzantine Fault Tolerance (BFT) requirement. The byzantine fault tolerance requirement can be understood as that byzantine nodes can exist in a block chain, and the block chain does not show the byzantine behavior to the outside. Generally, some Byzantine Fault tolerance algorithms require the number of nodes to be greater than 3f +1, where f is the number of Byzantine nodes, such as the practical Byzantine Fault tolerance algorithm pbft (practical Byzantine Fault tolerance).
In the related art, in order to increase a per second execution Transaction (TPS) index in a blockchain, it is necessary to increase the execution speed of a transaction. For this reason, the execution speed of the transaction can be increased by executing the transaction in parallel in the blockchain node. In one embodiment, the blockchain nodes may execute transactions in parallel by multiple processes in a single machine, and in another embodiment, the blockchain nodes may be deployed in a server cluster and execute transactions in parallel by multiple servers. Generally, for transfer transactions, the block link point first divides a plurality of transactions into a plurality of transaction groups according to accounts to which the transactions are accessed, and the same account is not accessed between the respective transaction groups, so that the respective transaction groups can be executed in parallel. However, when a smart contract is invoked in a transaction, the variables accessed in the transaction cannot be predicted prior to execution of the transaction, and thus multiple transactions cannot be efficiently grouped, and transactions cannot be executed in parallel.
The embodiment of the specification provides a scheme for executing transactions in parallel in the blockchain shown in fig. 1, which can effectively improve TPS in the blockchain.
Fig. 2 shows a structure diagram of a master node 1 and a slave node (e.g., a slave node 2) of a block chain provided in an embodiment of the present specification. As shown in fig. 2, the master node 1 includes a pre-execution module 11, a collision detection module 12, and a consensus module 13, and the slave node 2 includes a consensus module 22 and a calculation module 23. The master node 1 may for example be connected to a client, so that a plurality of transactions may be received from the client. After receiving each transaction, the host node 1 pre-executes the transaction by the pre-execution module 11, resulting in a pre-executed read-write set for the transaction. The pre-execution read-write set includes a pre-execution read set and a pre-execution write set, where the pre-execution read set may specifically be a key-value pair of a read variable generated in the process of pre-execution transaction, and the pre-execution write set may specifically be a key-value pair of a write variable generated in the process of pre-execution transaction. The pre-execution module 11 may read the state values of the variables from the pre-execution state set or the state database when pre-executing the transaction. The pre-execution module 11 sends the pre-execution read-write set of the transaction to the conflict detection module 12 after pre-executing the transaction. The conflict detection module 12 comprises a set of pre-execution states and a set of pre-execution transactions, wherein the master node 1 stores the set of pre-execution states and the set of pre-execution transactions, for example in a memory, for use by the conflict detection module 12. The conflict detection module 12 performs pre-execution conflict detection on each transaction serially. Specifically, the conflict detection module 12 detects whether a conflict exists between the pre-execution read set of the transaction and the write set of the transaction that has been pre-executed, and may determine that a conflict exists if the value of a variable in the pre-execution read set of the transaction is different from the value of the variable in the pre-execution state set. If it is determined that there is no conflict, the conflict detection module 12 updates the state in the pre-execution write set of the transaction to the pre-execution state set and arranges the transaction in order into the pre-execution transaction set.
The consensus module 13 obtains a plurality of transactions in a previously recorded sequence from a pre-executed transaction set, and initiates a consensus proposal including the obtained plurality of transactions and the sequence of the plurality of transactions in the pre-executed transaction set to a consensus module (e.g., the consensus module 22) of each slave node. In addition, the consensus proposal may also include a set of pre-executed reads for each transaction.
After the consensus of the plurality of consensus nodes in the blockchain is successful, the computing module in each slave node may start to execute the plurality of transactions. The calculation module 23 of the slave node 2 includes a grouping submodule 231, a plurality of execution submodules (an execution submodule 232, an execution submodule 233, and an execution submodule 234 are schematically illustrated in the figure), and a re-execution submodule 235.
Specifically, in the master node 1, since the conflict detection is performed on each transaction in series during the pre-execution of each transaction, and the consensus is initiated according to the transaction arrangement sequence in the pre-execution transaction set, if the master node 1 executes a plurality of transactions that are agreed, the obtained execution result is necessarily consistent with the pre-execution result of each transaction, and therefore, the master node 1 may not execute the plurality of transactions again, but may use the pre-execution result of each of the plurality of transactions as the execution result.
In the slave node 2, the grouping submodule 231 first divides the plurality of transactions into a plurality of transaction groups according to the pre-execution read-write set, and there is no conflict transaction between each transaction group. Among these situations, the situation where there is a conflict transaction between two transaction groups generally includes the following situations: transactions in the first transaction group read the first variable (i.e., the first transaction group reads the first variable), and transactions in the second transaction group write the first variable; writing a first variable into the first transaction group, and writing a first variable into the second transaction group; the first transaction group reads and writes the first variable, and the second transaction group writes the first variable; the first transaction group reads and writes the first variable, and the second transaction group reads and writes the first variable. Wherein a conflict transaction may also be considered to not exist if two transaction groups read the same variable. Generally, to simplify the scheme, the grouping sub-module 231 may group the transactions as required without accessing the same variables between the respective transaction groups.
Thereafter, the plurality of execution sub-modules may execute the plurality of transactions in parallel according to the grouping result of the plurality of transactions. During the process of executing the transaction, if it is determined that the executing read-write set of the transaction is inconsistent with the pre-executing read-write set, that is, the master node 1 provides the slave node 2 with an incorrect pre-executing read-write set (that is, the master node acts as a malicious node), the slave node 2 may rollback the execution of the transaction, and the re-execution sub-module 235 re-executes the rolled-back transaction after the processing of each execution sub-module completes all the multiple transactions, so as to ensure the correctness of the packet.
Through the process, when the main node in the block chain pre-executes the transaction, the conflict among the transactions is considered, and the order of submitting the transactions is determined according to the sequence of detecting the pre-execution conflict of each transaction, so that the world state of the slave node when executing the transaction is consistent with the world state of the main node when pre-executing the transaction under the condition that the main node does not do harm. The slave node does not need to pre-execute a plurality of transactions, and can group the plurality of transactions based on the pre-execution read-write set of the master node, so that the plurality of transactions are executed in parallel. In addition, the slave node compares the execution read-write set and the pre-execution read-write set of the transaction, determines the transaction with inconsistent variable state during execution and pre-execution of the master node, rolls back the execution of the transaction, and re-executes the transaction after processing all transactions, thereby ensuring that the transaction which is badly done by the master node is eliminated.
The above process will be described in detail below with reference to a flow chart of a method of performing a transaction as shown in fig. 3. In fig. 3, only the flow performed by the master node 1 and the slave node 2 is shown, and it is understood that other slave nodes in the block chain perform the same flow as the slave node 2.
As shown in fig. 3, first, in step S301, the master node 1 pre-executes transactions, resulting in pre-executed read-write sets for the respective transactions.
The master node 1 may pre-execute a transaction immediately after each receipt of the transaction. The master node 1 may pre-execute in parallel a plurality of transactions received simultaneously. Specifically, when the host node 1 performs a transaction in advance, when reading a value of any variable from the pre-execution state set or the state database in fig. 2, the host node records the key-value pair of the read variable in a read cache of the transaction set in the memory, when writing a value of any variable, records the key-value pair of the written variable in a write cache of the transaction, and after the pre-execution is completed, the host node may obtain the pre-execution read-write set of the transaction based on the read cache and the write cache of the transaction. The master node 1 may include a storage device (not shown in fig. 2) for storing a state database, the state database stores world states of the accounts in the block chain and the variables defined by the contracts, and the master node 1 updates the state database according to the execution result of each transaction in the block after generating the block.
When the master node 1 reads a variable (for example, variable a) in the process of pre-executing the transaction, the master node 1 first determines whether a value of the variable a is stored in a write cache of the transaction, and if the value of the variable a is stored, the value of the variable a can be directly read from the write cache. In the event that it is determined that the value of variable a is not stored in the write cache, it is determined whether the value of variable a is stored in the read cache for the transaction, and if so, the value of variable a may be read from the read cache. In the case where it is determined that the value of the variable a is not stored in the read cache, it is determined whether the value of the variable a is stored in the pre-execution state set, and if the value of the variable a is stored, the value of the variable a may be read from the pre-execution state set. In the event that it is determined that the value of variable a is not stored in the pre-execution state set, the value of variable a may be read from the state database. That is, the master node 1 reads the variable with the priority of: the write cache of the transaction > the read cache of the transaction > the set of pre-execution states > the state database, by which it is ensured that the value of the variable read during pre-execution is the latest value of the variable.
The master node 1 gets the pre-executed read-write set of the respective transaction after pre-executing each transaction as described above. In one embodiment, the set of pre-executed reads and writes includes a read set and a write set, wherein the read set includes key-value pairs (key-values) of variables read when the transaction is pre-executed, and the write set includes key-value pairs of variables written when the transaction is pre-executed. In another embodiment, the read set of the pre-executed read/write set may include version numbers of variables read when the transaction is pre-executed, and the write set may include version numbers of variables written therein, where, for example, each written value of a variable and a version number corresponding to each written value are stored in the state database, so that the values read and written in the transaction may be determined by including the version numbers of the variables in the read/write set.
In the case of a contract invoked in a transaction, it is possible for a block link point to write a different variable depending on the value of the variable read in the course of executing the contract invoked by the transaction. For example, when the value of the read variable is 1, 10 is written to the variable a, when the value of the read variable is 2, 20 is written to the variable b, and so on. Thus, for a transaction that invokes a contract, the block link points must execute the transaction to determine the variables read and written for the transaction, and thus the read and write sets for the transaction. To this end, the master node 1 obtains a set of pre-executed reads for each transaction by pre-executing each transaction of a plurality of transactions, the pre-executed process being substantially the same as the process of executing the transaction, except that the pre-execution of the transaction is an execution process performed before consensus and the execution of the transaction is an execution process performed after consensus. And the pre-execution result of the pre-execution transaction is used only to update the set of pre-execution states and not to update the world state, and the execution result of the execution transaction is used to update the world state.
At step S303, the master node 1 determines whether the pre-execution read set of the transaction conflicts with the pre-execution state set.
The pre-execution state set is the latest state value of each variable cached by the master node 1 in the process of pre-executing each transaction. The master node 1 performs pre-execution conflict detection for each transaction serially after pre-execution of each transaction.
Specifically, the master node 1 first determines whether a variable (e.g., variable a) in the pre-execution read set of the transaction Tx1 is included in the pre-execution state set when pre-execution conflict detection is performed for the transaction Tx1 in the plurality of transactions. If not, it is similarly determined whether other variables in the pre-execution read set of transaction Tx1 are included in the pre-execution state set. If all of the variables in the pre-execution read set of the transaction Tx1 are not included in the pre-execution state set, i.e., the transaction that has been previously pre-execution conflict detected has not read or written a variable accessed by the transaction, then it may be determined that the pre-execution read set of the transaction Tx1 does not conflict with the pre-execution state set, i.e., it is determined that the pre-execution of the transaction Tx1 does not conflict with the transaction that has been previously pre-execution conflict detected.
If the main node 1 determines that the value of the variable A is included in the pre-execution state set, whether the value of the variable A in the pre-execution read set is consistent with the value of the variable A in the pre-execution state set is determined, and if so, the value of the variable A read by the transaction is the latest state of the variable A in the pre-execution process. After the master node 1 determines that the read value is the most recent state in the pre-execution process for each variable in the transaction Tx1 pre-execution read set, it may be determined that there is no conflict between the pre-execution read set and the pre-execution state set for the transaction Tx 1.
If the master node 1 determines that the value of the variable a in the pre-execution read set of the transaction Tx1 does not match the value of the variable a in the pre-execution state set, it indicates that the value of the variable a read by the transaction Tx1 is not the most recent state in the pre-execution process, and therefore, it may be determined that the pre-execution read set of the transaction Tx1 conflicts with the pre-execution state set. In the case where it is determined that there is a conflict, the master node 1 may re-pre-execute the transaction Tx1 by performing step S301.
In step S305, in a case where it is determined that there is no conflict between the pre-execution read set and the pre-execution state set of the transaction, the master node 1 updates the pre-execution state set and the pre-execution transaction set based on the pre-execution read set of the transaction.
Specifically, for example, the master node 1 determines that there is no conflict between the pre-execution read set of the transaction Tx2 in the multiple transactions and the pre-execution state set, and the master node 1 updates the values of the variables read or written in the pre-execution read-write set of the transaction Tx2 to the pre-execution state set, so that the latest state of each variable in the pre-execution process is recorded in the pre-execution state set. Meanwhile, the master node 1 records the transaction sequence into the pre-execution transaction set, for example, records the transaction to the end position (i.e., the last position) of the pre-execution transaction set. That is, the order of the recorded transactions in the set of pre-executed transactions embodies the order of conflict detection for the individual transactions, and the individual recorded transactions do not conflict with previously recorded transactions. Wherein the set of pre-executed transactions is, for example, in the form of a sequence table or in the form of a queue.
In step S307, the master node 1 sends a plurality of transactions recorded in advance in the pre-executed transaction set in the order, the order of the transactions in the pre-executed transaction set, and the pre-executed read-write set of the transactions to the slave node 2.
Specifically, the master node 1 may send a plurality of transactions arranged in an order at the head of a pre-executed transaction set (e.g., a pre-executed transaction queue), an arrangement order of the transactions in the pre-executed transaction set, and a pre-executed read-write set of the transactions to each slave node as a consensus suggestion, so as to achieve consensus with each slave node, that is, the transactions are taken as transactions in a block to be generated, and a submission order of the transactions is an arrangement order of the transactions in the pre-executed transaction set.
By doing so, the master node 1 eliminates conflicts between transactions when performing pre-execution, and each node performs each transaction in the order of arrangement in the pre-execution transaction set when performing transactions, so that the read-write set resulting from performing transactions without doing harm to the master node is consistent with the pre-execution read-write set of the transaction.
In step S309, the master node 1 generates a block after completing the pre-execution of the plurality of transactions.
After the host node 1 completes the pre-execution of the plurality of transactions, since the above-mentioned consensus process makes the pre-execution read-write set of the transactions consistent with the execution read-write set as described above, the host node 1 may directly use the pre-execution result of the transaction as the execution result of the transaction. And updating the state database according to the pre-execution read-write sets of the transactions, and generating a block. The block includes a block head and a block body. The block body includes, for example, data such as a transaction body and a receipt of each of the plurality of transactions. The block header may include data such as a status root, a receipt root, a transaction root, etc.
In step S311, the slave node 2 groups a plurality of transactions based on the set of pre-execution reads and writes.
The slave node 2 may group the plurality of transactions based on the key (key) of the read variable and the key of the written variable included in the pre-execution read-write set of each transaction. As described above, the grouping may be such that transactions in different transaction groups do not access the same variable, including read and write operations, and in the event that the grouping condition is met, there will be no conflicting transactions between the transaction groups, and thus the transaction groups may be executed in parallel.
In step S313, the slave node 2 executes the plurality of transactions in parallel according to the grouping result and the arrangement order of the plurality of transactions, wherein the transaction in which the execution read-write set and the pre-execution read-write set do not coincide is rolled back.
Referring to fig. 2, the slave node 2 may execute transactions in a plurality of transaction groups in parallel through a plurality of execution sub-modules. Assuming that the grouping submodule 231 groups a plurality of transactions into 6 groups g1 to g6, the grouping submodule 231 may transmit the group g1 and the group g2 to the execution submodule 232, the group g3 and the group g4 to the execution submodule 233, and the group g5 and the group g6 to the execution submodule 234, so that the respective execution submodules may execute the transactions in the groups into which they are grouped in parallel.
Taking the execution submodule 232 as an example, the execution submodule 232 may process the group g1 and the group g2 into which it is divided in series or in parallel. Because there may be conflicts between transactions in one group, the execution submodule 232 executes transactions in a single group serially. The execution submodule 232 obtains an executing read-write set of the transaction Tx1 after executing a transaction (e.g., transaction Tx 1) of the group g 1. The execution submodule 232 may compare whether the execution read-write set of the transaction Tx1 is consistent with the pre-execution read-write set. If the transaction Tx1 execution read-write set is consistent with the pre-execution read-write set, the execution submodule 232 may update the state (i.e., world state) of each variable in the cache according to the transaction Tx1 execution write set.
If not, it indicates that the master node 1 provides the slave node 2 with the wrong set of pre-executed reads and writes. I.e. master node 1 acts as a slave. In this case, in order to enable the execution submodule 232, the execution submodule 233 and the execution submodule 234 to continue to execute each transaction group in parallel according to the existing grouping result, the execution submodule 232 rolls back the execution of the transaction Tx1, specifically, may delete the read-write set obtained by executing the transaction Tx1, and move the transaction Tx1 out of the group g1 and place the transaction Tx1 in the group g7, where the group g7 is used for aggregating transactions of which the execution read set is different from the pre-execution read set. That is, by rolling back the execution of transaction Tx1 so that transaction Tx1 does not affect the current world state, causing the rolling back of other transactions, by moving transaction Tx1 out of group g1 so that the variables accessed by transaction Tx1 do not affect the grouping of other transactions so that the respective execution submodules can continue to execute the respective transaction groups in parallel.
Optionally, the rolled back transaction is re-executed from node 2 at step S315.
After the slave node 2 executes all of the plurality of transactions (including the transactions rolled back after execution), the transactions in group g7, i.e., the one or more transactions moved from the plurality of transaction groups that have been rolled back, may be re-executed according to the state of the variables maintained in the cache. Wherein the variable state maintained in the cache is a variable state derived from a write set of a transaction that is not rolled back from the plurality of transactions. The execution order in which the plurality of transactions in group g7 are re-executed may be determined according to preset rules. For example, the multiple transactions may be performed serially according to the order of their transaction numbers in group g 7.
In another embodiment, the slave node 2, after rolling back the transaction, may return the transaction execution failure directly to the client without re-executing the transaction.
In the above-described case where the master node performs the transaction as described above, each slave node performs rollback on the same transaction during the execution of the transaction and performs the rolled back transactions in the same order based on the same world state, so that each slave node finally obtains the same execution result on a plurality of transactions and obtains the same world state corresponding to the block including the plurality of transactions. Meanwhile, the world state of each slave node is branched from the world state of the master node at the same block height, a plurality of slave nodes can cancel the master node through consensus, and a new master node is reselected from the plurality of slave nodes to execute subsequent blocks.
In step S317, a tile is generated from the node 2. Optionally, the slave node 2 may include a pre-executed read-write set of multiple transactions in a block. By including the pre-executed read-write set of multiple transactions in a block, when other slave nodes lose data due to a failure or the like, the multiple transactions in the block can be re-executed based on the pre-executed read-write set of the block in the slave node 2, thereby obtaining a world state consistent with the slave node 2.
Fig. 4 is an architecture diagram of another master node and slave node provided in an embodiment of the present specification. The architecture diagram shown in fig. 4 is different from the architecture diagram shown in fig. 2 in that the consensus module 13 in the master node 1 includes a grouping submodule 131, the grouping submodule 131 groups a plurality of transactions based on a pre-execution read-write set of the plurality of transactions, and sends the plurality of transactions, an arrangement order thereof, a grouping result of the plurality of transactions, and the pre-execution read-write set of the plurality of transactions to the slave node 2 for consensus. The slave node 2 does not include the grouping submodule 131, and can directly execute the transactions in the plurality of transaction groups in parallel according to the received grouping result of the plurality of transactions.
In another embodiment, in the case that the master node is trusted, the slave node does not need to verify whether the master node is malicious based on the set of pre-executed reads and writes, and thus the master node may not send the set of pre-executed reads and writes to the slave node and the slave node may not include the re-execution submodule.
Fig. 5 is a flowchart of a method for performing a transaction according to an embodiment of the present disclosure. Steps S501 to S505 in the flowchart may refer to the above description of steps S301 to S305 in fig. 3, step S509 may refer to the above description of step S307 in fig. 3, step S511 may refer to the above description of step S309 in fig. 3, and steps S513 to S517 may refer to the above description of steps S313 to S317 in fig. 3, and are not repeated herein. The flowchart differs from the flowchart shown in fig. 3 in that the master node 1 executes step S507 after step S505, determines a plurality of transactions recorded in order from the pre-execution transaction set, and divides the plurality of transactions into a plurality of transaction groups according to the pre-execution read-write set of the plurality of transactions. So that the plurality of transactions, their ordering in the set of pre-executed transactions, the grouping result of the plurality of transactions and the set of pre-executed reads and writes of the plurality of transactions can be sent to the slave node 2. Therefore, the slave node 2 can directly execute the transactions in a plurality of transaction groups in parallel, and the transaction execution speed is further improved.
By the method shown in fig. 3 or fig. 5, when the transactions are pre-executed by the master node in the block chain, the conflicts among the transactions are considered, and the order of submitting the transactions is determined according to the sequence of detecting the pre-execution conflicts of the transactions, so that the world state of the slave node when executing the transactions is consistent with the world state when pre-executing the transactions, the transactions are prevented from being re-executed by the slave node when executing the transactions due to the change of the world state, and the transaction execution speed is increased.
Fig. 6 is an architecture diagram of a block chain master node according to an embodiment of the present disclosure, where the block chain master node includes:
a pre-execution unit 61, configured to pre-execute each received transaction based on a set of pre-execution states, and obtain a set of pre-execution reads and writes for each transaction;
a conflict detection unit 62 for serially performing the following for each transaction after pre-executing each transaction: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set;
a sending unit 63, configured to send, to a slave node, multiple transactions recorded in advance in the pre-executed transaction set in the order, the order of the multiple transactions in the pre-executed transaction set, and a pre-executed read-write set of the multiple transactions.
In one implementation, the pre-execution unit 61 is specifically configured to determine whether a value of a first variable is included in the pre-execution state set when the first variable is read in pre-execution of any of the transactions, and read the value of the first variable from a state database in a case where it is determined that the value of the first variable is not included in the pre-execution state set.
In one implementation, the conflict detection unit 62 is specifically configured to determine whether a second variable in a pre-execution read set of the transaction is included in the pre-execution state set, determine whether a value of the second variable in the pre-execution state set is consistent with a value of the second variable in the pre-execution read set in the case that the second variable is determined to be included in the pre-execution state set, and if not, determine that the pre-execution read set conflicts with the pre-execution state set.
In one implementation, the conflict detection unit 62 is further configured to re-pre-execute the second transaction in case that it is determined that the pre-execution read set of the pre-executed second transaction conflicts with the pre-execution state set.
Fig. 7 is an architecture diagram of a block chain master node according to an embodiment of the present specification, including:
a pre-execution unit 71, configured to pre-execute each received transaction based on the pre-execution state set, and obtain a pre-execution read-write set of each transaction;
a conflict detection unit 72 for serially performing the following for each transaction after pre-executing each transaction: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
a determining unit 73 for determining a plurality of transactions recorded in order from the pre-execution transaction set;
a grouping unit 74, configured to group the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
a sending unit 75, configured to send the multiple transactions, the arrangement order of the multiple transactions in the pre-execution transaction set, and the grouping result of the multiple transactions to the slave node.
Embodiments of the present specification also provide a computer-readable storage medium on which a computer program is stored, which, when executed in a computer, causes the computer to perform the method shown in fig. 3 or fig. 5.
Embodiments of the present specification further provide a blockchain master node, including a memory and a processor, where the memory stores executable code, and the processor executes the executable code to implement the method shown in fig. 3 or fig. 5.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium that stores computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and embedded microcontrollers, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a server system. Of course, this application does not exclude that with future developments in computer technology, the computer implementing the functionality of the above described embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device or a combination of any of these devices.
Although one or more embodiments of the present description provide method operational steps as described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive approaches. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of sequences, and does not represent a unique order of performance. When an actual apparatus or end product executes, it may execute sequentially or in parallel (e.g., parallel processors or multi-threaded environments, or even distributed data processing environments) according to the method shown in the embodiment or the figures. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in processes, methods, articles, or apparatus that include the recited elements is not excluded. For example, if the terms first, second, etc. are used to denote names, they do not denote any particular order.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, when implementing one or more of the present description, the functions of each module may be implemented in one or more software and/or hardware, or a module implementing the same function may be implemented by a combination of multiple sub-modules or sub-units, etc. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
One skilled in the art will appreciate that one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
One or more embodiments of the present description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more embodiments of the specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment. In the description of the specification, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the specification. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Moreover, various embodiments or examples and features of various embodiments or examples described in this specification can be combined and combined by one skilled in the art without being mutually inconsistent.
The above description is merely exemplary of one or more embodiments of the present disclosure and is not intended to limit the scope of one or more embodiments of the present disclosure. Various modifications and alterations to one or more embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of the present specification should be included in the scope of the claims.
Claims (24)
1. A method of performing a transaction in a blockchain, the blockchain including a master node and a slave node, the method comprising:
the main node executes each received transaction in advance based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after pre-executing each transaction, the master node serially processes each transaction as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
the master node sends a plurality of transactions which are recorded in advance in the pre-execution transaction set and are sequentially arranged, the arrangement sequence of the transactions in the pre-execution transaction set and a pre-execution read-write set of the transactions to the slave node;
and the slave node executes the multiple transactions according to the arrangement sequence of the multiple transactions and the pre-execution read-write set of each transaction.
2. The method of claim 1, wherein the master node pre-executing each transaction received based on a set of pre-execution states comprises the master node determining whether a value of a first variable is included in the set of pre-execution states when reading the first variable in pre-executing any transaction, and reading the value of the first variable from a state database in the event that it is determined that the value of the first variable is not included in the set of pre-execution states.
3. The method of claim 1 or 2, wherein the determining whether the pre-execution read set of the transaction conflicts with the pre-execution state set comprises determining whether a second variable in the pre-execution read set of the transaction is included in the pre-execution state set, and in the event that the second variable is determined to be included in the pre-execution state set, determining whether a value of the second variable in the pre-execution state set coincides with a value of the second variable in the pre-execution read set, and if not, determining that the pre-execution read set conflicts with the pre-execution state set.
4. The method of claim 1 or 2, wherein the slave node executing the plurality of transactions according to the ranked order and the pre-execution read-write set of the plurality of transactions comprises the slave node grouping the plurality of transactions according to the pre-execution read-write set of the plurality of transactions, and executing the plurality of transactions in parallel according to the ranked order and the grouping result of the plurality of transactions.
5. The method of claim 4, further comprising the slave node, after executing any transaction, comparing whether the executing read-write set of the transaction is consistent with the pre-executing read-write set of the transaction, and in the event that an inconsistency is determined for a third transaction, rolling back execution of the third transaction.
6. The method of claim 5, further comprising the slave node re-executing a rolled back transaction after executing the plurality of transactions, the rolled back transaction including the third transaction.
7. The method of claim 6, further comprising the slave node, after re-executing the rolled back transaction, generating a first block comprising a pre-executed read-write set of the plurality of transactions.
8. The method of claim 1 or 2, further comprising the master node re-pre-executing the second transaction if it is determined that a pre-execution read set of a pre-executed second transaction conflicts with the pre-execution state set.
9. A method of performing a transaction in a blockchain, the blockchain including a master node and a slave node, the method comprising:
the main node executes each received transaction in advance based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after pre-executing each transaction, the master node serially processes each transaction as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
the master node determining a plurality of previously recorded sequentially ordered transactions from the set of pre-executed transactions;
the main node groups the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
the master node sends the plurality of transactions, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the grouping results of the plurality of transactions to the slave node;
the slave node executes the plurality of transactions in parallel according to the arrangement order and the grouping result of the plurality of transactions.
10. The method of claim 9, wherein the master node further transmits pre-execution read-write sets of the plurality of transactions to the slave node, the slave node comparing whether the execution read-write set of any transaction is consistent with the pre-execution read-write set of that transaction after executing the transaction, and in the event that an inconsistency is determined for a fourth transaction, rolling back the execution of the fourth transaction.
11. A method of performing a transaction in a blockchain, the blockchain including a master node and slave nodes, the method performed by the master node comprising:
pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set;
and sending a plurality of transactions which are recorded in advance in the pre-execution transaction set and are arranged in sequence, the arrangement sequence of the transactions in the pre-execution transaction set and a pre-execution read-write set of the transactions to the slave node.
12. The method of claim 11, wherein pre-executing each received transaction based on a set of pre-execution states to obtain a set of pre-execution reads and writes for each transaction comprises, upon reading a first variable in pre-executing any transaction, determining whether a value of the first variable is included in the set of pre-execution states, and upon determining that the value of the first variable is not included in the set of pre-execution states, reading the value of the first variable from a state database.
13. The method of claim 11 or 12, wherein the determining whether the pre-execution read set of the transaction conflicts with the pre-execution state set comprises determining whether a second variable in the pre-execution read set of the transaction is included in the pre-execution state set, and in the event that the second variable is determined to be included in the pre-execution state set, determining whether a value of the second variable in the pre-execution state set coincides with a value of the second variable in the pre-execution read set, and if not, determining that the pre-execution read set conflicts with the pre-execution state set.
14. The method of claim 11 or 12, further comprising re-pre-executing the second transaction if it is determined that a pre-execution read set of a pre-executed second transaction conflicts with the pre-execution state set.
15. A method of performing a transaction in a blockchain, the blockchain including a master node and slave nodes, the method performed by the master node comprising:
pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction which is pre-executed, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
determining a plurality of previously recorded sequentially ordered transactions from the set of pre-executed transactions;
grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
and sending the plurality of transactions, the arrangement sequence of the transactions in the pre-execution transaction set and the grouping results of the transactions to the slave node.
16. A blockchain comprising a master node and a slave node,
the main node is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set;
the master node is further configured to send a plurality of transactions recorded in advance in the pre-execution transaction set in sequence, an arrangement sequence of the transactions in the pre-execution transaction set, and a pre-execution read-write set of the transactions to the slave node;
and the slave node is used for executing the transactions according to the arrangement sequence of the transactions and the pre-execution read-write set of each transaction.
17. A blockchain comprises a master node and a slave node,
the main node is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction; after each transaction is pre-executed, each transaction is processed serially as follows: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set; determining a sequentially ordered plurality of transactions of prior records from the set of pre-executed transactions; grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions; sending the plurality of transactions, the arranging sequence of the plurality of transactions in the pre-execution transaction set, and the grouping results of the plurality of transactions to the slave node;
the slave node is used for executing the plurality of transactions in parallel according to the arrangement sequence and the grouping result of the plurality of transactions.
18. A blockchain master node, comprising:
the pre-execution unit is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
a conflict detection unit for serially performing the following processing for each transaction after each transaction is pre-executed: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded into a pre-execution transaction set;
and the sending unit is used for sending the plurality of transactions which are recorded in advance in the pre-execution transaction set and are arranged in the sequence, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the pre-execution read-write set of the plurality of transactions to a slave node.
19. The blockchain master node of claim 18, wherein the pre-execution unit is specifically configured to determine whether a value of a first variable is included in the set of pre-execution states when the first variable is read in pre-executing any of the transactions, and to read the value of the first variable from a state database in the event that the value of the first variable is determined not to be included in the set of pre-execution states.
20. The master node of claim 18 or 19, wherein the conflict detection unit is specifically configured to determine whether a second variable in a pre-execution state set of the transaction is included in the pre-execution state set, determine whether a value of the second variable in the pre-execution state set and a value of the second variable in the pre-execution state set coincide in the case that the second variable is determined to be included in the pre-execution state set, and if not, determine that the pre-execution state set and the pre-execution state set have a conflict.
21. The master node of claim 18 or 19, the conflict detection unit further configured to re-pre-execute the second transaction if it is determined that a pre-execution read set of a pre-executed second transaction conflicts with the pre-execution state set.
22. A block-chain master node, comprising:
the pre-execution unit is used for pre-executing each received transaction based on the pre-execution state set to obtain a pre-execution read-write set of each transaction;
a conflict detection unit for serially performing the following processing for each transaction after each transaction is pre-executed: determining whether a pre-execution read set of the transaction conflicts with the pre-execution state set, wherein in the case that no conflict exists for a first transaction after pre-execution, the pre-execution state set is updated based on the pre-execution read set of the first transaction, and the first transaction sequence is recorded in a pre-execution transaction set;
a determining unit for determining a plurality of transactions recorded in sequence from the pre-execution transaction set;
the grouping unit is used for grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
and the sending unit is used for sending the plurality of transactions, the arrangement sequence of the plurality of transactions in the pre-execution transaction set and the grouping results of the plurality of transactions to the slave nodes of the block chain.
23. A computer-readable storage medium, on which a computer program is stored which, when executed in a computer, causes the computer to carry out the method of any one of claims 11-15.
24. A blockchain master node comprising a memory having stored therein executable code and a processor that, when executing the executable code, implements the method of any of claims 11-15.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111296820.6A CN113743941B (en) | 2021-11-04 | 2021-11-04 | Method for executing transaction in block chain, block chain and main node |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111296820.6A CN113743941B (en) | 2021-11-04 | 2021-11-04 | Method for executing transaction in block chain, block chain and main node |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113743941A CN113743941A (en) | 2021-12-03 |
CN113743941B true CN113743941B (en) | 2022-08-26 |
Family
ID=78727253
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111296820.6A Active CN113743941B (en) | 2021-11-04 | 2021-11-04 | Method for executing transaction in block chain, block chain and main node |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113743941B (en) |
Families Citing this family (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114547203A (en) * | 2022-02-25 | 2022-05-27 | 蚂蚁区块链科技(上海)有限公司 | Method for executing transaction, block chain, main node and slave node |
CN114564500A (en) * | 2022-02-28 | 2022-05-31 | 蚂蚁区块链科技(上海)有限公司 | Method and system for implementing structured data storage and query in block chain system |
CN115129727A (en) * | 2022-05-30 | 2022-09-30 | 蚂蚁区块链科技(上海)有限公司 | State data submission method, node and block chain system |
CN114936092A (en) * | 2022-05-30 | 2022-08-23 | 蚂蚁区块链科技(上海)有限公司 | Method for executing transaction in block chain and main node of block chain |
CN114827165B (en) * | 2022-05-30 | 2024-01-23 | 蚂蚁区块链科技(上海)有限公司 | Method and block link point for grouping multiple transactions |
CN114942847A (en) * | 2022-05-30 | 2022-08-26 | 蚂蚁区块链科技(上海)有限公司 | Method for executing transaction and block link point |
CN115150409B (en) * | 2022-06-29 | 2024-07-12 | 蚂蚁区块链科技(上海)有限公司 | Method for executing transaction in blockchain system, node and computer readable storage medium |
CN115098594A (en) * | 2022-06-29 | 2022-09-23 | 蚂蚁区块链科技(上海)有限公司 | Method for executing transaction in block chain system, block chain system and node |
CN115796874B (en) * | 2023-01-09 | 2023-05-09 | 杭州安节科技有限公司 | Concurrent execution method for blockchain transaction at operation level |
CN117422468B (en) * | 2023-12-18 | 2024-03-29 | 安徽中科晶格技术有限公司 | Method, equipment and storage medium for parallelizing contract link contracts based on DAG model |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US11070360B2 (en) * | 2018-08-13 | 2021-07-20 | International Business Machines Corporation | Parallel transaction validation and block generation in a blockchain |
CN110728578A (en) * | 2019-09-29 | 2020-01-24 | 南京金宁汇科技有限公司 | Parallel execution method, system and storage medium for block chain transaction |
CN112150163A (en) * | 2020-11-26 | 2020-12-29 | 北京微芯区块链与边缘计算研究院 | Block chain contract transaction parallel execution method and device |
CN112669155B (en) * | 2020-12-31 | 2024-05-03 | 杭州趣链科技有限公司 | Block chain-based transaction distribution execution method, device server and storage medium |
CN113220745B (en) * | 2021-05-19 | 2024-02-09 | 中国科学技术大学 | Transaction processing method and device based on blockchain and electronic equipment |
-
2021
- 2021-11-04 CN CN202111296820.6A patent/CN113743941B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN113743941A (en) | 2021-12-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113743941B (en) | Method for executing transaction in block chain, block chain and main node | |
CN113743940B (en) | Method for executing transaction in block chain, main node and slave node | |
CN113743950B (en) | Method, node and blockchain system for performing transactions in blockchain system | |
CN113743942B (en) | Transaction execution method, blockchain, master node and master storage device | |
CN115098594A (en) | Method for executing transaction in block chain system, block chain system and node | |
CN113743943B (en) | Method for executing transaction in block chain, main node and slave node | |
CN114827165B (en) | Method and block link point for grouping multiple transactions | |
TWI730690B (en) | Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment | |
CN113744061B (en) | Method for performing transactions in a blockchain system, and slave node | |
CN113744062B (en) | Method for performing transactions in a blockchain, blockchain node and blockchain | |
CN113204432B (en) | Transaction processing method and device in blockchain and electronic equipment | |
WO2023231336A1 (en) | Method for executing transaction and blockchain node | |
CN114936256A (en) | Method for executing transaction in block chain and block chain link point | |
CN114529417A (en) | Method for executing transaction, block chain, main node and slave node | |
CN113744063B (en) | Method and device for executing transaction in block chain | |
CN114547203A (en) | Method for executing transaction, block chain, main node and slave node | |
WO2023231335A1 (en) | Method for executing transaction in blockchain, and master node of blockchain | |
CN114936094A (en) | Method for executing transaction in block chain, master node and slave node of block chain | |
WO2024001025A1 (en) | Pre-execution cache data cleaning method and blockchain node | |
CN116707891A (en) | Replay attack checking method and block link point | |
CN115150409B (en) | Method for executing transaction in blockchain system, node and computer readable storage medium | |
CN113743949B (en) | Method for performing transactions in a blockchain, master node and slave node | |
CN115714652A (en) | Transaction execution method and block link point | |
CN115760405A (en) | Transaction execution method, device, computer equipment and medium | |
CN115033350A (en) | Execution method and device of distributed transaction |
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 | ||
TR01 | Transfer of patent right |
Effective date of registration: 20240929 Address after: Room 803, floor 8, No. 618 Wai Road, Huangpu District, Shanghai 200010 Patentee after: Ant blockchain Technology (Shanghai) Co.,Ltd. Country or region after: China Address before: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province Patentee before: Alipay (Hangzhou) Information Technology Co.,Ltd. Country or region before: China |