Transaction Conflict Detection Method in Blockchain System and Blockchain Node
By using multiple threads to execute transactions in parallel in the blockchain system and constructing query tree to detect conflicts, the dependence on state variable key division and negotiation mechanism in the existing technology is solved, improving the efficiency of transaction conflict detection and simplifying the process.
Patent Information
- Application Number
- CN202210907539.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-07-29
AI Technical Summary
In blockchain systems, the prior art needs to divide the keys of state variables to obtain fields and execute a negotiation mechanism to select field lengths to detect transaction conflicts, resulting in inefficiency and increased complexity.
By executing transactions in parallel through multi-threading, the numerical interval with a predetermined step size is used to determine the read and write set of transactions, and a query tree (such as a trine tree) is constructed to detect transaction conflicts, avoiding the division and negotiation mechanism of the keys of state variables.
It improves the efficiency of transaction conflict detection, reduces dependence on state variable keys, simplifies the conflict detection process, and improves the processing capabilities of blockchain nodes.
Smart Images

Figure CN115220924B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of blockchain technology, and more particularly to a transaction conflict detection method and blockchain node in a blockchain system. Background Art
[0002] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain system, data blocks are linked sequentially in chronological order to form a chain-like data structure, cryptographically guaranteeing an unalterable and unforgeable distributed ledger. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application. Summary of the Invention
[0003] The purpose of the present invention is to provide a transaction conflict detection method and blockchain node in a blockchain system.
[0004] In a first aspect, a transaction conflict detection method in a blockchain system is provided. The method is executed by a blockchain node in the blockchain system, wherein the blockchain node executes multiple transactions belonging to the same block in parallel, wherein the multiple transactions include multiple target transactions whose recipient fields correspond to a first account, and the keys of multiple state variables belonging to the first account form numerical intervals that increase in a predetermined step size. The method comprises: based on the execution results of the multiple target transactions, determining the multiple target transactions as first transactions and / or second transactions, respectively, and determining the numerical intervals formed by the keys of the multiple state variables requested to be queried by the first transaction, and determining the numerical intervals formed by the keys of the multiple state variables requested to be updated by the second transaction; and for each second transaction, determining whether there is a first transaction that conflicts with the second transaction based on the numerical interval of the second transaction, the numerical intervals of each of the first transactions, and the order of the multiple transactions.
[0005] In a second aspect, a blockchain node in a blockchain system is provided, wherein the blockchain node executes multiple transactions belonging to the same block in parallel, wherein the multiple transactions include multiple target transactions whose recipient fields correspond to a first account, and the keys of multiple state variables belonging to the first account form a numerical range that increases in a predetermined step size. The blockchain node includes: a result processing unit for determining the multiple target transactions as first transactions and / or second transactions, respectively, based on the execution results of the multiple target transactions, and determining the numerical range formed by the keys of the multiple state variables requested to be queried by the first transaction, and determining the numerical range formed by the keys of the multiple state variables requested to be updated by the second transaction; and a conflict detection unit for determining, for each second transaction, whether there is a first transaction that conflicts with the second transaction based on the numerical range of the second transaction, the numerical range of each first transaction, and the order of the multiple transactions.
[0006] In a third aspect, a computer-readable storage medium is provided, on which a computer program / instructions are stored. When the computer program is executed in a computing device, the computing device executes the method described in the first aspect.
[0007] In a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0008] In the above embodiment, when a blockchain node executes multiple transactions belonging to the same entity in parallel and there is a target transaction requesting a batch query of multiple state variables belonging to a certain account, the blockchain node no longer relies on the fields obtained by dividing the key of the state variable in the process of completing the conflict detection of the target transaction, and there is no need to execute the corresponding negotiation mechanism to select the field length used for dividing the field. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0010] Figure 1 A schematic diagram of a blockchain system exemplarily provided in the embodiments of this specification;
[0011] Figure 2 This is a flowchart of a transaction conflict detection method in a blockchain system provided in an embodiment of this specification;
[0012] Figure 3 This is a flowchart of another transaction conflict detection method in a blockchain system provided in an embodiment of this specification;
[0013] Figure 4 A schematic diagram of a ternary tree corresponding to a first account provided as an example in an embodiment of this specification;
[0014] Figure 5 A schematic diagram of the data structure of a node in a ternary tree exemplarily provided in an embodiment of this specification;
[0015] Figure 6 This is a schematic diagram of a blockchain node in a blockchain system provided in an embodiment of this specification. DETAILED DESCRIPTION
[0016] To help those skilled in the art better understand the technical solutions in this specification, the following will provide a clear and complete description of the technical solutions in the embodiments of this specification, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. All other embodiments derived by those skilled in the art based on the embodiments in this specification without creative effort shall fall within the scope of protection of this specification.
[0017] Figure 1 This is a schematic diagram of a blockchain system provided as an example in the embodiments of this specification. Figure 1As shown, a blockchain system is a distributed network built with multiple nodes (nodes) / blockchain nodes. Any two nodes within the system can communicate with each other at the application layer through a peer-to-peer (P2P) network. For example, any two nodes from Node 1 to Node 5 can communicate with each other at the application layer through a P2P network. The blockchain system utilizes a chained block structure to construct a decentralized (or multi-centralized) distributed ledger, which is stored on each node (or most nodes) in the distributed blockchain network. Therefore, the blockchain system needs to address the consistency and correctness of the ledger data on each of the multiple nodes in the decentralized (or multi-centralized) network. To this end, each node in the blockchain system runs a blockchain program. Under certain fault tolerance requirements, a consensus mechanism is used to ensure that all loyal nodes have the same transactions, thereby ensuring that all loyal nodes have consistent execution results for the same transactions. Multiple transactions are packaged into blocks, and the world state is updated based on the execution results of these multiple transactions. The current mainstream consensus mechanisms include but are not limited to: Proof of Work (POW), Proof of Stake (POS), Practical Byzantine Fault Tolerance (PBFT) algorithm, HoneyBadgerBFT algorithm, etc.
[0018] Accounts in blockchain systems are generally categorized into two types: externally owned accounts and contract accounts. Contract accounts store smart contract code and the values of associated state variables within that code, and can typically only be activated through external accounts. A single account may contain multiple state variables, each stored as a key-value pair.
[0019] Some accounts in a blockchain system support batch access to their state variables. For example, a requester might initiate a structured query statement through a smart contract to access multiple state variables under the corresponding contract account. This structured query statement will be converted by the blockchain node at the storage layer into a key to access these multiple state variables. Furthermore, blockchain nodes can execute multiple transactions belonging to the same block in parallel through multiple threads. Some of these transactions may have read-write conflicts. To ensure that all transactions are executed correctly, conflict detection is usually required for transactions with potential read-write conflicts, and some transactions with read-write conflicts must be re-executed. For example, thread 1 and thread 2 execute transactions 1 and 2 in the same block in parallel. Transaction 1 requests to update several state variables under contract account A, and transaction 2 requests to query multiple state variables under contract account A. If one of the target state variables that transaction 1 requests to update belongs to the multiple state variables that transaction 2 requests to query, and theoretically, transaction 1 is located before transaction 2 in the block to which it belongs, then the execution result of transaction 1 will affect the execution result of transaction 2. The conflict detection mechanism will find that transaction 2 conflicts with transaction 1, and the blockchain node needs to re-execute transaction 2 after transaction 1 completes execution and submits its execution result.
[0020] If a transaction, such as the aforementioned transaction 2, requests to query multiple state variables belonging to a certain account, the state variable key can be logically divided into multiple fields, each corresponding to a primary index. This allows the multi-level index to record the query results of transaction 2 on multiple state variables. Furthermore, if a transaction, such as transaction 1, requests to update several state variables belonging to the same account, the multi-level index corresponding to transaction 2 can be used to detect whether transaction 2 conflicts with transaction 1. However, in this implementation, it is necessary to ensure that the state variable key has a specific data structure, and the functional module that implements the conflict detection mechanism must also perform a specific negotiation process with the requester in advance to select the field length for dividing the key into multiple fields.
[0021] Embodiments of this specification provide a transaction conflict detection method and blockchain node in a blockchain system. When a blockchain node concurrently executes multiple transactions belonging to the same block, and a target transaction requests a batch query of multiple state variables belonging to a particular account, the blockchain node no longer relies on partitioning the state variable keys to obtain individual fields, nor does it need to implement a corresponding negotiation mechanism to select the field lengths used to partition the fields.
[0022] The method provided in the embodiments of this specification can be executed by a blockchain node in a blockchain system. Some accounts in the blockchain system (hereinafter referred to as first accounts) can support batch access to their state variables. For example, the key of the state variable belonging to the first account is a numeric value, and the keys of multiple state variables belonging to the first account can form a numeric range that increases by a predetermined step size. More specifically, for example, the keys of the multiple state variables are all integers and can form an integer range that increases by a step size of 1. The blockchain node can execute multiple transactions belonging to the same block in parallel through multiple threads. The multiple transactions are arranged in sequence and include multiple target transactions whose recipient fields correspond to the first account. That is, there are multiple target transactions in the multiple transactions that each request access to several state variables belonging to the first account. The first account can be a contract account or an external account.
[0023] Figure 2 This is a flowchart of a transaction conflict detection method in a blockchain system provided in an embodiment of this specification.
[0024] Step 21, based on the execution results of the multiple target transactions, the multiple target transactions are respectively determined as the first transaction and / or the second transaction, and the value range composed of the keys of the multiple state variables queried by the first transaction request is determined, and the value range composed of the keys of the multiple state variables updated by the second transaction request is determined.
[0025] The execution result of the target transaction may, for example, include the target transaction's read-write set, which may specifically include a read set and a write set. If the target transaction requests a query of several state variables belonging to a first account, its read set will include the keys of these state variables. The blockchain node may determine the target transaction as a first transaction if it determines that the read set of the target transaction includes the keys of these state variables belonging to the first account. If the target transaction requests an update of several state variables belonging to the first account, its write set will include the keys of these state variables. The blockchain node may determine the target transaction as a second transaction if it determines that the write set of the target transaction includes the keys of these state variables belonging to the first account. A single target transaction may request both a query and an update of several state variables belonging to a first account, and therefore may be simultaneously determined by the blockchain node as both a first transaction and a second transaction.
[0026] By analyzing the keys in the read set of the first transaction, we can obtain a numerical range consisting of the keys of the various state variables belonging to the first account in the read set. This numerical range is the numerical range consisting of the keys of the several state variables queried by the first transaction. Similarly, by analyzing the keys in the write set of the second transaction, we can obtain a numerical range consisting of the keys of the various state variables belonging to the first account in the write set. This numerical range is the numerical range consisting of the keys of the several state variables updated by the second transaction. It will be understood that when the number of state variables queried / updated by the first / second transaction is multiple, the numerical ranges of the first / second transaction have different upper and lower bounds.
[0027] Step 23: For each second transaction, determine whether there is a first transaction that conflicts with the second transaction based on the numerical interval of the second transaction, the numerical intervals of each first transaction, and the order of the transactions. For each second transaction, for example, the numerical intervals of each first transaction can be matched with the numerical interval of the second transaction. If the numerical interval of a first transaction overlaps with the numerical interval of a second transaction, and the order of the first transaction in the plurality of transactions is greater than the order of the second transaction in the plurality of transactions, then the first transaction is determined to conflict with the second transaction.
[0028] Figure 3 This is a flowchart of another transaction conflict detection method in a blockchain system provided in an embodiment of this specification.
[0029] In step 21, based on the execution results of the multiple target transactions, the multiple target transactions are respectively determined as first transactions and / or second transactions. The value ranges formed by the keys of the multiple state variables requested for query by the first transaction are determined, as well as the value ranges formed by the keys of the multiple state variables requested for update by the second transaction are determined. The implementation process of step 21 is described above and will not be repeated here.
[0030] In step 22, a query tree corresponding to the first account is constructed according to the numerical intervals of each first transaction.
[0031] The query tree is used to record the query status of each of the aforementioned first transactions on the state variables belonging to the first transaction. In other words, the query tree needs to be able to indicate the respective numerical intervals of each first transaction. The query tree can be, for example, a ternary tree, or a tree structure other than a ternary tree. For any current node in the ternary tree, the upper bound of the numerical interval recorded by the left child node of the current node is less than the lower bound of the numerical interval recorded by the current node, the lower bound of the numerical interval recorded by the right child node of the current node is greater than the upper bound of the numerical interval recorded by the current node, and the numerical interval recorded by the middle child node of the current node belongs to the numerical interval recorded by the current node. In addition, the current node can also record several transaction identifiers. The numerical interval recorded by the current node belongs to the numerical interval of the first transaction indicated by the transaction identifier recorded by the current node. The aforementioned transaction identifier can be the arrangement sequence number of the first transaction indicated by it in the aforementioned multiple transactions. In addition, in the process of constructing a ternary tree corresponding to the first account based on the numerical intervals of each first transaction, for each first transaction, the ternary tree corresponding to the first account can be updated once based on the numerical interval of the first transaction, so that the updated ternary tree includes several target nodes, and the numerical intervals recorded respectively for the several target nodes are merged to obtain a numerical interval that is the same as the numerical interval of the first transaction.
[0032] The following specifically takes the aforementioned multiple transactions, including 10 transactions arranged in sequence, as an example. It is assumed that transactions 1 to 4 and transactions 6 to 9 are all target transactions requesting to call smart contract A (that is, the aforementioned first account is the contract account corresponding to smart contract A), and the key of the state variable belonging to the first account is an integer. Transaction 2, transaction 4, transaction 7, transaction 8, and transaction 9 are determined to be first transactions. It is further assumed that the value ranges of the aforementioned first transactions are shown in Table 1 below.
[0033] First transaction Numerical range Transaction 2 [100,200] Transaction 4 [50,150] Transaction 7 [250,300] Transaction 8 [120,180] Transaction 9 [170,300]
[0034] Table 1
[0035] Based on Table 1 of the above example, please continue to see Figure 4 First, we can query the root node of the ternary tree corresponding to the first account based on the numerical range of transaction 2. Since the ternary tree corresponding to the first account has not yet been established, this query will create a root node corresponding to the first account, which is equivalent to the first update of the ternary tree corresponding to the first account. For example, we can create node N1 as the root node of the ternary tree, and record the transaction identifier of transaction 2 and the numerical range [100,200] in node N1.
[0036] Next, the ternary tree corresponding to the first account is queried based on the numerical interval [50,150] of transaction 4, and the second update of the ternary tree corresponding to the first account is completed during the query process. During the query process, the node N1 as the root node can be queried / traversed based on the numerical interval [50,150] of transaction 4, and it is found that the numerical interval [50,150] and the numerical interval [100,200] of node N1 have an overlapping area [100,150]. In this case, it is necessary to continue to query / traverse the neutron nodes of node N1 based on the numerical interval [100,150]. However, since the neutron nodes of node N1 are empty, a new node N2 can be added as the neutron node of node N1 in the ternary tree, and the numerical interval [100,150] and transaction [100,150] can be recorded in node N2. 4; in addition, for the other numerical interval [50,99] that constitutes the numerical interval [50,150] of transaction 4, its upper bound 99 is less than the lower bound 100 of the numerical interval [100,200] recorded in node N1. In this case, it is necessary to continue querying / traversing the left child node of node N1 based on the numerical interval [50,99]. However, the left child node of node N1 is empty. Based on this, a new node N3 can be added as the left child node of node N1 in the ternary tree, and the numerical interval [50,99] and the transaction identifier of transaction 4 can be recorded in node N3.
[0037] Next, the ternary tree corresponding to the first account is queried based on the numeric interval [250,300] of transaction 7. During the query process, the ternary tree corresponding to the first account is updated for the third time. During the query process, node N1, which serves as the root node, is queried / traversed based on the numeric interval [250,300] of transaction 7. It is found that the upper bound of its numeric interval [50,150] is less than the lower bound of the numeric interval [250,300]. In this case, it is necessary to continue quering / traversing the right child node of node N1 based on the numeric interval [250,300]. However, since the right child node of node N1 is empty, node N4 can be added to the ternary tree as the right child node of node N1. The numeric interval [250,300] and the transaction identifier of transaction 7 are recorded in node N4.
[0038] Next, the ternary tree corresponding to the first account is queried based on the numeric interval [120, 180] of transaction 8. During the query process, the ternary tree corresponding to the first account is updated for the fourth time. During the query process, node N1, which is the root node, can be queried / traversed based on the numeric interval [120, 180] of transaction 8. It is found that the numeric interval [120, 180] belongs to the numeric interval [100, 200] of node N1. In this case, it is necessary to continue to query / traverse the child nodes of node N1, and then continue to query / traverse node N2, which is the child node of node N1, based on the numeric interval [120, 180]. When querying / traversing node N2, it can be found that the value interval [120,180] overlaps with the value interval [100,150] of node N2. In this case, it is necessary to traverse the neutron nodes of node N2 according to the value interval [120,150]. However, since the neutron nodes of node N2 are empty, a new node N5 can be added to the ternary tree as the neutron node of node N2, and the value interval [120,150] and the transaction identifier of transaction 8 can be recorded in node N5. For the value interval [120,150] and the transaction identifier of transaction 8, the value interval [120,150] and the transaction identifier of transaction 8 can be recorded in node N5. 50] The other numerical intervals [151, 180] that make up the numerical interval [120, 180] have a lower bound 151 that is greater than the upper bound 150 of the numerical interval [120, 150] recorded in node N2. In this case, it is necessary to continue querying / traversing the right child node of node N2 based on the numerical interval [151, 180]. However, since the right child node of node N2 is empty, a new node N6 can be added to the ternary tree as the right child node of node N2, and the numerical interval [151, 180] and the transaction identifier of transaction 4 can be recorded in node N6.
[0039] Next, the ternary tree corresponding to the first account is queried based on the numeric interval [170, 250] of transaction 9. During this query, the fifth update of the ternary tree corresponding to the first account is completed. During the query, each node in the ternary tree can be queried / traversed based on the numeric interval [170, 250] of transaction 9. The specific query process is similar to the aforementioned process of querying / traversing the ternary tree based on the numeric intervals of transactions 4, 7, and 8. Ultimately, node N7 is added to the ternary tree as a neutron node of node N6, node N8 is added as a right child of node 6, and node N9 is added as a left child of node N4. Transaction 9's transaction identifier and numeric interval [170, 180] are recorded in node N7, transaction 9's transaction identifier and numeric interval [181, 200] are recorded in node N8, transaction 9's transaction identifier and numeric interval [201, 249] are recorded in node N9, and transaction 9's transaction identifier is added to node N4.
[0040] After constructing the ternary tree corresponding to the first account according to the numerical intervals of each first transaction, the corresponding auxiliary information can also be recorded in some or all nodes of the ternary tree. For any current node in the ternary tree, the auxiliary information recorded may include but is not limited to at least one of the following information: the maximum value of each permutation number recorded in the left subtree of the current node, the maximum value of each permutation number recorded in the middle subtree of the current node, and the maximum value of each permutation number recorded in the right subtree of the current node. For example, please continue to refer to Figure 4 In the ternary tree shown, for node N1, its left subtree includes node N3, and node N1 can record the maximum value of each permutation number recorded in its left subtree as permutation number 3; its subtree includes nodes N2, N5, N6, N7 and N8, and node N1 can record the maximum value of each permutation number recorded in its subtree as permutation number 9; its right subtree includes nodes N4 and N9, and node N1 can record the maximum value of each permutation number recorded in its right subtree as permutation number 9.
[0041] Any current node in the ternary tree can also record other information besides the value range, transaction identifier and auxiliary information, such as its left child node, middle child node and right child node, so as to continue to query its child nodes based on the current node. For example, please refer to Figure 5 The data structure of the aforementioned node N1 is provided as an example, which can record: the left child node of node N1 is node N3, the neutron node of node N1 is node N2, the right child node of node N1 is node N4, the maximum value of the permutation number recorded in the left subtree of node N1 is 4, the maximum value of the permutation number recorded in the neutron tree of node N1 is 9, the maximum value of the permutation number recorded in the right subtree of node N1 is 9, the transaction identifier 4 and the numerical range [100,200].
[0042] Step 231 : For each second transaction, determine, based on the query tree, whether there is a third transaction in each first transaction, and the value intervals of the third transaction and the second transaction have an overlapping area.
[0043] If yes, step 233 is executed to determine whether the third transaction conflicts with the second transaction according to the order of the plurality of transactions.
[0044] Let's continue with the example of the query tree being a ternary tree. In step 231, for example, the nodes in the ternary tree can be queried to determine whether there is an overlapping area between the numerical interval recorded in the node and the numerical interval of the second transaction. If so, the first transaction indicated by the several transaction identifiers recorded in the node is determined to be the third transaction. More specifically, the nodes in the ternary tree corresponding to the first transaction can be queried / traversed based on the numerical interval of the second transaction. The process of querying / traversing the ternary tree is similar to the process of updating the ternary tree described above and will not be repeated here. It should be noted that when querying / traversing a node in the ternary tree based on the numerical interval of the second transaction, it can be decided whether to continue querying / traversing any one of the left subtree, right subtree and middle subtree of the node based on the auxiliary information recorded in the node. For example, assuming that transactions 1, 3, 6 and 7 in the aforementioned transactions 1 to 10 are determined to be the second transaction, and assuming that the numerical interval of transaction 6 is [70,140]; the nodes in the ternary tree corresponding to the first transaction can be traversed based on the numerical interval [70,140] of transaction 6. Figure 4 . More specifically, for example, the node N1 as the root node can be queried / traversed first according to the numerical interval [70,140] of transaction 6, thereby finding that the numerical interval [70,140] and the numerical interval [100,200] of node N1 have an overlapping area [100,140]. In this case, it is necessary to continue to query / traverse the neutron nodes of node N1 according to the numerical interval [100,140]. However, before actually querying the neutron nodes of node N1, it is also possible to decide whether to continue to query the neutron nodes of node N1 based on the auxiliary information recorded in node N1. For example, based on the auxiliary information recorded in node N1, it may be found that the maximum value of the permutation number recorded in the neutron tree of node N1 is 9, which is greater than the permutation number of transaction 6, indicating that the execution of transaction 6 may affect the first transaction indicated by the permutation number recorded in the neutron tree of node N1, and then the neutron node N2 of node N1 can be continued to be queried; in addition, for the permutation number with the numerical interval [ 100,140] constitutes the other numerical intervals [70,99] of the numerical interval [70,140] of transaction 6, whose upper bound 99 is less than the lower bound 100 of the numerical interval [100,200] recorded in node N1. In this case, it is necessary to continue querying / traversing the left child node of node N1 based on the numerical interval [100,140]. However, before querying / traversing the left child node of node N1, it is also possible to decide whether to traverse the middle child nodes of node N1 based on the auxiliary information recorded in node N1. For example, based on the auxiliary information recorded in node N1, it may be found that the maximum value of the permutation sequence number recorded in the left subtree of node N1 is 4, which is less than the permutation sequence number of transaction 6. At this time, it means that the execution of transaction 6 is unlikely to affect the first transaction indicated by each permutation sequence number recorded in the left subtree of node N1. Therefore, there is no need to continue querying / traversing the left child node of node N1, thereby improving the efficiency of querying the ternary tree based on the numerical interval of the second transaction.
[0045] After blockchain nodes execute multiple transactions belonging to the same block in parallel through multithreading, they need to submit their respective execution results in the order in which the transactions were arranged. After the execution result of any first transaction is successfully submitted by the blockchain node, the ternary tree can also be updated based on the transaction identifier of the first transaction. For example, the transaction identifier used to indicate the transaction is deleted from each node of the ternary tree, and then the existence of idle nodes in the ternary tree is determined. Idle nodes are nodes that do not record transaction identifiers and whose left child, middle child, and right child are all empty. If idle nodes exist, they are deleted from the ternary tree. Therefore, after submitting the first transaction, the number of nodes in the ternary tree can be reduced, improving the query efficiency of the ternary tree based on the numerical range of other unsubmitted second transactions in the subsequent process.
[0046] Based on the same concept as the aforementioned method embodiment, the embodiment of this specification also provides a blockchain node in a blockchain system, wherein the blockchain node executes multiple transactions belonging to the same block in parallel, wherein the multiple transactions include multiple target transactions whose recipient fields correspond to a first account, and the keys of multiple state variables belonging to the first account form a numerical interval that increases in a predetermined step size. Figure 6 As shown, the blockchain node includes: a result processing unit 61, which is used to determine the multiple target transactions as first transactions and / or second transactions according to the execution results of the multiple target transactions, and determine the numerical interval composed of the keys of the multiple state variables requested to be queried by the first transaction, and determine the numerical interval composed of the keys of the multiple state variables requested to be updated by the second transaction; a conflict detection unit 65, which is used to determine, for each second transaction, whether there is a first transaction that conflicts with the second transaction based on the numerical interval of the second transaction, the numerical intervals of each of the first transactions, and the arrangement order of the multiple transactions.
[0047] In one possible implementation, the blockchain node further includes: a data management unit 63, configured to construct a query tree corresponding to the first account based on the numerical intervals of each of the first transactions; and a conflict detection unit 65, configured to determine, based on the query tree, whether a third transaction exists in each of the first transactions, and the numerical intervals of the third transaction and the second transaction have an overlapping area; and if so, determining whether the third transaction conflicts with the second transaction based on the arrangement order of the multiple transactions.
[0048] In one possible implementation, the query tree is a ternary tree; for any current node in the ternary tree, the upper bound of the numerical interval recorded by the left child node of the current node is smaller than the lower bound of the numerical interval recorded by the current node, the lower bound of the numerical interval recorded by the right child node of the current node is larger than the upper bound of the numerical interval recorded by the current node, and the numerical interval recorded by the neutron node of the current node belongs to the numerical interval recorded by the current node.
[0049] In one possible implementation, the current node records several transaction identifiers; the numerical range recorded in the current node belongs to the numerical range of the first transaction indicated by the transaction identifier recorded in the current node; the conflict detection unit 65 is used to query the current node to determine whether there is an overlapping area between the numerical range recorded in the current node and the numerical range of the second transaction; if so, the first transactions respectively indicated by the several transaction identifiers recorded in the current node are determined as the third transaction.
[0050] In one possible implementation, the transaction identifier is the permutation number of the first transaction indicated by it among the multiple transactions; auxiliary information is also recorded in the current node, and the auxiliary information includes at least one of the following information: the maximum value of each permutation number recorded in the left subtree of the current node, the maximum value of each permutation number recorded in the neutron tree of the current node, and the maximum value of each permutation number recorded in the right subtree of the current node; the conflict detection unit 65 is further used to determine whether to query at least one of the left subtree of the current node, the neutron tree of the current node, and the right subtree of the current node based on the permutation number of the second transaction and the auxiliary information.
[0051] In one possible implementation, the data management unit 63 is used to update the ternary tree corresponding to the first account according to the numerical interval of the first transaction, so that the updated ternary tree includes several target nodes, wherein the numerical intervals recorded respectively by the several target nodes are merged to obtain a numerical interval that is the same as the numerical interval of the first transaction.
[0052] In a possible implementation, the data management unit 63 is further used to, after the execution result of the first transaction is submitted by the blockchain node, delete the transaction identifier used to indicate the first transaction from each node of the ternary tree; determine whether there is an idle node in the ternary tree, wherein the idle node does not record the transaction identifier and its left child node, middle child node, and right child node are all empty; if so, delete the idle node from the ternary tree.
[0053] In a possible implementation, the first account is a contract account.
[0054] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any particular order.
[0055] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0056] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0057] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1A step that specifies a function in one or more boxes.
[0058] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0059] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0060] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules 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 disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0061] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as a method, system, or computer program product. Thus, one or more embodiments of this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0062] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0063] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.
[0064] The foregoing description is merely an example of one or more embodiments of this specification and is not intended to limit the one or more embodiments of this specification. Those skilled in the art will appreciate that various modifications and variations of one or more embodiments of this specification are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification are intended to be included within the scope of the claims.
Claims
1. A transaction conflict detection method in a blockchain system, the method being executed by a blockchain node in the blockchain system, the blockchain node executing multiple transactions belonging to the same block in parallel, the multiple transactions including multiple target transactions whose recipient fields correspond to a first account, and the keys of multiple state variables belonging to the first account forming numerical intervals that increase in a predetermined step size, the method comprising: Determining the multiple target transactions as first transactions and / or second transactions, respectively, based on execution results of the multiple target transactions, and determining a numerical range consisting of keys of multiple state variables requested to be queried by the first transaction, and determining a numerical range consisting of keys of multiple state variables requested to be updated by the second transaction; constructing a query tree corresponding to the first account according to the numerical intervals of each of the first transactions; For each second transaction, determining, according to the query tree, whether a third transaction exists in each first transaction, and the value ranges of the third transaction and the second transaction have an overlapping area; If yes, determine whether the third transaction conflicts with the second transaction according to the arrangement order of the multiple transactions.
2. According to the method according to claim 1, the query tree is a ternary tree; for any current node in the ternary tree, the upper bound of the numerical interval recorded by the left child node of the current node is less than the lower bound of the numerical interval recorded by the current node, the lower bound of the numerical interval recorded by the right child node of the current node is greater than the upper bound of the numerical interval recorded by the current node, and the numerical interval recorded by the neutron node of the current node belongs to the numerical interval recorded by the current node.
3. The method according to claim 2, wherein the current node records a plurality of transaction identifiers; the numerical range recorded by the current node belongs to the numerical range of the first transaction indicated by the transaction identifier recorded by the current node; in, Determining whether a third transaction exists in each of the first transactions according to the query tree includes: querying the current node to determine whether a numerical range recorded by the current node overlaps with a numerical range recorded by the second transaction; If yes, the first transactions respectively indicated by the multiple transaction identifiers recorded in the current node are determined as the third transaction.
4. The method according to claim 3, wherein the transaction identifier is a permutation sequence number of the first transaction indicated by the transaction identifier among the multiple transactions; the current node further records auxiliary information, the auxiliary information comprising at least one of the following: a maximum value of all permutation sequence numbers recorded in a left subtree of the current node, a maximum value of all permutation sequence numbers recorded in a middle subtree of the current node, and a maximum value of all permutation sequence numbers recorded in a right subtree of the current node; The method further comprises: According to the arrangement sequence number of the second transaction and the auxiliary information, it is determined whether to query at least one of the left subtree of the current node, the middle subtree of the current node, and the right subtree of the current node.
5. The method according to claim 2, wherein constructing a query tree corresponding to the first account according to the numerical interval of each first transaction comprises: The ternary tree corresponding to the first account is updated according to the numerical interval of the first transaction, so that the updated ternary tree includes a plurality of target nodes, wherein the numerical intervals respectively recorded by the plurality of target nodes are merged to obtain a numerical interval that is the same as the numerical interval of the first transaction.
6. The method according to claim 2, further comprising: After the execution result of the first transaction is submitted by the blockchain node, deleting the transaction identifier indicating the first transaction from each node of the ternary tree; Determining whether there is an idle node in the ternary tree, wherein the idle node does not record a transaction identifier and its left child node, middle child node, and right child node are all empty; If so, delete the idle node from the ternary tree.
7. The method according to any one of claims 1-6, wherein the first account is a contract account.
8. A blockchain node in a blockchain system, wherein the blockchain node executes multiple transactions belonging to the same block in parallel, the multiple transactions including multiple target transactions whose recipient fields correspond to a first account, and the keys of multiple state variables belonging to the first account form a numerical range that increases in a predetermined step size, the blockchain node comprising: a result processing unit configured to determine, based on the execution results of the multiple target transactions, the multiple target transactions as first transactions and / or second transactions, respectively, and to determine a numerical range consisting of keys of multiple state variables queried by the first transaction request, and to determine a numerical range consisting of keys of multiple state variables updated by the second transaction request; a data management unit, configured to construct a query tree corresponding to the first account according to the numerical interval of each of the first transactions; a conflict detection unit, configured to determine, for each of the second transactions, based on the query tree, whether a third transaction exists in each of the first transactions, and the value intervals of the third transaction and the second transaction have an overlapping area; If yes, it is determined whether the third transaction conflicts with the second transaction according to the arrangement order of the multiple transactions.
9. The blockchain node according to claim 8, wherein the query tree is a ternary tree; for any current node in the ternary tree, the upper bound of the numerical interval recorded by the left child node of the current node is less than the lower bound of the numerical interval recorded by the current node, the lower bound of the numerical interval recorded by the right child node of the current node is greater than the upper bound of the numerical interval recorded by the current node, and the numerical interval recorded by the neutron node of the current node belongs to the numerical interval recorded by the current node.
10. The blockchain node according to claim 9, wherein the current node records a plurality of transaction identifiers; the numerical range recorded by the current node belongs to the numerical range of the first transaction indicated by the transaction identifier recorded by the current node; The conflict detection unit is configured to query the current node to determine whether there is an overlapping area between the numerical interval recorded by the current node and the numerical interval of the second transaction; If yes, the first transactions respectively indicated by the multiple transaction identifiers recorded in the current node are determined as the third transaction.
11. The blockchain node according to claim 10, wherein the transaction identifier is a permutation number of the first transaction indicated by the transaction identifier in the plurality of transactions; the current node further records auxiliary information, the auxiliary information comprising at least one of the following information: a maximum value of permutation numbers recorded in a left subtree of the current node, a maximum value of permutation numbers recorded in a middle subtree of the current node, and a maximum value of permutation numbers recorded in a right subtree of the current node; The conflict detection unit is further configured to determine whether to query at least one of the left subtree of the current node, the middle subtree of the current node, and the right subtree of the current node based on the arrangement sequence number of the second transaction and the auxiliary information.
12. The blockchain node according to claim 9, wherein the data management unit is configured to update the ternary tree corresponding to the first account according to the numerical interval of the first transaction, so that the updated ternary tree includes a plurality of target nodes, wherein the numerical intervals respectively recorded by the plurality of target nodes are merged to obtain a numerical interval that is the same as the numerical interval of the first transaction.
13. The blockchain node according to claim 9, wherein the data management unit is further configured to delete the transaction identifier indicating the first transaction from each node of the ternary tree after the execution result of the first transaction is submitted by the blockchain node; Determining whether there is an idle node in the ternary tree, wherein the idle node does not record a transaction identifier and its left child node, middle child node, and right child node are all empty; If yes, the idle node is deleted from the ternary tree.
14. The blockchain node according to any one of claims 8 to 13, wherein the first account is a contract account.
15. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed in a computing device, the computing device executes the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Transaction data processing method and device and computer equipment
CN112508573A
Hotspot keyword recommendation method and device, terminal and storage medium
CN112905871A
Method and system for realizing storage and query of structured data in block chain system
CN114564500A