Blockchain data migration method and device
By using B+ trees based on write-on-write replication technology in blockchain to generate a state tree and migrate data to the extension node, the problems of complex data migration logic and low performance in the existing technology are solved, and efficient and consistent data migration is achieved.
Patent Information
- Application Number
- CN202510002836.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-01-02
AI Technical Summary
When the existing blockchain data migration scheme splits data by time dimensions, the logic is complex and the performance is poor, and it cannot meet the dynamic migration needs.
The B+ tree based on write-on-write copy technology generates a state tree, and when data is migrated, the status data of the target state tree is sent to the extension node, the data mapping table is updated, and the target state tree in the main node is deleted.
It improves the efficiency of blockchain data migration, reduces the storage pressure of node devices, and ensures high consistency in the data migration process.
Smart Images

Figure CN119415500B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of blockchain technology, and in particular, relates to a blockchain data migration method. Background Art
[0002] The continuous growth of data on the blockchain has brought huge storage pressure to the blockchain system. In order to reduce the storage pressure of the blockchain, blockchain data can be migrated.
[0003] The state data in the account model is highly correlated and dependent. When migrating blockchain data in existing solutions, the existing state data storage solutions mostly sort the account addresses in lexicographic order. Although this sorting method is suitable for fast query, it cannot split data according to the time dimension and is difficult to meet the needs of dynamic migration. For example, when migrating by block or transaction time dimension, the byte order is inconsistent with the time order, resulting in complex data segmentation logic and poor performance. Summary of the invention
[0004] In view of this, an embodiment of the present application provides a blockchain data migration method to improve the data migration efficiency of the blockchain, thereby reducing the storage pressure of node devices in the blockchain, while ensuring high consistency during the data migration process.
[0005] A first aspect of an embodiment of the present application provides a blockchain data migration method, which is applied to a master node device of a blockchain, and the method includes:
[0006] Generate a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data;
[0007] When data migration is triggered, determining a target state tree to be migrated from the generated state tree;
[0008] Sending the state data of the target state tree to the extension node of the master node;
[0009] If the migration completion information returned by the extended node is received, the data mapping table stored in the master node is updated, wherein the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node;
[0010] Delete the target state tree in the master node.
[0011] In a possible implementation, one or more of the extended nodes are registered in the master node, each of the extended nodes has a corresponding global Bloom filter in the master node, and the method further includes:
[0012] receiving the global Bloom filter from the extended node;
[0013] In response to the query request, determining a target expansion node where target state data is located based on one or more of the global Bloom filters in the master node, the target state data being state data corresponding to the query request;
[0014] Sending the query request to the target extension node to request the target status data from the extension node;
[0015] Based on the data returned by the target extension node, target status data is determined.
[0016] In a possible implementation, determining the target state data based on the data returned by the target extension node includes:
[0017] Determine the time information corresponding to each data returned by the target extension node;
[0018] According to the time information, the latest data is determined as the target state data.
[0019] In a possible implementation manner, determining the time information corresponding to each data returned by the target extension node includes:
[0020] Determine a first state tree corresponding to the data returned by the target extension node;
[0021] Determine a block range corresponding to the first state tree from the data mapping table, wherein the block range is represented by a block number, and the block number is generated according to a time sequence;
[0022] The block range is used as the time information corresponding to the data returned by the target extension node.
[0023] In a possible implementation, before sending the target state tree to the extension node of the master node, the method further includes:
[0024] Determine whether an extended node to be migrated is currently registered in the master node, the extended node to be migrated being an extended node whose remaining storage space is greater than or equal to the storage space corresponding to the target state tree;
[0025] If the master node currently has no registered extension node to be migrated, registering the extension node in the master node;
[0026] The information of the registered extended node is updated in the data mapping table.
[0027] In a possible implementation, generating a state data tree based on the state data of an account in a blockchain includes:
[0028] Dividing the state data in the blockchain according to preset time intervals;
[0029] A state tree is generated based on the state data within a time interval, and each state tree is organized in time sequence.
[0030] A second aspect of an embodiment of the present application provides a blockchain data migration method, which is applied to an extension node device, and the method includes:
[0031] Receive the status data of the target status tree from the master node;
[0032] Performing data verification on the target state tree;
[0033] If the target state tree passes the verification, the target state tree is rebuilt in the extension node based on the state data. The target state tree is a B+ tree based on the copy-on-write technology. Each leaf node of the target state tree is used to store the state data of the account in the blockchain.
[0034] Return migration completion information to the master node, the master node is used to update the data mapping table stored in the master node according to the migration completion information and delete the target state tree in the master node, the data mapping table is used to characterize the mapping relationship between the state data stored in the extension node and the extension node.
[0035] In a possible implementation, after rebuilding the target state tree in the extended node based on the state data, the method further includes:
[0036] Updating the global Bloom filter of the extended node;
[0037] The updated global Bloom filter is sent to the master node.
[0038] In a possible implementation, the method further includes:
[0039] Receiving a query request from the master node;
[0040] Determine the data to be returned from the stored state tree according to the query request and the local Bloom filter in the extended node, each state tree in the extended node has a corresponding local Bloom filter, and the local Bloom filter is used to perform data query on the corresponding state tree;
[0041] The data to be returned is sent to the master node.
[0042] A third aspect of an embodiment of the present application provides a blockchain data migration device, which is applied to a master node device of a blockchain, and the device includes:
[0043] A generation module, used to generate a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data;
[0044] A determination module, configured to determine a target state tree to be migrated from the generated state trees when data migration is triggered;
[0045] A sending module, used for sending the state data of the target state tree to the extension node of the master node;
[0046] An updating module, configured to update a data mapping table stored in the master node if migration completion information returned by the extension node is received, wherein the data mapping table is used to represent a mapping relationship between the state data stored in the extension node and the extension node;
[0047] A deletion module is used to delete the target state tree in the master node.
[0048] A fourth aspect of an embodiment of the present application provides a blockchain data migration device, which is applied to an extension node device, and the device includes:
[0049] A receiving module, used to receive status data of a target status tree from a master node, wherein the target status tree is a B+ tree based on a copy-on-write technology, and each leaf node of the target status tree is used to store status data of an account in a blockchain;
[0050] A verification module, used for performing data verification on the target state tree;
[0051] A reconstruction module, configured to rebuild the target state tree in the extension node based on the state data if the target state tree passes the verification;
[0052] A sending module is used to return migration completion information to the master node, and the master node is used to update the data mapping table stored in the master node according to the migration completion information and delete the target status tree in the master node. The data mapping table is used to characterize the mapping relationship between the status data stored in the extension node and the extension node.
[0053] A fifth aspect of an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method described in the first aspect or the second aspect above is implemented.
[0054] A sixth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect or the second aspect above is implemented.
[0055] A seventh aspect of the embodiments of the present application provides a computer program product. When the computer program product is run on a computer device, the computer device executes the method described in the first aspect or the second aspect.
[0056] Compared with the prior art, the embodiments of the present application have the following advantages:
[0057] In an embodiment of the present application, the state data of the blockchain can be organized into a state tree for storage. The state tree is a B+ tree based on the copy-on-write technology. In the state tree, all data of the account status will be stored, that is, when the data is updated, the historical data will not be merged and modified, but the new state data will be recorded, realizing the full version storage of the state data. When triggering data migration, the master node can determine the target state tree to be migrated. An extension node can be registered on the master node, and the extension node can serve as the storage space of the master node. Therefore, the master node can send the data of the target state tree to the extension node of the master node, thereby migrating the state data in the master node to the extension node, reducing the storage pressure of the master node. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art.
[0059] Figure 1 This is a schematic diagram of the steps of a blockchain data migration method provided by an embodiment of the present application;
[0060] Figure 2 This is a schematic diagram of a state data storage method provided in an embodiment of the present application;
[0061] Figure 3 This is a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application;
[0062] Figure 4 This is a schematic diagram of the steps of another blockchain data migration method provided in an embodiment of the present application;
[0063] Figure 5 This is a schematic diagram of the steps of another blockchain data migration method provided in an embodiment of the present application;
[0064] Figure 6 This is a schematic diagram of the steps of another blockchain data migration method provided in an embodiment of the present application;
[0065] Figure 7 This is a schematic diagram of the steps of another blockchain data migration method provided in an embodiment of the present application;
[0066] Figure 8 It is a schematic diagram of a blockchain data migration device provided in an embodiment of the present application;
[0067] Fig. 9 It is a schematic diagram of another blockchain data migration device provided in an embodiment of the present application;
[0068] Fig.10 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0069] In the following description, specific details such as specific system structures, technologies, etc. are proposed for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from hindering the description of the present application.
[0070] In recent years, blockchain technology has been widely used in finance, medical care, the Internet of Things and other fields. However, with the continuous expansion of application scenarios, the data storage challenges faced by blockchain systems have become increasingly prominent, especially in the field of state data management and migration.
[0071] The data storage pressure of blockchain leads to a decrease in read and write performance. As the amount of data on the blockchain system continues to grow, the underlying storage system faces performance bottlenecks when processing large amounts of data. The increase in read paths and the amplification effect during writes lead to a significant decrease in read and write performance, thus affecting the overall efficiency of the blockchain network.
[0072] The blockchain system cannot handle infinitely growing data. Blockchain is essentially a system that continuously accumulates data. If the storage of expired or infrequently accessed data cannot be effectively optimized or migrated, the system storage requirements will continue to expand, eventually breaking through hardware limitations and affecting the sustainable operation of the system.
[0073] The current blockchain storage solution does not provide sufficient support for data migration. The current mainstream blockchain storage solution is based on the authentication data structure (ADS). Although it can provide data integrity verification, it has the following deficiencies in data segmentation and migration efficiency. The authentication data structure organizes data in a fixed tree structure. Although it supports partial data access, when faced with scenarios where large quantities of data need to be segmented, due to strong globality and dependency, the entire tree often needs to be reconstructed, resulting in low migration efficiency. Sorting by lexicographic order limits the segmentation strategy: Existing state data storage solutions mostly sort account addresses in lexicographic order. Although this sorting method is suitable for fast queries, it cannot segment data according to the time dimension and is difficult to meet dynamic migration requirements. For example, when migrating by block or transaction time dimension, the byte order is inconsistent with the time order, resulting in complex data segmentation logic and poor performance.
[0074] Based on this, an embodiment of the present application provides a data migration method for a blockchain, thereby providing an efficient and consistent state data migration solution.
[0075] The technical solution of the present application is described below through specific embodiments.
[0076] Reference Figure 1 , shows a schematic diagram of the steps of a blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0077] S101, generating a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data.
[0078] The execution subject of this embodiment may be a computer device, which may be a master node device of a blockchain, and a master node of a blockchain is deployed in the computer device. The master node may be deployed on a server, a cloud server, or other device, and the computer device may be a server, a cloud server, or other device. This embodiment does not limit the specific type of the computer device.
[0079] The blockchain of the account model can include state data. State data of an account in the blockchain refers to information stored in the blockchain network that reflects the current state of the account. State data can include the account's balance, number of transactions, and other related information to ensure the accuracy and consistency of the account status. The state data of an account in the blockchain is usually recorded in a pipelined manner. For example, after a transfer operation, the balance of an account will decrease or increase accordingly. State data ensures that each account on the blockchain has a clear and accurate balance record, thereby preventing the double-spending problem.
[0080] The state data of the account in the blockchain can be maintained through a state tree. The state tree in this embodiment may include leaf nodes, the leaf nodes are used to store the corresponding state data, and the nodes above the leaf nodes are used to store index information.
[0081] In this embodiment, the state data in the blockchain node can be stored in a B+ tree based on the Copy-on-Write (CoW) technology. Based on the Copy-on-Write technology, when the data of a node needs to be modified, the original node is not modified but a new node is created to store the modified data, and the parent node is copied and linked to the pointer of the new node. The B+ tree based on the Copy-on-Write technology can realize a single-layer multi-version storage architecture and avoid the read-write amplification of the traditional two-layer model. At the same time, the B+ tree based on the Copy-on-Write technology supports the generation of Merkle proofs, thereby ensuring the consistency and integrity of the state data.
[0082] The state tree in this embodiment can be a time-structured multi-version Merkle tree (TSMM-tree). The time-structured multi-version Merkle tree can be combined with a B+ tree based on the copy-on-write technology to support efficient state data storage, partitioning, and migration operations.
[0083] The master node device can divide the status data of the accounts in the blockchain according to preset time intervals; generate a status tree based on the status data within a time interval, and each status tree is linked in chronological order.
[0084] As an example, the master node device can generate an independent state tree for the state data for every N blocks. The state tree is organized in chronological order to facilitate the migration operation to manage data by time period. Each state tree corresponds to time period information. As an example, each state tree can have unique identification information, and the unique identification information can also characterize the time sequence corresponding to each state tree. For example, the first state tree generated can be TREE1, the second state tree generated can be TREE2, and the Nth state tree generated can be TREEN. 1, 2, and N can be the unique identification information of the state tree. The smaller the unique identification information, the older the state tree is, and the larger the unique identification information, the newer the state tree is.
[0085] The time period information of the state tree can also be represented by the block number. The block number can be a number generated in chronological order, so the block number can represent time. The master node device can organize the state data of every 100 blocks into a state tree. For example, blocks 1-100, blocks 101-200, and blocks 201-300 correspond to a state tree respectively. At this time, the size of the block number in the block range can represent the time newness and oldness information of the state tree.
[0086] In this embodiment, the state data can be segmented based on the time sequence, which can reduce the difficulty of data segmentation, so that the state data can be segmented flexibly. The state data is organized into a state tree in time sequence, and the state tree is used as a unit for data migration, so as to improve the efficiency of data migration. In view of the complex dependencies of state data, this embodiment innovatively proposes a time-structured storage and segmentation mechanism, which can achieve efficient and flexible data migration.
[0087] Figure 2 is a schematic diagram of a state tree shown in an embodiment of the present application. Figure 2 As shown, each state tree can correspond to a number, and each state tree can be organized in chronological order. In the main node and subsequent extended nodes, the state data can be organized through the state tree. Figure 2 The organization of state data in the master node and extended node of the blockchain is shown in Figure 2. Figure 2 As shown, in both the main node and the extended node, the state tree can be sorted by time. Each state tree can include a leaf node, and the leaf node stores state data.
[0088] S102: When data migration is triggered, determine a target state tree to be migrated from the generated state trees.
[0089] The master node device may receive a data migration instruction. For example, the master node may receive a data migration instruction from a smart contract, at which point data migration may be triggered.
[0090] In another possible implementation, when the storage space of the master node device reaches a preset threshold, data migration can be triggered.
[0091] The object of data migration can generally be historical state data. The master node device can determine the target state tree to be migrated from the generated state tree. Exemplarily, the master node device can determine the state tree arranged at the front from the existing state tree as the target state tree. That is, when selecting the target state tree, you can choose to select the state tree generated first in chronological order, that is, the state tree farthest away from the current time.
[0092] For example, currently the master node device may include three state trees, and the block ranges corresponding to the three state trees may be 1-100, 101-200, and 201-300. At this time, the state tree corresponding to the block range 1-100 may be used as the target state tree.
[0093] S103, sending the status data of the target status tree to the extension node of the master node.
[0094] The master node device can send the state data corresponding to the target state tree to the extension node, and the target state tree can include the state data of multiple accounts. The extension node can be pre-registered in the master node. The extension node can be deployed on other computer devices, and the extension node can be used as the storage space of the master node. The master node can pre-register the extension node with the master node through the remote procedure call service (RPC), so that the master node can migrate data to the extension node.
[0095] In the embodiment of the present application, the expansion node and the master node are deployed on different devices. The expansion node is deployed in the expansion node device, and the master node is deployed in the master node device. Through registration, the master node can obtain information such as the address and storage capacity of the expansion node, thereby facilitating data migration and communication between the master node and the expansion node. The master node can store the information of the expansion node in the data mapping table, so that the target expansion node can be determined according to the information in the data mapping table, and the device where the target expansion node is located is the device where the state data is stored after migration.
[0096] It is understandable that the master node device and the expansion node device are different devices, each with its own storage space. When the storage space of the master node device is under pressure, the state data stored in the master node device can be migrated to the expansion node device, so that the device of the expansion node can be used to store the state data of the master node, reducing the storage pressure of the master node. After the master node device migrates the state data to the expansion node device, the migrated state data can be deleted, thereby freeing up the storage space of the master node device, reducing the storage pressure of the master node device, and improving the data access efficiency of the master node.
[0097] In a possible implementation, the remote server may deploy a remote call service. The master node may send an extension node request to the remote server, so that the remote server may return extension node information to the master node. The extension node information may include the address, storage capacity, communication transmission mode, etc. of the extension node. The master node may receive the extension node information and record the extension node information in a data mapping table to register the extension node in the master node. Figure 2As shown, the extension node can deploy a remote call service, and through the remote call service, the extension node can be registered or unregistered in the main node.
[0098] When performing data migration, the master node device can call the remote service to send the state data of the target state tree to the extended node device. As an example, the master node device can send the data of the target state tree to the extended node device through the Rsync service. Rsync is an efficient data synchronization tool that supports incremental transmission and differential synchronization. It is used for state tree data transmission between the master node and the extended node during the data migration process.
[0099] After the master node device sends the state data corresponding to the target state data to the extension node, the extension node can verify the received data, and after the data verification passes, rebuild the state tree according to the state data corresponding to the target state data. After the data verification passes, the extension node can send a migration completion message to the master node device, and the migration completion message can indicate that the extension node has received the state data corresponding to the target state data and rebuilt the target state tree.
[0100] S104: if the migration completion information returned by the extended node is received, then update the data mapping table stored in the master node, wherein the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node.
[0101] After receiving the migration completion information, the master node device may update the data mapping table, so that the extended node corresponding to the target state tree may be recorded in the data mapping table.
[0102] When migrating state data to the extended node, the master node can maintain a data mapping table, which can record the location of each state tree, storage node information, data version range, etc., for data query and migration operations. Table 1 is a schematic diagram of a data mapping table provided in an embodiment of the present application.
[0103] Table 1
[0104]
[0105] As shown in Table 1, the data mapping table can record the mapping relationship between the main node device and the extension node, and the information of each extension node, such as the storage usage, version range, and availability status of the extension node. For example, remote service 1 in Table 1 can correspond to an extension node, remote service 2 can correspond to an extension node, and remote service 3 can correspond to an extension node. Treerange can be the state data range stored for the extension node, BF can be a global Bloom filter, and info can include the state of the extension node, storage space, etc.
[0106] S105, deleting the target status tree in the master node.
[0107] After updating the data mapping table, the state data of the target state tree in the master node can be deleted, thereby completing the migration of the target state tree from the master node to the extended node. The master node device deletes the target state tree, which can release the storage space in the master node device and reduce the storage pressure of the master node device.
[0108] In this embodiment, the state data is organized into multiple state tree units in timeline order, each state tree unit can contain state data within a fixed range, and multiple state tree units are organized in time order. By maintaining the state data based on the state tree, data segmentation can be flexibly performed, thereby facilitating flexible data migration and ensuring efficient data access. In this embodiment, during the data migration process, the data of the state tree is not merged or modified, thereby ensuring the consistency of the state of the entire network in the blockchain to support other nodes to perform simple payment verification.
[0109] This embodiment can register an extended node in the master node device, thereby expanding the storage space of the master node and reducing the storage pressure of the master node device.
[0110] Reference Figure 3 , shows a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0111] S301, generating a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data.
[0112] The execution subject of this embodiment may be the master node device mentioned above. S301-S305 of this embodiment may refer to S101-S105 in the previous embodiment, and will not be described in detail here.
[0113] S302: When data migration is triggered, determine a target state tree to be migrated from the generated state trees.
[0114] S303: Send the status data of the target status tree to the extension node of the master node.
[0115] S304: if the migration completion information returned by the extended node is received, then update the data mapping table stored in the master node, wherein the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node.
[0116] In a possible implementation, when returning the migration completion information, the extended node also sends the global Bloom filter of the extended node to the master node device. The master node device can update the global Bloom filter of the extended node into the data mapping table.
[0117] S304: Delete the target status tree in the master node.
[0118] S306: Receive the global Bloom filter from the extended node.
[0119] BloomFilter is a space-efficient data structure based on a hash function, which is used to quickly determine whether an element exists in a collection.
[0120] One or more extended nodes can be registered in the master node device. Each extended node can maintain a global Bloom filter, which can be used to determine whether data is in a certain extended node.
[0121] When the data in the extended node is updated, the global Bloom filter of the extended node is also updated. Therefore, each time the data migration is completed, the extended node can update the global Bloom filter and send the updated global Bloom filter to the master node device, so that the master node device can include the global filter of each extended node.
[0122] S307 , in response to the query request, determining a target expansion node where target state data is located based on one or more of the global Bloom filters in the master node, the target state data being state data corresponding to the query request.
[0123] The master node device can receive the query request. For example, the smart contract can send a data query request to the master node device. The master node device can determine the target extension node where the target state data is located through the global Bloom filter corresponding to each extension node.
[0124] The target extension node may include one or more. In this embodiment, the state data is continuously updated, and each time the state data is updated, it is recorded in the state tree. Different versions of the target state data may exist in multiple state trees, and each state tree corresponds to a different time. Therefore, the state data may exist in multiple state trees, and the target extension node corresponding to the query request may also include one or more.
[0125] S308: Send the query request to the target extension node to request the target status data from the extension node.
[0126] After determining one or more target extension nodes, the master node device can send a query request to each target extension node. In the target extension node, each state tree can correspond to a local Bloom filter. Based on the local Bloom filter, the target extension node can determine the state tree where the target state data is located, so that the corresponding target state data can be found from the corresponding state tree.
[0127] S309: Determine target status data based on the data returned by the target extension node.
[0128] The master node device may receive one or more data of the target expansion node. The master node device may determine the time information corresponding to each data returned by the target expansion node; and determine the latest data as the target state data according to the time information.
[0129] As an example, the data returned by each target extension node has a corresponding first state tree; the block range corresponding to the first state tree can be determined from the data mapping table, and the block range is represented by the block number, and the block number is generated according to the time sequence; the block range is used as the time information corresponding to the data returned by the target extension node. Afterwards, the master node device can determine the latest data as the target state data based on the block range. For example, the block range corresponding to the state tree corresponding to the 3 data returned by the target extension node can be 1-100, 101-200, and 201-300. At this time, the data in the state tree corresponding to the block range 201-300 can be used as the target state data.
[0130] In this embodiment, when performing data query, preliminary filtering can be performed through a global Bloom filter. The master node device can maintain the global Bloom filter of each extended node, so as to quickly locate the extended node that may contain the target state data. The extended node can further filter the data through a local Bloom filter. For the target extended node, the Bloom filter corresponding to each state tree can accurately locate the target state data. The queried data may include multiple, and the master node device can return the latest data. Based on the double-layer Bloom filter architecture, the master node device in the embodiment of the present application can quickly locate the target state data. Based on the state tree organized by the time structure, the master node device can determine the latest data, so that the query request can be responded to based on the latest data.
[0131] Reference Figure 4 , shows a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0132] S401, generating a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data.
[0133] The execution subject of this embodiment may be the master node device mentioned above. S401-S402 of this embodiment may refer to S101-S102 of the previous embodiment, and will not be described in detail here.
[0134] S402: When data migration is triggered, determine a target state tree to be migrated from the generated state trees.
[0135] S403, determining whether an extended node to be migrated is currently registered in the master node, the extended node to be migrated being an extended node whose remaining storage space is greater than or equal to the storage space corresponding to the target state tree.
[0136] The master node can register the extended node in advance through the remote call service. The master node can register the extended node when data migration is required or storage space is insufficient. Through the remote call service, the extended node can dynamically join and register with the master node. The registration information of the extended node can be updated in the mapping table.
[0137] As an example, the master node device can first determine whether the data with migration can be migrated to the extension node, that is, whether the remaining storage space of the extension node is greater than or equal to the storage space corresponding to the target state tree. The information of the extension node can be stored in the data mapping table. Based on the data mapping table, the master node device can determine the remaining storage space of each extension node, thereby determining whether migration can be performed.
[0138] S404: If the master node currently has no registered extended node to be migrated, register the extended node in the master node.
[0139] If the remaining storage space of the extended node is less than the storage space corresponding to the target state tree, the storage space is insufficient. In this case, the extended node can be registered in the main node to expand the storage space.
[0140] S405: Update the information of the registered extension node in the data mapping table.
[0141] S406, sending the status data of the target status tree to the extension node of the master node.
[0142] The execution subject of this embodiment may be the master node device mentioned above. S406-S408 of this embodiment and S103-S105 of the previous embodiment may refer to each other, and will not be described in detail here.
[0143] The master node device may send the status data of the target status tree to the extension node newly registered with the master node.
[0144] S407: If the migration completion information returned by the extended node is received, the data mapping table stored in the master node is updated, where the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node.
[0145] The global Bloom filter of the extended node can be updated in the data mapping table.
[0146] S408, deleting the target status tree in the master node.
[0147] The method in this embodiment can register an extension node in the master node, thereby expanding the storage space of the master node device. The migration mechanism of this embodiment effectively alleviates the storage bottleneck of the master node, improves service performance, and retains the blockchain's ability to trace historical data.
[0148] Reference Figure 5 , shows a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0149] S501, receiving status data of the target status tree from the master node.
[0150] The execution subject of this embodiment is an expansion node device. The expansion node device can be a computer device with storage space, such as a personal computer, a server, etc. This embodiment does not limit the specific type of the computer device.
[0151] S502: Perform data verification on the target status tree.
[0152] Based on the verification information in the target state data, each state data corresponding to the target state tree may be verified.
[0153] S503: If the target state tree passes verification, the target state tree is rebuilt in the extension node based on the state data. The target state tree is a B+ tree based on the copy-on-write technology. Each leaf node of the target state tree is used to store the state data of the account in the blockchain.
[0154] The extended node device can rebuild the target state tree in the extended node based on the state data of the target state tree. The same part of the state data is organized in the form of a state tree in the main node and the extended node, so as to facilitate data query and tracing.
[0155] S504, returning migration completion information to the master node, the master node is used to delete the target status tree in the master node according to the migration completion information and update the data mapping table stored in the master node, the data mapping table is used to characterize the mapping relationship between the status data stored in the extension node and the extension node.
[0156] In this embodiment, the state data in the extended node can also be maintained in the form of a state tree without merging or deleting the data, thereby ensuring the consistency of the data and facilitating the query and tracing of the data.
[0157] Reference Figure 6 , shows a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0158] S601, registering the extended node in the master node, and the master node updates the data mapping table.
[0159] The steps S601 to S610 in this embodiment may refer to the above embodiments and will not be described in detail here.
[0160] S602, the master node generates a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data.
[0161] S603: When data migration is triggered, the master node determines a target state tree to be migrated.
[0162] S604: The master node sends the state data of the target state tree to the extension node of the master node.
[0163] S605: The extended node receives the status data of the target status tree from the master node.
[0164] S606: The extension node performs data verification on the target status tree.
[0165] S607: If the target status tree passes verification, the extended node rebuilds the target status tree in the extended node based on the status data.
[0166] S608: The extended node returns migration completion information and a global Bloom filter to the master node.
[0167] S609, if the migration completion information returned by the extended node is received, the master node updates the data mapping table stored in the master node, where the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node.
[0168] S610: The master node deletes the target status tree in the master node.
[0169] In this embodiment, the master node device can migrate data to the extended node device and implement data query based on the Bloom filter. The method in this embodiment provides an efficient distributed data query mechanism. Through the dual filtering design of the global Bloom filter and the local Bloom filter of the extended node, the query performance is significantly optimized and the data location overhead in the distributed scenario is reduced.
[0170] Reference Figure 7 , shows a schematic diagram of the steps of another blockchain data migration method provided by an embodiment of the present application, which may specifically include the following steps:
[0171] S701, in response to a query request, based on one or more of the global Bloom filters in the master node, the master node determines a target extension node where target state data is located, the target state data being state data corresponding to the query request.
[0172] The steps S601 to S610 in this embodiment may refer to the above embodiments and will not be described in detail here.
[0173] S702: The master node sends the query request to the target extension node to request the target status data from the extension node.
[0174] S703: The extended node receives a query request from the master node.
[0175] S704: The master node determines the data to be returned from the stored state tree according to the query request and the local Bloom filter of the extended node.
[0176] In the extended node, each state tree may have a corresponding local Bloom filter, and the local filter may be used to determine whether the target state data exists in the state tree. After receiving the query request, the extended node may determine whether the target state data exists in each state tree based on the local Bloom filter corresponding to each state tree.
[0177] If the target state data exists in the target state tree, the extended node can search for the data to be returned from the target state tree.
[0178] S705, the extended node sends the data to be returned to the main node.
[0179] S706: The master node determines target status data based on the data returned by the target extension node.
[0180] This embodiment adopts a registration and migration mechanism for dynamic expansion nodes, which can significantly reduce the storage pressure of the main node while retaining the traceability of historical data. During the data migration process, the migrated data is not modified or merged, thereby ensuring the consistency of the state data across the entire network. The process design during the data migration process strictly guarantees the consistency and efficiency of data access. The dynamic horizontal expansion function is realized: it supports the dynamic addition and exit of expansion nodes, and realizes the flexible management of migration nodes in combination with the mapping table. It provides horizontal expansion capabilities, which can adapt to the data storage needs in different scenarios and meet the performance requirements of the system that change with the growth of data. Based on the state tree, a dynamic horizontal expansion solution for state data is proposed, which effectively alleviates the storage pressure caused by the continuous growth of data. It provides a collaborative working mechanism between the main node and the expansion node, combined with the optimized design of data migration and query, to ensure the scalability and high performance of the system.
[0181] During the migration process, the data location and status are recorded through the mapping table, and the Bloom filter is used for rapid positioning to ensure high consistency and high query efficiency of the migrated data. After the data is migrated, the migrated data is kept static, and no merge or change operations are performed to avoid data version inconsistency.
[0182] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0183] Reference Figure 8 , shows a schematic diagram of a blockchain data migration device provided in an embodiment of the present application, the device is applied to a master node device of the blockchain, and specifically may include a generation module 81, a determination module 82, a sending module 83 and a receiving module 84, wherein:
[0184] A generating module 81 is used to generate a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data;
[0185] A determination module 82, configured to determine a target state tree to be migrated from the generated state trees when data migration is triggered;
[0186] A sending module 83, used to send the state data of the target state tree to the extension node of the master node;
[0187] An updating module 84, configured to update a data mapping table stored in the master node if migration completion information returned by the extension node is received, wherein the data mapping table is used to represent a mapping relationship between the state data stored in the extension node and the extension node;
[0188] The deleting module 85 is used to delete the target state tree in the master node.
[0189] In a possible implementation manner, one or more of the extended nodes are registered in the master node, each of the extended nodes has a corresponding global Bloom filter in the master node, and the device further includes:
[0190] A global Bloom filter receiving module, configured to receive the global Bloom filter from the extended node;
[0191] A target extension node determination module, configured to determine, in response to a query request, a target extension node where target state data is located based on one or more of the global Bloom filters in the master node, wherein the target state data is state data corresponding to the query request;
[0192] A query request sending module, used to send the query request to the target extension node to request the target status data from the extension node;
[0193] The target state data determination module is used to determine the target state data based on the data returned by the target extension node.
[0194] In a possible implementation, the target state data determination module includes:
[0195] A time information determination submodule, used to determine the time information corresponding to each data returned by the target extension node;
[0196] The target state data determination submodule is used to determine the latest data as the target state data according to the time information.
[0197] In a possible implementation, the time information determination submodule includes:
[0198] A first state tree determining unit, configured to determine a first state tree corresponding to the data returned by the target extension node;
[0199] A block range determining unit, configured to determine a block range corresponding to the first state tree from the data mapping table, wherein the block range is represented by a block number, and the block number is generated according to a time sequence;
[0200] The time information determining unit is used to use the block range as the time information corresponding to the data returned by the target extension node.
[0201] In a possible implementation manner, the device further includes:
[0202] A judgment module, used to determine whether an extended node to be migrated is currently registered in the master node, the extended node to be migrated being an extended node whose remaining storage space is greater than or equal to the storage space corresponding to the target state tree;
[0203] A registration module, configured to register the extended node in the master node if the master node currently has no registered extended node to be migrated;
[0204] The data mapping table updating module is used to update the information of the registered extension node in the data mapping table.
[0205] In a possible implementation, the generating module 81 includes:
[0206] A division submodule, used to divide the state data in the blockchain according to a preset time interval;
[0207] The generating submodule is used to generate a state data tree based on the state data within a time interval, and each state data tree is linked in time sequence.
[0208] Reference Fig. 9 , shows a schematic diagram of a blockchain data migration device provided in an embodiment of the present application, the device is applied to an extension node device, and specifically may include: a receiving module 91, a verification module 92, a reconstruction module 93 and a sending module 94, wherein:
[0209] A receiving module 91 is used to receive the state data of the target state tree from the master node, wherein the target state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the target state tree is used to store the state data of the account in the blockchain;
[0210] A verification module 92, used for performing data verification on the target state tree;
[0211] A reconstruction module 93, configured to rebuild the target state tree in the extension node based on the state data if the target state tree passes the verification;
[0212] The sending module 94 is used to return the migration completion information to the master node, and the master node is used to delete the target status tree in the master node according to the migration completion information and update the data mapping table stored in the master node, and the data mapping table is used to characterize the mapping relationship between the status data stored in the extended node and the extended node.
[0213] In a possible implementation manner, the device further includes:
[0214] A global Bloom filter update module, used for updating the global Bloom filter of the extended node;
[0215] The global Bloom filter sending module is used to send the updated global Bloom filter to the master node.
[0216] In a possible implementation manner, the device further includes:
[0217] A query request receiving module, used to receive a query request from the master node;
[0218] A data determination module, configured to determine data to be returned from a stored state tree according to the query request and a local Bloom filter in the extended node, each state tree in the extended node having a corresponding local Bloom filter, the local Bloom filter being used to perform data query in the corresponding state tree;
[0219] The return module is used to send the data to be returned to the master node.
[0220] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.
[0221] Fig.10 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Fig.10 As shown, the computer device 100 of this embodiment includes: at least one processor 1000 ( Fig.10 Only one is shown in the figure), a memory 1001 and a computer program 1002 stored in the memory 1001 and executable on the at least one processor 1000, wherein the processor 1000 implements the steps of any of the above-mentioned method embodiments when executing the computer program 1002.
[0222] The computer device 100 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud computing device. The computer device may include, but is not limited to, a processor 1000 and a memory 1001. Those skilled in the art will appreciate that Fig.10 The computer device 100 is merely an example and does not constitute a limitation on the computer device 100 . The computer device 100 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 100 may also include input and output devices, network access devices, etc.
[0223] The processor 1000 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0224] In some embodiments, the memory 1001 may be an internal storage unit of the computer device 100, such as a hard disk or memory of the computer device 100. In other embodiments, the memory 1001 may also be an external storage device of the computer device 100, such as a plug-in hard disk, a smart memory card (SmartMediaCard, SMC), a secure digital (SecureDigital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 100. Further, the memory 1001 may also include both an internal storage unit of the computer device 100 and an external storage device. The memory 1001 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program. The memory 1001 may also be used to temporarily store data that has been output or is to be output.
[0225] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0226] An embodiment of the present application provides a computer program product. When the computer program product is run on a computer device, the computer device can implement the steps in the above-mentioned method embodiments when executing the computer device.
[0227] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application is described in detail with reference to the above-mentioned embodiments, a person skilled in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A data migration method for blockchain, characterized in that: A master node device applied to a blockchain, the method comprising: Generate a state tree based on the state data of the account in the blockchain, wherein the state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the state tree is used to store the state data; When data migration is triggered, determining a target state tree to be migrated from the generated state tree; Sending the state data of the target state tree to the extension node of the master node; If the migration completion information returned by the extended node is received, the data mapping table stored in the master node is updated, wherein the data mapping table is used to represent the mapping relationship between the state data stored in the extended node and the extended node; Deleting the target state tree in the master node; Wherein, the state data tree is generated based on the state data of the account in the blockchain, including: Dividing the state data in the blockchain according to preset time intervals; A state tree is generated based on the state data within a time interval, each state tree is organized in chronological order, and the state tree is a multi-version Merkel tree organized based on a time structure.
2. The method according to claim 1, characterized in that One or more of the extended nodes are registered in the master node, each of the extended nodes has a corresponding global Bloom filter in the master node, and the method further includes: receiving the global Bloom filter from the extended node; In response to the query request, determining a target expansion node where target state data is located based on one or more of the global Bloom filters in the master node, the target state data being state data corresponding to the query request; Sending the query request to the target extension node to request the target status data from the extension node; Based on the data returned by the target extension node, target status data is determined.
3. The method according to claim 2, characterized in that The determining target status data based on the data returned by the target extension node includes: Determine the time information corresponding to each data returned by the target extension node; According to the time information, the latest data is determined as the target state data.
4. The method according to claim 3, characterized in that The determining of the time information corresponding to each data returned by the target extension node includes: Determine a first state tree corresponding to the data returned by the target extension node; Determine a block range corresponding to the first state tree from the data mapping table, wherein the block range is represented by a block number, and the block number is generated according to a time sequence; The block range is used as the time information corresponding to the data returned by the target extension node.
5. The method according to any one of claims 1 to 4, characterized in that: Before sending the target state tree to the extension node of the master node, the method further includes: Determine whether an extended node to be migrated is currently registered in the master node, the extended node to be migrated being an extended node whose remaining storage space is greater than or equal to the storage space corresponding to the target state tree; If the master node currently has no registered extension node to be migrated, registering the extension node in the master node; The information of the registered extended node is updated in the data mapping table.
6. A data migration method for blockchain, characterized in that: Applied to an expansion node device, the method comprises: Receive status data of a target status tree from a master node, the target status tree is determined by the master node from a generated status tree, the master node is used to divide the status data in the blockchain according to a preset time interval; generate a status tree based on the status data within a time interval, each status tree is organized in chronological order, and the status tree is a multi-version Merkel tree organized based on a time structure; Performing data verification on the target state tree; If the target state tree passes the verification, the target state tree is rebuilt in the extension node based on the state data, the target state tree is a B+ tree based on the copy-on-write technology, and each leaf node of the target state tree is used for the state data; Return migration completion information to the master node, the master node is used to update the data mapping table stored in the master node according to the migration completion information and delete the state data of the target state tree, the data mapping table is used to characterize the mapping relationship between the state data stored in the extension node and the extension node.
7. The method according to claim 6, characterized in that After rebuilding the target state tree in the extended node based on the state data, the method further includes: Updating the global Bloom filter of the extended node; The updated global Bloom filter is sent to the master node.
8. The method according to claim 6 or 7, characterized in that The method further comprises: Receiving a query request from the master node; Determine the data to be returned from the stored state tree according to the query request and the local Bloom filter in the extended node, each state tree in the extended node has a corresponding local Bloom filter, and the local Bloom filter is used to perform data query on the corresponding state tree; The data to be returned is sent to the master node.
9. A computer 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 computer program, the method according to any one of claims 1 to 8 is implemented.
10. A computer program product, characterized in that When the computer program product is executed on a computer device, the computer device is caused to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Stateful container online migration method and apparatus
CN105607954A
MPTC account state tree and fast retrieval method of MPTC block-chain
CN108197226A