WO2023160085A1 - Method for executing transaction, blockchain, master node, and slave node - Google Patents

Method for executing transaction, blockchain, master node, and slave node Download PDF

Info

Publication number
WO2023160085A1
WO2023160085A1 PCT/CN2022/135338 CN2022135338W WO2023160085A1 WO 2023160085 A1 WO2023160085 A1 WO 2023160085A1 CN 2022135338 W CN2022135338 W CN 2022135338W WO 2023160085 A1 WO2023160085 A1 WO 2023160085A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
dag
execution
variable
master node
Prior art date
Application number
PCT/CN2022/135338
Other languages
French (fr)
Chinese (zh)
Inventor
刘晓建
张兆勇
Original Assignee
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2023160085A1 publication Critical patent/WO2023160085A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • 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
    • G06Q10/00Administration; Management
    • G06Q10/06Resources, workflows, human or project management; Enterprise or organisation planning; Enterprise or organisation modelling
    • G06Q10/063Operations research, analysis or management
    • G06Q10/0631Resource planning, allocation, distributing or scheduling for enterprises or organisations
    • G06Q10/06311Scheduling, planning or task assignment for a person or group
    • 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
    • G06Q10/00Administration; Management
    • G06Q10/06Resources, workflows, human or project management; Enterprise or organisation planning; Enterprise or organisation modelling
    • G06Q10/063Operations research, analysis or management
    • G06Q10/0631Resource planning, allocation, distributing or scheduling for enterprises or organisations
    • G06Q10/06316Sequencing of tasks or work
    • 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
    • G06Q10/00Administration; Management
    • G06Q10/06Resources, workflows, human or project management; Enterprise or organisation planning; Enterprise or organisation modelling
    • G06Q10/063Operations research, analysis or management
    • G06Q10/0633Workflow analysis
    • 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
    • G06Q10/00Administration; Management
    • G06Q10/10Office automation; Time management
    • G06Q10/103Workflow collaboration or project management

Definitions

  • the embodiments of this specification belong to the technical field of block chain, and in particular relate to a method for executing transactions in the block chain, the block chain, a master node and a slave node.
  • Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • the data blocks are combined into a chained data structure in a sequentially connected manner in chronological order, and a non-tamperable and unforgeable distributed ledger is cryptographically guaranteed. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application. However, since the variables accessed cannot be predicted before the transactions calling smart contracts are executed, they usually cannot be executed in parallel.
  • the purpose of the present invention is to provide a method for executing transactions in the block chain, so that the slave nodes in the block chain can execute transactions in parallel according to the consensus proposal of the master node.
  • the first aspect of this specification provides a method for executing a transaction in a blockchain, the blockchain includes a master node and a slave node, and the method includes:
  • the master node pre-executes the received first transaction, and generates a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
  • the master node generates DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the The most recent transaction before the first transaction updates the pre-execution state of the first variable after pre-execution, and the DAG data indicates the time sequence in which the first transaction and the second transaction access the first variable;
  • the master node sends the DAG data to the slave node;
  • the slave node executes the first transaction and the second transaction based on the DAG data.
  • the second aspect of this specification provides a blockchain, the blockchain includes a master node and a slave node,
  • the master node is used to: pre-execute the received first transaction, generate a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
  • the pre-execution read-write set the identification of the second transaction that most recently updated the first variable recorded earlier, generates DAG data, and the second transaction is the most recent post-pre-execution update before the pre-execution of the first transaction
  • the slave node is configured to execute the first transaction and the second transaction based on the DAG data.
  • the third aspect of this specification provides a block chain master node, including:
  • a pre-execution unit configured to pre-execute the received first transaction, and generate a pre-execution read-write set of the first transaction, the pre-execution read-write set includes access to the first variable;
  • a generation unit configured to generate DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the pre-execution A transaction that updates the pre-execution state of the first variable after pre-execution, the most recent before the first transaction, and the DAG data indicates the time sequence in which the first transaction and the second transaction access the first variable;
  • a sending unit configured to send the DAG data to the slave nodes of the block chain.
  • the fourth aspect of this specification provides a blockchain slave node, including:
  • a receiving unit configured to receive DAG data from the master node of the blockchain, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable;
  • An execution unit configured to execute the first transaction and the second transaction based on the DAG data.
  • the slave node can execute the transactions without conflicts in parallel according to the DAG data generated by the master node, and the transactions with conflicts can be executed according to the order in the DAG data Execution, thereby improving the efficiency of transaction execution.
  • FIG. 1 is a block chain architecture diagram applied in the embodiment of this specification
  • FIG. 2 is a flow chart of a method for executing a transaction in a blockchain in an embodiment of this specification
  • Fig. 3 is a DAG diagram in an embodiment of this specification.
  • FIG. 4 is an architecture diagram of a block chain master node in an embodiment of this specification.
  • Fig. 5 is an architecture diagram of a block chain slave node in an embodiment of this specification.
  • Fig. 1 shows a block chain architecture diagram applied in the embodiment of this specification.
  • the blockchain includes, for example, 6 nodes including a master node 1, a slave node 2 to a slave node 6.
  • the connection between nodes schematically represents a P2P (Peer to Peer, point-to-point) connection.
  • P2P Peer to Peer, point-to-point
  • These nodes store a full amount of books, that is, store the status of all blocks and all accounts.
  • each node in the blockchain generates the same state in the blockchain by executing the same transaction, and each node in the blockchain stores the same state database.
  • the master node 1 can be responsible for receiving transactions from the client, and initiate a consensus proposal to each slave node.
  • the consensus proposal includes, for example, multiple transactions in the block to be formed (such as block B1) and each Information such as the order in which transactions are submitted. After the nodes in the blockchain successfully reach consensus on the consensus proposal, each node can execute the multiple transactions according to the order of submission in the consensus proposal, thereby generating block B1.
  • block chain shown in FIG. 1 is only exemplary, and the embodiment of this description is not limited to be applied to the block chain shown in FIG. 1 , for example, it can also be applied to a block chain system including sharding.
  • the block chain includes 6 nodes
  • the embodiment of this specification is not limited thereto, but may include other numbers of nodes.
  • the nodes contained in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements.
  • BFT Byzantine Fault Tolerance
  • the Byzantine fault tolerance requirement can be understood as that there may be Byzantine nodes inside the blockchain, but the blockchain does not reflect Byzantine behavior externally.
  • 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).
  • a transaction in the blockchain field may refer to a unit of tasks performed and recorded in the blockchain.
  • a transaction usually includes a sending field (From), a receiving field (To) and a data field (Data).
  • the From field indicates the account address that initiated the transaction (that is, initiates a transfer task to another account)
  • the To field indicates the account address that received the transaction (that is, received the transfer)
  • the Data field Include the transfer amount.
  • the From field indicates the account address that initiated the transaction
  • the To field indicates the account address of the contract called by the transaction
  • the Data field includes the function name in the calling contract
  • the Data such as the incoming parameters of the function are used to obtain the code of the function from the blockchain and execute the code of the function when the transaction is executed.
  • Smart contracts on the blockchain are contracts that can be triggered by transactions on the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract in Ethereum is to initiate a transaction pointing to the address of the smart contract, so that each node in the Ethereum network runs the smart contract code in a distributed manner. It should be noted that in addition to creating smart contracts by users, smart contracts can also be set by the system in the genesis block. This type of contract is generally called a genesis contract. Generally, some blockchain data structures, parameters, attributes and methods can be set in the genesis contract. In addition, accounts with system administrator privileges can create system-level contracts or modify system-level contracts (referred to as system contracts). Wherein, the system contract can be used to add data structures of different business data in the blockchain.
  • Bob sends a transaction containing information about creating a smart contract (that is, deploying a contract) to the blockchain shown in Figure 1, and the data field of the transaction includes the code of the contract to be created (such as bytecode or machine code), the to field of the transaction is empty to indicate that the transaction is used to deploy the contract.
  • the nodes After the nodes reach an agreement through the consensus mechanism, determine the contract address "0x6f8ae93", each node adds the contract account corresponding to the contract address of the smart contract in the state database, allocates the state storage corresponding to the contract account, and The contract code is saved in the state storage of the contract, so the contract is created successfully.
  • the from field of the transaction is the address of the account of the transaction initiator (ie Bob), "0x6f8ae93" in the to field represents the address of the called smart contract, and the data field of the transaction includes the method and parameters of calling the smart contract.
  • each node in the blockchain can respectively execute the transaction, thereby respectively executing the contract, and updating the state database based on the execution of the contract.
  • transactions can be executed in parallel in blockchain nodes to speed up transaction execution.
  • the blockchain node can execute transactions in parallel through multiple processes in a single machine.
  • the blockchain node can be deployed in a server cluster and execute transactions in parallel through multiple servers.
  • blockchain nodes first divide multiple transactions into multiple transaction groups according to the accounts accessed by the transactions, and each transaction group does not access the same account, so that each transaction group can be executed in parallel.
  • a smart contract is called in a transaction, the variables accessed in the transaction cannot be predicted before the transaction is executed, so multiple transactions cannot be effectively grouped, and transactions cannot be executed in parallel.
  • the master node can execute the transaction and send the execution result to the slave node for verification.
  • the master node will only package non-conflicting transactions during execution and postpone conflicting transactions to The next block is packed so that slave nodes can achieve concurrent verification.
  • this method when the conflict rate between transactions is high, these transactions will be placed in different blocks, which reduces system performance and increases storage costs.
  • Fig. 2 is a flow chart of a method for executing a transaction in a block chain in an embodiment of this specification, the method can be executed by the master node and each slave node shown in Fig. 1, and master node 1 and slave node 2 are shown in Fig. 2 As an example, it is understood that other slave nodes in the blockchain perform the same operations as slave node 2.
  • step S201 the master node pre-executes the received transaction and generates a pre-execution read-write set of the transaction.
  • the pre-execution refers to the execution of the transaction by the master node before making a consensus proposal.
  • the master node 1 Before the consensus proposal, the master node 1 has not set the submission order of each transaction, and the master node 1 can pre-execute the transactions in any order.
  • the master node 1 may pre-execute the received transactions in the order in which they are received, or the master node 1 may also pre-execute the multiple transactions in parallel after receiving multiple transactions at the same time.
  • the master node 1 maintains the latest state set of variables (identified as the pre-execution state set hereinafter) according to the read and write operations of each transaction on the variable, and pre-executes the transaction according to the pre-execution state set.
  • a transaction Txi includes a read operation on variable A and a write operation on variable B.
  • the master node 1 pre-executes the transaction Txi and executes the read operation on the variable A, it determines whether the pre-execution state set has the value of the variable A, if not, reads the value of the variable A from the state database, and in the transaction Txi
  • the key-value pair of variable A is recorded in the pre-execution read set, and the read value of variable A is stored in the pre-execution state set.
  • variable A If the value of variable A is included in the pre-execution state set, variable A is directly read from the pre-execution state set The value of , record the key-value pair of variable A in the pre-execution read set of transaction Txi.
  • the master node 1 executes the write operation on the variable B, it records the key-value pair of the variable B in the pre-execution write set of the transaction Txi.
  • the pre-executed read-write set of the transaction Txi is obtained.
  • the master node 1 After the master node 1 completes the pre-execution of the transaction Txi, it judges whether the pre-execution read set of the transaction Txi is consistent with the variable values in the pre-execution state set. If the pre-execution transaction Txi is consistent, update the pre-execution state set according to the pre-execution read-write set of the transaction Txi, that is, update the key-value pair of variable B in the pre-execution read-write set to the pre-execution state set.
  • step S203 the master node identifies according to the pre-execution read-write set of the transaction, the previously recorded transaction (hereinafter referred to as the latest transaction) that recently updated the transaction access variable (the pre-execution state) through pre-execution before the transaction pre-execution , to generate Directed Acyclic Graph (DAG) data between transactions, indicating the chronological order in which transactions access variables.
  • DAG Directed Acyclic Graph
  • the DAG data is data used to indicate the DAG relationship between transactions, which may be in the form of graphs, tables, data, etc., which is not limited.
  • the DAG data includes the DAG table of each transaction
  • the DAG table of the transaction Txi includes the subsequent transactions and the in-degrees of the transaction Txi, wherein the subsequent transaction refers to a variable accessed through pre-execution (this variable is also a variable accessed by the transaction Txi)
  • the transaction whose chronological order is after transaction Txi is the transaction directly pointed to from transaction Txi in the DAG graph.
  • the in-degree refers to the number of transactions pointing to the transaction TXi in the DAG graph.
  • master node 1 can determine the transaction that most recently updated variable A before the pre-execution of transaction Txi according to the latest transaction index of variable A, assuming that the latest transaction is transaction Txj, then the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txj, and add 1 to the in-degree of the transaction Txi in the DAG table of the transaction Txi.
  • the master node 1 determines that there is no transaction to update the variable A before the pre-execution of the transaction Txi according to the latest transaction index of the variable A, the master node 1 can bind the latest transaction index of the variable A to the empty transaction and associate with the empty transaction Record the transaction Txi for recording that the transaction Txi reads the variable A.
  • master node 1 can determine the transaction that updated variable B before the pre-execution of transaction Txi according to the latest transaction index of variable B. Assuming that the latest transaction is Txk, master node 1 can determine Txk according to the DAG table of transaction Txk Whether there is a subsequent transaction, if there is a subsequent transaction Txm, the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txm, add 1 to the in-degree of the transaction Txi in the DAG table of the transaction Txi, and set The latest transaction index of variable B is bound to transaction Txi.
  • the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txk, and add the in-degree of the transaction Txi to the DAG table of the transaction Txk 1, and bind the latest transaction index of variable B to transaction Txi.
  • master node 1 first pre-executes transaction Tx1, which includes a read operation on variable A. After pre-executing transaction Tx1, the master node 1 sets the latest transaction of variable A as an empty transaction, and sets transaction Tx1 as the associated record of the empty transaction. Based on this, it can be concluded that the in-degree of transaction Tx1 is 0, and as shown in Table 1 Show the DAG table that records transaction Tx1:
  • the master node 1 pre-executes the transaction Tx2, and the transaction Tx2 includes a read operation on variable A and a write operation on variable B.
  • the master node 1 pre-executes and completes the transaction Tx2, according to the recent transaction indexes of variable A and variable B, it can be concluded that the latest transactions of variable A and variable B are all empty transactions, and the in-degree of transaction Tx2 can be concluded as 0.
  • master node 1 pre-executes transaction Tx3, and transaction Tx3 includes a read operation on variable A and a read operation on variable B.
  • transaction Tx3 After the master node 1 pre-executes and completes transaction Tx3, according to the latest transaction index of variable A and variable B, it can be concluded that the latest transaction of variable B is transaction Tx2. That is to say, during the pre-execution process, transaction Tx3 accesses variable B after transaction Tx2 writes variable B, so that the DAG relationship of transaction Tx2 pointing to transaction Tx3 can be recorded.
  • transaction Tx3 is recorded as a subsequent transaction, and the in-degree is added to the DAG table of transaction Tx3 by 1 to indicate the execution order of transaction Tx3 and transaction Tx2, that is, transaction Tx3 is executed after transaction Tx2.
  • master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 3:
  • the master node 1 also associates transaction Tx3 with the most recent empty transaction of the above-mentioned variable A.
  • the master node 1 pre-executes the transaction Tx4, and the transaction Tx4 includes a write operation to variable A and a read operation to variable B.
  • the related transactions of variable A’s recent empty transaction include transactions Tx1, Tx2 and Tx3, so transaction Tx4 is recorded as Tx1, Tx2 and Tx3 respectively Subsequent transactions to indicate that transaction Tx4 is executed after the execution of Tx1, Tx2 and Tx3 is completed, so as to avoid the execution results of each transaction being different from the pre-execution results due to read-write conflicts.
  • master node 1 can conclude that the latest transaction of variable B is transaction Tx2, so it records transaction Tx4 as the successor transaction of transaction Tx2. Master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 4:
  • master node 1 also binds the latest transaction index of variable A to transaction Tx4.
  • master node 1 pre-executes transaction Tx5, and transaction Tx4 includes a write operation to variable B.
  • transaction Tx5 can be recorded as the subsequent transaction of transaction Tx2 (transaction Tx3 and transaction Tx4) .
  • Master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 5:
  • master node 1 also binds the latest transaction index of variable B with transaction Tx5.
  • a DAG diagram as shown in FIG. 3 can be drawn, and the DAG diagram corresponds to the DAG data shown in Table 5.
  • step S205 the master node 1 sends the DAG data of multiple transactions to each slave node.
  • the master node 1 may pre-execute multiple transactions as described above, generate DAG data among the multiple transactions, and send the DAG data of the multiple transactions to each slave node as a consensus proposal. Master node 1 can also send multiple received transactions to each slave node. It can be understood that each slave node may also receive multiple transactions from other slave nodes or clients. Each slave node may also receive the DAG data of the plurality of transactions from other slave nodes.
  • the master node 1 can also generate an executable transaction set with an in-degree of 0 according to the DAG data, and send the transaction set to each slave node together.
  • master node 1 sends the DAG data shown in Table 5 to each slave node
  • master node 1 can obtain an executable transaction set including transaction Tx1 and transaction Tx2 according to the DAG data, and send the executable transaction set to each slave node slave node.
  • the master node 1 can also only send the DAG data of multiple transactions to each slave node, and each slave node can generate an executable transaction set according to the DAG data.
  • step S207 the slave node executes the transaction based on the DAG data.
  • the slave node 2 After the slave node 2 obtains the executable transaction set based on the DAG data, it first executes the transactions in the executable transaction set. Since the in-degrees of the transactions in the executable transaction set are all zero, that is, their execution will not conflict with other transactions, therefore, the master node 1 can execute multiple transactions in the executable transaction set in parallel.
  • the executable transaction set initially includes transaction Tx1 and transaction Tx2 .
  • Slave node 2 can execute transaction Tx1 and transaction Tx2 in parallel. After the slave node 2 completes the execution of the transaction Tx1, it can subtract 1 from the in-degree in the DAG table of the transaction Tx4. After the slave node 2 completes the execution of the transaction Tx2, the in-degrees of the transaction Tx3 and the transaction Tx4 can be respectively reduced by 1 in the DAG table, so that the in-degrees of the transaction Tx3 become 0. At this time, the slave node 2 can The transaction Tx3 is put into the executable transaction set, that is, the slave node 2 can execute the transaction Tx3.
  • slave node 2 After completing the execution of transaction Tx3, slave node 2 will decrease the in-degrees of transaction Tx4 and transaction Tx5 by 1, so that the in-degrees of transaction Tx4 will become 0. Similarly, slave node 2 can put transaction Tx4 into the executable transaction set middle.
  • Fig. 4 is an architecture diagram of a block chain master node in an embodiment of this specification, including:
  • the pre-execution unit 41 is configured to pre-execute the received first transaction, generate a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
  • the generation unit 42 is configured to generate DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the pre-execution The most recent transaction before the first transaction that updates the pre-execution state of the first variable after pre-execution, and the DAG data indicates the chronological order in which the first transaction and the second transaction access the first variable ;
  • a sending unit 43 configured to send the DAG data to the slave nodes of the block chain.
  • the pre-execution unit is specifically configured to pre-execute the received first transaction based on the pre-execution state set, and after the pre-execution completes the first transaction, based on the pre-execution read of the first transaction A write set updates the pre-execution state set.
  • the DAG data includes DAG tables of multiple transactions that have been pre-executed, and the DAG table of each transaction includes the number of subsequent transactions and inbound transactions of the transaction in the DAG graph.
  • the pre-execution read-write set includes a read operation on the first variable
  • the generation unit 42 is specifically configured to: add the first transaction to the DAG table of the second transaction Recording as a subsequent transaction of the second transaction, adding 1 to the in-degree of the first transaction in the DAG table of the first transaction.
  • the pre-execution read-write set includes a write operation on the first variable
  • the generating unit 42 is specifically configured to: read the DAG table of the second transaction, and in the second Where the transaction has a subsequent fourth transaction, record the first transaction as the successor transaction of the fourth transaction in the DAG table of the fourth transaction, and record all the subsequent transactions in the DAG table of the first transaction
  • the in-degree of the first transaction is increased by 1, and the first transaction is recorded as the transaction for which the first variable is updated most recently.
  • the generating unit 42 is specifically configured to: record the first transaction as the second transaction in the DAG table of the second transaction when the second transaction has no subsequent transaction For the subsequent transaction of the second transaction, add 1 to the in-degree of the first transaction in the DAG table of the first transaction, and record the first transaction as the transaction that most recently updated the first variable.
  • the master node further includes: an acquisition unit (not shown), configured to acquire a first set according to the respective DAG tables of the multiple transactions, and the first set includes the multiple transactions with zero in-degree,
  • the sending unit 43 is further configured to send the first set to the slave node.
  • Fig. 5 is an architecture diagram of a block chain slave node in an embodiment of this specification, including:
  • a receiving unit 51 configured to receive DAG data from the master node of the blockchain, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable;
  • An execution unit 52 configured to execute the first transaction and the second transaction based on the DAG data.
  • the slave node can execute the transactions without conflicts in parallel according to the DAG data generated by the master node, and the transactions with conflicts can be executed according to the order in the DAG data Execution, thereby improving the efficiency of transaction execution.
  • the improvement of a technology can be clearly distinguished as an improvement in hardware (for example, improvements in circuit structures such as diodes, transistors, and switches) or improvements in software (improvement in method flow).
  • improvements in circuit structures such as diodes, transistors, and switches
  • improvements in software improvement in method flow
  • the improvement of many current method flows can be regarded as the direct improvement of the hardware circuit structure.
  • Designers almost always get the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be realized by hardware physical modules.
  • a programmable logic device Programmable Logic Device, PLD
  • PLD Programmable Logic Device
  • FPGA Field Programmable Gate Array
  • HDL Hardware Description Language
  • ABEL Advanced Boolean Expression Language
  • AHDL Altera Hardware Description Language
  • HDCal JHDL
  • Lava Lava
  • Lola MyHDL
  • PALASM RHDL
  • VHDL Very-High-Speed Integrated Circuit Hardware Description Language
  • Verilog Verilog
  • the controller may be implemented in any suitable way, for example the controller may take the form of a microprocessor or processor and a computer readable medium storing computer readable program code (such as software or firmware) executable by the (micro)processor , logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers and embedded microcontrollers, examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory.
  • controller in addition to realizing the controller in a purely computer-readable program code mode, it is entirely possible to make the controller use logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded The same function can be realized in the form of a microcontroller or the like. Therefore, such a controller can be regarded as a hardware component, and the devices included in it for realizing various functions can also be regarded as structures within the hardware component. Or even, means for realizing various functions can be regarded as a structure within both a software module realizing a method and a hardware component.
  • the systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions.
  • a typical implementation device is a server system.
  • the computer that realizes the functions of the above embodiments can be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant , media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.
  • one or more embodiments of the present specification provide the operation steps of the method described in the embodiment or the flowchart, more or fewer operation steps may be included based on conventional or non-inventive means.
  • the sequence of steps enumerated in the embodiments is only one of the execution sequences of many steps, and does not represent the only execution sequence.
  • the methods shown in the embodiments or drawings can be executed sequentially or in parallel (such as a parallel processor or multi-thread processing environment, or even a distributed data processing environment).
  • These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions
  • the device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information.
  • 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 Disc (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 computing devices.
  • computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
  • one or more embodiments of this specification 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 employ a computer program embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. The form of the product.
  • program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types.
  • program modules may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network.
  • program modules may be located in both local and remote computer storage media including storage devices.

Abstract

A method for executing a transaction in a blockchain, a blockchain, a master node, and a slave node. The method comprises: a main node pre-executes a received first transaction to generate a pre-execution read-write set of the first transaction, wherein the pre-execution read-write set comprises access to a first variable; the master node generates DAG data according to the pre-execution read-write set of the first transaction and an identifier of a previously recorded second transaction which most recently updates the first variable, wherein the second transaction is the transaction which most recently updates a pre-execution state of the first variable after pre-execution before the first transaction is pre-executed, wherein the DAG data indicates a time sequence in which the first transaction and the second transaction access the first variable; the master node sends the DAG data to a slave node; and the slave node executes the first transaction and the second transaction on the basis of the DAG data.

Description

执行交易的方法、区块链、主节点和从节点Method of executing transactions, blockchain, master and slave nodes
本申请要求于2022年02月25日提交中国国家知识产权局、申请号为202210181705.2、申请名称为“执行交易的方法、区块链、主节点和从节点”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed with the State Intellectual Property Office of China on February 25, 2022, with the application number 202210181705.2, and the application title is "method for executing transactions, blockchain, master node and slave node", which The entire contents are incorporated by reference in this application.
技术领域technical field
本说明书实施例属于区块链技术领域,尤其涉及一种在区块链中执行交易的方法、区块链、主节点和从节点。The embodiments of this specification belong to the technical field of block chain, and in particular relate to a method for executing transactions in the block chain, the block chain, a master node and a slave node.
背景技术Background technique
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链系统中按照时间顺序将数据区块以顺序相连的方式组合成链式数据结构,并以密码学方式保证的不可篡改和不可伪造的分布式账本。由于区块链具有去中心化、信息不可篡改、自治性等特性,区块链也受到人们越来越多的重视和应用。然而,由于调用智能合约的交易在执行前不能预知访问的变量,因此通常不能并行执行。Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. In the blockchain system, the data blocks are combined into a chained data structure in a sequentially connected manner in chronological order, and a non-tamperable and unforgeable distributed ledger is cryptographically guaranteed. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application. However, since the variables accessed cannot be predicted before the transactions calling smart contracts are executed, they usually cannot be executed in parallel.
发明内容Contents of the invention
本发明的目的在于提供一种在区块链中执行交易的方法,使得可以区块链中的从节点可根据主节点的共识提议并行执行交易。The purpose of the present invention is to provide a method for executing transactions in the block chain, so that the slave nodes in the block chain can execute transactions in parallel according to the consensus proposal of the master node.
本说明书第一方面提供一种在区块链中执行交易的方法,所述区块链包括主节点和从节点,所述方法包括:The first aspect of this specification provides a method for executing a transaction in a blockchain, the blockchain includes a master node and a slave node, and the method includes:
所述主节点预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;The master node pre-executes the received first transaction, and generates a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;The master node generates DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the The most recent transaction before the first transaction updates the pre-execution state of the first variable after pre-execution, and the DAG data indicates the time sequence in which the first transaction and the second transaction access the first variable;
所述主节点将所述DAG数据发送给所述从节点;The master node sends the DAG data to the slave node;
所述从节点基于所述DAG数据执行所述第一交易和所述第二交易。The slave node executes the first transaction and the second transaction based on the DAG data.
本说明书第二方面提供一种区块链,所述区块链包括主节点和从节点,The second aspect of this specification provides a blockchain, the blockchain includes a master node and a slave node,
所述主节点用于:预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;将所述DAG数据发送给所述从节点;The master node is used to: pre-execute the received first transaction, generate a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable; The pre-execution read-write set, the identification of the second transaction that most recently updated the first variable recorded earlier, generates DAG data, and the second transaction is the most recent post-pre-execution update before the pre-execution of the first transaction A transaction in the pre-execution state of the first variable, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable; sending the DAG data to the slave node;
所述从节点用于基于所述DAG数据执行所述第一交易和所述第二交易。The slave node is configured to execute the first transaction and the second transaction based on the DAG data.
本说明书第三方面提供一种区块链主节点,包括:The third aspect of this specification provides a block chain master node, including:
预执行单元,用于预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;A pre-execution unit, configured to pre-execute the received first transaction, and generate a pre-execution read-write set of the first transaction, the pre-execution read-write set includes access to the first variable;
生成单元,用于根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;A generation unit, configured to generate DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the pre-execution A transaction that updates the pre-execution state of the first variable after pre-execution, the most recent before the first transaction, and the DAG data indicates the time sequence in which the first transaction and the second transaction access the first variable;
发送单元,用于将所述DAG数据发送给所述区块链的从节点。A sending unit, configured to send the DAG data to the slave nodes of the block chain.
本说明书第四方面提供一种区块链从节点,包括:The fourth aspect of this specification provides a blockchain slave node, including:
接收单元,用于从所述区块链的主节点接收DAG数据,所述DAG数据指示第一交易和第二交易访问第一变量的时间顺序;a receiving unit, configured to receive DAG data from the master node of the blockchain, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable;
执行单元,用于基于所述DAG数据执行所述第一交易和所述第二交易。An execution unit, configured to execute the first transaction and the second transaction based on the DAG data.
通过本说明书实施例提供的在区块链中执行交易的方案,从节点根据主节点生成的DAG数据,对于没有冲突的交易可以并行执行,对于有冲突的交易可根据DAG数据中的先后顺序先后执行,从而提高了交易执行效率。Through the scheme of executing transactions in the blockchain provided by the embodiment of this specification, the slave node can execute the transactions without conflicts in parallel according to the DAG data generated by the master node, and the transactions with conflicts can be executed according to the order in the DAG data Execution, thereby improving the efficiency of transaction execution.
附图说明Description of drawings
为了更清楚地说明本说明书实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以 根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following will briefly introduce the drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments recorded in this specification. , for those skilled in the art, other drawings can also be obtained according to these drawings without paying creative labor.
图1为本说明书实施例所应用的区块链架构图;FIG. 1 is a block chain architecture diagram applied in the embodiment of this specification;
图2为本说明书一实施例中的在区块链中执行交易的方法流程图;FIG. 2 is a flow chart of a method for executing a transaction in a blockchain in an embodiment of this specification;
图3为本说明书一实施例中的DAG图;Fig. 3 is a DAG diagram in an embodiment of this specification;
图4为本说明书一实施例中的一种区块链主节点的架构图;FIG. 4 is an architecture diagram of a block chain master node in an embodiment of this specification;
图5为本说明书一实施例中的一种区块链从节点的架构图。Fig. 5 is an architecture diagram of a block chain slave node in an embodiment of this specification.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本说明书中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本说明书保护的范围。In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described The embodiments are only some of the embodiments in this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.
图1示出本说明书实施例所应用的区块链架构图。如图1中,区块链中例如包含主节点1、从节点2~从节点6共6个节点。节点之间的连线示意性的表示P2P(Peer to Peer,点对点)连接。这些节点上都存储全量的账本,即存储全部区块和全部账户的状态。其中,区块链中的每个节点通过执行相同的交易而产生区块链中的相同的状态,区块链中的每个节点存储相同的状态数据库。所不同的是,主节点1可负责从客户端接收交易,并向各个从节点发起共识提议,该共识提议中例如包括将要成块的区块(例如区块B1)中的多个交易及各个交易的提交顺序等信息。在区块链中的节点对共识提议共识成功之后,各个节点可根据共识提议中的提交顺序执行该多个交易,从而生成区块B1。Fig. 1 shows a block chain architecture diagram applied in the embodiment of this specification. As shown in FIG. 1 , the blockchain includes, for example, 6 nodes including a master node 1, a slave node 2 to a slave node 6. The connection between nodes schematically represents a P2P (Peer to Peer, point-to-point) connection. These nodes store a full amount of books, that is, store the status of all blocks and all accounts. Wherein, each node in the blockchain generates the same state in the blockchain by executing the same transaction, and each node in the blockchain stores the same state database. The difference is that the master node 1 can be responsible for receiving transactions from the client, and initiate a consensus proposal to each slave node. The consensus proposal includes, for example, multiple transactions in the block to be formed (such as block B1) and each Information such as the order in which transactions are submitted. After the nodes in the blockchain successfully reach consensus on the consensus proposal, each node can execute the multiple transactions according to the order of submission in the consensus proposal, thereby generating block B1.
可以理解,图1所示的区块链仅仅是示例性的,本说明书实施例不限于应用于图1所示的区块链,例如还可以应用于包括分片的区块链系统中。It can be understood that the block chain shown in FIG. 1 is only exemplary, and the embodiment of this description is not limited to be applied to the block chain shown in FIG. 1 , for example, it can also be applied to a block chain system including sharding.
另外,图1中虽然示出了区块链中包括6个节点,本说明书实施例不限于此,而是可以包括其他数目的节点。具体是,区块链中包含的节点可以满足拜占庭容错(Byzantine Fault Tolerance,BFT)要求。所述的拜占庭容错要求可以理解为在区块链内部可以存在拜占庭节点,而区块链对外不体现拜占庭行为。一般的,一些拜占庭容错算法中要求节点个数大于3f+1,f为拜占庭节点个数,例如实用拜占庭容错算法PBFT(Practical Byzantine Fault Tolerance)。In addition, although it is shown in FIG. 1 that the block chain includes 6 nodes, the embodiment of this specification is not limited thereto, but may include other numbers of nodes. Specifically, the nodes contained in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements. The Byzantine fault tolerance requirement can be understood as that there may be Byzantine nodes inside the blockchain, but the blockchain does not reflect Byzantine behavior externally. 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).
区块链领域中的交易可以指在区块链中执行并记录在区块链中的任务单元。交易中通常包括发送字段(From)、接收字段(To)和数据字段(Data)。其中,在交易为转账交易的情况中,From字段表示发起该交易(即发起对另一个账户的转账任务)的账户地址,To字段表示接收该交易(即接收转账)的账户地址,Data字段中包括转账金额。在交易调用区块链中的智能合约的情况中,From字段表示发起该交易的账户地址,To字段表示交易所调用的合约的账户地址,Data字段中包括调用合约中的函数名、及对该函数的传入参数等数据,以用于在交易执行时从区块链中获取该函数的代码并执行该函数的代码。A transaction in the blockchain field may refer to a unit of tasks performed and recorded in the blockchain. A transaction usually includes a sending field (From), a receiving field (To) and a data field (Data). Among them, when the transaction is a transfer transaction, the From field indicates the account address that initiated the transaction (that is, initiates a transfer task to another account), the To field indicates the account address that received the transaction (that is, received the transfer), and the Data field Include the transfer amount. In the case of a transaction calling a smart contract in the blockchain, the From field indicates the account address that initiated the transaction, the To field indicates the account address of the contract called by the transaction, and the Data field includes the function name in the calling contract, and the Data such as the incoming parameters of the function are used to obtain the code of the function from the blockchain and execute the code of the function when the transaction is executed.
区块链中可提供智能合约的功能。区块链上的智能合约是在区块链系统上可以被交易触发执行的合约。智能合约可以通过代码的形式定义。在以太坊中调用智能合约,是发起一笔指向智能合约地址的交易,使得以太坊网络中每个节点分布式地运行智能合约代码。需要说明的是,除了可以由用户创建智能合约,也可以在创世块中由系统设置智能合约。这类合约一般称为创世合约。一般的,创世合约中可以设置一些区块链的数据结构、参数、属性和方法。此外,具有系统管理员权限的账户可以创建系统级的合约,或者修改系统级的合约(简称为系统合约)。其中,所述系统合约可用于在区块链中增加不同业务的数据的数据结构。The function of smart contracts can be provided in the blockchain. Smart contracts on the blockchain are contracts that can be triggered by transactions on the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract in Ethereum is to initiate a transaction pointing to the address of the smart contract, so that each node in the Ethereum network runs the smart contract code in a distributed manner. It should be noted that in addition to creating smart contracts by users, smart contracts can also be set by the system in the genesis block. This type of contract is generally called a genesis contract. Generally, some blockchain data structures, parameters, attributes and methods can be set in the genesis contract. In addition, accounts with system administrator privileges can create system-level contracts or modify system-level contracts (referred to as system contracts). Wherein, the system contract can be used to add data structures of different business data in the blockchain.
在部署合约的场景中,例如,Bob将一个包含创建智能合约信息(即部署合约)的交易发送到如图1所示的区块链中,该交易的data字段包括待创建的合约的代码(如字节码或者机器码),交易的to字段为空,以表示该交易用于部署合约。节点间通过共识机制达成一致后,确定合约的合约地址“0x6f8ae93…”,各个节点在状态数据库中添加与该智能合约的合约地址对应的合约账户,分配与该合约账户对应的状态存储,并将合约代码保存在该合约的状态存储中,从而合约创建成功。In the scenario of deploying a contract, for example, Bob sends a transaction containing information about creating a smart contract (that is, deploying a contract) to the blockchain shown in Figure 1, and the data field of the transaction includes the code of the contract to be created ( Such as bytecode or machine code), the to field of the transaction is empty to indicate that the transaction is used to deploy the contract. After the nodes reach an agreement through the consensus mechanism, determine the contract address "0x6f8ae93...", each node adds the contract account corresponding to the contract address of the smart contract in the state database, allocates the state storage corresponding to the contract account, and The contract code is saved in the state storage of the contract, so the contract is created successfully.
在调用合约的场景中,例如,Bob将一个用于调用智能合约的交易发送到如图1所示的区块链中,该交易的from字段是交易发起方(即Bob)的账户的地址,to字段中的“0x6f8ae93…”代表了被调用的智能合约的地址,交易的data字段包括调用智能合约的方法和参数。在区块链中对该交易进行共识之后,区块链中的各个节点可分别执行该交易,从而分别执行该合约,基于该合约的执行更新状态数据库。In the scenario of calling the contract, for example, Bob sends a transaction for calling the smart contract to the blockchain shown in Figure 1, the from field of the transaction is the address of the account of the transaction initiator (ie Bob), "0x6f8ae93..." in the to field represents the address of the called smart contract, and the data field of the transaction includes the method and parameters of calling the smart contract. After consensus is reached on the transaction in the blockchain, each node in the blockchain can respectively execute the transaction, thereby respectively executing the contract, and updating the state database based on the execution of the contract.
在相关技术中,为了提高区块链中的每秒执行交易(TPS)指标,需要加快交易的执行速度。为此,区块链节点中可通过并行执行交易来加快交易的执行速度。在一种实施方式中,区块链节点可通过单机中的多个进程并行执行交易,在另一种实施方式 中,区块链节点可部署在服务器集群中,通过多台服务器并行执行交易。通常,对于转账交易,区块链节点首先根据交易访问的账户将多个交易划分为多个交易组,各个交易组之间不访问相同的账户,从而可并行执行各个交易组。然而,当交易中调用智能合约时,在执行该交易之前不能预知该交易中访问的变量,从而无法对多个交易进行有效的分组,也就无法并行执行交易。In related technologies, in order to improve the transaction per second (TPS) indicator in the blockchain, it is necessary to accelerate the execution speed of transactions. To this end, transactions can be executed in parallel in blockchain nodes to speed up transaction execution. In one implementation, the blockchain node can execute transactions in parallel through multiple processes in a single machine. In another implementation, the blockchain node can be deployed in a server cluster and execute transactions in parallel through multiple servers. Usually, for transfer transactions, blockchain nodes first divide multiple transactions into multiple transaction groups according to the accounts accessed by the transactions, and each transaction group does not access the same account, so that each transaction group can be executed in parallel. However, when a smart contract is called in a transaction, the variables accessed in the transaction cannot be predicted before the transaction is executed, so multiple transactions cannot be effectively grouped, and transactions cannot be executed in parallel.
在另一种相关技术中,可由主节点执行交易,并将执行结果发送给从节点进行验证,为了加速验证阶段,主节点会在执行时仅打包无冲突的交易,将有冲突的交易推迟到下一个区块打包,这样从节点可以实现并发验证。然而,在该方式中,当交易间的冲突率较高时,这些交易会被放到不同的区块中,降低了系统性能,增大了存储成本。In another related technology, the master node can execute the transaction and send the execution result to the slave node for verification. In order to speed up the verification phase, the master node will only package non-conflicting transactions during execution and postpone conflicting transactions to The next block is packed so that slave nodes can achieve concurrent verification. However, in this method, when the conflict rate between transactions is high, these transactions will be placed in different blocks, which reduces system performance and increases storage costs.
图2为本说明书一实施例中的在区块链中执行交易的方法流程图,该方法可由图1所示的主节点和各个从节点执行,图2中示出主节点1和从节点2作为示例,可以理解,区块链中的其他从节点进行与从节点2相同的操作。Fig. 2 is a flow chart of a method for executing a transaction in a block chain in an embodiment of this specification, the method can be executed by the master node and each slave node shown in Fig. 1, and master node 1 and slave node 2 are shown in Fig. 2 As an example, it is understood that other slave nodes in the blockchain perform the same operations as slave node 2.
如图2所示,在步骤S201,主节点预执行接收的交易,生成交易的预执行读写集。As shown in FIG. 2 , in step S201 , the master node pre-executes the received transaction and generates a pre-execution read-write set of the transaction.
所述预执行是指主节点在进行共识提议前对交易的执行。在进行共识提议之前,主节点1还未设置各个交易的提交顺序,主节点1可按照任意顺序进行对交易的预执行。例如,主节点1可按照接收各个交易的先后顺序预执行接收的各个交易,或者主节点1也可以在同时接收到多个交易之后,并行预执行该多个交易。The pre-execution refers to the execution of the transaction by the master node before making a consensus proposal. Before the consensus proposal, the master node 1 has not set the submission order of each transaction, and the master node 1 can pre-execute the transactions in any order. For example, the master node 1 may pre-execute the received transactions in the order in which they are received, or the master node 1 may also pre-execute the multiple transactions in parallel after receiving multiple transactions at the same time.
主节点1在预执行交易的过程中根据各个交易对变量的读写操作维护变量最新状态集(下文标识为预执行状态集),并根据预执行状态集预执行交易。In the process of pre-executing the transaction, the master node 1 maintains the latest state set of variables (identified as the pre-execution state set hereinafter) according to the read and write operations of each transaction on the variable, and pre-executes the transaction according to the pre-execution state set.
例如,交易Txi中包括对变量A的读操作和对变量B的写操作。主节点1在预执行交易Txi时,在执行对变量A的读操作时,确定预执行状态集是否有变量A的值,如果没有则从状态数据库中读取变量A的值,在交易Txi的预执行读集中记录变量A的键值对,并在预执行状态集中存储该读取的变量A的值,如果预执行状态集中包括变量A的值,则直接从预执行状态集中读取变量A的值,在交易Txi的预执行读集中记录变量A的键值对。主节点1在执行对变量B的写操作时,在交易Txi的预执行写集中记录变量B的键值对。从而得到交易Txi的预执行读写集。For example, a transaction Txi includes a read operation on variable A and a write operation on variable B. When the master node 1 pre-executes the transaction Txi and executes the read operation on the variable A, it determines whether the pre-execution state set has the value of the variable A, if not, reads the value of the variable A from the state database, and in the transaction Txi The key-value pair of variable A is recorded in the pre-execution read set, and the read value of variable A is stored in the pre-execution state set. If the value of variable A is included in the pre-execution state set, variable A is directly read from the pre-execution state set The value of , record the key-value pair of variable A in the pre-execution read set of transaction Txi. When the master node 1 executes the write operation on the variable B, it records the key-value pair of the variable B in the pre-execution write set of the transaction Txi. Thus, the pre-executed read-write set of the transaction Txi is obtained.
主节点1在完成对交易Txi的预执行之后,判断交易Txi的预执行读集与预执行状态集中的变量值是否一致,如果不一致说明交易Txi与其他在先预执行的交易存在冲突,则重新预执行交易Txi,如果一致,则根据交易Txi的预执行读写集更新预执行状态集, 即将预执行读写集中的变量B的键值对更新到预执行状态集中。After the master node 1 completes the pre-execution of the transaction Txi, it judges whether the pre-execution read set of the transaction Txi is consistent with the variable values in the pre-execution state set. If the pre-execution transaction Txi is consistent, update the pre-execution state set according to the pre-execution read-write set of the transaction Txi, that is, update the key-value pair of variable B in the pre-execution read-write set to the pre-execution state set.
在步骤S203,主节点根据交易的预执行读写集、在先记录的在该交易预执行之前通过预执行最近更新该交易访问变量(的预执行状态)的交易(下文以最近交易表示)标识,生成交易之间的有向无环图(Directed Acyclic Graph,DAG)数据,指示交易访问变量的时间顺序。In step S203, the master node identifies according to the pre-execution read-write set of the transaction, the previously recorded transaction (hereinafter referred to as the latest transaction) that recently updated the transaction access variable (the pre-execution state) through pre-execution before the transaction pre-execution , to generate Directed Acyclic Graph (DAG) data between transactions, indicating the chronological order in which transactions access variables.
所述DAG数据为用于指示交易之间的DAG关系的数据,其可以为图形形式、表格形式、数据形式等,对此不作限定。例如,该DAG数据包括各个交易的DAG表,交易Txi的DAG表中包括交易Txi的后继交易和入度数,其中,后继交易是指通过预执行访问变量(该变量也为交易Txi访问的变量)的时间顺序在交易Txi之后的交易,在DAG图中为从交易Txi所直接指向的交易。入度数是指在DAG图中指向交易TXi的交易数目。The DAG data is data used to indicate the DAG relationship between transactions, which may be in the form of graphs, tables, data, etc., which is not limited. For example, the DAG data includes the DAG table of each transaction, and the DAG table of the transaction Txi includes the subsequent transactions and the in-degrees of the transaction Txi, wherein the subsequent transaction refers to a variable accessed through pre-execution (this variable is also a variable accessed by the transaction Txi) The transaction whose chronological order is after transaction Txi is the transaction directly pointed to from transaction Txi in the DAG graph. The in-degree refers to the number of transactions pointing to the transaction TXi in the DAG graph.
具体是,主节点1在预执行完成交易Txi之后,对于变量A,主节点1可根据变量A的最近交易索引确定在交易Txi的预执行之前最近更新变量A的交易,假设该最近交易为交易Txj,则主节点1可在交易Txj的DAG表中将交易Txi记录为后继交易,在交易Txi的DAG表中将交易Txi的入度数加1。如果主节点1根据变量A的最近交易索引确定在交易Txi的预执行之前没有更新变量A的交易,则主节点1可将变量A的最近交易索引与空交易绑定,并与该空交易关联地记录该交易Txi,以用于记录交易Txi读取了变量A。Specifically, after master node 1 pre-executes transaction Txi, for variable A, master node 1 can determine the transaction that most recently updated variable A before the pre-execution of transaction Txi according to the latest transaction index of variable A, assuming that the latest transaction is transaction Txj, then the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txj, and add 1 to the in-degree of the transaction Txi in the DAG table of the transaction Txi. If the master node 1 determines that there is no transaction to update the variable A before the pre-execution of the transaction Txi according to the latest transaction index of the variable A, the master node 1 can bind the latest transaction index of the variable A to the empty transaction and associate with the empty transaction Record the transaction Txi for recording that the transaction Txi reads the variable A.
对于变量B,主节点1可根据变量B的最近交易索引确定在交易Txi的预执行之前最近更新变量B的交易,假设该最近交易为Txk,则主节点1可根据交易Txk的DAG表确定Txk是否有后继交易,如果有后继交易Txm,则主节点1可在交易Txm的DAG表中将交易Txi记录为后继交易,在在交易Txi的DAG表中将交易Txi的入度数加1,并将变量B的最近交易索引与交易Txi绑定。如果主节点1根据交易Txk的DAG表确定Txk没有后继交易,则主节点1可在交易Txk的DAG表中将交易Txi记录为后继交易,在交易Txi的DAG表中将交易Txi的入度数加1,并将变量B的最近交易索引与交易Txi绑定。For variable B, master node 1 can determine the transaction that updated variable B before the pre-execution of transaction Txi according to the latest transaction index of variable B. Assuming that the latest transaction is Txk, master node 1 can determine Txk according to the DAG table of transaction Txk Whether there is a subsequent transaction, if there is a subsequent transaction Txm, the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txm, add 1 to the in-degree of the transaction Txi in the DAG table of the transaction Txi, and set The latest transaction index of variable B is bound to transaction Txi. If the master node 1 determines that Txk has no subsequent transaction according to the DAG table of the transaction Txk, the master node 1 can record the transaction Txi as a subsequent transaction in the DAG table of the transaction Txk, and add the in-degree of the transaction Txi to the DAG table of the transaction Txk 1, and bind the latest transaction index of variable B to transaction Txi.
在一个实例中,主节点1首先预执行交易Tx1,该交易Tx1包括对变量A的读操作。主节点1在预执行完成交易Tx1之后,设置变量A的最近交易为空交易,并将交易Tx1为该空交易关联记录,据此可得出交易Tx1的入度数为0,并如表1所示记录交易Tx1的DAG表:In one example, master node 1 first pre-executes transaction Tx1, which includes a read operation on variable A. After pre-executing transaction Tx1, the master node 1 sets the latest transaction of variable A as an empty transaction, and sets transaction Tx1 as the associated record of the empty transaction. Based on this, it can be concluded that the in-degree of transaction Tx1 is 0, and as shown in Table 1 Show the DAG table that records transaction Tx1:
交易trade 后继交易Subsequent transaction 入度数In-degree
Tx1Tx1 {}{} 00
表1Table 1
其中,表1中的“{}”表示Tx1的后继交易集合为空集,即没有后继交易。Wherein, "{}" in Table 1 indicates that the subsequent transaction set of Tx1 is an empty set, that is, there is no subsequent transaction.
之后,主节点1预执行交易Tx2,交易Tx2包括对变量A的读操作和对变量B的写操作。主节点1在预执行完成交易Tx2之后,根据变量A和变量B的最近交易索引可得出变量A和变量B的最近交易都是空交易,据此可得出交易Tx2的入度数为0,并将交易Tx2与上述变量A的最近空交易关联记录,将交易Tx2记录为变量B的最近交易,并如表2所示记录当前已预执行完成的交易的DAG表:Afterwards, the master node 1 pre-executes the transaction Tx2, and the transaction Tx2 includes a read operation on variable A and a write operation on variable B. After the master node 1 pre-executes and completes the transaction Tx2, according to the recent transaction indexes of variable A and variable B, it can be concluded that the latest transactions of variable A and variable B are all empty transactions, and the in-degree of transaction Tx2 can be concluded as 0. And record transaction Tx2 with the latest empty transaction of the above variable A, record transaction Tx2 as the latest transaction of variable B, and record the DAG table of the currently pre-executed completed transaction as shown in Table 2:
交易trade 后继交易Subsequent transaction 入度数In-degree
Tx1Tx1 {}{} 00
Tx2Tx2 {}{} 00
表2Table 2
之后,主节点1预执行交易Tx3,交易Tx3包括对变量A的读操作和对变量B的读操作。主节点1在预执行完成交易Tx3之后,根据变量A和变量B的最近交易索引可得出变量B的最近交易为交易Tx2。也就是说在预执行过程中,交易Tx3在交易Tx2写入变量B之后访问变量B,据此可记录交易Tx2指向交易Tx3的DAG关系,例如在DAG图中可通过箭头记录,或者可在交易Tx2的DAG表中将交易Tx3记录为后继交易,并在交易Tx3的DAG表中将入度数加1,以指示交易Tx3与交易Tx2的执行顺序,即交易Tx3在交易Tx2之后执行。例如,主节点1可如表3所示记录当前已预执行完成的交易的DAG表:Afterwards, master node 1 pre-executes transaction Tx3, and transaction Tx3 includes a read operation on variable A and a read operation on variable B. After the master node 1 pre-executes and completes transaction Tx3, according to the latest transaction index of variable A and variable B, it can be concluded that the latest transaction of variable B is transaction Tx2. That is to say, during the pre-execution process, transaction Tx3 accesses variable B after transaction Tx2 writes variable B, so that the DAG relationship of transaction Tx2 pointing to transaction Tx3 can be recorded. In the DAG table of Tx2, transaction Tx3 is recorded as a subsequent transaction, and the in-degree is added to the DAG table of transaction Tx3 by 1 to indicate the execution order of transaction Tx3 and transaction Tx2, that is, transaction Tx3 is executed after transaction Tx2. For example, master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 3:
交易trade 后继交易Subsequent transaction 入度数In-degree
Tx1Tx1 {}{} 00
Tx2Tx2 {Tx3}{Tx3} 00
Tx3Tx3 {}{} 11
表3table 3
通过如此记录交易Tx2与交易Tx3的DAG关系,并在执行交易时按照该DAG关系指示的执行顺序执行交易Tx2和交易Tx3,使得在执行交易Tx2和交易Tx3时的状态变化与预执行时一致,从而维持了各个交易之间的DAG关系的正确性,而根据该DAG关系可并行执行入度为零的多个交易,提高了交易的执行效率。By recording the DAG relationship between transaction Tx2 and transaction Tx3 in this way, and executing the transaction Tx2 and transaction Tx3 according to the execution sequence indicated by the DAG relationship when executing the transaction, so that the state changes when executing transaction Tx2 and transaction Tx3 are consistent with the pre-execution, Therefore, the correctness of the DAG relationship among the various transactions is maintained, and multiple transactions with an in-degree of zero can be executed in parallel according to the DAG relationship, thereby improving the execution efficiency of the transactions.
同时,主节点1还将交易Tx3与上述变量A的最近空交易关联记录。At the same time, the master node 1 also associates transaction Tx3 with the most recent empty transaction of the above-mentioned variable A.
之后,主节点1预执行交易Tx4,交易Tx4包括对变量A的写操作和对变量B的读操作。主节点1在预执行完成交易Tx4之后,根据变量A的最近交易索引可得出变量A的最近空交易的关联交易包括交易Tx1、Tx2和Tx3,因此将交易Tx4记录为Tx1、Tx2和Tx3各自的 后继交易,以指示在执行完成Tx1、Tx2和Tx3之后再执行交易Tx4,从而避免因读写冲突使得各个交易的执行结果与预执行结果不同。主节点1根据变量B的最近交易索引可得出变量B的最近交易为交易Tx2,因此将交易Tx4记录为交易Tx2的后继交易。主节点1可如表4所示记录当前已预执行完成的交易的DAG表:Afterwards, the master node 1 pre-executes the transaction Tx4, and the transaction Tx4 includes a write operation to variable A and a read operation to variable B. After master node 1 pre-executes and completes transaction Tx4, according to the latest transaction index of variable A, it can be concluded that the related transactions of variable A’s recent empty transaction include transactions Tx1, Tx2 and Tx3, so transaction Tx4 is recorded as Tx1, Tx2 and Tx3 respectively Subsequent transactions to indicate that transaction Tx4 is executed after the execution of Tx1, Tx2 and Tx3 is completed, so as to avoid the execution results of each transaction being different from the pre-execution results due to read-write conflicts. According to the latest transaction index of variable B, master node 1 can conclude that the latest transaction of variable B is transaction Tx2, so it records transaction Tx4 as the successor transaction of transaction Tx2. Master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 4:
交易trade 后继交易Subsequent transaction 入度数In-degree
Tx1Tx1 {Tx4}{Tx4} 00
Tx2Tx2 {Tx3,Tx4}{Tx3,Tx4} 00
Tx3Tx3 {Tx4}{Tx4} 11
Tx4Tx4 {}{} 33
表4Table 4
同时,主节点1还将变量A的最近交易索引与交易Tx4绑定。At the same time, master node 1 also binds the latest transaction index of variable A to transaction Tx4.
之后,主节点1预执行交易Tx5,交易Tx4包括对变量B的写操作。主节点1在预执行完成交易Tx5之后,根据变量A的最近交易索引可得出变量B的最近交易为Tx2,因此可将交易Tx5记录为交易Tx2后继交易(交易Tx3和交易Tx4)的后继交易。主节点1可如表5所示记录当前已预执行完成的交易的DAG表:Afterwards, master node 1 pre-executes transaction Tx5, and transaction Tx4 includes a write operation to variable B. After the master node 1 pre-executes and completes transaction Tx5, according to the latest transaction index of variable A, it can be concluded that the latest transaction of variable B is Tx2, so transaction Tx5 can be recorded as the subsequent transaction of transaction Tx2 (transaction Tx3 and transaction Tx4) . Master node 1 can record the DAG table of the currently pre-executed transactions as shown in Table 5:
交易trade 后继交易Subsequent transaction 入度数In-degree
Tx1Tx1 {Tx4}{Tx4} 00
Tx2Tx2 {Tx3,Tx4}{Tx3,Tx4} 00
Tx3Tx3 {Tx4,Tx5}{Tx4, Tx5} 11
Tx4Tx4 {Tx5}{Tx5} 33
Tx5Tx5 {}{} 22
表5table 5
同时,主节点1还将变量B的最近交易索引与交易Tx5绑定。根据当前已预执行完成的交易之间的DAG关系可绘出如图3所示的DAG图,该DAG图与表5所示的DAG数据对应。At the same time, master node 1 also binds the latest transaction index of variable B with transaction Tx5. According to the DAG relationship among the currently pre-executed completed transactions, a DAG diagram as shown in FIG. 3 can be drawn, and the DAG diagram corresponds to the DAG data shown in Table 5.
在步骤S205,主节点1将多个交易的DAG数据发送给各个从节点。In step S205, the master node 1 sends the DAG data of multiple transactions to each slave node.
主节点1可如上所述预执行多个交易,并生成该多个交易之间的DAG数据,并将该多个交易的DAG数据作为共识提议发送给各个从节点。主节点1还可以将接收的多个交易发送给各个从节点。可以理解,各个从节点也可能从其他从节点或者客户端接收到多个交易。各个从节点也可以从其他从节点接收到该多个交易的DAG数据。The master node 1 may pre-execute multiple transactions as described above, generate DAG data among the multiple transactions, and send the DAG data of the multiple transactions to each slave node as a consensus proposal. Master node 1 can also send multiple received transactions to each slave node. It can be understood that each slave node may also receive multiple transactions from other slave nodes or clients. Each slave node may also receive the DAG data of the plurality of transactions from other slave nodes.
除了将多个交易的DAG数据发送给各个从节点之外,主节点1还可以根据DAG数据生成入度数为0的可执行交易集合,并将该交易集合一起发送给各个从节点。例如,主节点1将表5所示的DAG数据发送给各个从节点,主节点1可根据该DAG数据得到包括交易Tx1和交易Tx2的可执行交易集合,并将该可执行交易集合发送给各个从节点。可以理解,主节点1也可以仅将多个交易的DAG数据发送给各个从节点,各个从节点可根据该DAG数据生成可执行交易集合。In addition to sending the DAG data of multiple transactions to each slave node, the master node 1 can also generate an executable transaction set with an in-degree of 0 according to the DAG data, and send the transaction set to each slave node together. For example, master node 1 sends the DAG data shown in Table 5 to each slave node, master node 1 can obtain an executable transaction set including transaction Tx1 and transaction Tx2 according to the DAG data, and send the executable transaction set to each slave node slave node. It can be understood that the master node 1 can also only send the DAG data of multiple transactions to each slave node, and each slave node can generate an executable transaction set according to the DAG data.
在步骤S207,从节点基于DAG数据执行交易。In step S207, the slave node executes the transaction based on the DAG data.
以从节点2为例,从节点2在获取基于DAG数据的可执行交易集合之后,首先执行可执行交易集合中的交易。由于可执行交易集合中的交易的入度数都为零,即其执行不会与其他交易产生冲突,因此,主节点1可并行执行可执行交易集合中的多个交易。Taking the slave node 2 as an example, after the slave node 2 obtains the executable transaction set based on the DAG data, it first executes the transactions in the executable transaction set. Since the in-degrees of the transactions in the executable transaction set are all zero, that is, their execution will not conflict with other transactions, therefore, the master node 1 can execute multiple transactions in the executable transaction set in parallel.
具体是,参考图3,可执行交易集合中初始包括交易Tx1和交易Tx2。从节点2可并行执行交易Tx1和交易Tx2。从节点2在完成对交易Tx1的执行之后,可在交易Tx4的DAG表中将入度数减1。从节点2在完成对交易Tx2的执行之后,可在交易Tx3和交易Tx4的的DAG表中将其入度数分别减1,使得交易Tx3的入度数变为0,此时,从节点2可将交易Tx3放入可执行交易集合中,即从节点2可执行交易Tx3。从节点2在完成对交易Tx3的执行之后,将交易Tx4和交易Tx5的入度数减1,使得交易Tx4的入度数变为0,类似地,从节点2可将交易Tx4放入可执行交易集合中。Specifically, referring to FIG. 3 , the executable transaction set initially includes transaction Tx1 and transaction Tx2 . Slave node 2 can execute transaction Tx1 and transaction Tx2 in parallel. After the slave node 2 completes the execution of the transaction Tx1, it can subtract 1 from the in-degree in the DAG table of the transaction Tx4. After the slave node 2 completes the execution of the transaction Tx2, the in-degrees of the transaction Tx3 and the transaction Tx4 can be respectively reduced by 1 in the DAG table, so that the in-degrees of the transaction Tx3 become 0. At this time, the slave node 2 can The transaction Tx3 is put into the executable transaction set, that is, the slave node 2 can execute the transaction Tx3. After completing the execution of transaction Tx3, slave node 2 will decrease the in-degrees of transaction Tx4 and transaction Tx5 by 1, so that the in-degrees of transaction Tx4 will become 0. Similarly, slave node 2 can put transaction Tx4 into the executable transaction set middle.
图4为本说明书一实施例中的一种区块链主节点的架构图,包括:Fig. 4 is an architecture diagram of a block chain master node in an embodiment of this specification, including:
预执行单元41,用于预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;The pre-execution unit 41 is configured to pre-execute the received first transaction, generate a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
生成单元42,用于根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;The generation unit 42 is configured to generate DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the pre-execution The most recent transaction before the first transaction that updates the pre-execution state of the first variable after pre-execution, and the DAG data indicates the chronological order in which the first transaction and the second transaction access the first variable ;
发送单元43,用于将所述DAG数据发送给所述区块链的从节点。A sending unit 43, configured to send the DAG data to the slave nodes of the block chain.
在一种实施方式中,所述预执行单元具体用于,基于预执行状态集预执行接收的第一交易,在预执行完成所述第一交易之后,基于所述第一交易的预执行读写集更新所述预执行状态集。In one embodiment, the pre-execution unit is specifically configured to pre-execute the received first transaction based on the pre-execution state set, and after the pre-execution completes the first transaction, based on the pre-execution read of the first transaction A write set updates the pre-execution state set.
在一种实施方式中,所述DAG数据包括已预执行完成的多个交易各自的DAG表, 每个交易的DAG表中包括该交易在DAG图中的后继交易和入度交易数目。In one embodiment, the DAG data includes DAG tables of multiple transactions that have been pre-executed, and the DAG table of each transaction includes the number of subsequent transactions and inbound transactions of the transaction in the DAG graph.
在一种实施方式中,所述预执行读写集中包括对所述第一变量的读操作,所述生成单元42具体用于:在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1。In one embodiment, the pre-execution read-write set includes a read operation on the first variable, and the generation unit 42 is specifically configured to: add the first transaction to the DAG table of the second transaction Recording as a subsequent transaction of the second transaction, adding 1 to the in-degree of the first transaction in the DAG table of the first transaction.
在一种实施方式中,所述预执行读写集中包括对所述第一变量的写操作,所述生成单元42具体用于:读取所述第二交易的DAG表,在所述第二交易具有后继的第四交易的情况中,在所述第四交易的DAG表中将所述第一交易记录为所述第四交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。In one embodiment, the pre-execution read-write set includes a write operation on the first variable, and the generating unit 42 is specifically configured to: read the DAG table of the second transaction, and in the second Where the transaction has a subsequent fourth transaction, record the first transaction as the successor transaction of the fourth transaction in the DAG table of the fourth transaction, and record all the subsequent transactions in the DAG table of the first transaction The in-degree of the first transaction is increased by 1, and the first transaction is recorded as the transaction for which the first variable is updated most recently.
在一种实施方式中,所述生成单元42具体用于:在所述第二交易没有后继交易的情况中,在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。In one embodiment, the generating unit 42 is specifically configured to: record the first transaction as the second transaction in the DAG table of the second transaction when the second transaction has no subsequent transaction For the subsequent transaction of the second transaction, add 1 to the in-degree of the first transaction in the DAG table of the first transaction, and record the first transaction as the transaction that most recently updated the first variable.
在一种实施方式中,所述主节点,还包括:获取单元(未示出),用于根据所述多个交易各自的DAG表获取第一集合,所述第一集合中包括所述多个交易中入度数为零的交易,In one embodiment, the master node further includes: an acquisition unit (not shown), configured to acquire a first set according to the respective DAG tables of the multiple transactions, and the first set includes the multiple transactions with zero in-degree,
所述发送单元43还用于将所述第一集合发送给所述从节点。The sending unit 43 is further configured to send the first set to the slave node.
图5为本说明书一实施例中的一种区块链从节点的架构图,包括:Fig. 5 is an architecture diagram of a block chain slave node in an embodiment of this specification, including:
接收单元51,用于从所述区块链的主节点接收DAG数据,所述DAG数据指示第一交易和第二交易访问第一变量的时间顺序;A receiving unit 51, configured to receive DAG data from the master node of the blockchain, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable;
执行单元52,用于基于所述DAG数据执行所述第一交易和所述第二交易。An execution unit 52, configured to execute the first transaction and the second transaction based on the DAG data.
通过本说明书实施例提供的在区块链中执行交易的方案,从节点根据主节点生成的DAG数据,对于没有冲突的交易可以并行执行,对于有冲突的交易可根据DAG数据中的先后顺序先后执行,从而提高了交易执行效率。Through the scheme of executing transactions in the blockchain provided by the embodiment of this specification, the slave node can execute the transactions without conflicts in parallel according to the DAG data generated by the master node, and the transactions with conflicts can be executed according to the order in the DAG data Execution, thereby improving the efficiency of transaction execution.
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程 门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, the improvement of a technology can be clearly distinguished as an improvement in hardware (for example, improvements in circuit structures such as diodes, transistors, and switches) or improvements in software (improvement in method flow). However, with the development of technology, the improvement of many current method flows can be regarded as the direct improvement of the hardware circuit structure. Designers almost always get the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be realized by hardware physical modules. For example, a programmable logic device (Programmable Logic Device, PLD) (such as a field programmable gate array (Field Programmable Gate Array, FPGA)) is such an integrated circuit, the logic function of which is determined by the user's programming of the device. It is programmed by the designer to "integrate" a digital system on a PLD, instead of asking a chip manufacturer to design and make a dedicated integrated circuit chip. Moreover, nowadays, instead of making integrated circuit chips by hand, this kind of programming is mostly realized by "logic compiler (logic compiler)" software, which is similar to the software compiler used when program development and writing, but before compiling The original code of the computer must also be written in a specific programming language, which is called a hardware description language (Hardware Description Language, HDL), and there is not only one kind of HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language) , AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., are currently the most commonly used The most popular are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. It should also be clear to those skilled in the art that only a little logical programming of the method flow in the above-mentioned hardware description languages and programming into an integrated circuit can easily obtain a hardware circuit for realizing the logic method flow.
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller may be implemented in any suitable way, for example the controller may take the form of a microprocessor or processor and a computer readable medium storing computer readable program code (such as software or firmware) executable by the (micro)processor , logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers and embedded microcontrollers, examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that, in addition to realizing the controller in a purely computer-readable program code mode, it is entirely possible to make the controller use logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded The same function can be realized in the form of a microcontroller or the like. Therefore, such a controller can be regarded as a hardware component, and the devices included in it for realizing various functions can also be regarded as structures within the hardware component. Or even, means for realizing various functions can be regarded as a structure within both a software module realizing a method and a hardware component.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为服务器系统。当然,本申请不排除随着未来计算机技术的发展,实现上述实施例功能的计算机例如可以为个人计算机、膝上型计算机、车载人机交互设备、蜂窝电话、相机电话、智能电话、个人 数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not exclude that with the development of future computer technology, the computer that realizes the functions of the above embodiments can be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant , media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.
虽然本说明书一个或多个实施例提供了如实施例或流程图所述的方法操作步骤,但基于常规或者无创造性的手段可以包括更多或者更少的操作步骤。实施例中列举的步骤顺序仅仅为众多步骤执行顺序中的一种方式,不代表唯一的执行顺序。在实际中的装置或终端产品执行时,可以按照实施例或者附图所示的方法顺序执行或者并行执行(例如并行处理器或者多线程处理的环境,甚至为分布式数据处理环境)。术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、产品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、产品或者设备所固有的要素。在没有更多限制的情况下,并不排除在包括所述要素的过程、方法、产品或者设备中还存在另外的相同或等同要素。例如若使用到第一,第二等词语用来表示名称,而并不表示任何特定的顺序。Although one or more embodiments of the present specification provide the operation steps of the method described in the embodiment or the flowchart, more or fewer operation steps may be included based on conventional or non-inventive means. The sequence of steps enumerated in the embodiments is only one of the execution sequences of many steps, and does not represent the only execution sequence. When an actual device or terminal product is executed, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (such as a parallel processor or multi-thread processing environment, or even a distributed data processing environment). The term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, product, or apparatus comprising a set of elements includes not only those elements, but also other elements not expressly listed elements, or also elements inherent in such a process, method, product, or apparatus. Without further limitations, it is not excluded that there are additional identical or equivalent elements in a process, method, product or device comprising said elements. For example, if the words first, second, etc. are used, they are used to indicate names and do not indicate any particular order.
为了描述的方便,描述以上装置时以功能分为各种模块分别描述。当然,在实施本说明书一个或多个时可以把各模块的功能在同一个或多个软件和/或硬件中实现,也可以将实现同一功能的模块由多个子模块或子单元的组合实现等。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。For the convenience of description, when describing the above devices, functions are divided into various modules and described separately. Of course, when implementing one or more of the present specification, the functions of each module can be realized in the same or more software and/or hardware, and the modules that realize the same function can also be realized by a combination of multiple submodules or subunits, etc. . The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
本发明是参照根据本发明实施例的方法、装置(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。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 should be understood that each procedure and/or block in the flowchart and/or block diagram, and a combination of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括 指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams.
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储、石墨烯存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. 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 Disc (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 computing devices. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
本领域技术人员应明白,本说明书一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that one or more embodiments of this specification 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 employ a computer program embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. The form of the product.
本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本本说明书一个或多个实施例,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在 内的本地和远程计算机存储介质中。One or more embodiments of this specification 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 may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including storage devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本说明书的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。Each embodiment in this specification is described in a progressive manner, the same and similar parts of each embodiment can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for relevant parts, refer to part of the description of the method embodiment. In the description of this specification, descriptions referring to the terms "one embodiment", "some embodiments", "example", "specific examples", or "some examples" mean that specific features described in connection with the embodiment or example , structures, materials or features are included in at least one embodiment or example of this specification. In this specification, the schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the described specific features, structures, materials or characteristics may be combined in any suitable manner in any one or more embodiments or examples. In addition, those skilled in the art can combine and combine different embodiments or examples and features of different embodiments or examples described in this specification without conflicting with each other.
以上所述仅为本说明书一个或多个实施例的实施例而已,并不用于限制本本说明书一个或多个实施例。对于本领域技术人员来说,本说明书一个或多个实施例可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在权利要求范围之内。The above description is only an example of one or more embodiments of this specification, and is not intended to limit one or more embodiments of this specification. For those skilled in the art, various modifications and changes may occur in one or more embodiments of this description. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this specification shall be included in the scope of the claims.

Claims (19)

  1. 一种在区块链中执行交易的方法,所述区块链包括主节点和从节点,所述方法包括:A method of executing a transaction in a blockchain, the blockchain comprising a master node and a slave node, the method comprising:
    所述主节点预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;The master node pre-executes the received first transaction, and generates a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable;
    所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成有向无环图DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;The master node generates directed acyclic graph DAG data according to the pre-executed read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is The most recent transaction prior to pre-execution of said first transaction that updates the pre-execution state of said first variable after pre-execution, said DAG data indicating that said first transaction and said second transaction access said first variable time sequence;
    所述主节点将所述DAG数据发送给所述从节点;The master node sends the DAG data to the slave node;
    所述从节点基于所述DAG数据执行所述第一交易和所述第二交易。The slave node executes the first transaction and the second transaction based on the DAG data.
  2. 根据权利要求1所述的方法,所述主节点预执行接收的第一交易包括,所述主节点基于预执行状态集预执行接收的第一交易,在预执行完成所述第一交易之后,基于所述第一交易的预执行读写集更新所述预执行状态集。According to the method according to claim 1, said master node pre-executing the received first transaction comprises: said master node pre-executing the received first transaction based on the pre-execution state set, and after the pre-execution completes the first transaction, The pre-execution state set is updated based on the pre-execution read-write set of the first transaction.
  3. 根据权利要求1或2所述的方法,其中,所述DAG数据包括已预执行完成的多个交易各自的DAG表,每个交易的DAG表中包括该交易在DAG图中的后继交易和入度交易数目。The method according to claim 1 or 2, wherein the DAG data includes the respective DAG tables of multiple transactions that have been pre-executed, and the DAG table of each transaction includes the subsequent transactions and input of the transaction in the DAG graph. number of transactions.
  4. 根据权利要求3所述的方法,所述预执行读写集中包括对所述第一变量的读操作,所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据包括:The method according to claim 3, wherein the pre-execution read-write set includes a read operation on the first variable, and the master node according to the pre-execution read-write set of the first transaction, the latest update of the previous record The identification of the second transaction of the first variable, generating DAG data includes:
    所述主节点在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1。The master node records the first transaction as a subsequent transaction of the second transaction in the DAG table of the second transaction, and records the in-degree of the first transaction in the DAG table of the first transaction plus 1.
  5. 根据权利要求3所述的方法,所述预执行读写集中包括对所述第一变量的读操作,所述第二交易标识为空交易标识,所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据包括:According to the method according to claim 3, the pre-execution read-write set includes the read operation of the first variable, the second transaction identifier is an empty transaction identifier, and the master node pre-executes according to the first transaction Executing the read-write set, the previously recorded identification of the second transaction that most recently updated the first variable, and generating DAG data includes:
    所述主节点与所述第一变量的空交易标识关联地记录所述第一交易的标识;The master node records the identifier of the first transaction in association with the empty transaction identifier of the first variable;
    所述主节点在预执行完成所述第一交易之后,预执行接收的第三交易,生成所述第三交易的预执行读写集,所述第三交易的预执行读写集中包括对所述第一变量的写操作;After the pre-execution of the first transaction is completed, the master node pre-executes the received third transaction to generate a pre-execution read-write set of the third transaction, and the pre-execution read-write set of the third transaction includes all The write operation of the first variable;
    所述主节点根据所述第三交易的预执行读写集和与所述第一变量的空交易标识关 联记录的所述第一交易的标识,在所述第一交易的DAG表中将所述第三交易记录为所述第一交易的后继交易,在所述第三交易的DAG表中将所述第三交易的入度数加1,记录所述第三交易为最近更新所述第一变量的交易。According to the pre-execution read-write set of the third transaction and the identifier of the first transaction recorded in association with the empty transaction identifier of the first variable, the master node stores the all in the DAG table of the first transaction The third transaction is recorded as the successor transaction of the first transaction, and the in-degree of the third transaction is added to the DAG table of the third transaction by 1, and the third transaction is recorded as the latest update of the first transaction. Variable transactions.
  6. 根据权利要求3所述的方法,所述第一交易的预执行读写集中包括对所述第一变量的写操作,所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据包括:According to the method according to claim 3, the pre-execution read-write set of the first transaction includes a write operation on the first variable, and the master node according to the pre-execution read-write set of the first transaction, prior The identifier of the second transaction that most recently updated the first variable is recorded, and the DAG data generation includes:
    所述主节点读取所述第二交易的DAG表,在所述第二交易具有后继的第四交易的情况中,在所述第四交易的DAG表中将所述第一交易记录为所述第四交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。The master node reads the DAG table of the second transaction, and in the case where the second transaction has a subsequent fourth transaction, records the first transaction in the DAG table of the fourth transaction as the For the subsequent transaction of the fourth transaction, add 1 to the in-degree of the first transaction in the DAG table of the first transaction, and record the first transaction as the transaction that most recently updated the first variable.
  7. 根据权利要求6所述的方法,所述主节点根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据还包括:在所述第二交易没有后继交易的情况中,在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。According to the method according to claim 6, the generation of DAG data by the master node according to the pre-executed read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable further includes: In the case that the second transaction has no successor transaction, the first transaction is recorded in the DAG table of the second transaction as the successor transaction of the second transaction, and in the DAG table of the first transaction Adding 1 to the in-degree of the first transaction, and recording the first transaction as the latest update of the first variable.
  8. 根据权利要求3所述的方法,还包括:The method according to claim 3, further comprising:
    所述主节点根据所述多个交易各自的DAG表获取第一集合,所述第一集合中包括所述多个交易中入度数为零的交易,The master node obtains a first set according to the respective DAG tables of the multiple transactions, and the first set includes transactions whose in-degrees are zero among the multiple transactions,
    将所述第一集合发送给所述从节点。Sending the first set to the slave node.
  9. 根据权利要求8所述的方法,所述第一集合中包括所述第二交易,所述第一交易为所述第二交易的后继交易,所述从节点基于所述DAG数据执行所述第一交易和所述第二交易包括:The method according to claim 8, wherein the first set includes the second transaction, the first transaction is a subsequent transaction of the second transaction, and the slave node executes the second transaction based on the DAG data A transaction and said second transaction include:
    所述从节点并行执行所述第一集合中的交易;在执行完所述第二交易之后,将所述第一交易的入度数减1;在所述第一交易的入度数减至0的情况中,将所述第一交易放入所述第一集合中。The slave node executes the transactions in the first set in parallel; after executing the second transaction, the in-degree of the first transaction is decremented by 1; when the in-degree of the first transaction is reduced to 0 In case, the first transaction is put into the first set.
  10. 根据权利要求2所述的方法,所述第一交易的预执行读写集包括对第一变量的读操作,所述基于所述第一交易的预执行读写集更新所述预执行状态集包括:确定所述预执行读写集中所述第一变量的值与所述预执行状态集中的所述第一变量的值是否一致,在一致的情况中,基于所述第一交易的预执行读写集更新所述预执行状态集,所述生成DAG数据包括,在一致的情况中生成DAG数据。The method according to claim 2, wherein the pre-execution read-write set of the first transaction includes a read operation on a first variable, and the pre-execution state set is updated based on the pre-execution read-write set of the first transaction Including: determining whether the value of the first variable in the pre-execution read-write set is consistent with the value of the first variable in the pre-execution state set, and if they are consistent, pre-execution based on the first transaction The read-write set updates the pre-execution state set, and the generating DAG data includes generating DAG data in a consistent situation.
  11. 一种区块链,所述区块链包括主节点和从节点,A blockchain comprising a master node and a slave node,
    所述主节点用于:预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;将所述DAG数据发送给所述从节点;The master node is used to: pre-execute the received first transaction, generate a pre-execution read-write set of the first transaction, and the pre-execution read-write set includes access to the first variable; The pre-execution read-write set, the identification of the second transaction that most recently updated the first variable recorded earlier, generates DAG data, and the second transaction is the most recent post-pre-execution update before the pre-execution of the first transaction A transaction in the pre-execution state of the first variable, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable; sending the DAG data to the slave node;
    所述从节点用于基于所述DAG数据执行所述第一交易和所述第二交易。The slave node is configured to execute the first transaction and the second transaction based on the DAG data.
  12. 一种区块链主节点,包括:A blockchain master node comprising:
    预执行单元,用于预执行接收的第一交易,生成所述第一交易的预执行读写集,所述预执行读写集中包括对第一变量的访问;A pre-execution unit, configured to pre-execute the received first transaction, and generate a pre-execution read-write set of the first transaction, the pre-execution read-write set includes access to the first variable;
    生成单元,用于根据所述第一交易的预执行读写集、在先记录的最近更新所述第一变量的第二交易的标识,生成DAG数据,所述第二交易为在预执行所述第一交易之前最近的在预执行后更新所述第一变量的预执行状态的交易,所述DAG数据指示所述第一交易和所述第二交易访问所述第一变量的时间顺序;A generation unit, configured to generate DAG data according to the pre-execution read-write set of the first transaction and the identifier of the previously recorded second transaction that most recently updated the first variable, and the second transaction is the pre-execution A transaction that updates the pre-execution state of the first variable after pre-execution, the most recent before the first transaction, and the DAG data indicates the time sequence in which the first transaction and the second transaction access the first variable;
    发送单元,用于将所述DAG数据发送给所述区块链的从节点。A sending unit, configured to send the DAG data to the slave nodes of the block chain.
  13. 根据权利要求12所述的主节点,所述预执行单元具体用于,基于预执行状态集预执行接收的第一交易,在预执行完成所述第一交易之后,基于所述第一交易的预执行读写集更新所述预执行状态集。According to the master node according to claim 12, the pre-execution unit is specifically configured to pre-execute the received first transaction based on the pre-execution state set, and after the pre-execution completes the first transaction, based on the first transaction The pre-execution read-write set updates the pre-execution state set.
  14. 根据权利要求12或13所述的主节点,其中,所述DAG数据包括已预执行完成的多个交易各自的DAG表,每个交易的DAG表中包括该交易在DAG图中的后继交易和入度交易数目。The master node according to claim 12 or 13, wherein the DAG data includes the respective DAG tables of multiple transactions that have been pre-executed, and the DAG table of each transaction includes the subsequent transactions and The number of inbound transactions.
  15. 根据权利要求14所述的主节点,所述预执行读写集中包括对所述第一变量的读操作,所述生成单元具体用于:在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1。According to the master node according to claim 14, the pre-execution read-write set includes a read operation on the first variable, and the generating unit is specifically configured to: add the first variable in the DAG table of the second transaction A transaction is recorded as a subsequent transaction of the second transaction, and the in-degree of the first transaction is added by 1 in the DAG table of the first transaction.
  16. 根据权利要求14所述的主节点,所述预执行读写集中包括对所述第一变量的写操作,所述生成单元具体用于:读取所述第二交易的DAG表,在所述第二交易具有后继的第四交易的情况中,在所述第四交易的DAG表中将所述第一交易记录为所述第四交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。According to the master node according to claim 14, the pre-execution read-write set includes a write operation on the first variable, and the generating unit is specifically configured to: read the DAG table of the second transaction, and in the Where the second transaction has a subsequent fourth transaction, the first transaction is recorded in the DAG table of the fourth transaction as the successor transaction of the fourth transaction, and in the DAG table of the first transaction Adding 1 to the in-degree of the first transaction, and recording the first transaction as the latest update of the first variable.
  17. 根据权利要求16所述的主节点,所述生成单元具体用于:在所述第二交易没有后继交易的情况中,在所述第二交易的DAG表中将所述第一交易记录为所述第二交易的后继交易,在所述第一交易的DAG表中将所述第一交易的入度数加1,记录所述第一交易为最近更新所述第一变量的交易。According to the master node according to claim 16, the generating unit is specifically configured to: record the first transaction in the DAG table of the second transaction as the For the subsequent transaction of the second transaction, add 1 to the in-degree of the first transaction in the DAG table of the first transaction, and record the first transaction as the transaction that most recently updated the first variable.
  18. 根据权利要求14所述的主节点,还包括:The master node according to claim 14, further comprising:
    获取单元,用于根据所述多个交易各自的DAG表获取第一集合,所述第一集合中包括所述多个交易中入度数为零的交易,An acquisition unit, configured to acquire a first set according to the respective DAG tables of the plurality of transactions, the first set includes transactions whose in-degrees are zero among the plurality of transactions,
    所述发送单元还用于将所述第一集合发送给所述从节点。The sending unit is further configured to send the first set to the slave node.
  19. 一种区块链从节点,包括:A blockchain slave node, comprising:
    接收单元,用于从所述区块链的主节点接收DAG数据,所述DAG数据指示第一交易和第二交易访问第一变量的时间顺序;a receiving unit, configured to receive DAG data from the master node of the blockchain, the DAG data indicating the time sequence in which the first transaction and the second transaction access the first variable;
    执行单元,用于基于所述DAG数据执行所述第一交易和所述第二交易。An execution unit, configured to execute the first transaction and the second transaction based on the DAG data.
PCT/CN2022/135338 2022-02-25 2022-11-30 Method for executing transaction, blockchain, master node, and slave node WO2023160085A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210181705.2 2022-02-25
CN202210181705.2A CN114547203A (en) 2022-02-25 2022-02-25 Method for executing transaction, block chain, main node and slave node

Publications (1)

Publication Number Publication Date
WO2023160085A1 true WO2023160085A1 (en) 2023-08-31

Family

ID=81679309

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135338 WO2023160085A1 (en) 2022-02-25 2022-11-30 Method for executing transaction, blockchain, master node, and slave node

Country Status (2)

Country Link
CN (1) CN114547203A (en)
WO (1) WO2023160085A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114529417A (en) * 2022-02-25 2022-05-24 蚂蚁区块链科技(上海)有限公司 Method for executing transaction, block chain, main node and slave node
CN114547203A (en) * 2022-02-25 2022-05-27 蚂蚁区块链科技(上海)有限公司 Method for executing transaction, block chain, main node and slave node
CN115150409A (en) * 2022-06-29 2022-10-04 蚂蚁区块链科技(上海)有限公司 Method for executing transaction in block chain system, block chain system and node

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112150163A (en) * 2020-11-26 2020-12-29 北京微芯区块链与边缘计算研究院 Block chain contract transaction parallel execution method and device
US20210091957A1 (en) * 2019-09-25 2021-03-25 International Business Machines Corporation Consensus protocol for blockchain dag structure
CN113674095A (en) * 2021-10-20 2021-11-19 浙商银行股份有限公司 Method for improving block chain throughput based on transaction DAG
CN113743941A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Method for executing transaction in block chain, block chain and main node
CN113743942A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Transaction execution method, block chain, main node and main storage device
CN114547203A (en) * 2022-02-25 2022-05-27 蚂蚁区块链科技(上海)有限公司 Method for executing transaction, block chain, main node and slave node

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210091957A1 (en) * 2019-09-25 2021-03-25 International Business Machines Corporation Consensus protocol for blockchain dag structure
CN112150163A (en) * 2020-11-26 2020-12-29 北京微芯区块链与边缘计算研究院 Block chain contract transaction parallel execution method and device
CN113674095A (en) * 2021-10-20 2021-11-19 浙商银行股份有限公司 Method for improving block chain throughput based on transaction DAG
CN113743941A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Method for executing transaction in block chain, block chain and main node
CN113743942A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Transaction execution method, block chain, main node and main storage device
CN114547203A (en) * 2022-02-25 2022-05-27 蚂蚁区块链科技(上海)有限公司 Method for executing transaction, block chain, main node and slave node

Also Published As

Publication number Publication date
CN114547203A (en) 2022-05-27

Similar Documents

Publication Publication Date Title
WO2023160085A1 (en) Method for executing transaction, blockchain, master node, and slave node
WO2020082871A1 (en) Method, device and system for executing blockchain transactions in parallel
WO2023160083A1 (en) Method for executing transactions, blockchain, master node, and slave node
CN114827165B (en) Method and block link point for grouping multiple transactions
TWI719797B (en) Storage and execution method and device of smart contract in blockchain and electronic equipment
WO2023231336A1 (en) Method for executing transaction and blockchain node
WO2024001024A1 (en) Method for executing transaction in blockchain system, and blockchain system and nodes
TWI679581B (en) Method and device for task execution
CN108599973B (en) Log association method, device and equipment
WO2023231337A1 (en) Method for executing transaction in blockchain, and master node and slave node of blockchain
WO2023231335A1 (en) Method for executing transaction in blockchain, and master node of blockchain
EP3779692A1 (en) Data processing method and device, client, and server
WO2024001025A1 (en) Pre-execution cache data cleaning method and blockchain node
WO2024001032A1 (en) Method for executing transaction in blockchain system, and blockchain system and nodes
CN116305298B (en) Method and device for managing computing power resources, storage medium and electronic equipment
WO2023231342A1 (en) Method and apparatus for automatically executing contract on the basis of variable state
WO2023240933A1 (en) Distributed application deployment method and apparatus based on blockchain
CN116032756A (en) Method for updating configuration information of application program based on block chain and block chain link point
CN116366666A (en) Chain state updating method and block link point in block chain system
WO2024092932A1 (en) Transaction execution method and blockchain node
CN116881361A (en) Transaction execution method, node and blockchain system
CN116662292A (en) Transaction execution method, node and blockchain system
CN116821242A (en) Block synchronization method, device and block chain system
CN116204335A (en) Block generation method and device
CN116993502A (en) Prompt word management method and device based on block chain system

Legal Events

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

Ref document number: 22928345

Country of ref document: EP

Kind code of ref document: A1