Data archiving method and system for block chain
By verifying the parameters and connectivity of the archive server on the blockchain and transferring cold data to the archive server, the problems of high blockchain data storage cost and low query efficiency are solved, and more efficient data query and storage are achieved. manage.
Patent Information
- Application Number
- CN202410689745.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-03
AI Technical Summary
The cost of data storage on the blockchain is high, and cold data that has not been accessed for a long time affects the efficiency of data query. The existing technology has not yet proposed an effective solution.
Provide a blockchain data archiving method and system that sends a data archiving request to the blockchain through an archiving tool, verifies the upstream parameters and connectivity of the archive server, removes the data on the blockchain and records the hash value, Submit and query data to the archive server first, reducing the storage cost and query pressure of the blockchain.
It effectively improves the query efficiency of blockchain data, reduces storage costs, and ensures that new nodes can obtain data through the network for synchronization.
Smart Images

Figure CN118585507A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of blockchain storage system expansion, and in particular to a data archiving method and system for a blockchain. Background Art
[0002] Due to the characteristics of blockchain, the data on the blockchain will only increase and not decrease, so the database will become larger and larger, and the storage cost will increase accordingly, until the database can no longer carry the data. The existing technology uses a distributed database, but it will affect the overall query efficiency because there is a lot of data with low access frequency.
[0003] In the existing technology, there is high data storage cost on the blockchain, and cold data that has not been accessed for a long time affects the query efficiency of data on the chain. At present, no effective solution has been proposed. Summary of the invention
[0004] The present invention provides a data archiving method and system for a blockchain to solve the problems in the prior art of high data storage costs on the blockchain and long-term inaccessible cold data affecting data query efficiency on the chain.
[0005] To achieve the above-mentioned purpose, on the one hand, the present invention provides a data archiving method of a blockchain, the method comprising: S1, an archiving tool sends a data archiving request to the blockchain; S2, verifying whether the uplink parameters of the archiving server are correct on the blockchain, and verifying whether the IP and port of the archiving server can be connected to the blockchain; if so, submitting all block data on the blockchain that currently need to be archived to the archiving server in sequence, removing the data on the blockchain, and recording the hash value returned by the archiving server after archiving for subsequent verification; otherwise, returning an error code.
[0006] Optionally, submitting all block data on the blockchain that currently need to be archived to the archive server in sequence includes: S21, determining whether all block data on the blockchain that currently need to be archived have been archived. If so, removing the data on the blockchain, and recording the hash value returned by the archive server after archiving for subsequent verification; otherwise, submitting the current block data on the blockchain to the archive server; S22, verifying whether the storage result submitted to the archive server is correct. If so, using the next block data on the blockchain as the current block data and returning to S21; otherwise, entering S1 and rolling back the data archiving request.
[0007] Optionally, the uplink parameters include: block height and timestamp.
[0008] Optionally, before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the process includes: constructing an archive range of blocks currently required to be archived according to the block height in the upstream parameter.
[0009] Optionally, after S2, it also includes: the cli tool preferentially initiates a data query request to the archive server; or the cli tool preferentially initiates a data query request to the blockchain, and if no corresponding data is found, then initiates a data query request to the archive server.
[0010] On the other hand, the present invention provides a data archiving system for a blockchain, the system comprising: an archiving request unit, used for an archiving tool to send a data archiving request to the blockchain; a data archiving unit, used to verify whether the uplink parameters of the archiving server are correct on the blockchain, and to verify whether the IP and port of the archiving server can be connected to the blockchain; if so, all block data on the blockchain that currently needs to be archived are submitted to the archiving server in sequence, the data on the blockchain is removed, and the hash value returned by the archiving server after archiving is recorded for subsequent verification; otherwise, an error code is returned.
[0011] Optionally, submitting all block data on the blockchain that currently need to be archived to the archive server in sequence includes: a first judgment unit, used to judge whether all block data on the blockchain that currently need to be archived have been archived. If so, remove the data on the blockchain and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, submit the current block data on the blockchain to the archive server; a second judgment unit, used to verify whether the storage result submitted to the archive server is correct. If so, use the next block data on the blockchain as the current block data and return to the first judgment unit; otherwise, enter the archive request unit to roll back the data archive request.
[0012] Optionally, the uplink parameters include: block height and timestamp.
[0013] Optionally, before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the process includes: constructing an archive range of blocks currently required to be archived according to the block height in the upstream parameter.
[0014] Optionally, it also includes: a data query unit, which is used for the cli tool to preferentially initiate a data query request to the archive server; or the cli tool preferentially initiates a data query request to the blockchain, and if the corresponding data is not found, then initiates a data query request to the archive server.
[0015] Beneficial effects of the present invention:
[0016] The present invention provides a data archiving method and system for a blockchain, wherein the method comprises: S1, an archiving tool sends a data archiving request to a blockchain; S2, verifying whether the uplink parameters of the archiving server are correct on the blockchain, and verifying whether the IP and port of the archiving server can be connected to the blockchain; if so, submitting all block data on the blockchain that currently need to be archived to the archiving server in sequence, removing the data on the blockchain, and recording the hash value returned by the archiving server after archiving for subsequent verification; otherwise, returning an error code. The method transfers block data with a lower access frequency to the archiving server through data archiving, which can effectively improve the query efficiency of data on the blockchain and reduce the data storage cost on the blockchain; ensuring that new nodes can obtain data on the archiving server and the blockchain through the network for synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flow chart of a blockchain data archiving method provided by an embodiment of the present invention;
[0018] Figure 2 It is a structural diagram of a blockchain data archiving system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all 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.
[0020] Figure 1 is a flow chart of a data archiving method of a blockchain provided by an embodiment of the present invention, such as Figure 1 As shown, the method includes:
[0021] S1. The archiving tool sends a data archiving request to the blockchain;
[0022] S2. Verify on the blockchain whether the uplink parameters of the archive server are correct, and verify whether the IP and port of the archive server can connect to the blockchain; if so, submit all the block data on the blockchain that currently needs to be archived to the archive server in sequence, remove the data on the blockchain, and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, return an error code.
[0023] Specifically, the uplink parameters include: block height and timestamp.
[0024] The verification on the blockchain of whether the uplink parameters of the archive server are correct is specifically as follows:
[0025] 1. If the timestamp is before the current time, the judgment is correct;
[0026] Assume that the current time is 10:00 AM on May 27, 2024, and the timestamp in the uplink parameter is 2:00 PM on May 27, 2024, then there is no way to archive the data, and the verification of the uplink parameter is wrong, an error code is returned, and no archiving is performed. On the contrary, if the timestamp in the uplink parameter is 2:00 PM on May 20, 2024, that is, the timestamp is before the current time, the verification of the uplink parameter is correct and archiving can be performed.
[0027] 2. The block height in the upstream parameter is before the latest block height. If the latest block height is N, then the maximum block height in the upstream parameter is N-1, and the judgment is correct;
[0028] Assume: the latest block height in the blockchain is 101, and the block height in the upstream parameter is 102 at this time, that is, to archive 102 block height data, which exceeds the latest block height, there is no way to archive it, so the verification of the upstream parameter is wrong, an error code is returned, and no archiving is performed. On the contrary, if the block height in the upstream parameter is 100 at this time, that is, only 100 block height data needs to be archived, then the verification of the upstream parameter is correct and archiving can be performed.
[0029] If the uplink parameters of the archive server are verified to be correct on the blockchain, and the IP and port of the archive server can be connected to the blockchain, all block data on the blockchain that currently needs to be archived will be submitted to the archive server in sequence.
[0030] Before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the following steps are included:
[0031] According to the block height in the upstream parameter, the block archiving range that currently needs to be archived is constructed.
[0032] Assume that, for the first archiving, the block height in the upstream parameter is 10, then the block range that needs to be archived is constructed as 1-10; for the second archiving, the block height in the upstream parameter is 100, then the block range that needs to be archived is directly constructed as 11-100.
[0033] Furthermore, submitting all block data currently required to be archived on the blockchain to the archive server in sequence includes:
[0034] S21. Determine whether all block data on the blockchain that need to be archived have been archived. If so, remove the data on the blockchain and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, submit the current block data on the blockchain to the archive server;
[0035] S22. Check whether the storage result submitted to the archive server is correct. If so, use the next block data on the blockchain as the current block data and return to S21. Otherwise, enter S1 and roll back the data archive request.
[0036] Specifically, suppose that the block data from 1 to 10 is to be archived; first submit the first block data to the archive server; verify whether the storage result submitted to the archive server is correct, that is, the block data processing is completed and no changes have occurred, then continue to submit 2 block data to the archive server, verify that the storage result submitted to the archive server is correct, then continue to submit the third block data to the archive server, until the 10th block data is submitted to the archive server, and verify that the storage result submitted to the archive server is correct, then remove the data on the blockchain, and record the hash value returned by the archive server after archiving for subsequent verification (store the hash value on the blockchain). That is, the next time you want to archive the 100th block height, you can know that the last time you have archived to the 10th block height according to the hash value on the blockchain, then directly archive the 11th to 100th block data.
[0037] On the contrary, the block data of 1-10 is archived; the first block data is submitted to the archive server; the storage result submitted to the archive server is verified to be correct, and the 2nd block data is submitted to the archive server. At this time, if the database write fails, the storage result submitted to the archive server is verified to be wrong, then the loop is directly jumped out, the data archiving request is rolled back, and the data is no longer archived; and the first block data of the archive is deleted. It should be noted that when the archiving tool sends a data archiving request to the blockchain again, and verifies that the upstream parameters of the archive server are correct on the blockchain, and verifies that the IP and port of the archive server can be connected to the blockchain, all the block data on the blockchain that currently need to be archived must be submitted to the archive server in sequence from the beginning, that is, the block data of 1-10 is archived, instead of archiving the block data of 2-10.
[0038] In this application, after S2, it also includes:
[0039] The cli tool first initiates data query requests to the archive server;
[0040] Or the cli tool first initiates a data query request to the blockchain. If no corresponding data is found, it then initiates a data query request to the archive server.
[0041] In order to reduce the pressure of blockchain query, you can first query the data from the archive server. If there is no data, then query the data from the blockchain.
[0042] Furthermore, in the present application, after S2, the step further includes: data recovery; specifically:
[0043] 1. The archiving tool sends a data recovery request to the blockchain;
[0044] 2. Verify on the blockchain whether the uplink parameters of the archive server are correct, and verify whether the IP and port of the archive server can be connected to the blockchain; if so, construct the block data range that currently needs to be restored according to the block height in the uplink parameters; download all the block data that currently needs to be restored from the archive server in sequence, and rewrite them to the database on the blockchain; otherwise, return an error code.
[0045] Specifically, the block data that needs to be restored is downloaded from the archive server in sequence and rewritten into the database on the blockchain, including:
[0046] 21. Determine whether all the block data that needs to be restored has been restored. If not, download the current block data on the archive server and write it to the database on the blockchain;
[0047] 22. Determine whether the data recovery process encounters an exception. If not, use the next block data as the current block data and return to 21; otherwise, roll back the data recovery request.
[0048] It should be noted that if the data recovery process encounters an exception, when the data is restored again, all the block data currently needed to be restored on the archive server must be downloaded from the beginning and rewritten to the database on the blockchain.
[0049] Figure 2 : is a schematic diagram of the structure of a blockchain data archiving system provided by an embodiment of the present invention, such as Figure 2 As shown, the system includes:
[0050] An archiving request unit 201 is used for the archiving tool to send a data archiving request to the blockchain;
[0051] The data archiving unit 202 is used to verify whether the uplink parameters of the archiving server are correct on the blockchain, and to verify whether the IP and port of the archiving server can be connected to the blockchain; if so, all block data on the blockchain that currently needs to be archived are submitted to the archiving server in sequence, the data on the blockchain is removed, and the hash value returned by the archiving server after archiving is recorded for subsequent verification; otherwise, an error code is returned.
[0052] The uplink parameters include: block height and timestamp.
[0053] The verification on the blockchain of whether the uplink parameters of the archive server are correct is specifically as follows:
[0054] 1. If the timestamp is before the current time, the judgment is correct;
[0055] 2. The block height in the upstream parameter is before the latest block height. If the latest block height is N, then the maximum block height in the upstream parameter is N-1, and the judgment is correct.
[0056] Before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the following steps are included:
[0057] According to the block height in the upstream parameter, the block archiving range that currently needs to be archived is constructed.
[0058] Submitting all block data currently required to be archived on the blockchain to the archive server in sequence includes:
[0059] The first judgment unit is used to judge whether all block data currently required to be archived on the blockchain have been archived. If so, remove the data on the blockchain and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, submit the current block data on the blockchain to the archive server;
[0060] The second judgment unit is used to verify whether the storage result submitted to the archive server is correct. If so, the next block data on the blockchain is used as the current block data and returns to the first judgment unit; otherwise, it enters the archive request unit and rolls back the data archive request.
[0061] The data archiving system of the blockchain also includes:
[0062] Data query unit, used by the cli tool to initiate data query requests to the archive server first;
[0063] Or the cli tool first initiates a data query request to the blockchain. If no corresponding data is found, it then initiates a data query request to the archive server.
[0064] The data archiving system of the blockchain further includes: a data recovery unit; specifically:
[0065] 1. The archiving tool sends a data recovery request to the blockchain;
[0066] 2. Verify on the blockchain whether the uplink parameters of the archive server are correct, and verify whether the IP and port of the archive server can be connected to the blockchain; if so, construct the block data range that currently needs to be restored according to the block height in the uplink parameters; download all the block data that currently needs to be restored from the archive server in sequence, and rewrite them to the database on the blockchain; otherwise, return an error code.
[0067] Specifically, the block data that needs to be restored is downloaded from the archive server in sequence and rewritten into the database on the blockchain, including:
[0068] 21. Determine whether all the block data that needs to be restored has been restored. If not, download the current block data on the archive server and write it to the database on the blockchain;
[0069] 22. Determine whether the data recovery process encounters an exception. If not, use the next block data as the current block data and return to 21; otherwise, roll back the data recovery request.
[0070] Beneficial effects of the present invention:
[0071] The present invention provides a data archiving method and system for a blockchain, wherein the method comprises: S1, an archiving tool sends a data archiving request to a blockchain; S2, verifying whether the uplink parameters of the archiving server are correct on the blockchain, and verifying whether the IP and port of the archiving server can be connected to the blockchain; if so, submitting all block data on the blockchain that currently need to be archived to the archiving server in sequence, removing the data on the blockchain, and recording the hash value returned by the archiving server after archiving for subsequent verification; otherwise, returning an error code. The method transfers block data with a lower access frequency to the archiving server through data archiving, which can effectively improve the query efficiency of data on the blockchain and reduce the data storage cost on the blockchain; ensuring that new nodes can obtain data on the archiving server and the blockchain through the network for synchronization.
[0072] 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 archiving method for a blockchain, characterized in that: include: S1. The archiving tool sends a data archiving request to the blockchain; S2. Verify on the blockchain whether the uplink parameters of the archive server are correct, and verify whether the IP and port of the archive server can connect to the blockchain; if so, submit all the block data on the blockchain that currently needs to be archived to the archive server in sequence, remove the data on the blockchain, and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, return an error code.
2. The method according to claim 1, characterized in that Submitting all block data currently required to be archived on the blockchain to the archive server in sequence includes: S21. Determine whether all block data on the blockchain that need to be archived have been archived. If so, remove the data on the blockchain and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, submit the current block data on the blockchain to the archive server; S22. Check whether the storage result submitted to the archive server is correct. If so, use the next block data on the blockchain as the current block data and return to S21. Otherwise, enter S1 and roll back the data archive request.
3. The method according to claim 1, characterized in that The uplink parameters include: Block height and timestamp.
4. The method according to claim 3, characterized in that Before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the following steps are included: According to the block height in the upstream parameter, the block archiving range that currently needs to be archived is constructed.
5. The method according to claim 1, characterized in that After S2, it also includes: The cli tool first initiates data query requests to the archive server; Or the cli tool first initiates a data query request to the blockchain. If no corresponding data is found, it then initiates a data query request to the archive server.
6. A blockchain data archiving system, characterized in that: include: An archiving request unit, used for the archiving tool to send a data archiving request to the blockchain; The data archiving unit is used to verify whether the uplink parameters of the archiving server are correct on the blockchain, and to verify whether the IP and port of the archiving server can be connected to the blockchain; if so, all the block data on the blockchain that currently needs to be archived will be submitted to the archiving server in sequence, the data on the blockchain will be removed, and the hash value returned by the archiving server after archiving will be recorded for subsequent verification; otherwise, an error code will be returned.
7. The system according to claim 6, characterized in that Submitting all block data currently required to be archived on the blockchain to the archive server in sequence includes: The first judgment unit is used to judge whether all block data currently required to be archived on the blockchain have been archived. If so, remove the data on the blockchain and record the hash value returned by the archive server after archiving for subsequent verification; otherwise, submit the current block data on the blockchain to the archive server; The second judgment unit is used to verify whether the storage result submitted to the archive server is correct. If so, the next block data on the blockchain is used as the current block data and returns to the first judgment unit; otherwise, it enters the archive request unit and rolls back the data archive request.
8. The system according to claim 6, characterized in that The uplink parameters include: Block height and timestamp.
9. The system according to claim 8, characterized in that Before submitting all block data currently required to be archived on the blockchain to the archive server in sequence, the following steps are included: According to the block height in the upstream parameter, the block archiving range that currently needs to be archived is constructed.
10. The system according to claim 6, characterized in that Also includes: Data query unit, used by the cli tool to initiate data query requests to the archive server first; Or the cli tool first initiates a data query request to the blockchain. If no corresponding data is found, it then initiates a data query request to the archive server.
Citation Information
Patent Citations
Data archiving method of block-chain block data and electronic equipment
CN107423426A
Data archiving method and device, equipment and storage medium
CN113360456A
Block chain data processing method and device, electronic equipment and storage medium
CN116627999A
