Block data storage method and device based on Fabric
By determining the blocks that meet the archiving conditions in the Fabric blockchain system, set the empty and encrypted storage to the archive database under the chain, solve the problem of storage pressure and cost on the chain, and achieve efficient storage and secure data archiving.
Patent Information
- Application Number
- CN202411489352.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-01-24
AI Technical Summary
In the Fabric blockchain system, as time is used increases, on-chain storage pressure and costs continue to expand, and a method is needed to alleviate these pressures and costs.
By determining the blocks and block heights that meet the archiving conditions, the corresponding block data is obtained from the blockchain, blanked, and the obtained block data is encrypted and stored in the blockchain offline. in the archive database.
It reduces the pressure and cost of on-chain storage, improves on-chain performance, and ensures the security of off-chain data through dense archiving.
Smart Images

Figure CN119357290A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present invention relate to blockchain technology, and more particularly, to a method and device for storing block data based on Fabric. Background Art
[0002] Fabric is the core blockchain framework launched by the Hyperledger Alliance. It is more suitable for building alliance chains within and between complex enterprises. According to the goals of the Hyperledger Alliance, Fabric is built as a modular, pluggable basic alliance chain framework.
[0003] In the Fabric architecture, enterprises are connected with different subnets according to different business purposes. Each subnet corresponds to a channel, and each channel has its own independent blockchain. In the Fabric architecture, nodes can actually be divided into ordinary nodes (called Peer nodes) and order nodes (Order nodes). Fabric divides business processing and Internet access into three parts: endorsement, sorting, and adding to the ledger after verification.
[0004] In the blockchain system, when a certain time or a certain amount of transactions are reached, the blockchain system will generate blocks. In the Fabri architecture, each peer node in the blockchain stores the full amount of block data. As the usage time increases, the storage pressure and cost on the chain will continue to increase. Summary of the invention
[0005] One or more embodiments of the present invention describe a Fabric-based block data storage method and device, which can reduce the on-chain storage pressure and cost of the blockchain.
[0006] According to a first aspect, a block data storage method based on Fabric is provided, the method comprising:
[0007] For Fabric-based blockchains, determine the blocks and block heights that meet the archiving conditions;
[0008] According to the determined blocks and block heights that meet the archiving conditions, corresponding block data is obtained from the blockchain, and the obtained block data is cleared on the blockchain;
[0009] The obtained block data is encrypted and stored in the offline archive database of the blockchain.
[0010] The archiving conditions include: the frequency of access to the data in the block is lower than a preset access frequency threshold; and / or the time interval between the last access time of the data in the block and the current time is greater than a preset interval threshold; and / or the length of time the data in the block is stored on the blockchain is greater than a preset duration threshold.
[0011] The obtaining corresponding block data from the blockchain according to the determined blocks and block heights meeting the archiving conditions includes:
[0012] Query the mapping relationship between the block number and the offset in the index database, and query the block file pointer to obtain the information of the corresponding block file, so as to determine a first height interval from the previously archived block height to the block height on the current blockchain that needs to be archived;
[0013] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the last configuration block number on the blockchain is first read, and the last configuration block number read is compared with the block number of the current block to avoid archiving the last configuration block on the blockchain. If they are different, the file pointer of the current block is obtained from the index database through the block number of the current block, and the corresponding file name, starting offset, and offset are obtained, thereby obtaining the data of the current block corresponding to the block offset;
[0014] The obtained block data is cleared on the blockchain, including:
[0015] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the data of the corresponding block offset is cleared through file operations.
[0016] The archive database is a local storage resource or a cloud storage resource.
[0017] The method further comprises:
[0018] If a block to be archived is a configuration block but not the last configuration block, there is no need to clear the data of the configuration block from the blockchain; if a block to be archived is a transaction block, the above-mentioned process of clearing the acquired block data on the blockchain is performed.
[0019] After storing the encrypted block data in an archive database offline in the blockchain, the method further includes:
[0020] Get the starting recovery block height;
[0021] Determine a second height interval between the starting recovery block height and the latest archived block height in the archive database;
[0022] In the archive database, decrypt the block data in the determined second height interval;
[0023] The decrypted block data is restored to the blockchain.
[0024] The restoring the decrypted block data to the blockchain includes:
[0025] For each block in the determined second height interval, execute the following loop in sequence:
[0026] For the current block, determine whether the current block is the last configuration block on the blockchain. If so, skip it. If it is a configuration block but not the last configuration block, copy it at the block position of the configuration block on the blockchain.
[0027] The method further includes: presetting a user public-private key pair and a platform public-private key pair; encrypting the user public key using the platform public key, and then storing the encrypted user public key in a system database of the blockchain;
[0028] The encrypting of the acquired block data includes: after reading the block data meeting the archiving condition from the blockchain, reading the corresponding encrypted user public key from the system database, using the platform private key to decode the encrypted user public key into a plaintext user public key, and then using the user public key to encrypt the block data to be archived;
[0029] Decrypting the block data in the determined second height interval includes: decrypting the block data in the determined second height interval using a corresponding user private key.
[0030] According to a second aspect, a block data storage device based on Fabric is proposed, the device comprising:
[0031] The archiving condition determination module is configured to determine the blocks and block heights that meet the archiving conditions for the Fabric-based blockchain;
[0032] The archiving processing module is configured to obtain corresponding block data from the blockchain according to the determined blocks and block heights that meet the archiving conditions, and to clear the obtained block data on the blockchain;
[0033] The off-chain processing module is configured to encrypt the acquired block data and store the encrypted block data in an archive database offline in the blockchain.
[0034] According to a third aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in any embodiment of the present invention is implemented.
[0035] The Fabric-based block data storage method and device provided in the embodiments of the present invention have at least the following beneficial effects:
[0036] (1) Reduce storage costs and improve on-chain performance
[0037] The block data that meets the archiving conditions, such as cold data that is not frequently accessed on the chain, is archived and dumped to cheaper storage media off the chain, reducing the storage pressure and cost on the chain and improving the performance on the chain.
[0038] (2) Confidential archiving ensures off-chain data security
[0039] The user's public and private keys are encrypted with the platform's public key, and the archived blocks are encrypted with the user's public key. The user's private key is used for decryption when reading, ensuring the security of dumping blocks locally or in the cloud. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 It is a flowchart of a block data storage method based on Fabric in one embodiment of the present invention.
[0042] Figure 2 It is a flowchart of a block data storage method based on Fabric in another embodiment of the present invention.
[0043] Figure 3 It is a structural diagram of a block data storage device based on Fabric in one embodiment of the present invention.
[0044] Figure 4 It is a structural diagram of a block data storage device based on Fabric in another embodiment of the present invention. DETAILED DESCRIPTION
[0045] The solution provided by the present invention is described below in conjunction with the accompanying drawings.
[0046] First of all, it should be noted that the terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise.
[0047] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0048] Figure 1 FIG. 1 is a flowchart of a method for storing block data based on Fabric in one embodiment of the present invention. Figure 1 , the method comprising:
[0049] Step 101: For a blockchain based on Fabric, determine the blocks and block heights that meet the archiving conditions;
[0050] Step 103: According to the determined blocks and block heights that meet the archiving conditions, corresponding block data is obtained from the blockchain, and the obtained block data is cleared on the blockchain;
[0051] Step 105: Encrypt the acquired block data and store the encrypted block data in an offline archive database of the blockchain.
[0052] according to Figure 1 It can be seen from the process shown that in the embodiment of the present invention, the blocks and block heights that meet the archiving conditions are first determined (the block height is used to determine which blocks need to be archived), and then the block data that need to be archived are stored from the blockchain to the blockchain offline. In other words, there is no need to store these archived block data on the blockchain, which releases the blockchain resources occupied by these archived block data, thereby greatly reducing the storage pressure and cost on the chain.
[0053] Combine the following Figure 1 The process shown is used to illustrate the method of the present invention.
[0054] First, the main logic related to blocks in the Farbic-based blockchain is explained. Blocks in Farbic are isolated from each other by channels, and the node block data in the same channel will be synchronized to be consistent. Blocks are divided into configuration blocks and transaction blocks. Configuration blocks are blocks generated after modifications are made to the channel, and transaction blocks are blocks generated after users perform endorsement transactions. Special blockchains will automatically generate a genesis block after startup, and the genesis block is also a configuration block. For the identification of blocks, at the user level, they are distinguished by block height, that is, the block number. The block height represents the number of blocks in the channel, and the block height starts from 1. In the underlying logic, the block information in the channel is identified by the block number, which starts from 0, and block 0 is the genesis block.
[0055] First, execute step 101: for a blockchain based on Fabric, determine the blocks and block heights that meet the archiving conditions.
[0056] In this step 101, the user of the blockchain can determine the blocks and block heights that meet the archiving conditions. The block height of the current blockchain can be displayed to the user, and then the user can select the specified block height to be archived, that is, the blocks from the first block to the block height specified by the user meet the archiving conditions and need to be archived.
[0057] Of course, in the embodiment of the present invention, the management system of the blockchain can also automatically determine whether there are currently blocks and block heights that meet the archiving conditions based on pre-set archiving conditions.
[0058] In this step 101, the archiving conditions may include: the frequency of access to the data in the block is lower than a preset access frequency threshold; in this case, the block data is cold data and is likely to be data that will not be accessed subsequently. Therefore, it can be considered to be taken out of the blockchain and dragged to the blockchain for storage.
[0059] And / or, in this step 101, the archiving conditions may include: the time interval between the last access time of the data in the block and the current time is greater than a preset interval threshold. For example, for block data that has not been accessed for more than 20 years, it can be considered to be taken out of the blockchain and dragged to the blockchain for storage.
[0060] And / or, in this step 101, meeting the archiving conditions may include: the length of time that the data in the block has been stored on the blockchain is greater than a preset time threshold. For example, block data that has been stored for 100 years can be considered to be taken out of the blockchain and dragged to the blockchain for storage.
[0061] Next, step 103 is executed: according to the determined blocks and block heights that meet the archiving conditions, corresponding block data is obtained from the blockchain, and the obtained block data is cleared on the blockchain.
[0062] Block height is used to determine which blocks need to be archived.
[0063] In one embodiment of the present invention, in step 103, the specific implementation process of obtaining corresponding block data from the blockchain according to the determined blocks and block heights that meet the archiving conditions includes:
[0064] Query the mapping relationship between the block number and the offset in the index database, and query the block file pointer to obtain the information of the corresponding block file, so as to determine a first height interval from the previously archived block height to the block height on the current blockchain that needs to be archived;
[0065] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the last configuration block number on the blockchain is first read, and the last configuration block number read is compared with the block number of the current block to avoid archiving the last configuration block on the blockchain. If they are different, the file pointer of the current block is obtained from the index database through the block number of the current block, and the corresponding file name, starting offset, and offset are obtained, thereby obtaining the data of the current block corresponding to the block offset;
[0066] Accordingly, in step 103, the acquired block data is cleared on the blockchain, including:
[0067] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the data of the corresponding block offset is cleared through file operations.
[0068] Next, execute step 105: encrypt the acquired block data, and store the encrypted block data in the offline archive database of the blockchain.
[0069] In the embodiment of the present invention, in order to ensure the security of block data stored outside the blockchain and prevent leakage, the native block data is encrypted and stored. The encryption algorithm is a national secret, each platform user has his own pair of user public and private key pairs, and the platform has a pair of platform public and private key pairs to realize the encryption protection of user public and private keys, that is, the user public key can be encrypted using the platform public key, and then the encrypted user public key is saved in the system database of the blockchain; when the user performs the archiving operation, the block data to be archived will be read from the blockchain, and then the corresponding user's public key will be read from the system database, and the platform private key will be used to decode it into plain text, and then the user public key will be used to encrypt the block data to be archived, and the encrypted ciphertext will be stored in the local file system or database.
[0070] Through the above operations, the block data stored in the off-chain database is ciphertext, which effectively ensures the security of block cold data. When querying cold data, the user's private key can be used to decrypt the ciphertext block data and then query the corresponding data.
[0071] In one embodiment of the present invention, the archive database is a local storage resource of a node or a cloud storage resource.
[0072] In one embodiment of the present invention, a block to be archived may be a configuration block (but not the last configuration block) on the blockchain, or a transaction block. If a block to be archived is a configuration block but not the last configuration block, there is no need to clear the data of the configuration block from the blockchain; if a block to be archived is a transaction block, the above-mentioned clearing of the acquired block data on the blockchain is performed.
[0073] In an embodiment of the present invention, after the encrypted block data is stored in the archive database offline of the blockchain, the block data in the archive database can be further restored to the blockchain. Thus, after step 105, the following is further included:
[0074] Step 107: Get the starting recovery block height;
[0075] Step 109: Determine a second height interval between the height of the initial recovery block and the height of the latest archived block in the archive database;
[0076] Step 111: Decrypting the block data in the determined second height interval in the archive database;
[0077] Step 113: restore the decrypted block data to the blockchain.
[0078] In one embodiment of the present invention, in step 113, restoring the decrypted block data to the blockchain includes:
[0079] For each block in the determined second height interval, execute the following loop in sequence:
[0080] For the current block, determine whether the current block is the last configuration block on the blockchain. If so, skip it. If it is a configuration block but not the last configuration block, copy it at the block position of the configuration block on the blockchain.
[0081] In one embodiment of the present invention, adaptive modifications can be made to the underlying core code of the Fabric version of the blockchain, including modifications to the system contract to adapt the SDK for user use, and modifications to the ledger module to support the ability to archive and restore node blocks. The technical solution is as follows:
[0082] 4.1 Blockchain underlying architecture transformation
[0083] Adaptation is made for the underlying system contracts and ledger modules of the blockchain.
[0084] The Fabric version used in the present invention may be 1.4.7, for example. In this version, the block data is sorted by the formula node after being endorsed by the endorsement node, and finally written by the account book into the block file under the path specified by the peer node. After the system runs for a long time or the transaction volume is large, a considerable amount of cold data that is not frequently accessed will be generated. In this process, the functions of controlling the writing of block data into files and maintaining the file system are completed by the block file manager in the account book module. The main function of the block file manager is to verify the block data and generate block files. The block file manager provides query, writing and synchronization of block data for the system contract, and uses an index database to support the implementation of the above functions. There can be multiple blocks in a block file. The function of the index database is to record the specified block and the block file in which it is located and the offset therein to locate the block. The interface of the block file manager is exposed to the query system chain code in the form of protobuf and gprc. This chain code supports querying the current channel block information, querying the latest and oldest blocks, querying blocks according to block numbers and block hashes, and querying transaction information according to transaction IDs.
[0085] The present invention mainly aims at the fabric bottom-level query system contract and the block manager of the ledger module to make modifications to adapt to the block secret archiving and recovery. Among them, archiving is to transfer the cold data that is not frequently accessed and occupies storage resources in the block file system to relatively cheap local storage or cloud storage. For the query system chain code, multiple interfaces for archiving and recovery capabilities should be added, so that users can call the system chain code through SDK to implement archiving related operations. For the block file manager, three interfaces are mainly made for archiving, recovery and querying archive information. Correspondingly, the archive prefix is added to the index database, and a new index database space is opened to store the archive mapping information and configuration block information. In addition, an archive-specific database will be configured in the block file manager, which is responsible for recording the archived height and updating the height of the configuration block when the block is written to the file, to ensure that the last configuration block is recorded.
[0086] 4.2 Archive Block
[0087] This section mainly describes how the underlying ledger module of the blockchain implements the archiving function.
[0088] The archiving function designed in the present invention is single-node archiving, that is, the user archives a single peer node, and full synchronization can be achieved for nodes newly added to the channel. In addition, the latest configuration block is not archived.
[0089] To implement the archiving function, we must first understand the main logic related to blocks in the blockchain. Blocks in Farbic are isolated from each other by channels, and the node block data in the same channel will be synchronized to be consistent. Blocks are divided into configuration blocks and transaction blocks. Configuration blocks are blocks generated after modifications are made to the channel, and transaction blocks are blocks generated after users perform endorsement transactions. Special blockchains will automatically generate a genesis block after startup, and the genesis block is also a configuration block. For the identification of blocks, at the user level, they are distinguished by block height, that is, the block number. The block height represents the number of blocks in the channel, and the block height starts from 1. In the underlying logic, the block information in the channel is identified by the block number, which starts from 0, and block 0 is the genesis block.
[0090] See also Figure 2The archiving function is displayed to the user by showing the current block height, and then the user enters the specified block height to be archived, that is, all blocks from the first block to the block height specified by the user are archived. After the page receives the specified height, it is passed by the SDK to the query system chain code. The system chain code should first check whether the current block height meets the archiving requirements, then check whether the current archived height can be archived, and then query the archived block data, encrypt it and store it in the specified storage medium, and finally send it to the block file manager through grpc to trigger the underlying archiving logic.
[0091] The implementation and transformation of the underlying ledger module for archiving is as follows: According to the above, the block file manager controls the process of generating blocks from block data. The present invention implements the block archiving function in the block file manager. For the block manager, a new archiving database should be added to store the current archiving height to anchor the current archiving progress. Figure 2 After receiving the specified archiving height, the block file manager first queries the current archived height to verify whether it meets the archiving logic requirements. Then query the mapping relationship between the block number and the offset in the index database. This mapping describes the file information of the specified block, including its block file name and the specific location in the block file. At the same time, query the block mapping relationship of the height to be archived, that is, the block file pointer, to obtain the information of its block file. Through the above logic, an interval from the current archived height to the specified height can be determined. Cyclic archiving is performed in this interval. First, the last configuration block number is read from the archive database, and then the current archive block number is verified to avoid archiving the last configuration block. Then, the file pointer of the current block to be archived is obtained from the index database through the block number, and the corresponding file name, starting offset, and offset are obtained. Finally, through file operations, the data of the corresponding block offset is cleared. After the cycle ends, the archived height in the archive database is updated to complete the archiving operation.
[0092] 4.3 Confidential Storage
[0093] This section mainly describes the process of how to encrypt block data when it is stored off-chain in Section 4.2.
[0094] In order to ensure the security of cold data storage and prevent leakage, the present invention adopts the method of encrypting the original block data before storage. The encryption algorithm is a national secret. Each platform user has his own pair of user public and private keys. At the same time, the platform has a pair of platform public and private keys to implement encryption protection of user public and private keys. The user public key is encrypted with the platform public key and stored in the platform database. Figure 2When the user performs an archiving operation, the block data to be archived will be read from the blockchain, and then the corresponding user's public key will be read from the system database, and the platform private key will be used to decode it into plain text. Then, this user public key will be used to encrypt the block data to be archived, and the encrypted ciphertext will be stored in the local file system or database.
[0095] Through the above operations, the block data stored in the off-chain database is ciphertext, which effectively ensures the security of block cold data. When querying cold data, the user's private key can be used to decrypt the ciphertext block data and then query the corresponding data.
[0096] 4.4 Recovery Block
[0097] This section mainly describes the process of how to restore archived block data to the chain.
[0098] This invention supports restoring archived block data to the chain. Figure 2 , the user needs to enter a starting recovery height, which means that all blocks from the block number corresponding to this block height to the block number corresponding to the archived block height are restored on the chain. Due to the characteristics of the block being tamper-proof, the generated block data will not change, and the local storage will use a flag to mark whether this block has been archived. When restoring, the off-chain storage will not delete the block data, so that the user will be able to archive much faster when archiving repeatedly.
[0099] See also Figure 2 When restoring, the platform will query the block data to be restored from the off-chain, and pass it and the starting recovery height to the query system chain code through the SDK. The system chain code first obtains the archived height on the chain, determines whether the starting recovery height is legal, and then establishes an interval from block number 0 to the block number of the object to be restored. The block recovery operation is performed in order from the archived height to the starting recovery height, from high to low. During this period, the off-chain storage will be accessed to obtain the corresponding block data and then the private key stored in the system database by the user will be read. The platform private key is used for decryption to decrypt the ciphertext block data. Each call to the underlying interface of the ledger will only restore one block.
[0100] When the block file manager receives the incoming starting recovery height and the corresponding block data, it will read the configuration block height from the archive database, check whether the block is the last configuration block, and if so, exit without restoring the latest configuration block. If it is not the last configuration block, it will get the corresponding file pointer from the index database according to the block number, get the block file where the block is located and the starting offset and file offset, and write the block data to the position determined by the offset to complete a single recovery operation.
[0101] 4.5 Query Cold Data
[0102] This section mainly describes the adaptation of Fabric's original block query capability for archive recovery.
[0103] The archiving designed by the present invention has the function of cold data querying off-chain, that is, when the block data queried by the user has been archived, the on-chain query will filter the corresponding error information, and then query the corresponding information in the off-chain storage system and return it to the user.
[0104] The present invention is adapted to the query interface native to Fabric, including querying blocks according to block numbers, querying blocks according to block hashes, querying transactions according to transaction IDs, and querying blocks according to transaction IDs. After querying archived data for these four queries, the block file manager will return an error message that the block has been archived. If the error message contains this, the block data will be queried from the off-chain storage system according to the corresponding information. If the query is for a block, after obtaining the block data plaintext by restoring the decryption operation of the block data ciphertext, the structure of the block is obtained using the built-in decoding operation of Fabric and returned. At the same time, the interface for querying according to the transaction ID needs to add an index mapping the transaction ID to the block number in the index database.
[0105] Figure 3 FIG. 1 is a schematic diagram of a block data storage device based on Fabric in one embodiment of the present invention. Figure 3 In one embodiment of the present invention, a block data storage device based on Fabric includes:
[0106] The archiving condition determination module 301 is configured to determine the blocks and block heights that meet the archiving conditions for the blockchain based on Fabric;
[0107] The archiving processing module 302 is configured to obtain corresponding block data from the blockchain according to the determined blocks and block heights that meet the archiving conditions, and to clear the obtained block data on the blockchain;
[0108] The off-chain processing module 303 is configured to encrypt the acquired block data and store the encrypted block data in an archive database offline in the blockchain.
[0109] In one embodiment of the apparatus of the present invention, the archiving condition includes: the frequency of access to the data in the block is lower than a preset access frequency threshold; and / or the time interval between the last access time of the data in the block and the current time is greater than a preset interval threshold; and / or the length of time the data in the block is stored on the blockchain is greater than a preset duration threshold.
[0110] In one embodiment of the apparatus of the present invention, when the archiving processing module 302 obtains the corresponding block data from the blockchain according to the determined blocks and block heights that meet the archiving conditions, it is configured to execute:
[0111] Query the mapping relationship between the block number and the offset in the index database, and query the block file pointer to obtain the information of the corresponding block file, so as to determine a first height interval from the previously archived block height to the block height on the current blockchain that needs to be archived;
[0112] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the last configuration block number on the blockchain is first read, and the last configuration block number read is compared with the block number of the current block to avoid archiving the last configuration block on the blockchain. If they are different, the file pointer of the current block is obtained from the index database through the block number of the current block, and the corresponding file name, starting offset, and offset are obtained, thereby obtaining the data of the current block corresponding to the block offset;
[0113] In one embodiment of the apparatus of the present invention, when the archive processing module 302 clears the acquired block data on the blockchain, it is configured to execute:
[0114] In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the data of the corresponding block offset is cleared through file operations.
[0115] In one embodiment of the apparatus of the present invention, the archive database is a local storage resource or a cloud storage resource.
[0116] In one embodiment of the apparatus of the present invention, the archiving processing module 302 is further configured to execute:
[0117] If a block to be archived is a configuration block but not the last configuration block, there is no need to clear the data of the configuration block from the blockchain; if a block to be archived is a transaction block, the above-mentioned process of clearing the acquired block data on the blockchain is performed.
[0118] In one embodiment of the device of the present invention, see Figure 4 , the Fabric-based block data storage device may further include: a recovery processing module 401;
[0119] The recovery processing module 401 is configured to execute:
[0120] Get the starting recovery block height;
[0121] Determine a second height interval between the starting recovery block height and the latest archived block height in the archive database;
[0122] In the archive database, decrypt the block data in the determined second height interval;
[0123] The decrypted block data is restored to the blockchain.
[0124] See also Figure 4 In one embodiment of the device of the present invention, when restoring the decrypted block data to the blockchain, the recovery processing module 401 specifically performs:
[0125] For each block in the determined second height interval, execute the following loop in sequence:
[0126] For the current block, determine whether the current block is the last configuration block on the blockchain. If so, skip it. If it is a configuration block but not the last configuration block, copy it at the block position of the configuration block on the blockchain.
[0127] See also Figure 3 , Figure 4 In an embodiment of the device of the present invention, a user public-private key pair and a platform public-private key pair are pre-set; the user public key is encrypted using the platform public key, and then the encrypted user public key is stored in the system database of the blockchain;
[0128] When encrypting the acquired block data, the downlink processing module 303 is specifically configured to execute: after reading the block data that meets the archiving conditions from the blockchain, read the corresponding encrypted user public key from the system database, use the platform private key to decode the encrypted user public key into a plaintext user public key, and then use the user public key to encrypt the block data to be archived;
[0129] When decrypting the block data in the determined second height interval, the recovery processing module 401 is specifically configured to execute: decrypting the block data in the determined second height interval using the corresponding user private key.
[0130] It should be noted that the above-mentioned devices are usually implemented on the server side, and can be set on independent servers respectively, or some or all of the devices can be combined and set on the same server. The server can be a single server or a server cluster composed of multiple servers. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system. The above-mentioned devices can also be implemented on a computer terminal with strong computing power.
[0131] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute a method in any one of the embodiments in the specification.
[0132] An embodiment of the present invention provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method in any embodiment of the specification is implemented.
[0133] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the device of the embodiment of the present invention. In other embodiments of the specification, the above-mentioned device may include more or fewer components than those shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0134] The various embodiments of the present invention are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0135] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, widgets, or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0136] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method 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 on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A block data storage method based on Fabric, characterized in that: The method includes: For Fabric-based blockchains, determine the blocks and block heights that meet the archiving conditions; According to the determined blocks and block heights that meet the archiving conditions, corresponding block data is obtained from the blockchain, and the obtained block data is cleared on the blockchain; The obtained block data is encrypted and stored in the offline archive database of the blockchain.
2. The method according to claim 1, characterized in that The archiving conditions include: the frequency of access to the data in the block is lower than a preset access frequency threshold; and / or the time interval between the last access time of the data in the block and the current time is greater than a preset interval threshold; and / or the length of time the data in the block is stored on the blockchain is greater than a preset duration threshold.
3. The method according to claim 1, characterized in that The obtaining corresponding block data from the blockchain according to the determined blocks and block heights meeting the archiving conditions includes: Query the mapping relationship between the block number and the offset in the index database, and query the block file pointer to obtain the information of the corresponding block file, so as to determine a first height interval from the previously archived block height to the block height on the current blockchain that needs to be archived; In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the last configuration block number on the blockchain is first read, and the last configuration block number read is compared with the block number of the current block to avoid archiving the last configuration block on the blockchain. If they are different, the file pointer of the current block is obtained from the index database through the block number of the current block, and the corresponding file name, starting offset, and offset are obtained, thereby obtaining the data of the current block corresponding to the block offset; The obtained block data is cleared on the blockchain, including: In the determined first height interval, the process is executed in a loop from the first block to the last block: for the current block, the data of the corresponding block offset is cleared through file operations.
4. The method according to claim 1, characterized in that: The archive database is a local storage resource or a cloud storage resource.
5. The method according to claim 1, characterized in that The method further comprises: If a block to be archived is a configuration block but not the last configuration block, there is no need to clear the data of the configuration block from the blockchain; if a block to be archived is a transaction block, the above-mentioned process of clearing the acquired block data on the blockchain is performed.
6. The method according to claim 1, characterized in that After storing the encrypted block data in an archive database offline in the blockchain, the method further includes: Get the starting recovery block height; Determine a second height interval between the starting recovery block height and the latest archived block height in the archive database; In the archive database, decrypt the block data in the determined second height interval; The decrypted block data is restored to the blockchain.
7. The method according to claim 6, characterized in that The restoring the decrypted block data to the blockchain includes: For each block in the determined second height interval, execute the following loop in sequence: For the current block, determine whether the current block is the last configuration block on the blockchain. If so, skip it. If it is a configuration block but not the last configuration block, copy it at the block position of the configuration block on the blockchain.
8. The method according to claim 6, characterized in that The method further includes: presetting a user public-private key pair and a platform public-private key pair; encrypting the user public key using the platform public key, and then storing the encrypted user public key in a system database of the blockchain; The encrypting of the acquired block data includes: after reading the block data meeting the archiving condition from the blockchain, reading the corresponding encrypted user public key from the system database, using the platform private key to decode the encrypted user public key into a plaintext user public key, and then using the user public key to encrypt the block data to be archived; Decrypting the block data in the determined second height interval includes: decrypting the block data in the determined second height interval using a corresponding user private key.
9. A block data storage device based on Fabric, characterized in that: The device includes: The archiving condition determination module is configured to determine the blocks and block heights that meet the archiving conditions for the Fabric-based blockchain; The archiving processing module is configured to obtain corresponding block data from the blockchain according to the determined blocks and block heights that meet the archiving conditions, and to clear the obtained block data on the blockchain; The off-chain processing module is configured to encrypt the acquired block data and store the encrypted block data in an archive database offline in the blockchain.
10. A computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Blockchain data storage method and device
CN111708835A
Block chain data management method and device, electronic equipment and medium
CN112925479A
Data archive
US20210342291A1
Blockchain block data archiving method and apparatus, and query method and apparatus
WO2019024673A1
Blockchain data clipping method and apparatus, node recovery method and apparatus, and device and medium
WO2021218300A1
Cited By
Intelligent contract-driven supply chain economic optimization method
CN121998204A