WO2023274409A1 - Method for executing transaction in blockchain system and blockchain node - Google Patents
Method for executing transaction in blockchain system and blockchain node Download PDFInfo
- Publication number
- WO2023274409A1 WO2023274409A1 PCT/CN2022/103384 CN2022103384W WO2023274409A1 WO 2023274409 A1 WO2023274409 A1 WO 2023274409A1 CN 2022103384 W CN2022103384 W CN 2022103384W WO 2023274409 A1 WO2023274409 A1 WO 2023274409A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- transaction
- existence
- variable
- execution
- contract
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2379—Updates performed during online database operations; commit processing
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
- G06F16/252—Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q20/00—Payment architectures, schemes or protocols
- G06Q20/38—Payment protocols; Details thereof
- G06Q20/389—Keeping log of transactions for guaranteeing non-repudiation of a transaction
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/50—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
Definitions
- the embodiment of this specification relates to the technical field of blockchain, and more specifically, relates to a method and blockchain nodes for executing transactions in a blockchain system.
- Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
- Blockchain is a chained data structure that combines data blocks in a sequential manner in chronological order, and is a cryptographically guaranteed non-tamperable and unforgeable distributed ledger. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application.
- smart contracts are allowed to be deployed and invoked in the blockchain system.
- key in order to prevent repeated creation of the same object or variable (hereafter denoted as key), before creating an object, it will first try to check the existence of the object, and only when the object does not exist will the subsequent operate.
- the embodiment of this specification aims to provide a more efficient method for executing transactions in the blockchain system, so that while executing the interface for confirming the existence of the key, the transaction is executed in parallel according to the preset existence of the key, reducing The time consumption caused by the key existence check improves the system efficiency.
- the first aspect of this specification provides a method for executing a transaction in a blockchain system, in which a contract is called in the transaction, and an interface function for confirming the existence of variables is called in the contract, and the method consists of Blockchain node execution, including:
- the second aspect of this specification provides a block chain node, the block chain node is used to execute the transaction, the contract is called in the transaction, the interface function used to confirm the existence of the variable is called in the contract, the block Chain nodes include:
- a first execution unit configured to execute the interface function
- the second execution unit is configured to execute the contract according to the preset existence of the variable before the result of the interface function is returned.
- a third aspect of the present specification provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed in a computer, the computer is instructed to execute any one of the methods described in the first aspect.
- the fourth aspect of this specification provides a blockchain node, including a memory and a processor, the memory stores executable code, and when the processor executes the executable code, any item method.
- the execution body that executes the transaction can use the interface provided by the platform to check the existence of the key when executing the transaction for the first time, and send the key existence key to the execution body that executes the platform code.
- the contract developer can predict the existence of the key with a high accuracy rate, that is, in the case where the actual existence of the key is the same as the preset existence, there is a high probability that there is no need to re-execute the transaction, which can reduce the execution of transactions In the process of waiting for the result of storage access, the transaction execution speed is improved and the system efficiency is improved.
- the blockchain platform can reduce the number of generation and sending of system requests by providing interfaces that combine key existence checks and other predetermined operations, and improve system efficiency.
- FIG. 1 shows a block chain architecture diagram applied in the embodiment of this specification
- Fig. 2 shows the architecture diagram of the blockchain node provided by the embodiment of this specification
- Fig. 3 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification
- Fig. 4 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification
- Fig. 5 shows an architecture diagram of a blockchain node provided by the embodiment of this specification.
- Fig. 1 shows a block chain system architecture diagram applied in the embodiment of this specification.
- the block chain system (hereinafter referred to as block chain) for example includes A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P has a total of 16 full nodes.
- the connection between nodes schematically represents a P2P (Peer to Peer, point-to-point) connection.
- P2P Peer to Peer, point-to-point
- each full-scale node in the blockchain generates the same state in the blockchain system by executing the same transaction, that is, each full-scale node in the blockchain performs the same operation and stores the same state database.
- the following describes the execution of a transaction in a node in the blockchain as an example.
- block chain shown in FIG. 1 is only exemplary, and the embodiment of this description is not limited to be applied to the block chain shown in FIG. 1 , for example, it can also be applied to a block chain system including sharding.
- the blockchain includes 16 full nodes
- the embodiment of this specification is not limited thereto, but may include other numbers of full nodes.
- the nodes contained in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements.
- BFT Byzantine Fault Tolerance
- the Byzantine fault tolerance requirement can be understood as that there may be Byzantine nodes inside the blockchain, but the blockchain does not reflect Byzantine behavior externally.
- some Byzantine fault-tolerant algorithms require the number of nodes to be greater than 3f+1, where f is the number of Byzantine nodes, such as the practical Byzantine fault-tolerant algorithm PBFT (Practical Byzantine Fault Tolerance).
- a block chain node includes a processing unit 21 and a storage unit 22 .
- the blockchain node is a single server
- the processing unit 21 can be a plurality of CPUs included in the server
- the storage unit 22 can be a storage medium (such as storage) included in the server
- the storage unit 22 For example, a block database and a state database are stored in it.
- the block database is used to store the block data in the blockchain
- the state database is used to store the state data in the blockchain.
- the blockchain node is a server cluster
- the processing unit 21 can be a CPU included in any server in the blockchain node
- the storage unit 22 can be a CPU included in any server in the blockchain node. storage medium.
- the blockchain node includes one or more servers and computing hardware (such as FPGA) connected to the server.
- the processing unit 21 can also include a CPU connected to the server. FPGA.
- TEE technology such as SGX of Intel, SEV of AMD, TrustZone (trusted area) of ARM, etc.
- TEE technology such as SGX of Intel, SEV of AMD, TrustZone (trusted area) of ARM, etc.
- the processing unit 21 when the processing unit 21 executes the contract called in the transaction, it usually executes the contract in a virtual machine, and the virtual machine is used to provide an execution environment for the contract. context, a cache for storing data during execution, etc.
- Ethereum Compared with the Bitcoin network, Ethereum has expanded, adopting the account system and world state, and can record the balance and state of the account directly through the account in the state database.
- Accounts in Ethereum can be divided into two types: Externally owned account: user’s account, such as the account of the owner of Ethereum; contract account: stores the executed smart contract code and the status of the smart contract code value, usually only activated by external account calls.
- the value of the state in the smart contract code is the value of the variable defined in the smart contract, and the value of the variable is stored in the state storage of the contract in the state database, for example, stored in the data structure of the MPT tree.
- the processing unit 21 may assign an execution body (for example, thread 1 ) to execute the transaction.
- the execution body may be implemented by one of the multiple CPUs in the server, or by the aforementioned FPGA.
- thread 1 can execute transactions in the TEE environment.
- the TEE may be implemented in the form of a virtual machine.
- thread 1 can send a storage access request to thread 2, and wait for thread 2 to return the access result to the state database, or thread 1
- the execution of the transaction can be suspended, and the state database can be accessed, and the execution of the transaction can be resumed after the access result is obtained.
- the thread 1 that executes the transaction can send the key existence check request to the thread 2, so that the thread 2 can read the value of the key And return the read result to determine the existence of the key.
- thread 2 sends the read request to the state database in the hard disk, and waits for the hard disk to return the read result. Thread 1 needs to obtain the reading result through thread 2 before continuing to execute the transaction, which takes a lot of time and reduces the execution efficiency of the transaction.
- the embodiment of this specification provides a solution for executing a transaction.
- the thread 1 that executes the transaction needs to check the existence of the key, based on the interface provided by the blockchain platform to confirm the existence of the key, it sends a message to the thread 2 to check the existence of the key.
- the request for a security check executes the transaction based on the preset existence of the key.
- the preset existence is likely to be the same as the actual existence of the key, there is a high probability that there is no need to re-execute the transaction, and thread 1 can execute the transaction while thread 2 is performing storage access, which reduces the transaction execution time and improves the transaction efficiency. execution efficiency.
- the module executes the key existence check interface and transaction in parallel through two execution bodies, but any method that can realize parallel execution can be adopted, for example, two execution bodies in one execution body can be used
- the module executes the key existence check interface and the transaction. After one module executes the key existence check interface, it sends an access request to the storage (such as a hard disk), so that another module can execute the transaction in parallel while waiting for the result of the access.
- the storage such as a hard disk
- Fig. 3 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification, the flow is executed by threads 1 and 2 in the blockchain node, wherein thread 1 is used to execute transactions, and thread 2 is used to execute the code provided by the blockchain platform, which is used to support the execution of the transaction.
- a contract is called in the transaction, and an interface function for confirming the existence of variables is called in the contract.
- thread 1 executes step S301 to execute a transaction and generate a key existence confirmation request.
- an interface ie, a function for confirming the existence of variables can be provided in the blockchain platform.
- a new key will be added to the contract called in the transaction, and the interface used to confirm the existence of the variable is called before the addition to check the existence of the key to confirm whether the key does not exist.
- the contract includes, for example, the following instructions:
- the KeyexistCheck() function is an interface provided by the blockchain platform to check whether the key exists, and the contract can directly call this interface to check the existence of the key.
- the KeyexistHandle() function is a function defined in the contract, which is used to perform predetermined operations when the key existence returned by the KeyexistCheck() function exists, such as returning transaction failure to the user. "Else" indicates that the SetKV() function is executed when the key existence returned by the KeyexistCheck() function does not exist.
- the SetKV() function is used to create a new key (such as key1), where new_value is the initial value of key1. After thread 1 starts to execute the contract, after executing the above-mentioned KeyexistCheck() function contained in the contract, it can generate a request corresponding to this function for confirming the existence of the key and send it to thread 2.
- the AddNewKey interface can be provided in the blockchain platform, which is used to check the existence and add the key when it is determined that the key does not exist.
- the above interface can be called in the contract.
- the contract can be set to perform predetermined operations when the existence of the key returned by the AddNewKey interface exists, such as returning a transaction failure to the user.
- thread 1 executes the AddNewKey interface, it can generate a corresponding request for executing the AddNewKey interface to send to thread 2.
- Thread 2 sends an access request for the key to the storage according to the request, and while waiting for the access result, the operation of adding the key can be performed in parallel.
- the operation of adding a Key may include, according to the incoming parameters of AddNewKey, recording the key identifier and the initial value of the key in memory for subsequent updates to the storage, for example, updating to the storage after all transactions in the block are executed middle.
- thread 2 can delete the operation result of the operation of adding the key that has been executed, or can terminate the execution of the contract according to the settings in the AddNewKey interface, end the transaction, and return transaction failed.
- the existing key will be deleted in the contract called in the transaction, and the interface provided by the blockchain platform for determining the existence of the variable is called before the deletion to check the existence of the key. Check to see if the key exists.
- the contract includes, for example, the following instructions:
- the KeynotexistCheck() function is an interface provided by the blockchain platform to check whether the key (such as key1 shown in the code) does not exist, and the interface can be directly called in the contract.
- the KeynotexistHandle() function is a function defined in the contract, which is used to perform predetermined operations when the existence of the key returned by the KeynotexistCheck() function is non-existent, such as returning a transaction failure to the user. "Else" indicates that the DelKV() function is executed when the key existence returned by the KeynotexistCheck() function exists.
- the DelKV() function is used to delete the key. After the thread 1 in the processing unit 21 starts to execute the contract in the virtual machine, after executing the above-mentioned KeynotexistCheck() function contained in the contract, it can generate a request for confirming the existence of the key and send it to the thread 2.
- the DelKey interface can be provided in the blockchain platform, which is used to check the existence of the key and delete the key when it is determined that the key exists.
- the above interface can be called in the contract.
- thread 1 in the blockchain node executes the DelKey interface, it can generate a corresponding request to execute the DelKey interface to send to thread 2.
- Thread 2 sends an access request to the storage according to the request, and waits for the result of the access.
- the operation of deleting the Key can be performed in parallel. Similar to the above, the operation of deleting the key can be performed in memory.
- thread 1 may only send a system request to thread 2 when calling the interface.
- thread 1 is implemented in FPGA
- the communication between thread 1 and thread 2 is the communication between two hardwares (i.e. server and FPGA), and the communication cost is relatively high, so the above-mentioned AddNewkey interface and DelKey interface can be greatly improved. Reduce the resource overhead of generating and sending system requests and improve system efficiency.
- step S302 thread 1 sends the generated key existence confirmation request to thread 2.
- step S303 thread 1 continues to execute the transaction according to the preset existence of the key.
- the code of the above-mentioned KeyexistCheck interface thread 1 can use the existence of key1 corresponding to the Else branch as the preset existence, thereby executing the Else branch in the contract.
- thread 1 can similarly execute the transaction according to the preset existence (that is, execute the contract called in the transaction).
- thread 1 when thread 1 executes step S303, it continues to execute the subsequent code in the contract, that is, the key creation operation in the transaction, assuming that key1 does not exist. For example, as shown in the code in the first case above, thread 1 can continue to execute the code SetKV(key1, new_value) in the contract, that is, create key1 in the storage.
- thread 2 since thread 2 performs the operation of creating key1 when it is determined that key1 does not exist, and the operation of creating key1 performed by thread 2 will not affect the subsequent operations in thread 1's execution of the transaction, therefore, thread 1 You can follow the thread 2 assumption that key1 does not exist and key1 has been created, and continue to execute subsequent operations in the contract called by the exchange.
- thread 1 continues to execute the subsequent code in the contract assuming that the key exists, that is, the operation of deleting the key in the contract. For example, as shown in the code in the third case above, thread 1 may execute the code "DelKV(key1)" according to the existence of key1, that is, delete "key1" in the state database.
- thread 1 can continue to perform subsequent operations in the transaction assuming that the key exists and has been deleted.
- Thread 2 performs storage access in step S304 to confirm the existence of the key.
- thread 2 can access the state database in the hard disk to read the value of key1 from the state database to confirm whether key1 exists. If the value of key1 is read, it can be confirmed that key1 already exists. key1 value, it can be confirmed that key1 does not exist. After thread 2 determines the existence of key1 according to the storage access result, it may store the existence of key1 in the memory.
- step S305 thread 1 sends a system service request to thread 2.
- Thread 1 may generate a new system service request in the process of continuing to execute the transaction and needs to send it to thread 2 to request system service.
- the system service requests include, for example, other key existence confirmation requests, transaction completion requests, and other requests. It can be understood that since thread 2 can execute step S306 at any time before the end of the transaction, it is also possible to execute step S306 before thread 1 sends the system service request. Therefore, step S305 is shown with a dotted line in FIG. 3 , indicating that this step is Optional step.
- step S306 thread 2 determines whether to re-execute the transaction.
- Thread 2 can execute this step at any time before the end of the transaction, for example, after receiving any system service request, to determine whether to re-execute the transaction. At this time, if thread 2 has not obtained the result of the above storage access, assuming that the system service request is the existence confirmation request of other keys, thread 2 can determine not to re-execute the transaction, so that thread 1 and thread 2 can continue with the above key1. Handle the same process; assume that the system service request is a transaction completion request, that is, thread 1 has executed all the processing in the transaction, and requests to end the execution of the transaction. Thread 2 needs to wait for the result of the storage access, and obtain the result of the storage access Then confirm the existence of key1 to determine whether to re-execute the transaction.
- thread 2 If thread 2 has obtained the result of the storage access and stored the existence of key1 in memory, it can read the existence of key1 from memory and compare the existence of key1 with the above preset existence to determine whether Re-execute the transaction. If the existence of key1 is the same as the preset existence, there is no need to re-execute the transaction. Specifically, if the system server request is an existence confirmation request for other keys, thread 1 and thread 2 can continue to perform the same processing as the above-mentioned processing for key1; assuming that the system service request is a transaction completion request, thread 2 can complete the transaction. processing, and notify thread 1 to end the execution of the transaction.
- thread 2 executes step S307, and sends a notification to thread 1 to re-execute the transaction.
- thread 1 After thread 1 receives the notification of re-executing the transaction, it executes step S308, discards the execution result data generated during the previous execution of the transaction, and re-executes the transaction. In the process of re-executing the transaction, thread 1 may generate a key (namely key1) existence confirmation request again, and then perform step S309 to send the key existence confirmation request to thread 2.
- a key namely key1 existence confirmation request again
- thread 1 after thread 1 receives the notification of re-executing the transaction, it can add 1 to the parameter T defined in the contract to indicate that the execution of the transaction is the second execution, that is, not the first time Execution, or in another embodiment, after thread 2 sends the notification of re-execution of the transaction, it may add 1 to the parameter N defined in the platform code to indicate that the execution of the transaction is the second execution. Therefore, after thread 1 sends a key existence request to thread 2, it can determine that the execution of the transaction is not the first execution according to the value of parameter T, so it waits for thread 2 to return the response to the request.
- thread 2 After thread 2 receives the key existence confirmation request, it can determine that the execution of the transaction is not the first execution according to the value of parameter N. Therefore, thread 2 obtains the existence of key1 from the memory, and executes step S310, according to the existence A request response is returned, and it can be understood that the response here indicates that the existence of key1 is different from the preset existence.
- thread 1 After thread 1 receives the response returned by thread 2, it executes step S311 to end the execution of the transaction. Since the response returned by thread 2 indicates that the existence of key1 is different from the preset existence, the execution of the transaction fails, thread 1 ends the execution of the transaction, and returns the failure of the execution of the transaction to the user.
- Figure 4 shows a method for executing a transaction in a blockchain system provided by an embodiment of this specification, in which a contract is called, and an interface function for confirming the existence of a variable is called in the contract, and the method is determined by the block Block chain node execution, including:
- Step S401 execute the interface function
- Step S403 before the result of the interface function is returned, execute the contract according to the preset existence of the variable.
- step S401 and step S403 in FIG. 4 For details of step S401 and step S403 in FIG. 4 , reference may be made to the specific description of step S304 and step S303 above, which will not be repeated here.
- the executing the interface function includes: sending an access request to storage to confirm the existence of the variable.
- the executing the interface function further includes: performing predetermined processing on the variable according to the preset existence before waiting for the storage to return a result to the access request.
- the interface function is used to: add the variable in the storage when it is confirmed that the variable does not exist, or delete the variable in the storage when it is confirmed that the variable exists.
- the method further includes, before the execution of the transaction is completed, obtaining the access result of the access request, and determining the existence of the variable and the preset existence according to the access result In the case of different properties, it is determined to re-execute the transaction.
- the contract defines a first parameter indicating the number of transaction execution times
- executing the contract according to the preset existence of the variable includes determining that the transaction is executed according to the first parameter Executing the contract is executed for the first time, executing the contract according to the preset existence of the variable, and the method further includes updating the first parameter after determining to re-execute the transaction.
- the method further includes, when starting to execute the interface function in the re-execution of the transaction, if the transaction is determined to be executed not for the first time according to the first parameter, when obtaining the execution After the existence of the variable is returned by the interface function, the contract is executed according to the existence of the variable.
- the code of the interface function defines a second parameter indicating the number of transaction execution times
- the execution of the interface function includes determining that the execution of the transaction is the first execution according to the second parameter Afterwards, returning a confirmation response to the preset existence
- the executing the contract according to the preset existence of the variable includes executing the contract according to the preset existence of the variable according to the confirmation response
- the method also includes, after determining to re-execute the transaction, updating the second parameter.
- Fig. 5 shows an architecture diagram of a block chain node provided by the embodiment of this specification, the block chain node is used to execute a transaction, the contract is called in the transaction, and the contract is called in the contract to confirm the existence of the variable Interface function, the blockchain node includes:
- the first execution unit 51 is configured to execute the interface function
- the second execution unit 52 is configured to execute the contract according to the preset existence of the variable before the result of the interface function is returned.
- the first execution unit 51 is further configured to: send an access request to the storage to confirm the existence of the variable.
- the first execution unit 51 is further configured to: perform predetermined processing on the variable according to the preset existence before waiting for the storage to return a result to the access request.
- the interface function is used to: add the variable in the storage when it is confirmed that the variable does not exist, or delete the variable in the storage when it is confirmed that the variable exists.
- the block chain node further includes a determination unit 53, configured to obtain the access result of the access request before the execution of the transaction is completed, and determine the value of the variable according to the access result If the existence is different from the preset existence, it is determined to re-execute the transaction.
- a determination unit 53 configured to obtain the access result of the access request before the execution of the transaction is completed, and determine the value of the variable according to the access result If the existence is different from the preset existence, it is determined to re-execute the transaction.
- the contract defines a first parameter indicating the number of transaction execution times
- the second execution unit 52 is further configured to determine that the execution of the transaction is the first execution according to the first parameter , execute the contract according to the preset existence of the variable
- the block chain node further includes an updating unit 54, configured to update the first parameter after it is determined to re-execute the transaction.
- the block chain node further includes a re-execution unit, configured to start executing the interface function in the re-execution of the transaction, when it is determined according to the first parameter that the transaction is not In the case of the first execution, after obtaining the existence of the variable returned by executing the interface function, execute the contract according to the existence of the variable.
- a re-execution unit configured to start executing the interface function in the re-execution of the transaction, when it is determined according to the first parameter that the transaction is not In the case of the first execution, after obtaining the existence of the variable returned by executing the interface function, execute the contract according to the existence of the variable.
- the code of the interface function defines a second parameter indicating the number of transaction execution times
- the first execution unit 51 is further configured to determine that the execution of the transaction is the first according to the second parameter.
- the second execution unit 52 is also used to execute the contract according to the preset existence of the variable according to the confirmation response
- the update unit 54 is further configured to update the second parameter after it is determined to re-execute the transaction.
- the embodiment of this specification also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed in a computer, the computer is instructed to execute the methods shown in FIG. 3 and FIG. 4 .
- the embodiment of this specification also provides a block chain node, including a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, the methods shown in Figure 3 and Figure 4 are implemented .
- the software module can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or technical field Any other form of storage medium known in the art.
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Business, Economics & Management (AREA)
- Data Mining & Analysis (AREA)
- Accounting & Taxation (AREA)
- Strategic Management (AREA)
- Computing Systems (AREA)
- General Business, Economics & Management (AREA)
- Finance (AREA)
- Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
本申请要求于2021年07月02日提交中国国家知识产权局、申请号为2021107489771、申请名称为“在区块链系统中执行交易的方法和区块链节点”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 2021107489771 and the application title "method and blockchain node for executing transactions in a blockchain system" submitted to the State Intellectual Property Office of China on July 02, 2021, The entire contents of which are incorporated by reference in this application.
本说明书实施例涉及区块链技术领域,更具体地,涉及一种在区块链系统中执行交易的方法和区块链节点。The embodiment of this specification relates to the technical field of blockchain, and more specifically, relates to a method and blockchain nodes for executing transactions in a blockchain system.
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链是一种按照时间顺序将数据区块以顺序相连的方式组合成的一种链式数据结构,并以密码学方式保证的不可篡改和不可伪造的分布式账本。由于区块链具有去中心化、信息不可篡改、自治性等特性,区块链也受到人们越来越多的重视和应用。Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain is a chained data structure that combines data blocks in a sequential manner in chronological order, and is a cryptographically guaranteed non-tamperable and unforgeable distributed ledger. Due to the characteristics of decentralization, non-tamperable information, and autonomy, the blockchain has also received more and more attention and application.
在例如以太坊的区块链系统中,允许在区块链系统中部署和调用智能合约。在很多智能合约中,为了防止重复创建相同的对象或变量(下文表示为key),在创建对象前会首先试图检查该对象的存在性,并且只有在此对象并不存在时才会执行后续的操作。In a blockchain system such as Ethereum, smart contracts are allowed to be deployed and invoked in the blockchain system. In many smart contracts, in order to prevent repeated creation of the same object or variable (hereafter denoted as key), before creating an object, it will first try to check the existence of the object, and only when the object does not exist will the subsequent operate.
发明内容Contents of the invention
本说明书实施例旨在提供一种更有效的在区块链系统中执行交易的方法,使得在执行用于确认key存在性的接口的同时,并行地按照key的预设存在性执行交易,减少因key存在性检查造成的耗时,提高了系统效率。The embodiment of this specification aims to provide a more efficient method for executing transactions in the blockchain system, so that while executing the interface for confirming the existence of the key, the transaction is executed in parallel according to the preset existence of the key, reducing The time consumption caused by the key existence check improves the system efficiency.
为实现上述目的,本说明书第一方面提供一种在区块链系统中执行交易的方法,所述交易中调用合约,所述合约中调用用于确认变量存在性的接口函数,所述方法由区块链节点执行,包括:In order to achieve the above purpose, the first aspect of this specification provides a method for executing a transaction in a blockchain system, in which a contract is called in the transaction, and an interface function for confirming the existence of variables is called in the contract, and the method consists of Blockchain node execution, including:
执行所述接口函数;Execute the interface function;
在所述接口函数的结果返回之前,按照所述变量的预设存在性执行所述合约。Before the result of the interface function is returned, the contract is executed according to the preset existence of the variable.
本说明书第二方面提供一种区块链节点,所述区块链节点用于执行交易,所述交易中调用合约,所述合约中调用用于确认变量存在性的接口函数,所述区块链节点包括:The second aspect of this specification provides a block chain node, the block chain node is used to execute the transaction, the contract is called in the transaction, the interface function used to confirm the existence of the variable is called in the contract, the block Chain nodes include:
第一执行单元,用于执行所述接口函数;a first execution unit, configured to execute the interface function;
第二执行单元,用于在所述接口函数的结果返回之前,按照所述变量的预设存在性执行所述合约。The second execution unit is configured to execute the contract according to the preset existence of the variable before the result of the interface function is returned.
本说明书第三方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行第一方面所述的任一项方法。A third aspect of the present specification provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed in a computer, the computer is instructed to execute any one of the methods described in the first aspect.
本说明书第四方面提供一种区块链节点,包括存储器和处理器,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现第一方面所述的任一项方法。The fourth aspect of this specification provides a blockchain node, including a memory and a processor, the memory stores executable code, and when the processor executes the executable code, any item method.
通过本说明书实施例提供的执行交易的方案,执行交易的执行体在首次执行交易时可以通过平台提供的用于检查key存在性的接口,向执行平台代码的执行体发送用于进行key存在性检查的请求,并且平台在收到该请求后,按照key的预设存在性,让交易执行体继续执行交易,执行平台代码的执行体在接收到上述请求之后进行存储访问并根据存储访问 的结果确定是否重新执行交易,并通知执行交易的执行体。在合约开发人员能较高准确率预估key存在性的情况中,即在key的实际存在性与预设存在性大概率相同的情况中,大概率不需要重新执行交易,从而可以减少执行交易的过程中等待存储访问的结果的时间,提高了交易执行速度,提高了系统效率。另外,区块链平台通过提供结合key存在性检查和其它预定操作的接口,可以减少对系统请求的生成和发送次数,提高了系统效率。Through the transaction execution scheme provided by the embodiment of this specification, the execution body that executes the transaction can use the interface provided by the platform to check the existence of the key when executing the transaction for the first time, and send the key existence key to the execution body that executes the platform code. Check the request, and after the platform receives the request, according to the preset existence of the key, let the transaction execution body continue to execute the transaction, and the execution body that executes the platform code performs storage access after receiving the above request and according to the result of the storage access Determine whether to re-execute the transaction, and notify the executive that executed the transaction. In the case where the contract developer can predict the existence of the key with a high accuracy rate, that is, in the case where the actual existence of the key is the same as the preset existence, there is a high probability that there is no need to re-execute the transaction, which can reduce the execution of transactions In the process of waiting for the result of storage access, the transaction execution speed is improved and the system efficiency is improved. In addition, the blockchain platform can reduce the number of generation and sending of system requests by providing interfaces that combine key existence checks and other predetermined operations, and improve system efficiency.
通过结合附图描述本说明书实施例,可以使得本说明书实施例更加清楚:By describing the embodiments of this specification in conjunction with the accompanying drawings, the embodiments of this specification can be made clearer:
图1示出本说明书实施例所应用的区块链架构图;FIG. 1 shows a block chain architecture diagram applied in the embodiment of this specification;
图2示出本说明书实施例提供的区块链节点的架构图;Fig. 2 shows the architecture diagram of the blockchain node provided by the embodiment of this specification;
图3示出本说明书实施例提供的一种在区块链中执行交易的方法流程图;Fig. 3 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification;
图4示出本说明书实施例提供的一种在区块链中执行交易的方法流程图;Fig. 4 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification;
图5示出本说明书实施例提供的一种区块链节点的架构图。Fig. 5 shows an architecture diagram of a blockchain node provided by the embodiment of this specification.
下面将结合附图描述本说明书实施例。Embodiments of this specification will be described below with reference to the accompanying drawings.
图1示出本说明书实施例所应用的区块链系统架构图。如图1中,区块链系统(下文简称为区块链)中例如包含A、B、C、D、E、F、G、H、I、J、K、L、M、N、O、P共16个全量节点。节点之间的连线示意性的表示P2P(Peer to Peer,点对点)连接。这些节点上都存储全量的账本,即承担着存储全部交易、智能合约和各种状态。其中,区块链中的每个全量节点通过执行相同的交易而产生区块链系统中的相同的状态,即,区块链中的每个全量节点执行相同的操作,存储相同的状态数据库。下文中以区块链中的一个节点中对交易的执行为例进行描述。Fig. 1 shows a block chain system architecture diagram applied in the embodiment of this specification. As shown in Figure 1, the block chain system (hereinafter referred to as block chain) for example includes A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P has a total of 16 full nodes. The connection between nodes schematically represents a P2P (Peer to Peer, point-to-point) connection. These nodes store a full amount of books, that is, they are responsible for storing all transactions, smart contracts and various states. Among them, each full-scale node in the blockchain generates the same state in the blockchain system by executing the same transaction, that is, each full-scale node in the blockchain performs the same operation and stores the same state database. The following describes the execution of a transaction in a node in the blockchain as an example.
可以理解,图1所示的区块链仅仅是示例性的,本说明书实施例不限于应用于图1所示的区块链,例如还可以应用于包括分片的区块链系统中。It can be understood that the block chain shown in FIG. 1 is only exemplary, and the embodiment of this description is not limited to be applied to the block chain shown in FIG. 1 , for example, it can also be applied to a block chain system including sharding.
另外,图1中虽然示出了区块链中包括16个全量节点,本说明书实施例不限于此,而是可以包括其他数目的全量节点。具体是,区块链中包含的节点可以满足拜占庭容错(Byzantine Fault Tolerance,BFT)要求。所述的拜占庭容错要求可以理解为在区块链内部可以存在拜占庭节点,而区块链对外不体现拜占庭行为。一般的,一些拜占庭容错算法中要求节点个数大于3f+1,f为拜占庭节点个数,例如实用拜占庭容错算法PBFT(Practical Byzantine Fault Tolerance)。In addition, although it is shown in FIG. 1 that the blockchain includes 16 full nodes, the embodiment of this specification is not limited thereto, but may include other numbers of full nodes. Specifically, the nodes contained in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements. The Byzantine fault tolerance requirement can be understood as that there may be Byzantine nodes inside the blockchain, but the blockchain does not reflect Byzantine behavior externally. Generally, some Byzantine fault-tolerant algorithms require the number of nodes to be greater than 3f+1, where f is the number of Byzantine nodes, such as the practical Byzantine fault-tolerant algorithm PBFT (Practical Byzantine Fault Tolerance).
图2示出本说明书实施例提供的区块链节点的架构图。如图2所示,区块链节点中包括处理单元21和存储单元22。在一种实施方式中,区块链节点为单台服务器,处理单元21可以为该服务器中包括的多个CPU,存储单元22可以为该服务器中包括的存储介质(如存储),存储单元22中例如存储有区块数据库和状态数据库。其中,区块数据库用于存储区块链中的区块数据,状态数据库中用于存储区块链中的状态数据。在另一种实施方式中,区块链节点为服务器集群,处理单元21可以为区块链节点中的任一服务器中包括的CPU,存储单元22可以为区块链节点中任一服务器中包括的存储介质。在另一种实施方式中,区块链节点包括一台或多台服务器和与服务器连接的计算硬件(如FPGA),处理单元21除了包括服务器中的CPU之外,还可以包括为与服务器连接的FPGA。另外,在处理单元21为服务器中的CPU的情况中,服务器中可使用TEE技术(如Intel的SGX,AMD的SEV,ARM的TrustZone(可信区)等),从而处理单元21可以在TEE中进行例如执行交易的处理。其中,在上述各种实施方式中,处理单元21在执行交易中调用的合约时,通常在虚拟机中执行合约,虚拟机用于为合约提供执行环境,在该执行环境中包括用于执行合约的上下文、用于存储执行过程中的数据的缓存等。Fig. 2 shows the architecture diagram of the blockchain node provided by the embodiment of this specification. As shown in FIG. 2 , a block chain node includes a processing unit 21 and a storage unit 22 . In one embodiment, the blockchain node is a single server, the processing unit 21 can be a plurality of CPUs included in the server, the storage unit 22 can be a storage medium (such as storage) included in the server, and the storage unit 22 For example, a block database and a state database are stored in it. Among them, the block database is used to store the block data in the blockchain, and the state database is used to store the state data in the blockchain. In another embodiment, the blockchain node is a server cluster, the processing unit 21 can be a CPU included in any server in the blockchain node, and the storage unit 22 can be a CPU included in any server in the blockchain node. storage medium. In another embodiment, the blockchain node includes one or more servers and computing hardware (such as FPGA) connected to the server. In addition to the CPU in the server, the processing unit 21 can also include a CPU connected to the server. FPGA. In addition, in the case where the processing unit 21 is the CPU in the server, TEE technology (such as SGX of Intel, SEV of AMD, TrustZone (trusted area) of ARM, etc.) can be used in the server, so that the processing unit 21 can be in the TEE Perform processing such as executing transactions. Among them, in the above-mentioned various embodiments, when the processing unit 21 executes the contract called in the transaction, it usually executes the contract in a virtual machine, and the virtual machine is used to provide an execution environment for the contract. context, a cache for storing data during execution, etc.
鉴于很多区块链平台和应用是基于以太坊(Ethereum)的底层技术而构建的,这里以太坊为例对状态数据库进行说明。当然,基于其他区块链技术构建的区块链系统,也可能适用于本说明书实施例,例如基于Fabric的超级账本(Hyperledger)和企业操作系统(Enterprise Operating System,EOS)、Quorum、Corda等,不再赘述。In view of the fact that many blockchain platforms and applications are built based on the underlying technology of Ethereum, here we take Ethereum as an example to illustrate the state database. Of course, blockchain systems based on other blockchain technologies may also be applicable to the embodiments of this specification, such as Fabric-based hyperledger (Hyperledger) and enterprise operating system (Enterprise Operating System, EOS), Quorum, Corda, etc. No longer.
以太坊相比于比特币网络进行了拓展,采用账户系统和世界状态,可以在状态数据库中直接通过账户来记录账户的余额和状态。以太坊的账户可以分为两种类型:外部账户(Externally owned account):用户的账户,例如以太币拥有者账户;合约账户(contract account):存储执行的智能合约代码以及智能合约代码中状态的值,通常只能通过外部账户调用激活。其中,智能合约代码中状态的值即为在智能合约中定义的变量的值,该变量的值存储在状态数据库中的合约的状态存储中,例如,以MPT树的数据结构存储。Compared with the Bitcoin network, Ethereum has expanded, adopting the account system and world state, and can record the balance and state of the account directly through the account in the state database. Accounts in Ethereum can be divided into two types: Externally owned account: user’s account, such as the account of the owner of Ethereum; contract account: stores the executed smart contract code and the status of the smart contract code value, usually only activated by external account calls. Among them, the value of the state in the smart contract code is the value of the variable defined in the smart contract, and the value of the variable is stored in the state storage of the contract in the state database, for example, stored in the data structure of the MPT tree.
参考图2,当区块链节点执行交易时,处理单元21可以分配一个执行体(例如线程1)执行交易。其中,该执行体可以通过服务器中的多个CPU中的一个CPU实现,或者通过前述FPGA实现。其中,在线程1通过CPU实现的情况中,线程1可在TEE环境中执行交易。在该交易调用合约的情况中,该TEE可实现为虚拟机的形式。当交易的执行过程中需要访问存储单元22中的状态数据库时,在相关技术中,线程1可将存储访问请求发送给线程2,并等待线程2返回对状态数据库的访问结果,或者,线程1可中止对交易的执行,并进行对状态数据库的访问,在获取到访问结果之后再恢复对交易的执行。Referring to FIG. 2 , when a blockchain node executes a transaction, the processing unit 21 may assign an execution body (for example, thread 1 ) to execute the transaction. Wherein, the execution body may be implemented by one of the multiple CPUs in the server, or by the aforementioned FPGA. Among them, in the case that thread 1 is implemented by CPU, thread 1 can execute transactions in the TEE environment. In the case of the transaction calling contract, the TEE may be implemented in the form of a virtual machine. When the state database in the storage unit 22 needs to be accessed during the execution of the transaction, in related technologies, thread 1 can send a storage access request to thread 2, and wait for thread 2 to return the access result to the state database, or thread 1 The execution of the transaction can be suspended, and the state database can be accessed, and the execution of the transaction can be resumed after the access result is obtained.
其中,在很多合约中,包括对key的存在性的检查。例如,为了防止重复创建某个key(重复创建key,会导致该key之前的值被覆盖),(set:创建和更新)在创建key前会首先检查key的存在性,如果不存在才执行创建操作。或者,为了确认删除动作有效(“删除不存在的key”说明系统存在异常),在删除key之前首先检查key的存在性,如果存在才执行删除操作。区块链节点在执行调用该合约的交易时,当需要检查key的存在性时,执行交易的线程1可将key存在性检查请求发送给线程2,从而线程2通过对key的value进行读取并返回读取结果,以此确定key的存在性。在对key进行读取时,线程2将读取请求发送给硬盘中的状态数据库,并等待硬盘返回读取结果。线程1需要在通过线程2获取到读取结果之后才能继续进行对交易的执行,耗时较多,降低了交易的执行效率。Among them, in many contracts, including the check of the existence of the key. For example, in order to prevent repeated creation of a key (repeated key creation will cause the previous value of the key to be overwritten), (set: create and update) will first check the existence of the key before creating the key, and only execute the creation if it does not exist operate. Or, in order to confirm that the delete action is valid ("Delete a key that does not exist" indicates that the system is abnormal), before deleting the key, first check the existence of the key, and only execute the delete operation if it exists. When the blockchain node executes the transaction that calls the contract, when it is necessary to check the existence of the key, the thread 1 that executes the transaction can send the key existence check request to the thread 2, so that the thread 2 can read the value of the key And return the read result to determine the existence of the key. When reading the key, thread 2 sends the read request to the state database in the hard disk, and waits for the hard disk to return the read result. Thread 1 needs to obtain the reading result through thread 2 before continuing to execute the transaction, which takes a lot of time and reduces the execution efficiency of the transaction.
本说明书实施例提供一种执行交易的方案,执行交易的线程1在需要进行key存在性检查时,基于由区块链平台提供的确认key的存在性的接口,对线程2发送用于进行存在性检查的请求,基于key的预设存在性执行交易。在预设存在性大概率与key的实际存在性相同的情况中,大概率不需要重新执行交易,而线程1可以在线程2进行存储访问的同时执行交易,减少了交易执行时间,提高了交易的执行效率。可以理解,在本说明书实施例中,不限于通过两个执行体并行执行key存在性检查接口和交易,而是可以采用任何可以实现并行执行的方式,例如,可通过一个执行体中的两个模块执行key存在性检查接口和交易,其中当一个模块执行key存在性检查接口之后,向存储(例如硬盘)发送访问请求,从而另一个模块在等待访问的结果的同时可并行地执行交易中的后续操作。下文中,将以两个执行体并行执行为例进行描述。The embodiment of this specification provides a solution for executing a transaction. When the thread 1 that executes the transaction needs to check the existence of the key, based on the interface provided by the blockchain platform to confirm the existence of the key, it sends a message to the thread 2 to check the existence of the key. The request for a security check executes the transaction based on the preset existence of the key. In the case where the preset existence is likely to be the same as the actual existence of the key, there is a high probability that there is no need to re-execute the transaction, and thread 1 can execute the transaction while thread 2 is performing storage access, which reduces the transaction execution time and improves the transaction efficiency. execution efficiency. It can be understood that in the embodiment of this specification, it is not limited to execute the key existence check interface and transaction in parallel through two execution bodies, but any method that can realize parallel execution can be adopted, for example, two execution bodies in one execution body can be used The module executes the key existence check interface and the transaction. After one module executes the key existence check interface, it sends an access request to the storage (such as a hard disk), so that another module can execute the transaction in parallel while waiting for the result of the access. Follow up. In the following, the parallel execution of two executives will be taken as an example for description.
下文将详细描述本说明书实施例提供的执行交易的方案。The scheme for executing a transaction provided by the embodiment of this specification will be described in detail below.
图3示出本说明书实施例提供的一种在区块链中执行交易的方法流程图,该流程由区块链节点中的线程1和线程2执行,其中,线程1用于执行交易,线程2用于执行区块链平台提供的代码,该代码用于支持该交易的执行。所述交易中调用合约,所述合约中调用用于确认变量存在性的接口函数。Fig. 3 shows a flow chart of a method for executing a transaction in a blockchain provided by an embodiment of this specification, the flow is executed by threads 1 and 2 in the blockchain node, wherein thread 1 is used to execute transactions, and thread 2 is used to execute the code provided by the blockchain platform, which is used to support the execution of the transaction. A contract is called in the transaction, and an interface function for confirming the existence of variables is called in the contract.
参考图3,首先,线程1执行步骤S301,执行交易,生成key存在性确认请求。Referring to FIG. 3 , first, thread 1 executes step S301 to execute a transaction and generate a key existence confirmation request.
在执行调用合约的交易时,在进行与合约中定义的key相关的操作之前,需要首先确认key的存在性。例如,在执行调用合约的交易时,在添加变量之前,可首先确认该变量是否不存在,或者在删除变量之前,可首先确认该变量是否存在。When executing a transaction that calls a contract, before performing operations related to the key defined in the contract, it is necessary to first confirm the existence of the key. For example, when executing a transaction that calls a contract, before adding a variable, it can first be confirmed whether the variable does not exist, or before deleting the variable, it can first be confirmed whether the variable exists.
在第一种情况中,区块链平台中可提供用于确认变量存在性的接口(即函数)。假设交易中调用的合约中将要添加新的key,并在该添加之前调用用于确认变量存在性的接口,以进行对key的存在性的检查,从而确认key是否不存在。具体是,合约中例如包括如下指令:In the first case, an interface (ie, a function) for confirming the existence of variables can be provided in the blockchain platform. Assume that a new key will be added to the contract called in the transaction, and the interface used to confirm the existence of the variable is called before the addition to check the existence of the key to confirm whether the key does not exist. Specifically, the contract includes, for example, the following instructions:
If(KeyexistCheck(key1))If(KeyexistCheck(key1))
{KeyexistHandle(key1)},{KeyexistHandle(key1)},
Else SetKV(key1,new_value);Else SetKV(key1, new_value);
其中,KeyexistCheck()函数为由区块链平台提供的用于检查key是否存在的接口,合约中可直接调用该接口,以进行对key存在性的检查。KeyexistHandle()函数是合约中定义的函数,用于在KeyexistCheck()函数返回的key存在性为存在的情况下进行的预定操作,例如向用户返回交易失败等。“Else”表示,在KeyexistCheck()函数返回的key存在性为不存在的情况下,执行SetKV()函数。SetKV()函数用于创建新的key(例如key1),其中new_value为key1的初始值。线程1在开始执行合约之后,当执行到合约中包含的上述KeyexistCheck()函数之后,可以生成与该函数对应的用于确认key存在性的请求,以发送给线程2。Among them, the KeyexistCheck() function is an interface provided by the blockchain platform to check whether the key exists, and the contract can directly call this interface to check the existence of the key. The KeyexistHandle() function is a function defined in the contract, which is used to perform predetermined operations when the key existence returned by the KeyexistCheck() function exists, such as returning transaction failure to the user. "Else" indicates that the SetKV() function is executed when the key existence returned by the KeyexistCheck() function does not exist. The SetKV() function is used to create a new key (such as key1), where new_value is the initial value of key1. After thread 1 starts to execute the contract, after executing the above-mentioned KeyexistCheck() function contained in the contract, it can generate a request corresponding to this function for confirming the existence of the key and send it to thread 2.
在第二种情况中,区块链平台中可以提供AddNewKey接口,该接口用于进行存在性检查、在确定key不存在的情况中,添加key。合约中可在需要添加key时,在合约中调用上述接口。与上述第一种情况类似地,在合约中可设置当AddNewKey接口返回的key存在性为存在时进行的预定操作,例如向用户返回交易失败。线程1在执行AddNewKey接口之后,可生成对应的执行AddNewKey接口的请求,以发送给线程2。线程2根据该请求向存储发送对key的访问请求,并且在等待访问结果的同时,可并行地进行添加Key的操作。添加Key的操作可以包括,根据AddNewKey的传入参数,在内存中记录key的标识和key的初始值,以用于后续更新到存储中,例如在区块的全部交易都执行完之后更新到存储中。其中,在访问结果指示key的存在性为存在的情况下,线程2可删除已经执行的添加key的操作的操作结果,或者可根据AddNewKey接口中的设置终止对合约的执行,结束交易,并返回交易失败。In the second case, the AddNewKey interface can be provided in the blockchain platform, which is used to check the existence and add the key when it is determined that the key does not exist. When the key needs to be added in the contract, the above interface can be called in the contract. Similar to the first case above, the contract can be set to perform predetermined operations when the existence of the key returned by the AddNewKey interface exists, such as returning a transaction failure to the user. After thread 1 executes the AddNewKey interface, it can generate a corresponding request for executing the AddNewKey interface to send to thread 2. Thread 2 sends an access request for the key to the storage according to the request, and while waiting for the access result, the operation of adding the key can be performed in parallel. The operation of adding a Key may include, according to the incoming parameters of AddNewKey, recording the key identifier and the initial value of the key in memory for subsequent updates to the storage, for example, updating to the storage after all transactions in the block are executed middle. Among them, when the access result indicates that the existence of the key exists, thread 2 can delete the operation result of the operation of adding the key that has been executed, or can terminate the execution of the contract according to the settings in the AddNewKey interface, end the transaction, and return transaction failed.
在第三种情况中,假设交易中调用的合约中将要删除已有的key,并在该删除之前调用区块链平台提供的用于确定变量存在性的接口,以进行对key的存在性的检查,从而确认key是否存在。具体是,合约中例如包括如下指令:In the third case, it is assumed that the existing key will be deleted in the contract called in the transaction, and the interface provided by the blockchain platform for determining the existence of the variable is called before the deletion to check the existence of the key. Check to see if the key exists. Specifically, the contract includes, for example, the following instructions:
If(KeynotexistCheck(key1))If(KeynotexistCheck(key1))
{KeynotexistHandle(key1)},{KeynotexistHandle(key1)},
Else,DelKV(key1);Else, DelKV(key1);
其中,KeynotexistCheck()函数为区块链平台提供的用于检查key(例如代码中示出的key1)是否不存在的接口,合约中可直接调用该接口。KeynotexistHandle()函数是合约中定义的函数,用于在KeynotexistCheck()函数返回的key存在性为不存在的情况下进行的预定操作,例如向用户返回交易失败等。“Else”表示,在KeynotexistCheck()函数返回的key存在性为存在的情况下,执行DelKV()函数。DelKV()函数用于删除key。处理单元21中的线程1在虚拟机中开始执行合约之后,当执行到合约中包含的上述KeynotexistCheck()函数之后,可以生成用于确认key存在性的请求,以发送给线程2。Among them, the KeynotexistCheck() function is an interface provided by the blockchain platform to check whether the key (such as key1 shown in the code) does not exist, and the interface can be directly called in the contract. The KeynotexistHandle() function is a function defined in the contract, which is used to perform predetermined operations when the existence of the key returned by the KeynotexistCheck() function is non-existent, such as returning a transaction failure to the user. "Else" indicates that the DelKV() function is executed when the key existence returned by the KeynotexistCheck() function exists. The DelKV() function is used to delete the key. After the thread 1 in the processing unit 21 starts to execute the contract in the virtual machine, after executing the above-mentioned KeynotexistCheck() function contained in the contract, it can generate a request for confirming the existence of the key and send it to the thread 2.
在第四种情况中,区块链平台中可以提供DelKey接口,该接口用于进行存在性检查、并在确定key存在的情况中,删除key。合约中可在需要删除key时,在合约中调用上述接口。区块链节点中的线程1在执行DelKey接口之后,可生成对应的执行DelKey接口的请求,以发送给线程2,线程2根据该请求向存储发送对key的访问请求,并且在等待访问结果的同时,可并行地进行删除Key的操作。与上文类似地,该删除key的操作可在内存中进行。In the fourth case, the DelKey interface can be provided in the blockchain platform, which is used to check the existence of the key and delete the key when it is determined that the key exists. When the key needs to be deleted in the contract, the above interface can be called in the contract. After thread 1 in the blockchain node executes the DelKey interface, it can generate a corresponding request to execute the DelKey interface to send to thread 2. Thread 2 sends an access request to the storage according to the request, and waits for the result of the access. At the same time, the operation of deleting the Key can be performed in parallel. Similar to the above, the operation of deleting the key can be performed in memory.
其中,在上述第二种和第四种情况中,通过一个接口进行key存在性检查和添加/删除两个操作,线程1在调用该接口时,可以仅向线程2发送一个系统请求。在线程1在FPGA中实现的情况下,线程1和线程2之间的通信为两个硬件(即服务器和FPGA)之间的通信,通信成本较高,因此通过上述AddNewkey接口和DelKey接口可以大大减少生成和发送系统请求的资源开销,提高系统效率。Wherein, in the above-mentioned second and fourth cases, two operations of key existence check and addition/deletion are performed through an interface, and thread 1 may only send a system request to thread 2 when calling the interface. In the case that thread 1 is implemented in FPGA, the communication between thread 1 and thread 2 is the communication between two hardwares (i.e. server and FPGA), and the communication cost is relatively high, so the above-mentioned AddNewkey interface and DelKey interface can be greatly improved. Reduce the resource overhead of generating and sending system requests and improve system efficiency.
另外,在由一个线程中的模块1和模块2执行接口代码和合约代码的情况中,假设模块1在SGX内,在模块1需要向模块2发送系统请求时,模块1需要进行SGX技术下的切换,以切换为模块2,切换成本较高,因此通过上述AddNewkey接口和DelKey接口同样可以大大减少生成和发送系统请求的资源开销。In addition, in the case where the interface code and contract code are executed by module 1 and module 2 in one thread, assuming that module 1 is in SGX, when module 1 needs to send a system request to module 2, module 1 needs to perform Switching to switch to module 2 has a high switching cost, so the resource overhead of generating and sending system requests can also be greatly reduced through the above-mentioned AddNewkey interface and DelKey interface.
在步骤S302,线程1将生成的key存在性确认请求发送给线程2。In step S302, thread 1 sends the generated key existence confirmation request to thread 2.
在步骤S303,线程1按照key的预设存在性继续执行交易。In step S303, thread 1 continues to execute the transaction according to the preset existence of the key.
在一种实施方式中,在所述交易中调用的合约中,除了包括上述Key存在性检查接口之外,在该接口之后还包括对交易执行次数的查询,例如交易中定义了指示交易执行次数的参数T,参数的初始值设为T=1,线程1通过查询该参数T的值可确定交易的本次执行为对交易的首次执行,从而,线程1在进行该确定之后执行步骤S303,按照key的预设存在性继续执行交易。例如,参考上述KeyexistCheck接口的代码,线程1可将Else分支对应的key1的存在性作为预设存在性,从而执行合约中的Else分支。对于上述AddNewKey接口、KeynotexistCheck接口和DelKey接口,线程1可类似地按照预设存在性执行交易(即执行交易中调用的合约)。In one embodiment, in the contract called in the transaction, in addition to the above-mentioned Key existence check interface, it also includes a query for the number of transaction execution times after the interface, for example, the transaction defines the number of transaction execution times parameter T, the initial value of the parameter is set to T=1, thread 1 can determine that this execution of the transaction is the first execution of the transaction by querying the value of the parameter T, thus, thread 1 executes step S303 after making the determination, Continue to execute the transaction according to the preset existence of the key. For example, referring to the code of the above-mentioned KeyexistCheck interface, thread 1 can use the existence of key1 corresponding to the Else branch as the preset existence, thereby executing the Else branch in the contract. For the above-mentioned AddNewKey interface, KeynotexistCheck interface and DelKey interface, thread 1 can similarly execute the transaction according to the preset existence (that is, execute the contract called in the transaction).
在另一种实施方式中,在平台提供的代码(例如上述进行key存在性检查的接口)中可包括对交易执行次数的查询,例如在平台提供的代码中可定义指示交易执行次数的参数N,参数的初始值设为N=1,线程2在从线程1接收到key存在性确认请求之后,可查询参数N的值,从而确定交易的本次执行为首次执行,从而,线程2可立即向线程1返回对预设存在性的确认应答,同时执行步骤S304,进行存储访问,以确认key的存在性。线程1在从线程2接收到确认应答之后,从而执行步骤S303,按照key的预设存在性继续执行交易。In another embodiment, the code provided by the platform (such as the above-mentioned interface for key existence check) may include the query of the number of transaction executions, for example, the code provided by the platform may define the parameter N indicating the number of transaction executions , the initial value of the parameter is set to N=1, thread 2 can query the value of parameter N after receiving the key existence confirmation request from thread 1, so as to determine that this execution of the transaction is the first execution, thus, thread 2 can immediately A confirmation response to the preset existence is returned to thread 1, and step S304 is executed at the same time to perform storage access to confirm the existence of the key. After thread 1 receives the confirmation response from thread 2, it executes step S303, and continues to execute the transaction according to the preset existence of the key.
具体是,对于上述第一种情况,线程1在执行步骤S303时,按照假设key1不存在的情况继续执行合约中的后续代码,即交易中的创建key的操作。例如,如上述第一种情况中的代码所示,线程1可继续执行合约中的代码SetKV(key1,new_value),即在存储中创建key1。Specifically, for the first case above, when thread 1 executes step S303, it continues to execute the subsequent code in the contract, that is, the key creation operation in the transaction, assuming that key1 does not exist. For example, as shown in the code in the first case above, thread 1 can continue to execute the code SetKV(key1, new_value) in the contract, that is, create key1 in the storage.
在上述第二种情况中,由于线程2在确定key1不存在的情况中进行创建key1的操作,并且线程2执行的创建key1的操作不会影响线程1执行交易中后续的操作,因此,线程1可以按照线程2假设key1不存在并且已创建key1的情况,继续执行交易所调用的合约中的后续操作。In the above second case, since thread 2 performs the operation of creating key1 when it is determined that key1 does not exist, and the operation of creating key1 performed by thread 2 will not affect the subsequent operations in thread 1's execution of the transaction, therefore, thread 1 You can follow the thread 2 assumption that key1 does not exist and key1 has been created, and continue to execute subsequent operations in the contract called by the exchange.
在上述第三种情况中,线程1按照假设key存在的情况继续执行合约中的后续代码,即合约中删除key的操作。例如,如上述第三种情况中的代码所示,线程1可按照key1存在的情况执行代码“DelKV(key1)”,即在状态数据库中删除“key1”。In the above third case, thread 1 continues to execute the subsequent code in the contract assuming that the key exists, that is, the operation of deleting the key in the contract. For example, as shown in the code in the third case above, thread 1 may execute the code "DelKV(key1)" according to the existence of key1, that is, delete "key1" in the state database.
在上述第四种情况中,与第二种情况类似地,线程1可以按照假设key存在并且已删除key的情况,继续执行交易中的后续操作。In the above fourth case, similar to the second case, thread 1 can continue to perform subsequent operations in the transaction assuming that the key exists and has been deleted.
线程2在步骤S304进行存储访问,确认key存在性。Thread 2 performs storage access in step S304 to confirm the existence of the key.
具体是,线程2可访问硬盘中的状态数据库,以从状态数据库中读取key1的值,从而确认key1是否存在,如果读取到key1的值,则可确认key1已经存在,如果未读取到key1的值,则可确认key1不存在。线程2在根据存储访问结果确定key1的存在性之后,可将key1的存在性存储在内存中。Specifically, thread 2 can access the state database in the hard disk to read the value of key1 from the state database to confirm whether key1 exists. If the value of key1 is read, it can be confirmed that key1 already exists. key1 value, it can be confirmed that key1 does not exist. After thread 2 determines the existence of key1 according to the storage access result, it may store the existence of key1 in the memory.
在步骤S305,线程1向线程2发送系统服务请求。In step S305, thread 1 sends a system service request to thread 2.
线程1在继续执行所述交易的过程中可能产生了新的系统服务请求需要发送给线程2,以请求系统服务。所述系统服务请求例如包括其它key的存在性确认请求、交易完成请求等请求。可以理解,由于线程2可在交易结束之前的任何时间执行步骤S306,因此,也有可能在线程1发送系统服务请求之前执行步骤S306,因此,图3中以虚线示出步骤S305,表示该步骤为可选的步骤。Thread 1 may generate a new system service request in the process of continuing to execute the transaction and needs to send it to thread 2 to request system service. The system service requests include, for example, other key existence confirmation requests, transaction completion requests, and other requests. It can be understood that since thread 2 can execute step S306 at any time before the end of the transaction, it is also possible to execute step S306 before thread 1 sends the system service request. Therefore, step S305 is shown with a dotted line in FIG. 3 , indicating that this step is Optional step.
在步骤S306,线程2确定是否重新执行交易。In step S306, thread 2 determines whether to re-execute the transaction.
线程2可以在交易结束之前的任意时间,例如在接收到任一系统服务请求之后,执行该步骤,确定是否重新执行交易。此时,如果线程2尚未得到上述存储访问的结果,假设系统服务请求为其它key的存在性确认请求,线程2可确定不重新执行交易,从而线程1和线程2可继续进行与上述针对key1的处理相同的处理;假设系统服务请求为交易完成请求,即,线程1已经执行完了交易中的全部处理,请求结束对交易的执行,线程2需要等待存储访问的结果,并在得到存储访问的结果之后确认key1的存在性,从而确定是否重新执行交易。Thread 2 can execute this step at any time before the end of the transaction, for example, after receiving any system service request, to determine whether to re-execute the transaction. At this time, if thread 2 has not obtained the result of the above storage access, assuming that the system service request is the existence confirmation request of other keys, thread 2 can determine not to re-execute the transaction, so that thread 1 and thread 2 can continue with the above key1. Handle the same process; assume that the system service request is a transaction completion request, that is, thread 1 has executed all the processing in the transaction, and requests to end the execution of the transaction. Thread 2 needs to wait for the result of the storage access, and obtain the result of the storage access Then confirm the existence of key1 to determine whether to re-execute the transaction.
如果线程2已经得到存储访问的结果并将key1的存在性存储在内存中,则可从内存中读取key1的存在性,并将key1的存在性与上述预设存在性进行比较,以确定是否重新执行交易。如果key1的存在性与预设存在性相同,则不需要重新执行交易。具体是,如果系统服务器请求为其它key的存在性确认请求,线程1和线程2可继续进行与上述针对key1的处理相同的处理;假设系统服务请求为交易完成请求,线程2可进行完成交易的处理,并通知线程1结束对所述交易的执行。If thread 2 has obtained the result of the storage access and stored the existence of key1 in memory, it can read the existence of key1 from memory and compare the existence of key1 with the above preset existence to determine whether Re-execute the transaction. If the existence of key1 is the same as the preset existence, there is no need to re-execute the transaction. Specifically, if the system server request is an existence confirmation request for other keys, thread 1 and thread 2 can continue to perform the same processing as the above-mentioned processing for key1; assuming that the system service request is a transaction completion request, thread 2 can complete the transaction. processing, and notify thread 1 to end the execution of the transaction.
如果key1的存在性与预设存在性不同,则线程2执行步骤S307,向线程1发送重新执行交易的通知。If the existence of key1 is different from the preset existence, thread 2 executes step S307, and sends a notification to thread 1 to re-execute the transaction.
线程1在接收到重新执行交易的通知之后,执行步骤S308,弃用交易在之前的执行过程中产生的执行结果数据,并重新执行该交易。线程1在重新执行交易的过程中,可再次生成key(即key1)存在性确认请求,并之后执行步骤S309,将key存在性确认请求发送给线程2。After thread 1 receives the notification of re-executing the transaction, it executes step S308, discards the execution result data generated during the previous execution of the transaction, and re-executes the transaction. In the process of re-executing the transaction, thread 1 may generate a key (namely key1) existence confirmation request again, and then perform step S309 to send the key existence confirmation request to thread 2.
如上文所述,在一种实施方式中,线程1在接收到重新执行交易的通知之后,可将合约中定义的参数T加1,以指示对交易的执行为第2次执行,即非首次执行,或者在另一种实施方式中,线程2在发送重新执行交易的通知之后,可将平台代码中定义的参数N加1,以指示对交易的执行为第2次执行。从而,线程1在向线程2发送key存在性请求之后,可根据参数T的值,确定对交易的执行为非首次执行,因此等待线程2返回请求的应答。线程2在接收到key存在性确认请求之后,可根据参数N的值确定对交易的执行为非首次执行,因此,线程2从内存中获取key1的存在性,并执行步骤S310,根据该存在性返回请求应答,可以理解,这里的应答指示key1的存在性与预设存在性不同。As mentioned above, in one embodiment, after thread 1 receives the notification of re-executing the transaction, it can add 1 to the parameter T defined in the contract to indicate that the execution of the transaction is the second execution, that is, not the first time Execution, or in another embodiment, after thread 2 sends the notification of re-execution of the transaction, it may add 1 to the parameter N defined in the platform code to indicate that the execution of the transaction is the second execution. Therefore, after thread 1 sends a key existence request to thread 2, it can determine that the execution of the transaction is not the first execution according to the value of parameter T, so it waits for thread 2 to return the response to the request. After thread 2 receives the key existence confirmation request, it can determine that the execution of the transaction is not the first execution according to the value of parameter N. Therefore, thread 2 obtains the existence of key1 from the memory, and executes step S310, according to the existence A request response is returned, and it can be understood that the response here indicates that the existence of key1 is different from the preset existence.
线程1在接收到线程2返回的应答之后,执行步骤S311,结束对交易的执行。由于线程2返回的应答指示key1的存在性与预设存在性不同,因此交易执行失败,线程1结束对交易的执行,并向用户返回交易执行失败。After thread 1 receives the response returned by thread 2, it executes step S311 to end the execution of the transaction. Since the response returned by thread 2 indicates that the existence of key1 is different from the preset existence, the execution of the transaction fails, thread 1 ends the execution of the transaction, and returns the failure of the execution of the transaction to the user.
图4示出本说明书实施例提供的一种在区块链系统中执行交易的方法,所述交易中调用合约,所述合约中调用用于确认变量存在性的接口函数,所述方法由区块链节点执行,包括:Figure 4 shows a method for executing a transaction in a blockchain system provided by an embodiment of this specification, in which a contract is called, and an interface function for confirming the existence of a variable is called in the contract, and the method is determined by the block Block chain node execution, including:
步骤S401,执行所述接口函数;Step S401, execute the interface function;
步骤S403,在所述接口函数的结果返回之前,按照所述变量的预设存在性执行所述合约。Step S403, before the result of the interface function is returned, execute the contract according to the preset existence of the variable.
图4中的步骤S401和步骤S403具体可参考上文对步骤S304和步骤S303的具体描述,在此不再赘述。For details of step S401 and step S403 in FIG. 4 , reference may be made to the specific description of step S304 and step S303 above, which will not be repeated here.
在一种实现方式中,所述执行所述接口函数包括:向存储发送访问请求,以确认所述 变量的存在性。In an implementation manner, the executing the interface function includes: sending an access request to storage to confirm the existence of the variable.
在一种实现方式中,所述执行所述接口函数还包括:在等待所述存储对所述访问请求返回结果之前,按照所述预设存在性对所述变量进行预定处理。In an implementation manner, the executing the interface function further includes: performing predetermined processing on the variable according to the preset existence before waiting for the storage to return a result to the access request.
在一种实现方式中,所述接口函数用于:在确认所述变量不存在的情况中在存储中添加所述变量,或者在确认所述变量存在的情况中在存储中删除所述变量。In an implementation manner, the interface function is used to: add the variable in the storage when it is confirmed that the variable does not exist, or delete the variable in the storage when it is confirmed that the variable exists.
在一种实现方式中,所述方法还包括,在所述交易的执行完成之前,获取所述访问请求的访问结果,在根据所述访问结果确定所述变量的存在性与所述预设存在性不同的情况下,确定重新执行所述交易。In an implementation manner, the method further includes, before the execution of the transaction is completed, obtaining the access result of the access request, and determining the existence of the variable and the preset existence according to the access result In the case of different properties, it is determined to re-execute the transaction.
在一种实现方式中,所述合约中定义了指示交易执行次数的第一参数,所述按照所述变量的预设存在性执行所述合约包括,在根据所述第一参数确定所述交易的执行为首次执行之后,按照所述变量的预设存在性执行所述合约,所述方法还包括,在确定重新执行所述交易之后,更新所述第一参数。In one implementation, the contract defines a first parameter indicating the number of transaction execution times, and executing the contract according to the preset existence of the variable includes determining that the transaction is executed according to the first parameter Executing the contract is executed for the first time, executing the contract according to the preset existence of the variable, and the method further includes updating the first parameter after determining to re-execute the transaction.
在一种实现方式中,所述方法还包括,在重新执行所述交易中开始执行所述接口函数时,在根据所述第一参数确定所述交易为非首次执行的情况中,在获取执行所述接口函数返回的所述变量的存在性之后,按照所述变量的存在性执行所述合约。In an implementation manner, the method further includes, when starting to execute the interface function in the re-execution of the transaction, if the transaction is determined to be executed not for the first time according to the first parameter, when obtaining the execution After the existence of the variable is returned by the interface function, the contract is executed according to the existence of the variable.
在一种实现方式中,所述接口函数的代码中定义了指示交易执行次数的第二参数,所述执行所述接口函数包括,在根据所述第二参数确定所述交易的执行为首次执行之后,返回对所述预设存在性的确定应答,所述按照所述变量的预设存在性执行所述合约包括,根据所述确定应答按照所述变量的预设存在性执行所述合约,所述方法还包括,在确定重新执行所述交易之后,更新所述第二参数。In an implementation manner, the code of the interface function defines a second parameter indicating the number of transaction execution times, and the execution of the interface function includes determining that the execution of the transaction is the first execution according to the second parameter Afterwards, returning a confirmation response to the preset existence, the executing the contract according to the preset existence of the variable includes executing the contract according to the preset existence of the variable according to the confirmation response, The method also includes, after determining to re-execute the transaction, updating the second parameter.
图5示出本说明书实施例提供的一种区块链节点的架构图,所述区块链节点用于执行交易,所述交易中调用合约,所述合约中调用用于确认变量存在性的接口函数,所述区块链节点包括:Fig. 5 shows an architecture diagram of a block chain node provided by the embodiment of this specification, the block chain node is used to execute a transaction, the contract is called in the transaction, and the contract is called in the contract to confirm the existence of the variable Interface function, the blockchain node includes:
第一执行单元51,用于执行所述接口函数;The first execution unit 51 is configured to execute the interface function;
第二执行单元52,用于在所述接口函数的结果返回之前,按照所述变量的预设存在性执行所述合约。The second execution unit 52 is configured to execute the contract according to the preset existence of the variable before the result of the interface function is returned.
在一种实现方式中,所述第一执行单元51还用于:向存储发送访问请求,以确认所述变量的存在性。In an implementation manner, the first execution unit 51 is further configured to: send an access request to the storage to confirm the existence of the variable.
在一种实现方式中,所述第一执行单元51还用于:在等待所述存储对所述访问请求返回结果之前,按照所述预设存在性对所述变量进行预定处理。In an implementation manner, the first execution unit 51 is further configured to: perform predetermined processing on the variable according to the preset existence before waiting for the storage to return a result to the access request.
在一种实现方式中,所述接口函数用于:在确认所述变量不存在的情况中在存储中添加所述变量,或者在确认所述变量存在的情况中在存储中删除所述变量。In an implementation manner, the interface function is used to: add the variable in the storage when it is confirmed that the variable does not exist, or delete the variable in the storage when it is confirmed that the variable exists.
在一种实现方式中,所述区块链节点还包括确定单元53,用于在所述交易的执行完成之前,获取所述访问请求的访问结果,在根据所述访问结果确定所述变量的存在性与所述预设存在性不同的情况下,确定重新执行所述交易。In an implementation manner, the block chain node further includes a determination unit 53, configured to obtain the access result of the access request before the execution of the transaction is completed, and determine the value of the variable according to the access result If the existence is different from the preset existence, it is determined to re-execute the transaction.
在一种实现方式中,所述合约中定义了指示交易执行次数的第一参数,所述第二执行单元52还用于,在根据所述第一参数确定所述交易的执行为首次执行之后,按照所述变量的预设存在性执行所述合约,所述区块链节点还包括,更新单元54,用于在确定重新执行所述交易之后,更新所述第一参数。In one implementation, the contract defines a first parameter indicating the number of transaction execution times, and the second execution unit 52 is further configured to determine that the execution of the transaction is the first execution according to the first parameter , execute the contract according to the preset existence of the variable, and the block chain node further includes an updating unit 54, configured to update the first parameter after it is determined to re-execute the transaction.
在一种实现方式中,所述区块链节点还包括,重新执行单元,用于在重新执行所述交易中开始执行所述接口函数时,在根据所述第一参数确定所述交易为非首次执行的情况中,在获取执行所述接口函数返回的所述变量的存在性之后,按照所述变量的存在性执行所述合约。In an implementation manner, the block chain node further includes a re-execution unit, configured to start executing the interface function in the re-execution of the transaction, when it is determined according to the first parameter that the transaction is not In the case of the first execution, after obtaining the existence of the variable returned by executing the interface function, execute the contract according to the existence of the variable.
在一种实现方式中,所述接口函数的代码中定义了指示交易执行次数的第二参数,所述第一执行单元51还用于,在根据所述第二参数确定所述交易的执行为首次执行之后, 返回对所述预设存在性的确定应答,所述第二执行单元52还用于,根据所述确定应答按照所述变量的预设存在性执行所述合约,所述更新单元54还用于在确定重新执行所述交易之后,更新所述第二参数。In one implementation, the code of the interface function defines a second parameter indicating the number of transaction execution times, and the first execution unit 51 is further configured to determine that the execution of the transaction is the first according to the second parameter. After the second execution, return a confirmation response to the preset existence, and the second execution unit 52 is also used to execute the contract according to the preset existence of the variable according to the confirmation response, and the update unit 54 is further configured to update the second parameter after it is determined to re-execute the transaction.
本说明书实施例还提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行图3和图4所示方法。The embodiment of this specification also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed in a computer, the computer is instructed to execute the methods shown in FIG. 3 and FIG. 4 .
本说明书实施例还提供一种区块链节点,包括存储器和处理器,所述存储器中存储有可执行代码,所述处理器执行所述可执行代码时,实现图3和图4所示方法。The embodiment of this specification also provides a block chain node, including a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, the methods shown in Figure 3 and Figure 4 are implemented .
需要理解,本文中的“第一”,“第二”等描述,仅仅为了描述的简单而对相似概念进行区分,并不具有其他限定作用。It should be understood that descriptions such as "first" and "second" in this document are only used to distinguish similar concepts for the sake of simplicity of description, and do not have other limiting functions.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this specification is described in a progressive manner, the same and similar parts of each embodiment can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for relevant parts, refer to part of the description of the method embodiment.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other implementations are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. Multitasking and parallel processing are also possible or may be advantageous in certain embodiments.
本领域普通技术人员应该还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。本领域普通技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。其中,软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。Those of ordinary skill in the art should further realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the hardware and software interchangeability, the composition and steps of each example have been generally described in terms of functions in the above description. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Those of ordinary skill in the art may implement the described functionality using different methods for each particular application, but such implementation should not be considered as exceeding the scope of the present application. Among them, the software module can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or technical field Any other form of storage medium known in the art.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above have further described the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above descriptions are only specific embodiments of the present invention and are not intended to limit the scope of the present invention. Protection scope, within the spirit and principles of the present invention, any modification, equivalent replacement, improvement, etc., shall be included in the protection scope of the present invention.
Claims (18)
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110748977.1 | 2021-07-02 | ||
| CN202110748977.1A CN113254467B (en) | 2021-07-02 | 2021-07-02 | Method and blockchain node for executing transactions in a blockchain system |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2023274409A1 true WO2023274409A1 (en) | 2023-01-05 |
Family
ID=77190491
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2022/103384 Ceased WO2023274409A1 (en) | 2021-07-02 | 2022-07-01 | Method for executing transaction in blockchain system and blockchain node |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN113254467B (en) |
| WO (1) | WO2023274409A1 (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113254467B (en) * | 2021-07-02 | 2022-05-10 | 支付宝(杭州)信息技术有限公司 | Method and blockchain node for executing transactions in a blockchain system |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109299335A (en) * | 2018-08-31 | 2019-02-01 | 阿里巴巴集团控股有限公司 | Control method, device, server and the readable storage medium storing program for executing of data storage |
| US20200052884A1 (en) * | 2018-08-13 | 2020-02-13 | International Business Machines Corporation | Parallel transaction validation and block generation in a blockchain |
| CN111047449A (en) * | 2020-03-12 | 2020-04-21 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for executing transactions in blockchain |
| CN111324425A (en) * | 2020-02-28 | 2020-06-23 | 百度在线网络技术(北京)有限公司 | Data access method, device, equipment and storage medium |
| CN113254467A (en) * | 2021-07-02 | 2021-08-13 | 支付宝(杭州)信息技术有限公司 | Method and blockchain node for performing transactions in blockchain system |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111324396B (en) * | 2020-03-19 | 2023-09-15 | 深圳市迅雷网络技术有限公司 | A blockchain smart contract execution method, device and equipment |
-
2021
- 2021-07-02 CN CN202110748977.1A patent/CN113254467B/en active Active
-
2022
- 2022-07-01 WO PCT/CN2022/103384 patent/WO2023274409A1/en not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20200052884A1 (en) * | 2018-08-13 | 2020-02-13 | International Business Machines Corporation | Parallel transaction validation and block generation in a blockchain |
| CN109299335A (en) * | 2018-08-31 | 2019-02-01 | 阿里巴巴集团控股有限公司 | Control method, device, server and the readable storage medium storing program for executing of data storage |
| CN111324425A (en) * | 2020-02-28 | 2020-06-23 | 百度在线网络技术(北京)有限公司 | Data access method, device, equipment and storage medium |
| CN111047449A (en) * | 2020-03-12 | 2020-04-21 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for executing transactions in blockchain |
| CN113254467A (en) * | 2021-07-02 | 2021-08-13 | 支付宝(杭州)信息技术有限公司 | Method and blockchain node for performing transactions in blockchain system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN113254467B (en) | 2022-05-10 |
| CN113254467A (en) | 2021-08-13 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| JP5006348B2 (en) | Multi-cache coordination for response output cache | |
| JP6353924B2 (en) | Reduced data volume durability status for block-based storage | |
| US8898680B2 (en) | System and method for supporting asynchronous message processing in a distributed data grid | |
| US8185499B2 (en) | System and method for transactional session management | |
| US6857082B1 (en) | Method for providing a transition from one server to another server clustered together | |
| JP6920513B2 (en) | Systems and methods to support distributed data structures in distributed data grids | |
| US9378218B2 (en) | Apparatus and method for enabling clients to participate in data storage in distributed file system | |
| US12105735B2 (en) | Asynchronous accounting method and apparatus for blockchain, medium and electronic device | |
| CN104793988A (en) | Cross-database distributed transaction implementation method and device | |
| JP2010157202A (en) | Distributed transaction recovery system and method | |
| US10133489B2 (en) | System and method for supporting a low contention queue in a distributed data grid | |
| CN113505002B (en) | Distributed components in a computing cluster | |
| CN112162846A (en) | Transaction processing method, device and computer readable storage medium | |
| US20200202355A1 (en) | Storage and execution of smart contracts in blockchains | |
| WO2023231339A1 (en) | Transaction execution method and node in blockchain system, and blockchain system | |
| WO2022048358A1 (en) | Data processing method and device, and storage medium | |
| CN114036164B (en) | A high-concurrency transaction locking method and system combining optimistic locking and pessimistic locking | |
| US10798146B2 (en) | System and method for universal timeout in a distributed computing environment | |
| US11522966B2 (en) | Methods, devices and systems for non-disruptive upgrades to a replicated state machine in a distributed computing environment | |
| US10127270B1 (en) | Transaction processing using a key-value store | |
| CN103905512B (en) | A kind of data processing method and equipment | |
| WO2023274409A1 (en) | Method for executing transaction in blockchain system and blockchain node | |
| WO2023103340A1 (en) | Block data committing method and apparatus | |
| CN106371919B (en) | A shuffling data cache method based on map-reduce computing model | |
| JP2019504401A (en) | High throughput, high reliability data processing system |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22832221 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 22832221 Country of ref document: EP Kind code of ref document: A1 |