CN113743940B - Method for executing transaction in block chain, main node and slave node - Google Patents

Method for executing transaction in block chain, main node and slave node Download PDF

Info

Publication number
CN113743940B
CN113743940B CN202111296815.5A CN202111296815A CN113743940B CN 113743940 B CN113743940 B CN 113743940B CN 202111296815 A CN202111296815 A CN 202111296815A CN 113743940 B CN113743940 B CN 113743940B
Authority
CN
China
Prior art keywords
execution
transaction
transactions
read
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111296815.5A
Other languages
Chinese (zh)
Other versions
CN113743940A (en
Inventor
谢桂鲁
邓福喜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202111296815.5A priority Critical patent/CN113743940B/en
Publication of CN113743940A publication Critical patent/CN113743940A/en
Application granted granted Critical
Publication of CN113743940B publication Critical patent/CN113743940B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3827Use of message hashing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/401Transaction verification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules

Abstract

A method of performing a transaction in a blockchain, a master node and a slave node. The method comprises the following steps: the master node pre-executes each transaction received based on a pre-execution state set and/or a state database; after each transaction is pre-executed, performing conflict detection on each transaction in series based on the pre-execution state set, and updating the pre-execution state set and the pre-execution transaction set in the case of passing detection; determining a plurality of transactions from the set of pre-executed transactions, calculating a first hash value of a set of pre-executed reads and writes for the plurality of transactions; grouping the plurality of transactions; transmitting the plurality of transactions, the arrangement order thereof, the grouping result and the first hash value to a slave node; executing transactions in the plurality of transaction groups in parallel from a node; calculating a second hash value of the executing read-write set of the plurality of transactions; determining whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.

Description

Method for executing transaction in block chain, main node and slave node
Technical Field
The embodiments of the present specification relate to the field of blockchain technology, and more particularly, to a method for performing a transaction in a blockchain, a master node, and a slave 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 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, a master node and a slave node, which improves 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 into a pre-execution transaction set;
the main node determines a plurality of transactions which are recorded in advance and arranged in sequence from the pre-execution transaction set, and calculates a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
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 order of the plurality of transactions in the pre-execution transaction set, the grouping result of the plurality of transactions and the first hash value to the slave node;
according to the arrangement sequence of the multiple transactions and the grouping result of the multiple transactions, executing the multiple transactions in parallel by the slave node according to the arrangement sequence of the multiple transactions and the grouping result of the multiple transactions, and obtaining an execution read-write set of each transaction;
the slave node calculates second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm;
the slave node determines whether to submit the execution results of the plurality of transactions according to the comparison result of the first hash value and the second hash value.
A second 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;
determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set, and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
sending the plurality of transactions, the ordering of the plurality of transactions in the set of pre-executed transactions, the grouping results of the plurality of transactions, and the first hash value to the slave node.
A third 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 performed by the slave node comprising:
receiving a plurality of transactions, an arrangement order of the plurality of transactions, a grouping result of the plurality of transactions, and a first hash value from the master node; the multiple transactions are multiple transactions which are obtained by the main node from a pre-execution transaction set and are sequentially arranged in a previous record, the arrangement sequence of the multiple transactions is the arrangement sequence of the multiple transactions in the pre-execution transaction set, the grouping result of the multiple transactions is information grouped based on a pre-execution read-write set of the multiple transactions, the first hash value is a hash value of the pre-execution read-write set of the multiple transactions obtained based on a preset algorithm, and the pre-execution read-write set is obtained by the main node based on a pre-execution state set; a plurality of transactions which pass through conflict detection based on the pre-execution state set are sequentially recorded in the pre-execution transaction set;
according to the arrangement sequence of the multiple transactions and the grouping results of the multiple transactions, executing the multiple transactions in parallel to obtain an execution read-write set of each transaction;
calculating second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm;
determining whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.
A fourth 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 into a pre-execution transaction set; determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set, and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm; grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions; sending the plurality of transactions, the ordering of the plurality of transactions in the set of pre-executed transactions, the grouping results of the plurality of transactions, and the first hash value to the slave node;
the slave node is used for executing the plurality of transactions in parallel according to the arrangement sequence of the plurality of transactions and the grouping result of the plurality of transactions to obtain an execution read-write set of each transaction; calculating second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm; determining whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.
A fifth aspect of the present specification provides 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;
the calculation unit is used for determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
the grouping unit is used for grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
a sending unit, configured to send the multiple transactions, the arrangement order of the multiple transactions in the pre-execution transaction set, the grouping results of the multiple transactions, and the first hash value to the slave node.
A sixth aspect of the present specification provides a blockchain slave node comprising:
a receiving unit, configured to receive a plurality of transactions, an arrangement order of the plurality of transactions, grouping results of the plurality of transactions, and a first hash value from a blockchain master node; the multiple transactions are multiple transactions which are obtained by the main node from a pre-execution transaction set and are sequentially arranged in a previous record, the arrangement sequence of the multiple transactions is the arrangement sequence of the multiple transactions in the pre-execution transaction set, the grouping result of the multiple transactions is information grouped based on a pre-execution read-write set of the multiple transactions, the first hash value is a hash value of the pre-execution read-write set of the multiple transactions obtained based on a preset algorithm, and the pre-execution read-write set is obtained by the main node based on a pre-execution state set; a plurality of transactions which pass through conflict detection based on the pre-execution state set are sequentially recorded in the pre-execution transaction set;
the execution unit is used for executing the transactions in parallel according to the arrangement sequence of the transactions and the grouping result of the transactions to obtain an execution read-write set of each transaction;
the calculation unit is used for calculating second hash values of the execution read-write sets of the multiple transactions according to the preset algorithm;
a comparison unit configured to determine whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.
A seventh aspect of the present specification provides a computer readable storage medium having stored thereon a computer program which, when executed on a computer, causes the computer to perform the method of the second or third aspect.
An eighth aspect of the present specification provides a blockchain master node comprising a memory having stored therein executable code and a processor that, when executing the executable code, implements the method according to the second aspect.
A ninth aspect of the present specification provides a blockchain slave node comprising a memory having stored therein executable code and a processor that, when executing the executable code, implements the method of the third aspect.
By the method provided by the embodiment of the specification, 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 pre-executing conflict detection on 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. In this case, the master node may send only the hash values of the pre-execution read-write sets of the multiple transactions to the slave node for verifying whether the master node performs malicious work, and the master node may be determined to perform malicious work as long as the hash values of the pre-execution read-write sets are not consistent with the hash values of the execution read-write sets of the multiple transactions.
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 an architecture diagram of a block chain master node according to an embodiment of the present disclosure;
fig. 5 is an architecture diagram of a slave node in a blockchain 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 skilled in the art based on the embodiments in the present specification without any inventive step should fall within the scope of protection 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 the number of transactions in the block to be blocked (e.g., block B1) and the order of submission of the respective transactions. After the node in the blockchain successfully agrees on the consensus proposal, the nodes may perform the 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 the embodiments of the present specification are not limited to application to the blockchain shown in fig. 1, and may also be applied to a blockchain system including slices, for example.
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-tolerant 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-tolerant 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 points first divide the transactions into transaction groups according to the account accessed by the transaction, and the same account is not accessed between each transaction group, so that each transaction group 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, i.e., 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., 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 of 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 recorded in sequence from the pre-execution transaction set, the consensus module 13 includes a grouping submodule 131, the grouping submodule 131 groups the plurality of transactions according to the respective pre-execution read-write sets of the plurality of transactions to obtain a plurality of transaction groups, and no conflict transaction exists between the transaction groups. 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; the first transaction group writes a 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 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 131 may group multiple transactions as required by not having access to the same variables between the various transaction groups.
Additionally, the consensus module 13 also calculates a first hash value of a set of pre-executed reads and writes for the plurality of transactions. Thereafter, the master node 1 initiates a consensus proposal to a consensus module (e.g. the consensus module 22) of each slave node, wherein the consensus proposal comprises the plurality of transactions, the ranking of the plurality of transactions in the pre-execution transaction set, the grouping result of the plurality of transactions, and the first hash value.
After the consensus of the plurality of consensus nodes in the blockchain is successful, the computing module in each slave node may start to perform the plurality of transactions. The calculation module 23 of the slave node 2 includes a plurality of execution submodules (schematically illustrated in the figure are an execution submodule 232, an execution submodule 233, and an execution submodule 234), and a hash value comparison module 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 of the consensus, 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, a plurality of execution sub-modules may execute the transactions in the plurality of transaction groups in parallel, resulting in execution read-write sets of the respective transactions. Then, the hash value comparing module 235 calculates a second hash value of the executing read-write set of the multiple transactions, and compares whether the first hash value is consistent with the second hash value, and in case of consistency, the executing results of the multiple transactions may be submitted to generate corresponding blocks.
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. In this case, the master node 1 sends the hash value of the pre-execution read-write sets of the multiple transactions to each slave node, and the slave node can verify whether the master node is malicious or not based on the hash value.
The above process will be described in detail below with reference to a flow chart of a method of performing a transaction 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 the other slave nodes in the blockchain 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 during execution of the contract invoked for 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.
In 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 transaction Tx1 are not included in the pre-execution state set, i.e., the variables accessed by the transaction have not been read or written by a transaction that has previously been pre-execution conflict detected, then it may be determined that the pre-execution read set of 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 previously been 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 variable A in the pre-execution read set of transaction Tx1 does not match the value of variable A in the pre-execution state set, it indicates that the value of variable A read by 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 transaction Tx1 conflicts with the pre-execution state set. In case 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 determines a plurality of transactions recorded in the order from the pre-execution transaction set, and calculates a first hash value of the pre-execution read-write set of the plurality of transactions.
For example, in a case where the master node 1 records the transaction passing each collision detection to the end of line of the transaction queue, the master node 1 may determine a plurality of transactions of the transaction queue arranged in the order of the end of line and calculate the first hash value of the plurality of transactions.
In one embodiment, when calculating the first hash values of the multiple transactions, the master node 1 may arrange the variable values in the pre-execution read set and the pre-execution write set of the multiple transactions together according to a preset rule to form one data. For example, the variables in the read set for each of the transactions may be arranged alphabetically, the variables in the single variable may be arranged in the order of the size of the transaction number, the variables in the write set for each of the transactions may be similarly ordered, the read set and the write set may be arranged in a predetermined order, for example, the data in the read set is arranged before the data in the write set. After the arrangement, a hash value may be taken from the data obtained by the arrangement to obtain a first hash value, or the data obtained by the arrangement may be encoded and the encoded data may be taken from the hash value to obtain the first hash value.
In another embodiment, the master node 1 may arrange the variable values in the pre-execution read sets and the pre-execution write sets of the multiple transactions as a tree-like data structure, such as an MPT tree, a merck tree, etc., according to preset rules. Taking the MPT tree as an example, for the pre-execution read set of the transaction, the master node 1 may determine the position of the variable in the leaf node of the MPT tree according to a plurality of letters included in the key of the variable read in the transaction, and may determine the order of the value of the variable in the leaf node according to the size of the transaction number of the transaction. After arranging the variable values in both the pre-execution read set and the pre-execution write set of the multiple transactions as a tree-like data structure, for example, as two MPT trees, the master node 1 may calculate the hash values of the nodes starting from the leaf nodes of the two MPT trees and going up to calculate the hash value of the root node of the two MPT trees. Then, the master node 1 may calculate a first hash value based on the hash values of the root nodes of the two MPT trees, for example, the hash values of the root nodes of the two MPT trees are spliced and then the hash value is calculated, so as to obtain the first hash value.
In step S309, the master node 1 groups the plurality of transactions according to the pre-execution read-write set of the plurality of transactions.
The master node 1 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 S311, the master node 1 transmits the plurality of transactions, the arrangement order of the plurality of transactions in the pre-execution transaction set, the grouping result of the plurality of transactions, and the first hash value to the slave node 2.
Specifically, the master node 1 sends the multiple transactions, the arrangement order of the multiple transactions in the pre-execution transaction set, the grouping result of the multiple transactions, and the first hash value to the slave nodes and sends the slave nodes to the slave nodes, so as to agree with the slave nodes, that is, the multiple transactions are taken as the multiple transactions in the block to be generated, and the submission order of the multiple transactions is the arrangement order of the multiple transactions in the pre-execution 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 S313, 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 S315, the slave node 2 executes the multiple transactions in parallel according to the grouping result and the ranking order of the multiple transactions, resulting in an execution read-write set of each transaction.
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 131 divides the plurality of transactions into 6 groups g1 to g6, the slave node 2 may transmit the group g1 and the group g2 to the execution submodule 232, transmit the group g3 and the group g4 to the execution submodule 233, and transmit 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 divided 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. Since there may be conflicts between transactions in a group, the execution submodule 232 executes the transactions in a single group serially according to the rank order of the transactions in the single group. The execution submodule 232 obtains an execution read-write set for a transaction Tx1 after executing the transaction (e.g., transaction Tx 1) for group g 1. The respective execution read-write sets of the transactions are available through respective execution submodules.
At step S317, a second hash value of the executing read-write set of the plurality of transactions is computed from node 2.
The slave node 2 may calculate the second hash values of the multiple transactions executing the read-write set through the same preset algorithm as that of the master node 1, and the specific process may refer to the description of step S307, which is not described herein again.
In step S319, the slave node 2 compares whether the first hash value and the second hash value coincide.
If the first hash value does not match the second hash value, indicating that the master node 1 acts to deny the slave node 2 the provision of an erroneous pre-execution read-write set, the slave node 2 may determine that the results of executing the plurality of transactions based on the grouping result are erroneous results, and thus, the slave node 2 may not submit the results of executing the plurality of transactions. The plurality of nodes may re-agree on a transaction in the block to be generated, or the plurality of slave nodes may re-determine a master node for re-agreeing on a transaction in the block to be generated.
In step S321, the slave node 2 generates a tile in the case where it is determined that the first hash value coincides with the second hash value.
This step can be referred to the above description of step S313, and is not repeated here.
By the method shown in fig. 3, when the master node in the blockchain pre-executes the transactions, the conflicts between 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 in the case that the master node does not do harm. In this case, the master node may send only the hash values of the pre-execution read-write sets of the multiple transactions to the slave node for verifying whether the master node performs malicious work, and the master node may be determined to perform malicious work as long as the hash values of the pre-execution read-write sets are not consistent with the hash values of the execution read-write sets of the multiple transactions.
Fig. 4 is a block chain master node structure diagram provided in an embodiment of this specification, including:
a pre-execution unit 41, 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 42 for, after pre-executing each transaction, serially performing the following for 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 calculating unit 43, configured to determine a plurality of transactions recorded in sequence from the pre-execution transaction set, and calculate a first hash value of a pre-execution read-write set of the plurality of transactions according to a preset algorithm;
a grouping unit 44, configured to group the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
a sending unit 45, configured to send the multiple transactions, the arrangement order of the multiple transactions in the pre-execution transaction set, the grouping results of the multiple transactions, and the first hash value to the slave node.
In one implementation, the pre-execution unit 41 is specifically configured to, when a first variable is read in pre-execution of any one transaction, determine whether a value of the first variable is stored in the pre-execution state set, and in a case where it is determined that the value of the first variable is not stored in the pre-execution state set, read the value of the first variable from a state database.
In one implementation, the conflict detection unit 42 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 42 is further configured to re-pre-execute the second transaction if it is determined that the pre-execution read set of the pre-executed second transaction conflicts with the pre-execution state set.
In one implementation, the calculating unit 43 is specifically configured to arrange variable values in the pre-execution read-write sets of the multiple transactions as first data according to a preset rule, and calculate the first hash value based on the first data.
In one implementation, the calculating unit 43 is specifically configured to arrange the variable values in the pre-execution read sets of the multiple transactions into a first tree-shaped data structure according to a preset rule, arrange the variable values in the pre-execution write sets of the multiple transactions into a second tree-shaped data structure according to a preset rule, and calculate the first hash value according to the first tree-shaped data structure and the second tree-shaped data structure.
Fig. 5 is a block chain slave node structure diagram provided in an embodiment of the present specification, including:
a receiving unit 51, configured to receive a plurality of transactions, an arrangement order of the plurality of transactions, grouping results of the plurality of transactions, and a first hash value from a blockchain master node; the multiple transactions are multiple transactions which are obtained by the main node from a pre-execution transaction set and are sequentially arranged in a previous record, the arrangement sequence of the multiple transactions is the arrangement sequence of the multiple transactions in the pre-execution transaction set, the grouping results of the multiple transactions are the grouping results based on pre-execution read-write sets of the multiple transactions, the first hash value is the hash value of the pre-execution read-write sets of the multiple transactions obtained based on a preset algorithm, and the pre-execution read-write sets are obtained by the main node based on a pre-execution state set; a plurality of transactions which pass through conflict detection based on the pre-execution state set are sequentially recorded in the pre-execution transaction set;
the execution unit 52 is configured to execute the multiple transactions in parallel according to the arrangement order of the multiple transactions and the grouping result of the multiple transactions, so as to obtain an execution read-write set of each transaction;
a calculating unit 53, configured to calculate second hash values of the executed read-write sets of the multiple transactions according to the preset algorithm;
a comparing unit 54, configured to determine whether to submit the execution results of the multiple transactions according to the comparison result of the first hash value and the second hash value.
An embodiment of the present specification provides a block chain 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.
The embodiment of the present specification further provides a blockchain slave node, which includes a memory and a processor, where the memory stores executable codes, and the processor executes the executable codes to implement the method shown in fig. 3.
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 storing 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 an embedded microcontroller, 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 conceived to be both a software module implementing 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 embodiments may be, for example, a personal computer, a laptop computer, a vehicle mounted human interaction device, a cellular telephone, 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 orders and does not represent the only order of execution. 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 a process, method, article, or apparatus that comprises 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.
As will be appreciated by one skilled in the art, 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 the like) 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 present specification can 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. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
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 into a pre-execution transaction set;
the main node determines a plurality of transactions which are recorded in advance and arranged in sequence from the pre-execution transaction set, and calculates a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
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 order of the plurality of transactions in the pre-execution transaction set, the grouping result of the plurality of transactions and the first hash value to the slave node;
the slave node executes the multiple transactions in parallel according to the arrangement sequence of the multiple transactions and the grouping result of the multiple transactions to obtain an execution read-write set of each transaction;
the slave node calculates second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm;
the slave node determines whether to submit the execution results of the plurality of transactions according to the comparison result of the first hash value and the second hash value.
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, when reading a first variable in pre-executing any transaction, determining whether a value of the first variable is stored in the set of pre-execution states, in the event that it is determined that the value of the first variable is not stored in the set of pre-execution states, reading the value of the first variable from a state database.
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, further comprising the master node re-pre-executing the second transaction in the event that it is determined that a pre-execution read set of a pre-executed second transaction conflicts with the pre-execution state set.
5. The method of claim 1 or 2, wherein the master node calculating a first hash value of the set of pre-executed reads and writes for the plurality of transactions according to a preset algorithm comprises the master node arranging variable values in the set of pre-executed reads and writes for the plurality of transactions as first data according to a preset rule, the first hash value being calculated based on the first data.
6. The method of claim 1 or 2, wherein the master node calculating a first hash value of the set of pre-executed reads for the plurality of transactions according to a predetermined algorithm comprises the master node arranging variable values in the set of pre-executed reads for the plurality of transactions as a first tree data structure according to a predetermined rule, arranging variable values in the set of pre-executed writes for the plurality of transactions as a second tree data structure according to a predetermined rule, and calculating the first hash value according to the first tree data structure and the second tree data structure.
7. 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;
determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set, and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
sending the plurality of transactions, the ordering of the plurality of transactions in the set of pre-executed transactions, the grouping results of the plurality of transactions, and the first hash value to the slave node.
8. The method of claim 7, wherein said pre-executing each transaction received based on a set of pre-execution states comprises, upon reading a first variable in pre-executing any transaction, determining whether a value of the first variable is stored in the set of pre-execution states, and upon determining that the value of the first variable is not stored in the set of pre-execution states, reading the value of the first variable from a state database.
9. The method of claim 7 or 8, 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.
10. The method of claim 7 or 8, further comprising re-pre-executing the second transaction in the event that it is determined that a pre-execution read set of a pre-executed second transaction conflicts with the pre-execution state set.
11. The method of claim 7 or 8, wherein the calculating the first hash values of the set of pre-executed reads and writes for the plurality of transactions according to a preset algorithm comprises arranging variable values in the set of pre-executed reads and writes for the plurality of transactions as first data according to a preset rule, the first hash values being calculated based on the first data.
12. The method of claim 7 or 8, wherein the calculating the first hash values of the sets of pre-executed reads for the plurality of transactions according to the predetermined algorithm comprises arranging variable values in the sets of pre-executed reads for the plurality of transactions as a first tree-like data structure according to a predetermined rule, arranging variable values in the sets of pre-executed writes for the plurality of transactions as a second tree-like data structure according to a predetermined rule, and calculating the first hash values according to the first tree-like data structure and the second tree-like data structure.
13. A method of performing a transaction in a blockchain, the blockchain including a master node and a slave node, the method performed by the slave node comprising:
receiving a plurality of transactions, an arrangement order of the plurality of transactions, a grouping result of the plurality of transactions, and a first hash value from the master node; the multiple transactions are multiple transactions which are obtained by the main node from a pre-execution transaction set and are sequentially arranged in a previous record, the arrangement sequence of the multiple transactions is the arrangement sequence of the multiple transactions in the pre-execution transaction set, the grouping result of the multiple transactions is the result of grouping based on pre-execution read-write sets of the multiple transactions, the first hash value is the hash value of the pre-execution read-write sets of the multiple transactions obtained based on a preset algorithm, and the pre-execution read-write sets of the multiple transactions are obtained by the main node based on a pre-execution state set; a plurality of transactions which pass through conflict detection based on the pre-execution state set are sequentially recorded in the pre-execution transaction set;
according to the arrangement sequence of the multiple transactions and the grouping results of the multiple transactions, executing the multiple transactions in parallel to obtain an execution read-write set of each transaction;
calculating second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm;
determining whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.
14. 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 into a pre-execution transaction set; determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set, and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm; grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions; sending the plurality of transactions, the ordering of the plurality of transactions in the set of pre-executed transactions, the grouping results of the plurality of transactions, and the first hash value to the slave node;
the slave node is used for executing the plurality of transactions in parallel according to the arrangement sequence of the plurality of transactions and the grouping result of the plurality of transactions to obtain an execution read-write set of each transaction; calculating second hash values of the executing read-write sets of the multiple transactions according to the preset algorithm; determining whether to submit execution results of the plurality of transactions according to a comparison result of the first hash value and the second hash value.
15. 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;
the calculation unit is used for determining a plurality of transactions recorded in advance in sequence from the pre-execution transaction set and calculating a first hash value of a pre-execution read-write set of the transactions according to a preset algorithm;
the grouping unit is used for grouping the multiple transactions according to the pre-execution read-write sets of the multiple transactions;
a sending unit, configured to send the multiple transactions, the arrangement order of the multiple transactions in the pre-execution transaction set, the grouping results of the multiple transactions, and the first hash value to a slave node of the blockchain.
16. The master node of claim 15, wherein the pre-execution unit is specifically configured to, upon reading a first variable in pre-execution of any of the transactions, determine whether a value of the first variable is stored in the pre-execution state set, and in the event that it is determined that the value of the first variable is not stored in the pre-execution state set, read the value of the first variable from a database of states.
17. The master node of claim 15 or 16, 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.
18. The master node of claim 15 or 16, 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.
19. The master node of claim 15 or 16, wherein the computing unit is specifically configured to arrange variable values in the set of pre-executed reads and writes of the plurality of transactions as first data according to a preset rule, and to compute the first hash value based on the first data.
20. The master node of claim 15 or 16, wherein the computing unit is specifically configured to arrange the variable values in the pre-execution read sets of the multiple transactions into a first tree-like data structure according to a preset rule, arrange the variable values in the pre-execution write sets of the multiple transactions into a second tree-like data structure according to a preset rule, and compute the first hash value according to the first tree-like data structure and the second tree-like data structure.
21. A blockchain slave node, comprising:
a receiving unit, configured to receive a plurality of transactions, an arrangement order of the plurality of transactions, grouping results of the plurality of transactions, and a first hash value from a blockchain master node; the multiple transactions are multiple transactions which are obtained by the main node from a pre-execution transaction set and are sequentially arranged in a previous record, the arrangement sequence of the multiple transactions is the arrangement sequence of the multiple transactions in the pre-execution transaction set, the grouping result of the multiple transactions is the result of grouping based on pre-execution read-write sets of the multiple transactions, the first hash value is the hash value of the pre-execution read-write sets of the multiple transactions obtained based on a preset algorithm, and the pre-execution read-write sets of the multiple transactions are obtained by the main node based on a pre-execution state set; a plurality of transactions which pass through conflict detection based on the pre-execution state set are sequentially recorded in the pre-execution transaction set;
the execution unit is used for executing the transactions in parallel according to the arrangement sequence of the transactions and the grouping result of the transactions to obtain an execution read-write set of each transaction;
the calculation unit is used for calculating second hash values of the execution read-write sets of the multiple transactions according to the preset algorithm;
a comparison unit, configured to determine whether to submit execution results of the multiple transactions according to a comparison result of the first hash value and the second hash value.
22. 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 7-13.
23. 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 7-12.
24. A blockchain slave node comprising a memory having stored therein executable code and a processor that, when executing the executable code, implements the method of claim 13.
CN202111296815.5A 2021-11-04 2021-11-04 Method for executing transaction in block chain, main node and slave node Active CN113743940B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111296815.5A CN113743940B (en) 2021-11-04 2021-11-04 Method for executing transaction in block chain, main node and slave node

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111296815.5A CN113743940B (en) 2021-11-04 2021-11-04 Method for executing transaction in block chain, main node and slave node

Publications (2)

Publication Number Publication Date
CN113743940A CN113743940A (en) 2021-12-03
CN113743940B true CN113743940B (en) 2022-08-12

Family

ID=78727337

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111296815.5A Active CN113743940B (en) 2021-11-04 2021-11-04 Method for executing transaction in block chain, main node and slave node

Country Status (1)

Country Link
CN (1) CN113743940B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114564412B (en) * 2022-04-27 2022-07-22 北京微芯感知科技有限公司 Method and system for deterministic transaction concurrent scheduling of block chains
CN114936093A (en) * 2022-05-30 2022-08-23 蚂蚁区块链科技(上海)有限公司 Transaction execution method in blockchain system, node and blockchain system
CN114827165B (en) * 2022-05-30 2024-01-23 蚂蚁区块链科技(上海)有限公司 Method and block link point for grouping multiple transactions
CN114936092A (en) * 2022-05-30 2022-08-23 蚂蚁区块链科技(上海)有限公司 Method for executing transaction in block chain and main node of block chain
CN115796874B (en) * 2023-01-09 2023-05-09 杭州安节科技有限公司 Concurrent execution method for blockchain transaction at operation level
CN117527832A (en) * 2024-01-03 2024-02-06 杭州趣链科技有限公司 Transaction ordering method and device for blockchain, electronic equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220745A (en) * 2021-05-19 2021-08-06 中国科学技术大学 Transaction processing method and device based on block chain and electronic equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20200139034A (en) * 2019-06-03 2020-12-11 삼성에스디에스 주식회사 Blockchain based computing system and method for managing transaction thereof
CN110728578A (en) * 2019-09-29 2020-01-24 南京金宁汇科技有限公司 Parallel execution method, system and storage medium for block chain transaction
SG11202103246SA (en) * 2020-04-20 2021-04-29 Alipay Hangzhou Inf Tech Co Ltd Distributed blockchain data storage under account model
CN112150163A (en) * 2020-11-26 2020-12-29 北京微芯区块链与边缘计算研究院 Block chain contract transaction parallel execution method and device
CN112887437B (en) * 2021-04-28 2021-08-03 支付宝(杭州)信息技术有限公司 Block chain transaction processing method, block chain node and block chain system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220745A (en) * 2021-05-19 2021-08-06 中国科学技术大学 Transaction processing method and device based on block chain and electronic equipment

Also Published As

Publication number Publication date
CN113743940A (en) 2021-12-03

Similar Documents

Publication Publication Date Title
CN113743940B (en) Method for executing transaction in block chain, main node and slave node
CN113743941B (en) Method for executing transaction in block chain, block chain and main node
CN113743950B (en) Method, node and blockchain system for performing transactions in blockchain system
CN115098594A (en) Method for executing transaction in block chain system, block chain system and node
CN113743942B (en) Transaction execution method, blockchain, master node and master storage device
CN114827165B (en) Method and block link point for grouping multiple transactions
CN108599973B (en) Log association method, device and equipment
WO2023231336A1 (en) Method for executing transaction and blockchain node
CN113744062B (en) Method for performing transactions in a blockchain, blockchain node and blockchain
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
CN114936256A (en) Method for executing transaction in block chain and block chain link point
CN113743943B (en) Method for executing transaction in block chain, main node and slave node
CN114936092A (en) Method for executing transaction in block chain and main node of block chain
CN114936094A (en) Method for executing transaction in block chain, master node and slave node of block chain
CN113744061B (en) Method for performing transactions in a blockchain system, and slave node
CN115098483A (en) Pre-execution cache data cleaning method and block link point
CN115150409A (en) Method for executing transaction in block chain system, block chain system and node
CN115640356A (en) Transaction execution method in blockchain system, consensus node and blockchain system
CN116244373A (en) Transaction execution method, blockchain system, master node and slave storage device
CN114697344B (en) Method for determining consensus node in blockchain system, node, storage medium and computing device
CN115658806A (en) Transaction execution method and node in blockchain system
CN115714652A (en) Transaction execution method and block link point
CN115577044A (en) Transaction execution method in blockchain system, consensus node and blockchain system

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