Data archiving method, computer device and storage medium

By saving the leaf nodes of the Merkle tree to the local database with the tree root as an auxiliary index when the leaf nodes reach a threshold, the problem of heavy calculation tasks for the Merkle tree root is solved, and the amount of computation is significantly reduced and the efficiency is improved.

CN115952170BActive Publication Date: 2025-10-28HANGZHOU FUZAMEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211727108.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2025-10-28
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

In blockchain databases, when the amount of data in a Merkle tree is large, the computational task at the root of the tree is arduous and involves a large amount of computation.

Method used

When the total number of leaf nodes in the Merkle tree reaches a threshold, the leaf nodes are saved to the local database with the root as an auxiliary index, and the Merkle tree is cleared to accommodate new leaf nodes. At the same time, when updating archived leaf nodes, the auxiliary indexes of other leaf nodes are updated to control the height of the Merkle tree.

Benefits of technology

This significantly reduces the computational burden on Merkel tree roots, decreases the computational load, and improves computational efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115952170B_ABST
    Figure CN115952170B_ABST
Patent Text Reader

Abstract

This invention provides a data archiving method, computer device, and storage medium. The method includes: in response to inserting a new leaf node into a first Merkle tree, determining whether the total number of leaf nodes reaches a first threshold; if yes, calculating and saving the first root of the first Merkle tree; and saving each leaf node in a local database using the first root as an auxiliary index; clearing the first Merkle tree; in response to updating the first leaf node of the first Merkle tree, searching for the first leaf node in the first Merkle tree; if found, updating directly; if not found, searching and updating from the local database; and searching for a second leaf node in the local database based on the second root of the first leaf node minus one threshold; calculating a third root based on the updated first leaf node and each second leaf node; and updating the auxiliary index of the first leaf node and each second leaf node from the second root to the third root.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, specifically to a data archiving method, computer equipment, and storage medium. Background Technology

[0002] In blockchain database solutions, using Merkle tree structures to store data is a common approach. A Merkle tree is a binary tree; when a new leaf node is added, or an existing leaf node is updated, the root of the tree needs to be recalculated.

[0003] In existing blockchain solutions, when the amount of data becomes large enough, the computational tasks of the root of the tree become extremely heavy. Summary of the Invention

[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a data archiving method, computer device and storage medium that can reduce the computational workload of Merkle root computation tasks.

[0005] In a first aspect, the present invention provides a data archiving method suitable for blockchain nodes, comprising:

[0006] In response to inserting a new leaf node into the first Merkle tree, determine whether the total number of leaf nodes in the first Merkle tree has reached a first threshold:

[0007] Yes, then calculate and save the first root of the first Merkle tree; and,

[0008] Each leaf node of the first Merkle tree is stored in the local database using the first tree root as an auxiliary index;

[0009] Clear the first Merkle tree;

[0010] In response to updating the first leaf node of the first Merkle tree, find the first leaf node in the first Merkle tree:

[0011] If found, update the first leaf node directly;

[0012] If not found, then search the local database and update the first leaf node; and,

[0013] Based on the second root of the first leaf node found, search the local database for the first threshold minus one second leaf node that corresponds to the second root;

[0014] Calculate the third root based on the updated first leaf node and the first threshold minus one second leaf node;

[0015] Update the auxiliary index of the first leaf node and the first threshold minus one second leaf node from the second root to the third root.

[0016] In a second aspect, the present invention also provides a computer device including one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors to cause the one or more processors to perform methods provided according to embodiments of the present invention.

[0017] Thirdly, the present invention also provides a storage medium storing a computer program that causes a computer to perform the methods provided according to various embodiments of the present invention.

[0018] The data archiving method, computer device, and storage medium provided by various embodiments of the present invention archive and save these leaf nodes to a local database with the root as an auxiliary index whenever the total number of leaf nodes in the Merkle tree reaches a first threshold, and clear the Merkle tree to accommodate new leaf nodes; at the same time, when updating the leaf nodes already archived to the local database, the auxiliary indexes of other leaf nodes archived in the same batch are also updated; ultimately, the height of the Merkle tree is controlled at a relatively low height, thereby controlling the computational workload of the Merkle tree root to a low order of magnitude, and significantly reducing the computational workload of the Merkle tree root computation task. Attached Figure Description

[0019] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:

[0020] Figure 1 This is a flowchart of a data archiving method provided in an embodiment of the present invention.

[0021] Figure 2 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0022] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.

[0023] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0024] Figure 1 This is a flowchart of a data archiving method provided in an embodiment of the present invention.

[0025] like Figure 1 As shown, in this embodiment, the present invention provides a data archiving method suitable for blockchain nodes, including:

[0026] S11: In response to inserting a new leaf node into the first Merkle tree, determine whether the total number of leaf nodes in the first Merkle tree has reached a first threshold:

[0027] Yes, then proceed to step S13: calculate and save the first root of the first Merkle tree; and,

[0028] S15: Using the first tree root as an auxiliary index, store each leaf node of the first Merkle tree in the local database;

[0029] S17: Clear the first Merkle tree;

[0030] S21: In response to updating the first leaf node of the first Merkle tree, find the first leaf node in the first Merkle tree:

[0031] If found, proceed to step S22: directly update the first leaf node;

[0032] If not found, proceed to step S23: search and update the first leaf node from the local database; and,

[0033] S25: Based on the second root of the first leaf node found, search the local database for the first threshold minus one second leaf node that also corresponds to the second root;

[0034] S27: Calculate the third root based on the updated first leaf node and the first threshold minus one second leaf node;

[0035] S29: Update the auxiliary index of the first leaf node and the first threshold minus one second leaf node from the second root to the third root.

[0036] In this embodiment, the first threshold is configured as 1024 and the layer height of the first Merkle tree is 10, as an example to illustrate the above method. Those skilled in the art should understand that in more embodiments, the layer height of the first Merkle tree can be configured to any reasonable layer height such as 8 / 9 / 11 / 12, and the first threshold can be configured to 256 (2...) according to actual needs. 8 ) / 512(2 9 ) / 2048(2 11 ) / 4096(2 12 (This can achieve the same technical effect.)

[0037] In step S11, when blockchain node a inserts a new leaf node L1 into Merkle tree T1, it is determined whether the total number of leaf nodes in T1 has reached 1024.

[0038] No, then the process ends;

[0039] Yes, then proceed to step S13, calculate the first tree root root1 based on the 1024 leaf nodes in the current T1, and include; and,

[0040] Step S15: Using the account ID corresponding to each leaf node as the primary index and the first tree root1 as the secondary index, store the 1024 leaf nodes in the current T1 in the local database localdb respectively.

[0041] Step S17: Clear Merkle tree T1.

[0042] That is, whenever the Merkle tree T1 is full with 1024 leaf nodes, the batch of 1024 leaf nodes will be archived and stored in the local database localdb, and T1 will be cleared to store new leaf nodes.

[0043] Those skilled in the art should understand that, taking the example of a Merkle tree T1 having a total of 50,000 leaf nodes (including all leaf nodes archived to the local database localdb, and all leaf nodes existing in the tree but not archived):

[0044] In the existing scheme, for a Merkle tree containing 50,000 leaf nodes, calculating the root of the tree requires (50,000+25,000+12,500+6,250+3,125+1,563+782+391+196+98+49+25+13+7+4+2+1) = 100,006 hash calculations.

[0045] In the scheme of this application, a Merkle tree containing 50,000 leaf nodes includes 1,024 leaf nodes that have been archived and stored in the local database localdb in 48 batches, and 848 leaf nodes that exist in the tree but have not yet been archived. Calculating the root of the tree only requires (1024+512+256+128+64+32+16+8+4+2+1+25+13+7+4+2+1) = 2,099 hash calculations, which significantly reduces the computational workload of calculating the Merkle tree root compared to existing schemes.

[0046] At the same time, those skilled in the art should understand that the solution in this application requires the maintenance of auxiliary indexes for archived leaf nodes in the local database localdb.

[0047] For example, when blockchain node a updates leaf node L2 in Merkle tree T1, it executes step S21 to find leaf node L2 in T1:

[0048] If found, proceed to step S22 and directly update the leaf node L2;

[0049] If not found, proceed to step S23: find the first leaf node L2 in the local database localdb, update it to the first leaf node L2′, and save; and,

[0050] Step S25: Based on the auxiliary index of the found first leaf node L2: second tree root2, search for 1023 second leaf nodes that are archived in the same batch as L2 in the local database localdb.

[0051] Step S27: Calculate the third tree root root3 based on the updated first leaf node L2′ and the 1023 second leaf nodes found in step S25;

[0052] Step S29: Update the auxiliary index of the first leaf node L2′ and the 1023 second leaf nodes found in step S25 from the second tree root2 to the third tree root3.

[0053] Those skilled in the art should understand that the cost of maintaining the auxiliary index described above is acceptable compared to the reduced computational load.

[0054] The above embodiment archives and saves these leaf nodes to the local database with the tree root as an auxiliary index whenever the total number of leaf nodes in the Merkle tree reaches a first threshold, and clears the Merkle tree to accommodate new leaf nodes; at the same time, when updating the leaf nodes already archived to the local database, the auxiliary indexes of other leaf nodes archived in the same batch are also updated; ultimately, the height of the Merkle tree is controlled at a relatively low height, thereby controlling the computational workload of the Merkle tree root to a low order of magnitude, and significantly reducing the computational workload of the Merkle tree root computation task.

[0055] Figure 2 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention.

[0056] like Figure 2 As shown, in another aspect, this application also provides a computer device including one or more central processing units (CPUs) 201, which can perform various appropriate actions and processes according to programs stored in read-only memory (ROM) 202 or programs loaded from storage portion 208 into random access memory (RAM) 203. The RAM 203 also stores various programs and data required for the operation of the device 200. The CPU 201, ROM 202, and RAM 203 are interconnected via a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.

[0057] The following components are connected to I / O interface 205: an input section 206 including a keyboard, mouse, etc.; an output section 207 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, modem, etc. The communication section 209 performs communication processing via a network such as the Internet. Drive 210 is also connected to I / O interface 205 as needed. Removable media 211, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 210 as needed so that computer programs read from them can be installed into storage section 208 as needed.

[0058] In particular, according to embodiments of this disclosure, the methods described in any of the above embodiments can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program containing program code for performing any of the above methods. In such embodiments, the computer program can be downloaded and installed from a network via communication section 209, and / or installed from removable medium 211.

[0059] In another aspect, this application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiments; or it may be a standalone computer-readable storage medium not assembled into the device. The computer-readable storage medium stores one or more programs that are used by one or more processors to perform the methods described in this application.

[0060] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified function or operation, or by a combination of dedicated hardware and computer instructions.

[0061] The units or modules described in the embodiments of this application can be implemented in software or hardware. The described units or modules can also be located in a processor; for example, each unit can be a software program located in a computer or mobile smart device, or it can be a separately configured hardware device. The names of these units or modules do not, in certain circumstances, constitute a limitation on the unit or module itself.

[0062] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the concept of this application. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.

Claims

1. A data archiving method, characterized in that, The method is applicable to blockchain nodes, and the method includes: In response to inserting a new leaf node into the first Merkle tree, determine whether the total number of leaf nodes in the first Merkle tree has reached a first threshold: Yes, then calculate and save the first root of the first Merkle tree; and, Each leaf node of the first Merkle tree is stored in the local database using the first tree root as an auxiliary index. Clear the first Merkle tree; In response to updating the first leaf node of the first Merkle tree, the first leaf node is located in the first Merkle tree: If found, update the first leaf node directly; If not found, then search the local database and update the first leaf node; and, Based on the second root of the first leaf node found, search the local database for a second leaf node that corresponds to the second root, which is the first threshold minus one. Calculate the third root based on the updated first leaf node and the first threshold minus one second leaf node; The auxiliary index of the first leaf node and the first threshold minus one second leaf node is updated from the second tree root to the third tree root.

2. The method according to claim 1, characterized in that, The first threshold is 1024, 2048 or 512.

3. A computer device, characterized in that, The device includes: One or more processors; Memory, used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors perform the method as described in claim 1 or 2.

4. A storage medium storing a computer program, characterized in that, When the program is executed by the processor, it implements the method as described in claim 1 or 2.

Citation Information

Patent Citations

  • Data reference processing method, device, apparatus and storage medium for block chain

    CN109255056A

  • State tree data storage method, state tree data synchronization method, state tree data synchronization equipment and storage medium

    CN110442579A