Database operation methods, devices and systems

By creating savepoints and rolling back the state database after receiving business data, the problem of limited node operation methods is solved, and more efficient and stable database operations are achieved.

CN116450731BActive Publication Date: 2025-10-31TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210013164.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-07
Publication Date
2025-10-31
Estimated Expiration
2042-01-07

AI Technical Summary

Technical Problem

The nodes operate on the state database in a relatively simple way, which affects node performance and leads to a decrease in stability.

Method used

The block-producing node and consensus node first execute transactions of n business data in sequence, create savepoints and roll back the state database when the SQL instruction group fails to execute, broadcast temporary blocks to achieve consensus, and perform operations directly on the state database.

Benefits of technology

It enriches the database operation methods, reduces the impact on node performance, and improves the performance stability and efficiency of nodes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116450731B_ABST
    Figure CN116450731B_ABST
Patent Text Reader

Abstract

A database operation method, apparatus, and system belong to the field of blockchain technology. The method includes: when a block-producing node receives n pieces of first business data (also called messages), it sequentially executes transactions for the n pieces of first business data; the transactions for the first business data include: creating a savepoint for a target state database; executing a group of SQL instructions corresponding to the first business data; if the execution of the SQL instruction group fails, rolling back the target state database to the state at the time the savepoint was created; if a target SQL instruction group exists, rolling back the state database indicated by each piece of first business data to the state at the savepoint where the state database was created; broadcasting a first temporary block containing the n pieces of first business data and the DML instructions in the target SQL instruction group to the consensus node, so as to facilitate the first consensus between the block-producing node and the consensus node. This application solves the problem of the relatively simple operation method of nodes on the state database, and is applicable to blockchain systems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and in particular to a database operation method, apparatus and system. Background Technology

[0002] A blockchain system consists of clients and multiple nodes, each maintaining its own blockchain. Blocks in the blockchain record business data sent by the clients, and nodes maintain a state database, which they can update based on the business data on the blockchain.

[0003] The blockchain system consists of multiple nodes: block-producing nodes, consensus nodes, and ordinary nodes. Upon receiving business data, the block-producing node simulates an update to the state database based on that data and packages the updated result along with the original business data into a temporary block for broadcast. The consensus node can simulate an update to the state database based on the business data in this temporary block, determine if the updated result matches the result in the original block, and then reach a consensus with the block-producing node based on this determination. After the block-producing node and the consensus node reach a consensus, all nodes—block-producing node, consensus node, and ordinary nodes—update the state database according to the consensus result and add the temporary block to the blockchain. Specifically, each of the block-producing node and consensus node, when simulating an update to the state database based on business data, simulates the state database locally and updates the simulated state database according to the business data to obtain the updated result.

[0004] However, currently, the way nodes operate on the state database is relatively simple. Summary of the Invention

[0005] This application provides a database operation method, apparatus, and system, which can solve the problem that the current methods for nodes to operate on state databases are relatively limited. The technical solution is as follows:

[0006] Firstly, a database operation method is provided, the method being executed by block-producing nodes in a blockchain system, the blockchain system further including consensus nodes; the method includes:

[0007] Upon receiving n pieces of first business data sent by the client, the transactions of the n pieces of first business data are executed sequentially; wherein, n≥1, for one of the n pieces of first business data, the transaction of the first business data includes: creating a savepoint for the target state database; executing the Structured Quevy Language (SQL) instruction set corresponding to the first business data; if the SQL instruction set fails to execute, rolling back the target state database to the state at the time of creating the savepoint according to the savepoint; the first business data is used to indicate a target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; the SQL instruction set includes instructions for the target operation;

[0008] When a target SQL instruction group exists, for each state database indicated by the n first business data, the state database is rolled back to the state at the save point when the state database was created; the target SQL instruction group includes Data Manipulation Language (DML) instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0009] The first temporary block is broadcast to the consensus node so that the block-producing node and the consensus node can reach a first consensus based on the first temporary block. The first temporary block records the n first business data and the DML instructions in the target SQL instruction group.

[0010] Secondly, a database operation method is provided, the method being executed by a consensus node in a blockchain system, the blockchain system further including: a block-producing node, the method comprising:

[0011] Receive the first temporary block broadcast by the block-producing node; wherein the first temporary block records n first service data and DML instructions, n≥1;

[0012] The transactions of the n first business data are executed sequentially; wherein, for one of the n first business data, the transaction of the first business data includes: creating a savepoint for the target state database; executing the SQL instruction group corresponding to the first business data; if the SQL instruction group fails to execute, rolling back the target state database to the state at the time of creating the savepoint according to the savepoint; the first business data is used to indicate the target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; the SQL instruction group includes instructions for the target operation;

[0013] When a target SQL instruction group exists, for each state database indicated by the n first business data, the state database is rolled back to the state at the save point when the state database was created; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0014] Determine whether the DML instructions in the target SQL instruction group are the same as the DML instructions in the first temporary block;

[0015] Based on the result of the judgment, a first consensus is reached with the block-producing node.

[0016] Thirdly, a database operation method is provided, the method being executed by ordinary nodes in a blockchain system, the blockchain system further including block-producing nodes and consensus nodes, the method comprising:

[0017] Receive the first temporary block broadcast by the block-producing node; wherein the first temporary block records n first service data and DML instructions, n≥1;

[0018] When the block-producing node and the consensus node reach a first consensus based on the first temporary block, the DML instruction recorded in the first temporary block is executed, and the first temporary block is added to the blockchain.

[0019] Fourthly, a blockchain system is provided, which includes: a client, block-producing nodes, consensus nodes, and ordinary nodes;

[0020] The client is used to send business data to the block-producing node;

[0021] The block-producing node is used to execute any of the methods provided in the first aspect;

[0022] The consensus node is used to execute any of the methods provided in the second aspect;

[0023] The ordinary node is used to execute any of the methods provided by the third party.

[0024] Fifthly, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one instruction, at least one program, code set or instruction set, the at least one instruction, the at least one program, the code set or instruction set being loaded and executed by the processor to implement any of the methods provided in the first, second or third aspects.

[0025] In a sixth aspect, a computer-readable storage medium is provided, the storage medium storing at least one instruction, at least one program, code set, or instruction set, the at least one instruction, the at least one program, the code set, or the instruction set being loaded and executed by a processor to implement any of the methods provided in the first, second, or third aspects.

[0026] In a seventh aspect, a computer program product comprising instructions is provided, characterized in that, when the computer program product is run on a computer, it causes the computer to perform any of the methods provided in the first, second, or third aspects.

[0027] The beneficial effects of the technical solution provided in this application include at least the following:

[0028] This application provides a database operation method in which both the block-producing node and the consensus node first execute transactions of n first business data sequentially to operate on the state database on the node. When a target SQL instruction group exists, for each state database indicated by the n first business data, the node also rolls back the state database to the state at the point when the state database was created. After the block-producing node and the consensus node reach a consensus, the DML instructions in the target SQL instruction group are then executed. It is evident that the database operation method provided in this application does not simulate a state database on the node, but rather operates directly on the state database. Therefore, this application provides a novel database operation method, enriching the ways in which databases can be operated.

[0029] Furthermore, in related technologies, when a node simulates a state database, it starts a process to simulate that state database, which affects the node's performance. In this embodiment, neither the block-producing node nor the consensus node needs to simulate a state database, and the transactions executing n pieces of first business data are all performed within the process of running the state database. Therefore, the database operation method provided in this embodiment has a smaller impact on node performance, resulting in higher node performance stability and overall higher node performance. Attached Figure Description

[0030] Figure 1 A schematic diagram of the structure of a blockchain system provided in this application embodiment;

[0031] Figure 2 A schematic diagram of a blockchain provided for an embodiment of this application;

[0032] Figure 3 A flowchart illustrating a database operation method provided in this application embodiment;

[0033] Figure 4 A flowchart illustrating another database operation method provided in this application embodiment;

[0034] Figure 5 A flowchart illustrating another database operation method provided in this application embodiment;

[0035] Figure 6 A flowchart illustrating another database operation method provided in this application embodiment;

[0036] Figure 7 A flowchart illustrating another database operation method provided in this application embodiment;

[0037] Figure 8 A flowchart illustrating another database operation method provided in this application embodiment;

[0038] Figure 9 A flowchart illustrating another database operation method provided in this application embodiment;

[0039] Figure 10 This is a schematic diagram of the structure of a database operation device provided in an embodiment of this application;

[0040] Figure 11 This is a schematic diagram of another database operation device provided in an embodiment of this application;

[0041] Figure 12 This is a schematic diagram of another database operation device provided in an embodiment of this application;

[0042] Figure 13 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation

[0043] To make the principles and technical solutions of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0044] The blockchain system involved in this application can be a distributed system formed by connecting at least one client and multiple nodes (any form of computing device accessing the network, such as a server, user terminal; or part of a computing device, such as a function board; or a virtual machine running on a computing device) through network communication. User terminals include, but are not limited to, mobile phones, computers, smart voice interaction devices, smart home appliances, and vehicle terminals.

[0045] See Figure 1 , Figure 1 This is a schematic diagram of the structure of the blockchain system 100 provided in this application embodiment, consisting of multiple nodes and clients ( Figure 1(Taking a single client as an example) A peer-to-peer (P2P) network is formed between nodes. The P2P protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). In a blockchain system, any machine, such as a server or terminal, can join and become a node. A node includes a hardware layer, a middleware layer, an operating system layer, and an application layer.

[0046] Figure 1 The functions of each node in the blockchain system shown include:

[0047] 1) Routing: A basic function of nodes used to support communication between nodes.

[0048] 2) Applications are deployed in the blockchain to implement specific business needs. They record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system. When other nodes successfully verify the source and integrity of the record data, they add the record data to a temporary block.

[0049] For example, the business logic implemented by the application includes:

[0050] 2.1) A wallet provides the function of conducting electronic currency transactions, including initiating transactions. It sends the transaction data of the current transaction to other nodes in the blockchain system. After successful verification by other nodes, as a response acknowledging the validity of the transaction, the transaction record data is stored in a temporary block of the blockchain. The wallet also supports querying the remaining electronic currency in an electronic currency address.

[0051] 2.2) Shared ledger, used to provide functions such as storage, query and modification of ledger data. It sends the record data of the operation on the ledger data to other nodes in the blockchain system. After the other nodes verify the validity, as a response to acknowledge the validity of the ledger data, they store the record data in a temporary block. They can also send confirmation to the node that initiated the operation.

[0052] 2.3) Smart contracts are computerized protocols that can execute the terms of a contract. They are implemented through code deployed on a shared ledger that executes when certain conditions are met. Based on actual business needs, the code is used to complete automated transactions, such as querying the logistics status of goods purchased by a buyer and transferring the buyer's electronic money to the merchant's address after the buyer signs for the goods. Of course, smart contracts are not limited to executing contracts for transactions; they can also execute contracts for processing received information.

[0053] 3) A blockchain consists of a series of blocks that are sequentially generated. Once a new block is added to the blockchain, it will not be removed. The blocks record the data submitted by the nodes in the blockchain system.

[0054] See Figure 2 , Figure 2 This is an optional schematic diagram of the block structure provided in this application embodiment. Each block includes the hash value of the transaction records stored in this block (the hash value of this block) and the hash value of the previous block. The blocks are connected through their hash values ​​to form a blockchain. Additionally, the block may include information such as a timestamp when it was generated. A blockchain is essentially a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains relevant information used to verify the validity of the information (anti-counterfeiting) and to generate the next block.

[0055] Furthermore, the client is used to send business data, such as the transaction data mentioned above, to nodes in the blockchain system. The client can be an electronic device such as a mobile phone or computer with a specific application installed. Smart contracts in the nodes can store business data on the blockchain.

[0056] A node can run at least one smart contract, and each smart contract has at least one corresponding state database (also known as a storage engine). For a smart contract and its corresponding state database, during the execution of the smart contract, state data (also known as world state) can be recorded in the state database based on business data on the blockchain.

[0057] For example, when a smart contract in a node is running, if the node needs to record business data on the blockchain for adding, deleting, modifying, or querying state data, the node can add, delete, modify, or query business data in the state database corresponding to the smart contract based on that business data.

[0058] The aforementioned state database can be of various types. For example, it can be a key-value (KV) database, a document database, or a relational database, also known as a Relational Database Management System (RDBMS). Key-value databases do not support filtered queries; document databases support filtered queries but not joined or nested queries; relational databases support filtered, joined, aggregated, and nested queries, and possess transactional properties (such as atomicity) and multiple indexes. This embodiment uses a relational database as an example; therefore, the state database in this embodiment can support more complex query methods and possesses transactional and multiple index characteristics.

[0059] As described above, nodes in a blockchain system can update the state database based on business data on the blockchain. For example, a blockchain system may consist of multiple nodes: block-producing nodes, consensus nodes (one or more), and ordinary nodes (one or more). Upon receiving business data, the block-producing node simulates an update to the state database based on that data and packages the updated result along with the business data into a temporary block for broadcast. The consensus node can simulate an update to the state database based on the business data in the temporary block, determine whether the updated result is the same as the updated result in the block, and then reach a consensus with the block-producing node based on the result of this determination. After the block-producing node and the consensus node reach a consensus, the block-producing node, consensus node, and ordinary nodes all update the state database according to the consensus result and add the temporary block to the blockchain. Specifically, each of the block-producing node and consensus node, when simulating an update to the state database based on business data, simulates the state database locally and updates the simulated state database according to the business data to obtain the updated result.

[0060] However, currently, the way nodes operate on the state database is relatively simple.

[0061] This application provides another database operation method, which operates the database in a way that differs from the above-described database operation methods, thus enriching the ways in which nodes can operate on the state database.

[0062] For example, Figure 3 This is a flowchart illustrating a database operation method provided in an embodiment of this application. This method is executed by block-producing nodes in a blockchain system, such as... Figure 3 As shown, the database operation method includes:

[0063] Step 11: Upon receiving n pieces of first business data from the client, execute the transactions for each of the n pieces of first business data sequentially; where n ≥ 1. For one piece of first business data among the n pieces of first business data, the transaction for that first business data includes: creating a savepoint for the target state database; executing the SQL instruction group corresponding to the first business data; and if the SQL instruction group fails to execute, rolling back the target state database to the state at the time the savepoint was created. The first business data is used to indicate the target operation to be performed on the target state database, which is a relational database. The target operation includes: adding, deleting, modifying, and / or querying data. The SQL instruction group includes the instructions for the target operation.

[0064] For any one of the n first business data (any first business data), the first business data is used to indicate the target operation to be performed on the target state database. The target operation includes: adding, deleting, modifying and / or querying data.

[0065] For example, the first business data may include an identifier of the smart contract corresponding to the target state database. This identifier indicates that the first business data needs to invoke the smart contract, thereby indirectly instructing the target state database. The first business data may also include instruction data related to the target operation. In this way, the first business data can instruct the target operation to be performed on the target state database.

[0066] It should be noted that, in this embodiment of the application, the state database is a relational database as an example, therefore the target state database is also a relational database.

[0067] For this first piece of business data, the transactions of the first piece of business data include:

[0068] (1) Create a save point for the target state database.

[0069] It should be noted that the block-producing node contains a process that runs the target state database, and this process is used to operate on the target state database. For relational databases, when creating savepoints for the target state database, the node can create the savepoints within this process without having to restart the process used to create the savepoints.

[0070] (2) Execute the SQL instruction group corresponding to the first business data.

[0071] The first business data is used to instruct on the target operation to be performed on the target state database. This SQL instruction set includes the instructions for the target operation. It should be noted that the target state database is a relational database, and relational databases require SQL instructions for operation. The first business data is not an executable instruction. Therefore, the block-producing node can obtain the corresponding SQL instruction set based on the first business data and execute the SQL instruction set to perform the target operation indicated by the first business data on the target state database.

[0072] An SQL instruction group consists of one or more SQL instructions. When a block-producing node executes this SQL instruction group, it can execute the SQL instructions within the group sequentially. After executing the SQL instruction group, the block-producing node can perform the target operation on the target state database.

[0073] For example, suppose the first business data instructs the insertion of data 1 and data 2 into table X of the target state database. Then, the corresponding SQL instruction set for the first business data could include: SQL instruction 1 to insert data 1 into table X of the target state database, and SQL instruction 2 to insert data 2 into table X of the target state database. The block-producing node can execute SQL instruction 1 and SQL instruction 2 sequentially.

[0074] (3) When the SQL instruction group fails to execute, the target state database is rolled back to the state when the savepoint was created, based on the savepoint created in the transaction.

[0075] The SQL command group may execute successfully or fail. If the SQL command group executes successfully, the transaction for the first business data ends; if the SQL command group executes unsuccessfully, the block-producing node can roll back the target state database to the state when the savepoint was created, that is, the state of the target state database before the block-producing node executed the transaction.

[0076] For example, still using SQL instructions 1 and 2 as an example, if both SQL instructions 1 and 2 execute successfully during the sequential execution of SQL instructions 1 and 2 by the block-producing node, then the block-producing node can determine that the SQL instruction group has been executed successfully, and the transaction for the first business data ends. If SQL instruction 1 or SQL instruction 2 fails to execute, then the block-producing node will determine that the SQL instruction group has failed. In this case, the block-producing node will roll back the target state database to the state when the savepoint was created in the transaction, that is, the state before data 1 and data 2 were inserted.

[0077] In the above embodiments, taking a first service data as an example, when n>1, the state databases indicated by the n first service data can be the same or different, and the operations indicated by the n first service data can be the same or different. This application embodiment does not limit this.

[0078] The following example, using Table 1, illustrates a transaction involving n pieces of first business data. Table 1 uses n pieces of first business data, including first business data 1, 2, and 3, as an example, and all n pieces of first business data indicate the state database Y.

[0079] Table 1

[0080]

[0081] Please refer to Table 1. The first business data 1 includes SQL instructions 1 and 2. When the block production node executes the transaction of the first business data 1, it first creates a save point 1 for the state database Y, and then executes SQL instructions 1 and 2 in sequence. Since both SQL instructions 1 and 2 are executed successfully, the block production node will start executing the transaction of the first business data 2.

[0082] Please refer to Table 1. The first business data 2 includes SQL instructions 3 and 4. When the block producer node executes the transaction for the first business data 2, it first creates savepoint 2 in the state database Y (the state of inserted data 1 and data 2). Then, the block producer node executes SQL instructions 3 and 4 sequentially. Since SQL instruction 3 executes successfully and SQL instruction 4 fails, the block producer node determines that the SQL instruction group corresponding to the first business data 2 has failed. At this point, the block producer node rolls back the state database Y to the state when savepoint 2 was created (the state before data 3 was inserted). Afterward, the block producer node begins executing the transaction for the first business data 3.

[0083] Please continue to refer to Table 1. The first business data 3 includes SQL instructions 5 and 6. When the block production node executes the transaction of the first business data 3, it first creates the save point 3 of the state database Y, and then executes SQL instructions 5 and 6 in sequence. Since both SQL instructions 5 and 6 are executed successfully and there is no next first business data, the block production node ends the transaction of executing n first business data.

[0084] It should be noted that Table 1 uses the example of n first business data including three first business data and each SQL instruction group including two SQL instructions. Optionally, the SQL instruction group may also include one SQL instruction, three SQL instructions, or four SQL instructions, etc. n can be any integer greater than or equal to 1. This application embodiment does not limit the number of SQL instructions in the SQL instruction group.

[0085] SQL command execution failure means either the SQL command fails during execution, or the SQL command does not fail during execution but fails when returning the final result.

[0086] In addition, during the execution of the transaction of the first business data, the block-producing node can also call the state database indicated by the first business data before executing the SQL instruction group corresponding to the first business data.

[0087] Step 12: When a target SQL instruction group exists, for each state database indicated by n first business data, roll back the state database to the state at the save point when the state database was created; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0088] The operations indicated by the first business data include adding, deleting, modifying, and / or querying data. When the operations indicated by the first business data include adding, deleting, and / or modifying data, the corresponding SQL instruction set includes DML instructions; when the operations indicated by the first business data include querying data, the corresponding SQL instruction set includes Data Query Language (DQL) instructions. DML instructions include instructions expressed using INSERT statements, instructions expressed using DELETE statements, and instructions expressed using UPDATE statements. DQL instructions include query instructions expressed using SELECT statements for retrieving data.

[0089] The operations indicated by the n first business data may include adding, modifying, and / or deleting data, or they may not. When the operation indicated by the first business data includes adding, modifying, and / or deleting data, if the SQL instruction group corresponding to the first business data is executed successfully, the block-producing node can determine that the SQL instruction group is the target SQL instruction group. The block-producing node can also roll back each state database indicated by the n first business data to the state at the savepoint where the state database was created, based on the n savepoints created.

[0090] Taking Table 1 above as an example, the SQL instruction groups corresponding to the first business data 1 and 3 were both executed successfully. Furthermore, both the first business data 1 and 3 were used to instruct the addition of data to the state database Y. Therefore, the SQL instruction groups corresponding to the first business data 1 and 3 are both target instruction groups. After the block node completes the transactions for the first business data 1, 2, and 3, it will roll back the state database Y to the state at the time of creating the first savepoint (the aforementioned savepoint 1).

[0091] It should be noted that if the target SQL instruction group does not exist in the SQL instruction group corresponding to the n pieces of first business data, then the block-producing node's execution of the SQL instruction group corresponding to the n pieces of first business data will not change the state database, and therefore, the block-producing node does not need to perform subsequent steps. If the target SQL instruction group exists in the SQL instruction group corresponding to the n pieces of first business data, then the block-producing node's execution of the SQL instruction group corresponding to the n pieces of first business data will change the state database, and therefore, the block-producing node needs to perform subsequent steps to reach consensus with the consensus nodes in the blockchain system.

[0092] Step 13: Broadcast the first temporary block to the consensus node so that the block-producing node and the consensus node can reach a first consensus based on the first temporary block. The first temporary block records n first business data and DML instructions in the target SQL instruction group.

[0093] When the aforementioned target SQL instruction group exists, the block-producing node can broadcast the first temporary block to the consensus node, so that the consensus node in the blockchain system can receive the first temporary block and reach a consensus with the block-producing node based on the first temporary block.

[0094] Optionally, the block-producing node may generate a first temporary block before executing a transaction containing n pieces of first business data (e.g., after receiving the n pieces of first business data), and record the n pieces of first business data in the first temporary block. If a target SQL instruction group exists, the block-producing node may record the DML instructions in the target SQL instruction group in a cache. After executing the transaction containing the n pieces of first business data, the block-producing node may record the DML instructions from the cache in the first temporary block and broadcast the DML instructions, so that the block-producing node and the consensus node can reach a first consensus based on the first temporary block.

[0095] In summary, in the database operation method provided by this application embodiment, the block-producing node first executes the transactions of the n first business data sequentially to operate on the state database on the node. When a target SQL instruction group exists, for each state database indicated by the n first business data, the node also rolls back the state database to the state at the save point when the state database was created. Afterwards, the block-producing node broadcasts a temporary block to reach consensus with the consensus node. It is evident that the database operation method provided by this application embodiment does not simulate a state database on the node, but directly operates on the state database. Therefore, this application embodiment provides a new database operation method, enriching the ways in which databases can be operated.

[0096] Furthermore, in related technologies, when a node simulates a state database, it starts a process to simulate that state database, which affects the node's performance. In this embodiment, neither the block-producing node nor the consensus node needs to simulate a state database, and the transactions executing n pieces of first business data are all performed within the process of running the state database. Therefore, the database operation method provided in this embodiment has a smaller impact on node performance, resulting in higher node performance stability and overall higher node performance.

[0097] For example, Figure 4 This is a flowchart illustrating another database operation method provided for embodiments of this application. This method is executed by a consensus node in a blockchain system, such as... Figure 4 As shown, the database operation method includes:

[0098] Step 21: Receive the first temporary block broadcast by the block-producing node; wherein the first temporary block records n first business data and DML instructions, n≥1.

[0099] Step 22: Execute transactions for n pieces of first business data sequentially; wherein, for one piece of first business data among the n pieces of first business data, the transaction for the first business data includes: creating a savepoint for the target state database; executing the SQL instruction group corresponding to the first business data; if the SQL instruction group fails to execute, rolling back the target state database to the state when the savepoint was created; the first business data is used to indicate the target operation to be performed on the target state database, which is a relational database; the target operation includes: adding, deleting, modifying and / or querying data; the SQL instruction group includes the instructions for the target operation.

[0100] After receiving the first temporary block broadcast by the block-producing node, the consensus node can sequentially execute transactions based on the n first business data points in the first temporary block. The process of the consensus node sequentially executing transactions of the n first business data points can be referenced from the process of the block-producing node sequentially executing transactions of the n first business data points, and will not be described in detail here in the embodiments of this application.

[0101] It should be noted that each node in the blockchain system maintains the same state database. During the execution of n transactions involving the first set of business data, the block-producing node adds, deletes, modifies, and / or queries data in its state database. Similarly, during the execution of n transactions involving the first set of business data, the consensus node adds, deletes, modifies, and / or queries data in its state database.

[0102] Step 23: When a target SQL instruction group exists, for each state database indicated by n first business data, roll back the state database to the state at the save point when the state database was created; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0103] Similar to block-producing nodes, after executing transactions of n first business data in sequence, consensus nodes can also roll back each state database indicated by the n first business data to the state at the point when the state database was created if the target SQL instruction group exists in the n SQL instruction groups corresponding to the n first business data obtained by the consensus node.

[0104] It should be noted that if the target SQL instruction group does not exist in the SQL instruction group corresponding to the n pieces of first business data, then the consensus node's execution of the SQL instruction group corresponding to the n pieces of first business data will not change the state database, and therefore, the consensus node does not need to perform subsequent steps. If the target SQL instruction group exists in the SQL instruction group corresponding to the n pieces of first business data, then the consensus node's execution of the SQL instruction group corresponding to the n pieces of first business data will change the state database, and therefore, the consensus node needs to perform subsequent steps to reach consensus with the block-producing nodes in the blockchain system.

[0105] Step 24: Determine whether the DML instructions in the target SQL instruction group are the same as the DML instructions in the first temporary block.

[0106] After step 23, the consensus node can compare the DML instructions in the target SQL instruction group (DML instructions executed by the consensus node) with the DML instructions in the first temporary block (DML instructions executed by the block-producing node). If these two DML instructions are the same, it means that the consensus node and the block-producing node executed the same DML instructions. If these two DML instructions are different, it means that the consensus node and the block-producing node executed different DML instructions.

[0107] Step 25: Based on the judgment results, reach the first consensus with the block-producing node.

[0108] The consensus node can reach a first consensus with the block-producing node based on the result of the judgment in step 24.

[0109] For example, a consensus node can broadcast the result of the judgment in step 24 to all nodes in the blockchain system. After receiving the broadcast results from each consensus node (this embodiment does not limit the number of consensus nodes), if all the results are the same as the two DML instructions mentioned above, it means that the block-producing node and each consensus node have executed the same DML instruction, and at this time, the block-producing node and the consensus node have reached a consensus. If there are results with different DML instructions, it means that the block-producing node and each consensus node have not executed the same DML instruction, and at this time, the block-producing node and the consensus node cannot reach a consensus. After the consensus node and the block-producing node reach the first consensus, the block-producing node will broadcast information indicating that the first consensus has been reached (also called consensus information, signature information, or voting information) so that each node in the blockchain system can determine that the consensus node and the block-producing node have reached the first consensus. The information indicating whether the first consensus has been reached includes the first temporary block and the flag indicating that the first consensus has been reached.

[0110] Of course, consensus nodes and block-producing nodes can also use other methods to achieve the first consensus. The information used to indicate whether the first consensus has been reached can also be broadcast by the consensus node. This application embodiment does not limit this.

[0111] In summary, in the database operation method provided by this application embodiment, the consensus node first executes the transactions of the n first business data sequentially to operate on the state database on the node. When a target SQL instruction group exists, each state database indicated by the n first business data is rolled back to the state at the point when the state database was created. Afterwards, the consensus node and the block-producing node perform the first consensus. It can be seen that the database operation method provided by this application embodiment does not simulate the state database on the node, but directly operates on the state database. Therefore, this application embodiment provides a new database operation method, enriching the ways in which databases can be operated.

[0112] For example, Figure 5 This is a flowchart illustrating another database operation method provided for embodiments of this application. This method is executed by a regular node in a blockchain system, such as... Figure 5 As shown, the database operation method includes:

[0113] Step 31: Receive the first temporary block broadcast by the block-producing node or consensus node; wherein, the first temporary block records n first business data and DML instructions, n≥1; the first temporary block is the block broadcast by the block-producing node and consensus node after reaching the first consensus based on the first temporary block.

[0114] Step 32: Execute the DML instructions recorded in the first temporary block and add the first temporary block to the blockchain.

[0115] When the block-producing node and the consensus node reach the first consensus based on the first temporary block, each node in the blockchain system receives information indicating the achievement of the first consensus, which may include the first temporary block. Each node can execute the DML instructions recorded in the first temporary block, thereby ensuring that the state databases on all nodes in the blockchain system remain consistent. During this process, each node does not need to repeatedly run smart contracts or re-execute the transactions of the aforementioned n first business data.

[0116] Furthermore, when the block-producing node and the consensus node reach the first consensus based on the first temporary block, each node in the blockchain system can add the first temporary block to the blockchain to record on the blockchain that each node has executed the DML instructions in the first temporary block, so that the state database on each node is consistent with the data on the blockchain, and the blockchain maintained by each node is the same.

[0117] Furthermore, if the block-producing node and the consensus node cannot reach a first consensus, both the block-producing node and the consensus node can delete the first temporary block to invalidate it.

[0118] For example, Figure 6 This is a flowchart of another database operation method provided for embodiments of this application, such as... Figure 6 As shown, the database operation method includes:

[0119] Step 101: When the block-producing node receives n pieces of first business data sent by the client, it executes the transaction of the n pieces of first business data in sequence, where n≥1.

[0120] Step 101 can be referred to step 11, and will not be repeated here in the embodiments of this application.

[0121] Step 102: When a target SQL instruction group exists, for each state database indicated by n first business data, the production block node rolls back the state database to the state at the save point where the state database was created; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0122] Step 102 can be referred to step 12, and will not be repeated here in the embodiments of this application.

[0123] Step 103: The block-producing node broadcasts the first temporary block to the consensus node. The first temporary block records n first business data and DML instructions in the target SQL instruction group.

[0124] Step 103 can be referred to step 13, and will not be repeated here in the embodiments of this application.

[0125] Step 104: The consensus node executes the transactions of n first business data in sequence according to the first temporary block.

[0126] Step 104 can be referred to step 22, and will not be repeated here in the embodiments of this application.

[0127] Step 105: When a target SQL instruction group exists, for each state database indicated by n first business data, the consensus node rolls back the state database to the state at the save point where the state database was created; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0128] Step 105 can be referred to step 23, and will not be repeated here in the embodiments of this application.

[0129] Step 106: The consensus node determines whether the DML instruction in the target SQL instruction group is the same as the DML instruction in the first temporary block.

[0130] Step 106 can be referred to step 24, and will not be repeated here in the embodiments of this application.

[0131] Step 107: The consensus node conducts the first consensus with the block-producing node based on the judgment result.

[0132] Step 107 can be referred to step 25, and will not be repeated here in the embodiments of this application.

[0133] Step 108: When the block-producing node and the consensus node reach the first consensus based on the first temporary block, the block-producing node executes the DML instructions recorded in the first temporary block and adds the first temporary block to the blockchain.

[0134] Step 109: When the block-producing node and the consensus node reach the first consensus based on the first temporary block, the consensus node executes the DML instructions recorded in the first temporary block and adds the first temporary block to the blockchain.

[0135] Step 110: When the block-producing node and the consensus node reach the first consensus based on the first temporary block, the ordinary node receives the first temporary block broadcast by the block-producing node or the consensus node, executes the DML instructions recorded in the first temporary block, and adds the first temporary block to the blockchain.

[0136] Step 110 can be referred to steps 31 and 32, which will not be repeated here in the embodiments of this application.

[0137] In summary, this application provides a database operation method in which both the block-producing node and the consensus node first execute transactions of the n first business data sequentially to operate on the state database on the node. When a target SQL instruction group exists, the node can also roll back each state database indicated by the n first business data to the state at the point when the state database was created. Afterwards, the block-producing node and the consensus node reach consensus. It is evident that the database operation method provided in this application does not simulate a state database on the node, but rather operates directly on the state database. Therefore, this application provides a novel database operation method, enriching the ways in which databases can be operated.

[0138] Furthermore, in related technologies, when a node simulates a state database, it starts a process to simulate that state database, which affects the node's performance. In this embodiment, neither the block-producing node nor the consensus node needs to simulate a state database, and the transactions executing n pieces of first business data are all performed within the process of running the state database. Therefore, the database operation method provided in this embodiment has a smaller impact on node performance, resulting in higher node performance stability and overall higher node performance.

[0139] Furthermore, each block-producing node has at least one smart contract installed, and this smart contract has at least one corresponding state database (including a target state database). For example, the addresses of the state databases corresponding to different smart contracts in a node are different. Thus, different smart contracts correspond to different state databases to isolate the data in different state databases.

[0140] A smart contract includes contract data related to operations on the state database corresponding to that smart contract. Before executing transactions for n pieces of first business data sequentially, a block-producing node can obtain the SQL instruction set corresponding to each piece of first business data based on the smart contracts installed on the node.

[0141] Taking the aforementioned first business data as an example, the block-producing node can obtain the SQL instruction set corresponding to the first business data based on the first business data and the first contract data related to the target operation in the smart contract corresponding to the target state database.

[0142] There are many ways to implement the first contract data.

[0143] In one possible implementation of the first contract data, the first contract data includes an SQL statement; the block-producing node can assemble the first business data and the SQL statement to obtain the SQL instruction group corresponding to the first business data.

[0144] For example, the first business data is used to instruct the insertion of data 1 and data 2 into table X of the target state database. Then, the first contract data includes the SQL statement for inserting the data. The block-producing node assembles the first business data and the SQL statement, resulting in a SQL instruction group corresponding to the first business data, which includes: SQL instruction 1 for inserting data 1 into table X of the target state database, and SQL instruction 2 for inserting data 2 into table X of the target state database.

[0145] In another possible implementation of the first contract data, the first contract data includes a target object (also known as a structured object); the block-producing node can perform object relational mapping (ORM) on the target object to obtain the SQL statement related to the target operation; then, the block-producing node assembles the first business data and the SQL statement to obtain the SQL instruction group corresponding to the first business data.

[0146] For example, the first business data instructs the insertion of data 1 and data 2 into table X of the target state database. The first contract data includes the target object. The block-producing node performs ORM on the target object to obtain the SQL statement for inserting the data. Then, the block-producing node assembles the first business data and the SQL statement to obtain the corresponding SQL instruction set. This SQL instruction set includes SQL instruction 1 for inserting data 1 into table X of the target state database, and SQL instruction 2 for inserting data 2 into table X of the target state database.

[0147] Before executing transactions of n first business data in sequence, the consensus node can also refer to the method of the block producing node to obtain the SQL instruction group corresponding to the first business data, and obtain the SQL instruction group corresponding to each first business data. This embodiment of the application will not be described in detail here.

[0148] Furthermore, in the above embodiments, each node in the blockchain system is equipped with at least one smart contract, and the at least one smart contract has at least one corresponding state database.

[0149] It should be noted that each node in the blockchain system can install, upgrade, and delete (also known as destroy) smart contracts based on business data sent by the client (different from the first business data mentioned above). After one node in the blockchain system installs, upgrades, or deletes a smart contract, other nodes can also do the same.

[0150] The following example illustrates how a block-producing node installs, upgrades, and deletes a smart contract based on business data sent by a client, and how consensus nodes and ordinary nodes correspondingly install, upgrade, and delete the same smart contract. This smart contract can be any of the smart contracts described in the above embodiments, or it can be another smart contract installed after the smart contract in the above embodiments has been installed.

[0151] like Figure 7 As shown, in Figure 6 Based on this, the database operation method provided in the embodiments of this application further includes:

[0152] Step 201: When the block-producing node receives second business data sent by the client, including information about a smart contract, it installs the smart contract on the block-producing node and creates a state database corresponding to the smart contract; the smart contract includes second contract data related to the creation of a database object in the state database corresponding to the smart contract.

[0153] The second business data is used to instruct the installation of the smart contract and the creation of the corresponding state database. After receiving the second business data, the block-producing node can install the smart contract on the block-producing node and create the corresponding state database based on the information of the smart contract in the second business data.

[0154] Step 202: The block-producing node executes the creation SQL command to create a database object in the state database corresponding to the smart contract, based on the data from the second contract.

[0155] After creating the state database corresponding to a smart contract, the block-producing node can execute the creation SQL command based on the second contract data in the smart contract to create a database object in the state database corresponding to that smart contract. This database object can be a table, view, index, rule, syntax, function, stored procedure, trigger, etc.

[0156] Similar to the first contract data mentioned above, the second contract data can also be implemented in various ways.

[0157] In the first possible implementation of the second contract data, the second contract data includes the creation SQL instruction.

[0158] In a second possible implementation of the second contract data, the second contract data includes a second object. In this case, before executing the creation SQL instruction, the block-producing node can perform ORM on the second object to obtain the creation SQL instruction.

[0159] It should be noted that SQL commands, in addition to DML and DQL commands, also include Data Definition Language (DDL) commands. DDL commands include commands represented by CREATE statements, ALTER statements, and DROP statements. The CREATE SQL command can be a DDL command representing a CREATE statement.

[0160] Step 203: The block-producing node broadcasts the second temporary block to the consensus node. The second temporary block records the second business data and the creation SQL instruction.

[0161] After installing a smart contract, creating the corresponding state database, and creating a database object in the state database, the block-producing node can broadcast a second temporary block to the consensus node, so that the consensus node can receive the second temporary block and reach a consensus with the block-producing node based on the second temporary block.

[0162] Optionally, the block-producing node may generate a second temporary block after step 201 and record the second business data in the second temporary block. After step 202, the block-producing node may record the creation SQL instruction in the second temporary block.

[0163] Step 204: Based on the second business data in the second temporary block, the consensus node installs the smart contract on the consensus node and creates the state database corresponding to the smart contract.

[0164] Step 205: The consensus node executes a creation SQL command to create a database object in the state database corresponding to a smart contract, based on the data from the second contract.

[0165] After receiving the second temporary block, the consensus node can install a smart contract on the node based on the second business data in the second temporary block, create a state database corresponding to the smart contract, and execute a creation SQL command to create a database object in the state database corresponding to the smart contract based on the second contract data in the smart contract. The process of the consensus node performing these operations can be referred to the process of the block-producing node performing these operations, and will not be described in detail in this embodiment.

[0166] Step 206: The consensus node compares the creation SQL instruction executed by the consensus node with the creation SQL instruction in the second temporary block to see if they are the same.

[0167] After step 205, the consensus node can compare the creation SQL instruction executed by the consensus node with the creation SQL instruction executed by the block-producing node in the second temporary block to see if they are the same.

[0168] Step 207: Based on the comparison results, the consensus node conducts a second consensus with the block-producing node.

[0169] The method by which consensus nodes and block-producing nodes conduct second consensus can refer to the method by which consensus nodes and block-producing nodes conduct first consensus, and will not be elaborated here in the embodiments of this application.

[0170] Step 208: When the block-producing node and the consensus node reach a second consensus, the block-producing node adds the second temporary block to the blockchain.

[0171] Step 209: When the block-producing node and the consensus node reach a second consensus, the consensus node adds the second temporary block to the blockchain.

[0172] Step 210: When the block-producing node and the consensus node reach a second consensus, the ordinary node receives the second temporary block broadcast by the block-producing node or the consensus node, installs the smart contract on the ordinary node according to the second business data in the second temporary block, creates the state database corresponding to the smart contract, executes the creation SQL command to create a database object in the state database corresponding to the smart contract, and adds the second temporary block to the blockchain.

[0173] When the block-producing node and the consensus node reach a second consensus, the block-producing node or the consensus node will broadcast information indicating the second consensus (including a second temporary block). Both the block-producing node and the consensus node can add the second temporary block to the blockchain. Ordinary nodes will install a smart contract on their nodes based on the second business data in the second temporary block, create a state database corresponding to the smart contract, and execute a creation SQL command to create a database object in the state database corresponding to the smart contract based on the second contract data in the smart contract. The process of ordinary nodes performing these operations can be referenced to the process of block-producing nodes performing these operations, and will not be elaborated further in this embodiment.

[0174] After that, block-producing nodes, consensus nodes, and ordinary nodes all maintain the same blockchain, and these nodes all have the same smart contracts installed and maintain the same state database.

[0175] It should be noted that if the block-producing node and the consensus node cannot reach a second consensus, both the block-producing node and the consensus node need to delete the installed smart contract and its corresponding state database. Simultaneously, both the block-producing node and the consensus node also need to delete the second temporary block to invalidate it.

[0176] Furthermore, such as Figure 8 As shown, in Figure 7 Based on this, after the block-producing node and the consensus node reach a second consensus, the database operation method provided in this application embodiment further includes:

[0177] Step 301: When the block-producing node receives the third business data, including the update contract, sent by the client, it updates the smart contract installed on the block-producing node to the update contract according to the third business data; the update contract includes: third contract data related to the state database corresponding to the update smart contract.

[0178] An update contract is also a smart contract; it is an updated and upgraded version of an existing smart contract. The update contract includes third-party contract data related to the state database corresponding to the aforementioned smart contract.

[0179] This embodiment of the application takes updating the smart contract and its corresponding state database simultaneously as an example. Optionally, the smart contract can be updated without updating its corresponding state database. In this case, the updated contract does not include data from the third contract, and this embodiment of the application does not limit this approach.

[0180] Step 302: The block-producing node executes an update SQL command to update the state database corresponding to the smart contract based on the data from the third contract.

[0181] After updating one of the aforementioned smart contracts, the block-producing node can also obtain update SQL commands to update the state database corresponding to that smart contract based on the data from the third contract. Executing these update SQL commands will update the database objects and / or the data on those database objects in the state database.

[0182] Similar to the second contract data mentioned above, the third contract data can also be implemented in various ways.

[0183] In the first possible implementation of the third contract data, the third contract data includes the update SQL instruction.

[0184] In the second possible implementation of the third contract data, the third contract data includes a third object. In this case, before executing the update SQL instruction, the block-producing node can perform ORM on the third object to obtain the update SQL instruction.

[0185] This update SQL command can also be a DDL command, such as a command represented by the ALTER statement in a DDL command.

[0186] Step 303: The block-producing node broadcasts the third temporary block to the consensus node; the third temporary block records the third business data and update SQL instructions.

[0187] After step 302, the block-producing node can broadcast a third temporary block to the consensus node so that the consensus node can receive the third temporary block and reach a consensus with the block-producing node based on the third temporary block.

[0188] Optionally, the block-producing node may generate a third temporary block after step 301 and record the third business data in the third temporary block. After step 302, the block-producing node may record update SQL instructions in the third temporary block.

[0189] Step 304: The consensus node updates the smart contract installed on the consensus node to an updated contract based on the third business data in the third temporary block.

[0190] Step 305: The consensus node executes an update SQL command to update the database object in the state database corresponding to the smart contract based on the data from the third contract.

[0191] After receiving the third temporary block, the consensus node can update the smart contract installed on the node to the aforementioned updated contract based on the third business data in the third temporary block, and execute update SQL instructions to update the database objects in the state database corresponding to the smart contract based on the third contract data in the smart contract. The process of the consensus node performing these operations can be referred to the process of the block-producing node performing these operations, and will not be described in detail in the embodiments of this application.

[0192] Step 306: The consensus node compares the update SQL instruction executed by the consensus node with the update SQL instruction in the third temporary block to see if they are the same.

[0193] After step 305, the consensus node can compare the update SQL instruction executed by the consensus node with the update SQL instruction executed by the block-producing node in the third temporary block to see if they are the same.

[0194] Step 307: Based on the comparison results, the consensus node conducts a third consensus with the block-producing node.

[0195] The method by which consensus nodes and block-producing nodes conduct third consensus can refer to the method by which consensus nodes and block-producing nodes conduct first consensus, and will not be elaborated here in the embodiments of this application.

[0196] Step 308: When the block-producing node and the consensus node reach a third consensus, the block-producing node adds the third temporary block to the blockchain.

[0197] Step 309: When the block-producing node and the consensus node reach a third consensus, the consensus node adds the third temporary block to the blockchain.

[0198] Step 310: When the block-producing node and the consensus node reach a third consensus, the ordinary node receives the third temporary block broadcast by the block-producing node or the consensus node, updates the smart contract installed on the ordinary node to an update contract according to the third business data in the third temporary block, executes the update SQL command to update the database object in the state database corresponding to the smart contract according to the third contract data, and adds the third temporary block to the blockchain.

[0199] After receiving the third temporary block, a regular node can update the smart contract installed on the node to the aforementioned updated contract based on the third business data in the third temporary block, and execute update SQL commands to update the database objects in the state database corresponding to the smart contract based on the third contract data in the smart contract. The process of regular nodes performing these operations can be referred to the process of block-producing nodes performing these operations, and will not be described in detail in this embodiment.

[0200] When the block-producing node and the consensus node reach a third consensus, the block-producing node, the consensus node, and the ordinary node can all add the third temporary block to the blockchain so that these nodes all maintain the same blockchain. At this time, these nodes all have the same smart contract installed and maintain the same state database.

[0201] It should be noted that if the block-producing node and the consensus node cannot reach a third consensus, both the block-producing node and the consensus node need to restore the smart contract and the corresponding state database. Simultaneously, both the block-producing node and the consensus node also need to delete the third temporary block to invalidate it.

[0202] Furthermore, such as Figure 9 As shown, in Figure 7 or Figure 8 Based on this, after the block-producing nodes and consensus nodes reach a second consensus, such as Figure 9 As shown, the database operation method provided in this application embodiment further includes:

[0203] Step 401: When the block-producing node receives the fourth business data sent by the client, it executes a delete SQL command to delete a smart contract and its corresponding state database according to the fourth business data; the fourth business data is used to indicate the deletion of a smart contract and its corresponding state database.

[0204] This smart contract can be Figure 7 Smart contracts in the context can also be Figure 8 The updated contract in this application is not limited in this embodiment.

[0205] A smart contract can include fourth contract data, and block-producing nodes can obtain the delete SQL command based on the fourth contract data.

[0206] The fourth contract data can be the delete SQL instruction. Alternatively, the fourth contract data can be a fourth object, and the block-producing node can perform ORM on the fourth object before executing the delete SQL instruction to obtain the delete SQL instruction.

[0207] The delete SQL command can also be a DDL command, such as the delete (DROP) statement in a DDL command.

[0208] During the execution of the delete SQL command, the block-producing node can clear the data in the state database, archive the data, delete the state database, and delete the smart contract.

[0209] Step 402: The block-producing node broadcasts the fourth temporary block to the consensus node so that the block-producing node and the consensus node can conduct the fourth consensus based on the fourth temporary block; the fourth temporary block records the fourth business data and the delete SQL instruction.

[0210] Step 403: The consensus node executes a delete SQL command to delete a smart contract and its corresponding state database based on the fourth business data in the fourth temporary block.

[0211] After receiving the fourth temporary block, the consensus node can execute a delete SQL command to delete a smart contract and its corresponding state database based on the fourth business data in the fourth temporary block. The process by which the consensus node performs these operations can be referenced from the process by which the block-producing node performs these operations, and will not be described in detail here.

[0212] Step 404: The consensus node compares the delete SQL instruction executed by the consensus node with the delete SQL instruction in the fourth temporary block to see if they are the same.

[0213] After step 403, the consensus node can compare the delete SQL instruction executed by the consensus node with the delete SQL instruction executed by the block-producing node in the fourth temporary block to see if they are the same.

[0214] Step 405: Based on the comparison results, the consensus node conducts a fourth consensus with the block-producing node.

[0215] The method by which consensus nodes and block-producing nodes conduct the fourth consensus can refer to the method by which consensus nodes and block-producing nodes conduct the first consensus, and will not be elaborated here in the embodiments of this application.

[0216] Step 406: When the block-producing node and the consensus node reach the fourth consensus, the block-producing node adds the fourth temporary block to the blockchain.

[0217] Step 407: When the block-producing node and the consensus node reach the fourth consensus, the consensus node adds the fourth temporary block to the blockchain.

[0218] Step 408: When the block-producing node and the consensus node reach the fourth consensus, the ordinary node receives the fourth temporary block broadcast by the block-producing node or the consensus node, and executes a delete SQL command to delete a smart contract and its corresponding state database based on the fourth business data in the fourth temporary block.

[0219] When the block-producing node and the consensus node reach the fourth consensus, ordinary nodes will receive the fourth temporary block. Afterwards, ordinary nodes can execute a delete SQL command to delete a smart contract and its corresponding state database based on the fourth business data in the fourth temporary block. The process by which ordinary nodes perform these operations can be referenced to the process by which the block-producing node performs these operations; therefore, it will not be elaborated upon in this embodiment.

[0220] When the block-producing node and the consensus node reach the fourth consensus, the block-producing node, the consensus node, and the ordinary nodes can all add the fourth temporary block to the blockchain so that each node maintains the same blockchain. At this time, these nodes all have the same smart contract installed and maintain the same state database.

[0221] It should be noted that if the block-producing node and the consensus node cannot reach a fourth consensus, both the block-producing node and the consensus node need to restore the smart contract and the corresponding state database. Simultaneously, both the block-producing node and the consensus node also need to delete the fourth temporary block to invalidate it.

[0222] When a client sends business data (such as the first, second, third, and fourth business data mentioned above) to a block-producing node, it can be called a client-initiated transaction; the business data can also be called transaction data. Sending the first business data to a block-producing node can be called a client-initiated contract call transaction; sending the second, third, or fourth business data to a block-producing node can be called a client-initiated contract management transaction.

[0223] Business data has a transaction number (Identity document, ID). Block-producing nodes can distinguish different business data based on the transaction ID of the business data. For example, when n>1, the above n first business data have different transaction IDs.

[0224] In addition, smart contracts include functions, and contract data can be recorded in these functions. For example, functions in a smart contract may include: call functions, query functions, initialization functions, upgrade functions, and delete functions. The first type of contract data can be contained in the call function or query function, the second type in the initialization function, the third type in the upgrade function, and the fourth type in the delete function.

[0225] Smart contracts also include at least one of DDL, DML, and DQL interfaces. When a node needs to use contract data in a certain function, it can run the smart contract and call the interface related to the contract data in that function to obtain the contract data.

[0226] In addition, the smart contract in this application embodiment also includes a contract framework, and the aforementioned initialization function, upgrade function and deletion function can all be included in the contract framework.

[0227] Smart contracts are written by staff. When writing a smart contract, staff can write SQL statements and SQL instructions (or objects that can be obtained after ORM, and objects that can be obtained after ORM) within the functions of the contract framework, thereby obtaining the smart contract. Staff can freely write SQL instructions according to their needs to define the database objects in the state database corresponding to the smart contract. Since writing SQL statements and SQL instructions is relatively easy, the smart contract writing threshold in this embodiment is low, improving the user experience for staff.

[0228] Optionally, in this embodiment, the state database created by the node (i.e., the state database maintained) is located on the node. Alternatively, the state database created by the node may not be located on the block-producing node. For example, the state database created by the node may be located on a remote device outside the node. This embodiment does not limit this. When the state database is not located on the node, the node does not need to store the state database, thus reducing the storage and computational pressure on the node.

[0229] Furthermore, embodiments of this application also provide a database operation device, which can be a block-producing node in a blockchain system, and the blockchain system also includes consensus nodes. Figure 10 As shown, the database operation device includes:

[0230] The first execution module 701 is configured to sequentially execute transactions of n first business data when receiving n first business data sent by the client; wherein n≥1, for one of the n first business data, the transaction of the first business data includes: creating a savepoint of the target state database; executing the Structured Query Language (SQL) instruction set corresponding to the first business data; and if the SQL instruction set fails to execute, rolling back the target state database to the state at the time of creating the savepoint; the first business data is used to indicate a target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; and the SQL instruction set includes instructions for the target operation.

[0231] The rollback module 702 is used to roll back the state database to the state at the save point when the state database was created, for each state database indicated by the n first business data when a target SQL instruction group exists; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0232] The first broadcast module 703 is used to broadcast a first temporary block to the consensus node so that the block-producing node and the consensus node can reach a first consensus based on the first temporary block. The first temporary block records the n first business data and the DML instructions in the target SQL instruction group.

[0233] Optionally, the block-producing node has at least one smart contract installed, and the at least one smart contract has at least one corresponding state database. The smart contract includes contract data related to operating on the state database corresponding to the smart contract; the at least one state database includes the target state database, and the database operation device further includes:

[0234] First acquisition module ( Figure 10 (Not shown in the image), used to obtain the SQL instruction group corresponding to the first business data based on the first business data and the first contract data related to the target operation in the smart contract corresponding to the target state database before sequentially executing the transaction of the n first business data.

[0235] Optionally, the first contract data includes an SQL statement; the first acquisition module is used to: assemble the first business data and the SQL statement to obtain the SQL instruction group corresponding to the first business data.

[0236] Optionally, the first contract data includes a target object; the first acquisition module is used to: perform object-relational mapping (ORM) on the target object to obtain an SQL statement related to the target operation; and assemble the first business data and the SQL statement to obtain an SQL instruction group corresponding to the first business data.

[0237] Optionally, the database operation device further includes:

[0238] Processing module ( Figure 10 (Not shown in the image), used to install the smart contract on the block node and create a state database corresponding to the smart contract when receiving second business data including information about a smart contract sent by a client; the smart contract includes second contract data related to creating a database object in the state database corresponding to the smart contract;

[0239] Second execution module ( Figure 10 (not shown in the image), used to execute a creation SQL command to create a database object in the state database corresponding to the smart contract based on the second contract data;

[0240] Second broadcast module ( Figure 10 (Not shown in the image), used to broadcast a second temporary block to the consensus node, so that the block-producing node and the consensus node can perform a second consensus based on the second temporary block; the second temporary block records the second business data and the creation SQL instruction;

[0241] Third execution module ( Figure 10 (not shown in the image), used to add the second temporary block to the blockchain when the block-producing node and the consensus node reach the second consensus based on the second temporary block.

[0242] Optionally, the second contract data includes the creation SQL instruction; or, the second contract data includes a second object, and the database operation device further includes: a second acquisition module, used to perform ORM on the second object before executing the creation SQL instruction to obtain the creation SQL instruction.

[0243] Optionally, the database operation device further includes:

[0244] First update module ( Figure 10 (Not shown in the image), used to update the smart contract to the updated contract according to the third business data sent by the client after the block-producing node and the consensus node reach the second consensus; the updated contract includes: third contract data related to the state database corresponding to the updated smart contract;

[0245] Second update module ( Figure 10 (not shown in the image), used to execute update SQL instructions to update the state database corresponding to the smart contract based on the third contract data;

[0246] Third broadcast module ( Figure 10 (Not shown in the image), used to broadcast the third temporary block to the consensus node, so that the block-producing node and the consensus node can perform a third consensus based on the third temporary block; the third temporary block records the third business data and the update SQL instruction;

[0247] Fourth execution module ( Figure 10 (Not shown in the image), used to add the third temporary block to the blockchain when the block-producing node and the consensus node reach the third consensus based on the third temporary block.

[0248] Optionally, the database operation device further includes:

[0249] Third execution module ( Figure 10 (Not shown in the image), is used to execute a delete SQL command to delete the smart contract and its corresponding state database based on the fourth business data sent by the client after the block-producing node and the consensus node reach the second consensus; the fourth business data is used to indicate the deletion of the smart contract and its corresponding state database.

[0250] Fourth broadcast module ( Figure 10 (Not shown in the image), used to broadcast the fourth temporary block to the consensus node, so that the block-producing node and the consensus node can perform a fourth consensus based on the fourth temporary block; the fourth temporary block records the fourth business data and the delete SQL instruction;

[0251] Fifth Execution Module ( Figure 10 (Not shown in the image), used to add the fourth temporary block to the blockchain when the block-producing node and the consensus node reach the fourth consensus based on the fourth temporary block.

[0252] Optionally, the database operation device further includes:

[0253] Sixth Execution Module ( Figure 10 (not shown in the image), used to execute the DML instructions recorded in the first temporary block and add the first temporary block to the blockchain when the block-producing node and the consensus node reach the first consensus.

[0254] This application embodiment also provides another database operation device, which is a consensus node in a blockchain system. The blockchain system further includes block-producing nodes, such as... Figure 11 As shown, the database operation device includes:

[0255] The receiving module 801 is used to receive the first temporary block broadcast by the block producing node; wherein the first temporary block records n first service data and DML instructions, n≥1;

[0256] Execution module 802 is used to sequentially execute transactions of the n first business data; wherein, for one of the n first business data, the transaction of the first business data includes: creating a savepoint of the target state database; executing the SQL instruction group corresponding to the first business data; and if the execution of the SQL instruction group fails, rolling back the target state database to the state when the savepoint was created; the first business data is used to indicate a target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; the SQL instruction group includes instructions for the target operation;

[0257] The rollback module 803 is used to roll back the state database to the state at the save point when the state database was created, for each state database indicated by the n first business data when a target SQL instruction group exists; the target SQL instruction group includes DML instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed.

[0258] The judgment module 804 is used to determine whether the DML instruction in the target SQL instruction group is the same as the DML instruction in the first temporary block;

[0259] The consensus module 805 is used to reach a first consensus with the block-producing node based on the result of the judgment.

[0260] Optionally, the database operation device further includes:

[0261] Execution module ( Figure 11 (Not shown in the image), used to execute the DML instructions recorded in the first temporary block and add the first temporary block to the blockchain when the block-producing node and the consensus node reach a first consensus based on the first temporary block.

[0262] This application embodiment also provides another database operation device, which is executed by a regular node in a blockchain system. The blockchain system further includes block-producing nodes and consensus nodes, such as... Figure 12 As shown, the database operation device includes:

[0263] The receiving module 901 is used to receive the first temporary block broadcast by the block producing node or the consensus node; wherein the first temporary block records n first business data and DML instructions, n≥1; the first temporary block is a block broadcast by the block producing node and the consensus node after reaching a first consensus based on the first temporary block.

[0264] The execution module 902 is used to execute the DML instructions recorded in the first temporary block and add the first temporary block to the blockchain.

[0265] It is understood that the database operation device provided in the above embodiments is only an example of the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the database operation device and the database operation method embodiments provided in the above embodiments belong to the same concept. The database operation device embodiments can be referred to the description of the database operation method embodiments, which will not be repeated here.

[0266] In this application embodiment, the block-producing node, consensus node, and ordinary node can all be servers. Figure 13 This is a schematic diagram of the structure of a server provided in an embodiment of this application.

[0267] Specifically, server 110 includes a central processing unit (CPU) 111, a system memory 112 including random access memory (RAM) 1121 and read-only memory (ROM) 1122, and a system bus 113 connecting the system memory 112 and the CPU 111. Server 110 also includes a mass storage device 114 for storing the operating system 1141, application programs 1142, and other program modules 1143.

[0268] Mass storage device 114 is connected to central processing unit 111 via a mass storage controller (not shown) connected to system bus 113. Mass storage device 114 and its associated computer-readable media provide non-volatile storage for server 110. That is, mass storage device 114 may include computer-readable media (not shown) such as hard disk or compact disc read-only memory (CD-ROM) drives.

[0269] Without loss of generality, computer-readable media can include computer storage media and communication media. Computer storage media includes volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media include RAM, ROM, erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other solid-state storage technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape cassettes, magnetic tape, disk storage, or other magnetic storage devices. Of course, those skilled in the art will recognize that computer storage media are not limited to the above-mentioned types. The system memory 112 and mass storage device 114 described above can be collectively referred to as memory.

[0270] According to various embodiments of this application, server 110 can also be connected to a remote computer on a network, such as the Internet. That is, server 110 can be connected to network 116 via network interface unit 115 connected to system bus 113, or it can also use network interface unit 115 to connect to other types of networks or remote computer systems (not shown).

[0271] The aforementioned memory also includes one or more programs, which are stored in the memory and configured to be executed by the CPU.

[0272] Embodiments of this application also provide a computer device including a processor and a memory, the memory storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded by the processor and executed in accordance with the steps performed by a block-producing node, consensus node, or ordinary node in any of the database operation methods described in the above embodiments.

[0273] Embodiments of this application also provide a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the steps executed by a block-producing node, consensus node, or ordinary node in any of the database operation methods described above.

[0274] Embodiments of this application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps executed by a block-producing node, consensus node, or ordinary node in any of the database operation methods described above.

[0275] Optionally, the computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), solid-state drives (SSDs), or optical discs, etc. The random access memory may include resistive random access memory (ReRAM) and dynamic random access memory (DRAM).

[0276] This application also provides a blockchain system, which includes: a client, a block-producing node, a consensus node, and ordinary nodes; the client is used to send business data to the block-producing node; the block-producing node is used to execute the steps performed by the block-producing node in any of the database operation methods provided in this application; the consensus node is used to execute the steps performed by the consensus node in any of the database operation methods provided in this application; and the ordinary nodes are used to execute the steps performed by the ordinary nodes in any of the database operation methods provided in this application.

[0277] It is understood that in this application, the term "at least one" refers to one or more, and "multiple" means two or more. The terms "first," "second," etc., are used to distinguish identical or similar items with essentially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," etc., nor are there any limitations on quantity or execution order. The term "and / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Furthermore, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.

[0278] The order of steps in the method embodiments provided in this application can be adjusted appropriately, and steps can also be added or removed as appropriate. Any variations that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this invention should be included within the protection scope of this invention, and therefore will not be elaborated further.

[0279] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0280] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A database operation method, characterized in that, The method is executed by block-producing nodes in a blockchain system, which also includes consensus nodes; the method includes: Upon receiving n pieces of first business data sent by the client, the transactions of the n pieces of first business data are executed sequentially; wherein, n≥1, for one of the n pieces of first business data, the transaction of the first business data includes: creating a savepoint for the target state database; executing the Structured Query Language (SQL) instruction set corresponding to the first business data; if the SQL instruction set fails to execute, rolling back the target state database to the state at the time the savepoint was created; the first business data is used to indicate a target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; the SQL instruction set includes instructions for the target operation; When a target SQL instruction group exists, for each state database indicated by the n first business data, the state database is rolled back to the state at the save point when the state database was created; the target SQL instruction group includes Data Manipulation Language (DML) instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed. The first temporary block is broadcast to the consensus node so that the block-producing node and the consensus node can reach a first consensus based on the first temporary block. The first temporary block records the n first business data and the DML instructions in the target SQL instruction group.

2. The method according to claim 1, characterized in that, After broadcasting the first temporary block to the consensus node, the method further includes: When the block-producing node and the consensus node reach the first consensus, the DML instruction recorded in the first temporary block is executed, and the first temporary block is added to the blockchain.

3. The method according to claim 1 or 2, characterized in that, The block node is equipped with at least one smart contract, and the at least one smart contract has at least one corresponding state database. The smart contract includes contract data related to operating the state database corresponding to the smart contract. The at least one state database includes the target state database, and the method further includes: Before executing the transactions of the n first business data in sequence, the SQL instruction group corresponding to the first business data is obtained based on the first business data and the first contract data related to the target operation in the smart contract corresponding to the target state database.

4. The method according to claim 3, characterized in that, The method satisfies any of the following conditions: The first contract data includes SQL statements; based on the first business data and the first contract data related to the target operation in the smart contract corresponding to the target state database, the SQL instruction group corresponding to the first business data is obtained, including: assembling the first business data and the SQL statements to obtain the SQL instruction group corresponding to the first business data; The first contract data includes a target object; based on the first business data and the first contract data related to the target operation in the smart contract corresponding to the target state database, a SQL instruction group corresponding to the first business data is obtained, including: performing object-relational mapping (ORM) on the target object to obtain an SQL statement related to the target operation; assembling the first business data and the SQL statement to obtain the SQL instruction group corresponding to the first business data.

5. The method according to claim 3, characterized in that, The method further includes: Upon receiving second business data from the client, including information about a smart contract, the smart contract is installed on the block node, and a state database corresponding to the smart contract is created; the smart contract includes second contract data related to the creation of a database object in the state database corresponding to the smart contract. Based on the second contract data, execute the creation SQL command to create a database object in the state database corresponding to the smart contract; The second temporary block is broadcast to the consensus node so that the block-producing node and the consensus node can reach a second consensus based on the second temporary block; the second temporary block records the second business data and the creation SQL instruction; When the block-producing node and the consensus node reach the second consensus based on the second temporary block, the second temporary block is added to the blockchain.

6. The method according to claim 5, characterized in that, The second contract data includes the creation SQL instruction; Alternatively, the second contract data may include a second object, and the method may further include: performing an ORM on the second object before executing the creation SQL instruction to obtain the creation SQL instruction.

7. The method according to claim 5, characterized in that, After the block-producing node and the consensus node reach the second consensus, the method further includes: Upon receiving third business data from the client that includes an updated contract, the smart contract is updated to the updated contract based on the third business data; the updated contract includes: third contract data related to the state database corresponding to the updated smart contract; Based on the third contract data, execute an update SQL command to update the state database corresponding to the smart contract; The third temporary block is broadcast to the consensus node so that the block-producing node and the consensus node can perform a third consensus based on the third temporary block; the third temporary block records the third business data and the update SQL instruction; When the block-producing node and the consensus node reach the third consensus based on the third temporary block, the third temporary block is added to the blockchain.

8. The method according to claim 5, characterized in that, After the block-producing node and the consensus node reach the second consensus, the method further includes: Upon receiving the fourth business data sent by the client, a delete SQL command is executed to delete the smart contract and its corresponding state database based on the fourth business data; the fourth business data is used to indicate the deletion of the smart contract and its corresponding state database. The fourth temporary block is broadcast to the consensus node so that the block-producing node and the consensus node can perform a fourth consensus based on the fourth temporary block; the fourth temporary block records the fourth business data and the deletion SQL instruction; When the block-producing node and the consensus node reach the fourth consensus based on the fourth temporary block, the fourth temporary block is added to the blockchain.

9. A database operation method, characterized in that, The method is executed by consensus nodes in a blockchain system, which further includes block-producing nodes. The method includes: Receive the first temporary block broadcast by the block-producing node; wherein the first temporary block records n first service data and DML instructions, n≥1; The transactions of the n first business data are executed sequentially; wherein, for one of the n first business data, the transaction of the first business data includes: creating a savepoint for the target state database; executing the Structured Query Language (SQL) instruction set corresponding to the first business data; if the SQL instruction set fails to execute, rolling back the target state database to the state at the time of creating the savepoint according to the savepoint; the first business data is used to indicate the target operation to be performed on the target state database, the target state database being a relational database; the target operation includes: adding, deleting, modifying, and / or querying data; the SQL instruction set includes instructions for the target operation; When a target SQL instruction group exists, for each state database indicated by the n first business data, the state database is rolled back to the state at the save point when the state database was created; the target SQL instruction group includes Data Manipulation Language (DML) instructions, and the target SQL instruction group is a group of SQL instructions that have been successfully executed. Determine whether the DML instructions in the target SQL instruction group are the same as the DML instructions in the first temporary block; Based on the result of the judgment, a first consensus is reached with the block-producing node.

10. The method according to claim 9, characterized in that, The method further includes: When the block-producing node and the consensus node reach a first consensus based on the first temporary block, the DML instruction recorded in the first temporary block is executed, and the first temporary block is added to the blockchain.

11. A database operation method, characterized in that, The method is executed by ordinary nodes in the blockchain system, which also includes block-producing nodes and consensus nodes. The method includes: Receive a first temporary block broadcast by the block-producing node or the consensus node; wherein, the first temporary block records n first business data and Data Manipulation Language (DML) instructions, n≥1; the first temporary block is a block broadcast when the block-producing node and the consensus node reach a first consensus based on the first temporary block; Execute the DML instructions recorded in the first temporary block and add the first temporary block to the blockchain; Specifically, during the process of the block-producing node and the consensus node reaching a first consensus based on the first temporary block, when the block-producing node receives n first business data sent by the client, it sequentially executes the transactions of the n first business data; when a target SQL instruction group exists, for each state database indicated by the n first business data, it rolls back the state database to the state at the point when the state database was created; and broadcasts the first temporary block to the consensus node. The consensus node receives the first temporary block broadcast by the block-producing node; executes the transactions of the n first business data in sequence; when a target SQL instruction group exists, for each state database indicated by the n first business data, rolls back the state database to the state at the point when the state database was created; determines whether the DML instruction in the target SQL instruction group is the same as the DML instruction in the first temporary block; and performs a first consensus with the block-producing node based on the result of the determination.

12. A blockchain system, characterized in that, The blockchain system includes: clients, block-producing nodes, consensus nodes, and ordinary nodes; The client is used to send business data to the block-producing node; The block-producing node is used to perform the method according to any one of claims 1 to 8; The consensus node is used to execute the method described in claim 9 or 10; The ordinary node is used to perform the method of claim 11.

13. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction, at least one program, a code set, or an instruction set, the at least one instruction, the at least one program, the code set, or the instruction set being loaded and executed by the processor to implement the method as claimed in any one of claims 1 to 8, or the method as claimed in claim 9 or 10, or the method as claimed in claim 11.

14. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method as claimed in any one of claims 1 to 8, or the method as claimed in claim 9 or 10, or the method as claimed in claim 11.

15. A computer program product containing instructions, characterized in that, When the computer program product is run on a computer, it causes the computer to perform the method as described in any one of claims 1 to 8, or the method as described in claim 9 or 10, or the method as described in claim 11.

Citation Information

Patent Citations

  • Database system, node and method

    CN111241590A