WO2023160095A1 - Method and system for implementing structured data storage and queries in blockchain system - Google Patents

Method and system for implementing structured data storage and queries in blockchain system Download PDF

Info

Publication number
WO2023160095A1
WO2023160095A1 PCT/CN2022/135638 CN2022135638W WO2023160095A1 WO 2023160095 A1 WO2023160095 A1 WO 2023160095A1 CN 2022135638 W CN2022135638 W CN 2022135638W WO 2023160095 A1 WO2023160095 A1 WO 2023160095A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
blockchain
data
block
transactions
Prior art date
Application number
PCT/CN2022/135638
Other languages
French (fr)
Chinese (zh)
Inventor
何家华
俞本权
田世坤
Original Assignee
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2023160095A1 publication Critical patent/WO2023160095A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Definitions

  • This specification relates to the field of information technology, in particular to methods and systems for implementing structured data storage and query in blockchain systems.
  • smart contracts are the carrier of business logic.
  • Some blockchain systems only provide a k-v (key-value, key-value pair) query interface, that is, in a smart contract, only a single data query method that provides a key to query the value associated with the key is supported, lacking more efficient and flexible data Query methods (such as conditional query, range query, joint query across tables, etc.), lead to various restrictions on the development of business logic.
  • One of the embodiments of this specification provides a method for implementing structured data storage and query in a blockchain system, the method comprising: using a relational database for data storage and query during the execution of a blockchain transaction.
  • One of the embodiments of this specification provides a system for implementing structured data storage and query in a blockchain system, and the system for implementing structured data storage and query is used to: use relational Database for data storage and query.
  • One of the embodiments of this specification provides a device for implementing structured data storage and query in a blockchain system.
  • the device includes a processor and a storage device, the storage device is used to store instructions, and when the processor executes the instructions, it realizes the structured data storage in the blockchain system as described in any embodiment of this specification and query methods.
  • One of the embodiments of this specification provides a blockchain transaction execution method.
  • the method includes: obtaining one or more transactions to be executed; executing the one or more transactions, wherein state data related to the one or more transactions is read and written using a relational database.
  • One of the embodiments of this specification provides a blockchain transaction execution system.
  • the system includes: a transaction acquisition module, used to acquire one or more transactions to be executed; a transaction execution module, used to execute the one or more transactions, wherein a relational database is used to pair with the one or more Transaction-related state data is read and written.
  • the apparatus includes a processor and a storage device, the storage device is used to store instructions, and when the processor executes the instructions, the blockchain transaction execution method described in any embodiment of this specification is implemented.
  • FIG. 1 is a schematic diagram of an application scenario of a blockchain system according to some embodiments of this specification
  • Fig. 2 is an exemplary flow chart of a blockchain transaction execution method according to some embodiments of this specification
  • Fig. 3 is an exemplary block diagram of a blockchain transaction execution system according to some embodiments of this specification.
  • Fig. 4 is a schematic diagram of a storage module for implementing structured data storage and query according to some embodiments of the present specification.
  • system means for distinguishing different components, elements, components, parts or assemblies of different levels.
  • the words may be replaced by other expressions if other words can achieve the same purpose.
  • Fig. 1 is a schematic diagram of an application scenario of a blockchain system according to some embodiments of this specification.
  • the blockchain system 100 may include a client 110 , a blockchain network 120 and a network 130 .
  • the client 110 may be a terminal using blockchain services, which may be linked to a certain node in the blockchain network 120 through the network 130 .
  • the client 110 can initiate a transaction, that is, generate a transaction and send the generated transaction to the blockchain network 120 , so that the transaction is broadcast on the blockchain network 120 .
  • the transactions appearing in this specification specifically refer to blockchain transactions, which are used to trigger various events in the blockchain system 100 .
  • the event may include one or more of the joining of a new node, the exit of a node, transfer, data deposit, etc.
  • the certified data may include one or more of medical information, electronic contracts, electronic credentials, electronic orders, digital fingerprints, and the like.
  • Smart contracts are modular, reusable, and automatically executed scripts that run on the blockchain.
  • the contract code (such as bytecode) is stored in each blockchain node, and each (part) contract corresponds to a contract address.
  • a transaction pointing to the contract address can be generated, and all blockchain nodes in the blockchain network 120 can execute the contract code and write the execution result into the blockchain data. That is, the code in the smart contract can be triggered by a transaction, which can also be called the execution of the transaction.
  • a transfer transaction can trigger the update of the account balance of both parties to the transfer
  • a data deposit transaction can trigger the data to be deposited into the blockchain data
  • a data query transaction can trigger the reading of the blockchain data, etc. wait.
  • the blockchain network 120 may include multiple blockchain nodes, for example, node 120-1, node 120-2, node 120-3, . . . , node 120-n in FIG. 1 .
  • any blockchain node receives the transaction initiated by the client 110 , it can forward the transaction to other nodes, so that the transaction is broadcasted on the blockchain network 120 .
  • a blockchain node may collect transactions broadcast in the blockchain network 120 and generate a block based on one or more transactions. Among them, the prerequisite for generating a valid block may include: the blockchain nodes participating in the consensus reach a consensus on the execution result of the transaction on which the block is generated (consensus is passed). In addition, blockchain nodes can also initiate transactions.
  • the blockchain data stored by each blockchain node in the blockchain network 120 can be consistent.
  • Blockchain data can include block data and state data.
  • the block data includes a data chain (that is, a block chain) in which multiple blocks are linked in order of generation time, and the block data has the property of being unmodifiable.
  • a block may include two parts: a block header and a block body, where the key information (or summary information) of the block can be written in the block header, and the detailed information of the block can be written in the block body. For example, block timestamp, block hash value (of this block), block hash value of parent block (previous block), block height, and Merkle tree can be written in the block header.
  • Root hash, etc. where the block timestamp can reflect the generation time of the block, the block hash value can be calculated based on the content in the block header, and the block height can reflect which block is generated .
  • a transaction list, transaction receipt list, etc. can be written in the block body.
  • the transaction list includes one or more transactions based on which the block is generated (which can be collectively referred to as transactions in the block).
  • the transaction receipt list includes one or more transactions in the block. Receipts for multiple transactions.
  • Transactions can be written into the transaction list in the form of key-value pairs (k-v), key (key/keyword, can be abbreviated as k) is the transaction ID, and value (value, can be abbreviated as v) is each field of the transaction.
  • key key/keyword
  • value value
  • the various fields of the transaction may include the account address of the transaction initiator, the transaction timestamp, the amount the transaction initiator is willing to pay for the transaction, the account address of the calling smart contract, the name of the function in the calling smart contract, the provided Input to the function, etc.
  • State data is blockchain data that supports addition, deletion, query, and modification.
  • Key-value pairs (k-v) can be used to store state data
  • k is the identification (name/ID) of state data
  • v is the value (such as value) of state data.
  • state data may include the world state composed of the state of all blockchain accounts (account state).
  • the account status can be stored in the form of k-v, where k is the account identifier (also called the account address), and v is the value of the account status.
  • the account status can include the account balance.
  • the account status can also include the hash value of the smart contract code and the status stored in the account of the smart contract.
  • Each smart contract can have a corresponding storage, and correspondingly, the state data can also include the storage of the smart contract.
  • the storage of smart contracts can include contract code (such as bytecode) and account storage.
  • account storage can save contract variables.
  • Contract variables can be stored in the form of k-v, where k is the variable name and v is the variable value.
  • the k of the contract variable can be the name (address) of the asset account
  • the v of the contract variable can be the balance of the asset account.
  • the balance may include k-v corresponding to different asset types, k may be an asset type (such as RMB, USD, etc.), and v may be the balance of the asset type.
  • state data in the form of key-value pairs can be organized into the form of a Merkle tree.
  • the underlying database can be constructed based on a Merkle tree, and this database can be called a Merkle tree-based database.
  • a Merkle tree is a hash binary tree, which is a data structure for quickly summarizing and verifying the integrity of large-scale data.
  • SPV Simple Payment Verification, simple payment verification
  • the SPV node in 120 also called light node/light client, which can be the client 110
  • can also perform relevant verification such as verifying whether the transaction exists, whether the transaction belongs to a certain block, etc.
  • the Merkle tree used to record state data may include one or more of a state tree, a transaction tree, a receipt tree, a storage tree, and the like.
  • the state tree is used to save the state of the world.
  • Each block can correspond to a transaction tree, and the transaction tree of each block is used to save all transactions in the block.
  • Each block can correspond to a receipt tree, and the receipt tree of each block is used to save the execution results of all transactions in the block.
  • Each smart contract can correspond to a storage tree, which is used to save the account storage of the smart contract.
  • the Merkle tree used to record state data may include an MPT (Merkle Patricia Tree) tree, and the MPT tree combines the characteristics of a Merkle tree (Merkle Tree) and a compressed prefix tree (Patricia Tree). Reduce storage overhead and improve query efficiency.
  • MPT Merkle Patricia Tree
  • Patricia Tree a compressed prefix tree
  • the hash value of the root node of the Merkle tree (referred to as the root hash) is stored in the block (header). Any change to the state data recorded in the Merkle tree will cause a change in the root hash. Therefore, Merkle The tree can provide a data proof function (SPV function).
  • SPV function data proof function
  • the single query mode of obtaining the complete value (that is, all fields of the state data) based on the key can only realize limited business logic, and (large) part of the business logic still needs to be implemented off-chain (Even reliability needs to be considered separately), causing problems such as development difficulties, inconsistent off-chain systems, and difficulty in upgrading.
  • the embodiment of this specification provides a method and system for implementing structured data storage and query in a blockchain system.
  • blockchain nodes can store and query data based on relational data.
  • Figure 2 For the details of reading and writing involved in the transaction execution process and block generation process, you can refer to Figure 2 and its related descriptions, and will not repeat them here.
  • Relational databases are used to store structured data.
  • Structured data is data that is logically expressed and realized by a two-dimensional table structure.
  • each row can be used to store various fields of the same entry, and each column can correspond to a field. It can be understood that, for state data represented by key-value pairs, each row of the two-dimensional table may correspond to a key of the same state data, and each column in the table may correspond to a certain field of the state data.
  • a relational database can include a transaction table, and each row of the transaction table can store various fields of the same transaction, such as the account address of the transaction initiator, the address of the destination contract account, and the transaction timestamp (indicating the generation time of the transaction) , cost information, etc.
  • Relational databases can provide efficient storage according to the structural rules of blockchain data. Relational databases can also provide efficient and flexible query functions by indexing specific fields in the blockchain data. For example, conditional queries and range queries for specific fields can be realized through indexes. Just as an example, by indexing transaction timestamps, smart contract developers can write statements that query transactions generated in a specific time period, and then implement richer business logic in smart contracts.
  • the interaction between the smart contract and the underlying relational database can be performed through an abstraction layer for data reading and writing.
  • developers can use APIs for data storage and query when writing contract codes.
  • developers are provided with many conveniences, including but not limited to: developers do not need to worry about string escaping and other trivial matters, which are automatically handled by the machine; compile-time checks ensure type safety and reduce the chance of developers making mistakes; The interface is exposed in the form of a list to prevent developers from using unimplemented functions by mistake.
  • the nodes in the client 110/block chain network 120 may include various types of computing devices, such as laptop computers, desktop computers, servers, and so on.
  • the server may be an independent server or a server group, and the server group may be centralized or distributed.
  • servers may be regional or remote.
  • the server may execute on a cloud platform.
  • the cloud platform may include one of private cloud, public cloud, hybrid cloud, community cloud, decentralized cloud, internal cloud, etc. or any combination thereof.
  • the client 110 and the blockchain node can be integrated on the same computing device.
  • the network 130 connects the various components of the system so that communication between the various components is possible.
  • Networks between parts of the system may include wired and/or wireless networks.
  • network 130 may include a cable network, a wired network, a fiber optic network, a telecommunications network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a public Switched Telephone Network (PSTN), Bluetooth Network, ZigBee Network (ZigBee), Near Field Communication (NFC), In-Device Bus, In-Device Wire, Cable Connection, etc. or any combination thereof.
  • the network connection between each two parts may adopt one of the above methods, or may adopt multiple methods. It can be understood that the network 130 and the blockchain network 120 do not have to have a clear boundary. In a more general application scenario, blockchain nodes and ordinary network nodes can be connected to the same physical network. form a blockchain network.
  • Fig. 2 is an exemplary flowchart of a blockchain transaction execution method according to some embodiments of this specification.
  • Process 200 can be executed by any blockchain node.
  • the process 200 can occur in multiple possible scenarios, for example, in the scenario of generating a new block based on one or more transactions, in the catch-up block (including executing one or more transactions based on the generation of the old block, to synchronize blockchain data) scenario.
  • the process 200 may include:
  • Step 210 acquire one or more transactions to be executed.
  • the blockchain node may generate a new block based on one or more transactions received within a period of time, and the one or more transactions need to be executed during the process of generating the new block.
  • the blockchain node In the scenario of catching up with the block, the blockchain node also needs to execute one or more transactions on which the old block is generated, wherein the blockchain node can obtain the old block from other nodes in the blockchain network 120, And obtain one or more related transactions based on the old block.
  • Step 220 execute the one or more transactions, wherein state data related to the one or more transactions is read and written using a relational database.
  • any transaction may only include reading (query) or writing (adding) relevant state data, or both reading (query) and Contains write (new/modified) related state data.
  • the state data read and the state tree data written due to execution of the same transaction may be the same or different (only part of the same or no intersection at all).
  • the execution of any transaction can also include deleting related state data from the relational database.
  • blockchain nodes simulate execution of multiple transactions received.
  • the blockchain nodes execute the multiple transactions concurrently, during which the read-write sets of the multiple transactions are generated, and based on the read-write sets, the difference between different transactions (assumed to be the first transaction and the second transaction) is judged. Whether there is a read-write conflict, if yes, abandon the formal execution of one of the first transaction and the second transaction.
  • the transaction can be regarded as the execution subject of reading and writing, which aims to indicate that reading and writing occurs due to the execution of which transaction.
  • the read-write set of a transaction refers to the set of data stored in read-write during the execution of the transaction, including the read-set and write-set.
  • the read set can contain the key of the state data read by the transaction
  • the write set can contain the key and its value of the state data written by the transaction
  • the write set can also contain a key with a delete flag to indicate that the key is deleted.
  • a read-write conflict means that the state data read by one transaction overlaps with the data written by another transaction, and it can be judged whether there is a read-write conflict based on the key in the read-write set of the two transactions.
  • the client 110 After the client 110 confirms that the initiated transaction has been abandoned (officially) executed, it can re-initiate a transaction (hereinafter referred to as transaction retry), and some of the contents of the two transactions are the same (the content that the user can perceive and hope to be successful on the chain is the same).
  • transaction retry a transaction
  • the blockchain nodes do not update the blockchain data during the simulated execution of the transaction, but update the blockchain data during the formal execution of the transaction (for example, after the consensus is passed).
  • the mechanism of simulated execution prevents blockchain nodes from reading the state data written in the current block generation process, but can only read the state data submitted in the generation process of the previous block (valid block generated after the consensus was passed).
  • relational database since the relational database satisfies the ACID characteristics of transactions, using the relational database to read and write state data related to the one or more transactions can ensure the correctness and reliability of transaction execution. It can be understood that the execution of a transaction may include a transaction responsible for reading and writing state data.
  • a transaction consists of one or more operations. Transactions must meet ACID characteristics, namely Atomicity, Consistency, Isolation and Durability.
  • Atomicity means: all operations in a transaction are either executed or not executed at all. If an error occurs during the execution of the transaction, the data should be rolled back (restored) to the state before the execution of the transaction, as if the transaction had never happened .
  • a transaction can be regarded as the execution subject of the operations contained in the transaction.
  • Consistency means: before and after the transaction, the constraints on the data will not be broken, that is, the data written to the database must comply with all preset rules, which can include data accuracy, seriality, and subsequent database can spontaneously Complete the scheduled work. For example, if you want to transfer 100 from account A to account B, you must subtract 100 from account A and add 100 to account B, and the problem of unequal increase and decrease cannot occur.
  • Isolation means that a transaction is invisible to other transactions until all the modifications involved are completed, that is, it is impossible to know the intermediate state in the process of executing the transaction while executing other transactions.
  • Persistence means that after a transaction is completed, the execution result of the transaction must be persisted. Even if the database crashes, the execution result of the committed transaction will not be lost after the database is restored.
  • isolation means that multiple concurrent operations are isolated from each other (do not interfere). Isolation is crucial in database operations. If isolation is not considered, problems such as dirty reads, non-repeatable reads, and phantom reads may occur.
  • Dirty read refers to: transaction T1 reads the uncommitted data of transaction T2, and as a result, a state rollback is performed for transaction T2, resulting in transaction T1 getting dirty data.
  • Non-repeatable reading means that after transaction T1 reads data D, data D is updated by transaction T2, resulting in inconsistent data when data D is read again during the execution of transaction T1.
  • Phantom reading means transaction A reads data according to certain conditions, during which transaction B inserts new data that meets the same search conditions, and when transaction A reads data according to the conditions again, it finds the newly inserted data of transaction B.
  • the database can provide four isolation levels from low to high: Read uncommitted, Read Committed, Repeated Read, and Serializable.
  • Read uncommitted cannot ensure that any problem will not occur
  • Read committed can ensure that dirty read problems will not occur
  • repeatable reads can ensure that dirty reads and non-repeatable reads will not occur
  • serialization can ensure that Dirty, non-repeatable reads, and phantom reads do not occur.
  • the blockchain nodes may execute the two or more transactions concurrently. For different transactions among the two or more transactions (assumed to be the first transaction and the second transaction), the blockchain node can determine whether there is a read-write conflict between the first transaction and the second transaction. If not, the two transactions are successfully executed concurrently, which can ensure the efficient execution of the transaction. If yes, perform state rollback for one of the first transaction and the second transaction, and re-execute one of the first transaction and the second transaction after the execution of the other transaction is completed. That is, reads and writes to the same state data are isolated through transaction serialization. For the read-write set of transactions and read-write conflicts, you can also refer to the relevant descriptions above.
  • transaction A and transaction B trigger the update of the balance of the same account.
  • the balance of the account is represented by amount (ie key/key).
  • amount 100.
  • the specific deduction logic is If the account balance is sufficient, 60 will be deducted, otherwise the deduction will fail. Obviously, if the isolation is not considered, it may happen that before any transaction is deducted, the account balance is found to be sufficient (that is, greater than 60), so both transaction A and transaction B subtract 60 from the account balance, causing the account balance to become negative number. If transaction A and transaction B are executed according to the isolation requirements, the blockchain nodes can execute transaction A and transaction B concurrently.
  • the blockchain node After discovering that both transaction A and transaction B trigger the update of the amount, the blockchain node can perform a state rollback for one of the transactions (maybe set it as transaction A), and execute transaction B again after transaction A is executed. In this way, when transaction B is executed again, the blockchain node will find that the account balance is insufficient, and then the deduction will fail, which will not cause the account balance to become negative.
  • Read-Your-Writes means "read what you write", which means that after a node updates a piece of data (such as the aforementioned amount), it can always access the latest value it has updated.
  • the blockchain system needs to support the SPV function, while the blockchain node stores the state data related to the one or more transactions based on the relational database, it can also store the state data related to the one or more transactions based on the Merkel
  • the tree's database stores state data associated with the one or more transactions.
  • storing generally refers to adding state data, deleting existing state data, and modifying existing state data (modifying value). That is, the dual writing of state data is realized through a relational database and a Merkle tree-based database to meet SPV requirements while providing powerful data query capabilities.
  • the blockchain nodes may also perform consensus on the execution results of the one or more transactions to generate a block. Understandably, the purpose of consensus is to generate identical and correct (valid) blocks. After the consensus is passed, each blockchain node can add the same block to the blockchain.
  • the blockchain node may also write the read-write set of the one or more transactions into a block, for example, into a block body. In this way, arbitrary data tampering will cause the consensus to fail, thus ensuring the immutability of the blockchain.
  • Fig. 3 is a block diagram of a blockchain transaction execution system according to some embodiments of this specification. As shown in FIG. 3 , the system 300 may include a transaction acquisition module 310 and a transaction execution module 320 .
  • the transaction obtaining module 310 may be used to obtain one or more transactions to be executed.
  • Transaction execution module 320 may be configured to execute the one or more transactions. Wherein, the transaction execution module 320 may use a relational database to read and write status data related to the one or more transactions.
  • the system 300 may further include a storage module as shown in FIG. 4 , which is used for data storage and query using a relational database during transaction execution. That is, the transaction execution module 320 can call the storage module to read and write state data during the execution of the transaction.
  • the function of the storage module can be further refined, that is, the storage module can be regarded as a subsystem in the system 300, which is used to implement structured data storage and query in the blockchain system 100.
  • system 300 can be included in a larger system, such as included in a block generation system, and the block generation system can also include a consensus module, which is used to verify the execution results of the one or more transactions Consensus is performed to generate blocks.
  • a consensus module which is used to verify the execution results of the one or more transactions Consensus is performed to generate blocks.
  • system and its modules shown in FIG. 3 can be implemented in various ways.
  • the system and its modules may be implemented by hardware, software, or a combination of software and hardware.
  • the hardware part can be implemented by using dedicated logic;
  • the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or specially designed hardware.
  • an appropriate instruction execution system such as a microprocessor or specially designed hardware.
  • processor control code for example on a carrier medium such as a magnetic disk, CD or DVD-ROM, such as a read-only memory (firmware ) or on a data carrier such as an optical or electronic signal carrier.
  • the system and its modules in this specification can not only be realized by hardware circuits such as very large scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc. , can also be realized by software executed by various types of processors, for example, and can also be realized by a combination of the above-mentioned hardware circuits and software (for example, firmware).
  • hardware circuits such as very large scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc.
  • programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc.
  • software for example, and can also be realized by a combination of the above-mentioned hardware circuits and software (for example, firmware).
  • the above description of the system and its modules is only for convenience of description, and does not limit this description to the scope of the illustrated embodiments. It can be understood that for those skilled in the art, after understanding the principle of the system, it is possible to combine various modules arbitrarily, or form a subsystem to connect with other modules without departing from this principle.
  • the transaction acquisition module 310 and the transaction execution module 320 may be different modules in one system, or one module may realize the functions of these two modules. Such deformations are within the protection scope of this specification.
  • the possible beneficial effects of the embodiments of this specification include but are not limited to: (1) Using a relational database to store structured blockchain data can provide efficient and flexible data storage and query functions; (2) The relational database meets The ACID characteristics of transactions can ensure the correctness and reliability of transaction execution; (3) transaction concurrency based on transaction isolation can reduce transaction retries and provide support for Read-Your-Writes semantics; (4) through Relational databases and databases based on Merkle trees implement double writing of state data, which can meet SPV requirements while providing powerful data query capabilities. It should be noted that different embodiments may have different beneficial effects. In different embodiments, the possible beneficial effects may be any one or a combination of the above, or any other possible beneficial effects.
  • aspects of the embodiments of this specification can be illustrated and described by several patentable categories or situations, including any new and useful process, machine, product or combination of substances, or Any new and useful improvements to them.
  • various aspects of the embodiments of this specification may be completely executed by hardware, may be completely executed by software (including firmware, resident software, microcode, etc.), or may be executed by a combination of hardware and software.
  • the above hardware or software may be referred to as “block”, “module”, “engine”, “unit”, “component” or “system”.
  • aspects of the embodiments of this specification may be embodied as a computer product on one or more computer-readable media, the product including computer-readable program code.
  • a computer storage medium may contain a propagated data signal embodying a computer program code, for example, in baseband or as part of a carrier wave.
  • the propagated signal may have various manifestations, including electromagnetic form, optical form, etc., or a suitable combination.
  • a computer storage medium may be any computer-readable medium, other than a computer-readable storage medium, that can be used to communicate, propagate, or transfer a program for use by being coupled to an instruction execution system, apparatus, or device.
  • Program code residing on a computer storage medium may be transmitted over any suitable medium, including radio, electrical cable, fiber optic cable, RF, or the like, or combinations of any of the foregoing.
  • the computer program codes required for the operation of each part of the embodiments of this specification can be written in any one or more programming languages, including object-oriented programming languages such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB.NET , Python, etc., conventional programming languages such as C language, VisualBasic, Fortran2003, Perl, COBOL2002, PHP, ABAP, dynamic programming languages such as Python, Ruby and Groovy, or other programming languages.
  • the program code may run entirely on the user's computer, or as a stand-alone software package, or run partly on the user's computer and partly on a remote computer, or entirely on the remote computer or processing device.
  • the remote computer can be connected to the user computer through any form of network, such as a local area network (LAN) or wide area network (WAN), or to an external computer (such as through the Internet), or in a cloud computing environment, or as a service Use software as a service (SaaS).
  • LAN local area network
  • WAN wide area network
  • SaaS service Use software as a service

Abstract

The embodiments of the present description disclose a method and system for implementing structured data storage and queries in a blockchain system. The method comprises: during a transaction execution process, storing and querying data by using a relational database.

Description

在区块链系统中实现结构化数据存储和查询的方法和系统Method and system for implementing structured data storage and query in blockchain system
本申请要求于2022年02月28日提交中国专利局、申请号为202210185170.6、发明名称为“在区块链系统中实现结构化数据存储和查询的方法和系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202210185170.6 and the title of the invention "Method and System for Realizing Structured Data Storage and Query in Blockchain System" submitted to the China Patent Office on February 28, 2022. The entire contents of which are incorporated by reference in this application.
技术领域technical field
本说明书涉及信息技术领域,特别涉及在区块链系统中实现结构化数据存储和查询的方法和系统。This specification relates to the field of information technology, in particular to methods and systems for implementing structured data storage and query in blockchain systems.
背景技术Background technique
区块链系统中,智能合约是业务逻辑的载体。一些区块链系统仅提供k-v(key-value,键值对)查询接口,即在智能合约中仅支持通过提供key来查询与该key关联的value的单一数据查询方式,缺乏更加高效灵活的数据查询方式(如条件查询、范围查询、跨表的联合查询等),导致业务逻辑的开发受到各种限制。In the blockchain system, smart contracts are the carrier of business logic. Some blockchain systems only provide a k-v (key-value, key-value pair) query interface, that is, in a smart contract, only a single data query method that provides a key to query the value associated with the key is supported, lacking more efficient and flexible data Query methods (such as conditional query, range query, joint query across tables, etc.), lead to various restrictions on the development of business logic.
因此,希望提供一种数据查询能力更强的区块链存储方案。Therefore, it is hoped to provide a blockchain storage solution with stronger data query capabilities.
发明内容Contents of the invention
本说明书实施例之一提供一种在区块链系统中实现结构化数据存储和查询的方法,所述方法包括:在区块链交易执行过程中使用关系型数据库进行数据存储和查询。One of the embodiments of this specification provides a method for implementing structured data storage and query in a blockchain system, the method comprising: using a relational database for data storage and query during the execution of a blockchain transaction.
本说明书实施例之一提供一种在区块链系统中实现结构化数据存储和查询的系统,所述实现结构化数据存储和查询的系统用于:在区块链交易执行过程中使用关系型数据库进行数据存储和查询。One of the embodiments of this specification provides a system for implementing structured data storage and query in a blockchain system, and the system for implementing structured data storage and query is used to: use relational Database for data storage and query.
本说明书实施例之一提供一种在区块链系统中实现结构化数据存储和查询的装置。所述装置包括处理器和存储设备,所述存储设备用于存储指令,当所述处理器执行指令时,实现如本说明书任一实施例所述的在区块链系统中实现结构化数据存储和查询的方法。One of the embodiments of this specification provides a device for implementing structured data storage and query in a blockchain system. The device includes a processor and a storage device, the storage device is used to store instructions, and when the processor executes the instructions, it realizes the structured data storage in the blockchain system as described in any embodiment of this specification and query methods.
本说明书实施例之一提供一种区块链交易执行方法。所述方法包括:获取待执行的一个或多个交易;执行所述一个或多个交易,其中,使用关系型数据库对与所述一个或多个交易相关的状态数据进行读写。One of the embodiments of this specification provides a blockchain transaction execution method. The method includes: obtaining one or more transactions to be executed; executing the one or more transactions, wherein state data related to the one or more transactions is read and written using a relational database.
本说明书实施例之一提供一种区块链交易执行系统。所述系统包括:交易获取模块,用于获取待执行的一个或多个交易;交易执行模块,用于执行所述一个或多个交易,其中,使用关系型数据库对与所述一个或多个交易相关的状态数据进行读写。One of the embodiments of this specification provides a blockchain transaction execution system. The system includes: a transaction acquisition module, used to acquire one or more transactions to be executed; a transaction execution module, used to execute the one or more transactions, wherein a relational database is used to pair with the one or more Transaction-related state data is read and written.
本说明书实施例之一提供一种区块链交易执行装置。所述装置包括处理器和存储设备,所述存储设备用于存储指令,当所述处理器执行指令时,实现如本说明书任一实施例所述的区块链交易执行方法。One of the embodiments of this specification provides a blockchain transaction execution device. The apparatus includes a processor and a storage device, the storage device is used to store instructions, and when the processor executes the instructions, the blockchain transaction execution method described in any embodiment of this specification is implemented.
附图说明Description of drawings
图1是根据本说明书一些实施例所示的区块链系统的应用场景示意图;FIG. 1 is a schematic diagram of an application scenario of a blockchain system according to some embodiments of this specification;
图2是根据本说明书一些实施例所示的区块链交易执行方法的示例性流程图;Fig. 2 is an exemplary flow chart of a blockchain transaction execution method according to some embodiments of this specification;
图3是根据本说明书一些实施例所示的区块链交易执行系统的示例性模块图;Fig. 3 is an exemplary block diagram of a blockchain transaction execution system according to some embodiments of this specification;
图4是根据本说明书一些实施例所示的实现结构化数据存储和查询的存储模块的示意图。Fig. 4 is a schematic diagram of a storage module for implementing structured data storage and query according to some embodiments of the present specification.
具体实施方式Detailed ways
为了更清楚地说明本说明书实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单的介绍。显而易见地,下面描述中的附图仅仅是本说明书的一些示例或实施例,对于本领域的普通技术人 员来讲,在不付出创造性劳动的前提下,还可以根据这些附图将本说明书应用于其它类似情景。除非从语言环境中显而易见或另做说明,图中相同标号代表相同结构或操作。In order to more clearly illustrate the technical solutions of the embodiments of the present specification, the following briefly introduces the drawings that need to be used in the description of the embodiments. Apparently, the accompanying drawings in the following description are only some examples or embodiments of this specification, and those skilled in the art can also apply this specification to other similar scenarios. Unless otherwise apparent from context or otherwise indicated, like reference numerals in the figures represent like structures or operations.
应当理解,本文使用的“系统”、“装置”、“单元”和/或“模组”是用于区分不同级别的不同组件、元件、部件、部分或装配的一种方法。然而,如果其他词语可实现相同的目的,则可通过其他表达来替换所述词语。It should be understood that "system", "device", "unit" and/or "module" as used herein is a method for distinguishing different components, elements, components, parts or assemblies of different levels. However, the words may be replaced by other expressions if other words can achieve the same purpose.
如本说明书中所示,除非上下文明确提示例外情形,“一”、“一个”、“一种”和/或“该”等词并非特指单数,也可包括复数。一般说来,术语“包括”与“包含”仅提示包括已明确标识的步骤和元素,而这些步骤和元素不构成一个排它性的罗列,方法或者设备也可能包含其它的步骤或元素。As indicated in this specification, words such as "a", "an", "an" and/or "the" are not specific to the singular and may include the plural unless the context clearly indicates an exception. Generally speaking, the terms "comprising" and "comprising" only suggest the inclusion of clearly identified steps and elements, and these steps and elements do not constitute an exclusive list, and the method or device may also contain other steps or elements.
本说明书中使用了流程图用来说明根据本说明书的实施例的系统所执行的操作。应当理解的是,前面或后面操作不一定按照顺序来精确地执行。相反,可以按照倒序或同时处理各个步骤。同时,也可以将其他操作添加到这些过程中,或从这些过程移除某一步或数步操作。The flowchart is used in this specification to illustrate the operations performed by the system according to the embodiment of this specification. It should be understood that the preceding or following operations are not necessarily performed in the exact order. Instead, various steps may be processed in reverse order or simultaneously. At the same time, other operations can be added to these procedures, or a certain step or steps can be removed from these procedures.
图1是根据本说明书一些实施例所示的区块链系统的应用场景示意图。如图1所示,区块链系统100可以包括用户端110、区块链网络120和网络130。Fig. 1 is a schematic diagram of an application scenario of a blockchain system according to some embodiments of this specification. As shown in FIG. 1 , the blockchain system 100 may include a client 110 , a blockchain network 120 and a network 130 .
用户端110可以是使用区块链服务的终端,其可以通过网络130链接至区块链网络120中的某一节点。用户端110可以发起交易,即生成交易并将生成的交易发送至区块链网络120,以使交易在区块链网络120被广播。The client 110 may be a terminal using blockchain services, which may be linked to a certain node in the blockchain network 120 through the network 130 . The client 110 can initiate a transaction, that is, generate a transaction and send the generated transaction to the blockchain network 120 , so that the transaction is broadcast on the blockchain network 120 .
需要说明的是,本说明书中出现的交易特指区块链交易,用于触发区块链系统100中的各类事件。例如,事件可以包括新节点的加入、节点的退出、转账、数据存证等中的一种或多种。在一些实施例中,存证的数据可以包括医疗信息、电子合同、电子凭据、电子订单、数字指纹等中的一种或多种。It should be noted that the transactions appearing in this specification specifically refer to blockchain transactions, which are used to trigger various events in the blockchain system 100 . For example, the event may include one or more of the joining of a new node, the exit of a node, transfer, data deposit, etc. In some embodiments, the certified data may include one or more of medical information, electronic contracts, electronic credentials, electronic orders, digital fingerprints, and the like.
智能合约(简称合约)是运行在区块链上的模块化、可重用、自动执行的脚本。部署合约时合约代码(如字节码)被存储到各区块链节点,每个(份)合约对应一个合约地址。当预定的条件发生时,可产生一笔交易指向合约地址的交易,区块链网络120中的区块链节点都可执行合约代码,并将执行结果写入区块链数据。即,智能合约中的代码可以通过交易触发执行,也可称作交易的执行。仅作为示例,转账交易可以触发对转账双方的账户余额的更新,数据存证交易可以触发将要存证的数据写入区块链数据,数据查询交易可以触发对区块链数据的读取,等等。Smart contracts (referred to as contracts) are modular, reusable, and automatically executed scripts that run on the blockchain. When the contract is deployed, the contract code (such as bytecode) is stored in each blockchain node, and each (part) contract corresponds to a contract address. When a predetermined condition occurs, a transaction pointing to the contract address can be generated, and all blockchain nodes in the blockchain network 120 can execute the contract code and write the execution result into the blockchain data. That is, the code in the smart contract can be triggered by a transaction, which can also be called the execution of the transaction. As an example only, a transfer transaction can trigger the update of the account balance of both parties to the transfer, a data deposit transaction can trigger the data to be deposited into the blockchain data, a data query transaction can trigger the reading of the blockchain data, etc. wait.
区块链网络120可以包括多个区块链节点,例如,图1中的节点120-1、节点120-2、节点120-3、...、节点120-n。任一区块链节点接收到用户端110发起的交易后,可以将交易转发给其他节点,以使交易在区块链网络120被广播。区块链节点可以收集在区块链网络120中广播的交易并基于一个或多个交易生成区块。其中,生成有效区块的前提条件可以包括:参与共识的区块链节点对生成区块所基于的交易的执行结果达成一致(共识通过)。另外,区块链节点也可以发起交易。The blockchain network 120 may include multiple blockchain nodes, for example, node 120-1, node 120-2, node 120-3, . . . , node 120-n in FIG. 1 . After any blockchain node receives the transaction initiated by the client 110 , it can forward the transaction to other nodes, so that the transaction is broadcasted on the blockchain network 120 . A blockchain node may collect transactions broadcast in the blockchain network 120 and generate a block based on one or more transactions. Among them, the prerequisite for generating a valid block may include: the blockchain nodes participating in the consensus reach a consensus on the execution result of the transaction on which the block is generated (consensus is passed). In addition, blockchain nodes can also initiate transactions.
基于共识机制,区块链网络120中各个区块链节点存储的区块链数据可以保持一致。Based on the consensus mechanism, the blockchain data stored by each blockchain node in the blockchain network 120 can be consistent.
区块链数据可以包括区块数据和状态数据。Blockchain data can include block data and state data.
其中,区块数据包括多个区块按产生时间顺序链接而成的数据链(即区块链),区块数据具有不可修改的特性。区块可以包括区块头和区块体两部分,其中,区块头中可写入区块的关键信息(或称为概要信息),区块体中可以写入区块的详细信息。例如,区块头中可以写入区块时间戳、(本区块的)区块哈希值、父区块(前一区块)的区块哈希值、区块高度、默克尔树的根哈希等,其中,区块时间戳可反映区块的产生时间,区块哈希值可基于区块头中的内容计算得到,区块高度可反映本区块是第几个生成的区块。区块体中可以写入交易列表、交易收据列表等,交易列表包括生成区块所基于的一个或多个 交易(可统称为区块中的交易),交易收据列表包括区块中的一个或多个交易的收据。Among them, the block data includes a data chain (that is, a block chain) in which multiple blocks are linked in order of generation time, and the block data has the property of being unmodifiable. A block may include two parts: a block header and a block body, where the key information (or summary information) of the block can be written in the block header, and the detailed information of the block can be written in the block body. For example, block timestamp, block hash value (of this block), block hash value of parent block (previous block), block height, and Merkle tree can be written in the block header. Root hash, etc., where the block timestamp can reflect the generation time of the block, the block hash value can be calculated based on the content in the block header, and the block height can reflect which block is generated . A transaction list, transaction receipt list, etc. can be written in the block body. The transaction list includes one or more transactions based on which the block is generated (which can be collectively referred to as transactions in the block). The transaction receipt list includes one or more transactions in the block. Receipts for multiple transactions.
可以将交易以键值对(k-v)形式写入交易列表中,key(键/关键字,可简写为k)为交易ID,value(值,可简写为v)为交易的各个字段。仅作为示例,交易的各个字段可以包括交易发起方的账户地址、交易时间戳、交易发起方愿意为交易支付的金额、调用的智能合约的账户地址、调用的智能合约中的函数的名称、提供给函数的输入等。Transactions can be written into the transaction list in the form of key-value pairs (k-v), key (key/keyword, can be abbreviated as k) is the transaction ID, and value (value, can be abbreviated as v) is each field of the transaction. As an example only, the various fields of the transaction may include the account address of the transaction initiator, the transaction timestamp, the amount the transaction initiator is willing to pay for the transaction, the account address of the calling smart contract, the name of the function in the calling smart contract, the provided Input to the function, etc.
状态数据为支持增删查改的区块链数据,可用键值对(k-v)来存储状态数据,k为状态数据的标识(名称/ID),v为状态数据的值(如数值)。例如,状态数据可以包括所有区块链账户的状态(账户状态)组成的世界状态。账户状态可以k-v形式存储,k为账户标识(也可称为账户地址),v为账户状态的值。账户状态可以包括账户余额,对于智能合约关联的合约账户,账户状态还可以包括智能合约代码的哈希值、智能合约的账户存储的状态。State data is blockchain data that supports addition, deletion, query, and modification. Key-value pairs (k-v) can be used to store state data, k is the identification (name/ID) of state data, and v is the value (such as value) of state data. For example, state data may include the world state composed of the state of all blockchain accounts (account state). The account status can be stored in the form of k-v, where k is the account identifier (also called the account address), and v is the value of the account status. The account status can include the account balance. For the contract account associated with the smart contract, the account status can also include the hash value of the smart contract code and the status stored in the account of the smart contract.
每个智能合约(账户)可具有对应的存储,相应地,状态数据还可以包括智能合约的存储。智能合约的存储可包括合约代码(如字节码)和账户存储两部分。其中,账户存储可保存合约变量。合约变量可以k-v形式存储,k为变量名,v为变量值。具体地,合约变量的k可以是资产账户的名称(地址),合约变量的v可以是资产账户的余额。进一步地,余额可以包括不同资产类型对应的k-v,k可以是资产类型(如,人民币、美元等),v可以是该资产类型的余额。逻辑上,键值对形式的状态数据(多个键值对)可以被组织成默克尔(Merkle)树的形式。底层数据库可基于Merkle树构建,该数据库可称作基于默克尔树的数据库。Each smart contract (account) can have a corresponding storage, and correspondingly, the state data can also include the storage of the smart contract. The storage of smart contracts can include contract code (such as bytecode) and account storage. Among them, account storage can save contract variables. Contract variables can be stored in the form of k-v, where k is the variable name and v is the variable value. Specifically, the k of the contract variable can be the name (address) of the asset account, and the v of the contract variable can be the balance of the asset account. Further, the balance may include k-v corresponding to different asset types, k may be an asset type (such as RMB, USD, etc.), and v may be the balance of the asset type. Logically, state data in the form of key-value pairs (multiple key-value pairs) can be organized into the form of a Merkle tree. The underlying database can be constructed based on a Merkle tree, and this database can be called a Merkle tree-based database.
默克尔树是一种哈希二叉树,它是一种用于快速归纳和校验大规模数据完整性的数据结构。SPV(Simplified Payment Verification,简单支付验证)充分利用了Merkle树的这个特点,在保存较少的区块链数据的情况下,例如,仅保存区块头而不保存区块体时,区块链网络120中的SPV节点(也称为轻量节点/轻客户端,可以是用户端110)也可以进行相关验证,如验证交易是否存在、交易是否属于某个区块等。A Merkle tree is a hash binary tree, which is a data structure for quickly summarizing and verifying the integrity of large-scale data. SPV (Simplified Payment Verification, simple payment verification) makes full use of this feature of the Merkle tree. In the case of saving less blockchain data, for example, when only the block header is saved but not the block body, the blockchain network The SPV node in 120 (also called light node/light client, which can be the client 110) can also perform relevant verification, such as verifying whether the transaction exists, whether the transaction belongs to a certain block, etc.
在一些实施例中,用于记录状态数据的默克尔树可以包括状态树、交易树、收据树、存储树等中的一种或多种。其中,状态树用于保存世界状态。每个区块可对应一棵交易树,每个区块的交易树用于保存区块中的所有交易。每个区块可对应一棵收据树,每个区块的收据树用于保存区块中的所有交易的执行结果。每个智能合约可对应一棵存储树,存储树用于保存智能合约的账户存储。In some embodiments, the Merkle tree used to record state data may include one or more of a state tree, a transaction tree, a receipt tree, a storage tree, and the like. Among them, the state tree is used to save the state of the world. Each block can correspond to a transaction tree, and the transaction tree of each block is used to save all transactions in the block. Each block can correspond to a receipt tree, and the receipt tree of each block is used to save the execution results of all transactions in the block. Each smart contract can correspond to a storage tree, which is used to save the account storage of the smart contract.
在一些实施例中,用于记录状态数据的默克尔树可以包括MPT(Merkle Patricia Tree)树,MPT树结合了默克尔树(Merkle Tree)和压缩前缀树(Patricia Tree)的特点,可以减小存储开销以及提高查询效率。In some embodiments, the Merkle tree used to record state data may include an MPT (Merkle Patricia Tree) tree, and the MPT tree combines the characteristics of a Merkle tree (Merkle Tree) and a compressed prefix tree (Patricia Tree). Reduce storage overhead and improve query efficiency.
默克尔树的根节点的哈希值(简称根哈希)保存于区块(头)中,对默克尔树记录的任意状态数据的改动会引起根哈希的变化,因此默克尔树可以提供数据证明功能(SPV功能)。对于依赖k-v接口进行数据查询的区块链系统,基于key获取完整value(即状态数据的所有字段)的单一查询模式仅能实现有限的业务逻辑,(大)部分业务逻辑还需要在链下实现(甚至需要另外考虑可靠性),造成开发困难、链下系统不统一、升级困难等问题。The hash value of the root node of the Merkle tree (referred to as the root hash) is stored in the block (header). Any change to the state data recorded in the Merkle tree will cause a change in the root hash. Therefore, Merkle The tree can provide a data proof function (SPV function). For blockchain systems that rely on the k-v interface for data query, the single query mode of obtaining the complete value (that is, all fields of the state data) based on the key can only realize limited business logic, and (large) part of the business logic still needs to be implemented off-chain (Even reliability needs to be considered separately), causing problems such as development difficulties, inconsistent off-chain systems, and difficulty in upgrading.
为此,本说明书实施例提供了在区块链系统中实现结构化数据存储和查询的方法和系统。在交易执行过程中,区块链节点可基于关系型数据进行数据存储和查询。关于交易执行过程以及区块生成过程中涉及的读写细节,可以参考图2及其相关描述,这里不再赘述。To this end, the embodiment of this specification provides a method and system for implementing structured data storage and query in a blockchain system. During transaction execution, blockchain nodes can store and query data based on relational data. For the details of reading and writing involved in the transaction execution process and block generation process, you can refer to Figure 2 and its related descriptions, and will not repeat them here.
关系型数据库用于存储结构化数据。结构化数据是由二维表结构来逻辑表达和实现的数据。二维表 中,每一行可用于存储同一条目的各个字段,每一列可对应一个字段。可以理解,对于可用键值对表示的状态数据,二维表的每一行可对应同一状态数据的key,表中的每一列可对应状态数据的某个字段。以交易为例,关系型数据库可以包括交易表,交易表的每一行可存储同一交易的各个字段,如交易发起方的账户地址、目的合约账户的地址、交易时间戳(指示交易的产生时间)、费用信息等。Relational databases are used to store structured data. Structured data is data that is logically expressed and realized by a two-dimensional table structure. In a two-dimensional table, each row can be used to store various fields of the same entry, and each column can correspond to a field. It can be understood that, for state data represented by key-value pairs, each row of the two-dimensional table may correspond to a key of the same state data, and each column in the table may correspond to a certain field of the state data. Taking transactions as an example, a relational database can include a transaction table, and each row of the transaction table can store various fields of the same transaction, such as the account address of the transaction initiator, the address of the destination contract account, and the transaction timestamp (indicating the generation time of the transaction) , cost information, etc.
结构化的特性使得数据易于存储和查询。关系型数据库能够按照区块链数据的结构规律提供高效的存储。关系型数据库也能通过对区块链数据当中的特定字段建立索引,提供高效灵活的查询功能,例如,通过索引实现针对特定字段的条件查询、范围查询等。仅作为示例,通过对交易时间戳建立索引,智能合约的开发人员可以编写查询产生于特定时间段的交易的语句,进而可在智能合约中实现更丰富的业务逻辑。Structured features make data easy to store and query. Relational databases can provide efficient storage according to the structural rules of blockchain data. Relational databases can also provide efficient and flexible query functions by indexing specific fields in the blockchain data. For example, conditional queries and range queries for specific fields can be realized through indexes. Just as an example, by indexing transaction timestamps, smart contract developers can write statements that query transactions generated in a specific time period, and then implement richer business logic in smart contracts.
在一些实施例中,智能合约与底层的关系型数据库间的交互可通过数据读写的抽象层进行。具体而言,开发人员在编写合约代码时能够以API的方式进行数据存储和查询。如此,为开发人员提供了诸多便利,包括但不限于:开发人员无需担心字符串转义等琐事,交由机器自动处理;编译时检查保证了类型的安全,减少开发人员出错的机会;以白名单的方式暴露接口,避免开发人员错误使用未实现的功能。In some embodiments, the interaction between the smart contract and the underlying relational database can be performed through an abstraction layer for data reading and writing. Specifically, developers can use APIs for data storage and query when writing contract codes. In this way, developers are provided with many conveniences, including but not limited to: developers do not need to worry about string escaping and other trivial matters, which are automatically handled by the machine; compile-time checks ensure type safety and reduce the chance of developers making mistakes; The interface is exposed in the form of a list to prevent developers from using unimplemented functions by mistake.
在一些实施例中,用户端110/区块链网络120中的节点可以包括各类计算设备,如膝上型计算机、台式计算机、服务器等等。其中,服务器可以是独立的服务器或者服务器组,该服务器组可以是集中式的或者分布式的。在一些实施例中,服务器可以是区域的或者远程的。在一些实施例中,服务器可在云平台上执行。例如,该云平台可包括私有云、公共云、混合云、社区云、分散式云、内部云等中的一种或其任意组合。在一些实施例中,用户端110和区块链节点可以集成于同一计算设备。In some embodiments, the nodes in the client 110/block chain network 120 may include various types of computing devices, such as laptop computers, desktop computers, servers, and so on. Wherein, the server may be an independent server or a server group, and the server group may be centralized or distributed. In some embodiments, servers may be regional or remote. In some embodiments, the server may execute on a cloud platform. For example, the cloud platform may include one of private cloud, public cloud, hybrid cloud, community cloud, decentralized cloud, internal cloud, etc. or any combination thereof. In some embodiments, the client 110 and the blockchain node can be integrated on the same computing device.
网络130连接系统的各组成部分,使得各部分之间可以进行通讯。在系统中各部分之间的网络可以包括有线网络和/或无线网络。例如,网络130可以包括电缆网络、有线网络、光纤网络、电信网络、内部网络、互联网、局域网络(LAN)、广域网络(WAN)、无线局域网络(WLAN)、城域网(MAN)、公共交换电话网络(PSTN)、蓝牙网络、紫蜂网络(ZigBee)、近场通信(NFC)、设备内总线、设备内线路、线缆连接等或其任意组合。每两个部分之间的网络连接可以是采用上述一种方式,也可以是采取多种方式。可以理解,网络130与区块链网络120不必具有明显的分界,在更一般的应用场景中,区块链节点与普通网络节点可以共同接入同一物理网络中,其中的区块链节点在逻辑上构成区块链网络。The network 130 connects the various components of the system so that communication between the various components is possible. Networks between parts of the system may include wired and/or wireless networks. For example, network 130 may include a cable network, a wired network, a fiber optic network, a telecommunications network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a public Switched Telephone Network (PSTN), Bluetooth Network, ZigBee Network (ZigBee), Near Field Communication (NFC), In-Device Bus, In-Device Wire, Cable Connection, etc. or any combination thereof. The network connection between each two parts may adopt one of the above methods, or may adopt multiple methods. It can be understood that the network 130 and the blockchain network 120 do not have to have a clear boundary. In a more general application scenario, blockchain nodes and ordinary network nodes can be connected to the same physical network. form a blockchain network.
图2是根据本说明书一些实施例所示的区块链交易执行方法的示例性流程图。流程200可以由任一区块链节点执行。流程200可以发生在多个可能的场景下,例如,在基于一个或多个交易生成新区块的场景下,在追赶区块(包含执行生成旧区块所基于的一个或多个交易,以同步区块链数据)的场景下。如图2所示,流程200可以包括:Fig. 2 is an exemplary flowchart of a blockchain transaction execution method according to some embodiments of this specification. Process 200 can be executed by any blockchain node. The process 200 can occur in multiple possible scenarios, for example, in the scenario of generating a new block based on one or more transactions, in the catch-up block (including executing one or more transactions based on the generation of the old block, to synchronize blockchain data) scenario. As shown in Figure 2, the process 200 may include:
步骤210,获取待执行的一个或多个交易。Step 210, acquire one or more transactions to be executed.
在生成新区块的场景下,区块链节点可以基于一段时间内接收到的一个或多个交易生成新区块,在生成新区块的过程中需要执行所述一个或多个交易。In the scenario of generating a new block, the blockchain node may generate a new block based on one or more transactions received within a period of time, and the one or more transactions need to be executed during the process of generating the new block.
在追赶区块的场景下,区块链节点也需要执行生成旧区块所基于的一个或多个交易,其中,区块链节点可以从区块链网络120中的其他节点获取旧区块,并基于旧区块获得相关的一个或多个交易。In the scenario of catching up with the block, the blockchain node also needs to execute one or more transactions on which the old block is generated, wherein the blockchain node can obtain the old block from other nodes in the blockchain network 120, And obtain one or more related transactions based on the old block.
步骤220,执行所述一个或多个交易,其中,使用关系型数据库对与所述一个或多个交易相关的状态数据进行读写。 Step 220, execute the one or more transactions, wherein state data related to the one or more transactions is read and written using a relational database.
可以理解,任一交易的执行可以只包含对相关状态数据的读取(查询)或者只包含写入(新增)相关的状态数据,也可以既包含对相关状态数据的读取(查询)又包含写入(新增/更改)相关的状态数 据。其中,因执行同一交易而读取的状态数据和写入的状态树数据可以相同,也可以不相同(仅部分相同或完全没有交集)。另外,任一交易的执行也可以包含从关系型数据库中删除相关的状态数据。It can be understood that the execution of any transaction may only include reading (query) or writing (adding) relevant state data, or both reading (query) and Contains write (new/modified) related state data. Wherein, the state data read and the state tree data written due to execution of the same transaction may be the same or different (only part of the same or no intersection at all). In addition, the execution of any transaction can also include deleting related state data from the relational database.
在一些区块链系统中,区块链节点会对接收到的多个交易进行模拟执行。模拟执行过程中,区块链节点并发执行所述多个交易,期间生成所述多个交易的读写集,并基于读写集判断不同交易(假设为第一交易和第二交易)之间是否存在读写冲突,若是,则放弃所述第一交易和所述第二交易之一的正式执行。为了便于描述,可以将交易视为读写的执行主体,旨在表明读写因执行何交易而发生。交易的读写集是指执行交易过程中读写存储的数据集合,包括读集和写集。读集可以包含交易读取的状态数据的key,写集可以包含交易写入的状态数据的key及其value,写集还可以包含携带删除标记的key以指示删除该key。读写冲突是指一个交易读取的状态数据与另一个交易写入的数据重叠,可根据两个交易的读写集中的key判断读写冲突是否存在。In some blockchain systems, blockchain nodes simulate execution of multiple transactions received. During the simulation execution process, the blockchain nodes execute the multiple transactions concurrently, during which the read-write sets of the multiple transactions are generated, and based on the read-write sets, the difference between different transactions (assumed to be the first transaction and the second transaction) is judged. Whether there is a read-write conflict, if yes, abandon the formal execution of one of the first transaction and the second transaction. For ease of description, the transaction can be regarded as the execution subject of reading and writing, which aims to indicate that reading and writing occurs due to the execution of which transaction. The read-write set of a transaction refers to the set of data stored in read-write during the execution of the transaction, including the read-set and write-set. The read set can contain the key of the state data read by the transaction, the write set can contain the key and its value of the state data written by the transaction, and the write set can also contain a key with a delete flag to indicate that the key is deleted. A read-write conflict means that the state data read by one transaction overlaps with the data written by another transaction, and it can be judged whether there is a read-write conflict based on the key in the read-write set of the two transactions.
用户端110确认发起的交易被放弃(正式)执行后,可以重新发起一个交易(以下简交易重试),这两个交易的部分内容相同(用户可以感知且希望上链成功的内容相同)。可以理解,区块链节点不会在交易的模拟执行过程中更新区块链数据,而是在交易的正式执行过程中(例如,共识通过后)更新区块链数据。模拟执行的机制使得区块链节点无法读取当前区块生成过程中写入的状态数据,只能读取上一区块(共识通过后生成的有效区块)生成过程中提交的状态数据。After the client 110 confirms that the initiated transaction has been abandoned (officially) executed, it can re-initiate a transaction (hereinafter referred to as transaction retry), and some of the contents of the two transactions are the same (the content that the user can perceive and hope to be successful on the chain is the same). It can be understood that the blockchain nodes do not update the blockchain data during the simulated execution of the transaction, but update the blockchain data during the formal execution of the transaction (for example, after the consensus is passed). The mechanism of simulated execution prevents blockchain nodes from reading the state data written in the current block generation process, but can only read the state data submitted in the generation process of the previous block (valid block generated after the consensus was passed).
相比之下,由于关系型数据库满足事务的ACID特性,使用关系型数据库对与所述一个或多个交易相关的状态数据进行读写,可以保证交易执行的正确性和可靠性。可以理解,一个交易的执行可包含一个负责状态数据的读写的事务。In contrast, since the relational database satisfies the ACID characteristics of transactions, using the relational database to read and write state data related to the one or more transactions can ensure the correctness and reliability of transaction execution. It can be understood that the execution of a transaction may include a transaction responsible for reading and writing state data.
下面对事务及其ACID特性进行解释。Transactions and their ACID properties are explained below.
一个事务由一个或多个操作组成。事务须满足ACID特性,即原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)。A transaction consists of one or more operations. Transactions must meet ACID characteristics, namely Atomicity, Consistency, Isolation and Durability.
原子性是指:一个事务中的所有操作,要么全部执行要么全部不执行,事务执行过程中若发生错误,数据应当回滚(恢复)到事务执行前的状态,如同这个事务从未发生过一样。为了便于描述,可以将事务作为事务所包含的操作的执行主体。Atomicity means: all operations in a transaction are either executed or not executed at all. If an error occurs during the execution of the transaction, the data should be rolled back (restored) to the state before the execution of the transaction, as if the transaction had never happened . For ease of description, a transaction can be regarded as the execution subject of the operations contained in the transaction.
一致性是指:事务开始前和结束后,对数据的约束不会被破坏,即写入数据库的数据必须符合所有的预设规则,其中可包含数据的精准度、串联性以及后续数据库能自发完成预定工作。例如,要从A账户转100到B账户,必须是从A账户中减去100并往B账户中加100,而不能出现增减数额不相等的问题。Consistency means: before and after the transaction, the constraints on the data will not be broken, that is, the data written to the database must comply with all preset rules, which can include data accuracy, seriality, and subsequent database can spontaneously Complete the scheduled work. For example, if you want to transfer 100 from account A to account B, you must subtract 100 from account A and add 100 to account B, and the problem of unequal increase and decrease cannot occur.
隔离性是指:一个事务在涉及的修改全部完成之前,对其他事务来说是不可见的,即在执行其他事务是无法获知执行该事务过程中的中间状态。Isolation means that a transaction is invisible to other transactions until all the modifications involved are completed, that is, it is impossible to know the intermediate state in the process of executing the transaction while executing other transactions.
持久性是指:一个事务完成后,事务的执行结果必须是持久化保存的,即使数据库发生崩溃,在数据库回复后,已提交的事务的执行结果仍然不会丢失。Persistence means that after a transaction is completed, the execution result of the transaction must be persisted. Even if the database crashes, the execution result of the committed transaction will not be lost after the database is restored.
其中,隔离性意味着多个并发操作之间是互相隔离(不不干扰)的。隔离性在数据库操作中至关重要,如果不考虑隔离性,可能会出现脏读、不可重复读、幻读的问题。Among them, isolation means that multiple concurrent operations are isolated from each other (do not interfere). Isolation is crucial in database operations. If isolation is not considered, problems such as dirty reads, non-repeatable reads, and phantom reads may occur.
脏读是指:事务T1读取了事务T2未提交的数据,结果针对事务T2执行了状态回滚,导致事务T1拿到了脏数据。Dirty read refers to: transaction T1 reads the uncommitted data of transaction T2, and as a result, a state rollback is performed for transaction T2, resulting in transaction T1 getting dirty data.
不可重复读是指:事务T1读取数据D后,数据D被事务T2更新了,导致执行事务T1过程中再次读取数据D时发现数据前后不一致。Non-repeatable reading means that after transaction T1 reads data D, data D is updated by transaction T2, resulting in inconsistent data when data D is read again during the execution of transaction T1.
幻读是指:事务A按照一定条件进行数据读取,期间事务B插入了满足相同搜索条件的新数据,事务A再次按照该条件进行数据读取时,发现了事务B新插入的数据。Phantom reading means: transaction A reads data according to certain conditions, during which transaction B inserts new data that meets the same search conditions, and when transaction A reads data according to the conditions again, it finds the newly inserted data of transaction B.
针对以上问题,数据库可提供读未提交(Read uncommitted)、读提交(Read Committed)、可重复读(Repeated Read)、串行化(Serializable)这四种由低到高的隔离级别。其中,读未提交无法确保任一问题不会出现,读提交(Read Committed)能够确保脏读问题不会出现,可重复读能够确保脏读和不可重复读问题不会出现,串行化能够确保脏、不可重复读和幻读问题不会出现。In response to the above problems, the database can provide four isolation levels from low to high: Read uncommitted, Read Committed, Repeated Read, and Serializable. Among them, read uncommitted cannot ensure that any problem will not occur, read committed (Read Committed) can ensure that dirty read problems will not occur, repeatable reads can ensure that dirty reads and non-repeatable reads will not occur, and serialization can ensure that Dirty, non-repeatable reads, and phantom reads do not occur.
在一些实施例中,当所述一个或多个交易包括两个或以上交易时,区块链节点可以并发执行所述两个或以上交易。对于所述两个或以上交易中的不同交易(假设为第一交易和第二交易),区块链节点可以判断第一交易和第二交易是否存在读写冲突。若否,则这两个交易并发执行成功,可以保证交易的高效执行。若是,则针对所述第一交易和所述第二交易之一执行状态回滚,并在另一交易执行完毕后重新执行所述第一交易和所述第二交易之一。即,通过交易串行隔离对相同状态数据的读写。关于交易的读写集以及读写冲突,还可以参考前文的相关描述。In some embodiments, when the one or more transactions include two or more transactions, the blockchain nodes may execute the two or more transactions concurrently. For different transactions among the two or more transactions (assumed to be the first transaction and the second transaction), the blockchain node can determine whether there is a read-write conflict between the first transaction and the second transaction. If not, the two transactions are successfully executed concurrently, which can ensure the efficient execution of the transaction. If yes, perform state rollback for one of the first transaction and the second transaction, and re-execute one of the first transaction and the second transaction after the execution of the other transaction is completed. That is, reads and writes to the same state data are isolated through transaction serialization. For the read-write set of transactions and read-write conflicts, you can also refer to the relevant descriptions above.
仅作为示例,假设交易A和交易B触发对同一账户余额的更新,该账户的余额用amount(即键/key)表示,在执行交易A和交易B之前amount=100,具体的扣款逻辑是若账户余额充足则扣款60,否则扣款失败。显然,若不考虑隔离性,有可能出现:任一交易扣款前,都发现账户余额充足(即大于60),于是交易A和交易B都从账户余额中减去60,导致账户余额变成负数。若按隔离性要求执行交易A和交易B,则区块链节点可以并发执行交易A和交易B。在发现交易A和交易B都触发对amount的更新后,区块链节点可针对其中一个交易(不妨设为交易A)执行状态回滚,并在交易A执行完毕后再执行一次交易B。如此,再次执行交易B时,区块链节点就会发现账户余额不足,进而扣款失败,不会导致账户余额变成负数。As an example only, assume that transaction A and transaction B trigger the update of the balance of the same account. The balance of the account is represented by amount (ie key/key). Before executing transaction A and transaction B, amount=100. The specific deduction logic is If the account balance is sufficient, 60 will be deducted, otherwise the deduction will fail. Obviously, if the isolation is not considered, it may happen that before any transaction is deducted, the account balance is found to be sufficient (that is, greater than 60), so both transaction A and transaction B subtract 60 from the account balance, causing the account balance to become negative number. If transaction A and transaction B are executed according to the isolation requirements, the blockchain nodes can execute transaction A and transaction B concurrently. After discovering that both transaction A and transaction B trigger the update of the amount, the blockchain node can perform a state rollback for one of the transactions (maybe set it as transaction A), and execute transaction B again after transaction A is executed. In this way, when transaction B is executed again, the blockchain node will find that the account balance is insufficient, and then the deduction will fail, which will not cause the account balance to become negative.
可以看出,相较于模拟执行,基于事务的隔离性进行交易并发,可以减少交易重试,且可以为Read-Your-Writes语义提供支持。Read-Your-Writes意为“读己之所写”,是指节点更新一个数据(如前述amount)后总是能访问到自身更新过的最新值。It can be seen that compared with simulated execution, transaction concurrency based on transaction isolation can reduce transaction retries and provide support for Read-Your-Writes semantics. Read-Your-Writes means "read what you write", which means that after a node updates a piece of data (such as the aforementioned amount), it can always access the latest value it has updated.
在一些实施例中,若区块链系统需要支持SPV功能,则区块链节点在基于关系型数据库对与所述一个或多个交易相关的状态数据进行存储的同时,还可以基于默克尔树的数据库对与所述一个或多个交易进行相关的状态数据进行存储。其中,存储泛指状态数据的新增、删除已有状态数据、修改已有状态数据(修改value)。即,通过关系型数据库以及基于默克尔树的数据库实现状态数据的双写,以在提供强大数据查询能力的同时满足SPV需求。In some embodiments, if the blockchain system needs to support the SPV function, while the blockchain node stores the state data related to the one or more transactions based on the relational database, it can also store the state data related to the one or more transactions based on the Merkel The tree's database stores state data associated with the one or more transactions. Among them, storing generally refers to adding state data, deleting existing state data, and modifying existing state data (modifying value). That is, the dual writing of state data is realized through a relational database and a Merkle tree-based database to meet SPV requirements while providing powerful data query capabilities.
在生成新区块的场景下,区块链节点还可以对所述一个或多个交易的执行结果进行共识以生成区块。可以理解,共识的目的是生成相同且正确(有效)的区块。共识通过后,各区块链节点可将相同的区块添加入区块链。In the scenario of generating a new block, the blockchain nodes may also perform consensus on the execution results of the one or more transactions to generate a block. Understandably, the purpose of consensus is to generate identical and correct (valid) blocks. After the consensus is passed, each blockchain node can add the same block to the blockchain.
在一些实施例中,区块链节点还可以将所述一个或多个交易的读写集写入区块中,例如,写入区块体中。如此,任意的数据篡改都会导致共识无法通过,从而保证了区块链的不可篡改性。In some embodiments, the blockchain node may also write the read-write set of the one or more transactions into a block, for example, into a block body. In this way, arbitrary data tampering will cause the consensus to fail, thus ensuring the immutability of the blockchain.
应当注意的是,上述有关流程的描述仅仅是为了示例和说明,而不限定本说明书的适用范围。对于本领域技术人员来说,在本说明书的指导下可以对流程进行各种修正和改变。然而,这些修正和改变仍在本说明书的范围之内。It should be noted that, the above descriptions about the process are only for illustration and description, and do not limit the scope of application of this specification. For those skilled in the art, various modifications and changes can be made to the flow under the guidance of this specification. However, such modifications and changes are still within the scope of this specification.
图3是根据本说明书一些实施例所示的区块链交易执行系统的模块图。如图3所示,系统300可以包括交易获取模块310和交易执行模块320。Fig. 3 is a block diagram of a blockchain transaction execution system according to some embodiments of this specification. As shown in FIG. 3 , the system 300 may include a transaction acquisition module 310 and a transaction execution module 320 .
交易获取模块310可以用于获取待执行的一个或多个交易。The transaction obtaining module 310 may be used to obtain one or more transactions to be executed.
交易执行模块320可以用于执行所述一个或多个交易。其中,交易执行模块320可以使用关系型数据库对与所述一个或多个交易相关的状态数据进行读写。 Transaction execution module 320 may be configured to execute the one or more transactions. Wherein, the transaction execution module 320 may use a relational database to read and write status data related to the one or more transactions.
在一些实施例中,系统300还可以包括如图4所示的存储模块,该存储模块用于在交易执行过程中使用关系型数据库进行数据存储和查询。即,交易执行模块320在执行交易过程中可以调用存储模块实现对状态数据的读写。存储模块的功能还可以进一步细化,即可将存储模块视为系统300中的子系统,该子系统用于在区块链系统100中实现结构化数据存储和查询。In some embodiments, the system 300 may further include a storage module as shown in FIG. 4 , which is used for data storage and query using a relational database during transaction execution. That is, the transaction execution module 320 can call the storage module to read and write state data during the execution of the transaction. The function of the storage module can be further refined, that is, the storage module can be regarded as a subsystem in the system 300, which is used to implement structured data storage and query in the blockchain system 100.
可以理解,系统300可以包含在更大的系统中,如包含在区块生成系统中,该区块生成系统还可以包括共识模块,该共识模块用于对所述一个或多个交易的执行结果进行共识以生成区块。It can be understood that the system 300 can be included in a larger system, such as included in a block generation system, and the block generation system can also include a consensus module, which is used to verify the execution results of the one or more transactions Consensus is performed to generate blocks.
关于系统300及其模块的更多细节,可以参考图2及其相关描述。For more details about the system 300 and its modules, refer to FIG. 2 and its related descriptions.
应当理解,图3所示的系统及其模块可以利用各种方式来实现。例如,在一些实施例中,系统及其模块可以通过硬件、软件或者软件和硬件的结合来实现。其中,硬件部分可以利用专用逻辑来实现;软件部分则可以存储在存储器中,由适当的指令执行系统,例如微处理器或者专用设计硬件来执行。本领域技术人员可以理解上述的方法和系统可以使用计算机可执行指令和/或包含在处理器控制代码中来实现,例如在诸如磁盘、CD或DVD-ROM的载体介质、诸如只读存储器(固件)的可编程的存储器或者诸如光学或电子信号载体的数据载体上提供了这样的代码。本说明书的系统及其模块不仅可以有诸如超大规模集成电路或门阵列、诸如逻辑芯片、晶体管等的半导体、或者诸如现场可编程门阵列、可编程逻辑设备等的可编程硬件设备的硬件电路实现,也可以用例如由各种类型的处理器所执行的软件实现,还可以由上述硬件电路和软件的结合(例如,固件)来实现。It should be understood that the system and its modules shown in FIG. 3 can be implemented in various ways. For example, in some embodiments, the system and its modules may be implemented by hardware, software, or a combination of software and hardware. Wherein, the hardware part can be implemented by using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or specially designed hardware. Those skilled in the art will appreciate that the methods and systems described above can be implemented using computer-executable instructions and/or contained in processor control code, for example on a carrier medium such as a magnetic disk, CD or DVD-ROM, such as a read-only memory (firmware ) or on a data carrier such as an optical or electronic signal carrier. The system and its modules in this specification can not only be realized by hardware circuits such as very large scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc. , can also be realized by software executed by various types of processors, for example, and can also be realized by a combination of the above-mentioned hardware circuits and software (for example, firmware).
需要注意的是,以上对于系统及其模块的描述,仅为描述方便,并不能把本说明书限制在所举实施例范围之内。可以理解,对于本领域的技术人员来说,在了解系统的原理后,可能在不背离这一原理的情况下,对各个模块进行任意组合,或者构成子系统与其他模块连接。例如,在一些实施例中,交易获取模块310和交易执行模块320可以是一个系统中的不同模块,也可以是一个模块实现这两个模块的功能。诸如此类的变形,均在本说明书的保护范围之内。It should be noted that the above description of the system and its modules is only for convenience of description, and does not limit this description to the scope of the illustrated embodiments. It can be understood that for those skilled in the art, after understanding the principle of the system, it is possible to combine various modules arbitrarily, or form a subsystem to connect with other modules without departing from this principle. For example, in some embodiments, the transaction acquisition module 310 and the transaction execution module 320 may be different modules in one system, or one module may realize the functions of these two modules. Such deformations are within the protection scope of this specification.
本说明书实施例可能带来的有益效果包括但不限于:(1)使用关系型数据库来存储结构化的区块链数据,可以提供高效灵活的数据存储和查询功能;(2)关系型数据库满足事务的ACID特性,可以保证交易执行的正确性和可靠性;(3)基于事务的隔离性进行交易并发,可以减少交易重试,且可以为Read-Your-Writes语义提供支持;(4)通过关系型数据库以及基于默克尔树的数据库实现状态数据的双写,可以在提供强大数据查询能力的同时满足SPV需求。需要说明的是,不同实施例可能产生的有益效果不同,在不同的实施例里,可能产生的有益效果可以是以上任意一种或几种的组合,也可以是其他任何可能获得的有益效果。The possible beneficial effects of the embodiments of this specification include but are not limited to: (1) Using a relational database to store structured blockchain data can provide efficient and flexible data storage and query functions; (2) The relational database meets The ACID characteristics of transactions can ensure the correctness and reliability of transaction execution; (3) transaction concurrency based on transaction isolation can reduce transaction retries and provide support for Read-Your-Writes semantics; (4) through Relational databases and databases based on Merkle trees implement double writing of state data, which can meet SPV requirements while providing powerful data query capabilities. It should be noted that different embodiments may have different beneficial effects. In different embodiments, the possible beneficial effects may be any one or a combination of the above, or any other possible beneficial effects.
上文已对基本概念做了描述,显然,对于本领域技术人员来说,上述详细披露仅仅作为示例,而并不构成对本说明书实施例的限定。虽然此处并没有明确说明,本领域技术人员可能会对本说明书实施例进行各种修改、改进和修正。该类修改、改进和修正在本说明书实施例中被建议,所以该类修改、改进、修正仍属于本说明书示范实施例的精神和范围。The basic concepts have been described above. Obviously, for those skilled in the art, the above detailed disclosure is only an example, and does not constitute a limitation to the embodiment of this specification. Although not explicitly stated here, those skilled in the art may make various modifications, improvements and amendments to the embodiments of this specification. Such modifications, improvements and corrections are suggested in the embodiments of this specification, so such modifications, improvements and corrections still belong to the spirit and scope of the exemplary embodiments of this specification.
同时,本说明书使用了特定词语来描述本说明书的实施例。如“一个实施例”、“一实施例”、和/或“一些实施例”意指与本说明书至少一个实施例相关的某一特征、结构或特点。因此,应强调并注意的是,本说明书中在不同位置两次或多次提及的“一实施例”或“一个实施例”或“一个替代性实施 例”并不一定是指同一实施例。此外,本说明书的一个或多个实施例中的某些特征、结构或特点可以进行适当的组合。Meanwhile, this specification uses specific words to describe the embodiments of this specification. For example, "one embodiment", "an embodiment", and/or "some embodiments" refer to a certain feature, structure or characteristic related to at least one embodiment of this specification. Therefore, it should be emphasized and noted that two or more references to "an embodiment" or "an embodiment" or "an alternative embodiment" in different places in this specification do not necessarily refer to the same embodiment . In addition, certain features, structures or characteristics in one or more embodiments of this specification may be properly combined.
此外,本领域技术人员可以理解,本说明书实施例的各方面可以通过若干具有可专利性的种类或情况进行说明和描述,包括任何新的和有用的工序、机器、产品或物质的组合,或对他们的任何新的和有用的改进。相应地,本说明书实施例的各个方面可以完全由硬件执行、可以完全由软件(包括固件、常驻软件、微码等)执行、也可以由硬件和软件组合执行。以上硬件或软件均可被称为“数据块”、“模块”、“引擎”、“单元”、“组件”或“系统”。此外,本说明书实施例的各方面可能表现为位于一个或多个计算机可读介质中的计算机产品,该产品包括计算机可读程序编码。In addition, those skilled in the art will understand that all aspects of the embodiments of this specification can be illustrated and described by several patentable categories or situations, including any new and useful process, machine, product or combination of substances, or Any new and useful improvements to them. Correspondingly, various aspects of the embodiments of this specification may be completely executed by hardware, may be completely executed by software (including firmware, resident software, microcode, etc.), or may be executed by a combination of hardware and software. The above hardware or software may be referred to as "block", "module", "engine", "unit", "component" or "system". In addition, aspects of the embodiments of this specification may be embodied as a computer product on one or more computer-readable media, the product including computer-readable program code.
计算机存储介质可能包含一个内含有计算机程序编码的传播数据信号,例如在基带上或作为载波的一部分。该传播信号可能有多种表现形式,包括电磁形式、光形式等,或合适的组合形式。计算机存储介质可以是除计算机可读存储介质之外的任何计算机可读介质,该介质可以通过连接至一个指令执行系统、装置或设备以实现通讯、传播或传输供使用的程序。位于计算机存储介质上的程序编码可以通过任何合适的介质进行传播,包括无线电、电缆、光纤电缆、RF、或类似介质,或任何上述介质的组合。A computer storage medium may contain a propagated data signal embodying a computer program code, for example, in baseband or as part of a carrier wave. The propagated signal may have various manifestations, including electromagnetic form, optical form, etc., or a suitable combination. A computer storage medium may be any computer-readable medium, other than a computer-readable storage medium, that can be used to communicate, propagate, or transfer a program for use by being coupled to an instruction execution system, apparatus, or device. Program code residing on a computer storage medium may be transmitted over any suitable medium, including radio, electrical cable, fiber optic cable, RF, or the like, or combinations of any of the foregoing.
本说明书实施例各部分操作所需的计算机程序编码可以用任意一种或多种程序语言编写,包括面向对象编程语言如Java、Scala、Smalltalk、Eiffel、JADE、Emerald、C++、C#、VB.NET、Python等,常规程序化编程语言如C语言、VisualBasic、Fortran2003、Perl、COBOL2002、PHP、ABAP,动态编程语言如Python、Ruby和Groovy,或其他编程语言等。该程序编码可以完全在用户计算机上运行、或作为独立的软件包在用户计算机上运行、或部分在用户计算机上运行部分在远程计算机运行、或完全在远程计算机或处理设备上运行。在后种情况下,远程计算机可以通过任何网络形式与用户计算机连接,比如局域网(LAN)或广域网(WAN),或连接至外部计算机(例如通过因特网),或在云计算环境中,或作为服务使用如软件即服务(SaaS)。The computer program codes required for the operation of each part of the embodiments of this specification can be written in any one or more programming languages, including object-oriented programming languages such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB.NET , Python, etc., conventional programming languages such as C language, VisualBasic, Fortran2003, Perl, COBOL2002, PHP, ABAP, dynamic programming languages such as Python, Ruby and Groovy, or other programming languages. The program code may run entirely on the user's computer, or as a stand-alone software package, or run partly on the user's computer and partly on a remote computer, or entirely on the remote computer or processing device. In the latter case, the remote computer can be connected to the user computer through any form of network, such as a local area network (LAN) or wide area network (WAN), or to an external computer (such as through the Internet), or in a cloud computing environment, or as a service Use software as a service (SaaS).
此外,除非权利要求中明确说明,本说明书实施例所述处理元素和序列的顺序、数字字母的使用、或其他名称的使用,并非用于限定本说明书实施例流程和方法的顺序。尽管上述披露中通过各种示例讨论了一些目前认为有用的发明实施例,但应当理解的是,该类细节仅起到说明的目的,附加的权利要求并不仅限于披露的实施例,相反,权利要求旨在覆盖所有符合本说明书实施例实质和范围的修正和等价组合。例如,虽然以上所描述的系统组件可以通过硬件设备实现,但是也可以只通过软件的解决方案得以实现,如在现有的处理设备或移动设备上安装所描述的系统。In addition, unless clearly stated in the claims, the sequence of processing elements and sequences, the use of numbers and letters, or the use of other names in the embodiments of this specification are not used to limit the sequence of the processes and methods of the embodiments of this specification. While the foregoing disclosure has discussed by way of various examples some embodiments of the invention that are presently believed to be useful, it should be understood that such detail is for illustrative purposes only and that the appended claims are not limited to the disclosed embodiments, but rather, the claims The claims are intended to cover all modifications and equivalent combinations that fall within the spirit and scope of the embodiments of this specification. For example, while the system components described above may be implemented as hardware devices, they may also be implemented as a software-only solution, such as installing the described system on an existing processing device or mobile device.
同理,应当注意的是,为了简化本说明书实施例披露的表述,从而帮助对一个或多个发明实施例的理解,前文对本说明书实施例的描述中,有时会将多种特征归并至一个实施例、附图或对其的描述中。但是,这种披露方法并不意味着本说明书实施例对象所需要的特征比权利要求中提及的特征多。实际上,实施例的特征要少于上述披露的单个实施例的全部特征。Similarly, it should be noted that, in order to simplify the description of the disclosure of the embodiments of this specification, so as to facilitate the understanding of one or more embodiments of the invention, in the foregoing descriptions of the embodiments of this specification, sometimes multiple features are combined into one implementation examples, drawings or descriptions thereof. However, this method of disclosure does not imply that the embodiments of the present specification require more features than those recited in the claims. Indeed, embodiment features are less than all features of a single foregoing disclosed embodiment.
针对本说明书引用的每个专利、专利申请、专利申请公开物和其他材料,如文章、书籍、说明书、出版物、文档等,特此将其全部内容并入本说明书作为参考。与本说明书内容不一致或产生冲突的申请历史文件除外,对本说明书权利要求最广范围有限制的文件(当前或之后附加于本说明书中的)也除外。需要说明的是,如果本说明书附属材料中的描述、定义、和/或术语的使用与本说明书所述内容有不一致或冲突的地方,以本说明书的描述、定义和/或术语的使用为准。Each patent, patent application, patent application publication, and other material, such as article, book, specification, publication, document, etc., cited in this specification is hereby incorporated by reference in its entirety. Application history documents that are inconsistent with or conflict with the content of this specification are excluded, and documents (currently or later appended to this specification) that limit the broadest scope of the claims of this specification are also excluded. It should be noted that if there is any inconsistency or conflict between the descriptions, definitions, and/or terms used in the accompanying materials of this manual and the contents of this manual, the descriptions, definitions and/or terms used in this manual shall prevail .
最后,应当理解的是,本说明书中所述实施例仅用以说明本说明书实施例的原则。其他的变形也可能属于本说明书实施例的范围。因此,作为示例而非限制,本说明书实施例的替代配置可视为与本说明 书的教导一致。相应地,本说明书的实施例不仅限于本说明书明确介绍和描述的实施例。Finally, it should be understood that the embodiments described in this specification are only used to illustrate the principles of the embodiments of this specification. Other modifications may also fall within the scope of the embodiments of this specification. Therefore, by way of illustration and not limitation, alternative configurations of the embodiments of this specification may be considered consistent with the teachings of this specification. Accordingly, the embodiments of this specification are not limited to the embodiments explicitly introduced and described in this specification.

Claims (6)

  1. 一种在区块链系统中实现结构化数据存储和查询的方法,其中,包括:A method for implementing structured data storage and query in a blockchain system, including:
    在区块链交易执行过程中使用关系型数据库进行数据存储和查询。A relational database is used for data storage and query during the execution of blockchain transactions.
  2. 如权利要求1所述的方法,其中,还包括:The method of claim 1, further comprising:
    在区块生成过程中将区块链交易的读写集写入区块。The read-write set of blockchain transactions is written to the block during block generation.
  3. 如权利要求1或2所述的方法,其中,在区块生成过程中还使用基于默克尔树的数据库进行数据存储。The method according to claim 1 or 2, wherein a Merkle tree-based database is also used for data storage during the block generation process.
  4. 如权利要求1所述的方法,其中,所述在区块链交易执行过程中使用关系型数据库进行数据存储和查询,包括:The method according to claim 1, wherein the use of a relational database for data storage and query during the execution of blockchain transactions includes:
    对于并发执行的两个或以上区块链交易中的第一区块链交易和第二区块链交易,判断所述第一区块链交易和所述第二区块链交易之间是否存在读写冲突,若是,则针对所述第一区块链交易和所述第二区块链交易之一执行状态回滚,并在另一区块链交易执行完毕后重新执行所述第一区块链交易和所述第二区块链交易之一。For the first block chain transaction and the second block chain transaction in two or more block chain transactions executed concurrently, it is judged whether there is Read and write conflicts, if so, execute state rollback for one of the first block chain transaction and the second block chain transaction, and re-execute the first block chain transaction after the execution of the other block chain transaction one of the block chain transaction and said second block chain transaction.
  5. 一种在区块链系统中实现结构化数据存储和查询的系统,其中,所述实现结构化数据存储和查询的系统用于:A system for implementing structured data storage and query in a block chain system, wherein the system for implementing structured data storage and query is used for:
    在区块链交易执行过程中使用关系型数据库进行数据存储和查询。A relational database is used for data storage and query during the execution of blockchain transactions.
  6. 一种在区块链系统中实现结构化数据存储和查询的装置,其中,包括处理器和存储设备,所述存储设备用于存储指令,当所述处理器执行指令时,实现如权利要求1~4中任一项所述的方法。A device for implementing structured data storage and query in a blockchain system, including a processor and a storage device, the storage device is used to store instructions, and when the processor executes the instructions, the implementation of claim 1 The method described in any one of ~4.
PCT/CN2022/135638 2022-02-28 2022-11-30 Method and system for implementing structured data storage and queries in blockchain system WO2023160095A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210185170.6 2022-02-28
CN202210185170.6A CN114564500A (en) 2022-02-28 2022-02-28 Method and system for implementing structured data storage and query in block chain system

Publications (1)

Publication Number Publication Date
WO2023160095A1 true WO2023160095A1 (en) 2023-08-31

Family

ID=81715695

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135638 WO2023160095A1 (en) 2022-02-28 2022-11-30 Method and system for implementing structured data storage and queries in blockchain system

Country Status (2)

Country Link
CN (1) CN114564500A (en)
WO (1) WO2023160095A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114564500A (en) * 2022-02-28 2022-05-31 蚂蚁区块链科技(上海)有限公司 Method and system for implementing structured data storage and query in block chain system
CN115220924A (en) * 2022-07-29 2022-10-21 蚂蚁区块链科技(上海)有限公司 Transaction conflict detection method in blockchain system and blockchain node

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110912937A (en) * 2019-12-23 2020-03-24 杭州中科先进技术研究院有限公司 Block chain-based digital certificate storage platform and certificate storage method
CN111241590A (en) * 2018-11-29 2020-06-05 华为技术有限公司 Database system, node and method
CN111242620A (en) * 2020-01-15 2020-06-05 阳光易购(湖南)科技有限公司 Data caching and querying method of block chain transaction system, terminal and storage medium
US20200409952A1 (en) * 2019-06-25 2020-12-31 International Business Machines Corporation Sql processing engine for blockchain ledger
CN113688186A (en) * 2021-08-25 2021-11-23 工银科技有限公司 Intelligent contract execution method, engine and block link point
CN113743950A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Method for performing transactions in a blockchain, blockchain node and blockchain
CN114564500A (en) * 2022-02-28 2022-05-31 蚂蚁区块链科技(上海)有限公司 Method and system for implementing structured data storage and query in block chain system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111241590A (en) * 2018-11-29 2020-06-05 华为技术有限公司 Database system, node and method
US20200409952A1 (en) * 2019-06-25 2020-12-31 International Business Machines Corporation Sql processing engine for blockchain ledger
CN110912937A (en) * 2019-12-23 2020-03-24 杭州中科先进技术研究院有限公司 Block chain-based digital certificate storage platform and certificate storage method
CN111242620A (en) * 2020-01-15 2020-06-05 阳光易购(湖南)科技有限公司 Data caching and querying method of block chain transaction system, terminal and storage medium
CN113688186A (en) * 2021-08-25 2021-11-23 工银科技有限公司 Intelligent contract execution method, engine and block link point
CN113743950A (en) * 2021-11-04 2021-12-03 支付宝(杭州)信息技术有限公司 Method for performing transactions in a blockchain, blockchain node and blockchain
CN114564500A (en) * 2022-02-28 2022-05-31 蚂蚁区块链科技(上海)有限公司 Method and system for implementing structured data storage and query in block chain system

Also Published As

Publication number Publication date
CN114564500A (en) 2022-05-31

Similar Documents

Publication Publication Date Title
US11138180B2 (en) Transaction protocol for reading database values
US11003689B2 (en) Distributed database transaction protocol
WO2023160095A1 (en) Method and system for implementing structured data storage and queries in blockchain system
US9652519B2 (en) Replicating data across multiple copies of a table in a database system
US10019536B2 (en) Snapshot-consistent, in-memory graph instances in a multi-user database
CN109086388B (en) Block chain data storage method, device, equipment and medium
US8938430B2 (en) Intelligent data archiving
US10754854B2 (en) Consistent query of local indexes
US9576038B1 (en) Consistent query of local indexes
US10866865B1 (en) Storage system journal entry redaction
US9396218B2 (en) Database insert with deferred materialization
US11875178B2 (en) Using multiple blockchains for applying transactions to a set of persistent data objects in persistent storage systems
WO2020192663A1 (en) Data management method and related device
WO2023124242A1 (en) Transaction execution method and apparatus, device, and storage medium
CN109358817B (en) Method, device and system for copying data
US20240143386A1 (en) Using multiple blockchains for applying transactions to a set of persistent data objects in persistent storage systems
CN117421302A (en) Data processing method and related equipment
CN116501812A (en) DDL statement execution method and device

Legal Events

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

Ref document number: 22928355

Country of ref document: EP

Kind code of ref document: A1