WO2024021411A1 - 区块链系统中的交易冲突检测方法及区块链节点 - Google Patents

区块链系统中的交易冲突检测方法及区块链节点 Download PDF

Info

Publication number
WO2024021411A1
WO2024021411A1 PCT/CN2022/135283 CN2022135283W WO2024021411A1 WO 2024021411 A1 WO2024021411 A1 WO 2024021411A1 CN 2022135283 W CN2022135283 W CN 2022135283W WO 2024021411 A1 WO2024021411 A1 WO 2024021411A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
node
numerical interval
recorded
current node
Prior art date
Application number
PCT/CN2022/135283
Other languages
English (en)
French (fr)
Inventor
刘晓建
何家华
Original Assignee
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2024021411A1 publication Critical patent/WO2024021411A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • 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/2308Concurrency control
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • the embodiments of this specification belong to the field of blockchain technology, and particularly relate to a transaction conflict detection method and blockchain nodes in a blockchain system.
  • Blockchain is a new application model of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • data blocks are combined into a chained data structure in a chronological manner and are cryptographically guaranteed to be an untamperable and unforgeable distributed ledger. Due to the characteristics of blockchain, such as decentralization, non-tamperable information, and autonomy, blockchain has also received more and more attention and applications.
  • the purpose of the present invention is to provide a transaction conflict detection method and a blockchain node in a blockchain system.
  • a transaction conflict detection method in a blockchain system is provided.
  • the method is executed by a blockchain node in the blockchain system.
  • the blockchain node executes transactions belonging to the same block in parallel. Multiple transactions include multiple target transactions with a recipient field corresponding to the first account, and keys belonging to multiple state variables of the first account form a numerical interval that increases in a predetermined step size.
  • the method includes: determining the multiple target transactions as first transactions and/or second transactions respectively according to the execution results of the multiple target transactions, and determining the values of several state variables queried by the first transaction request.
  • the numerical interval composed of keys and the numerical interval composed of keys that determine several state variables updated by the second transaction request; for each second transaction, according to the numerical interval of the second transaction, each of the The numerical range of the first transaction and the arrangement order of the multiple transactions determine whether there is a first transaction that conflicts with the second transaction.
  • a blockchain node in a blockchain system executes multiple transactions belonging to the same block in parallel, and the multiple transactions include a recipient field corresponding to the first account.
  • the keys belonging to multiple state variables of the first account form a numerical range that increases in predetermined steps.
  • the blockchain node includes: a result processing unit, configured to determine the plurality of target transactions as the first transaction and/or the second transaction according to the execution results of the plurality of target transactions, and determine the third transaction.
  • a third aspect provides a computer-readable storage medium on which a computer program/instructions are stored.
  • the computer program When executed in a computing device, the computing device performs the method described in the first aspect.
  • a fourth aspect provides a computing device, including a memory and a processor.
  • a computer program is stored in the memory.
  • the processor executes the computer program, the method described in the first aspect is implemented.
  • the blockchain node when the blockchain node executes multiple transactions in parallel and belong to the same transaction, and there is a target transaction request to query multiple state variables belonging to a certain account in batches, the blockchain node completes the conflict detection on the target transaction. In the process, it no longer relies on each field obtained by dividing the key of the state variable, and there is no need to perform a corresponding negotiation mechanism to select the field length used to divide the fields.
  • Figure 1 is a schematic diagram of a blockchain system provided as an example in the embodiment of this specification.
  • Figure 2 is a flow chart of a transaction conflict detection method in a blockchain system provided in the embodiment of this specification;
  • Figure 3 is a flow chart of another transaction conflict detection method in the blockchain system provided in the embodiment of this specification.
  • Figure 4 is a schematic diagram of a ternary tree corresponding to the first account provided as an example in the embodiment of this specification;
  • Figure 5 is a schematic diagram of the data structure of the nodes in the ternary tree provided as an example in the embodiment of this specification;
  • Figure 6 is a schematic diagram of a blockchain node in a blockchain system provided in the embodiment of this specification.
  • FIG. 1 is a schematic diagram of an exemplary blockchain system provided in the embodiment of this specification.
  • the blockchain system is a distributed network established through multiple nodes/blockchain nodes, and any two nodes it contains are connected through a peer-to-peer (P2P) network. Realize the communication connection at the application layer. For example, any two nodes among the nodes 1 to 5 included in it can realize the communication connection at the application layer through the P2P network.
  • the blockchain system uses a decentralized (or multi-centered) distributed ledger constructed by a chain block structure, which is stored on each node (or most nodes) in the distributed blockchain network. Therefore, the blockchain system needs to solve the problem of consistency and correctness of the respective ledger data on multiple decentralized (or multi-centered) nodes.
  • each node of the blockchain system runs a blockchain program.
  • the consensus mechanism is used to ensure that all loyal nodes have the same transactions, thereby ensuring that all loyal nodes have the same
  • the execution results of the transactions are consistent. Multiple transactions arranged in sequence are packaged into blocks and the world state is updated based on the execution results of the 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, Honey Badger Byzantine Fault Tolerance ( HoneyBadgerBFT) algorithm and so on.
  • Accounts in the blockchain system can usually be divided into two types: external accounts (Externally owned account) and contract accounts (contract account); the contract account is used to store smart contract code and related state variables in the smart contract code. ), which can usually only be activated by calling an external account.
  • a single account may contain multiple state variables, and the value of each state variable can be stored in the form of key and value pairs.
  • Some accounts in the blockchain system can support batch access to their state variables.
  • the requester may initiate a structured query statement through a smart contract to access multiple state variables under the corresponding contract account.
  • the structured query statement will be
  • the blockchain node converts it into a key for accessing the multiple state variables at the storage layer.
  • blockchain nodes can execute multiple transactions belonging to the same block in parallel through multi-threads. Some of the multiple transactions may have read and write conflicts. In order to ensure that the multiple transactions can be executed correctly, it is usually necessary to Conflict detection is performed on transactions that may have read and write conflicts, and some transactions with read and write conflicts are re-executed. For example, thread 1 and thread 2 execute transaction 1 and transaction 2 belonging to the same block in parallel.
  • Transaction 1 requests to update several state variables under contract account A
  • transaction 2 requests to query multiple state variables under contract account A. If there is a target state variable among the several state variables requested by transaction 1 to be updated, which belongs to the multiple state variables requested by transaction 2, and theoretically, the position of transaction 1 in the block to which it belongs is before transaction 2, then the execution of transaction 1 The result will affect the execution result of transaction 2. Through the execution conflict detection mechanism, it will be found that transaction 2 conflicts with transaction 1. The blockchain node needs to re-execute transaction 2 after transaction 1 completes the execution and submits its execution result.
  • the key of the state variable can be logically divided into multiple fields. Each field corresponds to a first-level index, so that multi-level indexes can be used.
  • Transaction 2 To record the query of multiple state variables by Transaction 2; furthermore, when there is a transaction such as Transaction 1 that requests to update several state variables belonging to the account, it can be detected based on the multi-level index corresponding to Transaction 2 whether Transaction 2 is consistent with Transaction 1 There is a conflict.
  • the functional module that performs the conflict detection mechanism needs to perform a specific negotiation process with the requester in advance to select the field that divides the key into multiple fields. length.
  • the embodiments of this specification provide a transaction conflict detection method and a blockchain node in a blockchain system.
  • a blockchain node executes multiple transactions belonging to the same block in parallel, and there is a target transaction request to batch query multiple state variables belonging to a certain account, the blockchain node completes the process of conflict detection on the target transaction. It no longer relies on each field obtained by dividing the key of the state variable, and there is no need to perform a corresponding negotiation mechanism to select the field length used to divide the fields.
  • the methods provided in the embodiments of this specification can be executed by blockchain nodes in the blockchain system.
  • Some accounts in the blockchain system (hereinafter referred to as the first account) can support batch access to their state variables, for example
  • the key of the state variable belonging to the first account is a numerical value
  • the keys of the multiple state variables belonging to the first account can form a numerical interval that increases according to a predetermined step size. More specifically, for example, the keys of the multiple state variables are all integers and Can form an integer interval incrementing by step size 1.
  • the blockchain node can execute multiple transactions belonging to the same block in parallel through multi-threads.
  • the multiple transactions are arranged in sequence and the multiple transactions include multiple target transactions with the recipient field corresponding to the first account, that is, the multiple transactions There are multiple target transactions in each transaction that respectively request access to several state variables belonging to the first account.
  • the first account can be a contract account or an external account.
  • Figure 2 is a flow chart of a transaction conflict detection method in a blockchain system provided in the embodiment of this specification.
  • Step 21 Determine the multiple target transactions as the first transaction and/or the second transaction respectively according to the execution results of the multiple target transactions, and determine the numerical range composed of the keys of several state variables queried by the first transaction request, and Determine the numerical range consisting of the keys of several state variables updated by the second transaction request.
  • the execution result of the target transaction may include the read-write set of the target transaction.
  • the read-write set may specifically include a read set and a write set. If the target transaction requests to query several state variables belonging to the first account, its read set will include the keys of the several state variables; the blockchain node can include the keys of several state variables belonging to the first account in the read set that determines the target transaction. In the case of key, determine the target transaction as the first transaction. If the target transaction requests to update several state variables belonging to the first account, its write set will include the keys of the several state variables; the blockchain node can include the keys of several state variables belonging to the first account in the write set that determines the target transaction. In the case of key, determine the target transaction as the second transaction. A single target transaction may request to query and update several state variables belonging to the first account respectively, so a single target transaction may be determined as the first transaction and the second transaction by the blockchain node at the same time.
  • a numerical interval consisting of the keys of each state variable belonging to the first account in the read set can be obtained.
  • This numerical interval is the key of several state variables queried by the first transaction request. composed of numerical intervals.
  • This numerical interval is a number of state variables updated by the second transaction request.
  • the numerical range composed of keys It can be understood that when the first transaction/second transaction requests multiple state variables to be queried/updated, the numerical ranges of the first transaction/second transaction have different upper bounds and lower bounds.
  • Step 23 For each second transaction, determine 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. For each second transaction, for example, the numerical range of each first transaction can be matched with the numerical range of the second transaction respectively. When there is an overlapping area between the numerical range of a first transaction and the numerical range of the second transaction, and When the ranking number of the first transaction in the plurality of transactions is greater than the ranking number of the second transaction in the plurality of transactions, it is determined that the first transaction conflicts with the second transaction.
  • Figure 3 is a flow chart of another transaction conflict detection method in the blockchain system provided in the embodiment of this specification.
  • Step 21 Determine the multiple target transactions as the first transaction and/or the second transaction respectively according to the execution results of the multiple target transactions, and determine the numerical range composed of the keys of several state variables queried by the first transaction request, and Determine the numerical range consisting of the keys of several state variables updated by the second transaction request.
  • the implementation process of step 21 is as mentioned above and will not be described again.
  • step 22 a query tree corresponding to the first account is constructed according to the numerical range of each first transaction.
  • the query tree is used to record the query status of the state variables belonging to the first transaction of each first transaction pair. In other words, the query tree needs to be able to indicate the respective numerical range of each first transaction.
  • the query tree may be, for example, a ternary tree, or may be a tree structure other than a ternary tree.
  • the upper bound of the numerical interval recorded by the current node's left child 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 current node's right child node is greater than the lower bound of the numerical interval recorded by the current node.
  • the upper bound of the numerical interval is used to record the query status of the state variables belonging to the first transaction of each first transaction pair. In other words, the query tree needs to be able to indicate the respective numerical range of each first transaction.
  • the query tree may be, for example, a ternary tree, or may be a tree structure other than a ternary tree.
  • the numerical interval recorded by the child node of the current node belongs to the numerical interval recorded by the current node.
  • the current node may 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 may be the first transaction indicated by it in the aforementioned multiple The sequence number in the transaction.
  • the ternary tree corresponding to the first account can be updated once according to the numerical interval of the first transaction. tree, so that the updated ternary tree includes several target nodes, and the numerical intervals 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.
  • Transaction 1 to Transaction 10 arranged in sequence as an example. It is assumed that Transaction 1 to Transaction 4 and Transaction 6 to Transaction 9 are all target transactions requesting the call of smart contract A (i.e. the aforementioned third transaction).
  • One account is the contract account corresponding to smart contract A)
  • 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 the first transactions, and continue to assume the above
  • the numerical range of each first transaction is shown in Table 1 below.
  • the ternary tree corresponding to the first account is queried based on the value range [50,150] of transaction 4.
  • the ternary tree corresponding to the first account is updated for the second time.
  • node N2 as the neutron node of node N1 in the ternary tree, and add it in Node N2 records the numerical interval [100,150] and the transaction identifier of transaction 4; in addition, for other numerical intervals [50,99] that form the numerical interval [50,150] of transaction 4 with the numerical interval [100,150], its upper bound 99 is smaller than node N1
  • the lower bound of 100 is the numerical interval [100,200] recorded in .
  • the left child node of node N1 is empty. Accordingly, you can Add node N3 as the left child node of node N1 to the ternary tree, and record the value range [50,99] and the transaction identifier of transaction 4 in node N3.
  • the ternary tree corresponding to the first account is queried based on the value range [250,300] of transaction 7.
  • the ternary tree corresponding to the first account is updated for the third time.
  • node N4 as the right child node of node N1 in the ternary tree, and add it to node N4. Record the value range [250,300] and the transaction ID of transaction 7.
  • the ternary tree corresponding to the first account is queried based on the value range [120,180] of transaction 8.
  • the ternary tree corresponding to the first account is updated for the fourth time.
  • node N5 can be added as the neutron node of node N2 in the ternary tree, and the value interval [120,150] and the transaction identifier of transaction 8 are recorded in node N5; for the value with The interval [120,150] constitutes other numerical intervals [151,180] of the numerical interval [120,180].
  • the ternary tree corresponding to the first account is queried based on the value range [170, 250] of transaction 9.
  • the ternary tree corresponding to the first account is updated for the fifth time.
  • the specific query process is similar to the aforementioned query/traverse ternary tree based on the numerical intervals of transaction 4, transaction 7, and transaction 8.
  • node N7 Record the transaction ID and value range [170,180] of transaction 9, record the transaction ID and value range [181,200] of transaction 9 in node N8, record the transaction ID and value range [201,249] of transaction 9 in node N9, and record the transaction ID and value range [201,249] of transaction 9 in node N9.
  • a new transaction identifier is added to record transaction 9 in N4.
  • the corresponding auxiliary information can also be correspondingly recorded in some or all nodes of 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 arrangement number recorded in the left subtree of the current node, the The maximum value of each arrangement number recorded in the neutron tree and the maximum value of each arrangement number recorded in the right subtree of the current node.
  • node N1 its left subtree includes node N3.
  • the maximum value of each arrangement number recorded in its left subtree that can be recorded in node N1 is arrangement number 3;
  • the subtree includes node N2, node N5, node N6, node N7 and node N8.
  • the maximum value of each arrangement number recorded in the subtree can be recorded in node N1.
  • the maximum value of each arrangement number recorded in the subtree is arrangement number 9; its right subtree includes node N4.
  • node N9 the maximum value of each arrangement number recorded in its right subtree that can be recorded in node N1 is arrangement number 9.
  • Any current node in the ternary tree can also record other information besides the numerical interval, transaction identifier and auxiliary information, such as recording its left sub-point, middle sub-node, right sub-node and other information, so as to continue to query its sub-nodes based on the current node. node.
  • the left child node of node N1 is node N3, the middle child node of node N1 is node N2, the right child node of node N1 is node N4,
  • the maximum value of the arrangement number recorded in the left subtree of node N1 is 4, the maximum value of the arrangement number recorded in the neutron subtree of node N1 is 9, and the maximum value of the arrangement number recorded in the right subtree of node N1 is 9.
  • Step 231 For each second transaction, determine whether there is a third transaction in each first transaction according to the query tree. The numerical ranges of the third transaction and the second transaction have overlapping areas.
  • step 233 is executed to determine whether there is a conflict between the third transaction and the second transaction according to the arrangement order of the multiple transactions.
  • the above query tree is a ternary tree.
  • the node in the ternary tree can be queried to determine whether there is an overlapping area between the numerical interval recorded by the node and the numerical interval of the second transaction. If so, the first transaction identifier respectively indicated by several transaction identifiers recorded in the node will be used.
  • the transaction is determined to be the third transaction. More specifically, the nodes in the ternary tree corresponding to the first transaction can be queried/traversed according to the value range of the second transaction.
  • the process of querying/traversing the ternary tree is similar to the aforementioned process of updating the ternary tree, and will not be described again here.
  • the maximum sequence number recorded in the neutron tree of node N1 is 9, which is greater than the sequence number of transaction 6, indicating that the execution of transaction 6 may affect the sequence number of node N1.
  • the first transaction indicated by the arrangement number recorded in the neutron tree can then continue to query the neutron node N2 of node N1; in addition, for other numerical intervals [70] that form the numerical interval [70,140] of transaction 6 with the numerical interval [100,140] ,99], its upper bound 99 is smaller than the lower bound 100 of the numerical interval [100,200] recorded in node N1.
  • the blockchain node After the blockchain node executes multiple transactions belonging to the same block in parallel through multi-threads, it needs to submit its respective execution results in sequence according to the order of the multiple transactions.
  • the ternary tree can also be updated based on the transaction identifier of the first transaction. For example, delete the transaction identifier used to indicate the transaction from each node of the ternary tree, and then determine whether there is an idle node in the ternary tree.
  • An idle node refers to an idle node that has no recorded transaction identifier and its left child node, middle child node, and right child node are all Empty node. If an idle node exists, delete the idle node from the ternary tree. Therefore, after the first transaction is submitted, the number of nodes in the ternary tree can be reduced, and the query efficiency when querying the ternary tree based on the numerical range of other unsubmitted second transactions in the subsequent process is improved.
  • the embodiments of this specification also provide a blockchain node in the blockchain system.
  • the blockchain node executes multiple transactions belonging to the same block in parallel.
  • the multiple transactions include multiple target transactions with a recipient field corresponding to the first account, and the keys belonging to the multiple state variables of the first account form a numerical interval that increases in a predetermined step size.
  • the blockchain node includes: a result processing unit 61, configured to determine the multiple target transactions as first transactions and/or second transactions according to the execution results of the multiple target transactions.
  • the conflict detection unit 65 uses For each second transaction, it is determined whether there is a conflict with the second transaction based on the numerical interval of the second transaction, the numerical interval of each first transaction and the arrangement order of the multiple transactions. First transaction.
  • the blockchain node further includes: a data management unit 63, configured to construct a query tree corresponding to the first account according to the numerical interval of each first transaction; the conflict The detection unit 65 is configured to determine whether there is a third transaction in each of the first transactions according to the query tree, and the numerical intervals of the third transaction and the second transaction have an overlapping area; if so, according to the The arrangement order of multiple transactions determines whether there is a conflict between the third transaction and the second transaction.
  • a data management unit 63 configured to construct a query tree corresponding to the first account according to the numerical interval of each first transaction
  • the conflict The detection unit 65 is configured to determine whether there is a third transaction in each of the first transactions according to the query tree, and the numerical intervals of the third transaction and the second transaction have an overlapping area; if so, according to the The arrangement order of multiple transactions determines whether there is a conflict between the third transaction and the second transaction.
  • 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 current node record The lower bound of the numerical interval, 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 current node The recorded value range.
  • several transaction identifiers are recorded in the current node; 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 conflict detection unit 65 is used 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 so, then combine several values recorded in the current node.
  • the first transaction respectively indicated by the transaction identifier is determined to be the third transaction.
  • the transaction identifier is the sequence number of the first transaction it indicates among the multiple transactions; auxiliary information is also recorded in the current node, and the auxiliary information includes the following items At least one item of information: the maximum value of each arrangement number recorded in the left subtree of the current node, the maximum value of each arrangement number recorded in the neutron tree of the current node, and the right subtree of the current node. The maximum value of each arrangement number recorded in the tree; the conflict detection unit 65 is also used to determine whether to query the left subtree of the current node, the At least one of the neutron subtree of the current node and the right subtree of the current node.
  • the data management unit 63 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 several targets. node, wherein the numerical intervals recorded by the plurality of target nodes are combined to obtain a numerical interval that is the same as the numerical interval of the first transaction.
  • the data management unit 63 is also configured to delete the indicator from each node of the ternary tree after the execution result of the first transaction is submitted by the blockchain node.
  • the transaction identifier of the first transaction determine whether there is an idle node in the ternary tree, where the transaction identifier is not recorded in the idle node and its left sub-node, middle sub-node and right sub-node are all empty; if so, Then delete the idle node from the ternary tree.
  • the first account is a contract account.
  • These computer program instructions may also be stored in a computer-readable memory that causes a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction means, the instructions
  • the device implements the functions specified in a process or processes of the flowchart and/or a block or blocks of the block diagram.
  • These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing a series of operating steps to be performed on the computer or other programmable device to produce computer-implemented processing, thereby executing on the computer or other programmable device.
  • Instructions provide steps for implementing the functions specified in a process or processes of a flowchart diagram and/or a block or blocks of a block diagram.
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer-readable media, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
  • Information may be computer-readable instructions, data structures, modules of programs, 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), and read-only memory.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • read-only memory read-only memory
  • ROM read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technology
  • compact disc read-only memory CD-ROM
  • DVD digital versatile disc
  • Magnetic tape cartridges magnetic tape disk storage, graphene storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device.
  • computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects. Furthermore, one or more embodiments of the present description may employ a computer program implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. Product form.
  • computer-usable storage media including, but not limited to, disk storage, CD-ROM, optical storage, etc.
  • program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types.
  • program modules may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network.
  • program modules may be located in both local and remote computer storage media including storage devices.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种区块链系统中的交易冲突检测方法及区块链节点。该方法由区块链系统中的区块链节点执行,该区块链节点中通过多线程并行执行属于相同区块的多个交易,该多个交易中包括接收方字段对应第一账户的多个目标交易,属于第一账户的多个状态变量的key组成按预定步长递增的数值区间。该方法包括:根据多个目标交易的执行结果,将多个目标交易分别确定为第一交易和/或第二交易,并确定第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定第二交易请求更新的若干状态变量的key所组成的数值区间;对于每个第二交易,根据该第二交易的数值区间、各个第一交易的数值区间以及该多个交易的排列顺序,确定是否存在与第二交易冲突的第一交易。

Description

区块链系统中的交易冲突检测方法及区块链节点
本申请要求于2022年7月29日提交中国国家知识产权局、申请号为202210907539.X、申请名称为“区块链系统中的交易冲突检测方法及区块链节点”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本说明书实施例属于区块链技术领域,尤其涉及一种区块链系统中的交易冲突检测方法及区块链节点。
背景技术
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链系统中按照时间顺序将数据区块以顺序相连的方式组合成链式数据结构,并以密码学方式保证的不可篡改和不可伪造的分布式账本。由于区块链具有去中心化、信息不可篡改、自治性等特性,区块链也受到人们越来越多的重视和应用。
发明内容
本发明的目的在于提供一种区块链系统中的交易冲突检测方法及区块链节点。
第一方面,提供了一种区块链系统中的交易冲突检测方法,所述方法由所述区块链系统中的区块链节点执行,所述区块链节点并行执行属于相同区块的多个交易,所述多个交易中包括接收方字段对应第一账户的多个目标交易,属于所述第一账户的多个状态变量的key组成按预定步长递增的数值区间。所述方法包括:根据所述多个目标交易的执行结果,将所述多个目标交易分别确定为第一交易和/或第二交易,并确定所述第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定所述第二交易请求更新的若干状态变量的key所组成的数值区间;对于每个所述第二交易,根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易。
第二方面,提供了一种区块链系统中的区块链节点,所述区块链节点并行执行属于相同区块的多个交易,所述多个交易中包括接收方字段对应第一账户的多个目标交 易,属于所述第一账户的多个状态变量的key组成按预定步长递增的数值区间。所述区块链节点包括:结果处理单元,用于根据所述多个目标交易的执行结果,将所述多个目标交易分别确定为第一交易和/或第二交易,并确定所述第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定所述第二交易请求更新的若干状态变量的key所组成的数值区间;冲突检测单元,用于对于每个所述第二交易,根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易。
第三方面,提供了一种计算机可读存储介质,其上存储有计算机程序/指令,当所述计算机程序在计算设备中执行时,计算设备执行第一方面中所述的方法。
第四方面,提供了一种计算设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器执行所述计算机程序时,实现第一方面中所述的方法。
上述实施例中,当区块链节点并行执行的属于相同的多个交易中,存在目标交易请求批量查询属于某个账户的多个状态变量时,区块链节点在完成对目标交易进行冲突检测的过程中,不再依赖于通过对状态变量的key进行划分以得到的各个字段,更无需执行通过相应的协商机制来选取用于划分字段的字段长度。
附图说明
为了更清楚地说明本说明书实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本说明书实施例中示例性提供的区块链系统的示意图;
图2为本说明书实施例中提供的一种区块链系统中的交易冲突检测方法的流程图;
图3为本说明书实施例中提供的另一种区块链系统中的交易冲突检测方法的流程图;
图4为本说明书实施例中示例性提供的与第一账户对应的三叉树的示意图;
图5为本说明书实施例中示例性提供的三叉树中的节点的数据结构的示意图;
图6为本说明书实施例中提供的一种区块链系统中的区块链节点的示意图。
具体实施方式
为了使本技术领域的人员更好地理解本说明书中的技术方案,下面将结合本说明 书实施例中的附图,对本说明书实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本说明书保护的范围。
图1为本说明书实施例中示例性提供的区块链系统的示意图。如图1所示,区块链系统是通过多个节点(Node)/区块链节点来建立的分布式网络,其包含的任意两个节点间通过点对点(Peer-to-Peer,P2P)网络实现在应用层的通信连接,例如其包含的节点1~节点5中任意两个节点间均可通过P2P网络实现在应用层的通信连接。区块链系统利用链式区块结构构造的去中心化(或称为多中心化)的分布式账本,保存于分布式的区块链网络中的每个节点(或大多节点上)上,因此区块链系统需要解决去中心化(或多中心化)的多个节点上各自的账本数据的一致性和正确性的问题。鉴于此,区块链系统的每个节点上都运行着区块链程序,在一定容错需求的设计下,通过共识(consensus)机制保证所有忠诚节点具有相同的交易,从而保证所有忠诚节点对相同交易的执行结果一致,将按顺序排列的多个交易打包成区块并基于该多个交易的执行结果更新世界状态。其中当前主流的共识机制包括但不限于:工作量证明(Proof of Work,POW)、股权证明(Proof of Stake,POS)、实用拜占庭容错(Practical Byzantine Fault Tolerance,PBFT)算法,蜜獾拜占庭容错(HoneyBadgerBFT)算法等等。
区块链系统中的账户通常可以被划分为外部账户(Externally owned account)和合约账户(contract account)两种类型;其中合约账户用于存储智能合约代码以及智能合约代码中相关状态变量(state variable)的值,其通常只能通过外部账户进行调用激活。单个账户下可能包含多个状态变量,可以采用键值对(key and value pair)的形式来存储各个状态变量的值。
区块链系统中的部分账户能够支持对其状态变量进行批量访问,例如请求者可能通过智能合约发起结构化查询语句来访问相应合约账户下的多个状态变量,该结构化查询语句将会被区块链节点在存储层转换成访问该多个状态变量的key。此外,区块链节点可以通过多线程并行执行属于相同区块的多个交易,该多个交易中的部分交易可能存在读写冲突;进而为了保证该多个交易均能被正确执行,通常需要对可能存在读写冲突的交易进行冲突检测,并对某些存在读写冲突的交易进行重新执行。举例来说,线程1和线程2并行执行属于相同区块的交易1和交易2,交易1请求更新合约账户A下的若干状态变量,交易2的请求查询合约账户A下的多个状态变量,如果交易1请求更新 的若干状态变量中存在某个目标状态变量属于交易2请求查询的多个状态变量,而且理论上交易1在其所属区块中的位置位于交易2之前,则交易1的执行结果会影响交易2的执行结果,通过执行冲突检测机制会发现交易2与交易1存在冲突,需要区块链节点在交易1完成执行并提交其执行结果后,重新执行交易2。
如果存在某个交易例如前述交易2请求查询属于某个账户的多个状态变量,可以将状态变量的key在逻辑上分成多个字段,每个字段各自对应一级索引,从而可以通过多级索引来记录交易2对多个状态变量的查询情况;进而,当存在某个交易例如交易1请求更新属于该账户的若干状态变量时,可以根据交易2对应的多级索引检测交易2是否与交易1存在冲突。然而在该实施方式中,需要确保状态变量的key具有特定的数据结构,而且还需要执行冲突检测机制的功能模块与请求者预先执行特定的协商过程,以选取将key划分成多个字段的字段长度。
本说明书实施例中提供了一种区块链系统中的交易冲突检测方法和区块链节点。当区块链节点并行执行属于相同区块的多个交易中,存在目标交易请求批量查询属于某个账户的多个状态变量时,区块链节点在完成对目标交易进行冲突检测的过程中,不再依赖于通过对状态变量的key进行划分以得到的各个字段,更无需执行通过相应的协商机制来选取用于划分字段的字段长度。
本说明书实施例中提供的方法可以由区块链系统中的区块链节点执行,该区块链系统中的部分账户(以下表述为第一账户)能够支持对其状态变量进行批量访问,例如属于第一账户的状态变量的key为数值,且属于第一账户的多个状态变量的key可以组成按预定步长递增的数值区间,更具体地例如该多个状态变量的key均为整数且能够组成按照步长1递增的整数区间。该区块链节点可以通过多线程并行执行属于相同区块的多个交易,该多个交易按顺序排列且该多个交易中包括接收方字段对应第一账户的多个目标交易,即该多个交易中存在多个目标交易分别请求访问属于第一账户的若干状态变量。第一账户可以是合约账户或外部账户。
图2为本说明书实施例中提供的一种区块链系统中的交易冲突检测方法的流程图。
步骤21,根据多个目标交易的执行结果,将多个目标交易分别确定为第一交易和/或第二交易,并确定第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定第二交易请求更新的若干状态变量的key所组成的数值区间。
目标交易的执行结果例如可以包括该目标交易的读写集,读写集具体可以包括读集和写集。如果目标交易请求查询属于第一账户的若干状态变量,则其读集中将会包 括该若干状态变量的key;区块链节点可以在确定目标交易的读集中包括属于第一账户的若干状态变量的key的情况下,将目标交易确定为第一交易。如果目标交易请求更新属于第一账户的若干状态变量,则其写集中将会包括该若干状态变量的key;区块链节点可以在确定目标交易的写集中包括属于第一账户的若干状态变量的key的情况下,将目标交易确定为第二交易。单个目标交易可能分别请求查询和更新属于第一账户的若干状态变量,因此单个目标交易可能同时被区块链节点确定为第一交易和第二交易。
可以通过分析第一交易的读集中的key,获得由该读集中属于第一账户的各个状态变量的key所组成的数值区间,该数值区间即是第一交易请求查询的若干状态变量的key所组成的数值区间。类似的,可以通过分析第二交易的写集中的key,获得由该写集中属于第一账户的各个状态变量的key所组成的数值区间,该数值区间即是第二交易请求更新的若干状态变量的key所组成的数值区间。可以理解的是,当第一交易/第二交易请求查询/更新的若干状态变量的数量为多个时,第一交易/第二交易的数值区间具有不同的上界和下界。
步骤23,对于每个第二交易,根据第二交易的数值区间、各个第一交易的数值区间以及多个交易的排列顺序,确定是否存在与第二交易冲突的第一交易。对于每个第二交易,例如可以将各个第一交易的数值区间分别与该第二交易的数值区间进行匹配,当某个第一交易的数值区间与第二交易的数值区间存在重叠区域,并且该第一交易在前述多个交易中的排列序号大于该第二交易在前述多个交易中的排列序号时,确定该第一交易与该第二交易存在冲突。
图3为本说明书实施例中提供的另一种区块链系统中的交易冲突检测方法的流程图。
步骤21,根据多个目标交易的执行结果,将多个目标交易分别确定为第一交易和/或第二交易,并确定第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定第二交易请求更新的若干状态变量的key所组成的数值区间。步骤21的实现过程参照前文,不再赘述。
在步骤22,根据各个第一交易的数值区间构造与第一账户对应的查询树。
查询树用于记录前述各个第一交易对属于第一交易的状态变量的查询情况,换而言之即查询树需要能够指示每个第一交易各自的数值区间。查询树例如可以为三叉树,也可以是除三叉树以外的树形结构。对于三叉树中的任一当前节点,当前节点的左子节点记录的数值区间的上界小于当前节点记录的数值区间的下界,当前节点的右子节 点记录的数值区间的下界大于当前节点记录的数值区间的上界,当前节点的中子节点记录的数值区间属于当前节点记录的数值区间。此外当前节点中还可以记录有若干交易标识,当前节点记录的数值区间属于当前节点记录的交易标识所指示的第一交易的数值区间,前述交易标识可以是其指示的第一交易在前述多个交易中的排列序号。此外在根据各个第一交易的数值区间构造与第一账户对应的三叉树的过程中,对于每个第一交易,均可以根据该第一交易的数值区间更新1次与第一账户对应的三叉树,从而使得更新后的三叉树中包括若干目标节点,对该若干目标节点分别记录的数值区间进行合并以得到的数值区间相同于该第一交易的数值区间。
下面具体以前述多个交易中包括依次排列的交易1~交易10等10个交易为例,假设交易1~交易4、交易6~交易9均是请求调用智能合约A的目标交易(即前述第一账户是智能合约A所对应的合约账户),属于第一账户的状态变量的key为整数,交易2、交易4、交易7、交易8、交易9被确定为第一交易,而且继续假设前述各个第一交易的数值区间如下表1所示。
第一交易 数值区间
交易2 [100,200]
交易4 [50,150]
交易7 [250,300]
交易8 [120,180]
交易9 [170,300]
表1
基于上述示例的表1,请继续参见图4。可以首先基于交易2的数值区间查询与第一账户对应的三叉树的根节点,由于此时并未建立与第一账户的三叉树,因此本次查询会创建与第一账户对应的根节点,相当于第1次更新与第一账户对应的三叉树。具体例如可以创建三叉树中作为根节点的节点N1,并在节点N1中记录交易2的交易标识以及数值区间[100,200]。
接着,根据交易4的数值区间[50,150]查询与第一账户对应的三叉树,查询过程中完成第2次更新与第一账户对应的三叉树。查询过程中具体可以根据交易4的数值区间[50,150]查询/遍历作为根节点的节点N1,从而发现数值区间[50,150]与节点N1的数值区间[100,200]存在重叠区域[100,150],此种情况下需要根据数值区间[100,150]继续查询/遍历节点N1的中子节点,然而由于节点N1的中子节点为空,可以在三叉树中新增作为 节点N1的中子节点的节点N2,并在节点N2中记录数值区间[100,150]以及交易4的交易标识;此外对于与数值区间[100,150]组成交易4的数值区间[50,150]的其它数值区间[50,99],其上界99小于节点N1中记录的数值区间[100,200]的下界100,此种情况下需要基于数值区间[50,99]继续查询/遍历节点N1的左子节点,然而节点N1的左子节点为空,据此可以在三叉树中新增作为节点N1的左子节点的节点N3,并在节点N3中记录数值区间[50,99]和交易4的交易标识。
接着,根据交易7的数值区间[250,300]查询与第一账户对应的三叉树,查询过程中完成第3次更新与第一账户对应的三叉树。查询过程中可以根据交易7的数值区间[250,300]查询/遍历作为根节点的节点N1,发现其数值区间[50,150]的上界小于数值区间[250,300]的下界,此种情况下需要根据数值区间[250,300]继续查询/遍历节点N1的右子节点,然而由于节点N1的右子节点为空,据此可以在三叉树中新增作为节点N1的右子节点的节点N4,并在节点N4中记录数值区间[250,300]以及交易7的交易标识。
接着,根据交易8的数值区间[120,180]查询与第一账户对应的三叉树,查询过程中完成第4次更新与第一账户对应的三叉树。查询过程中可以根据交易8的数值区间[120,180]查询/遍历作为根节点的节点N1,发现数值区间[120,180]属于节点N1的数值区间[100,200],此种情况下需要继续查询/遍历节点N1的中子节点,进而基于数值区间[120,180]继续查询/遍历作为节点N1的中子节点的节点N2。查询/遍历节点N2时可以发现数值区间[120,180]与节点N2的数值区间[100,150]存在重叠区域[120,150],此种情况下需要根据数值区间[120,150]遍历节点N2的中子节点,然而由于节点N2的中子节点为空,据此可以在三叉树中新增作为节点N2的中子节点的节点N5,并在节点N5中记录数值区间[120,150]以及交易8的交易标识;对于与数值区间[120,150]组成数值区间[120,180]的其它数值区间[151,180],其下界151大于节点N2中记录的数值区间[120,150]的上界150,此种情况下需要根据数值区间[151,180]继续查询/遍历节点N2的右子节点,然而由于节点N2的右子节点为空,据此可以在三叉树中新增作为节点N2的右子节点的节点N6,并在节点N6中记录数值区间[151,180]和交易4的交易标识。
接着,根据交易9的数值区间[170,250]查询与第一账户对应的三叉树,查询过程中完成第5次更新与第一账户对应的三叉树。查询过程中可以根据交易9的数值区间[170,250]查询/遍历三叉树中的各个节点,具体查询过程相似于前述基于交易4、交易7、交易8各自的数值区间查询/遍历三叉树的过程,最终可以实现在三叉树中新增作为节点N6的中子节点的节点N7,新增作为节点6的右子节点的节点N8,新增作为节点N4的 左子节点的节点N9,在节点N7中记录交易9的交易标识以及数值区间[170,180],在节点N8中记录交易9的交易标识以及数值区间[181,200],在节点N9中记录交易9的交易标识以及数值区间[201,249],以及在节点N4中新增记录交易9的交易标识。
根据各个第一交易的数值区间完成构造与第一账户对应的三叉树之后,还可以在三叉树的部分或全部节点中对应的记录其各自对应的辅助信息。对于三叉树中任意的当前节点而言,其记录的辅助信息可以包括但不限于如下各项信息中的至少一项:当前节点的左子树中记录的各个排列序号的最大值、当前节点的中子树中记录的各个排列序号的最大值和当前节点的右子树中记录的各个排列序号的最大值。例如请继续参照图4所示的三叉树,对于节点N1而言,其左子树中包括节点N3,节点N1中可以记录其左子树中记录的各个排列序号的最大值为排列序号3;其中子树中包括节点N2、节点N5、节点N6、节点N7和节点N8,节点N1中可以记录其中子树中记录的各个排列序号的最大值为排列序号9;其右子树中包括节点N4和节点N9,节点N1中可以记录其右子树中记录的各个排列序号的最大值为排列序号9。
三叉树中任意的当前节点还可以记录除数值区间、交易标识以及辅助信息以外的其它信息,例如记录其左子点、中子节点以及右子节点等其它信息,以便基于当前节点继续查询其子节点。例如请参照图5示例性提供的前述节点N1的数据结构,其中可以记录:节点N1的左子节点为节点N3、节点N1的中子节点为节点N2、节点N1的右子节点为节点N4、节点N1的左子树中记录的排列序号的最大值为4、节点N1的中子树中记录的排列序号的最大值为9、节点N1的右子树中记录的排列序号的最大值为9、交易标识4以及数值区间[100,200]。
步骤231,对于每个第二交易,根据查询树确定各个第一交易中是否存在第三交易,第三交易和第二交易的数值区间具有重叠区域。
如果是则执行步骤233,根据多个交易的排列顺序确定第三交易与第二交易是否存在冲突。
继续以前述查询树是三叉树为例。步骤231中例如可以查询三叉树中的节点,以确定该节点记录的数值区间与第二交易的数值区间是否存在重叠区域,如果是则将该节点中记录的若干交易标识所分别指示的第一交易确定为第三交易。更具体地说,可以根据第二交易的数值区间查询/遍历与第一交易对应的三叉树中的节点,查询/遍历三叉树的过程类似于前述更新三叉树的过程,此处不再赘述。需要特别说明的是,在根据第二交易的数值区间查询/遍历三叉树中的某个节点时,可以基于该节点中记录的辅 助信息决策是否继续查询/遍历该节点的左子树、右子树以及中子树中的任意一项。举例来说,假设前述交易1~交易10中的交易1、交易3、交易6和交易7被确定为第二交易,并且假设交易6的数值区间是[70,140];可根据交易6的数值区间[70,140]遍历如图4中所示三叉树的各个节点。更具体地,例如可以首先根据交易6的数值区间[70,140]查询/遍历作为根节点的节点N1,从而发现数值区间[70,140]与节点N1的数值区间[100,200]存在重叠区域[100,140],此种情况下需要根据数值区间[100,140]继续查询/遍历节点N1的中子节点,然而在实际查询节点N1的中子节点前,还可以基于节点N1中记录的辅助信息决策是否继续查询节点N1的中子节点,例如基于节点N1中记录的辅助信息可能发现节点N1的中子树中记录的排列序号的最大值为9,其大于交易6的排列序号,说明交易6的执行可能影响节点N1的中子树中记录的排列序号所指示的第一交易,进而可以继续查询节点N1的中子节点N2;此外对于与数值区间[100,140]组成交易6的数值区间[70,140]的其它数值区间[70,99],其上界99小于节点N1中记录的数值区间[100,200]的下界100,此种情况下需要根据数值区间[100,140]继续查询/遍历节点N1的左子节点,然而在查询/遍历节点N1的左子节点前,还可以基于节点N1中记录的辅助信息决策是否遍历节点N1的中子节点,例如基于节点N1中记录的辅助信息可能发现节点N1的左子树中记录的排列序号的最大值为4,其小于交易6的排列序号,此时说明交易6的执行不可能影响节点N1的左子树中记录的各个排列序号所分别指示的第一交易,进而无需继续查询/遍历节点N1的左子节点,从而提高基于第二交易的数值区间查询三叉树的效率。
区块链节点通过多线程并行执行属于相同区块的多个交易后,需要按照多个交易的排列顺序依次提交其各自的执行结果。当任意第一交易的执行结果被区块链节点成功提交后,还可以基于该第一交易的交易标识对应的更新三叉树。例如从三叉树的各个节点中删除用于指示该交易的交易标识,进而确定三叉树中是否存在空闲节点,空闲节点是指未记录交易标识且其左子节点、中子节点和右子节点均为空的节点。如果存在空闲节点则从三叉树中删除该空闲节点。从而,在提交第一交易后可以减少三叉树中节点的数量,提高后续过程中基于未提交的其它第二交易的数值区间查询三叉树时的查询效率。
与前述方法实施例基于相同的构思,本说明书实施例中还提供了一种区块链系统中的区块链节点,所述区块链节点并行执行属于相同区块的多个交易,所述多个交易中包括接收方字段对应第一账户的多个目标交易,属于所述第一账户的多个状态变量 的key组成按预定步长递增的数值区间。如图6所示,所述区块链节点包括:结果处理单元61,用于根据所述多个目标交易的执行结果,将所述多个目标交易分别确定为第一交易和/或第二交易,并确定所述第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定所述第二交易请求更新的若干状态变量的key所组成的数值区间;冲突检测单元65,用于对于每个所述第二交易,根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易。
在一种可能的实施方式中,所述区块链节点还包括:数据管理单元63,用于根据各个所述第一交易的数值区间构造与所述第一账户对应的查询树;所述冲突检测单元65,用于根据所述查询树确定各个所述第一交易中是否存在第三交易,所述第三交易和所述第二交易的数值区间具有重叠区域;如果是,则根据所述多个交易的排列顺序确定所述第三交易与所述第二交易是否存在冲突。
在一种可能的实施方式中,所述查询树是三叉树;对于所述三叉树中的任一当前节点,所述当前节点的左子节点记录的数值区间的上界小于所述当前节点记录的数值区间的下界,所述当前节点的右子节点记录的数值区间的下界大于所述当前节点记录的数值区间的上界,所述当前节点的中子节点记录的数值区间属于所述当前节点记录的数值区间。
在一种可能的实施方式中,所述当前节点中记录有若干交易标识;所述当前节点记录的数值区间,属于所述当前节点记录的交易标识所指示的第一交易的数值区间;所述冲突检测单元65,用于查询所述当前节点,以确定所述当前节点记录的数值区间与所述第二交易的数值区间是否存在重叠区域;如果是,则将所述当前节点中记录的若干交易标识所分别指示的第一交易确定为第三交易。
在一种可能的实施方式中,所述交易标识是其指示的第一交易在所述多个交易中的排列序号;所述当前节点中还记录有辅助信息,所述辅助信息包括如下各项信息中的至少一项:所述当前节点的左子树中记录的各个排列序号的最大值、所述当前节点的中子树中记录的各个排列序号的最大值和所述当前节点的右子树中记录的各个排列序号的最大值;所述冲突检测单元65,还用于根据所述第二交易的排列序号和所述辅助信息,确定是否查询所述当前节点的左子树、所述当前节点的中子树以及所述当前节点的右子树中的至少一项。
在一种可能的实施方式中,所述数据管理单元63用于根据所述第一交易的数值区 间更新与所述第一账户对应的三叉树,使更新后的所述三叉树中包括若干目标节点,其中对所述若干目标节点分别记录的数值区间进行合并以得到的数值区间相同于所述第一交易的数值区间。
在一种可能的实施方式中,所述数据管理单元63还用于当所述第一交易的执行结果被所述区块链节点提交后,从所述三叉树的各个节点中删除用于指示所述第一交易的交易标识;确定所述三叉树中是否存在空闲节点,其中所述空闲节点中未记录交易标识且其左子节点、中子节点和右子节点均为空;如果是,则从所述三叉树中删除所述空闲节点。
在一种可能的实施方式中,所述第一账户是合约账户。
虽然本说明书一个或多个实施例提供了如实施例或流程图所述的方法操作步骤,但基于常规或者无创造性的手段可以包括更多或者更少的操作步骤。实施例中列举的步骤顺序仅仅为众多步骤执行顺序中的一种方式,不代表唯一的执行顺序。在实际中的装置或终端产品执行时,可以按照实施例或者附图所示的方法顺序执行或者并行执行(例如并行处理器或者多线程处理的环境,甚至为分布式数据处理环境)。术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、产品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、产品或者设备所固有的要素。在没有更多限制的情况下,并不排除在包括所述要素的过程、方法、产品或者设备中还存在另外的相同或等同要素。例如若使用到第一,第二等词语用来表示名称,而并不表示任何特定的顺序。
本发明是参照根据本发明实施例的方法、装置(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个 方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁盘存储、石墨烯存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
本领域技术人员应明白,本说明书一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书一个或多个实施例,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。
本说明书中的各个实施例均采用递进的方式描述,各个实施例间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本说明书的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
以上所述仅为本说明书一个或多个实施例的实施例而已,并不用于限制本说明书一个或多个实施例。对于本领域技术人员来说,本说明书一个或多个实施例可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在权利要求范围之内。

Claims (17)

  1. 一种区块链系统中的交易冲突检测方法,所述方法由所述区块链系统中的区块链节点执行,所述区块链节点并行执行属于相同区块的多个交易,所述多个交易中包括接收方字段对应第一账户的多个目标交易,属于所述第一账户的多个状态变量的key组成按预定步长递增的数值区间,所述方法包括:
    根据所述多个目标交易的执行结果,将所述多个目标交易分别确定为第一交易和/或第二交易,并确定所述第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定所述第二交易请求更新的若干状态变量的key所组成的数值区间;
    对于每个所述第二交易,根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易。
  2. 根据权利要求1所述的方法,所述方法还包括:根据各个所述第一交易的数值区间构造与所述第一账户对应的查询树;
    其中,所述根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易,包括:
    根据所述查询树确定各个所述第一交易中是否存在第三交易,所述第三交易和所述第二交易的数值区间具有重叠区域;
    如果是,根据所述多个交易的排列顺序确定所述第三交易与所述第二交易是否存在冲突。
  3. 根据权利要求2所述的方法,所述查询树是三叉树;对于所述三叉树中的任一当前节点,所述当前节点的左子节点记录的数值区间的上界小于所述当前节点记录的数值区间的下界,所述当前节点的右子节点记录的数值区间的下界大于所述当前节点记录的数值区间的上界,所述当前节点的中子节点记录的数值区间属于所述当前节点记录的数值区间。
  4. 根据权利要求3中所述的方法,所述当前节点中记录有若干交易标识;所述当前节点记录的数值区间,属于所述当前节点记录的交易标识所指示的第一交易的数值区间;
    其中,所述根据所述查询树确定各个所述第一交易中是否存在第三交易,包括:
    查询所述当前节点,以确定所述当前节点记录的数值区间与所述第二交易的数值区间是否存在重叠区域;
    如果是,将所述当前节点中记录的若干交易标识所分别指示的第一交易确定为第 三交易。
  5. 根据权利要求4所述的方法,所述交易标识是其指示的第一交易在所述多个交易中的排列序号;所述当前节点中还记录有辅助信息,所述辅助信息包括如下各项信息中的至少一项:所述当前节点的左子树中记录的各个排列序号的最大值、所述当前节点的中子树中记录的各个排列序号的最大值和所述当前节点的右子树中记录的各个排列序号的最大值;
    所述方法还包括:根据所述第二交易的排列序号和所述辅助信息,确定是否查询所述当前节点的左子树、所述当前节点的中子树以及所述当前节点的右子树中的至少一项。
  6. 根据权利要求3所述的方法,所述根据各个所述第一交易的数值区间构造与所述第一账户对应的查询树,包括:根据所述第一交易的数值区间更新与所述第一账户对应的三叉树,使更新后的所述三叉树中包括若干目标节点,其中对所述若干目标节点分别记录的数值区间进行合并以得到的数值区间相同于所述第一交易的数值区间。
  7. 根据权利要求3所述的方法,所述方法还包括:
    当所述第一交易的执行结果被所述区块链节点提交后,从所述三叉树的各个节点中删除用于指示所述第一交易的交易标识;
    确定所述三叉树中是否存在空闲节点,其中所述空闲节点中未记录交易标识且其左子节点、中子节点和右子节点均为空;
    如果是,从所述三叉树中删除所述空闲节点。
  8. 根据权利要求1-7中任一项所述的方法,所述第一账户是合约账户。
  9. 一种区块链系统中的区块链节点,所述区块链节点并行执行属于相同区块的多个交易,所述多个交易中包括接收方字段对应第一账户的多个目标交易,属于所述第一账户的多个状态变量的key组成按预定步长递增的数值区间,所述区块链节点包括:
    结果处理单元,用于根据所述多个目标交易的执行结果,将所述多个目标交易分别确定为第一交易和/或第二交易,并确定所述第一交易请求查询的若干状态变量的key所组成的数值区间,以及确定所述第二交易请求更新的若干状态变量的key所组成的数值区间;
    冲突检测单元,用于对于每个所述第二交易,根据所述第二交易的数值区间、各个所述第一交易的数值区间以及所述多个交易的排列顺序,确定是否存在与所述第二交易冲突的第一交易。
  10. 根据权利要求9所述的区块链节点,所述区块链节点还包括:数据管理单元,用于根据各个所述第一交易的数值区间构造与所述第一账户对应的查询树;
    所述冲突检测单元,用于根据所述查询树确定各个所述第一交易中是否存在第三交易,所述第三交易和所述第二交易的数值区间具有重叠区域;如果是,则根据所述多个交易的排列顺序确定所述第三交易与所述第二交易是否存在冲突。
  11. 根据权利要求10所述的区块链节点,所述查询树是三叉树;对于所述三叉树中的任一当前节点,所述当前节点的左子节点记录的数值区间的上界小于所述当前节点记录的数值区间的下界,所述当前节点的右子节点记录的数值区间的下界大于所述当前节点记录的数值区间的上界,所述当前节点的中子节点记录的数值区间属于所述当前节点记录的数值区间。
  12. 根据权利要求11所述的区块链节点,所述当前节点中记录有若干交易标识;所述当前节点记录的数值区间,属于所述当前节点记录的交易标识所指示的第一交易的数值区间;
    所述冲突检测单元,用于查询所述当前节点,以确定所述当前节点记录的数值区间与所述第二交易的数值区间是否存在重叠区域;如果是,则将所述当前节点中记录的若干交易标识所分别指示的第一交易确定为第三交易。
  13. 根据权利要求12所述的区块链节点,所述交易标识是其指示的第一交易在所述多个交易中的排列序号;所述当前节点中还记录有辅助信息,所述辅助信息包括如下各项信息中的至少一项:所述当前节点的左子树中记录的各个排列序号的最大值、所述当前节点的中子树中记录的各个排列序号的最大值和所述当前节点的右子树中记录的各个排列序号的最大值;
    所述冲突检测单元,还用于根据所述第二交易的排列序号和所述辅助信息,确定是否查询所述当前节点的左子树、所述当前节点的中子树以及所述当前节点的右子树中的至少一项。
  14. 根据权利要求11所述的区块链节点,所述数据管理单元,用于根据所述第一交易的数值区间更新与所述第一账户对应的三叉树,使更新后的所述三叉树中包括若干目标节点,其中对所述若干目标节点分别记录的数值区间进行合并以得到的数值区间相同于所述第一交易的数值区间。
  15. 根据权利要求11所述的区块链节点,所述数据管理单元,还用于当所述第一交易的执行结果被所述区块链节点提交后,从所述三叉树的各个节点中删除用于指示 所述第一交易的交易标识;确定所述三叉树中是否存在空闲节点,其中所述空闲节点中未记录交易标识且其左子节点、中子节点和右子节点均为空;如果是,则从所述三叉树中删除所述空闲节点。
  16. 根据权利要求9-15中任一项所述的区块链节点,所述第一账户是合约账户。
  17. 一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算设备中执行时,计算设备执行权利要求1-8中任一项所述的方法。
PCT/CN2022/135283 2022-07-29 2022-11-30 区块链系统中的交易冲突检测方法及区块链节点 WO2024021411A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210907539.XA CN115220924A (zh) 2022-07-29 2022-07-29 区块链系统中的交易冲突检测方法及区块链节点
CN202210907539.X 2022-07-29

Publications (1)

Publication Number Publication Date
WO2024021411A1 true WO2024021411A1 (zh) 2024-02-01

Family

ID=83614384

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135283 WO2024021411A1 (zh) 2022-07-29 2022-11-30 区块链系统中的交易冲突检测方法及区块链节点

Country Status (2)

Country Link
CN (1) CN115220924A (zh)
WO (1) WO2024021411A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115220924A (zh) * 2022-07-29 2022-10-21 蚂蚁区块链科技(上海)有限公司 区块链系统中的交易冲突检测方法及区块链节点
CN115567542B (zh) * 2022-12-01 2023-03-10 杭州蚂蚁酷爱科技有限公司 节点集合的维护方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10333694B1 (en) * 2018-10-15 2019-06-25 Accelor Ltd. Systems and methods for secure smart contract execution via read-only distributed ledger
CN112508573A (zh) * 2021-01-29 2021-03-16 腾讯科技(深圳)有限公司 一种交易数据处理方法、装置以及计算机设备
CN112905871A (zh) * 2021-03-29 2021-06-04 中国平安人寿保险股份有限公司 热点关键词推荐方法、装置、终端及存储介质
CN114564500A (zh) * 2022-02-28 2022-05-31 蚂蚁区块链科技(上海)有限公司 在区块链系统中实现结构化数据存储和查询的方法和系统
CN115220924A (zh) * 2022-07-29 2022-10-21 蚂蚁区块链科技(上海)有限公司 区块链系统中的交易冲突检测方法及区块链节点

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10333694B1 (en) * 2018-10-15 2019-06-25 Accelor Ltd. Systems and methods for secure smart contract execution via read-only distributed ledger
CN112508573A (zh) * 2021-01-29 2021-03-16 腾讯科技(深圳)有限公司 一种交易数据处理方法、装置以及计算机设备
CN112905871A (zh) * 2021-03-29 2021-06-04 中国平安人寿保险股份有限公司 热点关键词推荐方法、装置、终端及存储介质
CN114564500A (zh) * 2022-02-28 2022-05-31 蚂蚁区块链科技(上海)有限公司 在区块链系统中实现结构化数据存储和查询的方法和系统
CN115220924A (zh) * 2022-07-29 2022-10-21 蚂蚁区块链科技(上海)有限公司 区块链系统中的交易冲突检测方法及区块链节点

Also Published As

Publication number Publication date
CN115220924A (zh) 2022-10-21

Similar Documents

Publication Publication Date Title
WO2024021411A1 (zh) 区块链系统中的交易冲突检测方法及区块链节点
US20220067025A1 (en) Ordering transaction requests in a distributed database according to an independently assigned sequence
JP2014500544A (ja) オブジェクトモデルとkey−valueモデル間のマッピング
CN108959510B (zh) 一种分布式数据库的分区级连接方法和装置
TW201600985A (zh) 資料的查詢方法及查詢裝置
WO2017008650A1 (zh) 一种用于过滤数据的设备及方法
US11698893B2 (en) System and method for use of lock-less techniques with a multidimensional database
WO2023231345A1 (zh) 对多个交易进行分组的方法和区块链节点
US9971822B1 (en) Replicated state management using journal-based registers
CN109144783B (zh) 一种分布式海量非结构化数据备份方法及系统
CN110019287B (zh) 执行结构化查询语言sql指令的方法和装置
WO2023231336A1 (zh) 执行交易的方法和区块链节点
CN113743940A (zh) 在区块链中执行交易的方法、区块链、主节点和从节点
WO2024001024A1 (zh) 在区块链系统中执行交易的方法、区块链系统和节点
Hu et al. Towards big linked data: a large-scale, distributed semantic data storage
CN113743942A (zh) 交易执行方法、区块链、主节点和主存储设备
Płuciennik et al. The multi-model databases–a review
CN114529417A (zh) 执行交易的方法、区块链、主节点和从节点
CN115129727A (zh) 状态数据的提交方法、节点和区块链系统
CN114547203A (zh) 执行交易的方法、区块链、主节点和从节点
CN113744062B (zh) 在区块链中执行交易的方法、区块链节点和区块链
WO2024041376A1 (zh) 分布式图数据处理系统、方法、装置、设备及存储介质
Packiaraj et al. Hypar-fca: a distributed framework based on hybrid partitioning for fca
WO2023103351A1 (zh) 一种区块链中智能合约的并行冲突域确定方法及装置
Dhanda Big data storage and analysis

Legal Events

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

Ref document number: 22952845

Country of ref document: EP

Kind code of ref document: A1