Data storage method and device based on blockchain technology
By introducing backup nodes and complete nodes into blockchain storage and using a consistent hash algorithm to map data blocks, the problem of large consumption and low utilization of blockchain storage resources is solved, and the saving and utilization of storage resources are achieved.
Patent Information
- Application Number
- CN202011131800.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-21
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2040-10-21
AI Technical Summary
When existing blockchain technology stores data, each node has a complete blockchain copy, resulting in large consumption of storage resources and low utilization, making it difficult to adapt to the increasing data and storage limitations of edge computing applications.
By setting up backup nodes and full nodes in the storage node, using a consistent hashing algorithm to map data blocks to the hash ring, and only the backup node and the full node store blocks, ensuring that each backup node only stores several blocks.
It effectively saves storage resources, improves the utilization rate of storage resources, overcomes the problems of large consumption and low utilization rate of storage resources in blockchain technology, and is suitable for edge computing and other scenarios with limited storage resources.
Smart Images

Figure CN114385746B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data storage method and device based on blockchain technology. Background Art
[0002] Storing data in large, centralized data centers often has performance, availability, and scalability issues, and also results in higher capital or operating expenses. Moreover, centralized data storage is also highly vulnerable to sophisticated cyber attacks. For these reasons, companies are beginning to seek decentralized data storage methods, and blockchain storage is one of them.
[0003] When existing blockchain technology is used for data storage, each node stores a complete copy of the blockchain, which takes up a lot of storage resources and results in low utilization of storage resources. As data continues to increase, the storage resources of each node also need to be continuously expanded, which makes it impractical for each node to store a complete backup. And because the storage resources of storage nodes are limited, when blockchain technology is applied to edge computing applications, it will bring great storage limitations.
[0004] Therefore, how to propose a storage method that saves storage resources has become an urgent problem to be solved. Summary of the invention
[0005] The embodiments of the present invention provide a data storage method and device based on blockchain technology, which are used to solve the defects of large storage resource consumption and low utilization rate in the prior art, and save storage resources.
[0006] In a first aspect, an embodiment of the present invention provides a data storage method based on blockchain technology, comprising:
[0007] The current storage node receives the data block to be stored;
[0008] The current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; the hash rings maintained by all backup nodes are the same;
[0009] The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block;
[0010] The storage nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0011] According to a data storage method based on blockchain technology in one embodiment of the present invention, the current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, including:
[0012] The current storage node is determined to be the node corresponding to the storage of the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and it is determined that it needs to store the data block.
[0013] According to a data storage method based on blockchain technology according to an embodiment of the present invention, the determining of the node corresponding to the storage of the data block includes:
[0014] The current storage node determines that it is one of the backup nodes corresponding to the position of the data block on the hash ring, and then determines that it needs to store the data block.
[0015] According to a data storage method based on blockchain technology in one embodiment of the present invention, based on the block unique identifier of the data block, the data block is mapped to a hash ring, including:
[0016] The current storage node calculates and obtains a hash value corresponding to the data block based on the block unique identifier of the data block;
[0017] Mapping the data block to a position corresponding to the hash value on the hash ring;
[0018] The hash value is within the value range of the hash ring.
[0019] According to a data storage method based on blockchain technology according to an embodiment of the present invention, the method further includes:
[0020] The current storage node receives the block acquisition application sent by the application node; the application node is the node that applies to obtain the data block;
[0021] The current storage node determines that it has the data block stored locally, and then sends the data block to the application node;
[0022] The block acquisition application is that the application node maps the data block to a hash ring based on the block unique identifier of the data block and sends it after determining that the data block is stored in the current backup node.
[0023] According to a data storage method based on blockchain technology according to an embodiment of the present invention, the method further includes:
[0024] The current storage node receives the node unique identifier of the newly added node broadcasted by the newly added node;
[0025] Based on the node unique identifier of the newly added node, the newly added node is mapped to a locally maintained hash ring.
[0026] According to a data storage method based on blockchain technology according to an embodiment of the present invention, the method further includes:
[0027] When the node to be left leaves, the node to be left is deleted from the locally maintained hash ring based on the node unique identifier of the node to be left.
[0028] In a second aspect, an embodiment of the present invention provides a data storage device based on blockchain technology, comprising:
[0029] A receiving module, used for the current storage node to receive the data blocks to be stored;
[0030] A mapping module, used for mapping the data block to a hash ring based on the block unique identifier of the data block when the current storage node determines that it is a backup node;
[0031] A storage module, configured to store the data block when the current storage node determines that it needs to store the data block based on its position on the hash ring and the position where the data block is mapped to the hash ring;
[0032] The nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0033] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the data storage method based on blockchain technology provided in the first aspect are implemented.
[0034] In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the data storage method based on blockchain technology as provided in the first aspect.
[0035] The data storage method and device based on blockchain technology provided by the embodiment of the present invention maps the data block to the locally maintained hash ring after the current storage node determines that it is a backup node, and keeps the hash rings maintained by all backup nodes the same; then based on its position on the hash ring and the position of the data block mapped to the hash ring, according to the consistent hashing algorithm, it is determined that it needs to store the data block, and then the data block is stored; by distinguishing between backup nodes and complete nodes, the complete node stores all blocks, and each backup node only stores a number of blocks, thereby reducing storage resources, overcoming the defects of large storage resource consumption and low utilization in blockchain technology, and saving storage resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] 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 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.
[0037] Figure 1 A flowchart of a data storage method based on blockchain technology provided by an embodiment of the present invention;
[0038] Figure 2 A schematic diagram of hash ring mapping in an edge computing scenario provided by an embodiment of the present invention;
[0039] Figure 3 It is a schematic diagram of a process for an application node to obtain a data block according to an embodiment of the present invention;
[0040] Figure 4 is a schematic diagram of a new node process provided by an embodiment of the present invention;
[0041] Figure 5 A flowchart of another data storage method based on blockchain technology provided by an embodiment of the present invention;
[0042] Figure 6 A schematic diagram of the structure of a data storage device based on blockchain technology provided by an embodiment of the present invention;
[0043] Figure 7 It is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 described embodiments are 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 creative work are within the scope of protection of the present invention.
[0045] To meet the requirements of low latency in 5G application scenarios, edge computing moves network, storage, computing and other services originally located in the network center to the edge of the network, providing IT (Internet Technology) services and cloud computing capabilities at the edge of the mobile network. Edge computing emphasizes being close to the user side to reduce the latency of network operations and service delivery, and improve user service experience.
[0046] Edge computing generally uses traditional centralized storage or distributed storage. Traditional distributed storage is to divide data into multiple copies based on certain rules and store them on different servers. Multiple storage servers are used to share the storage load. Generally, a central node is required as a control node, and no node stores complete data. This traditional storage method leads to a high risk of data tampering and attack. It can be combined with existing blockchain technology for secure storage in edge computing scenarios.
[0047] Blockchain originated from Bitcoin. In essence, it is a distributed shared ledger and database of a peer-to-peer network, which is decentralized, tamper-proof, traceable, open and transparent. As a reliable transaction model and storage mechanism, blockchain is widely used in various fields. The nodes between blockchains are based on the POW (Proof of work) consensus mechanism, and do not need to trust each other. A block is generated every ten minutes and broadcast to other nodes through a peer-to-peer network. Each node of the blockchain stores a complete copy of the blockchain in a chain structure, and each node storage is independent and equal in status, relying on the consensus mechanism to ensure data consistency.
[0048] As two emerging technologies, blockchain and edge computing have their own great advantages. In recent years, various industries have successively applied blockchain technology to edge computing, storing, calculating and encrypting data on the local network side. On the one hand, blockchain technology can improve data security, and on the other hand, edge computing can bring low latency to data access and processing, which has great application advantages. However, when the existing technology applies blockchain technology to edge computing applications, storage resources are consumed a lot, which brings great storage limitations. In order to overcome the problem of blockchain storage limitations, the inventive concept of each embodiment of the present invention is: by setting up backup nodes, each backup node only stores a number of blocks based on the consistent hashing algorithm, saving storage resources and reducing storage costs on the basis of blockchain decentralization and data security.
[0049] It is understandable that edge computing is one of the scenarios in which the embodiments of the present invention can be applied, but it is not limited to edge computing scenarios. All private chains with limited nodes can use the data storage method provided by the embodiments of the present invention for data storage, and the embodiments of the present invention do not limit this.
[0050] Figure 1 A flowchart of a data storage method based on blockchain technology provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method comprises the following steps:
[0051] Step 100, the current storage node receives the data block to be stored;
[0052] Specifically, a storage node in the blockchain in the edge computing scenario creates a new block based on the consensus mechanism, and then broadcasts the block to all storage nodes.
[0053] The current storage node can then receive the data block to be stored.
[0054] Step 110, the current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; the hash rings maintained by all backup nodes are the same;
[0055] Specifically, in this embodiment, in order to save storage resources, the backup node does not store all blocks, but selectively stores some blocks. Therefore, after receiving a data block, the backup node can first determine whether the block is a data block that it needs to store and then store it.
[0056] Therefore, if the current storage node is a backup node, after receiving the data block to be stored, the current storage node can map the data block to the locally maintained hash ring.
[0057] In this embodiment, the data block is hash-mapped to the hash ring through the hash function Hash (block identifier) based on the block unique identifier, that is, the backup node can map the data block to the hash ring maintained locally by the backup node based on the block unique identifier of the data block.
[0058] It can be understood that all backup nodes maintain the same hash ring, and the position of each backup node on the hash ring is also known to all backup nodes.
[0059] In this embodiment, the block identifier can select the hash value of the block header as a unique identifier of a block.
[0060] In this embodiment, the mapping functions are Hash (block identifier) and Hash (node identifier), which can be preset.
[0061] It is understandable that in this embodiment, the mapping functions Hash (block identifier) and Hash (node identifier) can be any function that can achieve a one-to-one correspondence between input values and output hash values, that is, for the hash function in this embodiment, for different inputs, its output must be different, and the value range of the output hash value remains within the value range of the hash ring. For example, if a 32-bit hash function is selected, the space of the hash ring is limited to 2 32 -1, that is, the hash ring value range is 0 to 2 32 -1.
[0062] Step 120: The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block.
[0063] Specifically, the current storage node can be hashed to the hash ring through the node unique identifier to obtain its position on the hash ring. In this embodiment, the node unique identifier can be the host IP address or host name, or other keywords can be selected to ensure that each node unique identifier only uniquely identifies one node.
[0064] Figure 2 A schematic diagram of hash ring mapping in an edge computing scenario provided by an embodiment of the present invention, such as Figure 2As shown, in this embodiment, after the current storage node obtains its position on the hash ring, it can determine whether it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring. If necessary, the data block is stored. If not, the current storage node does not process it and discards the block. This allows each backup node to store only a number of blocks based on a consistent hashing algorithm, saving storage resources. For example, a storage node can determine whether it is one of the N nodes in the hash ring that is clockwise from the position of the data block on the hash ring. If so, it can determine that it needs to store the data block and then stores the data block.
[0065] It can be understood that, in this embodiment, N should be greater than or equal to 1 and less than the number of all storage nodes on the hash ring.
[0066] The storage nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0067] Specifically, in this embodiment, the storage nodes are divided into several complete nodes and backup nodes, where the complete nodes store a complete copy of the blockchain. It can be understood that the number of complete nodes can be preset manually, depending on the storage resources of edge computing, and can be adjusted dynamically. Each backup node only stores several blocks based on the consistent hashing algorithm to reduce storage resources.
[0068] Specifically, in this embodiment, if a storage node needs to apply to store a data block and broadcast the block to all storage nodes, after the edge full node receives the data block, in order to store a complete blockchain copy, it verifies the block after receiving it and then directly adds it to the local blockchain.
[0069] The data storage method based on blockchain technology provided by the embodiment of the present invention maps the data block to the locally maintained hash ring after the current node determines that it is a backup node, and keeps the hash rings maintained by all backup nodes the same; then based on its position on the hash ring and the position of the data block mapped to the hash ring, according to the consistent hashing algorithm, it is determined that it needs to store the data block, and then the data block is stored; by distinguishing between backup nodes and complete nodes, the complete node stores all blocks, and each backup node only stores a number of blocks, thereby reducing storage resources, overcoming the defects of large storage resource consumption and low utilization in blockchain technology, and saving storage resources.
[0070] Optionally, based on the above embodiment, the current storage node determines that it needs to store the data block based on its position on the hash ring and the position where the data block is mapped to the hash ring, including:
[0071] The current storage node is determined to be the node corresponding to the storage of the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and it is determined that it needs to store the data block.
[0072] Specifically, in this embodiment, the principle of mapping data blocks to hash rings based on the consistent hashing algorithm and then storing them in corresponding storage nodes is as follows: first, the hash value of the current storage node can be calculated, and secondly, the block unique identifier is hashed to obtain a hash value, which can then be mapped to several storage nodes closest to it in a preset direction based on the hash value. In this embodiment, the preset direction can be clockwise or counterclockwise. For the same block, the preset direction can be kept consistent during access.
[0073] Specifically, after mapping the data block to the hash ring, the current node determines that it is the node corresponding to the storage of the data block based on its position on the hash ring and the position of the data block on the hash ring, and determines that it needs to store the data block.
[0074] Optionally, based on the above embodiment, determining that the node is a node corresponding to the storage of the data block includes:
[0075] The current node determines that it is one of the backup nodes corresponding to the position of the data block on the hash ring, and then determines that it needs to store the data block.
[0076] Specifically, when the current node determines that it is the node corresponding to the storage of the data block, it can determine that it needs to store the data block by determining that it is one of the nodes that is closer to the data block on the hash ring.
[0077] It can be understood that, in this embodiment, for each data block, it can be stored in multiple storage nodes, and the specific number can be preset, that is, the backup nodes corresponding to the position of the data block on the hash ring.
[0078] Specifically, the storage nodes can be first mapped to the hash ring space through a hash function, and then each newly generated data block is mapped to the hash ring, starting from the position of the data block on the hash ring, and a number of storage nodes are selected for storage in a preset direction. If you want to find a certain block, you only need to map the block to the hash ring and search for a preset number of backup nodes in a preset direction. For example, when a data block is stored, it is stored in the three backup nodes closest to the position of the data block on the hash ring in the clockwise direction. When obtaining this data block, the three backup nodes closest to the position of the data block on the hash ring in the clockwise direction are the nodes that store the data block.
[0079] In this embodiment, the preset direction may be a clockwise direction or a counterclockwise direction. For the same block, the preset direction may be kept the same during access.
[0080] For example, if the preset storage is in N storage nodes and the preset direction is clockwise, then after the current storage node maps the data block to the hash ring, the storage node can determine whether it is one of the N nodes closest to the location of the data block in the hash ring in the clockwise direction; if not, no processing is done and the block is discarded; if so, it can be confirmed that it is the node corresponding to the storage of the data block, and the data block is verified and stored in the local disk.
[0081] It is understandable that in this embodiment, when a storage node fails and goes offline, according to the mapping method of the algorithm, only the data objects in the interval from the failed node on the ring to the next node in the counterclockwise direction are affected, and these objects themselves are mapped to the failed node. When a storage node is added, for example, the preset data blocks are stored in three nodes in the clockwise direction on the hash ring. If a new storage node H is added between storage nodes C and D, the nodes in the clockwise direction are A, B, C, H, and D, respectively. The affected blocks are only the data blocks between node A and the newly added node H, because these blocks should be stored on the H node according to the preset storage rules. Therefore, when a storage node changes, the consistent hash ring can change the mapping relationship between the existing service request and the request processing server as little as possible, which can ensure the rapid migration of data and avoid data loss and system crash caused by node changes.
[0082] Optionally, based on the above embodiment, mapping the data block to a hash ring based on the block unique identifier of the data block includes:
[0083] The current storage node calculates and obtains a hash value corresponding to the data block based on the block unique identifier of the data block;
[0084] Mapping the data block to a position corresponding to the hash value on the hash ring;
[0085] The hash value is within the value range of the hash ring.
[0086] Specifically, the storage space can be abstracted as a ring, and all storage nodes can be configured on the ring based on their respective hash values. All nodes on the ring have a value corresponding to the hash value. The current storage node can calculate the hash value corresponding to the data block based on the block unique identifier of the data block through the hash function Hash (block), and then find the corresponding position of the hash value of the data block in the hash ring, which is the position of the data block mapped on the hash ring.
[0087] For example, the current storage node receives a data block to be stored, whose block unique identifier is 11100; based on the block unique identifier of the data block, the hash function Hash (block identifier) can be input to calculate the hash value corresponding to the data block as 0x459aa6a3, then the position corresponding to the hash value 0x459aa6a3 is found on the hash ring, which is the position where the data block is mapped on the hash ring.
[0088] It is understood that in this embodiment, the hash values calculated based on the node unique identifier through Hash (node identifier) or based on the block unique identifier through Hash (block) are all within the value range of the hash ring. It is understood that the value range of the hash ring is determined based on the hash function. For example, if a 32-bit hash function is selected, the space of the hash ring is limited to 2 32 -1.
[0089] Optionally, based on the above embodiment, the method further includes:
[0090] The current storage node receives the block acquisition application sent by the application node; the application node is the node that applies to obtain the data block;
[0091] The current storage node determines that it has the data block stored locally, and then sends the data block to the application node;
[0092] The block acquisition application is that the application node maps the data block to a hash ring based on the block unique identifier of the data block and sends it after determining that the data block is stored in the current backup node.
[0093] Specifically, Figure 3 is a schematic diagram of a process for an application node to obtain a data block according to an embodiment of the present invention; Figure 3 As shown, if it is a server in the edge computing system, that is, a storage node, it can be called an application node in this embodiment. If it wants to apply for a data block stored in the blockchain, the application node can first query whether the block exists locally. If not, it will apply to the storage node in the hash ring that stores the data block. Therefore, the application node needs to calculate and query the position of the data block on the hash ring, and then obtain the storage node closest to the position of the data block mapped on the hash ring in the clockwise direction, that is, the storage node where the data block is most likely to be stored.
[0094] Therefore, the data block can be requested from the first storage node in the clockwise direction of the location where the data block is mapped in the hash ring. If the storage node receives the block acquisition request and finds that the block is stored locally, it will send it to the requesting node. If the storage node loses the block, the next storage node in the clockwise direction will be selected for the block request.
[0095] For example, the application node applies to obtain a stored data block, whose block unique identifier is 11100; based on the block unique identifier of the data block, the hash function Hash (block identifier) can be input to calculate the hash value corresponding to the data block to be 0x459aa6a3, then the position corresponding to the hash value 0x459aa6a3 is found on the hash ring, and the position corresponding to the hash value 0x459aa6a3 is found clockwise on the hash ring, and the preset number closest to the preset direction of the position is further determined. Quantify nodes; for example, storage node A at the position corresponding to the hash value 0x459aa6a4, and then the applicant node can apply to storage node A for the data block with the block unique identifier 11100; if storage node A does not find the data block with the block unique identifier 11100 in its local storage, the applicant node can apply for the block to the next storage node in the clockwise direction, such as storage node B with a hash value of 0x459aa6a5; until the applicant node obtains the data block with the block unique identifier 11100.
[0096] Optionally, based on the above embodiment, the method further includes:
[0097] The current storage node receives the node unique identifier of the newly added node broadcasted by the newly added node;
[0098] Based on the node unique identifier of the newly added node, the newly added node is mapped to a locally maintained hash ring.
[0099] Specifically, Figure 4 is a schematic diagram of a new node process provided by an embodiment of the present invention; Figure 4 As shown, when a new backup server, that is, a new storage node, is added to the system, the new storage node can send its own node unique identifier to all storage nodes in the entire blockchain; when the current storage node receives the node unique identifier of the new storage node, it can map the new node to the position on the hash ring and save it locally.
[0100] It is understandable that all storage nodes jointly maintain a consistent hash ring space locally, so once a new storage node is added, it can be mapped to the consistent hash ring based on the node unique identifier of the new storage node as a backup node.
[0101] Optionally, based on the above embodiment, the method further includes:
[0102] When the node to be left leaves, the node to be left is deleted from the locally maintained hash ring based on the node unique identifier of the node to be left.
[0103] Specifically, when a storage node in the edge computing system is about to leave, the storage node to be left can send its own node unique identifier to all storage nodes in the entire blockchain; when the current storage node receives the node unique identifier of the storage node to be left, it can remove the node to be left in the locally maintained hash ring.
[0104] Specifically, when a node in the edge computing system is damaged, the node can also be considered as a node to be left, but the damaged node will not send any information to other nodes. Only after other nodes find that the node is damaged, based on the node unique identifier of the damaged node to be left, the damaged node to be left will be deleted from the locally maintained hash ring. It can be understood that in this embodiment, timed communication can be set between nodes. If information from other nodes can be received within a preset time, but information from a certain node is continuously not received, the node can be considered damaged and identified as a node to be left.
[0105] It can be understood that all storage nodes jointly maintain a consistent hash ring space locally. Therefore, once a storage node is about to leave, the remaining storage nodes will remove the node in the local hash ring, that is, based on the node unique identifier of the storage node to be left, obtain its location mapped to the consistent hash ring and delete it to ensure real-time update of the hash ring.
[0106] The data storage method based on blockchain technology provided by the embodiment of the present invention maps the data block to the locally maintained hash ring after the current node determines that it is a backup node, and keeps the hash rings maintained by all backup nodes the same; then based on its position on the hash ring and the position of the data block mapped to the hash ring, according to the consistent hashing algorithm, it is determined that it needs to store the data block, and then the data block is stored; by distinguishing between backup nodes and complete nodes, the complete node stores all blocks, and each backup node only stores a number of blocks, thereby reducing storage resources, overcoming the defects of large storage resource consumption and low utilization in blockchain technology, and saving storage resources.
[0107] Figure 5 A flowchart of another data storage method based on blockchain technology provided by an embodiment of the present invention is shown in FIG. Figure 5 As shown, the method comprises the following steps:
[0108] Step 500, nodes in the blockchain create blocks based on a consensus mechanism;
[0109] Specifically, if a storage node in the blockchain in the edge computing scenario needs to apply to store a data block, it will create a new block for the data block based on the consensus mechanism;
[0110] Step 510, sending to all storage nodes;
[0111] Specifically, after the storage node in step 500 creates a new block, it can broadcast the block to all storage nodes.
[0112] All storage nodes can then receive the data block to be stored.
[0113] Step 520, determining whether the node receiving the block is a backup node;
[0114] Specifically, since only complete nodes in this embodiment will store all blocks, and backup nodes will only store some blocks, after receiving the data block, the current storage node can first determine whether it is a backup node;
[0115] If the current storage node determines that it is a complete node, jump to step 530;
[0116] If the current storage node determines that it is a complete node, jump to step 550;
[0117] Step 530, verify the block;
[0118] If the current storage node is a complete node, it needs to store the data block; therefore, the current storage node can verify the block;
[0119] Step 540, join the local blockchain;
[0120] Specifically, once a full node verifies a block, it can store the data block and add it to the local blockchain;
[0121] Step 550, calculate Hash (block identifier) and map it into the hash ring;
[0122] Specifically, if the current storage node determines itself as a backup node, the data block can be hashed to the hash ring through the hash function Hash (block identifier), that is, the backup node can map the data block to the hash ring maintained locally by the backup node based on the block unique identifier of the data block.
[0123] Step 560, determine whether there are N clockwise nodes;
[0124] Specifically, for example, if the data block is preset to be stored in N storage nodes, after the current storage node maps the data block to the hash ring, the current storage node can determine whether it is one of the N nodes in the hash ring in the clockwise direction of the position of the data block on the hash ring;
[0125] If not, jump to step 570;
[0126] If yes, jump to step 580;
[0127] Step 570, no processing is performed;
[0128] Specifically, if after the current storage node maps the data block to the hash ring, the current storage node determines that it is not one of the N nodes in the hash ring that are clockwise from the location of the data block on the hash ring, then no processing is performed and the block is discarded;
[0129] Step 580, verifying the block;
[0130] Specifically, if after the current storage node maps the data block to the hash ring, the current storage node determines that it is one of the N nodes in the hash ring in the clockwise direction of the position of the data block on the hash ring, it can be confirmed that it is the node corresponding to the storage of the data block, and then the data block is verified;
[0131] Step 590, store locally.
[0132] Specifically, after the current storage node verifies the block, it can store it in the local disk.
[0133] The following is a description of a data storage device based on blockchain technology provided in an embodiment of the present invention. The data storage device based on blockchain technology described below and the data storage method based on blockchain technology described above can refer to each other.
[0134] Figure 6 A schematic diagram of a data storage device based on blockchain technology provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown, the device includes: a receiving module 610, a mapping module 620 and a storage module 630; wherein,
[0135] The receiving module 610 is used for the current storage node to receive the data block to be stored;
[0136] The mapping module 620 is used for the current storage node to determine that it is a backup node, and then based on the block unique identifier of the data block, map the data block to the hash ring;
[0137] The storage module 630 is used for the current storage node to determine that it needs to store the data block based on its position on the hash ring and the position where the data block is mapped to the hash ring, and then store the data block;
[0138] The nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0139] Specifically, the data storage device based on blockchain technology receives the data blocks to be stored through the receiving module 610; then determines through the mapping module 620 that the current storage node is a backup node, and then maps the data block to the hash ring based on the unique block identifier of the data block; finally, the storage module 630 determines that it needs to store the data block based on the position of the storage node on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block.
[0140] The data storage device based on blockchain technology provided by the embodiment of the present invention maps the data block to the locally maintained hash ring after the current node determines that it is a backup node, and keeps the hash rings maintained by all backup nodes the same; then based on its position on the hash ring and the position of the data block mapped to the hash ring, according to the consistent hashing algorithm, it is determined that it needs to store the data block, and then the data block is stored; by distinguishing between backup nodes and complete nodes, the complete node stores all blocks, and each backup node only stores a few blocks, thereby reducing storage resources, overcoming the defects of large storage resource consumption and low utilization in blockchain technology, and saving storage resources.
[0141] Figure 7 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention, such as Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the data storage method based on the blockchain technology, and the method includes:
[0142] The current storage node receives the data block to be stored;
[0143] The current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; the hash rings maintained by all backup nodes are the same;
[0144] The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block;
[0145] The nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0146] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0147] On the other hand, an embodiment of the present invention further provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, and when the program instructions are executed by a computer, the computer can execute the data storage method based on blockchain technology provided by the above-mentioned method embodiments, the method comprising:
[0148] The current storage node receives the data block to be stored;
[0149] The current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; the hash rings maintained by all backup nodes are the same;
[0150] The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block;
[0151] The nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0152] In another aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the data storage method based on blockchain technology provided in the above embodiments is implemented, and the method includes:
[0153] The current storage node receives the data block to be stored;
[0154] The current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; the hash rings maintained by all backup nodes are the same;
[0155] The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block;
[0156] The nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks.
[0157] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0158] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. 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 data storage method based on blockchain technology, characterized in that: include: The current storage node receives the data block to be stored; The current storage node determines that it is a backup node, and then maps the data block to a locally maintained hash ring based on the block unique identifier of the data block; All backup nodes maintain the same hash ring. The current storage node determines that it needs to store the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then stores the data block; The storage nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks; The current storage node determines that it needs to store the data block based on its position on the hash ring and the position where the data block is mapped to the hash ring, including: The current storage node determines that it is the node corresponding to the storage of the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then determines that it needs to store the data block; The step of determining the node corresponding to the data block includes: The current storage node determines that it is one of the backup nodes corresponding to the position of the data block on the hash ring, and then determines that it needs to store the data block; The current storage node determines that it is one of the backup nodes corresponding to the position of the data block on the hash ring, and then determines that it needs to store the data block, including: When the current storage node determines that it is the node corresponding to the data block, it determines that it needs to store the data block by determining that it is one of the nodes that is closer to the data block on the hash ring; Mapping the data block to a hash ring based on the block unique identifier of the data block includes: The current storage node calculates and obtains a hash value corresponding to the data block based on the block unique identifier of the data block; Mapping the data block to a position corresponding to the hash value on the hash ring; wherein the hash value is within the value range of the hash ring; Mapping the data block to a position corresponding to the hash value on the hash ring includes: According to a preset direction, the data block is mapped to a position corresponding to the hash value on the hash ring; the preset direction is clockwise or counterclockwise.
2. The data storage method based on blockchain technology according to claim 1 is characterized in that: The method further comprises: The current storage node receives the block acquisition application sent by the application node; the application node is the node that applies to obtain the data block; The current storage node determines that it has the data block stored locally, and then sends the data block to the application node; The block acquisition application is that the application node maps the data block to a hash ring based on the block unique identifier of the data block and sends it after determining that the data block is stored in the current backup node.
3. The data storage method based on blockchain technology according to claim 1 is characterized in that: The method further comprises: The current storage node receives the node unique identifier of the newly added node broadcasted by the newly added node; Based on the node unique identifier of the newly added node, the newly added node is mapped to a locally maintained hash ring.
4. The data storage method based on blockchain technology according to claim 1 is characterized in that: The method further comprises: When the node to be left leaves, the node to be left is deleted from the locally maintained hash ring based on the node unique identifier of the node to be left.
5. A data storage device based on blockchain technology, characterized in that: include: A receiving module, used for the current storage node to receive the data blocks to be stored; A mapping module, used for mapping the data block to a hash ring based on the block unique identifier of the data block when the current storage node determines that it is a backup node; A storage module, configured to store the data block when the current storage node determines that it needs to store the data block based on the current storage node's position on the hash ring and the position where the data block is mapped to the hash ring; The storage nodes include backup nodes and complete nodes; the complete nodes are nodes that store all data blocks; The storage module is further used for determining that the current storage node is a node corresponding to the storage of the data block based on its position on the hash ring and the position of the data block mapped to the hash ring, and then determining that it needs to store the data block; The storage module is further used for determining that the current storage node is one of the backup nodes corresponding to the position of the data block on the hash ring, and then determining that it needs to store the data block; The storage module is further used for, when the current storage node determines that it is the node corresponding to the storage of the data block, to determine that it needs to store the data block by determining that it is one of the nodes that is closer to the location of the data block on the hash ring; The mapping module is further configured to calculate, by the current storage node, a hash value corresponding to the data block based on the block unique identifier of the data block; and map the data block to a position corresponding to the hash value on the hash ring; wherein the hash value is within a value range of the hash ring; The mapping module is further used to map the data block to a position corresponding to the hash value on the hash ring according to a preset direction; the preset direction is clockwise or counterclockwise.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the data storage method based on blockchain technology as described in any one of claims 1 to 4 are implemented.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the data storage method based on blockchain technology as described in any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Credible cloud storage method and system based on block chain
CN110011981A
Block chain node load balancing method and device capable of reducing node collision
CN110098920A