Blockchain data storage and calling method and system
By separating storage blocks, transactions, and business data in the blockchain data storage system and using transaction and business identifier codes for indexing, the query timeout and server pressure issues caused by the MPT tree-based storage structure under high-concurrency transactions are resolved, achieving efficient data retrieval and fast response.
Patent Information
- Application Number
- CN202210725847.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-23
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-06-23
AI Technical Summary
The existing MPT tree-based blockchain data storage structure leads to query timeouts and increased server load under high-concurrency transaction conditions, making it unsuitable for high-concurrency transaction execution. Furthermore, it consumes a significant amount of memory when smart contracts retrieve or query transaction data.
Block data is stored in three separate units: block storage unit, transaction original business data storage unit, and business data storage unit. Transaction and business data are directly stored and queried using transaction identifiers and business identifiers as indexes, thus avoiding the problems caused by the MPT tree-style data storage structure.
It effectively solves the problems of query timeout and high concurrency, reduces the memory usage of smart contracts, and improves the data retrieval speed and the response speed of the blockchain network.
Smart Images

Figure CN115238303B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain data storage technology, and in particular to a blockchain data storage and retrieval method and system. Background Technology
[0002] Existing blockchain networks largely use MPT tree structures for data storage. In practical applications, as massive amounts of transaction data are stored, the depth of the MPT tree data storage structure increases, leading to timeout issues when smart contracts retrieve or query transaction data. Furthermore, as the depth increases, smart contracts need to temporarily store the query path of the MPT tree, resulting in a large amount of memory usage and increasing the server's operating pressure.
[0003] Secondly, the MPT tree-based data storage structure cannot handle the data storage requirements of high-concurrency transactions. In the case of high-concurrency transactions, multiple transactions will have different execution orders, resulting in different MPT tree forms. This leads to differences in the public ledger data among the nodes in the blockchain. Therefore, the blockchain data storage structure using the MPT tree format cannot adapt to high-concurrency transaction execution. Summary of the Invention
[0004] The purpose of this invention is to provide a blockchain data storage and retrieval method and apparatus, aiming to solve the aforementioned problems. The specific technical solution is as follows:
[0005] In a first aspect of the present invention, a blockchain data storage system is provided, the apparatus comprising:
[0006] A block storage unit is used to store and retrieve block data generated by the blockchain network, wherein the block data includes block height and transaction identifier code;
[0007] The transaction raw business data storage unit is connected to the block storage unit and is used to store the raw transaction data corresponding to the business identifier code in the block data. The raw transaction data is directly stored in the transaction raw business data storage unit as list data.
[0008] A business data storage unit is connected to the original business data storage unit for storing business data, which is business-related data extracted from the original transaction data.
[0009] In a second aspect of the present invention, a blockchain data storage method is provided, the method being applicable to any node server in a blockchain network, wherein the node server is equipped with the blockchain data storage system, the method comprising:
[0010] Obtain the set of transactions to be executed distributed by the master node. The set of transactions to be executed includes multiple transaction data. The transaction data includes a transaction identifier code and a business identifier code. The transaction identifier code is used to distinguish multiple transactions occurring in the blockchain network. The business identifier code is used to distinguish business processing or transactions in the upper-layer business system.
[0011] Multiple threads execute multiple transaction data simultaneously, obtaining the execution result data corresponding to each transaction data. A transaction data and its corresponding execution result data are recorded as a transaction original data.
[0012] Extract the transaction identifier code from each transaction's raw data, and store each transaction's raw data in the transaction's raw business data storage unit according to the order of its corresponding transaction identifier code.
[0013] Extract the business data and execution result data from the raw data of each transaction, wherein the business data includes a business identification code;
[0014] Each business data and its corresponding execution result data are stored in the business data storage unit according to the order of the business identifier codes in each business data.
[0015] Collect transaction identifier codes corresponding to multiple transaction data in the transaction set to be executed, generate block data based on the transaction identifier codes, and record the block data in the blockchain public ledger.
[0016] In a third aspect of the present invention, a blockchain data retrieval method is provided, applicable to multiple blockchain smart contracts set on a blockchain node server, the method comprising:
[0017] The smart contract executes a block data query operation based on business parameters, including the transaction identifier code to be queried;
[0018] The query invocation operation includes:
[0019] The smart contract finds the corresponding index in the block storage unit based on the transaction identifier code;
[0020] The smart contract finds the corresponding original transaction data in the original business data storage unit of the transaction according to the index, and sends the original transaction data into the smart contract to continue executing the contract code until the execution result corresponding to the smart contract is output.
[0021] Alternatively, the smart contract extracts a business identifier code from the original transaction data, finds the corresponding business data and execution result data in the business data storage unit based on the business identifier code, and sends the corresponding business data and execution result data into the smart contract to continue executing the contract code until the execution result corresponding to the smart contract is output.
[0022] The present invention has at least the following beneficial effects: Because the data generated by blockchain business is stored in three parts during data storage—a block storage unit for storing block data, a transaction original business data storage unit for storing original transaction data, and a business data storage unit for storing business data—and the transaction original business data storage unit and the business data storage unit use direct storage with transaction identifiers and business identifiers as indexes, when a smart contract runs on a blockchain node, the contract can directly find the corresponding original transaction data and business data through the transaction identifier and business identifier. This effectively avoids the response timeout and inapplicability to high concurrency issues caused by using an MPT tree-like data storage structure. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0024] Figure 1 This is a diagram of the original transaction data structure proposed in an embodiment of the present invention;
[0025] Figure 2 This is a schematic diagram of a blockchain network structure proposed in an optional embodiment of the present invention;
[0026] Figure 3 This is a blockchain data storage system proposed in another embodiment of the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0028] It should be noted that similar reference numerals or letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0029] Example 1
[0030] like Figure 3 As shown, this embodiment provides a blockchain data storage system, the device comprising:
[0031] A block storage unit is used to store and retrieve block data generated by the blockchain network. The block data includes block height and transaction identifier code. The transaction identifier code is used to characterize the unique code of a transaction generated in the blockchain network, so that the corresponding original transaction data can be found in its lower-level storage unit - the transaction original business data storage unit. The block data is the index and hash evidence of the original transaction data in the blockchain public ledger. The hash evidence can be understood as the hash value corresponding to the transaction original business data being part of the block data.
[0032] The transaction raw business data storage unit is connected to the block storage unit and is used to store the raw transaction data corresponding to the business identifier code in the block data. The raw transaction data is directly stored in the transaction raw business data storage unit as list data.
[0033] A business data storage unit is connected to the original business data storage unit for storing business data, which is business-related data extracted from the original transaction data.
[0034] To facilitate understanding of the storage system, such as Figure 1 and 2The image shows a complete set of raw transaction data. The business data can be understood as the business data submitted by the customer and received by the upper-layer business system. The business system generates a business identifier ID, which is a unique code in the upper-layer business system and cannot be applied to the blockchain network.
[0035] Secondly, in the blockchain network, all business transactions are considered transactions. Therefore, when a node receives business data sent by the upper-layer business system, it will determine the type of business and generate a transaction identifier ID to represent the uniqueness of the blockchain transaction. Then, it will send the ID to the corresponding voting node for voting to obtain voting information. Multiple signatures will be added along the way to verify its validity. Finally, the original transaction data will be generated and packaged and distributed to various nodes in the blockchain network through the master node.
[0036] After receiving the original transaction data, each node will classify and store it. Specifically, the business data will be separated from the original transaction data and stored in the business data storage unit, the original transaction data will be stored in the business data storage unit, the hash value of the original transaction data will be calculated, and the block data containing the hash value and the corresponding transaction identifier ID will be stored in the block storage unit.
[0037] Example 2
[0038] This embodiment provides a blockchain data storage method, applicable to any node server in a blockchain network, wherein the node server is equipped with the blockchain data storage system, and the method includes:
[0039] Step S1. The node server obtains the set of transactions to be executed distributed by the master node. The set of transactions to be executed includes multiple transaction data. The transaction data includes a transaction identifier code and a business identifier code. The transaction identifier code is used to distinguish multiple transactions occurring in the blockchain network. The business identifier code is used to distinguish business processing or transactions in the upper-layer business system.
[0040] Step S2. The node server can execute multiple transaction data simultaneously using multiple threads to obtain the execution result data corresponding to each transaction data. A transaction data and its corresponding execution result data are recorded as a transaction raw data. Since the data is directly stored in the corresponding storage unit instead of the MPT tree storage structure, it can be executed simultaneously using multiple threads, thereby meeting the data storage requirements of high-concurrency blockchain transactions.
[0041] Step S3. Extract the transaction identifier code from each transaction's original data, and store each transaction's original data in the transaction's original business data storage unit according to the order of its corresponding transaction identifier code, thereby completing the storage of the original transaction data. This data can be used for verification by other nodes in the blockchain network in the later stage, that is, querying by transaction identifier.
[0042] Step S4. Extract the business data and execution result data from the original data of each transaction, wherein the business data includes a business identification code;
[0043] Step S5. Store each business data and its corresponding execution result data in the business data storage unit according to the order of the business identifier codes in each business data, thereby completing the storage of business data and the execution result of the corresponding business. This data can be used by the upper-layer business system of the local node to query directly according to the business identifier code, without querying through the blockchain network.
[0044] Step S6. Collect transaction identifier codes corresponding to multiple transaction data in the transaction set to be executed, generate block data according to the transaction identifier codes, and record the block data in the blockchain public ledger;
[0045] The specific operation of generating block data based on the transaction identifier code is as follows: retrieve the original transaction data corresponding to the transaction identifier code from the original business data storage unit, calculate its hash value, and merge the hash value and the transaction identifier code to form block data.
[0046] Example 3
[0047] This embodiment provides a blockchain data retrieval method applicable to multiple blockchain smart contracts set up on a blockchain node server. Business operations on the blockchain can be composed of multiple functional smart contracts. Therefore, for some businesses that require access to historical blockchain business data to function, their corresponding smart contracts will perform data retrieval operations. The specific retrieval method can be as follows:
[0048] The smart contract executes a block data query operation based on business parameters, including the transaction identifier code to be queried;
[0049] The query invocation operation includes:
[0050] The smart contract finds the corresponding index in the block storage unit based on the transaction identifier code, and the index can be understood as the call path;
[0051] The smart contract finds the corresponding original transaction data in the original business data storage unit of the transaction according to the index, and sends the original transaction data into the smart contract to continue executing the contract code until the execution result corresponding to the smart contract is output. This method is to execute the smart contract through the original transaction data. However, in actual operation, since the original transaction data contains data from multiple aspects, and the execution of the smart contract may not require all the data or only historical business data, the execution speed will be significantly reduced when the original transaction data is used to drive the execution of the contract. This is because the contract needs to perform operations such as stripping the business data from the original transaction data, and the operation will induce side tasks such as signature verification and voting authenticity verification. Therefore, the embodiment provides a second method of calling block data.
[0052] Method 2:
[0053] The smart contract extracts the business identification code from the original transaction data, finds the corresponding business data and execution result data in the business data storage unit based on the business identification code, and sends the corresponding business data and execution result data into the smart contract to continue executing the contract code until the execution result corresponding to the smart contract is output. This method eliminates the operation of stripping business data from the original transaction data, avoids as many side tasks as possible such as signature verification and vote authenticity verification, and greatly reduces the data call burden.
[0054] The call path length of the two data retrieval methods mentioned above is significantly shorter than that of the MPT tree storage structure, which greatly reduces the memory occupied by the call path. Secondly, due to the short call path, ultra-high-speed data retrieval is achieved, further optimizing the response speed of the blockchain network when processing massive high-concurrency transactions.
[0055] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0056] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0057] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A blockchain data storage method, characterized in that, The method is applicable to any node server in a blockchain network, wherein the node server is equipped with the blockchain data storage system, and the method includes: Obtain the set of transactions to be executed distributed by the master node. The set of transactions to be executed includes multiple transaction data. The transaction data includes a transaction identifier code and a business identifier code. The transaction identifier code is used to distinguish multiple transactions occurring in the blockchain network. The business identifier code is used to distinguish business processing or transactions in the upper-layer business system. Multiple threads execute multiple transaction data simultaneously, obtaining the execution result data corresponding to each transaction data. A transaction data and its corresponding execution result data are recorded as a transaction original data. Extract the transaction identifier code from each transaction's raw data, and store each transaction's raw data in the transaction's raw business data storage unit according to the order of its corresponding transaction identifier code. Extract the business data and execution result data from the raw data of each transaction, wherein the business data includes a business identification code; Each business data and its corresponding execution result data are stored in the business data storage unit according to the order of the business identifier codes in each business data. Collect transaction identifier codes corresponding to multiple transaction data in the transaction set to be executed, generate block data based on the transaction identifier codes, and record the block data in the blockchain public ledger.
Citation Information
Patent Citations
Data storage method of block chain and block chain system
CN111275553A
Data access method and device based on block chain and electronic equipment
CN113077260A