Data storage method, device, equipment and readable storage medium based on blockchain

By calling the snapshot contract on the blockchain to generate a state tree snapshot, the problem of low blockchain data storage efficiency is solved, and fast storage and efficient backup are achieved.

CN113971002BActive Publication Date: 2024-10-15HAINAN HUOCHAIN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111129624.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-26
Publication Date
2024-10-15
Estimated Expiration
2041-09-26

AI Technical Summary

Technical Problem

As time goes by, more and more tree structures are created based on blockchain, which leads to increased difficulty in data backup and storage, longer storage time, slow storage speed, and low storage efficiency.

Method used

By calling the snapshot contract, perform a snapshot scan of the blockchain network, determine multiple blocks within the target time point, obtain the status tree, aggregate account nodes, set the snapshot index, generate a status tree snapshot in the snapshot space, and store the deadline time point currency transaction information, reducing the need to store a large number of state trees, and directly using snapshots to quickly store data.

Benefits of technology

It reduces the difficulty of data backup and storage, reduces storage time, and improves the speed and efficiency of data storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113971002B_ABST
    Figure CN113971002B_ABST
Patent Text Reader

Abstract

The present application discloses a data storage method, device, equipment and readable storage medium based on blockchain, which relates to the field of Internet technology, and realizes fast and accurate storage of transaction data information in a state tree by calling a snapshot contract. The method includes: calling a snapshot contract, performing a snapshot scan on the blockchain network, determining multiple blocks generated by the blockchain network in this period as of a target time point; obtaining multiple state trees corresponding to multiple blocks, reading the account nodes of each state tree in the multiple state trees, aggregating the account nodes of each state tree in the multiple state trees, and obtaining a blockchain account node; setting a snapshot index for the blockchain account node, and generating a state tree snapshot in the snapshot space based on the snapshot index, wherein the state tree snapshot stores multiple state trees and the account nodes of the multiple state trees store currency transaction information generated in this period as of the target time point.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a data storage method, device, equipment and readable storage medium based on blockchain. Background Art

[0002] With the continuous development of Internet technology and the continuous advancement of blockchain technology, the amount of data stored in the blockchain has increased rapidly. Therefore, data backup and preservation of the blockchain has become increasingly important.

[0003] In the related technology, when storing data based on blockchain, it is necessary to copy all application data at a certain moment, generate a copy of the application data at the current moment, and store the generated data copy in a specific file without interrupting the host business. The data copy in the specific file is usually stored in the database in a tree structure, that is, the data in the database is backed up and stored according to the tree structure.

[0004] In the process of implementing this application, the applicant found that the related technology has at least the following problems:

[0005] Since the blockchain is infinitely extensible, as time goes by, more and more tree structures are created based on the blockchain, the difficulty of data backup and storage gradually increases, and the storage time becomes longer, resulting in slow data storage speed and low storage efficiency. Summary of the invention

[0006] In view of this, the present application provides a data storage method, device, equipment and readable storage medium based on blockchain, the main purpose of which is to solve the current problem that with the passage of time, more and more tree structures are created based on blockchain, the difficulty of data backup storage gradually increases, the storage time becomes longer, resulting in slow data storage speed and low storage efficiency.

[0007] According to the first aspect of the present application, a data storage method based on blockchain is provided, the method comprising:

[0008] Calling a snapshot contract to perform a snapshot scan on the blockchain network to determine a plurality of blocks generated by the blockchain network in this period as of a target time point, where the target time point is the time point at which the snapshot contract is started to be called;

[0009] Acquire multiple state trees corresponding to the multiple blocks, read the account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain a blockchain account node;

[0010] A snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in a snapshot space, wherein the state tree snapshot stores the multiple state trees, and the account nodes of the multiple state trees store currency transaction information generated in the current period up to the target time point.

[0011] Optionally, obtaining the multiple status trees corresponding to the multiple blocks and reading the account node of each status tree in the multiple status trees includes:

[0012] For each block in the plurality of blocks, obtaining a state tree corresponding to the block;

[0013] Reading the extension node, the branch node and the leaf node of the status tree, and using the extension node, the branch node and the leaf node as the account node of the status tree;

[0014] Read the extension node, branch node and leaf node of the state tree of each block respectively, and obtain the account node of each state tree in the multiple state trees.

[0015] Optionally, setting a snapshot index for the blockchain account node, and generating a state tree snapshot in a snapshot space based on the snapshot index, includes:

[0016] Based on the snapshot contract, determine the write address of the blockchain account node in the state tree snapshot, combine the blockchain account node with the write address, and obtain the snapshot index;

[0017] According to the indication of the snapshot index, determining in the blockchain account node the currency transaction information generated in the current period up to the target time point, and marking the currency transaction information in the multiple state trees;

[0018] The marked multiple state trees are stored in the storage location indicated by the write address in the snapshot space to generate the state tree snapshot.

[0019] Optionally, after setting a snapshot index for the blockchain account node and generating a state tree snapshot in the snapshot space based on the snapshot index, the method further includes:

[0020] Determine the last block generated by the blockchain network at the target time point, and determine the target state tree corresponding to the last block in the state tree snapshot;

[0021] Marking the account nodes in the target state tree, identifying the marked account nodes in the target state tree, and reading the hash pointer stored in the account nodes;

[0022] Obtain unchanged historical currency transaction information from the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain initial account assets;

[0023] The ratio between the initial account assets and the preset unit assets is calculated, and the ratio is used as the voting amount, where the preset unit assets are the asset value of one unit of votes.

[0024] Optionally, the method further comprises:

[0025] When a data rollback request is detected, the data rollback request is identified and a rollback time point is determined, where the rollback time point is used to indicate a generation time point of a state tree snapshot of a previous cycle;

[0026] Searching the snapshot space for the last state tree snapshot generated before the rollback time point, and taking the last state tree snapshot as the designated state tree snapshot;

[0027] The specified state tree snapshot is read, specified currency transaction information is obtained in the specified state tree snapshot, the currency transaction information at the current time point is modified to the specified currency transaction information, and data rollback is completed.

[0028] Optionally, the method further comprises:

[0029] Determine a time point at which the state tree snapshot is stored in the snapshot space as a historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point;

[0030] When the time interval reaches the preset time interval, the snapshot contract is called to redetermine the multiple blocks generated by the blockchain in the current period as of the current time point, and a new state tree snapshot is generated based on the redetermined multiple blocks, and the new state tree snapshot is stored in the snapshot space.

[0031] Optionally, the method further comprises:

[0032] When it is detected that the snapshot contract is re-called to generate the new state tree snapshot, the state tree snapshot in the snapshot space is extracted as the historical state tree snapshot;

[0033] The historical state tree snapshot is stored in the historical snapshot space, and the historical snapshot space stores the historical state tree snapshot generated after the historical call to the snapshot contract.

[0034] According to the second aspect of the present application, a data storage device based on blockchain is provided, the device comprising:

[0035] A first determination module is used to call a snapshot contract, perform a snapshot scan on the blockchain network, and determine a plurality of blocks generated by the blockchain network in this period as of a target time point, where the target time point is the time point at which the snapshot contract is started to be called;

[0036] An acquisition module, configured to acquire multiple state trees corresponding to the multiple blocks, read an account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain a blockchain account node;

[0037] The first storage module is used to set a snapshot index for the blockchain account node, and generate a state tree snapshot in the snapshot space based on the snapshot index, wherein the state tree snapshot stores the multiple state trees, and the account nodes of the multiple state trees store currency transaction information generated within the current period as of the target time point.

[0038] Optionally, the acquisition module is used to acquire a status tree corresponding to each block in the multiple blocks; read the extension node, branch node and leaf node of the status tree, and use the extension node, branch node and leaf node as the account node of the status tree; read the extension node, branch node and leaf node of the status tree of each block respectively, and acquire the account node of each status tree in the multiple status trees.

[0039] Optionally, the first storage module is used to determine the write address of the blockchain account node in the state tree snapshot based on the snapshot contract, combine the blockchain account node with the write address to obtain the snapshot index; determine the currency transaction information generated within the current period as of the target time point in the blockchain account node according to the indication of the snapshot index, and mark the currency transaction information in the multiple state trees; store the marked multiple state trees in the storage location indicated by the write address in the snapshot space to generate the state tree snapshot.

[0040] Optionally, the device further comprises:

[0041] A second determination module is used to determine the last block generated by the blockchain network at the target time point, and determine the target state tree corresponding to the last block in the state tree snapshot;

[0042] A marking module, used to mark the account nodes in the target state tree, identify the marked account nodes in the target state tree, and read the hash pointer stored in the account node;

[0043] an aggregation module, configured to obtain unchanged historical currency transaction information from the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain initial account assets;

[0044] The calculation module is used to calculate the ratio between the initial account assets and the preset unit assets, and use the ratio as the voting amount, wherein the preset unit assets are the asset value of one unit of votes.

[0045] Optionally, the device further comprises:

[0046] An identification module, used for identifying the data rollback request and determining a rollback time point when a data rollback request is detected, wherein the rollback time point is used to indicate a generation time point of a state tree snapshot of a previous cycle;

[0047] A query module, used to query the last state tree snapshot generated before the rollback time point in the snapshot space, and use the last state tree snapshot as the designated state tree snapshot;

[0048] The modification module is used to read the specified state tree snapshot, obtain the specified currency transaction information in the specified state tree snapshot, modify the currency transaction information at the current time point to the specified currency transaction information, and complete the data rollback.

[0049] Optionally, the device further comprises:

[0050] A statistics module, used to determine the time point when the state tree snapshot is stored in the snapshot space as the historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point;

[0051] The acquisition module is further used to call the snapshot contract when the time interval reaches a preset time interval, redetermine the multiple blocks generated by the blockchain in the current period as of the current time point, generate a new state tree snapshot based on the redetermined multiple blocks, and store the new state tree snapshot in the snapshot space.

[0052] Optionally, the device further comprises:

[0053] An extraction module, configured to extract the state tree snapshot in the snapshot space as a historical state tree snapshot when detecting that the snapshot contract is re-called to generate the new state tree snapshot;

[0054] The second storage module is used to store the historical state tree snapshot into the historical snapshot space, and the historical snapshot space stores the historical state tree snapshot generated after the historical call to the snapshot contract.

[0055] According to a third aspect of the present application, a device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.

[0056] According to a fourth aspect of the present application, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.

[0057] By means of the above technical scheme, the present application provides a data storage method, device, equipment and readable storage medium based on blockchain. The present application performs a snapshot scan on the blockchain network by calling a snapshot contract, and determines the multiple blocks generated by the blockchain network in this period as of the target time point when the snapshot contract is called. Subsequently, multiple state trees corresponding to multiple blocks are obtained, the account nodes of each state tree in the multiple state trees are read, and the account nodes of each state tree in the multiple state trees are aggregated to obtain blockchain account nodes. Next, a snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, in which multiple state trees are stored and the account nodes of the multiple state trees store the currency transaction information generated in this period as of the target time point. By calling the snapshot contract to back up the data of multiple state trees in the blockchain, according to the snapshot index information of the account node, the currency transaction information stored in the account node in the state tree is stored in the snapshot space, and a state tree snapshot is generated. There is no need to store a large number of state trees in the storage space, and the snapshot is directly used to quickly and accurately store the data information in the state tree, which reduces the difficulty of data backup storage, reduces the data storage time, and improves the speed and efficiency of data storage.

[0058] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0060] Figure 1 A schematic diagram of a data storage method based on blockchain provided in an embodiment of the present application is shown;

[0061] Figure 2A schematic diagram of a data storage method based on blockchain provided in an embodiment of the present application is shown;

[0062] Figure 3A A schematic diagram of the structure of a blockchain-based data storage device provided in an embodiment of the present application is shown;

[0063] Figure 3B A schematic diagram of the structure of a blockchain-based data storage device provided in an embodiment of the present application is shown;

[0064] Figure 3C A schematic diagram of the structure of a blockchain-based data storage device provided in an embodiment of the present application is shown;

[0065] Figure 3D A schematic diagram of the structure of a blockchain-based data storage device provided in an embodiment of the present application is shown;

[0066] Figure 3E A schematic diagram of the structure of a blockchain-based data storage device provided in an embodiment of the present application is shown;

[0067] Figure 4 A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0068] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0069] The present application embodiment provides a data storage method based on blockchain, such as Figure 1 As shown, the method includes:

[0070] 101. Call the snapshot contract to perform a snapshot scan on the blockchain network to determine the multiple blocks generated by the blockchain network in this cycle as of the target time point. The target time point is the time point when the snapshot contract is started to be called.

[0071] 102. Obtain multiple state trees corresponding to multiple blocks, read the account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain the blockchain account node.

[0072] 103. Set a snapshot index for the blockchain account node, and generate a state tree snapshot in the snapshot space based on the snapshot index. The state tree snapshot stores multiple state trees, and the account nodes of the multiple state trees store currency transaction information generated in this period up to the target time point.

[0073] The method provided in the embodiment of the present application performs a snapshot scan on the blockchain network by calling a snapshot contract, and determines the multiple blocks generated by the blockchain network in this period as of the target time point when the snapshot contract is called. Subsequently, multiple state trees corresponding to multiple blocks are obtained, the account nodes of each state tree in the multiple state trees are read, and the account nodes of each state tree in the multiple state trees are aggregated to obtain blockchain account nodes. Next, a snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, which stores multiple state trees and the account nodes of the multiple state trees store currency transaction information generated in this period as of the target time point. By calling the snapshot contract to back up data of multiple state trees in the blockchain, according to the snapshot index information of the account node, the currency transaction information stored in the account node in the state tree is stored in the snapshot space, and a state tree snapshot is generated. There is no need to store a large number of state trees in the storage space, and the snapshot is directly used to quickly and accurately store the data information in the state tree, which reduces the difficulty of data backup storage, reduces the data storage time, and improves the speed and efficiency of data storage.

[0074] The present application embodiment provides a data storage method based on blockchain, such as Figure 2 As shown, the method includes:

[0075] 201. Call the snapshot contract to perform a snapshot scan on the blockchain network to determine the multiple blocks generated by the blockchain network in this cycle as of the target time point.

[0076] With the continuous development of Internet technology and the continuous progress of blockchain technology, the amount of data stored in the blockchain has increased rapidly. Therefore, data backup and preservation for blockchain have become increasingly important. At present, when storing data based on blockchain, it is necessary to copy all application data at a certain moment, generate a copy of the application data at the current moment, and store the generated data copy in a specific file while ensuring that the host business is not interrupted. Among them, the data copy in the specific file is usually stored in the database in a tree structure, that is, the data in the database is backed up and stored according to the tree structure. However, the applicant recognizes that since the blockchain is infinitely extended, as time goes by, the tree structures created based on the blockchain are increasing, the difficulty of data backup storage is gradually increased, and the storage time is prolonged, resulting in slow data storage and low storage efficiency.

[0077] Therefore, the present application proposes a data storage method based on blockchain, which performs a snapshot scan on the blockchain network by calling a snapshot contract, and determines the multiple blocks generated by the blockchain network in this period as of the target time point when the snapshot contract is called. Subsequently, multiple state trees corresponding to multiple blocks are obtained, the account nodes of each state tree in the multiple state trees are read, and the account nodes of each state tree in the multiple state trees are aggregated to obtain blockchain account nodes. Next, a snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, which stores multiple state trees and the account nodes of the multiple state trees store currency transaction information generated in this period as of the target time point. By calling the snapshot contract to back up data of multiple state trees in the blockchain, according to the snapshot index information of the account node, the currency transaction information stored in the account node in the state tree is stored in the snapshot space, and a state tree snapshot is generated. There is no need to store a large number of state trees in the storage space, and the snapshot is directly used to quickly and accurately store the data information in the state tree, which reduces the difficulty of data backup storage, reduces the data storage time, and improves the speed and efficiency of data storage.

[0078] Among them, this application is applied to the blockchain network of online currency transactions. By calling the snapshot contract, the state tree in the blockchain is snapshot-backed up, where the state tree is MPT (Merkle Patricia Tree), which can store key-value pairs of data of any length, and provides a mechanism for quickly calculating the hash identifier of the maintained data set, realizing fast state rollback, expanding light nodes, and completing simple payment verification. Snapshot technology achieves faster data storage by recording the state at a certain moment. Therefore, this application uses snapshot technology to perform snapshot data backup storage on the MPT state tree.

[0079] Specifically, the snapshot contract is called, and when it is detected that the snapshot contract is called, the current time point is determined, and the current time point is used as the target time point. Subsequently, the blockchain network is snapshot scanned to determine the multiple blocks generated by the blockchain network in this period as of the target time point, wherein the blockchain network is used to execute network currency transactions. Through the snapshot method, the multiple blocks generated in this period as of the target time point are obtained and stored. When the storage device has an application failure or the file is damaged, the data can be quickly restored to the state of a certain available time point. Specifically, the available time point can be the historical time point of the state tree snapshot generated by the historical call to the snapshot contract.

[0080] 202. Obtain multiple state trees corresponding to multiple blocks, read the account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain the blockchain account node.

[0081] In an embodiment of the present application, a new block is generated in the blockchain network at regular intervals, and transactions occur in the new block. Each block has one and only one state tree. The account node in the state tree is read to obtain the currency transaction information generated by the current block within this period up to the target time point.

[0082] Among them, for each block in multiple blocks, the state tree corresponding to the block is obtained. Then, since the MPT tree contains three types of nodes, Extension Node, which stores path compression data, that is, the hexadecimal data stored in shared nibbles, Branch Node, which cannot be compressed, and Leaf Node, which stores account state data, therefore, reading the extension node, branch node and leaf node of the state tree is equivalent to obtaining the data results and data information of the entire state tree, and using the extension node, branch node and leaf node as the account node of the state tree. Read the extension node, branch node and leaf node of the state tree of each block respectively, obtain the account node of each state tree in multiple state trees, and finally, aggregate the account nodes of each state tree in multiple state trees to obtain the blockchain account node.

[0083] By identifying the account nodes of the status tree, the data structure of the status tree and the currency transaction information of the current block are obtained, and then the account nodes of multiple status trees are aggregated to obtain the blockchain account nodes. This means that all the currency transaction information that has occurred in the entire blockchain within this period up to the target time point has been obtained.

[0084] 203. Set a snapshot index for the blockchain account node, and generate a state tree snapshot in the snapshot space based on the snapshot index.

[0085] In the embodiment of the present application, calling the snapshot contract will take a snapshot of the current blockchain, and the account node obtained by the snapshot will be written into the index address corresponding to the snapshot space according to the preset snapshot index, generating a state tree snapshot at the target time point. Using the snapshot method to store the currency transaction data in the state tree can store the data information in the state tree more quickly and improve the efficiency of the state tree data backup storage.

[0086] Specifically, based on the snapshot contract, the write address of the blockchain account node in the state tree snapshot is determined, the blockchain account node and the write address are combined to obtain a snapshot index, and then, according to the indication of the snapshot index, the currency transaction information generated in the current period up to the target time point is determined in the blockchain account node, wherein the currency transaction information may be an account balance, number of transactions, etc. The present application does not specifically limit the content of the currency transaction information, and the currency transaction information is marked in the multiple state trees. Finally, the marked multiple state trees are stored in the storage location indicated by the write address in the snapshot space to generate a state tree snapshot.

[0087] In the specific implementation process, since the present application is applied to the blockchain network for executing network currency transactions, the currency transaction information stored in the account node in the state tree of the last block in the state tree snapshot can represent the initial transaction state of the next cycle. Therefore, after generating the state tree snapshot, it is necessary to determine the last block generated by the blockchain network in this cycle as of the target time point, determine the target state tree corresponding to the last block in the state tree snapshot, and mark the account node in the target state tree. In the actual application process, after the new block is generated, the transaction occurs in the new block, and the state tree of the new block will also change accordingly, that is, the account balance and transaction number stored in the account node change, and the state tree constructs a new node to store the new currency transaction information in the changed part, and the unchanged part uses a hash pointer to share the historical transaction information with the previous state tree. So after marking the account node of the target state tree, it is necessary to identify the account node in the marked target state tree, read the hash pointer stored in the account node, obtain the unchanged historical currency transaction information at the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain the initial account assets. Finally, the ratio between the initial account assets and the preset unit assets is calculated, the ratio is rounded to an integer value, and the integer value is used as the voting amount. Specifically, the preset unit assets are the asset value of one unit of votes. The default value can be used, or it can be set by relevant staff according to specific transaction circumstances. This application does not specifically limit the size and setting method of the preset unit assets.

[0088] Among them, since the blockchain network will continuously generate new blocks and generate new currency transaction information, it is necessary to call the snapshot contract every once in a while to perform snapshot backup of the blockchain network. Specifically, a time interval can be set, such as 7 days, 15 days, etc. The length of the preset time interval is not specifically limited in this application. Determine the time point at which the state tree snapshot is stored in the snapshot space as the historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point. When the time interval reaches the preset time interval, call the snapshot contract, re-determine the multiple blocks generated in the current cycle when the blockchain ends at the current time point, and generate a new state tree snapshot based on the re-determined multiple blocks, and store the new state tree snapshot in the snapshot space. Among them, when it is detected that the snapshot contract is re-called to generate a new state tree snapshot, extract the state tree snapshot in the snapshot space as the historical state tree snapshot, and store the historical state tree snapshot in the historical snapshot space, wherein the historical snapshot space stores the historical state tree snapshot generated after the historical call to the snapshot contract, so that the corresponding historical state tree snapshot can be read in the historical snapshot space when data rollback is required later.

[0089] In other application scenarios, there are situations where currency transactions in the blockchain network are wrong or currency transaction data is damaged. At this time, the blockchain network will issue a data rollback request, requesting that the data information be restored to a certain historical moment. By querying the historical snapshot space, retrieving the historical state tree snapshot generated at the historical moment, and rewriting the current transaction data information to the historical transaction data information stored in the account node in the historical state tree snapshot, data rollback can be achieved, and the currency transaction information can be restored to a certain historical moment. Specifically, when a data rollback request is detected, the data rollback request is identified, the generation time point of the state tree snapshot indicating the previous cycle is determined as the rollback time point, the last state tree snapshot generated before the rollback time point is queried in the snapshot space, the last state tree snapshot is used as the specified state tree snapshot, the specified state tree snapshot is read, the specified currency transaction information is obtained in the specified state tree snapshot, the currency transaction information at the current time point is modified to the specified currency transaction information, and the data rollback is completed.

[0090] The method provided in the embodiment of the present application performs a snapshot scan on the blockchain network by calling a snapshot contract, and determines the multiple blocks generated by the blockchain network in this period as of the target time point when the snapshot contract is called. Subsequently, multiple state trees corresponding to multiple blocks are obtained, the account nodes of each state tree in the multiple state trees are read, and the account nodes of each state tree in the multiple state trees are aggregated to obtain blockchain account nodes. Next, a snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, which stores multiple state trees and the account nodes of the multiple state trees store currency transaction information generated in this period as of the target time point. By calling the snapshot contract to back up data of multiple state trees in the blockchain, according to the snapshot index information of the account node, the currency transaction information stored in the account node in the state tree is stored in the snapshot space, and a state tree snapshot is generated. There is no need to store a large number of state trees in the storage space, and the snapshot is directly used to quickly and accurately store the data information in the state tree, which reduces the difficulty of data backup storage, reduces the data storage time, and improves the speed and efficiency of data storage.

[0091] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a data storage device based on blockchain, such as Figure 3A As shown, the device includes: a first determining module 301 , an acquiring module 302 , and a first storing module 303 .

[0092] The first determination module 301 is used to call the snapshot contract, perform a snapshot scan on the blockchain network, and determine a plurality of blocks generated by the blockchain network in this period as of a target time point, where the target time point is the time point at which the snapshot contract is started to be called;

[0093] The acquisition module 302 is used to acquire multiple state trees corresponding to the multiple blocks, read the account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain the blockchain account node;

[0094] The first storage module 303 is used to set a snapshot index for the blockchain account node, and generate a state tree snapshot in the snapshot space based on the snapshot index, wherein the state tree snapshot stores the multiple state trees, and the account nodes of the multiple state trees store the currency transaction information generated in this period up to the target time point.

[0095] In a specific application scenario, the acquisition module 302 is used to obtain the status tree corresponding to each block in the multiple blocks; read the extension node, branch node and leaf node of the status tree, and use the extension node, branch node and leaf node as the account node of the status tree; read the extension node, branch node and leaf node of the status tree of each block respectively, and obtain the account node of each status tree in the multiple status trees.

[0096] In a specific application scenario, the first storage module 303 is used to determine the write address of the blockchain account node in the state tree snapshot based on the snapshot contract, combine the blockchain account node with the write address to obtain the snapshot index; determine the currency transaction information generated in the current period up to the target time point in the blockchain account node according to the indication of the snapshot index, and mark the currency transaction information in the multiple state trees; store the marked multiple state trees in the storage location indicated by the write address in the snapshot space to generate the state tree snapshot.

[0097] In specific application scenarios, such as Figure 3B As shown, the device further includes: a second determination module 304 , a marking module 305 , an aggregation module 306 , and a calculation module 307 .

[0098] The second determination module 304 is used to determine the last block generated by the blockchain network at the target time point, and determine the target state tree corresponding to the last block in the state tree snapshot;

[0099] The marking module 305 is used to mark the account nodes in the target state tree, identify the marked account nodes in the target state tree, and read the hash pointer stored in the account node;

[0100] The aggregation module 306 is used to obtain the unchanged historical currency transaction information from the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain the initial account assets;

[0101] The calculation module 307 is used to calculate the ratio between the initial account assets and the preset unit assets, and use the ratio as the voting amount, where the preset unit assets are the asset value of one unit of votes.

[0102] In specific application scenarios, such as Figure 3C As shown, the device further includes: an identification module 308 , a query module 309 , and a modification module 310 .

[0103] The identification module 308 is used to identify the data rollback request and determine the rollback time point when a data rollback request is detected. The rollback time point is used to indicate the generation time point of the state tree snapshot of the previous cycle;

[0104] The query module 309 is used to query the last state tree snapshot generated before the rollback time point in the snapshot space, and use the last state tree snapshot as the designated state tree snapshot;

[0105] The modification module 310 is used to read the specified state tree snapshot, obtain the specified currency transaction information in the specified state tree snapshot, modify the currency transaction information at the current time point to the specified currency transaction information, and complete the data rollback.

[0106] In specific application scenarios, such as Figure 3D As shown, the device further includes: a statistical module 311.

[0107] The statistics module 311 is used to determine the time point when the state tree snapshot is stored in the snapshot space as the historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point;

[0108] The acquisition module 302 is also used to call the snapshot contract when the time interval reaches a preset time interval, redetermine the multiple blocks generated by the blockchain in the current period as of the current time point, generate a new state tree snapshot based on the redetermined multiple blocks, and store the new state tree snapshot in the snapshot space.

[0109] In specific application scenarios, such as Figure 3E As shown, the device further includes: an extraction module 312 and a second storage module 313.

[0110] The extraction module 312 is used to extract the state tree snapshot in the snapshot space as the historical state tree snapshot when it is detected that the snapshot contract is re-called to generate the new state tree snapshot;

[0111] The second storage module 313 is used to store the historical state tree snapshot into the historical snapshot space, and the historical snapshot space stores the historical state tree snapshot generated after the snapshot contract is historically called.

[0112] The device provided in the embodiment of the present application performs a snapshot scan on the blockchain network by calling a snapshot contract, and determines the multiple blocks generated by the blockchain network in this period as of the target time point when the snapshot contract is called. Subsequently, multiple state trees corresponding to multiple blocks are obtained, the account nodes of each state tree in the multiple state trees are read, and the account nodes of each state tree in the multiple state trees are aggregated to obtain blockchain account nodes. Next, a snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, which stores multiple state trees and the account nodes of the multiple state trees store currency transaction information generated in this period as of the target time point. By calling the snapshot contract to back up data of multiple state trees in the blockchain, according to the snapshot index information of the account node, the currency transaction information stored in the account node in the state tree is stored in the snapshot space, and a state tree snapshot is generated, without storing a large number of state trees in the storage space, and the data information in the state tree is directly stored in the snapshot quickly and accurately, which reduces the difficulty of data backup storage, reduces the data storage time, and improves the speed and efficiency of data storage.

[0113] It should be noted that for other corresponding descriptions of the functional units involved in the blockchain-based data storage device provided in the embodiment of the present application, please refer to Figure 1 and Figure 2 The corresponding description in will not be repeated here.

[0114] In an exemplary embodiment, see Figure 4 , also provides a device, which includes a bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the data storage method based on blockchain in the above embodiment.

[0115] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the blockchain-based data storage method.

[0116] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by hardware, or by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.

[0117] Those skilled in the art will appreciate that the accompanying drawings are merely schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily required for implementing the present application.

[0118] Those skilled in the art will appreciate that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more devices different from the implementation scenario. The modules in the above implementation scenario can be combined into one module, or can be further split into multiple sub-modules.

[0119] The above application serial numbers are for description only and do not represent the advantages or disadvantages of the implementation scenarios.

[0120] The above disclosure only discloses several specific implementation scenarios of the present application. However, the present application is not limited thereto, and any changes that can be conceived by technicians in this field should fall within the scope of protection of the present application.

Claims

1. A data storage method based on blockchain, It is characterized in that The method is applied to a blockchain network, and the blockchain network is used to perform network currency transactions, comprising: Calling a snapshot contract to perform a snapshot scan on the blockchain network to determine a plurality of blocks generated by the blockchain network in this period as of a target time point, where the target time point is the time point at which the snapshot contract is started to be called; Acquire multiple state trees corresponding to the multiple blocks, read the account node of each state tree in the multiple state trees, aggregate the account nodes of each state tree in the multiple state trees, and obtain a blockchain account node, wherein the acquiring the multiple state trees corresponding to the multiple blocks and reading the account node of each state tree in the multiple state trees comprises: for each block in the multiple blocks, acquiring the state tree corresponding to the block, reading the extension node, branch node and leaf node of the state tree, using the extension node, branch node and leaf node as the account node of the state tree, respectively reading the extension node, branch node and leaf node of the state tree of each block, and acquiring the account node of each state tree in the multiple state trees; A snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, wherein the state tree snapshot stores the multiple state trees, and the account nodes of the multiple state trees store the currency transaction information generated within the current period up to the target time point, wherein the snapshot index is set for the blockchain account node, and based on the snapshot index, a state tree snapshot is generated in the snapshot space, including: based on the snapshot contract, determining the write address of the blockchain account node in the state tree snapshot, combining the blockchain account node with the write address to obtain the snapshot index, determining in the blockchain account node according to the indication of the snapshot index, the currency transaction information generated within the current period up to the target time point, marking the currency transaction information in the multiple state trees, storing the marked multiple state trees in the storage location indicated by the write address in the snapshot space, and generating the state tree snapshot.

2. The method according to claim 1, It is characterized in that After setting a snapshot index for the blockchain account node and generating a state tree snapshot in the snapshot space based on the snapshot index, the method further includes: Determine the last block generated by the blockchain network at the target time point, and determine the target state tree corresponding to the last block in the state tree snapshot; Marking the account nodes in the target state tree, identifying the marked account nodes in the target state tree, and reading the hash pointer stored in the account nodes; Obtain unchanged historical currency transaction information from the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain initial account assets; The ratio between the initial account assets and the preset unit assets is calculated, the ratio is rounded to obtain a first integer value, and the first integer value is used as the voting amount. The preset unit assets are the asset value of one unit of votes.

3. The method according to claim 1, It is characterized in that The method further comprises: When a data rollback request is detected, the data rollback request is identified and a rollback time point is determined, where the rollback time point is used to indicate a generation time point of a state tree snapshot of a previous cycle; Searching the snapshot space for the last state tree snapshot generated before the rollback time point, and taking the last state tree snapshot as the designated state tree snapshot; The specified state tree snapshot is read, specified currency transaction information is obtained in the specified state tree snapshot, the currency transaction information at the current time point is modified to the specified currency transaction information, and data rollback is completed.

4. The method according to claim 1, It is characterized in that The method further comprises: Determine a time point at which the state tree snapshot is stored in the snapshot space as a historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point; When the time interval reaches the preset time interval, the snapshot contract is called to redetermine the multiple blocks generated by the blockchain in the current period as of the current time point, and a new state tree snapshot is generated based on the redetermined multiple blocks, and the new state tree snapshot is stored in the snapshot space.

5. The method according to claim 4, It is characterized in that The method further comprises: When it is detected that the snapshot contract is re-called to generate the new state tree snapshot, the state tree snapshot in the snapshot space is extracted as the historical state tree snapshot; The historical state tree snapshot is stored in the historical snapshot space, and the historical snapshot space stores the historical state tree snapshot generated after the historical call to the snapshot contract.

6. A data storage device based on blockchain, It is characterized in that The device is applied to a blockchain network, and the blockchain network is used to perform network currency transactions, including: A first determination module is used to call a snapshot contract, perform a snapshot scan on the blockchain network, and determine a plurality of blocks generated by the blockchain network in this period as of a target time point, where the target time point is the time point at which the snapshot contract is started to be called; An acquisition module, configured to acquire multiple state trees corresponding to the multiple blocks, read an account node of each state tree in the multiple state trees, aggregate the account node of each state tree in the multiple state trees, and obtain a blockchain account node; A first storage module is used to set a snapshot index for the blockchain account node, and based on the snapshot index, generate a state tree snapshot in the snapshot space, wherein the state tree snapshot stores the multiple state trees, and the account nodes of the multiple state trees store currency transaction information generated in the current period up to the target time point; The acquisition module is used to acquire the state tree corresponding to each block in the multiple blocks; read the extension node, branch node and leaf node of the state tree, and use the extension node, branch node and leaf node as the account node of the state tree; respectively read the extension node, branch node and leaf node of the state tree of each block, and acquire the account node of each state tree in the multiple state trees; The first storage module is used to determine the write address of the blockchain account node in the state tree snapshot based on the snapshot contract, combine the blockchain account node with the write address to obtain the snapshot index; determine the currency transaction information generated within the current period as of the target time point in the blockchain account node according to the indication of the snapshot index, and mark the currency transaction information in the multiple state trees; store the marked multiple state trees in the storage location indicated by the write address in the snapshot space to generate the state tree snapshot.

7. The device according to claim 6, It is characterized in that The device also includes: A second determination module is used to determine the last block generated by the blockchain network at the target time point, and determine the target state tree corresponding to the last block in the state tree snapshot; A marking module, used to mark the account nodes in the target state tree, identify the marked account nodes in the target state tree, and read the hash pointer stored in the account node; an aggregation module, configured to obtain unchanged historical currency transaction information from the address indicated by the hash pointer, aggregate the historical currency transaction information with the new currency transaction information stored in the account node, and obtain initial account assets; The calculation module is used to calculate the ratio between the initial account assets and the preset unit assets, and use the ratio as the voting amount, wherein the preset unit assets are the asset value of one unit of votes.

8. The device according to claim 6, It is characterized in that The device also includes: An identification module, used for identifying the data rollback request and determining a rollback time point when a data rollback request is detected, wherein the rollback time point is used to indicate a generation time point of a state tree snapshot of a previous cycle; A query module, used to query the last state tree snapshot generated before the rollback time point in the snapshot space, and use the last state tree snapshot as the designated state tree snapshot; The modification module is used to read the specified state tree snapshot, obtain the specified currency transaction information in the specified state tree snapshot, modify the currency transaction information at the current time point to the specified currency transaction information, and complete the data rollback.

9. The device according to claim 6, It is characterized in that The device also includes: A statistics module, used to determine the time point when the state tree snapshot is stored in the snapshot space as the historical snapshot time point, and continuously count the time interval between the current time point and the historical snapshot time point; The acquisition module is further used to call the snapshot contract when the time interval reaches a preset time interval, redetermine the multiple blocks generated by the blockchain in the current period as of the current time point, generate a new state tree snapshot based on the redetermined multiple blocks, and store the new state tree snapshot in the snapshot space.

10. The device according to claim 9, It is characterized in that The device also includes: An extraction module, configured to extract the state tree snapshot in the snapshot space as a historical state tree snapshot when detecting that the snapshot contract is re-called to generate the new state tree snapshot; The second storage module is used to store the historical state tree snapshot into the historical snapshot space, and the historical snapshot space stores the historical state tree snapshot generated after the historical call to the snapshot contract.

11. A device comprising a memory and a processor, wherein the memory stores a computer program, It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

12. A readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.