Block data storage method based on coding and related device
By encoding block data in the blockchain network and distributing encoded fragment storage, the problem of excessive storage demand in the prior art is solved, and the effect of reducing node storage requirements while ensuring data integrity and security is achieved.
Patent Information
- Application Number
- CN202510746117.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-02
AI Technical Summary
It is difficult for existing blockchain systems to effectively reduce the storage demand for node block data while ensuring data integrity and security, resulting in the continuous growth of storage demand, increasing the threshold for node participation and may threaten the decentralized characteristics and attack resistance.
The encoded-based block data storage method is adopted to generate encoded fragments by encoding the block data in error correction code, and stored in the encoded fragment storage area within the blockchain network, and collect encoded fragments from the client nodes for decoding and recovery data when needed, reducing the storage needs of the nodes.
It effectively reduces the storage requirements of node block data, while ensuring the integrity and availability of data, and does not affect the security and decentralization characteristics of the blockchain.
Smart Images

Figure CN120578718A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a coding-based block data storage method and related devices. Background Art
[0002] Blockchain is a distributed system that enables trust between strangers and independent entities. Its advantages, such as openness, transparency, distributed storage, and tamper resistance, have led to its widespread adoption in various fields, including finance, healthcare, and the Internet of Things. However, as its scope of application continues to expand and its usage time continues to accumulate, the storage requirements of nodes are increasing. Blockchain storage scalability is becoming increasingly prominent and is becoming a key obstacle to its development. Current blockchain systems require all nodes to store a complete copy of the blockchain, which drives up the storage demands of participating nodes. This massive storage requirement not only raises the barrier to participation but also poses serious security risks. For example, resource-rich nodes could monopolize or even manipulate the network, threatening the blockchain's decentralization and attack resistance.
[0003] To address this challenge, existing technologies have proposed a variety of solutions, such as dividing blockchain nodes into light nodes and full nodes for storage, using pruning technology to delete unnecessary blockchain information, or using sidechain nodes for storage. However, these solutions struggle to effectively reduce the storage requirements for node block data while ensuring the integrity and security of blockchain data. Summary of the Invention
[0004] The present invention provides a coding-based block data storage method and related devices, which are used to solve the technical problem that existing block data storage methods are difficult to effectively reduce the storage requirements of node block data while ensuring the integrity and security of blockchain data.
[0005] The present invention provides a block data storage method based on coding, the method comprising:
[0006] When receiving a registration request sent by a client node, returning a connection identifier to the client node;
[0007] Storing the block data of each block in the blockchain network into the block data storage area;
[0008] According to a preset coding sequence, k blocks are grouped as a block group, and error correction coding is performed on the block data of the block group to generate a plurality of coding segments corresponding to the block group and store them in a coding segment storage area;
[0009] According to the preset usage rate, the coding segments of the corresponding block group are generated into sending records based on the shuffling algorithm, the coding segments of the corresponding block group and the sending records are propagated to the corresponding client nodes for storage, and the corresponding coding segments in the coding segment storage area are deleted;
[0010] When a target data request is received, a search is performed in the block data storage area; if the search fails in the block data storage area, a search is performed in the code segment storage area according to the code segment number corresponding to the target data; if the search is successful, the code segment found in the code segment storage area is decoded and reconstructed to generate the target data;
[0011] If the search fails in the coding segment storage area, a coding segment request is sent to the corresponding client node according to the required coding segment number. When a preset number of coding segments are received, the preset number of coding segments are decoded to reconstruct the target data.
[0012] Optionally, when receiving a registration request sent by the client node, the step of returning the connection identifier to the client node includes:
[0013] When receiving a registration request sent by a client node, it is determined according to the preset connection library whether the number of currently registered client nodes exceeds the preset number of registered connections. If not, the connection identifier is returned to the client node, so that the client node upgrades the HTTP connection to a WebSocket connection according to the connection identifier.
[0014] Optionally, the step of taking k blocks as a block group according to a preset coding order, performing an error correction code encoding operation on block data of the block group, generating a plurality of coding segments corresponding to the block group, and storing the generated coding segments in the coding segment storage area includes:
[0015] According to a preset coding order, k blocks are grouped as a block, and a coding matrix corresponding to the block group is generated based on an error correction code;
[0016] An encoding operation is performed according to the block data of the block group and the encoding matrix to generate n encoding segments corresponding to the block group, and the n encoding segments of the block group are stored in the encoding segment storage area.
[0017] Optionally, the method further includes: storing the reconstructed target data in a block data storage area.
[0018] Optionally, if the search in the code segment storage area fails, a code segment request is sent to a corresponding client node according to the required code segment number, and when a preset number of code segments are received, decoding the code segments that meet the preset number is performed to reconstruct and generate target data, including:
[0019] If the search fails in the code segment storage area, a holding record request task is sent to all client nodes in the node group; wherein the holding record is generated by the client node according to the received sending record;
[0020] Determine the required encoding segment number based on the holding record returned by the client node in the node group, and return the required encoding segment number to the client node to request the encoding segment;
[0021] When a preset number of coding segments are received, an empty response is returned to the client node in the node group, and the coding segments that meet the preset number are decoded to reconstruct and generate target data.
[0022] Optionally, each coding segment in the block group is generated as follows:
[0023]
[0024] Where: represents the jth coded segment, Represents the block data in the block group, G represents the encoding matrix, where G consists of two parts, the upper part is the k-order unit matrix E k , the lower part is the parity check matrix with m rows and k columns used to correct data errors.
[0025] The present invention also provides a block data storage system based on coding, comprising:
[0026] a connection unit, configured to return a connection identifier to the client node upon receiving a registration request sent by the client node;
[0027] A block data storage unit, used to store the block data of each block in the blockchain network into the block data storage area;
[0028] a coding storage unit, configured to treat k blocks as a block group according to a preset coding sequence, perform an error correction coding operation on block data of the block group, generate a plurality of coding segments corresponding to the block group, and store the generated coding segments in a coding segment storage area;
[0029] a propagation unit, configured to generate a sending record for the coding segment of the corresponding block group based on a shuffling algorithm according to a preset usage rate, propagate the coding segment of the corresponding block group and the sending record to the corresponding client node for storage, and delete the corresponding coding segment in the coding segment storage area;
[0030] a target search unit configured to search the block data storage area upon receiving a target data request; if the search fails in the block data storage area, search the code segment storage area according to the code segment number corresponding to the target data; if the search succeeds, decode the code segment found in the code segment storage area to reconstruct the target data;
[0031] The node search unit is used to send a code segment request to the corresponding client node according to the required code segment number if the search fails in the code segment storage area. When the code segments that meet the preset number are received, the code segments that meet the preset number are decoded to reconstruct and generate target data.
[0032] The present invention further provides a computer device comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the block data storage method as described above.
[0033] The present invention also provides a computer-readable storage medium having a computer program / instruction stored thereon, which implements the steps of the block data storage method as described above when the computer program / instruction is executed by a processor.
[0034] The present invention also provides a computer program product, comprising a computer program / instruction, which implements the steps of the block data storage method as described above when executed by a processor.
[0035] It can be seen from the above technical solutions that the present invention has the following advantages:
[0036] The present invention provides a block data storage method based on coding and a related device, the method comprising: when receiving a registration request sent by a client node, returning a connection identifier to the client node; storing the block data of each block in the blockchain network in a block data storage area; using k blocks as a block group according to a preset coding sequence, performing an error correction code encoding operation on the block data of the block group, generating a plurality of coding segments corresponding to the block group and storing them in a coding segment storage area; generating a sending record based on a shuffling algorithm for the coding segments of the corresponding block group according to a preset usage rate, and propagating the coding segments and the sending record of the corresponding block group to the corresponding client node for storage. and delete the corresponding coding segment in the coding segment storage area; when a target data request is received, search is performed from the block data storage area; if the search from the block data storage area fails, search is performed from the coding segment storage area according to the coding segment number corresponding to the target data, if the search is successful, the coding segment found from the coding segment storage area is decoded, and the target data is reconstructed; if the search from the coding segment storage area fails, a coding segment request is issued to the corresponding client node according to the required coding segment number, and when a preset number of coding segments are received, the coding segments that meet the preset number are decoded, and the target data is reconstructed.
[0037] In this invention, block data is encoded based on coding technology, and its encoded fragments are stored in a code fragment storage area or distributed to each node of the blockchain for storage. When the code fragment storage area cannot find the encoded fragment of the target data to be verified, the encoded fragments are collected from each node and decoded to restore the complete block data. This method not only effectively reduces the storage requirements of node block data, but also ensures data integrity and availability through error-correcting code technology, while also ensuring the security of the blockchain. This solves the technical problem that existing block data storage methods are difficult to effectively reduce the storage requirements of node block data while ensuring the integrity and security of blockchain data. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 A flowchart of a block data storage method based on coding provided by an embodiment of the present invention;
[0040] Figure 2A flowchart of a specific implementation of a block data storage method based on coding provided by an embodiment of the present invention;
[0041] Figure 3 This is a structural block diagram of a coding-based block data storage system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The embodiments of the present invention provide a coding-based block data storage method and related devices, which are used to solve the technical problem that existing block data storage methods are difficult to effectively reduce the storage requirements of node block data while ensuring the integrity and security of blockchain data.
[0043] In order to make the purpose, features, and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0044] The method provided in this application involves relevant concepts of blockchain data storage. For ease of understanding, the relevant concepts of blockchain data storage involved are introduced below.
[0045] Blockchain: Blockchain is used to record and store information. It uses a decentralized approach, allowing multiple computers (nodes) to jointly maintain a record that cannot be tampered with. Blockchain records data similarly to a public ledger. Every time a new transaction occurs, a new "block" is generated. This block contains transaction details and is linked to the previous block, forming a "chain." This approach ensures information security and immutability.
[0046] Full nodes: In a blockchain network, full nodes are computers that not only verify blockchain data but also store the entire blockchain's history. Full nodes ensure the integrity and transparency of the blockchain network because they store all blockchain data and can verify and update it at any time.
[0047] Ethereum: Ethereum is an open, decentralized digital platform, like a global computer network, that allows anyone to create and run applications. Unlike standard applications, Ethereum applications are decentralized, meaning no single company or institution controls them. Ethereum's core feature is "smart contracts," programs that execute automatically without human intervention.
[0048] Smart Contracts: A smart contract is an automated program that runs on Ethereum. It automatically executes its terms when the conditions set in the contract are met. For example, you and a friend could agree to transfer a certain amount of money to each other if a certain condition is met, without the need for an intermediary. Smart contracts ensure transparency and fairness because the execution of each contract is publicly visible and cannot be altered on the blockchain.
[0049] Error-correcting codes: Error-correcting codes are primarily used to protect data security. They split the original data into multiple parts and generate redundant data blocks. This ensures that even if some data is lost, the remaining data can still be restored to its original state. This approach is more efficient than traditional replication storage methods (such as backing up each piece of data separately) and saves storage space.
[0050] Encoded storage: Encoded storage involves converting data using a coding method to enable more efficient storage. For example, error-correcting codes can be used to split data and generate redundant parts to ensure data recovery in the event of loss or corruption. This not only reduces storage space usage but also ensures data security.
[0051] Decoding: Decoding is the process of restoring data that has been converted using encoding methods back to its original form. In error-correcting code storage, data is stored after being split and redundantly encoded. If some parts are lost or damaged, decoding can be used to reassemble the remaining redundant data and restore the original data. Decoding is a critical step in data recovery.
[0052] The following further describes the existing technical solutions for reducing the storage requirements of node block data.
[0053] Solution 1: Blockchain nodes can be divided into two types: light nodes and full nodes. The former only stores block headers, while the latter stores complete blocks. Therefore, light nodes lack the ability to independently verify transactions within a block and rely on full nodes to perform simplified payment authentication to verify the legitimacy of transactions within the block. This approach significantly reduces the storage requirements of light nodes in the blockchain, making it easier for nodes to participate in the blockchain. However, light nodes have weak verification capabilities and are easily deceived by malicious nodes masquerading as full nodes. Furthermore, the presence of full nodes can lead to a semi-centralized blockchain, contradicting its decentralized nature.
[0054] Option 2: Sharding can be used to divide a large blockchain into multiple subchains. Each subchain is equivalent to an independent blockchain, operated by a group of nodes or communities. A node belongs to a single community, meaning it only needs to store a given portion of the blockchain. Therefore, node storage requirements decrease proportionally with the number of shards. In fact, they scale logarithmically with the number of communities. This effectively reduces the size of the blockchain, thereby reducing the storage requirements of nodes in the subchains. However, sharding technology requires addressing issues related to cross-chain verification and subchain merging, which further increases node complexity.
[0055] Option 3: Use pruning technology to delete unnecessary blockchain information. However, pruning a blockchain permanently loses the pruned information. This makes it less applicable to blockchains that require ready access to historical information, such as those used for medical services. Furthermore, as the number of subchains increases, blockchain security decreases, making it easier for attackers to compromise subchains.
[0056] Option 4: Sidechain nodes can be used for storage. Sidechains are secondary blockchains connected to the main blockchain through a two-way peg. Digital assets can be transferred between the main chain and the sidechain, reducing the number of transactions on the main chain and, in turn, lowering storage requirements. Sidechains can have completely different consensus protocols, algorithms, or models from the main chain. Therefore, sidechains not only reduce the storage requirements of mainchain nodes but also potentially add new functionality to the blockchain, enhancing the privacy and security of traditional blockchains. However, sidechain nodes typically store the block hashes and execution status of the sidechain. The main chain only ensures the data integrity of each sidechain but cannot verify the authenticity of transactions executed within it. This poses the risk of data availability attacks (DAA). A malicious sidechain node could implement DAA by only providing block hashes to the main chain without sharing blocks with other nodes in the same sidechain.
[0057] It can be seen that existing solutions are difficult to effectively reduce the storage requirements of node block data while ensuring the integrity and security of blockchain data. To this end, the present invention provides a coding-based block data storage method. Based on coding technology, block data is encoded and its encoded fragments are distributed to each node of the blockchain for storage. When the complete block is required for verification, the encoded fragments are collected from each node and decoded to restore the complete block data. This method can not only effectively reduce the storage requirements of node block data, but also ensure data integrity and availability through error-correcting code technology, while also ensuring the security of the blockchain.
[0058] See also Figure 1 and Figure 2 The present invention provides a block data storage method based on coding, comprising:
[0059] Step 101: When a registration request is received from a client node, a connection identifier is returned to the client node.
[0060] It should be noted that this invention aims to reduce the storage requirements of full nodes in a blockchain through encoding technology, thereby proposing a feasible method to alleviate the storage scalability problem of blockchain. In this embodiment, nodes within a certain distance are considered a node group, which will jointly bear the block data storage requirements of a full blockchain node. A node group generally includes a server node and several client nodes, and this method is applied to the server node.
[0061] Specifically, when a registration request is received from a client node, the preset connection library is used to determine whether the number of currently registered client nodes exceeds the preset number of registered connections. If not, the connection identifier is returned to the client node, so that the client node upgrades the HTTP connection to a WebSocket connection according to the connection identifier.
[0062] It is understandable that before subsequent encoding and decoding operations, the server node needs to confirm the current online status of the client node, so the client node needs to connect to and register with the server node in advance, which is also the basis for the subsequent dissemination of encoded fragments. At the same time, in order to maintain the connection between the server node and the client node, the server node establishes a preset connection library, where the preset connection library includes the registered connection number CurrentLink and the connection list RegisterChanList. The registered connection number refers to the number of client nodes currently connected to the server node. Its type is an atomic integer, which is used to conveniently obtain the current number of registered client nodes and control the number of registered client nodes to not exceed the preset number of registered connections; the connection list is a bidirectional linked list, which is used to store the connection between the server node and each registered client node, and retrieve the corresponding connection identifier from it when the server node needs to distribute or collect encoded fragments.
[0063] In addition, the connection between the server node and the client node is generally persistent. In this embodiment, when the client node registers, its HTTP connection with the server node will be upgraded to a WebSocket connection. Among them, the WebSocket connection is a protocol for full-duplex communication on a single TCP connection. It allows real-time two-way communication between the client and the server, breaking the limitation that the request-response mode of the traditional HTTP protocol connection can only be initiated by the client. After that, the two can persistently transmit the encoded fragments through the connection. The server node will also periodically send a ping request to the client node to confirm the connection status and update the number of currently connected client nodes and the client node connection list. It is worth noting that in the absence of a client node connection, the block data storage method based on encoding technology will not be enabled, but the original block data of the block group will be directly retained.
[0064] Step 102: Store the block data of each block in the blockchain network into the block data storage area.
[0065] It is understandable that the storage capacity of the block data storage area is limited, so in practical applications, the block data in each block can be filtered and stored according to the actual usage rate.
[0066] Step 103 : k blocks are grouped as a block group according to a preset coding sequence, and error correction coding is performed on the block data of the block group to generate a plurality of coding segments corresponding to the block group and store them in a coding segment storage area.
[0067] This step specifically includes:
[0068] In sub-step 1031 , k blocks are grouped as a block group according to a preset coding sequence, and a coding matrix corresponding to the block group is generated based on an error correction code.
[0069] Sub-step 1032 , performing encoding operation according to the block data of the block group and the encoding matrix, generating n encoding segments corresponding to the block group, and storing the n encoding segments of the block group into the encoding segment storage area.
[0070] It should be noted that, considering the encoding and transmission costs of block data, a reasonable k value should be set in advance based on the average block data size in practical applications. When the blockchain network generates k blocks, its data is encoded.
[0071] This embodiment uses Reed-Solomon (RS) error correction code for encoding and decoding. This error correction code is a technology widely used in industrial data transmission. RS code achieves fault tolerance based on data redundancy. RS error correction code has two significant advantages: First, when the encoding parameter When it is determined, the same encoding matrix G can be generated for the same set of block data. This means that the nodes on the blockchain have the ability to encode and decode the same set of block data, and can determine whether the encoded fragment data has been maliciously tampered with by verifying the hash; secondly, the encoded fragment may be lost when it is transmitted between nodes, and the m verification code fragments with error correction capabilities in the encoded fragment generated by the error correction code have a considerable fault tolerance when collecting and decoding the encoded fragments.
[0072] Specifically, the block data of k blocks are encoded based on the RS code to obtain k data encoding segments and m check encoding segments, that is, n encoding segments are obtained, n=k+m; wherein each data encoding segment corresponds to one block data.
[0073] For ease of understanding, use the block data matrix Represents the block data of a block group, uses matrix G to represent the encoding matrix and uses matrix represents the set of coded segments obtained after encoding, then the j-th coded segment can be calculated as follows:
[0074]
[0075] Among them, the encoding matrix G consists of two parts, the upper part is the k-order unit matrix E k The lower part is the parity check matrix with m rows and k columns used to correct data errors. , where each element is a pseudo-random number. 8 )) can find a unique solution from k and m.
[0076] The encoding matrix G is multiplied by the block data matrix X to obtain the encoding fragment matrix F, as shown below:
[0077]
[0078] Right now:
[0079]
[0080] After obtaining a plurality of coding segments corresponding to the block group, the coding segments are stored in a coding segment storage area.
[0081] Step 104 : Generate a sending record for the coding segment of the corresponding block group based on a shuffling algorithm according to a preset usage rate, propagate the coding segment of the corresponding block group and the sending record to the corresponding client node for storage, and delete the corresponding coding segment in the coding segment storage area.
[0082] It should be noted that in order to maximize the utilization of storage space, if the usage rate of the block group exceeds the preset usage rate, the coding segments of the block group are stored in the coding segment storage area; if the usage rate of the block group does not exceed the preset usage rate, the coding segments of the block group are propagated and stored on the client nodes in the node group, and the corresponding coding segments in the coding segment storage area are deleted.
[0083] In order to maximize the storage space utilization of each node in the node group, the coding segments stored in each node should be as different as possible; at the same time, the number of coding segments stored in the node should not be too many, otherwise the storage demand will be reduced to a limited extent; of course, it should not be too few, otherwise the node will need to frequently broadcast requests for other coding segments for decoding and reconstruction of block data, thereby greatly increasing communication costs.
[0084] To ensure the randomness and uniqueness of the coded segments stored by each node, in this embodiment, before distributing the coded segments to each client node, the server node first generates a corresponding coded segment sending record (sendRec) for each client node using a shuffling algorithm. The sendRec record is sent along with the specified coded segment to the client node and stored as a coded segment holding record (keepRec) for that group of block data. The sendRec record includes the connection number of the client node to be disseminated, the set of coded segment labels for different block groups, and the data length of the coded segment; the hold record (keepRec) includes the set of coded segment labels corresponding to the coded segments of the block group held by the client node, as well as the data length of the coded segment.
[0085] In addition, when implementing the propagation function, the advantages of the Golang programming language in concurrent coroutines are fully utilized, and the distribution fragments and collection fragments are decomposed into subtasks based on coroutines, thereby reducing the operating system resource overhead; at the same time, the distribution fragments are designed to be asynchronous mode so that they will not block the main coroutine, reducing the system's resource allocation in communication.
[0086] Step 105: When a target data request is received, a search is performed in the block data storage area. If the search in the block data storage area fails, a search is performed in the code segment storage area according to the code segment number corresponding to the target data. If the search is successful, a decoding operation is performed on the code segment found in the code segment storage area to reconstruct and generate the target data.
[0087] In this step, when a server node receives a verification request for target data, it first checks the block data storage area. If the target data is not found, it checks the code segment storage area. Finally, it collects code segments from other nodes in the node group and decodes and reconstructs them. In other words, only when the server node has neither the original block data nor the corresponding code segment for the target data it needs will it broadcast the collected code segments to other nodes in the node group for decoding and reconstruction. Each code segment is assigned a corresponding code segment number for easy reference.
[0088] Step 106: If the search in the code segment storage area fails, a code segment request is sent to the corresponding client node according to the required code segment number. When a preset number of code segments are received, the preset number of code segments are decoded to reconstruct the target data.
[0089] In this embodiment, to improve decoding efficiency, all client nodes maintain their own record, keepRec, for each block data set. When a server node needs to collect the coded segments corresponding to a particular block data set, it first requests the corresponding keepRec from other client nodes in the node group. The server node then selects unique coded segments from these segments and returns the required coded segment identifier to the corresponding client node for request.
[0090] This step specifically includes:
[0091] Sub-step 1061: If the search in the code segment storage area fails, a holding record request task is sent to all client nodes in the node group; the holding record is generated by the client node according to the received sending record.
[0092] It should be noted that the server node does not need to confirm the keepRec of all client nodes before initiating the corresponding coding segment request, and the server node does not need to wait for the response of all client nodes. Instead, it can immediately start processing the received holding records to determine the different and required coding segment labels, thereby reducing the repeated coding segment transmission as much as possible and further reducing the coding segment propagation communication cost of the system.
[0093] Among them, the code segment transmission coroutines between each client node and the server node do not interfere with each other. Once the required code segment of a client node is confirmed, it is immediately requested to transmit the code segment.
[0094] Sub-step 1062: determining the required encoding segment number based on the holding record returned by the client node in the node group, and returning the required encoding segment number to the client node to request the encoding segment.
[0095] Sub-step 1063, when the preset number of code segments is received, an empty response is returned to the client node in the node group, and the code segments that meet the preset number are decoded to reconstruct and generate target data.
[0096] It should be noted that for a set of block data, once the server node holds at least k coded segments, it can decode and reconstruct the corresponding target data. Furthermore, once the server node has collected enough coded segments, it will directly return an empty response to other client nodes in the node group, eliminating the need for the client nodes to continue disseminating the coded segments. This reduces the transmission of duplicate coded segments and further reduces the communication cost of disseminating the coded segments.
[0097] Among them, the matrix Represents the set of coded segments held by the server node and uses matrix G' to represent the decoding matrix; the decoding matrix G' is composed of several row elements in the encoding matrix G. Then, after the server node collects a preset number of coded segments (no less than k), it can decode by multiplying the collected holding matrix F' by the inverse of the decoding matrix G' to obtain the target data matrix , as shown below:
[0098]
[0099] Right now:
[0100]
[0101] Step 107: Store the reconstructed target data into the block data storage area.
[0102] It is understandable that the target block data reconstructed through this request will not be actively cleared by the server node. For block data with a high reuse rate, this setting reduces the time complexity of the server node's block data request and reduces the communication cost of the encoding fragments between nodes.
[0103] At the same time, considering the scalability of the system, the server node can also select specific block data through a specified interface for search, recovery, or deletion. It can also choose to clear redundant data encoding fragments based on the held records or synchronize the current block group encoding fragments with the corresponding held records. This improves the ability to be compatible with other block data and encoding fragment scheduling strategies.
[0104] The block data storage method based on coding provided by the present invention has the following advantages:
[0105] 1. Encode the block data based on coding technology and distribute the encoded fragments to each node of the blockchain for storage. By increasing the communication cost within an acceptable range to reduce the block data storage requirements of each node in the node group, the storage requirements of the node block data are effectively reduced.
[0106] 2. This method does not require the blockchain itself to be split, nor does it require the permanent abandonment of part of the block data, thus ensuring the integrity of the blockchain and the block data therein, which leaves the security performance of the blockchain unaffected.
[0107] 3. The availability of block data is guaranteed. Although the server node in the node group only holds part of the block data, it can collect coding fragments from other nodes in the group when necessary to decode and restore the block data. At the same time, based on the node aggregation technology, fast decoding can be achieved to collect and restore data. Compared with the light node method, the availability of block data is further guaranteed.
[0108] 4. The coding fragments used are universal across all blockchain nodes, open and transparent, can achieve distributed storage, and are compatible with various security verification mechanisms. Security is guaranteed by the entire blockchain, so compared to blockchains that do not use this method, security has not decreased.
[0109] See also Figure 3 The present invention also provides a block data storage system based on coding, comprising:
[0110] The connection unit 201 is configured to return a connection identifier to the client node upon receiving a registration request sent by the client node;
[0111] The block data storage unit 202 is used to store the block data of each block in the blockchain network into the block data storage area;
[0112] The coding storage unit 203 is configured to treat k blocks as a block group according to a preset coding sequence, perform error correction coding on the block data of the block group, generate a plurality of coding segments corresponding to the block group, and store the generated segments in a coding segment storage area;
[0113] The propagation unit 204 is configured to generate a sending record for the coded segments of the corresponding block group based on a shuffling algorithm according to a preset usage rate, propagate the coded segments of the corresponding block group and the sending record to the corresponding client node for storage, and delete the corresponding coded segments in the coded segment storage area;
[0114] The target search unit 205 is configured to search the block data storage area when receiving a target data request; if the search fails in the block data storage area, the target data is searched in the code segment storage area according to the code segment number corresponding to the target data; if the search succeeds, the code segment found in the code segment storage area is decoded to reconstruct the target data;
[0115] The node search unit 206 is used to send a code segment request to the corresponding client node according to the required code segment number if the search fails in the code segment storage area. When the code segments that meet the preset number are received, the code segments that meet the preset number are decoded to reconstruct and generate target data.
[0116] The reconstructed data storage unit 207 is used to store the reconstructed target data into the block data storage area.
[0117] The present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the block data storage method as described above.
[0118] The present invention also provides a computer-readable storage medium having a computer program / instruction stored thereon, which implements the steps of the block data storage method as described above when the computer program / instruction is executed by a processor.
[0119] The present invention also provides a computer program product, comprising a computer program / instruction, which implements the steps of the block data storage method as described above when executed by a processor.
[0120] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0121] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0122] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0123] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0124] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0125] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that the technical solutions described in the above embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A block data storage method based on coding, characterized in that: The method comprises: When receiving a registration request sent by a client node, returning a connection identifier to the client node; Storing the block data of each block in the blockchain network into the block data storage area; According to a preset coding sequence, k blocks are grouped as a block group, and error correction coding is performed on the block data of the block group to generate a plurality of coding segments corresponding to the block group and store them in a coding segment storage area; According to the preset usage rate, the coding segments of the corresponding block group are generated into sending records based on the shuffling algorithm, the coding segments of the corresponding block group and the sending records are propagated to the corresponding client nodes for storage, and the corresponding coding segments in the coding segment storage area are deleted; When a target data request is received, a search is performed in the block data storage area; if the search fails in the block data storage area, a search is performed in the code segment storage area according to the code segment number corresponding to the target data; if the search is successful, the code segment found in the code segment storage area is decoded and reconstructed to generate the target data; If the search fails in the coding segment storage area, a coding segment request is sent to the corresponding client node according to the required coding segment number. When a preset number of coding segments are received, the preset number of coding segments are decoded to reconstruct the target data.
2. The block data storage method according to claim 1, characterized in that: The step of returning the connection identifier to the client node upon receiving the registration request sent by the client node includes: When receiving a registration request sent by a client node, it is determined according to the preset connection library whether the number of currently registered client nodes exceeds the preset number of registered connections. If not, the connection identifier is returned to the client node, so that the client node upgrades the HTTP connection to a WebSocket connection according to the connection identifier.
3. The block data storage method according to claim 1, wherein: The step of taking k blocks as a block group according to a preset coding order, performing an error correction code encoding operation on block data of the block group, generating a plurality of coding segments corresponding to the block group, and storing the generated coding segments in the coding segment storage area includes: According to a preset coding order, k blocks are grouped as a block group, and a coding matrix corresponding to the block group is generated based on an error correction code; An encoding operation is performed according to the block data of the block group and the encoding matrix to generate n encoding segments corresponding to the block group, and the n encoding segments of the block group are stored in the encoding segment storage area.
4. The block data storage method according to claim 1, wherein: Also includes: The reconstructed target data is stored in the block data storage area.
5. The block data storage method according to claim 1, wherein: If the search fails in the code segment storage area, a code segment request is sent to the corresponding client node according to the required code segment number. When a preset number of code segments are received, decoding operations are performed on the code segments that meet the preset number to reconstruct and generate target data, including: If the search fails in the code segment storage area, a holding record request task is sent to all client nodes in the node group; wherein the holding record is generated by the client node according to the received sending record; Determine the required encoding segment number based on the holding record returned by the client node in the node group, and return the required encoding segment number to the client node to request the encoding segment; When a preset number of coding segments are received, an empty response is returned to the client node in the node group, and the coding segments that meet the preset number are decoded to reconstruct and generate target data.
6. The block data storage method according to claim 1, characterized in that: Each coded segment in the block group is generated as follows: Where: represents the jth coded segment, Represents the block data in the block group, G represents the encoding matrix, where G consists of two parts, the upper part is the k-order unit matrix E k , the lower part is the parity check matrix with m rows and k columns used to correct data errors.
7. A block data storage system based on coding, characterized in that: include: a connection unit, configured to return a connection identifier to the client node upon receiving a registration request sent by the client node; A block data storage unit, used to store the block data of each block in the blockchain network into the block data storage area; a coding storage unit, configured to treat k blocks as a block group according to a preset coding sequence, perform an error correction coding operation on block data of the block group, generate a plurality of coding segments corresponding to the block group, and store the generated coding segments in a coding segment storage area; a propagation unit, configured to generate a sending record for the coding segment of the corresponding block group based on a shuffling algorithm according to a preset usage rate, propagate the coding segment of the corresponding block group and the sending record to the corresponding client node for storage, and delete the corresponding coding segment in the coding segment storage area; a target search unit configured to search the block data storage area upon receiving a target data request; if the search fails in the block data storage area, search the code segment storage area according to the code segment number corresponding to the target data; if the search succeeds, decode the code segment found in the code segment storage area to reconstruct the target data; The node search unit is used to send a code segment request to the corresponding client node according to the required code segment number if the search fails in the code segment storage area. When the code segments that meet the preset number are received, the code segments that meet the preset number are decoded to reconstruct and generate target data.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory, wherein: The processor executes the computer program to implement the steps of the block data storage method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, the steps of the block data storage method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the block data storage method according to any one of claims 1 to 6 are implemented.