Transaction analysis method in block chain system and block chain node
By dividing the contract status of smart contracts into multiple data objects in the blockchain system, setting up multiple APIs to analyze the transaction objective function and API call situation, the problem of high time consumption of multiple transaction conflict detection in the existing technology is solved, and fast and efficient conflict detection and transaction execution are achieved.
Patent Information
- Application Number
- CN202510125352.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-26
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2045-01-26
AI Technical Summary
When conflict detection of multiple transactions is performed, existing blockchain systems have problems such as high time consumption and low efficiency. Especially when pre-execution of multiple transactions, multiple rounds of parallel execution are required to obtain the correct pre-execution results.
By dividing the contract status of the smart contract into multiple data objects and setting multiple APIs for accessing these data objects in the blockchain system, the specific calling situation of the target function and the target API of the first transaction indication call is analyzed to determine whether there is a read-write conflict between the transactions.
This method does not require too much pre-execution, and can quickly and efficiently complete conflict detection of multiple transactions, improving transaction execution efficiency.
Smart Images

Figure CN120047141A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of computer technology, and particularly relate to a transaction analysis method and a blockchain node in a blockchain system. Background Art
[0002] A blockchain system is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. In a blockchain system, data blocks are combined into a chain-like data structure in a sequential connection manner according to the time sequence, and a distributed ledger that is tamper-proof and non-forgeable is guaranteed by cryptographic means. Due to the characteristics of decentralization, information immutability, autonomy, etc. of the blockchain system, the blockchain system has received more and more attention and applications.
[0003] In order to improve the transaction execution efficiency in a blockchain system, multiple transactions that are expected to be executed and have an order can usually be pre-executed. The pre-execution result of a single transaction includes the key of the state variable that the blockchain system needs to access due to executing this transaction, and the access type corresponding to this state variable, where the access type includes read and / or write across domains. For any transaction, the pre-execution result of this transaction can be used to determine whether there are read-write conflicts between this transaction and other transactions in the blockchain system; for each transaction with read-write conflicts, they need to be serially executed in the order, and for each transaction without read-write conflicts, they can be executed in parallel to improve the transaction execution efficiency.
[0004] There is a hope for a new solution to facilitate more efficient conflict detection for multiple transactions. Summary of the Invention
[0005] The purpose of the present invention is to provide a transaction analysis method and a blockchain node in a blockchain system.
[0006] In a first aspect, a transaction analysis method in a blockchain system is provided. A smart contract is deployed in the blockchain system. The contract state of the smart contract is divided into multiple data objects, and the multiple data objects have different storage locations in a data storage system. The blockchain system includes multiple application programming interfaces (APIs) for accessing the multiple data objects. The method includes: determining a target function in the smart contract that a first transaction expects to call; determining a number of target APIs called in the target function; determining an analysis result based on the first transaction, the number of target APIs, and the access types respectively corresponding to the number of target APIs, where the analysis result is used to determine whether there is a read / write conflict between the first transaction and other transactions. The analysis result includes multiple grouping keys and the access types respectively corresponding to the multiple grouping keys. The multiple grouping keys include the contract address of the smart contract and the identification information of each of the multiple data objects indicated by the first transaction to be accessed through the number of target APIs. The access type corresponding to the contract address is read.
[0007] In a second aspect, a blockchain node in a blockchain system is provided. A smart contract is deployed in the blockchain system. The contract state of the smart contract is divided into multiple data objects, and the multiple data objects have different storage locations in a data storage system. The blockchain system includes multiple APIs for accessing the multiple data objects. Among them, the blockchain node includes: a function determination unit for determining a target function in the smart contract that a first transaction expects to call; an interface determination unit for determining a number of target APIs called in the target function; an analysis and processing unit for determining an analysis result based on the first transaction, the number of target APIs, and the access types respectively corresponding to the number of target APIs, where the analysis result is used to determine whether there is a read / write conflict between the first transaction and other transactions. The analysis result includes multiple grouping keys and the access types respectively corresponding to the multiple grouping keys. The multiple grouping keys include the contract address of the smart contract and the identification information of each of the multiple data objects indicated by the first transaction to be accessed through the number of target APIs. The access type corresponding to the contract address is read.
[0008] In a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computing device, the computing device executes the method described in the first aspect.
[0009] In the technical solution provided by the embodiments of this specification, the contract state of the smart contract is divided into multiple data objects and stored in different storage locations in the data storage system. At the same time, multiple APIs for accessing the multiple data objects are set in the blockchain system. For any first transaction for invoking the smart contract, only by analyzing the specific invocation situation of the multiple APIs in a certain target function included in the smart contract indicated to be invoked by the first transaction, it is possible to know the access situation of the blockchain system to the multiple data objects during the actual execution of the first transaction by the blockchain system, that is, during the execution of the target function according to the first transaction, so as to obtain an analysis result that can be used to determine whether there is a read-write conflict between the first transaction and other transactions. In this process, there is no need to spend too much time pre-executing the first transaction, which is beneficial to more quickly and efficiently completing the conflict detection of multiple transactions including the first transaction and having an arrangement order. Brief Description of the Drawings
[0010] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments recorded in this specification. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0011] Figure 1 It is an architecture diagram of a blockchain system exemplarily provided in the embodiments of this specification;
[0012] Figure 2 It is a flowchart of a transaction analysis method in a blockchain system provided in the embodiments of this specification;
[0013] Figure 3 It is a schematic structural diagram of a blockchain node in a blockchain system provided in the embodiments of this specification. Detailed Embodiments
[0014] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings. Obviously, the described embodiments are only some embodiments of this specification, rather than all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.
[0015] Figure 1 It is an architecture diagram of a blockchain system exemplarily provided in the embodiments of this specification. The blockchain system may include N blockchain nodes, where Figure 1Exemplarily shown in the figure are 8 blockchain nodes such as Node 1 - Node 8. The connections between the nodes schematically represent the connections between the nodes, and the aforementioned connections are used to support data transmission between different nodes.
[0016] The blockchain system can provide the function of smart contracts. The smart contract in the blockchain system is a contract that can be triggered and executed by a transaction. The smart contract can be defined in the form of contract code. Invoking a smart contract in the blockchain system is to initiate a transaction pointing to the contract address of the smart contract, so that each node in the blockchain system runs the corresponding contract code distributively.
[0017] In various blockchain systems with smart contracts introduced, accounts can generally be divided into two types:
[0018] Contract account (CA): mainly used to store the contract code of the corresponding smart contract and the values of the state variables in the smart contract, and usually can only be activated by calling from an external account;
[0019] Externally owned account (EOA): an account registered by an external user in the blockchain system.
[0020] The design of external accounts and contract accounts is actually a mapping from account addresses to account states. The account state of any account usually includes fields such as nonce, balance, storageRoot, code, and / or codeHash. Nonce and balance exist in both external accounts and contract accounts, and the code, codeHash, and storageRoot attributes are generally only valid for contract accounts.
[0021] The contract account is used to store the contract state of the smart contract. After the smart contract is deployed in the blockchain system, a corresponding contract account will be generated. This contract account generally has some states, which are defined by the state variables in the smart contract and new values are generated when the smart contract is created and executed. The aforementioned smart contract generally refers to a contract that can automatically execute terms defined in digital form in the blockchain environment. When an event triggers the terms in the contract (meeting the execution conditions), the code can be automatically executed. The contract state of the smart contract contains the values of multiple state variables; in specific technical scenarios, the values of state variables are usually stored in the data storage system in the form of key - value pairs. The key of any state variable can be determined based on the declaration position of the state variable in the contract code during the compilation or execution of the smart contract, or based on the variable name of the state variable and / or several pre - order state variables in the smart contract that have a nested relationship with the state variable.
[0022] To improve the transaction execution efficiency in a blockchain system, multiple transactions that are expected to be executed and have an order can usually be pre-executed. The pre-execution result of a single transaction includes the key of the state variable that the blockchain system needs to access due to the execution of this transaction, and the access type corresponding to this state variable, where the access type includes read and / or write across domains. For any transaction, the pre-execution result of this transaction can be used to determine whether there are read-write conflicts between this transaction and other transactions in the blockchain system; for each transaction with read-write conflicts, they need to be serially executed in order, and for each transaction without read-write conflicts, they can be executed in parallel to improve the transaction execution efficiency.
[0023] For a single transaction, the time spent on pre-executing this transaction is comparable to the time spent on actually executing this transaction; especially for transactions that call smart contracts, the time required for pre-executing them is usually relatively large. In addition, usually a parallel execution method is also needed to pre-execute multiple transactions to improve the pre-execution efficiency of transactions. If there are many transactions with read-write conflicts among the multiple transactions expected to be executed, then multiple rounds of parallel execution processes are required to obtain the correct pre-execution results of these multiple transactions, resulting in the time required for pre-executing multiple transactions being close to or even greater than the time for serially executing these multiple transactions, that is, it takes more time to obtain the correct pre-execution results of each of the multiple transactions, which also means that it is difficult to quickly complete the conflict detection for multiple transactions.
[0024] In the embodiments of this specification, a transaction analysis method and a blockchain node in a blockchain system are provided. The contract state of a smart contract is divided into multiple data objects, and these multiple data objects have different storage locations in the relevant data storage system. The blockchain system includes multiple APIs for accessing these multiple data objects; when it is necessary to perform read-write analysis on a certain first transaction, the target function in a certain smart contract that the first transaction expects to call can be determined first; then several target APIs called in the target function can be determined; finally, the analysis result can be determined according to the first transaction, several target APIs, and the access types corresponding to several target APIs respectively. This analysis result can be used to determine whether there are read-write conflicts between the first transaction and other transactions. This analysis result includes multiple grouping keys and the access types corresponding to these multiple grouping keys respectively. These multiple grouping keys include the contract address of the smart contract called by the first transaction, and the identification information of several data objects indicated by the first transaction to be accessed through several target APIs. The access type corresponding to the contract address of the smart contract called by the first transaction is read.
[0025] Thus, by dividing the contract state of the smart contract into multiple data objects, storing the multiple data objects in different storage locations in the data storage system, and presetting multiple APIs for accessing the multiple data objects in the blockchain system; for any first transaction for invoking the smart contract, it only needs to analyze the specific invocation situation of the multiple APIs in a certain target function included in the smart contract indicated to be invoked by the first transaction, then it can know the access situation of the blockchain system to the multiple data objects during the actual execution of the first transaction, that is, during the execution of the target function according to the first transaction, so as to obtain an analysis result that can be used to judge whether there is a read-write conflict between the first transaction and other transactions. In this process, there is no need to spend too much time pre-executing the first transaction, which is beneficial to more quickly and efficiently complete the conflict detection of multiple transactions including the first transaction and having an arrangement order.
[0026] In addition, the identification information of the data object is used as a grouping key, which is separated from the key of the state variable (i.e., the storage key), which can improve the flexibility of writing smart contracts and is beneficial to organizing richer business semantics and state models in smart contracts.
[0027] Moreover, for different transactions, the analysis processes of different transactions are not related to each other; therefore, in the embodiments of this specification, the analysis processes of multiple transactions can also be executed in parallel to quickly obtain the analysis results corresponding to each of the multiple transactions.
[0028] In the blockchain system, object categories can also be divided for data objects. For any target category among the possible multiple object categories, a first API and a second API corresponding to the target category and allowed to be invoked by the smart contract can be set. It should be particularly noted that the first API is used to read the value of the state variable from the data objects belonging to the target category under the invocation of the smart contract, and the corresponding access type is "write"; the second API is used to write the value of the state variable to the data objects belonging to the target category under the invocation of the smart contract, and the corresponding access type is "read".
[0029] Exemplarily, based on whether the state variable in the data object is associated with the user account registered in the blockchain system, it can be divided into two object categories: contract state container (CSC) and contract shared object (CSO). In this article, CSC is also referred to as the first category, and CSO is referred to as the second category.
[0030] Taking C++ syntax as an example below, the first API and the second API for CSC and CSO can be set as follows:
[0031] template<typename T = void, typename... Args>
[0032] void set_private(const Account& to, const std::string& key, T& value);
[0033] / / set_private() is the second API corresponding to the CSC. Among its input parameters, the parameter name const Account& to is used to represent the account address of the user account / external account. When set_private() is called, the parameter value of the passed-in const Account& to can be used to determine the identification information of a data object belonging to the CSC; const std::string& key is used to represent the key of the accessed state variable, and T& value is used to represent the value of a state variable to be stored in the data storage system. template<typename T = void, typename... Args>
[0034] T get_private(const Account& to, const std::string& key);
[0035] / / get_private() is the first API corresponding to the ASO. Among its input parameters, the parameter name const Account& to is used to represent the account address of the user account / external account. When set_private() is called, the parameter value of the passed-in const Account& to can be used to determine the identification information of a data object belonging to the CSC; const std::string& key is used to represent the key of the accessed state variable; the return value is the value of the accessed state variable
[0036] template<typename T = void, typename... Args>
[0037] void set_shared(const std::string& root, const std::string& key, T& value);
[0038] / / set_shared() is the second API corresponding to the CSO. Among its input parameters, the parameter value of const std::string& root can be used to determine the identification information of a data object belonging to the CSO, const std::string& key is used to represent the key of the state variable being accessed, and T& value is used to represent the value of a state variable to be stored in the data storage system.
[0039] template<typename T = void, typename... Args>
[0040] T& value get_shared(const std::string& root, const std::string& key);
[0041] / / get_shared() is the first API corresponding to the CSO. Among the input parameters, the parameter value of const std::string& root can be used to determine the identification information of a data object belonging to the CSO, const std::string& key is used to represent the key of the state variable being accessed, and the return value is the value of the state variable being accessed.
[0042] For some object categories, such as the CSO in the foregoing example, dedicated APIs other than the first and second APIs may also be set to implement a predetermined transaction. For example, the following third API can also be set for the CSO:
[0043] bool value has_shared(const std::string& root, const std::string& key);
[0044] / / has_shared() is the third API corresponding to the CSO. Among its input parameters, the parameter value of const std::string& root can be used to determine the identification information of a data object belonging to the CSO, const std::string& key is used to represent the key of the state variable being accessed; this third API is used to query whether a certain state variable exists in the data object belonging to the CSO; it can be understood that the access type corresponding to this third API is "read".
[0045] For any first data object belonging to the CSC, each state variable included in the first data object can be associated with the same first account; for any two different first data objects belonging to the CSC, the state variables included in each are associated with different user accounts. Correspondingly, the identification information of the first data object can be determined based on the account address of the associated user account, for example, based on the contract address of the smart contract to which the first data object belongs and the account address of the associated user account.
[0046] For any second data object belonging to the CSO, the second data object can be predefined through the contract code of the smart contract; that is, one or more second data objects belonging to the CSO can be defined in the contract code of the smart contract. Correspondingly, the identification information of the second data object can also be predefined through the contract code of the smart contract.
[0047] Exemplarily, user accounts Alice and Bob registered in the blockchain system may both hold a certain token issued through smart contract Contract1, such as Token1, which means that in the contract state of smart contract Contract1, the balance information of user accounts Alice and Bob holding Token1 respectively may be recorded through state variables such as M1 and M2. In addition, the trading frequency of Token1 for user accounts Alice and Bob respectively may be recorded through state variables M3 and M4, and the circulation amount of Token1 issued by Alice and Bob through the smart contract may be recorded through state variable M5. In this case, state variables M1 and M3 can be divided into a data object Alice.Contract1 associated with user account Alice and belonging to the CSC, state variables M2 and M4 can be divided into a data object Bob.Contract1 associated with user account Bob and belonging to the CSC, and state variable M5 can be divided into a data object Root1.Contract1 belonging to the CSO.
[0048] A single data object may include the values of multiple state variables. To facilitate quick access to the state variables, a single data object can use a tree structure to organize the values of the multiple state variables included in the data object. The value of a state variable is stored in a leaf node of the tree structure, and in the directed path from the root node to the parent node of a leaf node, the key of the state variable corresponding to the value stored in the leaf node is stored, and the identification information of the data object is stored in the root node.
[0049] In addition to setting multiple APIs for accessing data objects in the blockchain system, other APIs can be set to read data information from relevant transactions under the invocation of smart contracts. For example, in the blockchain system, Account get_account() can also be set to read the account address corresponding to the user account that initiated a transaction from the transaction used to invoke a certain smart contract under the invocation of that smart contract; Account get_contract() can also be set to read the contract address of the smart contract invoked by the transaction from the transaction used to invoke that smart contract under the invocation of a certain smart contract.
[0050] Multiple data objects included in a smart contract have different storage locations in the data storage system. For example, data objects belonging to CSC are stored under the associated user account; data objects belonging to CSO are still stored under the contract account. Continuing with the previous example: The data object Alice.contract1 can be stored under the associated user account Alice, the data object Bob.Contract1 can be stored under the associated user account Bob, and the data object Root1.Contract1 can be stored under the contract account of the smart contract Contract1.
[0051] The foregoing has exemplarily introduced how to divide data objects according to the contract state of a smart contract and has also exemplarily introduced how to set APIs in the blockchain system that can be invoked by smart contracts. Next, it will be exemplarily described how to analyze the read and write situations of transactions used to invoke smart contracts on the contract state when it is necessary to detect conflicts among multiple transactions in the blockchain system.
[0052] Figure 2 This is a flowchart of a transaction analysis method in a blockchain system provided in an embodiment of this specification. A smart contract is deployed in the blockchain system, and the contract state of the smart contract is divided into multiple data objects, and these multiple data objects have different storage locations in the data storage system; in the blockchain system, more specifically, in the blockchain nodes included in the blockchain system, multiple APIs that can be invoked by smart contracts are preset, and these multiple APIs can access the multiple data objects included in the contract state of the smart contract under the invocation of the smart contract.
[0053] Referring to Figure 2 As shown, the method may include, but is not limited to, some or all of the following steps S201 to step S209.
[0054] Step S201, determine the target function in the smart contract indicated to be invoked by the first transaction.
[0055] For the first transaction used to invoke a smart contract, the form field of the transaction contains the account address corresponding to the user account that initiated the transaction, the to field contains the contract address corresponding to the invoked smart contract, and the data field contains the call parameters, such as the function identifier of the target function called in the smart contract and the input parameters of the target function, etc.
[0056] Take the following pseudocode of the smart contract Contract1 as an example:
[0057] / / ********************** / /
[0058] class MyContract{
[0059] / / Deposit() is used to increase the balance of a certain token (such as Token1) held by the user account
[0060] void Deposit(uint64_t value){
[0061] auto balance=get_private<uint64_t>(get_account(),"balance");
[0062] set_private(get_account(),"balance",balance+value);
[0063] }
[0064] / / Withdraw() is used to increase the balance of a certain token (such as Token1) held by the user account
[0065] void Withdraw(uint64_t value){
[0066] auto balance=get_private<uint64_t>(get_account(),"balance");
[0067] set_private(get_account(),"balance",balance-value);
[0068] }
[0069] / / Transfer() is used to transfer a certain type of token between user accounts. biz_id refers to the transaction identifier of the relevant transaction. If the transaction corresponding to biz_id has already occurred (judged by idempotency operation for example), it fails. If it has not occurred, the balance change operation of the corresponding account is performed, and it is recorded that the transaction has occurred.
[0070] void Transfer(const std::string&biz_id,const Account&to,uint64_tvalue){
[0071] require(!has_shared("root1",biz_id,"already exsit"),);
[0072] co_call(get_account(),get_contract(),"Withdraw",value);
[0073] co_call(to,get_contract(),"Deposit",value);
[0074] set_shared("root1",biz_id,"");
[0075] }
[0076] / / GetBalance() is used to query the balance of a certain type of token (such as Token1) held by the user account.
[0077] uint64_t GetBalance(){
[0078] return get_private<uint64_t>(get_account(),"balance");
[0079] }
[0080] .
[0081] / / ********************** / /
[0082] In Contract1 of the above example, functions Deposit(), Withdraw(), Transfer(), and GetBalance() are included.
[0083] Based on the smart contract Contract1 in the above example, when a user account, such as Alice, expects to transfer a certain token issued by Contract1, such as Token1, to another user account, such as Bob, and the transfer share is, for example, 100, the user account Alice can initiate a transaction for calling Contract1, such as transaction Tx1 = Alice.Contract1.Transfer(Bob, 100). Among them, the from field of Tx1 includes Alice's account address, the to field includes Contract1's contract address, and the data field can include the function identifier of the target function Transfer() and the input parameters of Transfer(). The input parameters of Transfer() can specifically include Bob's account address of the user account and the transfer share 100 of the expected transferred token Token1. Correspondingly, the function identifier of Transfer() can be obtained from the data field of transaction Tx1, and the contract address of Contract1 can be read from the to field of transaction Tx1; furthermore, based on Contract1's contract address and the function identifier of Transfer(), the function Transfer() in Contract1 is determined as the target function that transaction Tx1 expects to call.
[0084] Based on the smart contract Contract1 in the above example, when a user account, such as Dave, expects to subscribe for a certain token issued by Contract1, such as Token1, and the subscription share is, for example, 100, the user account Dave can initiate a transaction for calling Contract1, such as transaction Tx2 = Dave.Contract1.Deposit(100). The from field of transaction Tx2 includes Dave's account address, the to field includes Contract1's contract address, and the data field can include the function identifier of the target function Deposit() and the input parameters of Deposit(). The input parameters of Transfer() can include the subscription share 100 of the token Token1 that user account Dave expects to subscribe for. Correspondingly, the function identifier of Deposit() can be obtained from the data field of transaction Tx2, and the contract address of Contract1 can be read from the to field of transaction Tx2; based on Contract1's contract address and the function identifier of Deposit(), the function Deposit() in Contract1 is determined as the target function that transaction Tx2 expects to call.
[0085] Step S203, determine a number of target APIs called in the target function.
[0086] By analyzing the called target function, several target APIs called by the target function can be determined.
[0087] Continuing with the example in the previous text, when the target function is Transfer() included in the smart contract Contract1, by analyzing Transfer(), it can be known that the target APIs called in Transfer() specifically include: has_shared() and set_shared directly called by Transfer(), get_private() and set_private() indirectly called by Transfer() through co_call() and Depost(), and get_private() and set_private() indirectly called by Transfer() through co_call() and Withdraw().
[0088] Continuing with the example in the previous text, when the target function is Deposit() included in the smart contract Contract1, by analyzing Deposit(), it can be known that the target APIs called in Deposit() include: get_private() and set_private().
[0089] Step S205: Determine the analysis result of the first transaction according to the first transaction, several target APIs, and the access types corresponding to the several target APIs respectively. The analysis result of the first transaction is used to determine whether there are read-write conflicts between the first transaction and other transactions. The analysis result of the first transaction includes multiple grouping keys and the access types corresponding to the multiple grouping keys respectively. The multiple grouping keys include the contract address of the smart contract, and the identification information of several data objects indicated by the first transaction to be accessed through the several target APIs. The access type corresponding to the contract address is read.
[0090] The contract address of the called smart contract can be obtained from the first transaction, and this contract address is determined as the grouping key, and the access type corresponding to this contract address is set to read; Continuing with the previous example, the contract address of the smart contract Contract1 can be obtained from the to field of transaction Tx1 or transaction Tx2, and the access type corresponding to this contract address is set to read. In addition, through some or all of the following steps S2051 to S2055, the identification information of several data objects indicated by the first transaction to be accessed through several target APIs can be used as the grouping key in the analysis result and the access type is set.
[0091] Step S2051: Determine the input parameters of the target API when the target function is executed according to the first transaction.
[0092] For a single target API, when executing a target function according to a first transaction, some of the input parameters of the target API may come from the first transaction, and there may also be some input parameters provided by the target function; that is, the input parameters of the target API may be obtained from the first transaction or from the target function.
[0093] Continuing with the foregoing example, when the first transaction is transaction Tx1, by analyzing the calls of several target APIs by Transfer(), the input parameters of each of the several target APIs can be determined when executing Transfer() according to transaction Tx1.
[0094] The input parameters of has_shared() include: "root1" and the transaction identifier "biz_id", both of which are obtained from Transfer();
[0095] The input parameters of set_shared() include: "root1" and the transaction identifier "biz_id", both of which are obtained from Transfer();
[0096] The input parameters of get_private() include: when Transfer() indirectly calls get_private() through co_call() and Withdraw(), the input parameters include Alice's account address and "balance", where "balance" refers to the key of the state variable used to represent the balance of a certain token held by Alice; when Transfer() indirectly calls get_private() through co_call() and Deposit(), the input parameters include Bob's account address and "balance", where "balance" refers to the key of the state variable used to represent the balance of a certain token held by Bob; among them, the account addresses of Alice and Bob come from transaction Tx1;
[0097] The input parameters of set_private() include: in the case where Transfer() indirectly calls set_private() through co_call() and Withdraw(), the input parameters include Alice's account address, "balance", and balance–value; in the case where Transfer() indirectly calls set_private() through co_call() and Deposit(), the input parameters include Bob's account address, "balance", and balance+value; where the value of value in balance–value and balance+value comes from transaction Tx1, that is, the value of value is 100.
[0098] Continuing with the foregoing example, when the first transaction is transaction Tx2, by analyzing the calls of Deposit() to several target APIs, the input parameters of each of the several target APIs when executing Deposit() according to transaction Tx2 can be determined.
[0099] The input parameters of get_private() include: the account address of user account Dave and "balance";
[0100] The input parameters of set_private() include: the account address of user account Dave, "balance", and balance+value.
[0101] Step S2053, according to the input parameters, determine the identification information of the data object indicated by the first transaction to be accessed through the target API, and determine the identification information as the grouping key.
[0102] Continuing with the foregoing example, when the first transaction is transaction Tx1:
[0103] For the input parameters of has_shared(), the identification information such as "Root1.Contract1" can be determined according to "root1";
[0104] For the input parameters of set_shared(), the identification information such as "Root1.Contract1" can be determined according to "root1";
[0105] For the input parameters of get_private(), the identification information of the data object associated with Alice, such as Alice.Contract1, can be determined according to Alice's account address, and the identification information of the data object associated with Bob, such as Bob.Contract1, can be determined according to Bob's account address;
[0106] For input parameters similar to get_private(), for the input parameters of set_private(), the identification information of the data object associated with Alice, such as Alice.Contract1, can be determined based on Alice's account address, and the identification information of the data object associated with Bob, such as Bob.Contract1, can be determined based on Bob's account address.
[0107] Continuing with the foregoing example, when the first transaction is transaction Tx2:
[0108] For the input parameters of get_private(), the identification information of the data object associated with Dave, such as Dave.Contract1, can be determined based on the account address used for the account of Dave;
[0109] For input parameters similar to get_private(), for the input parameters of set_private(), the identification information of the data object associated with Dave, such as Dave.Contract1, can be determined based on the account address used for the account of Dave.
[0110] Step S2055, set the access type corresponding to the identification information to the access type corresponding to the target API.
[0111] Continuing with the foregoing example, when the first transaction is transaction Tx1:
[0112] The read-write type corresponding to has_shared() is "read", while the access type corresponding to set_shared() is "write". For the identification information determined based on the input parameters of has_shared() and set_shared(), such as Root1.Contract1, the access type corresponding to this identification information Root1.Contract1 can be set to "read" and "write";
[0113] The access type corresponding to get_private() is "read", while the access type corresponding to set_private() is "write". For the identification information determined based on the input parameters of get_private() and set_private(), such as Alice.Contract1 and Bob.Contract1, the access types corresponding to Alice.Contract1 and Bob.Contract1 can both be set to "read" and "write".
[0114] Finally, for transaction Tx1 in the foregoing example, the analysis results shown in Table 1 below can be obtained:
[0115]
[0116]
[0117] Table 1
[0118] Continuing with the foregoing example, when the first transaction is transaction Tx2:
[0119] The access type corresponding to get_private() is "read", while the access type corresponding to set_private() is "write". For the identification information determined according to the input parameters of get_private() and set_private(), such as Dave.Contract1, the corresponding access types can be set to "read" and "write". Finally, the following analysis results as shown in Table 2 can be obtained for transaction Tx2:
[0120]
[0121] Table 2
[0122] It should be specifically noted that the processes of the foregoing steps S2051 to S2055 are merely exemplary. For example, for each function included in the smart contract Contract1, the target parameters in the function that can be used to determine the identification information of the data object can be marked; for each API that takes the target parameter as an input parameter, the access type corresponding to the API is set to the access corresponding to the target parameter. In this way, when the target function is executed according to the first transaction, the parameter values corresponding to the respective target parameters in the target function can be first determined, and then the identification information corresponding to the respective data objects that may be accessed can be determined according to the parameter values corresponding to the respective target parameters, and according to the access types corresponding to the respective target parameters, the access types corresponding to the respective identification information used as the grouping keys can be determined.
[0123] The foregoing steps S201 to S205 describe in detail the process of analyzing the first transaction to obtain the analysis results. The obtained analysis results will be used to detect whether there are read-write conflicts between the first transaction and other transactions. For example, the blockchain system may need to perform conflict detection on multiple transactions belonging to the same block according to the order of arrangement of the multiple transactions before actually executing them, and finally implement serial execution of transactions with read-write conflicts and parallel execution of transactions without read-write conflicts. Based on the foregoing steps S201 to S205, the following steps S207 and S209 may continue to be executed.
[0124] Step S207: Determine whether there is the same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, where the arrangement position of the second transaction among multiple transactions is after the first transaction.
[0125] The analysis result of the second transaction can be obtained through a process similar to the foregoing Steps S201 to S205.
[0126] Taking the first transaction as the transaction Tx1 in the foregoing example and the second transaction as the transaction Tx2 in the foregoing example, it can be found by comparing the analysis result of the transaction Tx1 and the analysis result of the transaction Tx2 in the foregoing example that there is the same target grouping key "contract address of Contract1" in the analysis results of the transaction Tx1 and the transaction Tx2.
[0127] If there is no same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, it indicates that there is no read-write conflict between the first transaction and the second transaction. If there is the same target grouping key in the analysis result of the first transaction and the analysis result of the second transaction, the following Step S209 can be continued. When the access type corresponding to the target grouping key in the analysis result of the first transaction includes writing, it is determined that there is a read-write conflict between the first transaction and the second transaction.
[0128] In the foregoing Steps S201 to S209, the process of analyzing the transaction for calling the smart contract to obtain the analysis result is mainly described. For other transactions such as transfer transactions, the account addresses included in the from field and the to field of the transfer transaction can be directly used as the grouping keys, and their respective corresponding access types are set to "read" and "write".
[0129] Based on the same concept as the foregoing method embodiment, a blockchain node 300 in a blockchain system is further provided in the embodiment of the present specification. The smart contract is deployed in the blockchain system. The contract state of the smart contract is divided into multiple data objects, and the multiple data objects have different storage positions in the data storage system. The blockchain system includes multiple APIs for accessing the multiple data objects. Refer to Figure 3As shown in the figure, the blockchain node 300 includes: a function determination unit 301, configured to determine a target function in the smart contract expected to be invoked by a first transaction; an interface determination unit 303, configured to determine a plurality of target APIs invoked in the target function; an analysis and processing unit 305, configured to determine an analysis result according to the first transaction, the plurality of target APIs, and access types respectively corresponding to the plurality of target APIs, where the analysis result is used to determine whether there is a read-write conflict between the first transaction and other transactions, the analysis result includes a plurality of grouping keys and access types respectively corresponding to the plurality of grouping keys, the plurality of grouping keys include a contract address of the smart contract, and identification information of a plurality of data objects indicated by the first transaction to be accessed through the plurality of target APIs, and the access type corresponding to the contract address is read.
[0130] An embodiment of this specification also provides a computer-readable storage medium, on which a computer program / instructions are stored. When the computer program / instructions are executed on a computer, the computer is made to execute a transaction analysis method in a blockchain system provided in each of the foregoing embodiments.
[0131] An embodiment of this specification also provides a computing device, including a memory and a processor. A computer program / instructions are stored in the memory, and when the processor executes the computer program / instructions, a transaction analysis method in a blockchain system provided in each of the foregoing embodiments is implemented.
[0132] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many method flow improvements today can be regarded as direct improvements to hardware circuit structures. Almost all designers obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement to a method flow cannot be implemented using a hardware entity module. For example, a Programmable Logic Device (PLD) (e.g., a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logical function is determined by the user programming the device. Designers can program themselves to "integrate" a digital system onto a single PLD, without having to ask a chip manufacturer to design and fabricate a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly implemented using "logic compiler" software, which is similar to the software compiler used in program development and writing. The original code before compilation also has to be written in a specific programming language, which is called a Hardware Description Language (HDL), and there is not just one type of HDL, but many types, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones currently are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also be aware that by simply performing a little logical programming on the method flow using the above-mentioned several hardware description languages and programming it into an integrated circuit, it is easy to obtain the hardware circuit that implements the logical method flow.
[0133] The controller can be implemented in any suitable manner. For example, the controller can take the form of, for example, a microprocessor or a processor and a computer-readable medium storing computer-readable program code (such as software or firmware) executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of the controller include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program code, it is entirely possible to logically program the method steps to enable the controller to be implemented in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. to achieve the same function. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be regarded as the structures within the hardware component. Or even, the devices for implementing various functions can be regarded as either software modules for implementing the method or structures within the hardware component.
[0134] The systems, devices, modules, or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude that with the development of future computer technologies, the computers for implementing the functions of the above embodiments can be, for example, personal computers, laptop computers, in-vehicle human-machine interaction devices, cellular phones, camera phones, smart phones, personal digital assistants, media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.
[0135] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flowcharts, 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 among many orders of step execution and does not represent the only execution order. When the actual device or terminal product is executed, it may be executed in the order of the method shown in the embodiments or the drawings or in parallel (for example, in an environment of parallel processors or multi-threaded processing, or even in a distributed data processing environment). The term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, product or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, product or device. Without further limitation, there is no exclusion of additional identical or equivalent elements in the process, method, product or device comprising the said elements. For example, if terms such as first and second are used to denote names, they do not denote any particular order.
[0136] For convenience of description, when describing the above device, it is divided into various modules according to functions for separate description. Of course, when implementing one or more of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware, or the modules implementing the same function can be realized by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.
[0137] The present invention is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows 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 the processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate a device for realizing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0138] These computer program instructions can also be stored in a computer-readable memory that can direct 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 an instruction device that implements the functions specified in one or more of the processes and / or blocks Figure 1 in one or more of the processes and / or blocks Figure 1 specified in the block or blocks.
[0139] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, so that the instructions executed on the computer or other programmable apparatus provide steps for implementing the functions specified in one or more of the processes and / or blocks Figure 1 in one or more of the processes and / or blocks Figure 1 specified in the block or blocks.
[0140] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0141] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
[0142] Computer-readable media includes both permanent and non-permanent, removable and non-removable media implemented by any method or technology for storage of information such as 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 technologies, compact disc read only memory (CD-ROM), digital versatile discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transmission 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.
[0143] Those skilled in the art should understand that one or more embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, one or more embodiments of this specification can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, one or more embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0144] One or more embodiments of this specification can 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, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0145] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system embodiments, since they are basically similar to method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the partial description of the method embodiments. In the description of this specification, the description with reference to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0146] The above description is only for the embodiments of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included within the scope of the claims.
Claims
1. A transaction analysis method in a blockchain system, wherein a smart contract is deployed in the blockchain system, the contract state of the smart contract is divided into multiple data objects, the multiple data objects have different storage locations, and the blockchain system includes multiple application programming interfaces (APIs) for accessing the multiple data objects, the method comprising: Determining a target function in the smart contract called by the first transaction instruction; Determine a number of target APIs called in the target function; An analysis result is determined according to the first transaction, the several target APIs, and the access types corresponding to the several target APIs respectively. The analysis result is used to determine whether there is a read-write conflict between the first transaction and other transactions. The analysis result includes multiple grouping keys and the access types corresponding to the multiple grouping keys respectively. The multiple grouping keys include the contract address of the smart contract, and the identification information of the several data objects accessed by the several target APIs indicated by the first transaction. The access type corresponding to the contract address is read.
2. The method according to claim 1, wherein determining the analysis result according to the first transaction, the plurality of target APIs, and the access types corresponding to the plurality of target APIs comprises: The contract address of the smart contract is obtained from the first transaction, the contract address is determined as a grouping key, and the access type corresponding to the contract address is set to read.
3. The method according to claim 1, wherein determining the analysis result according to the first transaction, the plurality of target APIs, and the access types corresponding to the plurality of target APIs comprises: determining input parameters of the target API when executing the target function according to the first transaction; Determine, according to the input parameter, identification information of the data object accessed by the first transaction instruction through the target API, and determine the identification information as a grouping key; The access type corresponding to the identification information is set as the access type corresponding to the target API.
4. The method according to claim 3, wherein the determining the input parameters of the target API when executing the target function according to the first transaction comprises: From the first transaction, input parameters of the target API are obtained.
5. The method according to claim 3, wherein determining the input parameters of the target API when executing the target function according to the first transaction comprises: From the target function, an input parameter of the target API is obtained.
6. The method according to claim 1, wherein the plurality of data objects are divided into a plurality of object categories, and for any target category in the plurality of object categories, the plurality of APIs include a first API and a second API corresponding to the target category, the first API being used to read a value of a state variable from a data object belonging to the target category, and the second API being used to write a value of a state variable to a data object belonging to the target category; in, The access type corresponding to the first API is read, and the access type corresponding to the second API is write.
7. According to the method according to claim 6, the multiple object categories include a first category. For a first data object belonging to the first category, each state variable in the first data object is associated with the same first user account, and the identification information of the first data object is determined based on the account address of the first user account.
8. According to the method of claim 6, the multiple object categories include a second category, and for a second data object belonging to the second category, identification information of the second data object is pre-defined by the contract code of the smart contract.
9. According to the method described in claim 1, the data object is a tree structure, and the key of the state variable corresponding to the value stored in the leaf node is stored in the directed path between the root node of the tree structure and the parent node of the leaf node, and the identification information of the data object is stored in the root node.
10. The method according to any one of claims 1 to 9, wherein the first transaction belongs to a plurality of transactions having an arrangement order, the plurality of transactions further comprising a second transaction arranged after the first transaction, the method further comprising: Determine whether the analysis result of the first transaction and the analysis result of the second transaction have the same target grouping key; If the target group key exists, then when the access type corresponding to the target group key in the analysis result of the first transaction includes write, it is determined that there is a read-write conflict between the first transaction and the second transaction.
11. A blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, the contract state of the smart contract is divided into multiple data objects, the multiple data objects have different storage locations, and the blockchain system includes multiple application programming interfaces API for accessing the multiple data objects; The blockchain node includes: A function determination unit, configured to determine a target function in the smart contract that the first transaction expects to call; An interface determination unit, used to determine a number of target APIs called in the target function; An analysis processing unit is used to determine an analysis result according to the first transaction, the several target APIs, and the access types corresponding to the several target APIs, wherein the analysis result is used to determine whether there is a read-write conflict between the first transaction and other transactions, and the analysis result includes multiple grouping keys and the access types corresponding to the multiple grouping keys, wherein the multiple grouping keys include the contract address of the smart contract and the identification information of the several data objects accessed by the several target APIs indicated by the first transaction, and the access type corresponding to the contract address is read.
12. 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 10.
Citation Information
Patent Citations
Block chain privacy protection system and method capable of auditing and tracing
CN115906183A
Intelligent contract transaction rapid execution method based on fine-grained read-write analysis
CN116630040A
Transaction processing method in block chain system and block chain node
CN117408702A
Intelligent contract vulnerability detection method and system based on hybrid fuzzy test
CN117828616A
Optimization of execution of smart contracts
US20210318859A1