CN110599166A - Method and device for acquiring transaction dependency relationship in block chain - Google Patents

Method and device for acquiring transaction dependency relationship in block chain Download PDF

Info

Publication number
CN110599166A
CN110599166A CN201910848016.0A CN201910848016A CN110599166A CN 110599166 A CN110599166 A CN 110599166A CN 201910848016 A CN201910848016 A CN 201910848016A CN 110599166 A CN110599166 A CN 110599166A
Authority
CN
China
Prior art keywords
transaction
transactions
shared variable
shared
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910848016.0A
Other languages
Chinese (zh)
Inventor
石翔
李辉忠
张开翔
范瑞彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN201910848016.0A priority Critical patent/CN110599166A/en
Publication of CN110599166A publication Critical patent/CN110599166A/en
Priority to PCT/CN2020/114229 priority patent/WO2021047541A1/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/389Keeping log of transactions for guaranteeing non-repudiation of a transaction
    • 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

Abstract

The invention discloses a method and a device for acquiring transaction dependency relationship in a block chain, wherein the method comprises the following steps: obtaining a plurality of transactions; the plurality of transactions present an input order; according to the input sequence, sequentially executing preset operation on each transaction in the multiple transactions to obtain the dependency relationship of the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions. When the method is applied to financial technology (Fintech), the method can be used for acquiring the dependency relationship of a plurality of transactions and providing reference for the execution of the plurality of transactions.

Description

Method and device for acquiring transaction dependency relationship in block chain
Technical Field
The invention relates to the field of financial technology (Fintech) and the field of a block chain (Blockchain), in particular to a method and a device for acquiring a transaction dependency relationship in the block chain.
Background
With the development of computer technology, more and more technologies (big data, distributed, Blockchain (Blockchain), artificial intelligence, etc.) are applied in the financial field, and the traditional financial industry is gradually changing to financial technology (Fintech). Currently, transactions are often conducted through block links in the field of financial technology based on their non-tamper-ability.
However, as the volume of transactions continues to increase, serially executing transactions can result in a large number of transactions being queued for a long period of time. In order to increase the efficiency of executing the transaction, the parallel execution condition of the transaction can be considered, because the same shared variables may exist between the transactions, and two or more transactions with the same shared variables cannot be executed in parallel because of the conflict of the shared variables, a dependency relationship of the execution sequence can be formed between the transactions. In order to avoid shared variable conflicts between transactions, transactions need to be executed in parallel according to transaction dependencies. However, in the prior art, there is no method for obtaining transaction dependency in the blockchain, which is not favorable for executing the transaction in the blockchain, and is a problem to be solved urgently.
Disclosure of Invention
The embodiment of the application provides a method and a device for obtaining transaction dependency in a block chain, and solves the problem that the prior art is not provided with a method for obtaining transaction dependency in the block chain and is not beneficial to transaction execution in the block chain.
In a first aspect, an embodiment of the present application provides a method for acquiring a transaction dependency relationship in a blockchain: obtaining a plurality of transactions; the plurality of transactions present an input order; according to the input sequence, sequentially executing preset operation on each transaction in the multiple transactions to obtain the dependency relationship of the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
According to the method, after a plurality of transactions are obtained according to an input sequence, preset operation is sequentially executed on each transaction in the plurality of transactions according to the input sequence, so that the transaction depended on by each transaction is sequentially obtained, and the probability of confusion of the dependency relationship among the transactions is reduced.
In an optional implementation manner, after the performing a preset operation on each transaction in the multiple transactions in sequence according to the input order and obtaining the dependency relationship of the multiple transactions, the method further includes: executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship; and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
In the method, the transaction which does not have the dependency among the plurality of transactions is executed according to the dependency; after the execution is finished, the dependency relationship is updated, and the step of executing the transaction without the dependency transaction in the transactions according to the dependency relationship is returned, so that the transaction can be learned through the dependency relationship and the transaction can not be in conflict when being executed in parallel.
In an optional embodiment, the performing, in sequence, a preset operation on each of the plurality of transactions includes: for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order; if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
In the method, for a first transaction, if a first shared variable in a preamble shared variable and a second shared variable of the first transaction are the same shared variable, a second transaction corresponding to the first shared variable is determined as a transaction on which the first transaction depends, and the first shared variable is updated to correspond to the first transaction; if the preamble shared variable does not include the second shared variable of the first transaction, the second shared variable is added to the preamble shared variable, and the second shared variable is set to correspond to the first transaction, thereby providing a corresponding relationship between the shared variable and the transaction.
In an optional embodiment, if the preamble shared variable is null, determining that a node corresponding to the first transaction is a vertex of a directed graph; determining a second transaction corresponding to the first shared variable as a dependent transaction of the first transaction, including: establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship, including: executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
In the above method, if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of a directed graph, and establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transactions to update the directed graph, so that the dependency relationship of a plurality of transactions can be associated with the visual directed graph, and the visual representation method and the execution method of the dependency relationship of the plurality of transactions are provided.
In a second aspect, the present application provides an apparatus for obtaining transaction dependencies within a blockchain, including: an acquisition module for acquiring a plurality of transactions; the plurality of transactions present an input order; the processing module is used for sequentially executing preset operation on each transaction in the multiple transactions according to the input sequence to obtain the dependency relationship of the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
In an optional embodiment, the processing module is further configured to: executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship; and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
In an optional implementation manner, the processing module is specifically configured to: for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order; if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
In an optional embodiment, the processing module is further configured to: if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of the directed graph; establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
For the advantages of the second aspect and the embodiments of the second aspect, reference may be made to the advantages of the first aspect and the embodiments of the first aspect, which are not described herein again.
In a third aspect, an embodiment of the present application provides a computer device, which includes a program or instructions, and when the program or instructions are executed, the computer device is configured to perform the method of each embodiment of the first aspect and the first aspect.
In a fourth aspect, an embodiment of the present application provides a storage medium, which includes a program or instructions, and when the program or instructions are executed, the program or instructions are configured to perform the method of the first aspect and the embodiments of the first aspect.
Drawings
FIG. 1 is a schematic diagram of a blockchain;
fig. 2 is a schematic flowchart illustrating steps of a method for obtaining transaction dependencies in a blockchain according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a process of generating a transaction dependency relationship diagram in a method for obtaining transaction dependency relationships in a block chain according to an embodiment of the present application;
fig. 4 is a schematic diagram of a process of generating a transaction dependency relationship diagram in a method for obtaining transaction dependency relationships in a block chain according to an embodiment of the present application;
fig. 5 is a schematic diagram of a process of generating a transaction dependency graph in a method for obtaining transaction dependencies in a block chain according to an embodiment of the present application;
fig. 6 is a schematic diagram of a process of generating a transaction dependency relationship diagram in a method for obtaining transaction dependency relationships in a block chain according to an embodiment of the present application;
fig. 7 is a schematic overall flow chart corresponding to a method for obtaining transaction dependency in a block chain according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of an apparatus for acquiring transaction dependency in a blockchain according to an embodiment of the present disclosure.
Detailed Description
In order to better understand the technical solutions, the technical solutions will be described in detail below with reference to the drawings and the specific embodiments of the specification, and it should be understood that the specific features in the embodiments and examples of the present application are detailed descriptions of the technical solutions of the present application, but not limitations of the technical solutions of the present application, and the technical features in the embodiments and examples of the present application may be combined with each other without conflict.
The terms appearing in the embodiments of the present application are explained first below.
Block chains: as shown in fig. 1, a block chain is a chain consisting of a series of blocks, and each block records a Hash value of the block in addition to the data of the block, so that a chain is formed. The block chain has two core ideas, one is a cryptography technology, the other is a decentralization idea, and based on the two ideas, historical information on the block chain cannot be tampered.
And (3) node: each participant in the network is a node that participates in network set-up and data exchange. In a blockchain network, a node refers to a participant with a unique identity, and the node has a complete copy of the ledger and has the capability of participating in the consensus and ledger maintenance of the blockchain network.
Intelligent contract: an intelligent contract is a computer protocol intended to propagate, validate or execute contracts in an informational manner. Smart contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible. The specific form of the intelligent contract is a code which is deployed on a block chain and completes a specific function. For example, identity is a mainstream intelligent contract programming language, and an intelligent contract written in the identity language is called an identity contract. When an intelligent contract is deployed on a blockchain, a contract address is generated, and a user can call the intelligent contract through the contract address. The function defined in the intelligent contract is called a contract interface, and the calling of the intelligent contract is to call a certain contract interface in the contract through a contract address.
Trading: a transaction is a user request for an operation of an intelligent contract interface deployed on a blockchain. The transaction is initiated by the user, sent from the client of the user to the block chain node, and after receiving the transaction, the block chain node calls the corresponding intelligent contract according to the contract address and the interface specified by the transaction.
Sharing variables: in the interface (function) of the intelligent contract, some global variables are operated on, and the global variables are likely to be operated on by another contract interface. The global variables that are operated on in the interface of the smart contract are called shared variables. A transaction invokes an interface to an intelligent contract involving the manipulation of certain shared variables. These shared variables are referred to as shared variables for this transaction.
Transaction dependency relationship: if two transactions operate the same shared variable at the same time, in order to ensure the execution correctness, the two transactions have execution sequence, and after one transaction is executed, the other transaction can be executed. And the transaction dependency relationship describes the execution sequence of the transactions. The transaction with the dependency relationship must be executed according to the sequence of the dependency relationship. Transactions without dependencies may be executed in parallel.
In the operation process of financial institutions (banking institutions, insurance institutions or security institutions) for carrying out services (such as loan services and deposit services of banks, etc.), transactions are often carried out through block links in the field of financial technology based on the non-tamper property of the block links. However, as the volume of transactions increases, however, executing transactions serially may result in a large number of transactions being queued for a long period of time as the volume of transactions increases. In order to increase the efficiency of executing the transaction, the parallel execution condition of the transaction can be considered, because the same shared variables may exist between the transactions, and two or more transactions with the same shared variables cannot be executed in parallel because of the conflict of the shared variables, a dependency relationship of the execution sequence can be formed between the transactions. In order to avoid shared variable conflicts between transactions, transactions need to be executed in parallel according to transaction dependencies. However, in the prior art, there is no method for obtaining transaction dependency in a block chain, which does not meet the requirements of financial institutions such as banks, and cannot ensure efficient operation of various services of the financial institutions.
To this end, the present application provides a method for obtaining transaction dependency relationships in a blockchain, as shown in fig. 2, including the following steps:
step 201: a plurality of transactions is obtained.
An input order exists for the plurality of transactions.
Step 202: and according to the input sequence, sequentially executing preset operation on each transaction in the plurality of transactions to obtain the dependency relationship of the plurality of transactions.
The preset operation (hereinafter, referred to as a first preset operation) may be: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
Alternatively, the preset operation (hereinafter, referred to as a second preset operation) may be: if the transaction with the same shared variable as the first transaction does not exist in the preceding transaction combination of the first transaction, determining that the first transaction does not have the transaction depended on in the plurality of transactions; the shared variable is a variable which is possessed by at least two contract interfaces, and the transaction is a request for accessing the contract interfaces; the first transaction is any one of the plurality of transactions; the preamble transaction combination is a sequential combination of all transactions of the first transaction prior to the input sequence; if at least one second transaction with the same shared variable as the first transaction exists in the preamble transaction combination, taking the at least one second transaction as a transaction on which the first transaction depends in the plurality of transactions; wherein each second transaction in the at least one second transaction uniquely corresponds to one shared variable in the first transaction, and the second transaction uniquely corresponding to the shared variable is: the sequential backmost transaction of the shared variable is contained in the preamble transaction combination. When the first transaction is the first transaction of the multiple transactions, the preamble transaction combination is empty, and there is no transaction having the same shared variable as the first transaction in the preamble transaction combination.
It should be noted that if the transaction a and the transaction B satisfy the following conditions, the transaction a is called a transaction that the transaction B depends on: (1) in the input sequence, transaction A precedes transaction B. (2) Transaction a has the same at least one shared variable as transaction B. (3) Transaction a is a transaction in which transaction B inputs the order in the preceding transactions and the last transaction executes at least one shared variable. That is, the transaction between transaction a and transaction B (excluding transaction a and transaction B) does not have the same shared variables as transaction B.
If the first preset operation is performed, in the method from step 201 to step 202, after the multiple transactions are obtained according to the input sequence, the preset operation is sequentially executed for each transaction in the plurality of transactions, so that the transaction depended on by each transaction is sequentially obtained, the probability of confusion of dependency relationship among the transactions is reduced, wherein, since the dependent transaction of the preamble shared transaction must have been executed before the preamble shared transaction is executed, therefore, for each shared variable of the first transaction in the dependency relationship, only the second transaction with the most back input sequence in the preamble shared transactions of the first transaction needs to be considered, so that the conflict of the shared variables between the first transaction and the second transaction can be avoided, the method can describe the dependency relationship of the multiple transactions in a simplified manner, therefore, a method is provided for acquiring the dependency relationship of a plurality of transactions, and reference is provided for parallel execution of the plurality of transactions.
If according to the second preset operation, in the method of steps 201 to 202, after obtaining a plurality of transactions according to an input sequence, according to the input sequence, sequentially executing a preset operation on each transaction in the plurality of transactions, thereby sequentially obtaining the transaction depended on by each transaction, and reducing the possibility of confusion of dependency relationship among the transactions, wherein when there is no transaction having the same shared variable as the first transaction in a preamble transaction combination of a first transaction, it is determined that there is no transaction depended on by the first transaction in the plurality of transactions, and only the first transaction needs to be considered, and if there is at least one second transaction having the same shared variable as the first transaction in the preamble transaction combination, because the transaction depended on by the second transaction has been executed before the second transaction is executed, each shared variable in the dependency relationship for the first transaction, the conflict of the shared variables between the first transaction and the second transaction can be avoided only by considering the second transaction which contains the shared variable and is most back in the sequence in the preamble transaction combination.
Following step 202, the plurality of transactions may be executed according to their dependencies. In specific alternative embodiments, the following two methods can be adopted:
a first way of performing the plurality of transactions:
executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship; and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
A second way to perform the plurality of transactions:
executing transaction combinations of the plurality of transactions for which there is no dependent transaction in parallel; if at least two transactions meeting a preset parallel condition exist after the execution is finished, the at least two transactions are used as the transaction combination without the dependent transactions again so as to update the transaction combination without the dependent transactions; returning to the step of executing in parallel a transaction combination for which there is no dependent transaction in the plurality of transactions; the preset parallel condition is as follows: all transactions on which the at least two transactions depend in the plurality of transactions are in the combination of transactions for which there is no dependent transaction.
It should be noted that, in step 202, the following two ways may be adopted for specific alternative embodiments of the dependency relationship of the multiple transactions:
the first specific implementation of step 202 is:
the executing of the preset operation to each transaction in the plurality of transactions in sequence comprises: for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order; if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
The second specific implementation of step 202 is:
acquiring a shared variable combination of the first transaction; if the current transaction of each shared variable in the shared variable combination is empty, determining that no transaction with the same shared variable as the first transaction exists in the preorder transaction combination; taking a node corresponding to the first transaction as a vertex of a directed graph; recording the current transaction of each shared variable in the shared variable combination as the first transaction; if at least one shared variable which is not empty in the current transaction exists in the shared variable combination, taking the current transaction of the at least one shared variable as the at least one second transaction; establishing an edge of the at least one second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; updating the current transaction of each shared variable of the at least one shared variable to the first transaction; determining that there is no transaction in the preamble transaction combination that has the same shared variable as the first transaction; taking a node corresponding to the first transaction as a vertex of the directed graph; and recording the current transaction as the first transaction.
Obviously, the directed graph has more than one vertex, the first transaction has no depended-on transaction, and the following transaction may depend on the former transaction or not, if not, also can be used as the vertex.
The dependency relationship of a plurality of transactions can be represented according to a directed graph, and the method specifically comprises the following two implementation modes:
the first way according to the directed graph is:
if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of the directed graph; determining a second transaction corresponding to the first shared variable as a dependent transaction of the first transaction, including: establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship, including: executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
The second way according to the directed graph is:
executing, in parallel, a transaction of the plurality of transactions according to the directed graph in the following manner: executing the transactions corresponding to the nodes with the degree of income of 0 in the directed graph in the plurality of transactions in parallel; after parallel execution, deleting the nodes and the edges of the nodes corresponding to the transactions which are executed in parallel so as to update the nodes with the degree of entry of 0; and returning to the step of executing the transactions corresponding to the nodes with the 0 in-degree in the directed graph in the plurality of transactions in parallel.
The following describes a method for obtaining transaction dependencies in a blockchain according to the present application in detail by taking a way of recording dependencies of multiple transactions in a directed graph as an example. In the method, the transaction dependency relationship without redundant dependency edges is directly generated, and the redundant overhead when the transaction dependency is judged in the transaction parallel execution stage is eliminated. Because the input of the transactions in the blockchain has a precedence order, the two transactions with the same or a plurality of shared variables have the same or a plurality of shared variables, and the execution precedence order is the precedence order of the input blockchain. The sequence is executed before the preceding transaction and after the subsequent transaction. Therefore, when a transaction dependent edge is established according to a transaction on which one or more shared variables depend, only the dependent edge needs to be established with the latest transaction in the dependent transaction. The specific generation process of the transaction dependency graph is as follows:
as shown in table 1, there are 4 transactions in the blockchain, and the corresponding shared variables are as follows.
Trading Sharing variables
0 A,B
1 A,C
2 D,E
3 A,D
TABLE 1
If the shared variable A and the transaction D of the transaction C meet the following conditions, the transaction D is called as the transaction on which the shared variable K of the transaction C depends: (1) in the input sequence, transaction D precedes transaction C. (2) Transaction D also has a shared variable K.
The shared variable for transaction 0 is A, B. And searching the transaction with the dependence according to the A to be null, and searching the transaction with the dependence according to the B to be null. Thus, as shown in FIG. 3, the transaction dependency graph now has only one transaction 0.
As shown in FIG. 4, after transaction 0 is processed, the dependent transaction is updated and transaction 0 is recorded at both shared variables A and B. Processing to transaction 1, wherein the shared variables of transaction 1 are A and C. And (3) searching the transaction with the dependency by using the A, finding that the transaction has 0, and establishing an edge which points from 0 to 1 in the transaction dependency relationship graph to show that the transaction 1 depends on the execution result of the transaction 0. Then C is used to search for the transaction with the dependency, and 0 is found to be still existed, because the edge is already established before, the operation of establishing the edge is not performed.
As shown in fig. 5, when transaction 2 is processed and the transaction dependent on the shared variable is updated, the existing record is directly overwritten by the serial number of the latest transaction processed in the prior art, that is, the shared variable a is directly overwritten by 1, and the original 0 is directly overwritten. And then searching the transaction with the dependence according to the D to be null, and searching the transaction with the dependence according to the E to be null. Thus, transaction 2 does not have any directed edges in the transaction dependency graph. Transaction 2 is independent, a 2 vertex is created, and no edge points.
As shown in FIG. 6, after transaction 2 is processed, the dependent transactions are updated and transaction 2 is recorded in both shared variables D and E. Transaction 3 is then processed, with transaction 3's shared variables being A and D. And searching for the transaction with the dependency according to the A, and only recording the serial number of the latest transaction at the shared variable A, so that only the transaction 1 needs to be considered at the shared variable A, namely only an edge pointing from 1 to 3 needs to be established. At D, find transaction 2, establish 2 to point to 3 edge.
Therefore, the scheme eliminates the establishment of the redundancy dependency edge by only recording the current latest transaction serial number, and further eliminates the redundancy overhead when the transaction dependency is judged at the transaction parallel execution stage.
The following describes in detail the overall process of acquiring transaction dependency relationships in the blockchain proposed in the present application with reference to fig. 7.
Step 701: at least one transaction is taken from the blockchain.
Specifically, the process of step 701 may be that a unique node is selected from the blockchain, the transaction is first packaged into a "to-be-executed block", and then the "to-be-executed block" is sent to all nodes in the blockchain, and all nodes in the blockchain use the "to-be-executed block" for execution. Steps 701-708 are additional operations performed before each node in the blockchain executes the "to-be-executed block". Of course, there may be no transactions from the blockchain, and the following steps 702-708 are not performed. It should be noted that at least one transaction taken from the blockchain is arranged according to the input order of the transaction input blockchain.
Step 702: an unprocessed transaction is fetched in the order of entry of at least one transaction.
Step 703: and acquiring the shared variable of the current transaction.
In step 703, the method for obtaining the shared variable is not limited.
Step 704: all shared variable dependent transactions for the current transaction are queried.
Step 705: and establishing a dependency relationship according to the inquired dependent transaction, namely establishing a dependent edge pointing to the current transaction from the dependent transaction.
Step 706: and updating the dependence of the current transaction shared variable as the current transaction.
Step 706 ensures that only the most recent transactions are in the dependency record of the shared variable.
Step 707: it is determined whether there is an unprocessed transaction.
If yes, go back to step 702, otherwise, go to step 708.
Step 708: outputting a transaction dependency graph for use in parallel execution;
as shown in fig. 8, the present application provides an apparatus for obtaining transaction dependency relationship in a blockchain, including: an obtaining module 801 for obtaining a plurality of transactions; the plurality of transactions present an input order; a processing module 802, configured to sequentially perform a preset operation on each transaction in the multiple transactions according to the input sequence, so as to obtain a dependency relationship between the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
In an optional implementation, the processing module 802 is further configured to: executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship; and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
In an optional implementation manner, the processing module 802 is specifically configured to: for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order; if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
In an optional implementation, the processing module 802 is further configured to: if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of the directed graph; establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph; executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
Embodiments of the present application provide a computer device, which includes a program or instructions, and when the program or instructions are executed, the program or instructions are configured to perform a method for acquiring transaction dependencies within a blockchain and any optional method provided in embodiments of the present application.
Embodiments of the present application provide a storage medium, which includes a program or an instruction, and when the program or the instruction is executed, the program or the instruction is used to execute a method for acquiring transaction dependency relationship in a blockchain and any optional method provided by embodiments of the present application.
Finally, it should be noted that: as will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for obtaining transaction dependencies within a blockchain, comprising:
obtaining a plurality of transactions; the plurality of transactions present an input order;
according to the input sequence, sequentially executing preset operation on each transaction in the multiple transactions to obtain the dependency relationship of the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
2. The method of claim 1, wherein the sequentially performing a preset operation on each transaction of the plurality of transactions according to the input order, and after obtaining the dependency relationships of the plurality of transactions, further comprises:
executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship;
and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
3. The method of claim 2, wherein said performing a predetermined operation on each of said plurality of transactions in turn comprises:
for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order;
if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
4. The method of claim 3, further comprising:
if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of the directed graph;
determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, including:
establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph;
executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship, including:
executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
5. An apparatus for obtaining transaction dependencies within a blockchain, comprising:
an acquisition module for acquiring a plurality of transactions; the plurality of transactions present an input order;
the processing module is used for sequentially executing preset operation on each transaction in the multiple transactions according to the input sequence to obtain the dependency relationship of the multiple transactions; the preset operation is as follows: determining a second transaction with the most back input sequence in the preamble shared transactions of the first transaction as a transaction depended on by the first transaction; the preorder shared transaction is a transaction with an input sequence before the first transaction and the same shared variable as the first transaction; the shared variable is a variable which is possessed by at least two interfaces in the interfaces for processing the transaction; the first transaction is any one of the plurality of transactions.
6. The apparatus of claim 5, wherein the processing module is further to:
executing the transaction without the dependent transaction in the plurality of transactions according to the dependency relationship;
and after the execution is finished, updating the dependency relationship and returning to the step of executing the transaction without the dependency transaction in the plurality of transactions according to the dependency relationship.
7. The apparatus of claim 6, wherein the processing module is specifically configured to:
for a first transaction, if a first shared variable in preamble shared variables and a second shared variable of the first transaction are the same shared variable, determining a second transaction corresponding to the first shared variable as a transaction on which the first transaction depends, and updating the first shared variable corresponding to the first transaction; the preamble shared variable is obtained according to a shared variable of a transaction before the first transaction in an input order;
if the preamble shared variable does not include a second shared variable of the first transaction, adding the second shared variable to the preamble shared variable, and setting the second shared variable to correspond to the first transaction.
8. The apparatus of claim 7, wherein the processing module is further to:
if the preamble shared variable is null, determining that the node corresponding to the first transaction is a vertex of the directed graph;
establishing an edge of the second transaction corresponding node pointing to the first transaction corresponding node in the directed graph;
executing the transaction corresponding to the node with the degree of income of 0 in the directed graph; and after the execution, deleting the nodes and the edges of the nodes corresponding to the executed transaction so as to update the directed graph.
9. A computer device comprising a program or instructions that, when executed, perform the method of any of claims 1 to 4.
10. A storage medium comprising a program or instructions which, when executed, perform the method of any one of claims 1 to 4.
CN201910848016.0A 2019-09-09 2019-09-09 Method and device for acquiring transaction dependency relationship in block chain Pending CN110599166A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201910848016.0A CN110599166A (en) 2019-09-09 2019-09-09 Method and device for acquiring transaction dependency relationship in block chain
PCT/CN2020/114229 WO2021047541A1 (en) 2019-09-09 2020-09-09 Method and device for obtaining transaction dependency relationship in blockchain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910848016.0A CN110599166A (en) 2019-09-09 2019-09-09 Method and device for acquiring transaction dependency relationship in block chain

Publications (1)

Publication Number Publication Date
CN110599166A true CN110599166A (en) 2019-12-20

Family

ID=68858195

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910848016.0A Pending CN110599166A (en) 2019-09-09 2019-09-09 Method and device for acquiring transaction dependency relationship in block chain

Country Status (2)

Country Link
CN (1) CN110599166A (en)
WO (1) WO2021047541A1 (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111325928A (en) * 2020-04-01 2020-06-23 中国银行股份有限公司 Business execution method and device of bank self-service equipment
CN112037061A (en) * 2020-08-31 2020-12-04 深圳前海微众银行股份有限公司 Processing method and device for transactions in block chain, electronic equipment and storage medium
WO2021047541A1 (en) * 2019-09-09 2021-03-18 深圳前海微众银行股份有限公司 Method and device for obtaining transaction dependency relationship in blockchain
CN112950185A (en) * 2021-03-11 2021-06-11 杭州复杂美科技有限公司 Transaction fee payment method, device and storage medium based on parallel execution
WO2023103351A1 (en) * 2021-12-06 2023-06-15 深圳前海微众银行股份有限公司 Method and apparatus for determining parallel collision domain of smart contract in blockchain

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107688999A (en) * 2017-08-11 2018-02-13 杭州秘猿科技有限公司 A kind of parallel transaction based on block chain performs method
CN108537543A (en) * 2018-03-30 2018-09-14 百度在线网络技术(北京)有限公司 Method for parallel processing, device, equipment and the storage medium of block chain data
CN108564470A (en) * 2018-04-17 2018-09-21 北京天德科技有限公司 The transaction distribution method of block is built in a kind of block chain parallel
CN109377232A (en) * 2018-12-20 2019-02-22 众安信息技术服务有限公司 The transaction method for sequencing and equipment of block chain based on DAG
CN110135985A (en) * 2019-04-04 2019-08-16 杭州抖音科技有限公司 A kind of parallel execution method and system traded on block chain

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10255108B2 (en) * 2016-01-26 2019-04-09 International Business Machines Corporation Parallel execution of blockchain transactions
CN109636592B (en) * 2017-10-20 2023-02-28 北京航空航天大学 High performance intelligent contract design
CN108595157B (en) * 2018-04-28 2022-05-10 百度在线网络技术(北京)有限公司 Block chain data processing method, device, equipment and storage medium
CN110147273A (en) * 2019-05-17 2019-08-20 深圳前海微众银行股份有限公司 A kind of task executing method and device
CN110599166A (en) * 2019-09-09 2019-12-20 深圳前海微众银行股份有限公司 Method and device for acquiring transaction dependency relationship in block chain

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107688999A (en) * 2017-08-11 2018-02-13 杭州秘猿科技有限公司 A kind of parallel transaction based on block chain performs method
CN108537543A (en) * 2018-03-30 2018-09-14 百度在线网络技术(北京)有限公司 Method for parallel processing, device, equipment and the storage medium of block chain data
CN108564470A (en) * 2018-04-17 2018-09-21 北京天德科技有限公司 The transaction distribution method of block is built in a kind of block chain parallel
CN109377232A (en) * 2018-12-20 2019-02-22 众安信息技术服务有限公司 The transaction method for sequencing and equipment of block chain based on DAG
CN110135985A (en) * 2019-04-04 2019-08-16 杭州抖音科技有限公司 A kind of parallel execution method and system traded on block chain

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021047541A1 (en) * 2019-09-09 2021-03-18 深圳前海微众银行股份有限公司 Method and device for obtaining transaction dependency relationship in blockchain
CN111325928A (en) * 2020-04-01 2020-06-23 中国银行股份有限公司 Business execution method and device of bank self-service equipment
CN111325928B (en) * 2020-04-01 2021-12-21 中国银行股份有限公司 Business execution method and device of bank self-service equipment
CN112037061A (en) * 2020-08-31 2020-12-04 深圳前海微众银行股份有限公司 Processing method and device for transactions in block chain, electronic equipment and storage medium
CN112950185A (en) * 2021-03-11 2021-06-11 杭州复杂美科技有限公司 Transaction fee payment method, device and storage medium based on parallel execution
WO2022188528A1 (en) * 2021-03-11 2022-09-15 杭州复杂美科技有限公司 Transaction fee payment method based on parallel execution, and device and storage medium
CN112950185B (en) * 2021-03-11 2023-10-20 杭州复杂美科技有限公司 Transaction fee payment method, device and storage medium based on parallel execution
WO2023103351A1 (en) * 2021-12-06 2023-06-15 深圳前海微众银行股份有限公司 Method and apparatus for determining parallel collision domain of smart contract in blockchain

Also Published As

Publication number Publication date
WO2021047541A1 (en) 2021-03-18

Similar Documents

Publication Publication Date Title
JP6875557B2 (en) Methods and devices for writing service data to the blockchain system
CN110599166A (en) Method and device for acquiring transaction dependency relationship in block chain
CN108846659B (en) Block chain-based transfer method and device and storage medium
CN110704438B (en) Method and device for generating bloom filter in blockchain
CN111144883B (en) Processing performance analysis method and device for blockchain network
CN107391628A (en) Method of data synchronization and device
CN106033439A (en) Method and system for processing distributed transaction
CN110471923B (en) Processing method and device for blockchain transaction records
CN111861482B (en) Block chain account checking method and system
WO2021027612A1 (en) Method and apparatus for executing transaction in blockchain
CN113743950A (en) Method for performing transactions in a blockchain, blockchain node and blockchain
CN112785408A (en) Account checking method and device based on Hash
CN112650812A (en) Data fragment storage method and device, computer equipment and storage medium
CN113744063B (en) Method and device for executing transaction in block chain
CN113946628A (en) Data synchronization method and device based on interceptor
CN113869902A (en) Block chain transaction execution method and device
US11120513B2 (en) Capital chain information traceability method, system, server and readable storage medium
CN106874341A (en) A kind of database synchronization method
CN114064678A (en) Event data processing method and device and terminal equipment
CN110851178B (en) Inter-process program static analysis method based on distributed graph reachable computation
CN111951112A (en) Intelligent contract execution method based on block chain, terminal equipment and storage medium
CN115098228B (en) Transaction processing method and device, computer equipment and storage medium
CN111159198B (en) Parameter transaction processing method and device, computer equipment and readable storage medium
CN113468224A (en) Method and device for storing and inquiring state data and executing transaction in block chain
CN112150286A (en) Transaction processing method and device based on block chain, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination